Commit ce4b0269 authored by Gabriele M's avatar Gabriele M

Show in app reboot button

Change-Id: I8d65746b58c16a7cf4a430ea29bb7b0fba1802d5
parent f4b37294
......@@ -91,7 +91,7 @@ public class UpdaterReceiver extends BroadcastReceiver {
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();
pref.edit().remove(Constants.PREF_NEEDS_REBOOT_ID).apply();
if (shouldShowUpdateFailedNotification(context)) {
pref.edit().putBoolean(Constants.PREF_INSTALL_NOTIFIED, true).apply();
......
......@@ -75,6 +75,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
INFO,
DELETE,
CANCEL_INSTALLATION,
REBOOT,
}
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);
viewHolder.mProgressText.setText(R.string.list_verifying_update);
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 {
canDelete = true;
setButtonAction(viewHolder.mAction, Action.RESUME, downloadId, !isBusy());
......@@ -370,6 +376,13 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
clickListener = enabled ? view -> getCancelInstallationDialog().show() : null;
}
break;
case REBOOT: {
button.setText(R.string.reboot);
button.setEnabled(enabled);
clickListener = enabled ?
view -> mActivity.sendBroadcast(new Intent(Intent.ACTION_REBOOT)) : null;
}
break;
default:
clickListener = null;
}
......
......@@ -20,6 +20,7 @@ import android.content.SharedPreferences;
import android.os.UpdateEngine;
import android.os.UpdateEngineCallback;
import android.support.v7.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;
import org.lineageos.updater.misc.Constants;
......@@ -117,13 +118,19 @@ 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(Constants.PREF_NEEDS_REBOOT, false);
pref.getString(Constants.PREF_NEEDS_REBOOT_ID, null) != null;
}
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(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) {
......@@ -230,8 +237,10 @@ class ABUpdateInstaller {
}
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()
.putBoolean(Constants.PREF_NEEDS_REBOOT, needsReboot)
.putString(Constants.PREF_NEEDS_REBOOT_ID, id)
.remove(PREF_INSTALLING_AB_ID)
.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_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 PREF_NEEDS_REBOOT_ID = "needs_reboot_id";
public static final String UNCRYPT_FILE_EXT = ".uncrypt";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment