Migrate CheckForNewAppVersion to JobIntentService

pull/7975/head
TacoTheDank 2022-03-03 13:24:12 -05:00
rodzic 0f175de599
commit 81fef1be19
4 zmienionych plików z 12 dodań i 13 usunięć

Wyświetl plik

@ -383,7 +383,8 @@
android:exported="false" /> android:exported="false" />
<service <service
android:name=".CheckForNewAppVersion" android:name=".CheckForNewAppVersion"
android:exported="false" /> android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE" />
<!-- opting out of sending metrics to Google in Android System WebView --> <!-- opting out of sending metrics to Google in Android System WebView -->
<meta-data android:name="android.webkit.WebView.MetricsOptOut" android:value="true" /> <meta-data android:name="android.webkit.WebView.MetricsOptOut" android:value="true" />

Wyświetl plik

@ -1,7 +1,7 @@
package org.schabi.newpipe; package org.schabi.newpipe;
import android.app.IntentService;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
@ -9,6 +9,7 @@ import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.app.JobIntentService;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat; import androidx.core.app.NotificationManagerCompat;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@ -23,14 +24,12 @@ import org.schabi.newpipe.util.ReleaseVersionUtil;
import java.io.IOException; import java.io.IOException;
public final class CheckForNewAppVersion extends IntentService { public final class CheckForNewAppVersion extends JobIntentService {
public CheckForNewAppVersion() {
super("CheckForNewAppVersion");
}
private static final boolean DEBUG = MainActivity.DEBUG; private static final boolean DEBUG = MainActivity.DEBUG;
private static final String TAG = CheckForNewAppVersion.class.getSimpleName(); private static final String TAG = CheckForNewAppVersion.class.getSimpleName();
private static final String NEWPIPE_API_URL = "https://newpipe.net/api/data.json"; private static final String NEWPIPE_API_URL = "https://newpipe.net/api/data.json";
private static final int JOB_ID = -17000;
/** /**
* Method to compare the current and latest available app version. * Method to compare the current and latest available app version.
@ -147,14 +146,13 @@ public final class CheckForNewAppVersion extends IntentService {
* </ul> * </ul>
* <b>Must not be executed</b> when the app is in background. * <b>Must not be executed</b> when the app is in background.
*/ */
public static void startNewVersionCheckService() { public static void startNewVersionCheckService(final Context context) {
final Intent intent = new Intent(App.getApp().getApplicationContext(), enqueueWork(context, CheckForNewAppVersion.class, JOB_ID,
CheckForNewAppVersion.class); new Intent(context, CheckForNewAppVersion.class));
App.getApp().startService(intent);
} }
@Override @Override
protected void onHandleIntent(@Nullable final Intent intent) { protected void onHandleWork(@Nullable final Intent intent) {
try { try {
checkNewVersion(); checkNewVersion();
} catch (final IOException e) { } catch (final IOException e) {

Wyświetl plik

@ -176,7 +176,7 @@ public class MainActivity extends AppCompatActivity {
// Start the service which is checking all conditions // Start the service which is checking all conditions
// and eventually searching for a new version. // and eventually searching for a new version.
// The service searching for a new NewPipe version must not be started in background. // The service searching for a new NewPipe version must not be started in background.
CheckForNewAppVersion.startNewVersionCheckService(); CheckForNewAppVersion.startNewVersionCheckService(app);
} }
} }

Wyświetl plik

@ -33,7 +33,7 @@ public class UpdateSettingsFragment extends BasePreferenceFragment {
// Reset the expire time. This is necessary to check for an update immediately. // Reset the expire time. This is necessary to check for an update immediately.
defaultPreferences.edit() defaultPreferences.edit()
.putLong(getString(R.string.update_expiry_key), 0).apply(); .putLong(getString(R.string.update_expiry_key), 0).apply();
startNewVersionCheckService(); startNewVersionCheckService(getContext());
} }
@Override @Override