Bug 1323759 - Download distribution file by Install-Intent draft
authorJulian_Chu <walkingice0204@gmail.com>
Thu, 15 Dec 2016 13:18:57 +0800
changeset 450189 77293ed43779c82aa6d99f8a88237435782dc3d3
parent 450188 9a369d76b8a4d2c7b5a473a6926f1f31d681f3f2
child 539683 0fa9a1c8bc612cd0481d6e60a2169ebf27ad27a2
push id38779
push userbmo:walkingice0204@gmail.com
push dateFri, 16 Dec 2016 03:36:33 +0000
bugs1323759
milestone53.0a1
Bug 1323759 - Download distribution file by Install-Intent When Install-intent with Referrer is sent to BroadcastReceiver, it calls Distribution.OnReceivedReferrer to run a task in background-thread. When the task is running, the Distribution singleton-instance might be initialized, might be not. We can distinguish the situation by checking its state, then give different behavior. MozReview-Commit-ID: CmgC3s1UT8z
mobile/android/base/java/org/mozilla/gecko/distribution/Distribution.java
--- a/mobile/android/base/java/org/mozilla/gecko/distribution/Distribution.java
+++ b/mobile/android/base/java/org/mozilla/gecko/distribution/Distribution.java
@@ -289,41 +289,50 @@ public class Distribution {
     public static void onReceivedReferrer(final Context context, final ReferrerDescriptor ref) {
         // Track the referrer object for distribution handling.
         referrer = ref;
 
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
                 final Distribution distribution = Distribution.getInstance(context);
+                if (distribution.state == STATE_SET) {
+                    Log.i(LOGTAG, "Got installation intent, however already set distribution");
+                    return;
+                }
 
-                // This will bail if we aren't delayed, or we already have a distribution.
                 distribution.processDelayedReferrer(ref);
             }
         });
     }
 
     /**
      * Handle a referrer intent that arrives after first use of the distribution.
      */
     private void processDelayedReferrer(final ReferrerDescriptor ref) {
         ThreadUtils.assertOnBackgroundThread();
-        if (state != STATE_NONE) {
-            return;
-        }
 
         Log.i(LOGTAG, "Processing delayed referrer.");
 
+        // To download distribution file and put it into data directory
         if (!checkIntentDistribution(ref)) {
             // Oh well. No sense keeping these tasks around.
             this.onLateReady.clear();
             return;
         }
 
-        updateDistributionState(STATE_SET, false);
+        if (this.state == STATE_UNKNOWN) {
+            // The distribution instance have not been initialized, therefore stats is UNKNOWN.
+            // Only to download distribution file to make sure Distribution.doInit will find it well.
+            Log.d(LOGTAG, "distribution file downloaded.");
+        } else if (this.state == STATE_NONE) {
+            // Install-intent comes after initialization.
+            // Need to update state and notify change happens.
+            updateDistributionState(STATE_SET, false);
+        }
     }
 
     /**
      * Helper to grab a file in the distribution directory.
      *
      * Returns null if there is no distribution directory or the file
      * doesn't exist. Ensures init first.
      */