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

Commit 5125ed8e authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

Updater: UpdatesCheckReceiver: Make exact alarm work every time

Change-Id: Id950e6c4f44a445f78be60416e159045d120152e
parent 534048ee
Loading
Loading
Loading
Loading
+10 −13
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {

        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            Utils.cleanupDownloadsDir(context);
            cnState.setNetworkCallbackActive(false);
        }

        final SharedPreferences preferences =
@@ -66,11 +67,9 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
            return;
        }

        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            // Set a repeating alarm on boot to check for new updates once per day
            scheduleRepeatingUpdatesCheck(context);
            cnState.setNetworkCallbackActive(false);
        }
        // Exact alarms does not support repeating, so update to make it
        // work like repeating alarms. To check for update at the exact time.
        updateRepeatingUpdatesCheck(context);

        if (!Utils.isNetworkAvailable(context)) {
            if (!cnState.isNetworkCallbackActive()) {
@@ -168,12 +167,10 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {

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

        Date nextCheckDate = new Date(System.currentTimeMillis() +
                Utils.getUpdateCheckInterval(context));
        Date nextCheckDate = new Date(nextCheck);
        Log.d(TAG, "Setting automatic updates check: " + nextCheckDate);
    }

@@ -192,11 +189,11 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
        long millisToNextCheck = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
        PendingIntent updateCheckIntent = getUpdatesCheckIntent(context);
        AlarmManager alarmMgr = context.getSystemService(AlarmManager.class);
        long nextCheck = SystemClock.elapsedRealtime() + millisToNextCheck;
        alarmMgr.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME,
                SystemClock.elapsedRealtime() + millisToNextCheck,
                updateCheckIntent);
                nextCheck, updateCheckIntent);

        Date nextCheckDate = new Date(System.currentTimeMillis() + millisToNextCheck);
        Date nextCheckDate = new Date(nextCheck);
        Log.d(TAG, "Setting one-shot updates check: " + nextCheckDate);
    }