Show in app reboot button
Change-Id: I8d65746b58c16a7cf4a430ea29bb7b0fba1802d5
This commit is contained in:
@@ -91,7 +91,7 @@ public class UpdaterReceiver extends BroadcastReceiver {
|
|||||||
pm.reboot(null);
|
pm.reboot(null);
|
||||||
} else if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
|
} else if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
|
||||||
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
pref.edit().remove(Constants.PREF_NEEDS_REBOOT).apply();
|
pref.edit().remove(Constants.PREF_NEEDS_REBOOT_ID).apply();
|
||||||
|
|
||||||
if (shouldShowUpdateFailedNotification(context)) {
|
if (shouldShowUpdateFailedNotification(context)) {
|
||||||
pref.edit().putBoolean(Constants.PREF_INSTALL_NOTIFIED, true).apply();
|
pref.edit().putBoolean(Constants.PREF_INSTALL_NOTIFIED, true).apply();
|
||||||
|
@@ -75,6 +75,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
INFO,
|
INFO,
|
||||||
DELETE,
|
DELETE,
|
||||||
CANCEL_INSTALLATION,
|
CANCEL_INSTALLATION,
|
||||||
|
REBOOT,
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
@@ -157,6 +158,11 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
setButtonAction(viewHolder.mAction, Action.INSTALL, downloadId, false);
|
setButtonAction(viewHolder.mAction, Action.INSTALL, downloadId, false);
|
||||||
viewHolder.mProgressText.setText(R.string.list_verifying_update);
|
viewHolder.mProgressText.setText(R.string.list_verifying_update);
|
||||||
viewHolder.mProgressBar.setIndeterminate(true);
|
viewHolder.mProgressBar.setIndeterminate(true);
|
||||||
|
} else if (mUpdaterController.isWaitingForReboot(downloadId)) {
|
||||||
|
setButtonAction(viewHolder.mAction, Action.REBOOT, downloadId, false);
|
||||||
|
viewHolder.mProgressText.setText(R.string.installing_update_finished);
|
||||||
|
viewHolder.mProgressBar.setIndeterminate(false);
|
||||||
|
viewHolder.mProgressBar.setProgress(100);
|
||||||
} else {
|
} else {
|
||||||
canDelete = true;
|
canDelete = true;
|
||||||
setButtonAction(viewHolder.mAction, Action.RESUME, downloadId, !isBusy());
|
setButtonAction(viewHolder.mAction, Action.RESUME, downloadId, !isBusy());
|
||||||
@@ -370,6 +376,13 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
clickListener = enabled ? view -> getCancelInstallationDialog().show() : null;
|
clickListener = enabled ? view -> getCancelInstallationDialog().show() : null;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case REBOOT: {
|
||||||
|
button.setText(R.string.reboot);
|
||||||
|
button.setEnabled(enabled);
|
||||||
|
clickListener = enabled ?
|
||||||
|
view -> mActivity.sendBroadcast(new Intent(Intent.ACTION_REBOOT)) : null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
clickListener = null;
|
clickListener = null;
|
||||||
}
|
}
|
||||||
|
@@ -20,6 +20,7 @@ import android.content.SharedPreferences;
|
|||||||
import android.os.UpdateEngine;
|
import android.os.UpdateEngine;
|
||||||
import android.os.UpdateEngineCallback;
|
import android.os.UpdateEngineCallback;
|
||||||
import android.support.v7.preference.PreferenceManager;
|
import android.support.v7.preference.PreferenceManager;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.lineageos.updater.misc.Constants;
|
import org.lineageos.updater.misc.Constants;
|
||||||
@@ -117,13 +118,19 @@ class ABUpdateInstaller {
|
|||||||
static synchronized boolean isInstallingUpdate(Context context) {
|
static synchronized boolean isInstallingUpdate(Context context) {
|
||||||
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
return pref.getString(ABUpdateInstaller.PREF_INSTALLING_AB_ID, null) != null ||
|
return pref.getString(ABUpdateInstaller.PREF_INSTALLING_AB_ID, null) != null ||
|
||||||
pref.getBoolean(Constants.PREF_NEEDS_REBOOT, false);
|
pref.getString(Constants.PREF_NEEDS_REBOOT_ID, null) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static synchronized boolean isInstallingUpdate(Context context, String downloadId) {
|
static synchronized boolean isInstallingUpdate(Context context, String downloadId) {
|
||||||
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
return downloadId.equals(pref.getString(ABUpdateInstaller.PREF_INSTALLING_AB_ID, null)) ||
|
return downloadId.equals(pref.getString(ABUpdateInstaller.PREF_INSTALLING_AB_ID, null)) ||
|
||||||
pref.getBoolean(Constants.PREF_NEEDS_REBOOT, false);
|
TextUtils.equals(pref.getString(Constants.PREF_NEEDS_REBOOT_ID, null), downloadId);
|
||||||
|
}
|
||||||
|
|
||||||
|
static synchronized boolean isWaitingForReboot(Context context, String downloadId) {
|
||||||
|
String waitingId = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
.getString(Constants.PREF_NEEDS_REBOOT_ID, null);
|
||||||
|
return TextUtils.equals(waitingId, downloadId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ABUpdateInstaller(Context context, UpdaterController updaterController) {
|
private ABUpdateInstaller(Context context, UpdaterController updaterController) {
|
||||||
@@ -230,8 +237,10 @@ class ABUpdateInstaller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void installationDone(boolean needsReboot) {
|
private void installationDone(boolean needsReboot) {
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||||
|
String id = needsReboot ? prefs.getString(PREF_INSTALLING_AB_ID, null) : null;
|
||||||
PreferenceManager.getDefaultSharedPreferences(mContext).edit()
|
PreferenceManager.getDefaultSharedPreferences(mContext).edit()
|
||||||
.putBoolean(Constants.PREF_NEEDS_REBOOT, needsReboot)
|
.putString(Constants.PREF_NEEDS_REBOOT_ID, id)
|
||||||
.remove(PREF_INSTALLING_AB_ID)
|
.remove(PREF_INSTALLING_AB_ID)
|
||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
|
@@ -27,7 +27,7 @@ public final class Constants {
|
|||||||
public static final String PREF_AUTO_UPDATES_CHECK = "auto_updates_check";
|
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_AUTO_DELETE_UPDATES = "auto_delete_updates";
|
||||||
public static final String PREF_MOBILE_DATA_WARNING = "pref_mobile_data_warning";
|
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 PREF_NEEDS_REBOOT_ID = "needs_reboot_id";
|
||||||
|
|
||||||
public static final String UNCRYPT_FILE_EXT = ".uncrypt";
|
public static final String UNCRYPT_FILE_EXT = ".uncrypt";
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user