Skip to content

Commit

Permalink
Upgrade targetSdkVersion to 30 and minSdkVersion to 21
Browse files Browse the repository at this point in the history
  • Loading branch information
zihejia committed Oct 5, 2021
1 parent 72e6501 commit abc0c3a
Show file tree
Hide file tree
Showing 42 changed files with 953 additions and 4,738 deletions.
6 changes: 6 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
6 changes: 4 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ jobs:
- name: Checkout the code
uses: actions/checkout@v2
- name: Run Unit test
uses: reactivecircus/android-emulator-runner@v2
uses: reactivecircus/android-emulator-runner@v2.20.0
with:
api-level: 27
api-level: 30
profile: Nexus 6
arch: x86_64
script: ./gradlew createDebugCoverageReport
- name: Lint
run: ./gradlew lint
Expand Down
34 changes: 34 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>mixpanel-android</name>
<comment>Project mixpanel-android created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1633027344058</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
13 changes: 13 additions & 0 deletions .settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
36 changes: 29 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
buildscript {
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.android.tools.build:gradle:4.1.1'
}
}

Expand All @@ -17,19 +17,25 @@ group = GROUP
version = VERSION_NAME

android {
compileSdkVersion 27
buildToolsVersion '28.0.3'
compileSdkVersion 30
buildToolsVersion '30.0.3'

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

lintOptions {
abortOnError false
}

defaultConfig {
minSdkVersion 14
targetSdkVersion 27
targetSdkVersion 30
multiDexEnabled true
testApplicationId "com.mixpanel.android.mpmetrics"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

consumerProguardFiles 'proguard.txt'

buildConfigField "String", "MIXPANEL_VERSION", "\"${version}\""
Expand All @@ -41,6 +47,10 @@ android {
textOutput "stdout"
textReport true
}

testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
}
buildTypes {
debug{
Expand All @@ -63,7 +73,6 @@ allprojects {
}
repositories {
mavenCentral()
jcenter()
google()
}
}
Expand All @@ -73,7 +82,20 @@ allprojects {
// have to change the bit in uploadArchives that marks all dependencies as optional.
dependencies {
api 'com.google.firebase:firebase-messaging:17.3.4'
implementation("com.google.firebase:firebase-iid")
api 'com.android.installreferrer:installreferrer:1.0'
implementation "androidx.annotation:annotation:1.1.0"
implementation 'androidx.multidex:multidex:2.0.1'
androidTestImplementation 'androidx.test:core:1.4.0'

// AndroidJUnitRunner and JUnit Rules
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
androidTestUtil 'androidx.test:orchestrator:1.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.ext:truth:1.4.0'
androidTestImplementation 'com.google.truth:truth:1.0.1'
testImplementation "org.mockito:mockito-core:2.25.1"
androidTestImplementation "org.mockito:mockito-android:2.25.1"
}
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ RELEASE_REPOSITORY_URL=https://oss.sonatype.org/service/local/staging/deploy/mav
SNAPSHOT_REPOSITORY_URL=https://oss.sonatype.org/content/repositories/snapshots/

org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Thu Sep 30 12:08:33 PDT 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Process;
import android.test.AndroidTestCase;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
import androidx.test.platform.app.InstrumentationRegistry;

import com.mixpanel.android.util.Base64Coder;
import com.mixpanel.android.util.HttpService;
Expand All @@ -14,6 +17,13 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.Map;
Expand All @@ -29,7 +39,9 @@
* Created by sergioalonso on 5/16/17.
*/

public class AutomaticEventsTest extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
@SmallTest
public class AutomaticEventsTest {

private MixpanelAPI mCleanMixpanelAPI;
private static final String TOKEN = "Automatic Events Token";
Expand All @@ -44,10 +56,9 @@ public class AutomaticEventsTest extends AndroidTestCase {
private MPDbAdapter mockAdapter;
private CountDownLatch mMinRequestsLatch;

@Override
protected void setUp() throws Exception {
super.setUp();
mMockReferrerPreferences = new TestUtils.EmptyPreferences(getContext());
@Before
public void setUp() {
mMockReferrerPreferences = new TestUtils.EmptyPreferences(InstrumentationRegistry.getInstrumentation().getContext());
mTrackedEvents = 0;
mCanRunDecide = true;
mMinRequestsLatch = new CountDownLatch(2); // First Time Open and Update
Expand Down Expand Up @@ -80,9 +91,9 @@ public byte[] performRequest(String endpointUrl, Map<String, Object> params, SSL
}
};

getContext().deleteDatabase("mixpanel");
InstrumentationRegistry.getInstrumentation().getContext().deleteDatabase("mixpanel");

mockAdapter = new MPDbAdapter(getContext()) {
mockAdapter = new MPDbAdapter(InstrumentationRegistry.getInstrumentation().getContext()) {
@Override
public void cleanupEvents(String last_id, Table table, String token, boolean includeAutomaticEvents) {
if (token.equalsIgnoreCase(TOKEN)) {
Expand All @@ -102,7 +113,7 @@ public int addJSON(JSONObject j, String token, Table table, boolean isAutomaticR
}
};

final AnalyticsMessages automaticAnalyticsMessages = new AnalyticsMessages(getContext()) {
final AnalyticsMessages automaticAnalyticsMessages = new AnalyticsMessages(InstrumentationRegistry.getInstrumentation().getContext()) {

@Override
protected RemoteService getPoster() {
Expand Down Expand Up @@ -140,7 +151,7 @@ public void runDecideCheck(String token, RemoteService poster) throws RemoteServ
}
};

mCleanMixpanelAPI = new MixpanelAPI(getContext(), mMockReferrerPreferences, TOKEN, false, null) {
mCleanMixpanelAPI = new MixpanelAPI(InstrumentationRegistry.getInstrumentation().getContext(), mMockReferrerPreferences, TOKEN, false, null) {

@Override
/* package */ PersistentIdentity getPersistentIdentity(final Context context, final Future<SharedPreferences> referrerPreferences, final String token) {
Expand All @@ -166,12 +177,12 @@ AnalyticsMessages getAnalyticsMessages() {
};
}

@Override
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
mMinRequestsLatch.await(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS);
super.tearDown();
}

@Test
public void testAutomaticOneInstance() throws InterruptedException {
int calls = 3; // First Time Open, App Update, An Event One
mLatch = new CountDownLatch(calls);
Expand All @@ -185,6 +196,7 @@ public void testAutomaticOneInstance() throws InterruptedException {
assertEquals(null, mPerformRequestEvents.poll(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
}

@Test
public void testDisableAutomaticEvents() throws InterruptedException {
mCanRunDecide = false;

Expand All @@ -211,6 +223,7 @@ public void testDisableAutomaticEvents() throws InterruptedException {
assertEquals(null, mPerformRequestEvents.poll(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
}

@Test
public void testAutomaticMultipleInstances() throws InterruptedException {
final String SECOND_TOKEN = "Automatic Events Token Two";
mCanRunDecide = true;
Expand Down Expand Up @@ -243,7 +256,7 @@ public byte[] performRequest(String endpointUrl, Map<String, Object> params, SSL
}
};

final MPDbAdapter mpSecondDbAdapter = new MPDbAdapter(getContext()) {
final MPDbAdapter mpSecondDbAdapter = new MPDbAdapter(InstrumentationRegistry.getInstrumentation().getContext()) {
@Override
public void cleanupEvents(String last_id, Table table, String token, boolean includeAutomaticEvents) {
if (token.equalsIgnoreCase(SECOND_TOKEN)) {
Expand All @@ -262,7 +275,7 @@ public int addJSON(JSONObject j, String token, Table table, boolean isAutomaticR
}
};

final AnalyticsMessages mpSecondAnalyticsMessages = new AnalyticsMessages(getContext()) {
final AnalyticsMessages mpSecondAnalyticsMessages = new AnalyticsMessages(InstrumentationRegistry.getInstrumentation().getContext()) {
@Override
protected RemoteService getPoster() {
return mpSecondPoster;
Expand Down Expand Up @@ -299,7 +312,7 @@ public void runDecideCheck(String token, RemoteService poster) throws RemoteServ
}
};

MixpanelAPI mpSecondInstance = new TestUtils.CleanMixpanelAPI(getContext(), new TestUtils.EmptyPreferences(getContext()), SECOND_TOKEN) {
MixpanelAPI mpSecondInstance = new TestUtils.CleanMixpanelAPI(InstrumentationRegistry.getInstrumentation().getContext(), new TestUtils.EmptyPreferences(InstrumentationRegistry.getInstrumentation().getContext()), SECOND_TOKEN) {
@Override
AnalyticsMessages getAnalyticsMessages() {
return mpSecondAnalyticsMessages;
Expand All @@ -310,15 +323,15 @@ AnalyticsMessages getAnalyticsMessages() {
assertEquals(initialCalls, mTrackedEvents);

assertTrue(secondLatch.await(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
mLatch = new CountDownLatch(MPConfig.getInstance(getContext()).getBulkUploadLimit() - initialCalls);
for (int i = 0; i < MPConfig.getInstance(getContext()).getBulkUploadLimit() - initialCalls; i++) {
mLatch = new CountDownLatch(MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext()).getBulkUploadLimit() - initialCalls);
for (int i = 0; i < MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext()).getBulkUploadLimit() - initialCalls; i++) {
mCleanMixpanelAPI.track("Track event " + i);
}
assertTrue(mLatch.await(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));

assertEquals(AutomaticEvents.FIRST_OPEN, mPerformRequestEvents.poll(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
assertEquals(AutomaticEvents.APP_UPDATED, mPerformRequestEvents.poll(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
for (int i = 0; i < MPConfig.getInstance(getContext()).getBulkUploadLimit() - initialCalls; i++) {
for (int i = 0; i < MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext()).getBulkUploadLimit() - initialCalls; i++) {
assertEquals("Track event " + i, mPerformRequestEvents.poll(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
}

Expand Down
Loading

0 comments on commit abc0c3a

Please sign in to comment.