Ask for confirmation before installing updates
Since there's no quick and clean way to show a dialog from a serivice, don't allow to install updates from the notification.
This commit is contained in:
@@ -79,4 +79,8 @@
|
|||||||
|
|
||||||
<string name="confirm_delete_dialog_title">Delete file</string>
|
<string name="confirm_delete_dialog_title">Delete file</string>
|
||||||
<string name="confirm_delete_dialog_message">Delete the selected update file?</string>
|
<string name="confirm_delete_dialog_message">Delete the selected update file?</string>
|
||||||
|
|
||||||
|
<string name="apply_update_dialog_title">Apply update</string>
|
||||||
|
<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>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -21,6 +21,7 @@ import android.support.v7.app.AlertDialog;
|
|||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.text.format.Formatter;
|
import android.text.format.Formatter;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -34,6 +35,7 @@ import org.lineageos.updater.misc.BuildInfoUtils;
|
|||||||
import org.lineageos.updater.misc.StringGenerator;
|
import org.lineageos.updater.misc.StringGenerator;
|
||||||
import org.lineageos.updater.misc.Utils;
|
import org.lineageos.updater.misc.Utils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -300,7 +302,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
|
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Utils.triggerUpdate(mContext, downloadId);
|
getInstallDialog(downloadId).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -331,4 +333,36 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AlertDialog.Builder getInstallDialog(final String downloadId) {
|
||||||
|
UpdateDownload update = mUpdaterController.getUpdate(downloadId);
|
||||||
|
int resId;
|
||||||
|
try {
|
||||||
|
if (Utils.isABUpdate(update.getFile())) {
|
||||||
|
resId = R.string.apply_update_dialog_message_ab;
|
||||||
|
} else {
|
||||||
|
resId = R.string.apply_update_dialog_message;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(TAG, "Could not determine the type of the update");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String buildDate = StringGenerator.getDateLocalized(mContext,
|
||||||
|
DateFormat.MEDIUM, update.getTimestamp());
|
||||||
|
String buildInfoText = mContext.getString(R.string.list_build_version_date,
|
||||||
|
BuildInfoUtils.getBuildVersion(), buildDate);
|
||||||
|
return new AlertDialog.Builder(mContext)
|
||||||
|
.setTitle(R.string.apply_update_dialog_title)
|
||||||
|
.setMessage(mContext.getString(resId, buildInfoText,
|
||||||
|
mContext.getString(android.R.string.ok)))
|
||||||
|
.setPositiveButton(android.R.string.ok,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
Utils.triggerUpdate(mContext, downloadId);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(android.R.string.cancel, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -269,9 +269,6 @@ public class UpdaterService extends Service {
|
|||||||
mNotificationBuilder.setProgress(100, 100, false);
|
mNotificationBuilder.setProgress(100, 100, false);
|
||||||
String text = getString(R.string.download_completed_notification);
|
String text = getString(R.string.download_completed_notification);
|
||||||
mNotificationStyle.bigText(text);
|
mNotificationStyle.bigText(text);
|
||||||
mNotificationBuilder.addAction(R.drawable.ic_tab_install,
|
|
||||||
getString(R.string.install_button),
|
|
||||||
getInstallPendingIntent(update.getDownloadId()));
|
|
||||||
mNotificationBuilder.setTicker(text);
|
mNotificationBuilder.setTicker(text);
|
||||||
mNotificationBuilder.setOngoing(false);
|
mNotificationBuilder.setOngoing(false);
|
||||||
mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build());
|
mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build());
|
||||||
@@ -384,14 +381,6 @@ public class UpdaterService extends Service {
|
|||||||
PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PendingIntent getInstallPendingIntent(String downloadId) {
|
|
||||||
final Intent intent = new Intent(this, UpdaterService.class);
|
|
||||||
intent.setAction(ACTION_INSTALL_UPDATE);
|
|
||||||
intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId);
|
|
||||||
return PendingIntent.getService(this, 0, intent,
|
|
||||||
PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
private PendingIntent getRebootPendingIntent() {
|
private PendingIntent getRebootPendingIntent() {
|
||||||
final Intent intent = new Intent(this, UpdaterReceiver.class);
|
final Intent intent = new Intent(this, UpdaterReceiver.class);
|
||||||
intent.setAction(UpdaterReceiver.ACTION_INSTALL_REBOOT);
|
intent.setAction(UpdaterReceiver.ACTION_INSTALL_REBOOT);
|
||||||
|
Reference in New Issue
Block a user