Skip to content

Commit 063b86d

Browse files
committed
Merge commit 'b1d1ea72aadbf3b1455b5816bfc4135ae7ce45ba'
2 parents dd88376 + b1d1ea7 commit 063b86d

35 files changed

+1622
-133
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ dependency-reduced-pom.xml
3939
buildNumber.properties
4040

4141
local.properties
42+
buildSrc

CoreLibrary/src/main/java/com/didi/virtualapk/internal/VAInstrumentation.java

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.didi.virtualapk.internal;
1818

1919
import android.app.Activity;
20+
import android.app.Fragment;
2021
import android.app.Instrumentation;
2122
import android.content.ActivityNotFoundException;
2223
import android.content.ComponentName;
@@ -91,6 +92,82 @@ private ActivityResult realExecStartActivity(
9192
return result;
9293
}
9394

95+
public ActivityResult execStartActivity(
96+
Context who, IBinder contextThread, IBinder token, Fragment target,
97+
Intent intent, int requestCode, Bundle options) {
98+
mPluginManager.getComponentsHandler().transformIntentToExplicitAsNeeded(intent);
99+
// null component is an implicitly intent
100+
if (intent.getComponent() != null) {
101+
Log.i(TAG, String.format("execStartActivity[%s : %s]", intent.getComponent().getPackageName(),
102+
intent.getComponent().getClassName()));
103+
// resolve intent with Stub Activity if needed
104+
this.mPluginManager.getComponentsHandler().markIntentIfNeeded(intent);
105+
}
106+
107+
ActivityResult result = realExecStartActivity(who, contextThread, token, target,
108+
intent, requestCode, options);
109+
110+
return result;
111+
112+
}
113+
114+
private ActivityResult realExecStartActivity(
115+
Context who, IBinder contextThread, IBinder token, Fragment target,
116+
Intent intent, int requestCode, Bundle options) {
117+
ActivityResult result = null;
118+
try {
119+
Class[] parameterTypes = {Context.class, IBinder.class, IBinder.class, Fragment.class, Intent.class,
120+
int.class, Bundle.class};
121+
result = (ActivityResult)ReflectUtil.invoke(Instrumentation.class, mBase,
122+
"execStartActivity", parameterTypes,
123+
who, contextThread, token, target, intent, requestCode, options);
124+
} catch (Exception e) {
125+
if (e.getCause() instanceof ActivityNotFoundException) {
126+
throw (ActivityNotFoundException) e.getCause();
127+
}
128+
e.printStackTrace();
129+
}
130+
131+
return result;
132+
}
133+
134+
private ActivityResult realExecStartActivity(
135+
Context who, IBinder contextThread, IBinder token, String target,
136+
Intent intent, int requestCode, Bundle options) {
137+
ActivityResult result = null;
138+
try {
139+
Class[] parameterTypes = {Context.class, IBinder.class, IBinder.class, String.class, Intent.class,
140+
int.class, Bundle.class};
141+
result = (ActivityResult)ReflectUtil.invoke(Instrumentation.class, mBase,
142+
"execStartActivity", parameterTypes,
143+
who, contextThread, token, target, intent, requestCode, options);
144+
} catch (Exception e) {
145+
if (e.getCause() instanceof ActivityNotFoundException) {
146+
throw (ActivityNotFoundException) e.getCause();
147+
}
148+
e.printStackTrace();
149+
}
150+
151+
return result;
152+
}
153+
154+
public ActivityResult execStartActivity(
155+
Context who, IBinder contextThread, IBinder token, String target,
156+
Intent intent, int requestCode, Bundle options) {
157+
mPluginManager.getComponentsHandler().transformIntentToExplicitAsNeeded(intent);
158+
// null component is an implicitly intent
159+
if (intent.getComponent() != null) {
160+
Log.i(TAG, String.format("execStartActivity[%s : %s]", intent.getComponent().getPackageName(),
161+
intent.getComponent().getClassName()));
162+
// resolve intent with Stub Activity if needed
163+
this.mPluginManager.getComponentsHandler().markIntentIfNeeded(intent);
164+
}
165+
166+
ActivityResult result = realExecStartActivity(who, contextThread, token, target,
167+
intent, requestCode, options);
168+
return null;
169+
}
170+
94171
@Override
95172
public Activity newActivity(ClassLoader cl, String className, Intent intent) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
96173
try {

PluginDemo/app/build.gradle

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,27 @@ android {
1212
versionCode 1
1313
}
1414

15+
flavorDimensions "demo"
1516
productFlavors {
1617
beijing {
18+
dimension "demo"
1719
applicationId 'com.didi.virtualapk.demo'
1820
}
1921
shanghai {
22+
dimension "demo"
2023
applicationId 'com.didi.virtualapk.demo'
2124
}
2225
}
2326

27+
signingConfigs {
28+
release {
29+
storeFile file("../../keystore/test.keystore")
30+
storePassword "test123456"
31+
keyAlias "test"
32+
keyPassword "test123456"
33+
}
34+
}
35+
2436
buildTypes {
2537
debug {
2638
minifyEnabled false
@@ -29,6 +41,7 @@ android {
2941
release {
3042
minifyEnabled true
3143
shrinkResources true
44+
signingConfig signingConfigs.release
3245
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
3346
}
3447
}
@@ -37,7 +50,7 @@ android {
3750
dependencies {
3851
// the following aars are also compiled in host project, so they will be filterd when build plugin apk.
3952
// but, wo can still visit their Class and Resources.
40-
compile 'com.android.support:appcompat-v7:22.2.0'
53+
compile 'com.android.support:appcompat-v7:23.4.0'
4154
compile 'com.didi.virtualapk:core:0.9.1'
4255
}
4356

PluginDemo/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
33
repositories {
4+
google()
45
jcenter()
56
}
67
dependencies {
7-
classpath 'com.android.tools.build:gradle:2.3.3'
8-
classpath 'com.didi.virtualapk:gradle:0.9.4'
8+
classpath 'com.android.tools.build:gradle:3.0.0'
9+
classpath 'com.didi.virtualapk:gradle:0.9.7-dev'
910
}
1011
}
1112

1213
allprojects {
1314
repositories {
15+
google()
1416
jcenter()
1517
}
1618
}

PluginDemo/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Add a dependency in `build.gradle` in root of host project as following.
2828

2929
``` java
3030
dependencies {
31-
classpath 'com.didi.virtualapk:gradle:0.9.4'
31+
classpath 'com.didi.virtualapk:gradle:0.9.7-dev'
3232
}
3333
```
3434

@@ -85,7 +85,7 @@ Add a dependency in `build.gradle` in root of plugin project as following.
8585

8686
``` java
8787
dependencies {
88-
classpath 'com.didi.virtualapk:gradle:0.9.4'
88+
classpath 'com.didi.virtualapk:gradle:0.9.7-dev'
8989
}
9090
```
9191

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ dependencies {
4848
compile fileTree(dir: 'libs', include: ['*.jar'])
4949
testCompile 'junit:junit:4.12'
5050

51+
compile 'com.android.support:appcompat-v7:23.4.0'
5152
compile 'com.didi.virtualapk:core:0.9.1'
5253

5354
//compile project (":CoreLibrary")

app/src/main/java/com/didi/virtualapk/MainActivity.java

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package com.didi.virtualapk;
22

3+
import android.Manifest;
34
import android.app.AlertDialog;
45
import android.content.Context;
56
import android.content.Intent;
7+
import android.content.pm.PackageManager;
68
import android.database.Cursor;
79
import android.net.Uri;
810
import android.os.Build;
911
import android.os.Bundle;
1012
import android.os.Environment;
13+
import android.support.annotation.NonNull;
1114
import android.support.v7.app.AppCompatActivity;
1215
import android.util.Log;
1316
import android.view.View;
@@ -22,6 +25,10 @@
2225

2326
public class MainActivity extends AppCompatActivity {
2427

28+
private static final int PERMISSION_REQUEST_CODE_STORAGE = 20171222;
29+
30+
private static final String TAG = "MainActivity";
31+
2532
@Override
2633
protected void onCreate(Bundle savedInstanceState) {
2734
super.onCreate(savedInstanceState);
@@ -35,10 +42,50 @@ protected void onCreate(Bundle savedInstanceState) {
3542
}
3643
textView.setText(cpuArch);
3744
Log.d("ryg", "onCreate cpu arch is "+ cpuArch);
38-
this.loadPlugin(this);
3945
Log.d("ryg", "onCreate classloader is "+ getClassLoader());
46+
47+
if (hasPermission()) {
48+
Log.d(TAG,"loadPlugin");
49+
50+
this.loadPlugin(this);
51+
} else {
52+
requestPermission();
53+
}
54+
}
55+
56+
@Override
57+
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
58+
if (PERMISSION_REQUEST_CODE_STORAGE == requestCode) {
59+
if (grantResults[0] != PackageManager.PERMISSION_GRANTED) {
60+
requestPermission();
61+
} else {
62+
this.loadPlugin(this);
63+
}
64+
return;
65+
}
66+
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
4067
}
4168

69+
70+
private boolean hasPermission() {
71+
72+
Log.d(TAG,"hasPermission");
73+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
74+
return checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
75+
}
76+
return true;
77+
}
78+
79+
private void requestPermission() {
80+
81+
Log.d(TAG,"requestPermission");
82+
83+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
84+
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE_STORAGE);
85+
}
86+
}
87+
88+
4289
public void onButtonClick(View v) {
4390
if (v.getId() == R.id.button) {
4491
final String pkg = "com.didi.virtualapk.demo";

build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ buildscript {
33

44
repositories {
55
jcenter()
6+
google()
67
}
78
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.3.3'
9-
classpath 'com.didi.virtualapk:gradle:0.9.4'
9+
classpath 'com.android.tools.build:gradle:3.0.0'
10+
classpath 'com.didi.virtualapk:gradle:0.9.7-dev'
1011

1112
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
1213
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
@@ -18,7 +19,7 @@ ext {
1819
VERSION_BUILD_TOOLS = '25.0.2'
1920

2021
VERSION_MIN_SDK = 15
21-
VERSION_TARGET_SDK = 15
22+
VERSION_TARGET_SDK = 25
2223

2324
SOURCE_COMPATIBILITY = JavaVersion.VERSION_1_7
2425
}
@@ -27,6 +28,7 @@ allprojects {
2728
repositories {
2829
mavenCentral()
2930
jcenter()
31+
google()
3032
}
3133
}
3234

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

virtualapk-gradle-plugin/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
buildscript {
22
repositories {
33
mavenLocal()
4+
google()
45
mavenCentral()
56
jcenter()
67
}
@@ -20,6 +21,7 @@ tasks.withType(GroovyCompile) {
2021

2122
repositories {
2223
mavenLocal()
24+
google()
2325
mavenCentral()
2426
jcenter()
2527
}
@@ -42,7 +44,7 @@ dependencies {
4244
compile 'commons-codec:commons-codec:1.6'
4345
compile 'org.ow2.asm:asm:4.0'
4446
compile 'org.javassist:javassist:3.18.2-GA'
45-
compile 'com.android.tools.build:gradle:2.3.3'
47+
compile 'com.android.tools.build:gradle:3.0.0'
4648
}
4749

4850

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
GROUP_ID=com.didi.virtualapk
22
ARTIFACT_ID=gradle
3-
VERSION=0.9.4
3+
VERSION=0.9.7-dev

virtualapk-gradle-plugin/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

0 commit comments

Comments
 (0)