7
7
import android .content .SharedPreferences ;
8
8
import android .content .pm .PackageManager ;
9
9
import android .content .pm .Signature ;
10
- import android .net .ConnectivityManager ;
11
10
import android .net .Uri ;
12
11
import android .util .Log ;
13
12
14
13
import androidx .annotation .NonNull ;
15
14
import androidx .annotation .Nullable ;
16
15
import androidx .core .app .NotificationCompat ;
17
16
import androidx .core .app .NotificationManagerCompat ;
18
- import androidx .core .content .ContextCompat ;
19
17
import androidx .core .content .pm .PackageInfoCompat ;
20
18
import androidx .preference .PreferenceManager ;
21
19
@@ -48,7 +46,8 @@ public CheckForNewAppVersion() {
48
46
private static final boolean DEBUG = MainActivity .DEBUG ;
49
47
private static final String TAG = CheckForNewAppVersion .class .getSimpleName ();
50
48
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
52
51
= "B0:2E:90:7C:1C:D6:FC:57:C3:35:F0:88:D0:8F:50:5F:94:E4:D2:15" ;
53
52
private static final String NEWPIPE_API_URL = "https://newpipe.net/api/data.json" ;
54
53
@@ -129,44 +128,37 @@ private static void compareAppVersionAndShowNotification(@NonNull final Applicat
129
128
final String versionName ,
130
129
final String apkLocationUrl ,
131
130
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
+ }
140
134
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 );
154
140
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 );
160
154
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 ());
166
158
}
167
159
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 );
170
162
}
171
163
172
164
private void checkNewVersion () throws IOException , ReCaptchaException {
@@ -175,9 +167,8 @@ private void checkNewVersion() throws IOException, ReCaptchaException {
175
167
final SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences (app );
176
168
final NewVersionManager manager = new NewVersionManager ();
177
169
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 )) {
181
172
return ;
182
173
}
183
174
@@ -213,6 +204,7 @@ private void handleResponse(@NonNull final Response response,
213
204
214
205
// Parse the json from the response.
215
206
try {
207
+
216
208
final JsonObject githubStableObject = JsonParser .object ()
217
209
.from (response .responseBody ()).getObject ("flavors" )
218
210
.getObject ("github" ).getObject ("stable" );
0 commit comments