Bug 789964 - Always use Android install wizard for updates r=mfinkle
authorJames Willcox <jwillcox@mozilla.com>
Mon, 10 Sep 2012 13:51:35 -0400
changeset 104712 c675ef1daee1f0f27fc0f860af542be3afe9f9eb
parent 104711 bc546b6fe5b52b157cc9f649f381bbe57f838943
child 104713 9c8189bcb3900ece9741b32af3b9ba2e3ed2fc5d
push id14642
push userjwillcox@mozilla.com
push dateMon, 10 Sep 2012 17:54:52 +0000
treeherdermozilla-inbound@c675ef1daee1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs789964
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 789964 - Always use Android install wizard for updates r=mfinkle
mobile/android/base/UpdateService.java
mobile/android/base/locales/en-US/android_strings.dtd
mobile/android/base/strings.xml.in
--- a/mobile/android/base/UpdateService.java
+++ b/mobile/android/base/UpdateService.java
@@ -229,18 +229,17 @@ public class UpdateService extends Inten
         File pkg = downloadUpdatePackage(info, hasFlag(flags, UpdateServiceHelper.FLAG_OVERWRITE_EXISTING));
         if (pkg == null)
             return;
 
         Log.i(LOGTAG, "have update package at " + pkg);
 
         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
             Notification notification = new Notification(R.drawable.icon, getResources().getString(R.string.updater_apply_ticker), System.currentTimeMillis());
 
             Intent notificationIntent = new Intent(UpdateServiceHelper.ACTION_APPLY_UPDATE);
             notificationIntent.setClass(this, UpdateService.class);
             notificationIntent.putExtra(UpdateServiceHelper.EXTRA_PACKAGE_PATH_NAME, pkg.getAbsolutePath());
@@ -485,75 +484,16 @@ public class UpdateService extends Inten
 
         Log.i(LOGTAG, "Verifying package: " + updateFile);
 
         if (!verifyDownloadedPackage(updateFile)) {
             Log.e(LOGTAG, "Not installing update, failed verification");
             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);
         startActivity(intent);
     }
 
     private String getLastBuildID() {
         return mPrefs.getString(KEY_LAST_BUILDID, null);
@@ -586,39 +526,16 @@ public class UpdateService extends Inten
     private void saveUpdateInfo(UpdateInfo info) {
         SharedPreferences.Editor editor = mPrefs.edit();
         editor.putString(KEY_LAST_BUILDID, info.buildID);
         editor.putString(KEY_LAST_HASH_FUNCTION, info.hashFunction);
         editor.putString(KEY_LAST_HASH_VALUE, info.hashValue);
         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;
         public String hashFunction;
         public String hashValue;
         public int size;
 
         private boolean isNonEmpty(String s) {
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -236,16 +236,8 @@ just addresses the organization to follo
 <!ENTITY updater_downloading_ticker_failed "Failed to download &brandShortName; update&#8230;">
 <!ENTITY updater_downloading_select "Select to apply update when complete.">
 <!ENTITY updater_downloading_retry "Select to retry update download.">
 <!ENTITY updater_downloading_willapply "Waiting for download to complete.">
 
 <!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.">
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -223,17 +223,9 @@
   <string name="updater_downloading_select">&updater_downloading_select;</string>
   <string name="updater_downloading_retry">&updater_downloading_retry;</string>
   <string name="updater_downloading_willapply">&updater_downloading_willapply;</string>
   
   <string name="updater_apply_title">&updater_apply_title;</string>
   <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>