Skip to content

Commit

Permalink
feat: saas demo转为cdp demo (#117)
Browse files Browse the repository at this point in the history
Co-authored-by: styluo <>
  • Loading branch information
styluo authored Oct 28, 2021
1 parent df692b1 commit 58330cf
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 20 deletions.
4 changes: 2 additions & 2 deletions demos/demo-autotrack/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ dependencies {

implementation(name: 'tbs_sdk_44051', ext: 'jar')

debugApi project(':gio-sdk:autotracker')
releaseApi libraries.growingio.autotracker
debugApi project(':gio-sdk:autotracker-cdp')
releaseApi libraries.growingio.autotracker_cdp

implementation project(':demo-core')

Expand Down
2 changes: 1 addition & 1 deletion demos/demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ android {
testInstrumentationRunnerArguments listener: "com.growingio.autotest.TrackTestRunListener"

ndk {
abiFilters "armeabi", "armeabi-v7a", "x86"
abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86"
}
multiDexEnabled true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,32 @@

package com.growingio.autotest;

import com.growingio.android.sdk.autotrack.AutotrackConfiguration;
import com.growingio.android.sdk.autotrack.CdpAutotrackConfiguration;

import static com.growingio.autotest.help.MockServer.MOCK_SERVER_HOST;

public class TestTrackConfiguration {
public static final String TEST_PROJECT_ID = "testProjectId";
public static final String TEST_URL_SCHEME = "testUrlScheme";
public static final String TEST_DATA_SOURCE_ID = "testDataSourceId";

private TestTrackConfiguration() {
}

public static AutotrackConfiguration getTestConfig() {
AutotrackConfiguration configuration = new AutotrackConfiguration(TEST_PROJECT_ID, TEST_URL_SCHEME);
public static CdpAutotrackConfiguration getTestConfig() {
CdpAutotrackConfiguration configuration = new CdpAutotrackConfiguration(TEST_PROJECT_ID, TEST_URL_SCHEME);
configuration.setUploadExceptionEnabled(false)
.setDataCollectionServerHost(MOCK_SERVER_HOST)
.setDataSourceId(TEST_DATA_SOURCE_ID)
.setDebugEnabled(true);
return configuration;
}

public static AutotrackConfiguration getTestConfig(String urlScheme) {
AutotrackConfiguration configuration = new AutotrackConfiguration(TEST_PROJECT_ID, urlScheme);
public static CdpAutotrackConfiguration getTestConfig(String urlScheme) {
CdpAutotrackConfiguration configuration = new CdpAutotrackConfiguration(TEST_PROJECT_ID, urlScheme);
configuration.setUploadExceptionEnabled(false)
.setDataCollectionServerHost(MOCK_SERVER_HOST)
.setDataSourceId(TEST_DATA_SOURCE_ID)
.setDebugEnabled(true);
return configuration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.gio.test.three.DemoApplication;
import com.gio.test.three.autotrack.activity.ViewImpressionActivity;
import com.google.common.truth.Truth;
import com.growingio.android.sdk.autotrack.AutotrackConfiguration;
import com.growingio.android.sdk.autotrack.CdpAutotrackConfiguration;
import com.growingio.android.sdk.autotrack.GrowingAutotracker;
import com.growingio.android.sdk.track.events.PageLevelCustomEvent;
import com.growingio.autotest.EventsTest;
Expand Down Expand Up @@ -93,7 +93,7 @@ public void impressionEventTest() {
@Test
public void invalidArgumentsTest() {
ActivityScenario<ViewImpressionActivity> scenario = ActivityScenario.launch(ViewImpressionActivity.class);
AutotrackConfiguration configuration = new AutotrackConfiguration("xxx", "xxx");
CdpAutotrackConfiguration configuration = new CdpAutotrackConfiguration("xxx", "xxx");
configuration.setImpressionScale(-1);
Truth.assertThat(configuration.getImpressionScale()).isEqualTo(0);
configuration.setImpressionScale(1.12F);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ public class CircleServiceTest extends WebServicesTest {
@BeforeAppOnCreate
public static void beforeAppOnCreate() {
DataHelper.deleteEventsDatabase();
DemoApplication.setConfiguration(TestTrackConfiguration.getTestConfig("growing.d80871b41ef40518"));
DemoApplication.setConfiguration(TestTrackConfiguration.getTestConfig("growing.401dfd8bba45afda"));
}

@Test
public void circleServiceTest() {
String uri = "growing.d80871b41ef40518://growingio/webservice?serviceType=circle&wsUrl=" + Uri.encode(getWsUrl());
String uri = "growing.401dfd8bba45afda://growingio/webservice?serviceType=circle&wsUrl=" + Uri.encode(getWsUrl());
Intent intent = new Intent();
intent.setData(Uri.parse(uri));
ActivityScenario.launch(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void setup() {
@BeforeAppOnCreate
public static void beforeAppOnCreate() {
DataHelper.deleteEventsDatabase();
DemoApplication.setConfiguration(TestTrackConfiguration.getTestConfig("growing.d80871b41ef40518"));
DemoApplication.setConfiguration(TestTrackConfiguration.getTestConfig("growing.401dfd8bba45afda"));
}

protected String getWsUrl() {
Expand Down Expand Up @@ -126,7 +126,7 @@ public void onMessage(WebSocket webSocket, String text) {
});
mMockWebServer.enqueue(ready);

String uri = "growing.d80871b41ef40518://growingio/webservice?serviceType=debugger&wsUrl=" + Uri.encode(getWsUrl());
String uri = "growing.401dfd8bba45afda://growingio/webservice?serviceType=debugger&wsUrl=" + Uri.encode(getWsUrl());
Intent intent = new Intent();
intent.setData(Uri.parse(uri));
ActivityScenario.launch(intent);
Expand Down
4 changes: 2 additions & 2 deletions demos/demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="growing.d80871b41ef40518" />
<data android:scheme="growing.401dfd8bba45afda" />

<action android:name="android.intent.action.VIEW" />

Expand Down Expand Up @@ -127,4 +127,4 @@
</activity>
</application>

</manifest>
</manifest>
40 changes: 36 additions & 4 deletions demos/demo/src/main/java/com/gio/test/three/DemoApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
import android.content.Context;
import android.os.Build;
import android.os.Process;
import android.os.StrictMode;
import android.support.multidex.MultiDexApplication;
import android.util.Log;
import android.webkit.WebView;

import androidx.annotation.RequiresApi;

import com.growingio.android.oaid.OaidLibraryGioModule;
import com.growingio.android.sdk.autotrack.AutotrackConfiguration;
import com.growingio.android.sdk.autotrack.CdpAutotrackConfiguration;
import com.growingio.android.sdk.autotrack.GrowingAutotracker;
import com.growingio.android.sdk.track.events.helper.EventExcludeFilter;
import com.growingio.android.sdk.track.events.helper.FieldIgnoreFilter;
Expand All @@ -40,9 +41,9 @@ public class DemoApplication extends MultiDexApplication {
private static final String TAG = "DemoApplication";

private static boolean sIsAutotracker = true;
private static AutotrackConfiguration sConfiguration;
private static CdpAutotrackConfiguration sConfiguration;

public static void setConfiguration(AutotrackConfiguration configuration) {
public static void setConfiguration(CdpAutotrackConfiguration configuration) {
sConfiguration = configuration;
}

Expand Down Expand Up @@ -79,14 +80,19 @@ public void onViewInitFinished(boolean b) {
}

if (sConfiguration == null) {
sConfiguration = new AutotrackConfiguration("bfc5d6a3693a110d", "growing.d80871b41ef40518")
sConfiguration = new CdpAutotrackConfiguration("91eaf9b283361032", "growing.401dfd8bba45afda")
.setDataSourceId("91373f31ba946d28")
.setDataCollectionServerHost("http://uat-api.growingio.com")
.setUploadExceptionEnabled(false)
.setDebugEnabled(true)
.setDataCollectionEnabled(true)
.setExcludeEvent(EventExcludeFilter.of(EventExcludeFilter.EVENT_MASK_TRIGGER))
.setIgnoreField(FieldIgnoreFilter.of(FieldIgnoreFilter.FIELD_IGNORE_ALL))
.setPreloadComponent(new OaidLibraryGioModule());
}

enableStrictMode();

long startTime = System.currentTimeMillis();
GrowingAutotracker.startWithConfiguration(this, sConfiguration);
Log.d(TAG, "start time: " + (System.currentTimeMillis() - startTime));
Expand All @@ -109,4 +115,30 @@ private boolean isMainProcess() {
}
return false;
}

private void enableStrictMode() {
StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder()
.detectNetwork()
.detectCustomSlowCalls()
.permitDiskReads()
.permitDiskWrites()
.penaltyLog();
StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.detectLeakedRegistrationObjects()
.detectActivityLeaks()
.penaltyLog();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
threadPolicyBuilder.detectResourceMismatches();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
threadPolicyBuilder.detectUnbufferedIo();
vmPolicyBuilder.detectContentUriWithoutPermission();
}

StrictMode.setThreadPolicy(threadPolicyBuilder.build());
StrictMode.setVmPolicy(vmPolicyBuilder.build());
}
}

0 comments on commit 58330cf

Please sign in to comment.