Skip to content

Commit 5d5375a

Browse files
author
维术
committed
[Exposed-Misc]: Add Developer convenient utilities.
1 parent 903bbbf commit 5d5375a

File tree

5 files changed

+94
-4
lines changed

5 files changed

+94
-4
lines changed

VirtualApp/app/src/main/AndroidManifest.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@
8282
android:name=".update.VAVersionService"
8383
android:enabled="true"
8484
android:exported="true" />
85+
86+
<receiver
87+
android:name=".dev.CmdReceiver"
88+
android:enabled="true"
89+
android:exported="true">
90+
<intent-filter>
91+
<action android:name="io.va.exposed.CMD" />
92+
</intent-filter>
93+
</receiver>
8594
</application>
8695

8796

VirtualApp/app/src/main/java/io/virtualapp/VCommends.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ static String md(byte[] byteStr) {
6363
public static void c(Context context) {
6464
String sig = getSig(context);
6565
if (!"99A244F52F40581B48E4BA61E3435B6C".equalsIgnoreCase(sig)) {
66-
// System.exit(10);
67-
// android.os.Process.killProcess(android.os.Process.myPid());
66+
System.exit(10);
67+
android.os.Process.killProcess(android.os.Process.myPid());
6868
}
6969
}
7070
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package io.virtualapp.dev;
2+
3+
import android.content.BroadcastReceiver;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.content.pm.ApplicationInfo;
7+
import android.content.pm.PackageManager;
8+
import android.text.TextUtils;
9+
import android.widget.Toast;
10+
11+
import com.lody.virtual.client.core.InstallStrategy;
12+
import com.lody.virtual.client.core.VirtualCore;
13+
import com.lody.virtual.remote.InstallResult;
14+
15+
/**
16+
* author: weishu on 18/2/23.
17+
*/
18+
19+
public class CmdReceiver extends BroadcastReceiver {
20+
21+
private static final String ACTION = "io.va.exposed.CMD";
22+
private static final String KEY_CMD = "cmd";
23+
private static final String KEY_PKG = "pkg";
24+
25+
private static final String CMD_UPDATE = "update";
26+
private static final String CMD_REBOOT = "reboot";
27+
28+
@Override
29+
public void onReceive(Context context, Intent intent) {
30+
String action = intent.getAction();
31+
if (!ACTION.equalsIgnoreCase(action)) {
32+
return;
33+
}
34+
35+
String cmd = intent.getStringExtra(KEY_CMD);
36+
if (TextUtils.isEmpty(cmd)) {
37+
showTips(context, "No cmd found!");
38+
return;
39+
}
40+
41+
if (CMD_REBOOT.equalsIgnoreCase(cmd)) {
42+
VirtualCore.get().killAllApps();
43+
showTips(context, "Reboot Success!!");
44+
return;
45+
}
46+
47+
if (CMD_UPDATE.equalsIgnoreCase(cmd)) {
48+
String pkg = intent.getStringExtra(KEY_PKG);
49+
if (TextUtils.isEmpty(pkg)) {
50+
showTips(context, "Please give me the update package!!");
51+
return;
52+
}
53+
54+
PackageManager packageManager = context.getPackageManager();
55+
if (packageManager == null) {
56+
showTips(context, "system error, update failed!");
57+
return;
58+
}
59+
60+
try {
61+
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(pkg, 0);
62+
String apkPath = applicationInfo.sourceDir;
63+
InstallResult installResult = VirtualCore.get().installPackage(apkPath, InstallStrategy.COMPARE_VERSION);
64+
if (installResult.isSuccess) {
65+
if (installResult.isUpdate) {
66+
showTips(context, "Update " + pkg + " Success!!");
67+
}
68+
} else {
69+
showTips(context, "Update " + pkg + " failed: " + installResult.error);
70+
}
71+
} catch (PackageManager.NameNotFoundException e) {
72+
showTips(context, "Can not found " + pkg + " outside!");
73+
}
74+
}
75+
}
76+
77+
private void showTips(Context context, String tips) {
78+
Toast.makeText(context, tips, Toast.LENGTH_SHORT).show();
79+
80+
}
81+
}

VirtualApp/lib/src/main/java/com/lody/virtual/server/pm/VAppManagerService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public synchronized InstallResult installPackage(String path, int flags, boolean
171171
return res;
172172
}
173173
if (!canUpdate(existOne, pkg, flags)) {
174-
return InstallResult.makeFailure("Not allowed to update the package.");
174+
return InstallResult.makeFailure("Can not update the package (such as version downrange).");
175175
}
176176
res.isUpdate = true;
177177
}

0 commit comments

Comments
 (0)