diff --git a/android-core/build.gradle b/android-core/build.gradle index 5d0317568..5138920ad 100644 --- a/android-core/build.gradle +++ b/android-core/build.gradle @@ -169,7 +169,7 @@ dependencies { androidTestImplementation "androidx.lifecycle:lifecycle-common:2.5.0" androidTestImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2-native-mt" - androidTestImplementation("com.mparticle.internal:mocking:1.3.0") + androidTestImplementation("com.mparticle.internal:mocking:1.4.0") androidTestImplementation 'androidx.test:rules:1.4.0' } diff --git a/android-core/src/main/java/com/mparticle/MParticle.java b/android-core/src/main/java/com/mparticle/MParticle.java index 7be7e8a10..d9c52976d 100644 --- a/android-core/src/main/java/com/mparticle/MParticle.java +++ b/android-core/src/main/java/com/mparticle/MParticle.java @@ -1634,7 +1634,8 @@ public interface ResetListener { * @hidden */ public class Internal { - protected Internal() { } + + private Internal() { } /** * The ConfigManager is tasked with incorporating server-based, run-time, and XML configuration, diff --git a/android-core/src/main/java/com/mparticle/identity/IdentityApi.java b/android-core/src/main/java/com/mparticle/identity/IdentityApi.java index 7633a12ee..c68293f0a 100644 --- a/android-core/src/main/java/com/mparticle/identity/IdentityApi.java +++ b/android-core/src/main/java/com/mparticle/identity/IdentityApi.java @@ -392,7 +392,7 @@ public void run() { } } catch (Exception ex) { ConfigManager.setIdentityRequestInProgress(false); - task.setFailed(new IdentityHttpResponse(IdentityApi.UNKNOWN_ERROR, ex.toString())); + task.setFailed(new IdentityHttpResponse(IdentityApi.UNKNOWN_ERROR, ex)); } } } diff --git a/android-core/src/main/java/com/mparticle/identity/IdentityHttpResponse.java b/android-core/src/main/java/com/mparticle/identity/IdentityHttpResponse.java index f1d20b675..90dddd46b 100644 --- a/android-core/src/main/java/com/mparticle/identity/IdentityHttpResponse.java +++ b/android-core/src/main/java/com/mparticle/identity/IdentityHttpResponse.java @@ -14,10 +14,11 @@ public final class IdentityHttpResponse { private ArrayList errors = new ArrayList(); - private long mpId; + private Long mpId = null; private String context; private int httpCode; private boolean loggedIn; + private Exception exception; @NonNull public static final String MPID = "mpid"; @NonNull public static final String CONTEXT = "context"; @@ -42,6 +43,11 @@ public IdentityHttpResponse(int code, @NonNull String errorString) { this.errors.add(new Error(UNKNOWN, errorString)); } + public IdentityHttpResponse(int code, @NonNull Exception exception) { + this(code, exception.getMessage()); + this.exception = exception; + } + public IdentityHttpResponse(int httpCode, @Nullable JSONObject jsonObject) throws JSONException { this.httpCode = httpCode; if (!MPUtility.isEmpty(jsonObject)) { @@ -80,7 +86,8 @@ public List getErrors() { return errors; } - public long getMpId() { + @Nullable + public Long getMpId() { return mpId; } @@ -93,6 +100,11 @@ public int getHttpCode() { return httpCode; } + @Nullable + public Exception getException() { + return exception; + } + public boolean isLoggedIn() { return loggedIn; } diff --git a/android-core/src/main/java/com/mparticle/identity/MParticleIdentityClientImpl.java b/android-core/src/main/java/com/mparticle/identity/MParticleIdentityClientImpl.java index b72e2b3ab..9a8b395bc 100644 --- a/android-core/src/main/java/com/mparticle/identity/MParticleIdentityClientImpl.java +++ b/android-core/src/main/java/com/mparticle/identity/MParticleIdentityClientImpl.java @@ -250,7 +250,7 @@ private IdentityHttpResponse parseIdentityResponse(int httpCode, JSONObject json } return httpResponse; } catch (JSONException e) { - return new IdentityHttpResponse(httpCode, e.getMessage()); + return new IdentityHttpResponse(httpCode, e); } } diff --git a/android-core/src/main/java/com/mparticle/internal/MParticleApiClient.java b/android-core/src/main/java/com/mparticle/internal/MParticleApiClient.java index fb6df0ab3..cb808643d 100644 --- a/android-core/src/main/java/com/mparticle/internal/MParticleApiClient.java +++ b/android-core/src/main/java/com/mparticle/internal/MParticleApiClient.java @@ -30,7 +30,7 @@ public AliasNetworkResponse(int responseCode) { this(responseCode, null); } - AliasNetworkResponse(int responseCode, String errorMessage) { + public AliasNetworkResponse(int responseCode, String errorMessage) { this.responseCode = responseCode; this.errorMessage = errorMessage; } diff --git a/android-core/src/main/java/com/mparticle/internal/MParticleApiClientImpl.java b/android-core/src/main/java/com/mparticle/internal/MParticleApiClientImpl.java index 609360579..72c4096a9 100644 --- a/android-core/src/main/java/com/mparticle/internal/MParticleApiClientImpl.java +++ b/android-core/src/main/java/com/mparticle/internal/MParticleApiClientImpl.java @@ -68,7 +68,7 @@ public class MParticleApiClientImpl extends MParticleBaseClientImpl implements M private final String mApiKey; private final Context mContext; Integer mDeviceRampNumber = null; - private static String sSupportedKits; + private String supportedKits; private JSONObject mCurrentCookies; /** @@ -104,8 +104,8 @@ void setConfigUrl(MPUrl configUrl) { mConfigUrl = configUrl; } - static void setSupportedKitString(String supportedKitString) { - sSupportedKits = supportedKitString; + void setSupportedKitString(String supportedKitString) { + supportedKits = supportedKitString; } @@ -415,7 +415,7 @@ private void checkRampValue() throws MPRampException { } private String getSupportedKitString(){ - if (sSupportedKits == null) { + if (supportedKits == null) { MParticle instance = MParticle.getInstance(); if (instance != null) { Set supportedKitIds = instance.Internal().getKitManager().getSupportedKits(); @@ -429,13 +429,13 @@ private String getSupportedKitString(){ buffer.append(","); } } - sSupportedKits = buffer.toString(); + supportedKits = buffer.toString(); } } else { - sSupportedKits = ""; + supportedKits = ""; } } - return sSupportedKits; + return supportedKits; } public void setCookies(JSONObject serverCookies) { diff --git a/android-core/src/main/java/com/mparticle/internal/UploadHandler.java b/android-core/src/main/java/com/mparticle/internal/UploadHandler.java index 2e2288fb4..ce646509b 100644 --- a/android-core/src/main/java/com/mparticle/internal/UploadHandler.java +++ b/android-core/src/main/java/com/mparticle/internal/UploadHandler.java @@ -2,7 +2,6 @@ import android.content.Context; import android.content.SharedPreferences; -import android.os.Handler; import android.os.Looper; import android.os.Message; @@ -17,7 +16,6 @@ import com.mparticle.segmentation.SegmentListener; import org.json.JSONException; -import org.json.JSONObject; import java.io.IOException; import java.net.MalformedURLException; diff --git a/android-core/src/main/java/com/mparticle/networking/NetworkOptionsManager.java b/android-core/src/main/java/com/mparticle/networking/NetworkOptionsManager.java index 762909b23..4c30b960f 100644 --- a/android-core/src/main/java/com/mparticle/networking/NetworkOptionsManager.java +++ b/android-core/src/main/java/com/mparticle/networking/NetworkOptionsManager.java @@ -39,7 +39,7 @@ public static NetworkOptions validateAndResolve(NetworkOptions networkOptions) { } - static NetworkOptions defaultNetworkOptions() { + public static NetworkOptions defaultNetworkOptions() { return NetworkOptions.builder() .addDomainMapping(DomainMapping.identityMapping(getDefaultUrl(Endpoint.IDENTITY)) .setCertificates(defaultCertificates) diff --git a/android-core/src/test/java/com/mparticle/MockMParticle.java b/android-core/src/test/java/com/mparticle/MockMParticle.java index 2aa3b49e1..4845bbf3c 100644 --- a/android-core/src/test/java/com/mparticle/MockMParticle.java +++ b/android-core/src/test/java/com/mparticle/MockMParticle.java @@ -19,7 +19,7 @@ public class MockMParticle extends MParticle { public MockMParticle() { mAppContext = new MockContext(); - mInternal = new Internal(); + mInternal = Mockito.mock(Internal.class); mConfigManager = Mockito.mock(ConfigManager.class); mKitManager = Mockito.mock(KitFrameworkWrapper.class); mAppStateManager = Mockito.mock(AppStateManager.class); @@ -29,12 +29,13 @@ public MockMParticle() { mMessageManager = Mockito.mock(MessageManager.class); mMessaging = Mockito.mock(MPMessagingAPI.class); mMedia = Mockito.mock(MPMediaAPI.class); - mIdentityApi = new IdentityApi(new MockContext(), mAppStateManager, mMessageManager, Internal().getConfigManager(), mKitManager, OperatingSystem.ANDROID); Mockito.when(mKitManager.updateKits(Mockito.any())).thenReturn(new KitsLoadedCallback()); - MPEvent event = new MPEvent.Builder("this") - .customAttributes(new HashMap()) - .build(); - Map attributes = event.getCustomAttributes(); + Mockito.when(mInternal.getAppStateManager()).thenReturn(mAppStateManager); + Mockito.when(mInternal.getConfigManager()).thenReturn(mConfigManager); + Mockito.when(mInternal.getKitManager()).thenReturn(mKitManager); + Mockito.when(mInternal.getMessageManager()).thenReturn(mMessageManager); + mIdentityApi = new IdentityApi(new MockContext(), mAppStateManager, mMessageManager, Internal().getConfigManager(), mKitManager, OperatingSystem.ANDROID); + } diff --git a/android-kit-base/build.gradle b/android-kit-base/build.gradle index 038a89e62..b83945fba 100644 --- a/android-kit-base/build.gradle +++ b/android-kit-base/build.gradle @@ -75,5 +75,5 @@ dependencies { testImplementation 'androidx.legacy:legacy-support-v4:1.0.0' testImplementation project(':testutils') - androidTestImplementation "com.mparticle.internal:mocking:1.3.0" + androidTestImplementation "com.mparticle.internal:mocking:1.4.0" } diff --git a/android-kit-base/src/androidTest/kotlin/com/mparticle/kits/ConfiguredKitOptions.kt b/android-kit-base/src/androidTest/kotlin/com/mparticle/kits/ConfiguredKitOptions.kt index 8f6f2a5b7..176a3bc87 100644 --- a/android-kit-base/src/androidTest/kotlin/com/mparticle/kits/ConfiguredKitOptions.kt +++ b/android-kit-base/src/androidTest/kotlin/com/mparticle/kits/ConfiguredKitOptions.kt @@ -5,10 +5,14 @@ import com.mparticle.messages.KitConfigMessage class ConfiguredKitOptions : KitOptions() { val initialConfig = mutableMapOf() - override fun addKit(type: Class, kitId: Int): ConfiguredKitOptions { + fun addKit(type: Class, kitId: Int): ConfiguredKitOptions { return addKit(type, KitConfigMessage(id = kitId)) } + override fun addKit(kitId: Int, type: Class): KitOptions { + return addKit(type, kitId) + } + fun addKit(type: Class, kitId: Int, includeInConfig: Boolean): ConfiguredKitOptions { return addKit(type, KitConfigMessage(id = kitId), includeInConfig) } @@ -17,7 +21,7 @@ class ConfiguredKitOptions : KitOptions() { if (includeInConfig) { initialConfig[config.id] = config } - super.addKit(type, config.id) + super.addKit(config.id, type) return this } } diff --git a/android-kit-base/src/main/kotlin/com/mparticle/internal/AccessUtil.kt b/android-kit-base/src/main/kotlin/com/mparticle/internal/AccessUtil.kt new file mode 100644 index 000000000..2ebd76543 --- /dev/null +++ b/android-kit-base/src/main/kotlin/com/mparticle/internal/AccessUtil.kt @@ -0,0 +1,8 @@ +package com.mparticle.internal + +import com.mparticle.MParticle +import com.mparticle.kits.KitManagerImpl + +object AccessUtil { + fun kitManager(): KitManagerImpl = (MParticle.getInstance()?.Internal()?.kitManager as KitFrameworkWrapper).mKitManager as KitManagerImpl +} diff --git a/testutils/src/main/java/com/mparticle/mock/MockMParticle.java b/testutils/src/main/java/com/mparticle/mock/MockMParticle.java index f240ec83f..51e066372 100644 --- a/testutils/src/main/java/com/mparticle/mock/MockMParticle.java +++ b/testutils/src/main/java/com/mparticle/mock/MockMParticle.java @@ -29,11 +29,4 @@ public MockMParticle() { public void setIdentityApi(IdentityApi identityApi) { this.mIdentityApi = identityApi; } - - class MockInternal extends Internal { - - MockInternal() { - super(); - } - } }