Skip to content

Commit

Permalink
core changes
Browse files Browse the repository at this point in the history
  • Loading branch information
willpassidomo committed Jul 29, 2022
1 parent e1be2fd commit 6f28ca9
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 33 deletions.
2 changes: 1 addition & 1 deletion android-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
3 changes: 2 additions & 1 deletion android-core/src/main/java/com/mparticle/MParticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

public final class IdentityHttpResponse {
private ArrayList<Error> errors = new ArrayList<Error>();
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";
Expand All @@ -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)) {
Expand Down Expand Up @@ -80,7 +86,8 @@ public List<Error> getErrors() {
return errors;
}

public long getMpId() {
@Nullable
public Long getMpId() {
return mpId;
}

Expand All @@ -93,6 +100,11 @@ public int getHttpCode() {
return httpCode;
}

@Nullable
public Exception getException() {
return exception;
}

public boolean isLoggedIn() {
return loggedIn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -104,8 +104,8 @@ void setConfigUrl(MPUrl configUrl) {
mConfigUrl = configUrl;
}

static void setSupportedKitString(String supportedKitString) {
sSupportedKits = supportedKitString;
void setSupportedKitString(String supportedKitString) {
supportedKits = supportedKitString;
}


Expand Down Expand Up @@ -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<Integer> supportedKitIds = instance.Internal().getKitManager().getSupportedKits();
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions android-core/src/test/java/com/mparticle/MockMParticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<String, String>())
.build();
Map<String, ?> 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);

}


Expand Down
2 changes: 1 addition & 1 deletion android-kit-base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import com.mparticle.messages.KitConfigMessage
class ConfiguredKitOptions : KitOptions() {
val initialConfig = mutableMapOf<Int, KitConfigMessage>()

override fun addKit(type: Class<out KitIntegration>, kitId: Int): ConfiguredKitOptions {
fun addKit(type: Class<out KitIntegration>, kitId: Int): ConfiguredKitOptions {
return addKit(type, KitConfigMessage(id = kitId))
}

override fun addKit(kitId: Int, type: Class<out KitIntegration>): KitOptions {
return addKit(type, kitId)
}

fun addKit(type: Class<out KitIntegration>, kitId: Int, includeInConfig: Boolean): ConfiguredKitOptions {
return addKit(type, KitConfigMessage(id = kitId), includeInConfig)
}
Expand All @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 0 additions & 7 deletions testutils/src/main/java/com/mparticle/mock/MockMParticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,4 @@ public MockMParticle() {
public void setIdentityApi(IdentityApi identityApi) {
this.mIdentityApi = identityApi;
}

class MockInternal extends Internal {

MockInternal() {
super();
}
}
}

0 comments on commit 6f28ca9

Please sign in to comment.