From 3b9d427950155b95d1dbf0d787ef4278eb2aa457 Mon Sep 17 00:00:00 2001 From: Will Passidomo Date: Tue, 22 Feb 2022 12:45:16 -0800 Subject: [PATCH] feat: remove deprecated methods, AppConfig (#100) --- .../com/mparticle/MParticleOptionsTest.java | 4 +- .../java/com/mparticle/MPServiceUtil.java | 4 +- .../main/java/com/mparticle/MParticle.java | 10 +- .../java/com/mparticle/MParticleOptions.java | 69 +++----- .../com/mparticle/internal/AppConfig.java | 159 ------------------ .../com/mparticle/internal/ConfigManager.java | 107 ++++++------ .../com/mparticle/internal/Constants.java | 4 + .../mparticle/internal/DeviceAttributes.java | 3 - .../com/mparticle/internal/UserStorage.java | 2 +- .../networking/MParticleBaseClientImpl.java | 2 +- .../mparticle/internal/ConfigManagerTest.java | 43 +---- .../internal/MParticleApiClientImplTest.java | 2 +- .../mparticle/kits/BaseKitManagerStarted.java | 2 +- scripts/startup_perf_tests.sh | 0 .../main/java/com/mparticle/AccessUtils.java | 4 + .../com/mparticle/networking/MockServer.java | 15 +- .../mparticle/testutils/BaseAbstractTest.java | 4 + 17 files changed, 115 insertions(+), 319 deletions(-) delete mode 100644 android-core/src/main/java/com/mparticle/internal/AppConfig.java create mode 100644 scripts/startup_perf_tests.sh diff --git a/android-core/src/androidTest/java/com/mparticle/MParticleOptionsTest.java b/android-core/src/androidTest/java/com/mparticle/MParticleOptionsTest.java index 4aae19206..1b5e135c4 100644 --- a/android-core/src/androidTest/java/com/mparticle/MParticleOptionsTest.java +++ b/android-core/src/androidTest/java/com/mparticle/MParticleOptionsTest.java @@ -100,10 +100,10 @@ public void testCrashOnNoCredentials() throws Exception { setStoredPreference("key", "secret"); try { - MParticleOptions.builder(mContext).build(); + MParticleOptions.builder(mContext).buildForInternalRestart(); } catch (IllegalArgumentException ex) { - fail("MParticleOptions should build without credentials if there are stored credentials"); + fail("MParticleOptions should build without credentials if the internal build function is used"); } try { diff --git a/android-core/src/main/java/com/mparticle/MPServiceUtil.java b/android-core/src/main/java/com/mparticle/MPServiceUtil.java index b6e788c6a..14f8860b2 100644 --- a/android-core/src/main/java/com/mparticle/MPServiceUtil.java +++ b/android-core/src/main/java/com/mparticle/MPServiceUtil.java @@ -167,7 +167,7 @@ public void onKitsLoaded() { } }; KitFrameworkWrapper.addKitsLoadedListener(kitsLoadedListener); - MParticle.start(MParticleOptions.builder(mContext).build()); + MParticle.start(MParticleOptions.builder(mContext).buildForInternalRestart()); } catch (Exception e) { Logger.warning("FCM parsing error: " + e.toString()); @@ -188,7 +188,7 @@ private void handleNotificationTapInternal(Intent intent) { (NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE); manager.cancel(message.getId()); - MParticle.start(MParticleOptions.builder(mContext.getApplicationContext()).build()); + MParticle.start(MParticleOptions.builder(mContext.getApplicationContext()).buildForInternalRestart()); Intent broadcast = new Intent(MPMessagingAPI.BROADCAST_NOTIFICATION_TAPPED); broadcast.putExtra(MPMessagingAPI.CLOUD_MESSAGE_EXTRA, message); LocalBroadcastManager.getInstance(mContext).sendBroadcast(broadcast); diff --git a/android-core/src/main/java/com/mparticle/MParticle.java b/android-core/src/main/java/com/mparticle/MParticle.java index c6d7e44ae..d51ff29b2 100644 --- a/android-core/src/main/java/com/mparticle/MParticle.java +++ b/android-core/src/main/java/com/mparticle/MParticle.java @@ -231,7 +231,7 @@ public static void setInstance(@Nullable MParticle instance) { /** * @deprecated * This method has been replaced as the behavior has been inverted - Android ID collection is now disabled by default. - *

Use {@link androidIdEnabled(boolean)} instead. + *

Use {@link MParticle#isAndroidIdEnabled()} instead. * * * Query the status of Android ID collection. @@ -639,7 +639,7 @@ public void enableLocationTracking(@NonNull String provider, long minTime, long //noinspection MissingPermission locationManager.requestLocationUpdates(provider, minTime, minDistance, mLocationListener); locationTrackingEnabled = true; - }catch (SecurityException se) { + } catch (SecurityException ignored) { } SharedPreferences.Editor editor = mPreferences.edit(); @@ -822,13 +822,16 @@ public void disableUncaughtExceptionLogging() { } /** + * @deprecated + * * Retrieves the current setting of automatic screen tracking. * * @return The current setting of automatic screen tracking. */ @NonNull + @Deprecated public Boolean isAutoTrackingEnabled() { - return mConfigManager.isAutoTrackingEnabled(); + return false; } /** @@ -1653,6 +1656,5 @@ public KitFrameworkWrapper getKitManager() { public MessageManager getMessageManager() { return mMessageManager; } - } } diff --git a/android-core/src/main/java/com/mparticle/MParticleOptions.java b/android-core/src/main/java/com/mparticle/MParticleOptions.java index 69f531bd4..99beeacd1 100644 --- a/android-core/src/main/java/com/mparticle/MParticleOptions.java +++ b/android-core/src/main/java/com/mparticle/MParticleOptions.java @@ -26,8 +26,6 @@ * class used for passing optional settings to the SDK when it is started. */ public class MParticleOptions { - private static final String PREFKEY_API_KEY = "mp_key"; - private static final String PREFKEY_API_SECRET = "mp_secret"; private BaseIdentityTask mIdentityTask; private Context mContext; @@ -71,6 +69,13 @@ public MParticleOptions(@NonNull Builder builder) { if (builder.environment != null) { this.mEnvironment = builder.environment; } + if (mEnvironment == null || mEnvironment == MParticle.Environment.AutoDetect) { + if (builder.isAppDebuggable) { + this.mEnvironment = MParticle.Environment.Development; + } else { + this.mEnvironment = MParticle.Environment.Production; + } + } if (builder.identifyRequest != null) { this.mIdentifyRequest = builder.identifyRequest; } @@ -206,7 +211,7 @@ public Boolean isDevicePerformanceMetricsDisabled() { /** * @deprecated * This method has been replaced as the behavior has been inverted - Android ID collection is now disabled by default. - *

Use {@link isAndroidIdEnabled(boolean)} instead. + *

Use {@link MParticle#isAndroidIdEnabled()} instead. * * Query whether Android Id collection is enabled or disabled. * @return true if collection is disabled, false if it is enabled @@ -363,6 +368,7 @@ public static class Builder { private MParticle.OperatingSystem operatingSystem; private DataplanOptions dataplanOptions; private Map> configurations = new HashMap(); + private boolean isAppDebuggable; private Builder(Context context) { this.context = context; @@ -701,60 +707,35 @@ public Builder configuration(Configuration configuration) { */ @NonNull public MParticleOptions build() { - boolean devMode = MParticle.Environment.Development.equals(environment) || MPUtility.isAppDebuggable(context); String message; if (context == null) { throw new IllegalArgumentException("mParticle failed to start: context is required."); } + isAppDebuggable = MPUtility.isAppDebuggable(context); + boolean devMode = MParticle.Environment.Development.equals(environment) || isAppDebuggable; + if (MPUtility.isEmpty(apiKey)) { - apiKey = getString(PREFKEY_API_KEY); - if (MPUtility.isEmpty(apiKey)) { - apiKey = getConfigManager().getApiKey(); - if (MPUtility.isEmpty(apiKey)) { - message = "Configuration issue: No API key passed to start() or configured as mp_key in resources!"; - if (devMode) { - throw new IllegalArgumentException(message); - } else { - Logger.error(message); - } - } + message = "Configuration issue: No API key passed to start()!"; + if (devMode) { + throw new IllegalArgumentException(message); + } else { + Logger.error(message); } } if (MPUtility.isEmpty(apiSecret)) { - apiSecret = getString(PREFKEY_API_SECRET); - if (MPUtility.isEmpty(apiSecret)) { - apiSecret = getConfigManager().getApiSecret(); - if (MPUtility.isEmpty(apiSecret)) { - message = "Configuration issue: No API secret passed to start() or configured as mp_secret in resources!"; - if (devMode) { - throw new IllegalArgumentException(message); - } else { - Logger.error(message); - } + message = "Configuration issue: No API secret passed to start()!"; + if (devMode) { + throw new IllegalArgumentException(message); + } else { + Logger.error(message); } - } } - return new MParticleOptions(this); - } - - private String getString(String key) { - int id = this.context.getResources().getIdentifier(key, "string", this.context.getPackageName()); - if (id == 0) { - return null; + return new MParticleOptions(this); } - try { - return this.context.getResources().getString(id); - } catch (android.content.res.Resources.NotFoundException nfe) { - return null; - } - } - private ConfigManager getConfigManager() { - if (configManager == null) { - configManager = new ConfigManager(context); + MParticleOptions buildForInternalRestart() { + return new MParticleOptions(this); } - return configManager; - } } static class LocationTracking { diff --git a/android-core/src/main/java/com/mparticle/internal/AppConfig.java b/android-core/src/main/java/com/mparticle/internal/AppConfig.java deleted file mode 100644 index 7aaaffd0c..000000000 --- a/android-core/src/main/java/com/mparticle/internal/AppConfig.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.mparticle.internal; - -import android.content.Context; -import android.content.SharedPreferences; - -import com.mparticle.MParticle; - -/** - * This class is primarily responsible for parsing and representing XML/resource-based configuration. - */ -class AppConfig { - public static final String PREFKEY_EXCEPTIONS = "mp_reportUncaughtExceptions"; - public static final String PREFKEY_SESSION_TIMEOUT = "mp_sessionTimeout"; - public static final String PREFKEY_PROD_UPLOAD_INTERVAL = "mp_productionUploadInterval"; - public static final String PREFKEY_PUSH_ENABLED = "mp_enablePush"; - public static final String PREFKEY_PUSH_SENDER_ID = "mp_pushSenderId"; - public static final String PREFKEY_APP_LICENSE_KEY = "mp_appLicenseKey"; - public static final String PREFKEY_LICENSING_ENABLED = "mp_enableLicenseCheck"; - private static final String PREFKEY_AUTOTRACKING = "mp_enableAutoTracking"; - private static final String PREFKEY_FORCE_ENVIRONMENT= "mp_environment"; - - public static final boolean DEFAULT_ENABLE_PUSH = false; - public static final boolean DEFAULT_REPORT_UNCAUGHT_EXCEPTIONS = false; - public static final boolean DEFAULT_ENABLE_LICENSING = false; - public static final boolean DEFAULT_ENABLE_AUTO_TRACKING = false; - public static final boolean DEFAULT_ENABLE_PUSH_SOUND = false; - public static final boolean DEFAULT_ENABLE_PUSH_VIBRATION = false; - - private final Context mContext; - - public String mKey = null; - public String mSecret = null; - - public boolean reportUncaughtExceptions; - public int sessionTimeout = ConfigManager.DEFAULT_SESSION_TIMEOUT_SECONDS; - public int uploadInterval = ConfigManager.DEFAULT_UPLOAD_INTERVAL; - public boolean isPushEnabled = DEFAULT_ENABLE_PUSH; - private String pushSenderId = null; - public String licenseKey = null; - public boolean isLicensingEnabled = DEFAULT_ENABLE_LICENSING; - public boolean autoTrackingEnabled = DEFAULT_ENABLE_AUTO_TRACKING; - public int audienceTimeout = 100; - private static MParticle.Environment sEnvironment = MParticle.Environment.Production; - - public AppConfig(Context context, MParticle.Environment environment, SharedPreferences preferences, String apiKey, String apiSecret) { - mContext = context; - if (environment == null || environment == MParticle.Environment.AutoDetect){ - if (MPUtility.isAppDebuggable(context)){ - sEnvironment = MParticle.Environment.Development; - }else{ - sEnvironment = MParticle.Environment.Production; - } - }else{ - sEnvironment = environment; - } - if (apiKey == null) { - apiKey = preferences.getString(Constants.PrefKeys.API_KEY, ""); - } - if (apiSecret == null) { - apiSecret = preferences.getString(Constants.PrefKeys.API_SECRET, ""); - } - mKey = apiKey; - mSecret = apiSecret; - preferences.edit() - .putString(Constants.PrefKeys.API_KEY, mKey) - .putString(Constants.PrefKeys.API_SECRET, mSecret) - .apply(); - - reportUncaughtExceptions = getBoolean(PREFKEY_EXCEPTIONS, DEFAULT_REPORT_UNCAUGHT_EXCEPTIONS); - - String mode = getString(PREFKEY_FORCE_ENVIRONMENT, null); - if (mode != null) { - if (mode.toLowerCase().contains("dev")) { - Logger.warning("Forcing SDK into development mode based on configuration XML key: " + PREFKEY_FORCE_ENVIRONMENT + " and value: " + mode); - sEnvironment = MParticle.Environment.Development; - } else if (mode.toLowerCase().contains("prod")) { - Logger.warning("Forcing SDK into production mode based on configuration XML key: " + PREFKEY_FORCE_ENVIRONMENT + " and value: " + mode); - sEnvironment = MParticle.Environment.Production; - } - } - autoTrackingEnabled = getBoolean(PREFKEY_AUTOTRACKING, DEFAULT_ENABLE_AUTO_TRACKING); - sessionTimeout = getInteger(PREFKEY_SESSION_TIMEOUT, ConfigManager.DEFAULT_SESSION_TIMEOUT_SECONDS); - } - - public void delayedInit() { - uploadInterval = getInteger(PREFKEY_PROD_UPLOAD_INTERVAL, uploadInterval); - isPushEnabled = getBoolean(PREFKEY_PUSH_ENABLED, DEFAULT_ENABLE_PUSH); - if (isPushEnabled){ - pushSenderId = getString(PREFKEY_PUSH_SENDER_ID, null); - if (pushSenderId == null){ - Logger.error("Configuration issue: Push is enabled but no sender id is specified."); - } - } - - isLicensingEnabled = getBoolean(PREFKEY_LICENSING_ENABLED, DEFAULT_ENABLE_LICENSING); - if (isLicensingEnabled){ - licenseKey = getString(PREFKEY_APP_LICENSE_KEY, ""); - if (licenseKey == null){ - Logger.error("Configuration issue: Licensing enabled but no license key specified."); - } - } - } - - private int getResourceId(String key, String type) { - return this.mContext.getResources().getIdentifier(key, type, this.mContext.getPackageName()); - } - - public String getString(String key, String defaultString) { - int id = getResourceId(key, "string"); - if (id == 0) { - if (defaultString != null) { - Logger.debug(String.format("Configuration: No string resource for: %s, using default: %s", key, defaultString)); - } - return defaultString; - } - try { - return this.mContext.getResources().getString(id); - }catch (android.content.res.Resources.NotFoundException nfe){ - return defaultString; - } - } - - public boolean getBoolean(String key, boolean defaultValue) { - int id = getResourceId(key, "bool"); - if (id == 0) { - Logger.debug(String.format("Configuration: No string resource for: %s, using default: %b", key, defaultValue)); - return defaultValue; - } - try { - return this.mContext.getResources().getBoolean(id); - }catch (android.content.res.Resources.NotFoundException nfe){ - return defaultValue; - } - } - - public int getInteger(String key, int defaultValue) { - int id = getResourceId(key, "integer"); - if (id == 0) { - Logger.debug(String.format("Configuration: No string resource for: %s, using default: %d", key, defaultValue)); - return defaultValue; - } - try { - return this.mContext.getResources().getInteger(id); - }catch (android.content.res.Resources.NotFoundException nfe){ - return defaultValue; - } - } - - public static MParticle.Environment getEnvironment() { - return sEnvironment; - } - - public String getPushSenderId() { - if (MPUtility.isEmpty(pushSenderId)){ - pushSenderId = getString(PREFKEY_PUSH_SENDER_ID, null); - } - return pushSenderId; - } -} diff --git a/android-core/src/main/java/com/mparticle/internal/ConfigManager.java b/android-core/src/main/java/com/mparticle/internal/ConfigManager.java index dfff5aba8..6b8830022 100644 --- a/android-core/src/main/java/com/mparticle/internal/ConfigManager.java +++ b/android-core/src/main/java/com/mparticle/internal/ConfigManager.java @@ -78,8 +78,6 @@ public class ConfigManager { static SharedPreferences sPreferences; - AppConfig mLocalPrefs; - private static JSONArray sPushKeys; private UserStorage mUserStorage; private String mLogUnhandledExceptions = VALUE_APP_DEFINED; @@ -133,7 +131,12 @@ public ConfigManager(@NonNull MParticleOptions options) { public ConfigManager(@NonNull Context context, @Nullable MParticle.Environment environment, @Nullable String apiKey, @Nullable String apiSecret, @Nullable MParticleOptions.DataplanOptions dataplanOptions, @Nullable String dataplanId, @Nullable Integer dataplanVersion, @Nullable Integer configMaxAge, @Nullable List> configurations) { mContext = context.getApplicationContext(); sPreferences = getPreferences(mContext); - mLocalPrefs = new AppConfig(mContext, environment, sPreferences, apiKey, apiSecret); + if (apiKey != null || apiSecret != null) { + setCredentials(apiKey, apiSecret); + } + if (environment != null) { + setEnvironment(environment); + } mUserStorage = UserStorage.create(mContext, getMpid()); //if we are initialized with a DataplanOptions instance, then we will ignore values from remote config mIgnoreDataplanOptionsFromConfig = dataplanOptions != null; @@ -419,9 +422,9 @@ public boolean getRestrictAAIDBasedOnLAT() { * This method will be called from a background thread after startup is already complete. */ public void delayedStart() { - mLocalPrefs.delayedInit(); - if (isPushEnabled() && getPushRegistration() == null) { - MParticle.getInstance().Messaging().enablePushNotifications(getPushSenderId()); + String senderId = getPushSenderId(); + if (isPushEnabled() && senderId != null) { + MParticle.getInstance().Messaging().enablePushNotifications(senderId); } } @@ -442,49 +445,56 @@ private void applyConfig() { } public void enableUncaughtExceptionLogging(boolean userTriggered) { + if (userTriggered) { + setLogUnhandledExceptions(true); + } if (null == mExHandler) { Thread.UncaughtExceptionHandler currentUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); if (!(currentUncaughtExceptionHandler instanceof ExceptionHandler)) { mExHandler = new ExceptionHandler(currentUncaughtExceptionHandler); Thread.setDefaultUncaughtExceptionHandler(mExHandler); - if (userTriggered) { - setLogUnhandledExceptions(true); - } } } } public void disableUncaughtExceptionLogging(boolean userTriggered) { + if (userTriggered) { + setLogUnhandledExceptions(false); + } if (null != mExHandler) { Thread.UncaughtExceptionHandler currentUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); if (currentUncaughtExceptionHandler instanceof ExceptionHandler) { Thread.setDefaultUncaughtExceptionHandler(mExHandler.getOriginalExceptionHandler()); mExHandler = null; - if (userTriggered) { - setLogUnhandledExceptions(false); - } } } } public boolean getLogUnhandledExceptions() { if (VALUE_APP_DEFINED.equals(mLogUnhandledExceptions)) { - return mLocalPrefs.reportUncaughtExceptions; + return sPreferences.getBoolean(Constants.PrefKeys.REPORT_UNCAUGHT_EXCEPTIONS, false); } else { return VALUE_CUE_CATCH.equals(mLogUnhandledExceptions); } } public void setLogUnhandledExceptions(boolean log) { - mLocalPrefs.reportUncaughtExceptions = log; + sPreferences.edit().putBoolean(Constants.PrefKeys.REPORT_UNCAUGHT_EXCEPTIONS, log).apply(); } public String getApiKey() { - return mLocalPrefs.mKey; + return sPreferences.getString(Constants.PrefKeys.API_KEY, null); } public String getApiSecret() { - return mLocalPrefs.mSecret; + return sPreferences.getString(Constants.PrefKeys.API_SECRET,null); + } + + public void setCredentials(String apiKey, String secret) { + sPreferences.edit() + .putString(Constants.PrefKeys.API_KEY, apiKey) + .putString(Constants.PrefKeys.API_SECRET, secret) + .apply(); } public long getUploadInterval() { @@ -494,34 +504,49 @@ public long getUploadInterval() { if (mUploadInterval > 0) { return 1000 * mUploadInterval; } else { - return (1000 * mLocalPrefs.uploadInterval); + return (1000 * sPreferences.getInt(Constants.PrefKeys.UPLOAD_INTERVAL, DEFAULT_UPLOAD_INTERVAL)); } } } + public void setEnvironment(MParticle.Environment environment) { + if (environment != null) { + sPreferences.edit().putInt(Constants.PrefKeys.ENVIRONMENT, environment.getValue()).apply(); + } else { + sPreferences.edit().remove(Constants.PrefKeys.ENVIRONMENT).apply(); + } + } + public static MParticle.Environment getEnvironment() { - return AppConfig.getEnvironment(); + if (sPreferences != null) { + int env = sPreferences.getInt(Constants.PrefKeys.ENVIRONMENT, MParticle.Environment.Production.getValue()); + for(MParticle.Environment environment: MParticle.Environment.values()) { + if (environment.getValue() == env) { + return environment; + } + } + } + return MParticle.Environment.Production; } public void setUploadInterval(int uploadInterval) { - mLocalPrefs.uploadInterval = uploadInterval; + sPreferences.edit().putInt(Constants.PrefKeys.UPLOAD_INTERVAL, uploadInterval).apply(); } public int getSessionTimeout() { if (mSessionTimeoutInterval > 0) { return mSessionTimeoutInterval * 1000; } else { - return mLocalPrefs.sessionTimeout * 1000; + return sPreferences.getInt(Constants.PrefKeys.SESSION_TIMEOUT, DEFAULT_SESSION_TIMEOUT_SECONDS) * 1000; } } public void setSessionTimeout(int sessionTimeout) { - mLocalPrefs.sessionTimeout = sessionTimeout; + sPreferences.edit().putInt(Constants.PrefKeys.SESSION_TIMEOUT, sessionTimeout).apply(); } public boolean isPushEnabled() { - return mLocalPrefs.isPushEnabled || - (sPreferences.getBoolean(Constants.PrefKeys.PUSH_ENABLED, false) && getPushSenderId() != null); + return sPreferences.getBoolean(Constants.PrefKeys.PUSH_ENABLED, false) && getPushSenderId() != null; } public String getPushSenderId() { @@ -617,26 +642,6 @@ public void clearPushRegistrationBackground() { .apply(); } - public String getLicenseKey() { - return mLocalPrefs.licenseKey; - } - - public boolean isLicensingEnabled() { - return mLocalPrefs.licenseKey != null && mLocalPrefs.isLicensingEnabled; - } - - public void setPushSoundEnabled(boolean pushSoundEnabled) { - sPreferences.edit() - .putBoolean(Constants.PrefKeys.PUSH_ENABLE_SOUND, pushSoundEnabled) - .apply(); - } - - public void setPushVibrationEnabled(boolean pushVibrationEnabled) { - sPreferences.edit() - .putBoolean(Constants.PrefKeys.PUSH_ENABLE_VIBRATION, pushVibrationEnabled) - .apply(); - } - public boolean isEnabled() { boolean optedOut = this.getOptedOut(); return !optedOut || mSendOoEvents; @@ -651,18 +656,6 @@ public boolean getOptedOut() { return sPreferences.getBoolean(Constants.PrefKeys.OPTOUT, false); } - public boolean isAutoTrackingEnabled() { - return mLocalPrefs.autoTrackingEnabled; - } - - public boolean isPushSoundEnabled() { - return sPreferences.getBoolean(Constants.PrefKeys.PUSH_ENABLE_SOUND, AppConfig.DEFAULT_ENABLE_PUSH_SOUND); - } - - public boolean isPushVibrationEnabled() { - return sPreferences.getBoolean(Constants.PrefKeys.PUSH_ENABLE_VIBRATION, AppConfig.DEFAULT_ENABLE_PUSH_VIBRATION); - } - public void setPushNotificationIcon(int pushNotificationIcon) { sPreferences.edit() .putInt(Constants.PrefKeys.PUSH_ICON, pushNotificationIcon) @@ -822,10 +815,6 @@ public void mergeUserConfigs(long subjectMpId, long targetMpId) { targetUserStorage.merge(subjectUserStorage); } - public int getAudienceTimeout() { - return mLocalPrefs.audienceTimeout; - } - public int getCurrentRampValue() { return mRampValue; } diff --git a/android-core/src/main/java/com/mparticle/internal/Constants.java b/android-core/src/main/java/com/mparticle/internal/Constants.java index 23ce6b909..9e11156f3 100644 --- a/android-core/src/main/java/com/mparticle/internal/Constants.java +++ b/android-core/src/main/java/com/mparticle/internal/Constants.java @@ -531,6 +531,10 @@ public interface PrefKeys { String DISPLAY_PUSH_NOTIFICATIONS = "mp::displaypushnotifications"; String IDENTITY_CONNECTION_TIMEOUT = "mp::connection:timeout:identity"; String NETWORK_OPTIONS = "mp::network:options"; + String UPLOAD_INTERVAL = "mp::uploadInterval"; + String SESSION_TIMEOUT = "mp::sessionTimeout"; + String REPORT_UNCAUGHT_EXCEPTIONS = "mp::reportUncaughtExceptions"; + String ENVIRONMENT = "mp::environment"; } public interface MiscStorageKeys { diff --git a/android-core/src/main/java/com/mparticle/internal/DeviceAttributes.java b/android-core/src/main/java/com/mparticle/internal/DeviceAttributes.java index 7e56a6424..4295e04db 100644 --- a/android-core/src/main/java/com/mparticle/internal/DeviceAttributes.java +++ b/android-core/src/main/java/com/mparticle/internal/DeviceAttributes.java @@ -288,9 +288,6 @@ public void updateDeviceInfo(Context context, JSONObject deviceInfo) { deviceInfo.put(Constants.MessageKey.PUSH_TOKEN, registration.instanceId); deviceInfo.put(Constants.MessageKey.PUSH_TOKEN_TYPE, Constants.GOOGLE_GCM); } - - deviceInfo.put(Constants.MessageKey.PUSH_SOUND_ENABLED, configManager.isPushSoundEnabled()); - deviceInfo.put(Constants.MessageKey.PUSH_VIBRATION_ENABLED, configManager.isPushVibrationEnabled()); } } catch (JSONException jse) { Logger.debug("Failed while building device-customAttributes object: ", jse.toString()); diff --git a/android-core/src/main/java/com/mparticle/internal/UserStorage.java b/android-core/src/main/java/com/mparticle/internal/UserStorage.java index edb06adc0..883d56da3 100644 --- a/android-core/src/main/java/com/mparticle/internal/UserStorage.java +++ b/android-core/src/main/java/com/mparticle/internal/UserStorage.java @@ -460,7 +460,7 @@ private interface LegacySharedPreferencesKeys { SharedPreferencesMigrator(Context context) { messageManagerSharedPreferences = context.getSharedPreferences(Constants.PREFS_FILE, Context.MODE_PRIVATE); configManagerSharedPreferences = context.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE); - this.apiKey = new AppConfig(context, null, configManagerSharedPreferences, null, null).mKey; + this.apiKey = new ConfigManager(context).getApiKey(); } void migrate(UserStorage userStorage) { diff --git a/android-core/src/main/java/com/mparticle/networking/MParticleBaseClientImpl.java b/android-core/src/main/java/com/mparticle/networking/MParticleBaseClientImpl.java index 1088e59cd..26aad57cf 100644 --- a/android-core/src/main/java/com/mparticle/networking/MParticleBaseClientImpl.java +++ b/android-core/src/main/java/com/mparticle/networking/MParticleBaseClientImpl.java @@ -26,7 +26,7 @@ public class MParticleBaseClientImpl implements MParticleBaseClient { private ConfigManager mConfigManager; private BaseNetworkConnection mRequestHandler; private SharedPreferences mPreferences; - private String mApiKey; + String mApiKey; private static final String SERVICE_VERSION_1 = "/v1"; private static final String SERVICE_VERSION_2 = "/v2"; diff --git a/android-core/src/test/java/com/mparticle/internal/ConfigManagerTest.java b/android-core/src/test/java/com/mparticle/internal/ConfigManagerTest.java index 1e5c25e28..64941107f 100644 --- a/android-core/src/test/java/com/mparticle/internal/ConfigManagerTest.java +++ b/android-core/src/test/java/com/mparticle/internal/ConfigManagerTest.java @@ -156,19 +156,21 @@ public void testSetAndGetLogUnhandledExceptions() throws Exception { @Test public void testGetApiKey() throws Exception { - assertEquals(manager.mLocalPrefs.mKey, manager.getApiKey()); + manager.setCredentials("some key", "some key"); + assertEquals("some key", manager.getApiKey()); } @Test public void testGetApiSecret() throws Exception { - assertEquals(manager.mLocalPrefs.mSecret, manager.getApiSecret()); + manager.setCredentials("some key", "some secret"); + assertEquals("some secret", manager.getApiSecret()); } @Test public void testUploadInterval() throws Exception { JSONObject object = new JSONObject(sampleConfig); - - assertEquals((1000 * manager.mLocalPrefs.uploadInterval), manager.getUploadInterval()); + manager.setUploadInterval(987); + assertEquals((1000 * 987), manager.getUploadInterval()); object.put(ConfigManager.KEY_UPLOAD_INTERVAL, 110); manager.updateConfig(object); assertEquals(1000 * 110, manager.getUploadInterval()); @@ -190,7 +192,8 @@ public void testGetEnvironment() throws Exception { @Test public void testSessionTimeout() throws Exception { - assertEquals(manager.mLocalPrefs.sessionTimeout * 1000, manager.getSessionTimeout()); + manager.setSessionTimeout(123); + assertEquals(123 * 1000, manager.getSessionTimeout()); JSONObject object = new JSONObject(sampleConfig); object.put(ConfigManager.KEY_SESSION_TIMEOUT, 123); manager.updateConfig(object); @@ -204,24 +207,6 @@ public void testPushSenderId() throws Exception { assertEquals("sender_id_test", manager.getPushSenderId()); } - @Test - public void testPushSoundEnabled() throws Exception { - assertEquals(AppConfig.DEFAULT_ENABLE_PUSH_SOUND, manager.isPushSoundEnabled()); - manager.setPushSoundEnabled(true); - assertTrue(manager.isPushSoundEnabled()); - manager.setPushSoundEnabled(false); - assertFalse(manager.isPushSoundEnabled()); - } - - @Test - public void testPushVibrationEnabled() throws Exception { - assertEquals(AppConfig.DEFAULT_ENABLE_PUSH_VIBRATION, manager.isPushVibrationEnabled()); - manager.setPushVibrationEnabled(true); - assertTrue(manager.isPushVibrationEnabled()); - manager.setPushVibrationEnabled(false); - assertFalse(manager.isPushVibrationEnabled()); - } - @Test public void testIsEnabled() throws Exception { assertTrue(manager.isEnabled()); @@ -233,11 +218,6 @@ public void testIsEnabled() throws Exception { assertTrue(manager.isEnabled()); } - @Test - public void testIsAutoTrackingEnabled() throws Exception { - assertEquals(manager.mLocalPrefs.autoTrackingEnabled, manager.isAutoTrackingEnabled()); - } - @Test public void testPushNotificationIcon() throws Exception { assertEquals(0, ConfigManager.getPushIcon(context)); @@ -280,11 +260,6 @@ public void testSetMpid() throws Exception { assertEquals(mpid, manager.getMpid()); } - @Test - public void testGetAudienceTimeout() throws Exception { - assertEquals(manager.mLocalPrefs.audienceTimeout, manager.getAudienceTimeout()); - } - @Test public void testGetCurrentRampValue() throws Exception { assertEquals(-1, manager.getCurrentRampValue()); @@ -664,7 +639,7 @@ public void testConfigTimestamp() throws InterruptedException, JSONException { @Test public void testGetConfig() throws JSONException { ConfigManager.clear(); - + JSONObject newConfigJson = new JSONObject(); int configSize = Math.abs(ran.nextInt() % 15); for (int i = 0; i < configSize; i++) { diff --git a/android-core/src/test/java/com/mparticle/internal/MParticleApiClientImplTest.java b/android-core/src/test/java/com/mparticle/internal/MParticleApiClientImplTest.java index 8ca236dad..4002f5c89 100644 --- a/android-core/src/test/java/com/mparticle/internal/MParticleApiClientImplTest.java +++ b/android-core/src/test/java/com/mparticle/internal/MParticleApiClientImplTest.java @@ -317,7 +317,7 @@ public void testSetNextAllowedRequestTime() throws Exception { assertEquals(0, client.getNextRequestTime(endpoint)); //need a delta to account for test timing variation - double delta = 50; + long delta = 50; client.getRequestHandler().setNextAllowedRequestTime(null, endpoint); assertTrue(client.getNextRequestTime(endpoint) <= client.DEFAULT_THROTTLE_MILLIS + System.currentTimeMillis()); assertTrue(client.getNextRequestTime(endpoint) > System.currentTimeMillis() + client.DEFAULT_THROTTLE_MILLIS - delta); diff --git a/android-kit-base/src/androidTest/java/com/mparticle/kits/BaseKitManagerStarted.java b/android-kit-base/src/androidTest/java/com/mparticle/kits/BaseKitManagerStarted.java index 9de2c332f..478ca2407 100644 --- a/android-kit-base/src/androidTest/java/com/mparticle/kits/BaseKitManagerStarted.java +++ b/android-kit-base/src/androidTest/java/com/mparticle/kits/BaseKitManagerStarted.java @@ -56,7 +56,7 @@ public void onSuccess(IdentityApiResult result) { } })) .build()); - mKitManager = new CustomKitManagerImpl(mContext, com.mparticle.AccessUtils.getMessageManager(), new CoreCallbackImpl(MParticle.getInstance().Internal().getConfigManager(), MParticle.getInstance().Internal().getAppStateManager(), MParticle.getInstance().Internal().getKitManager()), AccessUtils.getUploadHandler(), MParticleOptions.builder(mContext).build()); + mKitManager = new CustomKitManagerImpl(mContext, com.mparticle.AccessUtils.getMessageManager(), new CoreCallbackImpl(MParticle.getInstance().Internal().getConfigManager(), MParticle.getInstance().Internal().getAppStateManager(), MParticle.getInstance().Internal().getKitManager()), AccessUtils.getUploadHandler(), emptyMParticleOptions(mContext)); mKitManager.setKitFactory(new CustomKitFactory()); AccessUtils.setKitManager(mKitManager); latch.await(); diff --git a/scripts/startup_perf_tests.sh b/scripts/startup_perf_tests.sh new file mode 100644 index 000000000..e69de29bb diff --git a/testutils/src/main/java/com/mparticle/AccessUtils.java b/testutils/src/main/java/com/mparticle/AccessUtils.java index fbd07975a..995681464 100644 --- a/testutils/src/main/java/com/mparticle/AccessUtils.java +++ b/testutils/src/main/java/com/mparticle/AccessUtils.java @@ -54,4 +54,8 @@ public static MParticleOptions.Builder setCredentialsIfEmpty(MParticleOptions.Bu } return builder; } + + public static MParticleOptions emptyMParticleOptions(Context context) { + return MParticleOptions.builder(context).buildForInternalRestart(); + } } diff --git a/testutils/src/main/java/com/mparticle/networking/MockServer.java b/testutils/src/main/java/com/mparticle/networking/MockServer.java index c11ccbf73..3d9c558d0 100644 --- a/testutils/src/main/java/com/mparticle/networking/MockServer.java +++ b/testutils/src/main/java/com/mparticle/networking/MockServer.java @@ -417,18 +417,17 @@ private MPUrl getUrl(String identityPath, Long mpid) { } private MParticleBaseClientImpl getClient() { - ConfigManager configManager = null; if (MParticle.getInstance() != null) { - configManager = MParticle.getInstance().Internal().getConfigManager(); + mConfigManager = MParticle.getInstance().Internal().getConfigManager(); } - if (configManager != null && !configManager.getApiKey().equals(mConfigManager.getApiKey())) { - baseClient = null; - mConfigManager = configManager; - } - if (baseClient == null) { + if (mConfigManager != null && baseClient != null && mConfigManager.getApiKey() != null && !mConfigManager.getApiKey().equals(baseClient.mApiKey)) { baseClient = new MParticleBaseClientImpl(context, mConfigManager); } - return baseClient; + if (baseClient != null) { + return baseClient; + } else { + return new MParticleBaseClientImpl(context, mConfigManager); + } } private OnRequestCallback getHappyIdentityRequestCallback() { diff --git a/testutils/src/main/java/com/mparticle/testutils/BaseAbstractTest.java b/testutils/src/main/java/com/mparticle/testutils/BaseAbstractTest.java index c6f426b66..dbefd695d 100644 --- a/testutils/src/main/java/com/mparticle/testutils/BaseAbstractTest.java +++ b/testutils/src/main/java/com/mparticle/testutils/BaseAbstractTest.java @@ -285,4 +285,8 @@ private boolean checkStorageCleared(int counter) { } return true; } + + protected MParticleOptions emptyMParticleOptions(Context context) { + return com.mparticle.AccessUtils.emptyMParticleOptions(context); + } }