Bug 1105590 - Wait for distribution intent to arrive. r=mfinkle, a=lsblakk
authorRichard Newman <rnewman@mozilla.com>
Fri, 28 Nov 2014 12:30:38 -0800
changeset 234111 f11fea48f8441d5737f6c4ab085429b60a1bfeb0
parent 234106 fdb3e0b2cb184db5c6948fa2404bfbbd4c052bcb
child 234112 f6726a81435109887c163c6afa89136af3ea8fe2
push id1
push usersledru@mozilla.com
push dateThu, 04 Dec 2014 17:57:20 +0000
reviewersmfinkle, lsblakk
bugs1105590
milestone35.0
Bug 1105590 - Wait for distribution intent to arrive. r=mfinkle, a=lsblakk
mobile/android/base/distribution/Distribution.java
--- a/mobile/android/base/distribution/Distribution.java
+++ b/mobile/android/base/distribution/Distribution.java
@@ -99,16 +99,18 @@ public class Distribution {
     private static final int CODE_CATEGORY_FETCH_SOCKET_ERROR = 11;
     private static final int CODE_CATEGORY_FETCH_SSL_ERROR = 12;
     private static final int CODE_CATEGORY_FETCH_NON_SUCCESS_RESPONSE = 13;
     private static final int CODE_CATEGORY_FETCH_INVALID_CONTENT_TYPE = 14;
 
     // Corresponds to the high value in Histograms.json.
     private static final long MAX_DOWNLOAD_TIME_MSEC = 40000;    // 40 seconds.
 
+    // Wait just a little while for the system to send a referrer intent after install.
+    private static final long DELAY_WAIT_FOR_REFERRER_MSEC = 400;
 
 
     /**
      * Used as a drop-off point for ReferrerReceiver. Checked when we process
      * first-run distribution.
      *
      * This is `protected` so that test code can clear it between runs.
      */
@@ -380,17 +382,26 @@ public class Distribution {
     /**
      * If applicable, download and select the distribution specified in
      * the referrer intent.
      *
      * @return true if a referrer-supplied distribution was selected.
      */
     private boolean checkIntentDistribution() {
         if (referrer == null) {
-            return false;
+            // Wait a predetermined time and try again.
+            // Just block the thread, because it's the simplest solution.
+            try {
+                Thread.sleep(DELAY_WAIT_FOR_REFERRER_MSEC);
+            } catch (InterruptedException e) {
+                // Good enough.
+            }
+            if (referrer == null) {
+                return false;
+            }
         }
 
         URI uri = getReferredDistribution(referrer);
         if (uri == null) {
             return false;
         }
 
         long start = SystemClock.uptimeMillis();