Bug 978143 - Propagate APK install cancellation back to webpage. r=wesj
authorMartyn Haigh <martyn.haigh@gmail.com>
Thu, 05 Jun 2014 02:21:00 -0400
changeset 206182 31db3f3b1107fb0549b26ffb94ddaa17f55fa365
parent 206181 24f124582f70a64103835464160441bc0a449c69
child 206183 e157171a4df1bd8e28efc425da03436fa73f333b
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs978143
milestone32.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 978143 - Propagate APK install cancellation back to webpage. r=wesj
mobile/android/base/webapp/EventListener.java
mobile/android/modules/WebappManager.jsm
--- a/mobile/android/base/webapp/EventListener.java
+++ b/mobile/android/base/webapp/EventListener.java
@@ -178,17 +178,17 @@ public class EventListener implements Na
                 if (proc.processName.equals(targetProcessName)) {
                     android.os.Process.killProcess(proc.pid);
                     break;
                 }
             }
         }
     }
 
-    public static void installApk(final Activity context, NativeJSObject message, EventCallback callback) {
+    public static void installApk(final Activity context, NativeJSObject message, final EventCallback callback) {
         final JSONObject messageData;
 
         // We get the manifest url out of javascript here so we can use it as a checksum
         // in a minute, when a package has been installed.
         String manifestUrl = null;
         String filePath = null;
 
         try {
@@ -232,16 +232,17 @@ public class EventListener implements Na
                         receiver.cleanup();
                     } catch (java.lang.IllegalArgumentException e) {
                         // IllegalArgumentException happens because resultCode is RESULT_CANCELED
                         // when the user presses the Done button in the install confirmation dialog,
                         // even though the install has been successful (and InstallListener already
                         // unregistered the receiver).
                         Log.e(LOGTAG, "error unregistering install receiver: ", e);
                     }
+                    callback.sendError("APK installation cancelled by user");
                 }
             }
         });
     }
 
     private static final int DEFAULT_VERSION_CODE = -1;
 
     public static JSONObject getApkVersions(Activity context, String[] packageNames) {
--- a/mobile/android/modules/WebappManager.jsm
+++ b/mobile/android/modules/WebappManager.jsm
@@ -495,16 +495,22 @@ this.WebappManager = {
           app: apk.app,
           // TODO: figure out why Webapps:InstallApk needs the "from" property.
           from: apk.app.installOrigin,
         };
         sendMessageToJava({
           type: "Webapps:InstallApk",
           filePath: apk.filePath,
           data: msg,
+        }, (data, error) => {
+          if (!!error) {
+            // There's no page to report back to so drop the error.
+            // TODO: we should notify the user about this failure.
+            debug("APK install failed : " + returnError);
+          }
         });
       }
     } else {
       // The user cancelled the notification, so remove the downloaded APKs.
       for (let apk of downloadedApks) {
         try {
           yield OS.file.remove(apk.filePath);
         } catch(ex) {