Clear NEEDS_REBOOT preference on reboot

UpdateEngine doesn't send an initial notification to bound client
if the last status is not known, so clear the preference when we
detect that the device has been rebooted.

Change-Id: Ib15dff5fa8ac9ec07a68018a83683cc561fd3e85
This commit is contained in:
Gabriele M
2018-03-24 16:17:19 +01:00
parent eecdf389ef
commit a409a4a03d
4 changed files with 16 additions and 5 deletions

View File

@@ -35,7 +35,11 @@
<service android:name=".controller.UpdaterService" />
<service android:name=".ExportUpdateService" />
<receiver android:name=".UpdaterReceiver" android:exported="false" />
<receiver android:name=".UpdaterReceiver" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<receiver android:name=".UpdatesCheckReceiver">
<intent-filter>

View File

@@ -18,7 +18,11 @@ package org.lineageos.updater;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.PowerManager;
import android.support.v7.preference.PreferenceManager;
import org.lineageos.updater.misc.Constants;
public class UpdaterReceiver extends BroadcastReceiver {
@@ -30,6 +34,9 @@ public class UpdaterReceiver extends BroadcastReceiver {
if (ACTION_INSTALL_REBOOT.equals(intent.getAction())) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
pm.reboot(null);
} else if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
pref.edit().remove(Constants.PREF_NEEDS_REBOOT).apply();
}
}
}

View File

@@ -42,7 +42,6 @@ class ABUpdateInstaller {
private static final String TAG = "ABUpdateInstaller";
private static final String PREF_INSTALLING_AB_ID = "installing_ab_id";
private static final String PREF_NEEDS_REBOOT = "needs_reboot";
private static ABUpdateInstaller sInstance = null;
@@ -119,13 +118,13 @@ class ABUpdateInstaller {
static synchronized boolean isInstallingUpdate(Context context) {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
return pref.getString(ABUpdateInstaller.PREF_INSTALLING_AB_ID, null) != null ||
pref.getBoolean(ABUpdateInstaller.PREF_NEEDS_REBOOT, false);
pref.getBoolean(Constants.PREF_NEEDS_REBOOT, false);
}
static synchronized boolean isInstallingUpdate(Context context, String downloadId) {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
return downloadId.equals(pref.getString(ABUpdateInstaller.PREF_INSTALLING_AB_ID, null)) ||
pref.getBoolean(ABUpdateInstaller.PREF_NEEDS_REBOOT, false);
pref.getBoolean(Constants.PREF_NEEDS_REBOOT, false);
}
private ABUpdateInstaller(Context context, UpdaterController updaterController) {
@@ -233,7 +232,7 @@ class ABUpdateInstaller {
private void installationDone(boolean needsReboot) {
PreferenceManager.getDefaultSharedPreferences(mContext).edit()
.putBoolean(PREF_NEEDS_REBOOT, needsReboot)
.putBoolean(Constants.PREF_NEEDS_REBOOT, needsReboot)
.remove(PREF_INSTALLING_AB_ID)
.apply();
}

View File

@@ -27,6 +27,7 @@ public final class Constants {
public static final String PREF_AUTO_UPDATES_CHECK = "auto_updates_check";
public static final String PREF_AUTO_DELETE_UPDATES = "auto_delete_updates";
public static final String PREF_MOBILE_DATA_WARNING = "pref_mobile_data_warning";
public static final String PREF_NEEDS_REBOOT = "needs_reboot";
public static final String UNCRYPT_FILE_EXT = ".uncrypt";