Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 99cd083e authored by Aayush Gupta's avatar Aayush Gupta
Browse files

Updater: UpdatesCheckReceiver: Migrate to setExactAndAllowWhileIdle

parent 1245486b
Loading
Loading
Loading
Loading
+4 −14
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
                try {
                    if (json.exists() && Utils.checkForNewUpdates(jsonNew)) {
                        showNotification(context);
                        updateRepeatingUpdatesCheck(context);
                        scheduleRepeatingUpdatesCheck(context);
                    }
                    //noinspection ResultOfMethodCallIgnored
                    jsonNew.renameTo(json);
@@ -149,11 +149,6 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
        return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
    }

    public static void updateRepeatingUpdatesCheck(Context context) {
        cancelRepeatingUpdatesCheck(context);
        scheduleRepeatingUpdatesCheck(context);
    }

    public static void scheduleRepeatingUpdatesCheck(Context context) {
        if (!Utils.isUpdateCheckEnabled(context)) {
            return;
@@ -161,8 +156,8 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {

        PendingIntent updateCheckIntent = getRepeatingUpdatesCheckIntent(context);
        AlarmManager alarmMgr = context.getSystemService(AlarmManager.class);
        alarmMgr.setRepeating(AlarmManager.RTC, System.currentTimeMillis() +
                Utils.getUpdateCheckInterval(context), Utils.getUpdateCheckInterval(context),
        alarmMgr.setExactAndAllowWhileIdle(AlarmManager.RTC,
                System.currentTimeMillis() + Utils.getUpdateCheckInterval(context),
                updateCheckIntent);

        Date nextCheckDate = new Date(System.currentTimeMillis() +
@@ -170,11 +165,6 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
        Log.d(TAG, "Setting automatic updates check: " + nextCheckDate);
    }

    public static void cancelRepeatingUpdatesCheck(Context context) {
        AlarmManager alarmMgr = context.getSystemService(AlarmManager.class);
        alarmMgr.cancel(getRepeatingUpdatesCheckIntent(context));
    }

    private static PendingIntent getUpdatesCheckIntent(Context context) {
        Intent intent = new Intent(context, UpdatesCheckReceiver.class);
        intent.setAction(ONESHOT_CHECK_ACTION);
@@ -185,7 +175,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
        long millisToNextCheck = AlarmManager.INTERVAL_HOUR * 2;
        PendingIntent updateCheckIntent = getUpdatesCheckIntent(context);
        AlarmManager alarmMgr = context.getSystemService(AlarmManager.class);
        alarmMgr.set(AlarmManager.ELAPSED_REALTIME,
        alarmMgr.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME,
                SystemClock.elapsedRealtime() + millisToNextCheck,
                updateCheckIntent);