77import android .content .SharedPreferences ;
88import android .content .pm .PackageManager ;
99import android .content .pm .Signature ;
10- import android .net .ConnectivityManager ;
1110import android .net .Uri ;
1211import android .util .Log ;
1312
1413import androidx .annotation .NonNull ;
1514import androidx .annotation .Nullable ;
1615import androidx .core .app .NotificationCompat ;
1716import androidx .core .app .NotificationManagerCompat ;
18- import androidx .core .content .ContextCompat ;
1917import androidx .core .content .pm .PackageInfoCompat ;
2018import androidx .preference .PreferenceManager ;
2119
@@ -48,7 +46,8 @@ public CheckForNewAppVersion() {
4846 private static final boolean DEBUG = MainActivity .DEBUG ;
4947 private static final String TAG = CheckForNewAppVersion .class .getSimpleName ();
5048
51- private static final String GITHUB_APK_SHA1
49+ // Public key of the certificate that is used in NewPipe release versions
50+ private static final String RELEASE_CERT_PUBLIC_KEY_SHA1
5251 = "B0:2E:90:7C:1C:D6:FC:57:C3:35:F0:88:D0:8F:50:5F:94:E4:D2:15" ;
5352 private static final String NEWPIPE_API_URL = "https://newpipe.net/api/data.json" ;
5453
@@ -129,44 +128,37 @@ private static void compareAppVersionAndShowNotification(@NonNull final Applicat
129128 final String versionName ,
130129 final String apkLocationUrl ,
131130 final int versionCode ) {
132- final int notificationId = 2000 ;
133-
134- if (BuildConfig .VERSION_CODE < versionCode ) {
135- // A pending intent to open the apk location url in the browser.
136- final Intent intent = new Intent (Intent .ACTION_VIEW , Uri .parse (apkLocationUrl ));
137- intent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
138- final PendingIntent pendingIntent
139- = PendingIntent .getActivity (application , 0 , intent , 0 );
131+ if (BuildConfig .VERSION_CODE >= versionCode ) {
132+ return ;
133+ }
140134
141- final String channelId = application
142- .getString (R .string .app_update_notification_channel_id );
143- final NotificationCompat .Builder notificationBuilder
144- = new NotificationCompat .Builder (application , channelId )
145- .setSmallIcon (R .drawable .ic_newpipe_update )
146- .setVisibility (NotificationCompat .VISIBILITY_PUBLIC )
147- .setContentIntent (pendingIntent )
148- .setAutoCancel (true )
149- .setContentTitle (application
150- .getString (R .string .app_update_notification_content_title ))
151- .setContentText (application
152- .getString (R .string .app_update_notification_content_text )
153- + " " + versionName );
135+ // A pending intent to open the apk location url in the browser.
136+ final Intent intent = new Intent (Intent .ACTION_VIEW , Uri .parse (apkLocationUrl ));
137+ intent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
138+ final PendingIntent pendingIntent
139+ = PendingIntent .getActivity (application , 0 , intent , 0 );
154140
155- final NotificationManagerCompat notificationManager
156- = NotificationManagerCompat .from (application );
157- notificationManager .notify (notificationId , notificationBuilder .build ());
158- }
159- }
141+ final String channelId = application
142+ .getString (R .string .app_update_notification_channel_id );
143+ final NotificationCompat .Builder notificationBuilder
144+ = new NotificationCompat .Builder (application , channelId )
145+ .setSmallIcon (R .drawable .ic_newpipe_update )
146+ .setVisibility (NotificationCompat .VISIBILITY_PUBLIC )
147+ .setContentIntent (pendingIntent )
148+ .setAutoCancel (true )
149+ .setContentTitle (application
150+ .getString (R .string .app_update_notification_content_title ))
151+ .setContentText (application
152+ .getString (R .string .app_update_notification_content_text )
153+ + " " + versionName );
160154
161- private static boolean isConnected (@ NonNull final App app ) {
162- final ConnectivityManager connectivityManager =
163- ContextCompat .getSystemService (app , ConnectivityManager .class );
164- return connectivityManager != null && connectivityManager .getActiveNetworkInfo () != null
165- && connectivityManager .getActiveNetworkInfo ().isConnected ();
155+ final NotificationManagerCompat notificationManager
156+ = NotificationManagerCompat .from (application );
157+ notificationManager .notify (2000 , notificationBuilder .build ());
166158 }
167159
168- public static boolean isGithubApk (@ NonNull final App app ) {
169- return getCertificateSHA1Fingerprint (app ).equals (GITHUB_APK_SHA1 );
160+ public static boolean isReleaseApk (@ NonNull final App app ) {
161+ return getCertificateSHA1Fingerprint (app ).equals (RELEASE_CERT_PUBLIC_KEY_SHA1 );
170162 }
171163
172164 private void checkNewVersion () throws IOException , ReCaptchaException {
@@ -175,9 +167,8 @@ private void checkNewVersion() throws IOException, ReCaptchaException {
175167 final SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences (app );
176168 final NewVersionManager manager = new NewVersionManager ();
177169
178- // Check if user has enabled/disabled update checking
179- // and if the current apk is a github one or not.
180- if (!prefs .getBoolean (app .getString (R .string .update_app_key ), true ) || !isGithubApk (app )) {
170+ // Check if the current apk is a github one or not.
171+ if (!isReleaseApk (app )) {
181172 return ;
182173 }
183174
@@ -213,6 +204,7 @@ private void handleResponse(@NonNull final Response response,
213204
214205 // Parse the json from the response.
215206 try {
207+
216208 final JsonObject githubStableObject = JsonParser .object ()
217209 .from (response .responseBody ()).getObject ("flavors" )
218210 .getObject ("github" ).getObject ("stable" );
0 commit comments