Bug 789964 - Always use Android install wizard for updates r=mfinkle

This commit is contained in:
James Willcox 2012-09-10 13:51:35 -04:00
Родитель 492ab13e09
Коммит 69aacaaaa4
3 изменённых файлов: 1 добавлений и 100 удалений

Просмотреть файл

@ -234,8 +234,7 @@ public class UpdateService extends IntentService {
saveUpdateInfo(info);
// If we have root, we always apply the update immediately because it happens in the background
if (mApplyImmediately || checkRoot()) {
if (mApplyImmediately) {
applyUpdate(pkg);
} else {
// Prompt to apply the update
@ -490,65 +489,6 @@ public class UpdateService extends IntentService {
return;
}
if (checkRoot())
applyUpdateWithRoot(updateFile);
else
applyUpdateWithActivity(updateFile);
}
private void applyUpdateWithRoot(File updateFile) {
mNotificationManager.cancel(NOTIFICATION_ID);
Notification notification = new Notification(R.drawable.icon, getResources().getString(R.string.updater_installing_ticker), System.currentTimeMillis());
notification.flags = Notification.FLAG_NO_CLEAR;
Intent notificationIntent = new Intent("org.mozilla.gecko.ACTION_NOOP");
notificationIntent.setClass(this, UpdateService.class);
PendingIntent contentIntent = PendingIntent.getService(this, 0, notificationIntent, 0);
notification.flags = Notification.FLAG_NO_CLEAR;
notification.setLatestEventInfo(this, getResources().getString(R.string.updater_installing_title),
getResources().getString(R.string.updater_installing_text),
contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, notification);
int result = runAsRoot("pm install " + updateFile.getAbsolutePath());
Log.i(LOGTAG, "install result = " + result);
updateFile.delete();
int tickerText = result == 0 ? R.string.updater_installing_ticker_success : R.string.updater_installing_ticker_fail;
int contentText = result == 0 ? R.string.updater_installing_text_success : R.string.updater_installing_text_fail;
mNotificationManager.cancel(NOTIFICATION_ID);
notification = new Notification(R.drawable.icon, getResources().getString(tickerText), System.currentTimeMillis());
notification.flags = Notification.FLAG_NO_CLEAR;
notificationIntent = new Intent(Intent.ACTION_MAIN);
notificationIntent.setClassName(getPackageName(), getPackageName() + ".App");
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.flags = Notification.FLAG_NO_CLEAR;
notification.setLatestEventInfo(this, getResources().getString(R.string.updater_installing_title),
getResources().getString(result == 0 ? R.string.updater_installing_text_success : R.string.updater_installing_text_fail),
contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, notification);
notification.setLatestEventInfo(this, getResources().getString(R.string.updater_installing_title),
getResources().getString(result == 0 ? R.string.updater_installing_text_success : R.string.updater_installing_text_fail),
contentIntent);
notification.flags = Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(NOTIFICATION_ID, notification);
}
private void applyUpdateWithActivity(File updateFile) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(updateFile), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@ -591,29 +531,6 @@ public class UpdateService extends IntentService {
editor.commit();
}
private int runAsRoot(String command) {
Process p = null;
try {
p = Runtime.getRuntime().exec("su");
OutputStream output = p.getOutputStream();
output.write(command.getBytes());
output.write(new String("; exit\n").getBytes());
output.flush();
p.waitFor();
return p.exitValue();
} catch (Exception e) {
return -1;
} finally {
if (p != null)
p.destroy();
}
}
private boolean checkRoot() {
return runAsRoot("echo woooooo") == 0;
}
private class UpdateInfo {
public URL url;
public String buildID;

Просмотреть файл

@ -241,11 +241,3 @@ just addresses the organization to follow, e.g. "This site is run by " -->
<!ENTITY updater_apply_title "&brandShortName;">
<!ENTITY updater_apply_ticker "&brandShortName; update available&#8230;">
<!ENTITY updater_apply_select "Select to apply downloaded update.">
<!ENTITY updater_installing_title "&brandShortName;">
<!ENTITY updater_installing_ticker "Updating &brandShortName;&#8230;">
<!ENTITY updater_installing_ticker_success "Successfully updated &brandShortName;">
<!ENTITY updater_installing_ticker_fail "Failed to update &brandShortName;">
<!ENTITY updater_installing_text "Installing update&#8230;">
<!ENTITY updater_installing_text_success "Succesfully updated.">
<!ENTITY updater_installing_text_fail "Failed to install update.">

Просмотреть файл

@ -228,12 +228,4 @@
<string name="updater_apply_ticker">&updater_apply_ticker;</string>
<string name="updater_apply_select">&updater_apply_select;</string>
<string name="updater_installing_title">&updater_installing_title;</string>
<string name="updater_installing_ticker">&updater_installing_ticker;</string>
<string name="updater_installing_ticker_success">&updater_installing_ticker_success;</string>
<string name="updater_installing_ticker_fail">&updater_installing_ticker_fail;</string>
<string name="updater_installing_text">&updater_installing_text;</string>
<string name="updater_installing_text_success">&updater_installing_text_success;</string>
<string name="updater_installing_text_fail">&updater_installing_text_fail;</string>
</resources>