Bug 1232773 - Check if user is opt out from Adjust before accessing. r=mfinkle
It made sense to me to have this code inside the AdjustHelper so I moved the
existing opt out code inside the AdjustHelper as well.
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -690,20 +690,17 @@ public class BrowserApp extends GeckoApp
JavaAddonManager.getInstance().init(appContext);
mSharedPreferencesHelper = new SharedPreferencesHelper(appContext);
mOrderedBroadcastHelper = new OrderedBroadcastHelper(appContext);
mBrowserHealthReporter = new BrowserHealthReporter();
mReadingListHelper = new ReadingListHelper(appContext, getProfile(), this);
mAccountsHelper = new AccountsHelper(appContext, getProfile());
if (AppConstants.MOZ_INSTALL_TRACKING) {
- final SharedPreferences prefs = GeckoSharedPrefs.forApp(this);
- if (prefs.getBoolean(GeckoPreferences.PREFS_HEALTHREPORT_UPLOAD_ENABLED, true)) {
- AdjustConstants.getAdjustHelper().onCreate(this, AdjustConstants.MOZ_INSTALL_TRACKING_ADJUST_SDK_APP_TOKEN);
- }
+ AdjustConstants.getAdjustHelper().onCreate(this, AdjustConstants.MOZ_INSTALL_TRACKING_ADJUST_SDK_APP_TOKEN);
}
if (AppConstants.MOZ_ANDROID_BEAM) {
NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
if (nfc != null) {
nfc.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
@@ -884,17 +881,17 @@ public class BrowserApp extends GeckoApp
}
});
}
}
@Override
public void onResume() {
super.onResume();
- AdjustConstants.getAdjustHelper().onResume();
+ AdjustConstants.getAdjustHelper().onResume(this);
final String args = ContextUtils.getStringExtra(getIntent(), "args");
// If an external intent tries to start Fennec in guest mode, and it's not already
// in guest mode, this will change modes before opening the url.
// NOTE: OnResume is called twice sometimes when showing on the lock screen.
final boolean enableGuestSession = GuestSession.shouldUse(this, args);
final boolean inGuestSession = GeckoProfile.get(this).inGuestMode();
if (enableGuestSession != inGuestSession) {
@@ -906,17 +903,17 @@ public class BrowserApp extends GeckoApp
"Prompt:ShowTop");
processTabQueue();
}
@Override
public void onPause() {
super.onPause();
- AdjustConstants.getAdjustHelper().onPause();
+ AdjustConstants.getAdjustHelper().onPause(this);
// Register for Prompt:ShowTop so we can foreground this activity even if it's hidden.
EventDispatcher.getInstance().registerGeckoThreadListener((GeckoEventListener) this,
"Prompt:ShowTop");
}
@Override
public void onStart() {
super.onStart();
--- a/mobile/android/base/java/org/mozilla/gecko/adjust/AdjustHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/adjust/AdjustHelper.java
@@ -1,25 +1,33 @@
/* -*- 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 org.mozilla.gecko.GeckoSharedPrefs;
+import org.mozilla.gecko.preferences.GeckoPreferences;
+
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
import com.adjust.sdk.Adjust;
import com.adjust.sdk.AdjustConfig;
import com.adjust.sdk.AdjustReferrerReceiver;
import com.adjust.sdk.LogLevel;
public class AdjustHelper implements AdjustHelperInterface {
public void onCreate(final Context context, final String maybeAppToken) {
+ if (isUserOptOut(context)) {
+ return;
+ }
+
final String environment;
final String appToken;
final LogLevel logLevel;
if (maybeAppToken != null) {
environment = AdjustConfig.ENVIRONMENT_PRODUCTION;
appToken = maybeAppToken;
logLevel = LogLevel.WARN;
} else {
@@ -31,16 +39,29 @@ public class AdjustHelper implements Adj
config.setLogLevel(logLevel);
Adjust.onCreate(config);
}
public void onReceive(final Context context, final Intent intent) {
new AdjustReferrerReceiver().onReceive(context, intent);
}
- public void onResume() {
+ public void onResume(final Context context) {
+ if (isUserOptOut(context)) {
+ return;
+ }
+
Adjust.onResume();
}
- public void onPause() {
+ public void onPause(final Context context) {
+ if (isUserOptOut(context)) {
+ return;
+ }
+
Adjust.onPause();
}
+
+ private boolean isUserOptOut(final Context context) {
+ final SharedPreferences prefs = GeckoSharedPrefs.forApp(context);
+ return !prefs.getBoolean(GeckoPreferences.PREFS_HEALTHREPORT_UPLOAD_ENABLED, true);
+ }
}
--- a/mobile/android/base/java/org/mozilla/gecko/adjust/AdjustHelperInterface.java
+++ b/mobile/android/base/java/org/mozilla/gecko/adjust/AdjustHelperInterface.java
@@ -10,11 +10,11 @@ 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);
void onReceive(final Context context, final Intent intent);
- void onResume();
- void onPause();
+ void onResume(final Context context);
+ void onPause(final Context context);
}
--- a/mobile/android/base/java/org/mozilla/gecko/adjust/StubAdjustHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/adjust/StubAdjustHelper.java
@@ -12,16 +12,16 @@ public class StubAdjustHelper implements
public void onCreate(final Context context, final String appToken) {
// Do nothing.
}
public void onReceive(final Context context, final Intent intent) {
// Do nothing.
}
- public void onResume() {
+ public void onResume(final Context context) {
// Do nothing.
}
- public void onPause() {
+ public void onPause(final Context context) {
// Do nothing.
}
}