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
--- 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.
*/