Bug 1633568 - AdjustHelper can inform more listeners about Attribution changes. r=Grisha, a=RyanVM FIREFOX_ESR_68_8_X_RELBRANCH
authorPetru-Mugurel Lingurar <petru.lingurar@softvision.ro>
Wed, 06 May 2020 14:52:02 +0000
branchFIREFOX_ESR_68_8_X_RELBRANCH
changeset 524813 9c08bb26d3af807efc3f1d80c067a0d3c7a2f57b
parent 524812 69e50e5c237c15870488c54ce0be7814b3f74c18
child 524814 779dee1241adec18384fa1ff2c7d8ed297cc8b85
push id1030
push userryanvm@gmail.com
push dateThu, 14 May 2020 19:53:46 +0000
treeherdermozilla-esr68@fc5a91e40024 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGrisha, RyanVM
bugs1633568
milestone68.8.1
Bug 1633568 - AdjustHelper can inform more listeners about Attribution changes. r=Grisha, a=RyanVM TelemetryCorePingDelegate was already a listener for AdjustAttribution campaign changes. The new "installation" ping also needs all data about the AdjustAttribution when it changes. To keep a simple API AdjustHelper will now be able to inform more listeners about Attribution changes and will send the entire object, each callback being responsible to extract the data it needs. Differential Revision: https://phabricator.services.mozilla.com/D74072
mobile/android/base/java/org/mozilla/gecko/adjust/AdjustBrowserAppDelegate.java
mobile/android/base/java/org/mozilla/gecko/adjust/AdjustHelper.java
mobile/android/base/java/org/mozilla/gecko/adjust/AdjustHelperInterface.java
mobile/android/base/java/org/mozilla/gecko/adjust/AttributionHelperListener.java
mobile/android/base/java/org/mozilla/gecko/adjust/StubAdjustHelper.java
mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryCorePingDelegate.java
--- a/mobile/android/base/java/org/mozilla/gecko/adjust/AdjustBrowserAppDelegate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/adjust/AdjustBrowserAppDelegate.java
@@ -8,28 +8,28 @@ import org.mozilla.gecko.BrowserApp;
 import org.mozilla.gecko.GeckoSharedPrefs;
 import org.mozilla.gecko.delegates.BrowserAppDelegate;
 import org.mozilla.gecko.mozglue.SafeIntent;
 import org.mozilla.gecko.preferences.GeckoPreferences;
 import org.mozilla.gecko.util.IntentUtils;
 
 public class AdjustBrowserAppDelegate extends BrowserAppDelegate {
     private final AdjustHelperInterface adjustHelper;
-    private final AttributionHelperListener attributionHelperListener;
+    private final AttributionHelperListener[] attributionHelperListeners;
 
-    public AdjustBrowserAppDelegate(AttributionHelperListener attributionHelperListener) {
+    public AdjustBrowserAppDelegate(AttributionHelperListener... attributionHelperListeners) {
         this.adjustHelper = AdjustConstants.getAdjustHelper();
-        this.attributionHelperListener = attributionHelperListener;
+        this.attributionHelperListeners = attributionHelperListeners;
     }
 
     @Override
     public void onCreate(BrowserApp browserApp, Bundle savedInstanceState) {
         adjustHelper.onCreate(browserApp,
                 AdjustConstants.MOZ_INSTALL_TRACKING_ADJUST_SDK_APP_TOKEN,
-                attributionHelperListener);
+                attributionHelperListeners);
 
         final boolean isInAutomation = IntentUtils.getIsInAutomationFromEnvironment(
                 new SafeIntent(browserApp.getIntent()));
 
         final SharedPreferences prefs = GeckoSharedPrefs.forApp(browserApp);
 
         // Adjust stores enabled state so this is only necessary because users may have set
         // their data preferences before this feature was implemented and we need to respect
--- a/mobile/android/base/java/org/mozilla/gecko/adjust/AdjustHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/adjust/AdjustHelper.java
@@ -16,33 +16,33 @@ import com.adjust.sdk.AdjustReferrerRece
 import com.adjust.sdk.LogLevel;
 import com.adjust.sdk.OnAttributionChangedListener;
 
 import org.mozilla.gecko.AppConstants;
 
 public class AdjustHelper implements AdjustHelperInterface, OnAttributionChangedListener {
 
     private static final String LOGTAG = AdjustHelper.class.getSimpleName();
-    private AttributionHelperListener attributionListener;
+    private AttributionHelperListener[] attributionListeners;
 
-    public void onCreate(final Context context, final String maybeAppToken, final AttributionHelperListener listener) {
+    public void onCreate(final Context context, final String maybeAppToken, final AttributionHelperListener... listeners) {
         final String environment;
         final LogLevel logLevel;
         if (AppConstants.MOZILLA_OFFICIAL) {
             environment = AdjustConfig.ENVIRONMENT_PRODUCTION;
             logLevel = LogLevel.WARN;
         } else {
             environment = AdjustConfig.ENVIRONMENT_SANDBOX;
             logLevel = LogLevel.VERBOSE;
         }
         if (maybeAppToken == null) {
             // We've got install tracking turned on -- we better have a token!
             throw new IllegalArgumentException("maybeAppToken must not be null");
         }
-        attributionListener = listener;
+        attributionListeners = listeners;
         AdjustConfig config = new AdjustConfig(context, maybeAppToken, environment);
         config.setLogLevel(logLevel);
         config.setOnAttributionChangedListener(this);
         Adjust.onCreate(config);
     }
 
     public void onPause() {
         Adjust.onPause();
@@ -57,19 +57,21 @@ public class AdjustHelper implements Adj
     }
 
     public void onReceive(final Context context, final Intent intent) {
         new AdjustReferrerReceiver().onReceive(context, intent);
     }
 
     @Override
     public void onAttributionChanged(AdjustAttribution attribution) {
-        if (attributionListener == null) {
+        if (attributionListeners == null) {
             throw new IllegalStateException("Expected non-null attribution listener.");
         }
 
         if (attribution == null) {
-            Log.e(LOGTAG, "Adjust attribution is null; skipping campaign id retrieval.");
+            Log.e(LOGTAG, "Adjust attribution is null. Skipping informing listeners about this.");
             return;
         }
-        attributionListener.onCampaignIdChanged(attribution.campaign);
+        for (AttributionHelperListener listener: attributionListeners) {
+            listener.onAttributionChanged(attribution);
+        }
     }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/adjust/AdjustHelperInterface.java
+++ b/mobile/android/base/java/org/mozilla/gecko/adjust/AdjustHelperInterface.java
@@ -8,15 +8,15 @@ package org.mozilla.gecko.adjust;
 import android.content.Context;
 import android.content.Intent;
 
 public interface AdjustHelperInterface {
     /**
      * Register the Application with the Adjust SDK.
      * @param appToken the (secret!) Adjust SDK per-application token to register with; may be null.
      */
-    void onCreate(final Context context, final String appToken, final AttributionHelperListener listener);
+    void onCreate(final Context context, final String appToken, final AttributionHelperListener... listener);
     void onPause();
     void onResume();
 
     void setEnabled(final boolean isEnabled);
     void onReceive(final Context context, final Intent intent);
 }
--- a/mobile/android/base/java/org/mozilla/gecko/adjust/AttributionHelperListener.java
+++ b/mobile/android/base/java/org/mozilla/gecko/adjust/AttributionHelperListener.java
@@ -1,17 +1,24 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.adjust;
 
+import android.support.annotation.NonNull;
+
+import com.adjust.sdk.AdjustAttribution;
+
 /**
  * Because of how our build module dependencies are structured, we aren't able to use
  * the {@link com.adjust.sdk.OnAttributionChangedListener} directly outside of {@link AdjustHelper}.
  * If the Adjust SDK is enabled, this listener should be notified when {@link com.adjust.sdk.OnAttributionChangedListener}
  * is fired (i.e. this listener would be daisy-chained to the Adjust one). The listener also
- * inherits thread-safety from GeckoSharedPrefs which is used to store the campaign ID.
+ * inherits thread-safety from GeckoSharedPrefs which is used to store the attribution.
  */
 public interface AttributionHelperListener {
-    void onCampaignIdChanged(String campaignId);
+    /**
+     * @param attribution - new Adjust attribution configuration.
+     */
+    void onAttributionChanged(@NonNull final AdjustAttribution attribution);
 }
--- a/mobile/android/base/java/org/mozilla/gecko/adjust/StubAdjustHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/adjust/StubAdjustHelper.java
@@ -4,17 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.adjust;
 
 import android.content.Context;
 import android.content.Intent;
 
 public class StubAdjustHelper implements AdjustHelperInterface {
-    public void onCreate(final Context context, final String appToken, final AttributionHelperListener listener) {
+    public void onCreate(final Context context, final String appToken, final AttributionHelperListener... listeners) {
         // Do nothing.
     }
 
     public void onPause() {
         // Do nothing.
     }
 
     public void onResume() {
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryCorePingDelegate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryCorePingDelegate.java
@@ -4,21 +4,24 @@
  * file, you can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
 package org.mozilla.gecko.telemetry;
 
 import android.accessibilityservice.AccessibilityServiceInfo;
 import android.content.Context;
 import android.content.SharedPreferences;
+import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.annotation.WorkerThread;
 import android.util.Log;
 import android.view.accessibility.AccessibilityManager;
 
+import com.adjust.sdk.AdjustAttribution;
+
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.mozilla.gecko.BrowserApp;
 import org.mozilla.gecko.GeckoApp;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.GeckoSharedPrefs;
 import org.mozilla.gecko.GeckoThread;
 import org.mozilla.gecko.PrefsHelper;
@@ -268,12 +271,12 @@ public class TelemetryCorePingDelegate e
                 accessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
             if (enabledServices.size() > 0) {
                 pingBuilder.setOptAccessibility(enabledServices);
             }
         }
     }
 
     @Override
-    public void onCampaignIdChanged(String campaignId) {
-        CampaignIdMeasurements.updateCampaignIdPref(getBrowserApp(), campaignId);
+    public void onAttributionChanged(@NonNull final AdjustAttribution attribution) {
+        CampaignIdMeasurements.updateCampaignIdPref(getBrowserApp(), attribution.campaign);
     }
 }