Skip to content

Commit

Permalink
feat: remove deprecated methods, AppConfig (mParticle#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
willpassidomo committed Mar 3, 2022
1 parent 292abb4 commit a5a934a
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 319 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions android-core/src/main/java/com/mparticle/MPServiceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions android-core/src/main/java/com/mparticle/MParticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p> Use {@link androidIdEnabled(boolean)} instead.
* <p> Use {@link MParticle#isAndroidIdEnabled()} instead.
*
*
* Query the status of Android ID collection.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -1654,6 +1657,5 @@ public KitFrameworkWrapper getKitManager() {
public MessageManager getMessageManager() {
return mMessageManager;
}

}
}
69 changes: 25 additions & 44 deletions android-core/src/main/java/com/mparticle/MParticleOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
* <p> Use {@link isAndroidIdEnabled(boolean)} instead.
* <p> 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
Expand Down Expand Up @@ -363,6 +368,7 @@ public static class Builder {
private MParticle.OperatingSystem operatingSystem;
private DataplanOptions dataplanOptions;
private Map<Class, List<Configuration>> configurations = new HashMap();
private boolean isAppDebuggable;

private Builder(Context context) {
this.context = context;
Expand Down Expand Up @@ -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 {
Expand Down
159 changes: 0 additions & 159 deletions android-core/src/main/java/com/mparticle/internal/AppConfig.java

This file was deleted.

Loading

0 comments on commit a5a934a

Please sign in to comment.