Allow to cancel ongoing installations
Change-Id: I46884b42b6e3f87fbee99a23f538cec990b3b873
This commit is contained in:
9
res/drawable/ic_cancel.xml
Normal file
9
res/drawable/ic_cancel.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2zM17,15.59L15.59,17 12,13.41 8.41,17 7,15.59 10.59,12 7,8.41 8.41,7 12,10.59 15.59,7 17,8.41 13.41,12 17,15.59z"/>
|
||||
</vector>
|
@@ -89,6 +89,7 @@
|
||||
<string name="action_description_install">Install update</string>
|
||||
<string name="action_description_info">Show information</string>
|
||||
<string name="action_description_delete">Delete update</string>
|
||||
<string name="action_description_cancel">Cancel installation</string>
|
||||
|
||||
<string name="confirm_delete_dialog_title">Delete file</string>
|
||||
<string name="confirm_delete_dialog_message">Delete the selected update file?</string>
|
||||
@@ -97,6 +98,8 @@
|
||||
<string name="apply_update_dialog_message">You are about to upgrade to <xliff:g id="update_name">%1$s</xliff:g>.\n\nIf you press <xliff:g id="ok">%2$s</xliff:g>, the device will restart itself in recovery mode to install the update.\n\nNote: This feature requires a compatible Recovery or updates will need to be installed manually.</string>
|
||||
<string name="apply_update_dialog_message_ab">You are about to upgrade to <xliff:g id="update_name">%1$s</xliff:g>.\n\nIf you press <xliff:g id="ok">%2$s</xliff:g>, the device will begin installing in the background.\n\nOnce completed, you will be prompted to reboot.</string>
|
||||
|
||||
<string name="cancel_installation_dialog_message">Cancel the installation?</string>
|
||||
|
||||
<string name="label_download_url">Download URL</string>
|
||||
<string name="toast_download_url_copied">URL Copied</string>
|
||||
|
||||
|
@@ -41,6 +41,7 @@ import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.lineageos.updater.controller.Controller;
|
||||
import org.lineageos.updater.controller.UpdaterService;
|
||||
import org.lineageos.updater.misc.BuildInfoUtils;
|
||||
import org.lineageos.updater.misc.Constants;
|
||||
import org.lineageos.updater.misc.PermissionsUtils;
|
||||
@@ -74,6 +75,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
||||
INSTALL,
|
||||
INFO,
|
||||
DELETE,
|
||||
CANCEL_INSTALLATION,
|
||||
}
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
@@ -157,7 +159,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
||||
update.getProgress() / 100.f);
|
||||
viewHolder.mProgressPercentage.setText(percentage);
|
||||
} else if (mUpdaterController.isInstallingUpdate(downloadId)) {
|
||||
setButtonAction(viewHolder.mAction, Action.INSTALL, downloadId, false);
|
||||
setButtonAction(viewHolder.mAction, Action.CANCEL_INSTALLATION, downloadId, true);
|
||||
viewHolder.mProgressText.setText(R.string.list_installing_update);
|
||||
viewHolder.mProgressBar.setProgress(update.getInstallProgress());
|
||||
String percentage = NumberFormat.getPercentInstance().format(
|
||||
@@ -396,6 +398,19 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
||||
};
|
||||
}
|
||||
break;
|
||||
case CANCEL_INSTALLATION: {
|
||||
button.setImageResource(R.drawable.ic_cancel);
|
||||
button.setContentDescription(
|
||||
mActivity.getString(R.string.action_description_cancel));
|
||||
button.setEnabled(enabled);
|
||||
clickListener = !enabled ? null : new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
getCancelInstallationDialog().show();
|
||||
}
|
||||
};
|
||||
}
|
||||
break;
|
||||
default:
|
||||
clickListener = null;
|
||||
}
|
||||
@@ -478,6 +493,21 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
||||
.setNegativeButton(android.R.string.cancel, null);
|
||||
}
|
||||
|
||||
private AlertDialog.Builder getCancelInstallationDialog() {
|
||||
return new AlertDialog.Builder(mActivity)
|
||||
.setMessage(R.string.cancel_installation_dialog_message)
|
||||
.setPositiveButton(android.R.string.ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent intent = new Intent(mActivity, UpdaterService.class);
|
||||
intent.setAction(UpdaterService.ACTION_INSTALL_STOP);
|
||||
mActivity.startService(intent);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null);
|
||||
}
|
||||
|
||||
private void stopActionMode() {
|
||||
if (mActionMode != null) {
|
||||
mActionMode.finish();
|
||||
|
@@ -205,4 +205,25 @@ class ABUpdateInstaller {
|
||||
.remove(PREF_INSTALLING_AB_ID)
|
||||
.apply();
|
||||
}
|
||||
|
||||
public boolean cancel() {
|
||||
if (!isInstallingUpdate(mContext)) {
|
||||
Log.e(TAG, "cancel: Not installing any update");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mUpdateEngine == null) {
|
||||
Log.e(TAG, "Not connected to update engine");
|
||||
return false;
|
||||
}
|
||||
|
||||
mUpdateEngine.cancel();
|
||||
installationDone();
|
||||
|
||||
mUpdaterController.getActualUpdate(mDownloadId)
|
||||
.setStatus(UpdateStatus.INSTALLATION_CANCELLED);
|
||||
mUpdaterController.notifyUpdateChange(mDownloadId);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -55,6 +55,7 @@ public class UpdaterService extends Service {
|
||||
public static final String EXTRA_DOWNLOAD_ID = "extra_download_id";
|
||||
public static final String EXTRA_DOWNLOAD_CONTROL = "extra_download_control";
|
||||
public static final String ACTION_INSTALL_UPDATE = "action_install_update";
|
||||
public static final String ACTION_INSTALL_STOP = "action_install_stop";
|
||||
|
||||
public static final int DOWNLOAD_RESUME = 0;
|
||||
public static final int DOWNLOAD_PAUSE = 1;
|
||||
@@ -213,6 +214,12 @@ public class UpdaterService extends Service {
|
||||
Log.e(TAG, "Could not install update", e);
|
||||
// TODO: user facing message
|
||||
}
|
||||
} else if (ACTION_INSTALL_STOP.equals(intent.getAction())) {
|
||||
if (ABUpdateInstaller.isInstallingUpdate(this)) {
|
||||
ABUpdateInstaller installer = new ABUpdateInstaller(this, mUpdaterController);
|
||||
installer.reconnect();
|
||||
installer.cancel();
|
||||
}
|
||||
}
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
Reference in New Issue
Block a user