Bug 789964 - Always use Android install wizard for updates r=mfinkle a=lsblakk
authorJames Willcox <jwillcox@mozilla.com>
Mon, 10 Sep 2012 13:51:35 -0400
changeset 109265 b0ca21422a15752a3a2e036d038a1effb29d4baf
parent 109264 a62178800150870dc2a54dba35bdf8427e9efce5
child 109266 f306fa59ad2a52d91a7da4a761fd33dc30159ea0
push id1490
push userakeybl@mozilla.com
push dateMon, 08 Oct 2012 18:29:50 +0000
treeherdermozilla-beta@f335e7dacdc1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, lsblakk
bugs789964
milestone17.0a2
Bug 789964 - Always use Android install wizard for updates r=mfinkle a=lsblakk
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
@@ -235,16 +235,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
@@ -222,17 +222,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>