Skip to content

Commit

Permalink
1. network update
Browse files Browse the repository at this point in the history
2. plugin okhttp and xcrash update
  • Loading branch information
hui.zhao authored and hui.zhao committed Nov 14, 2019
1 parent bd2ac30 commit e52819c
Show file tree
Hide file tree
Showing 42 changed files with 794 additions and 193 deletions.
10 changes: 5 additions & 5 deletions android-godeye-monitor-no-op/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 28
compileSdkVersion Integer.parseInt(COMPILE_SDK_VERSION)
buildToolsVersion BUILD_TOOLS_VERSION

defaultConfig {
minSdkVersion 16
targetSdkVersion 28
minSdkVersion Integer.parseInt(MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(TARGET_SDK_VERSION)
versionCode 1
versionName "1.0"
}
Expand All @@ -18,8 +20,6 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion = '28.0.3'

}

dependencies {
Expand Down
11 changes: 5 additions & 6 deletions android-godeye-monitor/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 28
compileSdkVersion Integer.parseInt(COMPILE_SDK_VERSION)
buildToolsVersion BUILD_TOOLS_VERSION

defaultConfig {
minSdkVersion 16
targetSdkVersion 28
minSdkVersion Integer.parseInt(MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(TARGET_SDK_VERSION)
versionCode 1
versionName "1.0"

Expand All @@ -26,18 +27,16 @@ android {
lintOptions {
abortOnError false
}
buildToolsVersion = '28.0.3'
}

dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'io.reactivex.rxjava2:rxjava:2.2.2'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation project(':android-godeye')
implementation project(':android-godeye-toolbox')
api 'com.koushikdutta.async:androidasync:2.2.1'
implementation "com.github.nisrulz:easydeviceinfo-base:2.4.1"
implementation 'com.iqiyi.xcrash:xcrash-android-lib:2.4.6'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.List;
import java.util.Map;

import cn.hikyson.android.godeye.toolbox.network.HttpContent;
import cn.hikyson.godeye.core.internal.modules.network.NetworkContent;
import cn.hikyson.godeye.core.internal.modules.network.NetworkInfo;
import cn.hikyson.godeye.core.internal.modules.network.NetworkTime;
Expand Down Expand Up @@ -50,18 +49,7 @@ public static NetworkSummaryInfo convert(NetworkInfo networkInfo) {
NetworkSummaryInfo networkSummaryInfo = new NetworkSummaryInfo();
networkSummaryInfo.isSuccessful = networkInfo.isSuccessful;
networkSummaryInfo.message = networkInfo.message;
if (networkInfo.networkContent instanceof HttpContent) {
HttpContent httpContent = (HttpContent) networkInfo.networkContent;
if (httpContent.httpResponse != null && networkInfo.isSuccessful) {
networkSummaryInfo.message = httpContent.httpResponse.message;
if (!isSuccessful(httpContent.httpResponse.code)) {
networkSummaryInfo.isSuccessful = false;
}
}
networkSummaryInfo.networkContent = convertHttpContentToSummaryContent(httpContent);
} else {
networkSummaryInfo.networkContent = convertUnknownProtocolContentToSummaryContent(networkInfo.networkContent);
}
networkSummaryInfo.networkContent = convertNetworkContentToSummaryContent(networkInfo.networkContent);
networkSummaryInfo.summary = networkInfo.summary;
networkSummaryInfo.totalTime = networkInfo.networkTime == null ? 0 : networkInfo.networkTime.totalTimeMillis;
networkSummaryInfo.networkTime = convertToTimePairs(networkInfo.networkTime);
Expand All @@ -80,21 +68,10 @@ private static List<TimePair> convertToTimePairs(NetworkTime networkTime) {
return networkTimeList;
}

private static Content convertHttpContentToSummaryContent(HttpContent httpContent) {
if (httpContent != null) {
return new Content(httpContent.getClass().getSimpleName(), httpContent.httpRequest.getStandardFormat(), httpContent.httpResponse.getStandardFormat());
}
return new Content("NULL", "NULL", "NULL");
}

private static Content convertUnknownProtocolContentToSummaryContent(NetworkContent networkContent) {
private static Content convertNetworkContentToSummaryContent(NetworkContent networkContent) {
if (networkContent != null) {
return new Content(networkContent.getClass().getSimpleName(), "Request unknown network protocol: " + networkContent.getClass().getSimpleName(), "Response unknown network protocol:" + networkContent.getClass().getSimpleName());
return new Content(networkContent.getClass().getSimpleName(), networkContent.requestToString(), networkContent.responseToString());
}
return new Content("NULL", "NULL", "NULL");
}

private static boolean isSuccessful(int code) {
return code >= 200 && code < 300;
}
}
21 changes: 11 additions & 10 deletions android-godeye-sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ apply plugin: 'com.android.application'
//}

android {
compileSdkVersion 28
compileSdkVersion Integer.parseInt(COMPILE_SDK_VERSION)
buildToolsVersion BUILD_TOOLS_VERSION

defaultConfig {
applicationId 'cn.hikyson.android.godeye.sample'
minSdkVersion 16
targetSdkVersion 28
minSdkVersion Integer.parseInt(MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(TARGET_SDK_VERSION)
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -29,24 +31,23 @@ android {
// resValue("integer", "CN_HIKYSON_ANDROID_GODEYE_MONITOR_PORT", project.ext.EXT_ANDROID_GODEYE_MONITOR_PORT)
}
}
buildToolsVersion = '28.0.3'
}

dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.squareup.okhttp3:okhttp:3.14.2'
implementation project(':android-godeye-monitor')
implementation project(':android-godeye')
implementation project(':android-godeye-toolbox')
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.iqiyi.xcrash:xcrash-android-lib:2.4.6'
implementation project(':android-godeye-toolboxes:android-godeye-okhttp')
implementation project(':android-godeye-toolboxes:android-godeye-xcrash')
}

apply plugin: 'cn.hikyson.methodcanary.plugin'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.Objects;
import java.util.Random;

import cn.hikyson.android.godeye.toolbox.network.GodEyePluginOkNetwork;
import cn.hikyson.android.godeye.okhttp.GodEyePluginOkNetwork;
import cn.hikyson.godeye.core.GodEyeHelper;
import cn.hikyson.godeye.core.exceptions.UninstallException;
import cn.hikyson.godeye.core.internal.modules.startup.StartupInfo;
Expand All @@ -25,7 +25,6 @@
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import xcrash.XCrash;

public class ToolsFragment extends Fragment {

Expand Down Expand Up @@ -68,7 +67,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
throw new IllegalStateException("This is a crash made by AndroidGodEye " + index + ".");
});
view.findViewById(R.id.fragment_tools_native_crash_bt).setOnClickListener(v -> {
XCrash.testNativeCrash(false);
// XCrash.testNativeCrash(false);
});
view.findViewById(R.id.fragment_tools_pageload_bt).setOnClickListener(v -> {
Intent intent = new Intent(ToolsFragment.this.getActivity(), SecondActivity.class);
Expand Down
4 changes: 0 additions & 4 deletions android-godeye-toolbox/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions android-godeye-toolbox/gradle.properties

This file was deleted.

2 changes: 0 additions & 2 deletions android-godeye-toolbox/src/main/res/values/strings.xml

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 28
compileSdkVersion Integer.parseInt(COMPILE_SDK_VERSION)
buildToolsVersion BUILD_TOOLS_VERSION


defaultConfig {
minSdkVersion 16
targetSdkVersion 28
minSdkVersion Integer.parseInt(MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(TARGET_SDK_VERSION)
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}

compileOptions {
targetCompatibility = "8"
sourceCompatibility = "8"
consumerProguardFiles 'consumer-rules.pro'
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion = '28.0.3'

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'

implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.okhttp3:okhttp:3.14.2'
implementation project(':android-godeye')
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=godeye-okhttp
POM_NAME=God Eye Okhttp
POM_PACKAGING=aar
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.hikyson.android;
package cn.hikyson.android.godeye.okhttp;

import android.content.Context;

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

Expand All @@ -17,10 +18,10 @@
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

assertEquals("cn.hikyson.android.godeye.toolbox.test", appContext.getPackageName());
assertEquals("cn.hikyson.android.godeye.okhttp.test", appContext.getPackageName());
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.hikyson.android.godeye.toolbox"/>
package="cn.hikyson.android.godeye.okhttp" />
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.hikyson.android.godeye.toolbox.network;
package cn.hikyson.android.godeye.okhttp;

import okhttp3.Call;
import okhttp3.EventListener;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package cn.hikyson.android.godeye.toolbox.network;
package cn.hikyson.android.godeye.okhttp;

import androidx.annotation.Keep;

import java.io.Serializable;

import cn.hikyson.godeye.core.internal.modules.network.NetworkContent;

@Keep
public class HttpContent implements NetworkContent {
public class HttpContent implements NetworkContent, Serializable {
public HttpRequest httpRequest;
public HttpResponse httpResponse;

Expand All @@ -14,6 +16,16 @@ public HttpContent() {
httpResponse = new HttpResponse();
}

@Override
public String requestToString() {
return httpRequest == null ? "NULL" : httpRequest.getStandardFormat();
}

@Override
public String responseToString() {
return httpResponse == null ? "NULL" : httpResponse.getStandardFormat();
}

@Override
public String toString() {
return "HttpContent{" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.hikyson.android.godeye.toolbox.network;
package cn.hikyson.android.godeye.okhttp;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.hikyson.android.godeye.toolbox.network;
package cn.hikyson.android.godeye.okhttp;

import androidx.annotation.Keep;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.hikyson.android.godeye.toolbox.network;
package cn.hikyson.android.godeye.okhttp;

import androidx.annotation.Keep;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.hikyson.android.godeye.toolbox.network;
package cn.hikyson.android.godeye.okhttp;

import java.io.EOFException;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.hikyson.android.godeye.toolbox.network;
package cn.hikyson.android.godeye.okhttp;


import java.io.IOException;
Expand All @@ -9,10 +9,8 @@
import java.util.HashMap;
import java.util.List;

import cn.hikyson.godeye.core.GodEye;
import cn.hikyson.godeye.core.GodEyeHelper;
import cn.hikyson.godeye.core.exceptions.UninstallException;
import cn.hikyson.godeye.core.internal.Producer;
import cn.hikyson.godeye.core.internal.modules.network.NetworkInfo;
import cn.hikyson.godeye.core.internal.modules.network.NetworkTime;
import okhttp3.Call;
Expand Down Expand Up @@ -165,9 +163,15 @@ public void responseBodyEnd(Call call, long byteCount) {
public void callEnd(Call call) {
super.callEnd(call);
this.mNetworkInfo.networkTime.totalTimeMillis = System.currentTimeMillis() - mCallStartTimeMillis;
mNetworkInfo.isSuccessful = true;
mNetworkInfo.message = "";
mNetworkInfo.networkContent = mHttpContentTimeMapping.removeAndGetRecord(call);
if (mNetworkInfo.networkContent != null) {
if (mNetworkInfo.networkContent.httpResponse != null) {
mNetworkInfo.isSuccessful = isSuccessful(mNetworkInfo.networkContent.httpResponse.code);
}
if (mNetworkInfo.networkContent.httpResponse != null) {
mNetworkInfo.message = mNetworkInfo.networkContent.httpResponse.message;
}
}
try {
GodEyeHelper.onNetworkEnd(mNetworkInfo);
} catch (UninstallException e) {
Expand All @@ -188,4 +192,8 @@ public void callFailed(Call call, IOException ioe) {
e.printStackTrace();
}
}

private static boolean isSuccessful(int code) {
return code >= 200 && code < 300;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">android-godeye-okhttp</string>
</resources>
Loading

0 comments on commit e52819c

Please sign in to comment.