Bug 1105590 - Wait for distribution intent to arrive. r=mfinkle, a=lmandel
authorRichard Newman <rnewman@mozilla.com>
Fri, 28 Nov 2014 12:30:38 -0800
changeset 227464 ef19db469965168d18e7025da371b73867932917
parent 227463 8e81c96d07495946c2bced18a28dca1f0b1b2ea2
child 227467 0fcb28a327609e4e693e000bdbdbe3b32ef57c4f
push id604
push userryanvm@gmail.com
push dateWed, 17 Dec 2014 16:11:19 +0000
treeherdermozilla-release@ef19db469965 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, lmandel
bugs1105590
milestone34.0
Bug 1105590 - Wait for distribution intent to arrive. r=mfinkle, a=lmandel
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();