Skip to content

Commit 6ee6b3d

Browse files
author
tiann
committed
[VXP]: feat, File Manager & Permission Manager.
1 parent 58fa5d9 commit 6ee6b3d

File tree

11 files changed

+276
-97
lines changed

11 files changed

+276
-97
lines changed

VirtualApp/app/src/main/java/io/virtualapp/gms/FakeGms.java

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import io.virtualapp.R;
3030
import io.virtualapp.abs.ui.VUiKit;
31+
import io.virtualapp.utils.DialogUtil;
3132
import okhttp3.OkHttpClient;
3233
import okhttp3.Request;
3334
import okhttp3.Response;
@@ -73,7 +74,7 @@ public static void uninstallGms(Activity activity) {
7374
.setMessage(R.string.uninstall_gms_success)
7475
.setPositiveButton(android.R.string.ok, null)
7576
.create();
76-
showDialog(hits);
77+
DialogUtil.showDialog(hits);
7778

7879
}).fail((v) -> {
7980
dialog.dismiss();
@@ -82,7 +83,7 @@ public static void uninstallGms(Activity activity) {
8283
}))
8384
.setNegativeButton(android.R.string.cancel, null)
8485
.create();
85-
showDialog(failDialog);
86+
DialogUtil.showDialog(failDialog);
8687
}
8788

8889
public static boolean isAlreadyInstalled(Context context) {
@@ -138,7 +139,7 @@ public static void installGms(Activity activity) {
138139
.setMessage(R.string.install_gms_success)
139140
.setPositiveButton(android.R.string.ok, null)
140141
.create();
141-
showDialog(failDialog);
142+
DialogUtil.showDialog(failDialog);
142143
});
143144
} else {
144145
activity.runOnUiThread(() -> {
@@ -156,7 +157,7 @@ public static void installGms(Activity activity) {
156157
}))
157158
.setNegativeButton(android.R.string.cancel, null)
158159
.create();
159-
showDialog(failDialog);
160+
DialogUtil.showDialog(failDialog);
160161
});
161162

162163
}
@@ -165,21 +166,10 @@ public static void installGms(Activity activity) {
165166
.setNegativeButton(android.R.string.cancel, null)
166167
.create();
167168

168-
showDialog(alertDialog);
169+
DialogUtil.showDialog(alertDialog);
169170
}
170171

171172

172-
private static void showDialog(AlertDialog dialog) {
173-
if (dialog == null) {
174-
return;
175-
}
176-
try {
177-
dialog.show();
178-
} catch (Throwable e) {
179-
e.printStackTrace();
180-
}
181-
}
182-
183173
private static String installGmsInternal(Activity activity, ProgressDialog dialog) {
184174
File cacheDir = activity.getCacheDir();
185175

@@ -354,7 +344,6 @@ private static String installGmsInternal(Activity activity, ProgressDialog dialo
354344
FileWriter writer = null;
355345
try {
356346
writer = new FileWriter(configDir, true);
357-
writer.append('\n');
358347
writer.append(modulePath.getAbsolutePath());
359348
writer.flush();
360349

@@ -383,11 +372,11 @@ private static void updateMessage(Activity activity, ProgressDialog dialog, Stri
383372
});
384373
}
385374

386-
interface DownloadListener {
375+
public interface DownloadListener {
387376
void onProgress(int progress);
388377
}
389378

390-
private static boolean downloadFile(String url, File outFile, DownloadListener listener) {
379+
public static boolean downloadFile(String url, File outFile, DownloadListener listener) {
391380
OkHttpClient client = new OkHttpClient();
392381
Request request = new Request.Builder().url(url).build();
393382
FileOutputStream fos = null;
@@ -430,9 +419,4 @@ private static boolean downloadFile(String url, File outFile, DownloadListener l
430419
}
431420

432421
}
433-
434-
private static void showFailTips(Activity activity) {
435-
436-
}
437-
438422
}
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
package io.virtualapp.settings;
2+
3+
import android.app.Activity;
4+
import android.app.ProgressDialog;
5+
import android.os.SystemClock;
6+
import android.support.v7.app.AlertDialog;
7+
import android.text.TextUtils;
8+
import android.util.Log;
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.os.VEnvironment;
14+
import com.lody.virtual.remote.InstallResult;
15+
16+
import org.json.JSONException;
17+
import org.json.JSONObject;
18+
19+
import java.io.File;
20+
import java.io.FileWriter;
21+
import java.io.IOException;
22+
import java.util.concurrent.Executors;
23+
import java.util.concurrent.TimeUnit;
24+
25+
import io.virtualapp.R;
26+
import io.virtualapp.gms.FakeGms;
27+
import io.virtualapp.home.LoadingActivity;
28+
import okhttp3.OkHttpClient;
29+
import okhttp3.Request;
30+
import okhttp3.Response;
31+
import okhttp3.ResponseBody;
32+
33+
import static io.virtualapp.utils.DialogUtil.showDialog;
34+
35+
/**
36+
* @author weishu
37+
* @date 2018/7/5.
38+
*/
39+
public class OnlinePlugin {
40+
41+
private static final String TAG = "OnlinePlugin";
42+
43+
public static final String FILE_MANAGE_PACKAGE = "com.amaze.filemanager";
44+
public static final String FILE_MANAGE_URL = "http://vaexposed.weishu.me/amaze.json";
45+
46+
public static final String PERMISSION_MANAGE_PACKAGE = "eu.faircode.xlua";
47+
public static final String PERMISSION_MANAGE_URL = "http://vaexposed.weishu.me/xlua.json";
48+
49+
public static void openOrDownload(Activity context, String packageName, String url, String tips) {
50+
if (context == null || packageName == null) {
51+
return;
52+
}
53+
54+
if (VirtualCore.get().isAppInstalled(packageName)) {
55+
LoadingActivity.launch(context, packageName, 0);
56+
return;
57+
}
58+
59+
AlertDialog failDialog = new AlertDialog.Builder(context, R.style.Theme_AppCompat_DayNight_Dialog_Alert)
60+
.setTitle(android.R.string.dialog_alert_title)
61+
.setMessage(tips)
62+
.setPositiveButton(android.R.string.ok, ((dialog1, which1) -> {
63+
ProgressDialog progressDialog = new ProgressDialog(context);
64+
progressDialog.setCancelable(false);
65+
progressDialog.show();
66+
67+
Executors.newSingleThreadExecutor().submit(() -> {
68+
String error = downloadAndInstall(context, progressDialog, url, packageName);
69+
try {
70+
progressDialog.dismiss();
71+
} catch (Throwable e) {
72+
e.printStackTrace();
73+
}
74+
75+
if (error == null) {
76+
context.runOnUiThread(() -> {
77+
LoadingActivity.launch(context, packageName, 0);
78+
});
79+
} else {
80+
context.runOnUiThread(() -> Toast.makeText(context, error, Toast.LENGTH_SHORT).show());
81+
}
82+
83+
});
84+
85+
}))
86+
.setNegativeButton(android.R.string.cancel, null)
87+
.create();
88+
89+
showDialog(failDialog);
90+
}
91+
92+
private static String downloadAndInstall(Activity activity, ProgressDialog dialog, String url, String packageName) {
93+
OkHttpClient client = new OkHttpClient.Builder()
94+
.connectTimeout(30, TimeUnit.SECONDS)
95+
.readTimeout(30, TimeUnit.SECONDS)
96+
.writeTimeout(30, TimeUnit.SECONDS)
97+
.build();
98+
99+
Request request = new Request.Builder()
100+
.url(url)
101+
.build();
102+
103+
updateMessage(activity, dialog, "Prepare download...");
104+
Response response;
105+
try {
106+
response = client.newCall(request).execute();
107+
} catch (IOException e) {
108+
return "Download failed, please check your network, error: 0";
109+
}
110+
111+
if (!response.isSuccessful()) {
112+
return "Download failed, please check your network, error: 1";
113+
}
114+
115+
Log.i(TAG, "response success: " + response.code());
116+
if (200 != response.code()) {
117+
return "Download failed, please check your network, error: 2";
118+
}
119+
120+
updateMessage(activity, dialog, "Parsing config...");
121+
ResponseBody body = response.body();
122+
if (body == null) {
123+
return "Download failed, please check your network, error: 3";
124+
}
125+
126+
String string;
127+
try {
128+
string = body.string();
129+
} catch (IOException e) {
130+
return "Download failed, please check your network, error: 4";
131+
}
132+
133+
JSONObject jsonObject;
134+
try {
135+
jsonObject = new JSONObject(string);
136+
} catch (JSONException e) {
137+
return "Download failed, please check your network, error: 5";
138+
}
139+
String downloadLink;
140+
boolean isXposed;
141+
try {
142+
downloadLink = jsonObject.getString("url");
143+
isXposed = jsonObject.optBoolean("xposed", false);
144+
} catch (JSONException e) {
145+
return "Download failed, please check your network, error: 6";
146+
}
147+
148+
File outFile = new File(activity.getCacheDir(), packageName + ".apk");
149+
FakeGms.downloadFile(downloadLink, outFile, progress -> updateMessage(activity, dialog, "download " + packageName + "..." + progress + "%"));
150+
151+
updateMessage(activity, dialog, "installing " + packageName);
152+
153+
InstallResult installResult = VirtualCore.get().installPackage(outFile.getAbsolutePath(), InstallStrategy.UPDATE_IF_EXIST);
154+
if (!installResult.isSuccess) {
155+
return "install " + packageName + " failed: " + installResult.error;
156+
}
157+
158+
if (isXposed) {
159+
// Enable the Xposed module.
160+
updateMessage(activity, dialog, "enable " + packageName + " in Xposed Installer");
161+
162+
File dataDir = VEnvironment.getDataUserPackageDirectory(0, "de.robv.android.xposed.installer");
163+
File modulePath = VEnvironment.getPackageResourcePath(packageName);
164+
File configDir = new File(dataDir, "exposed_conf" + File.separator + "modules.list");
165+
FileWriter writer = null;
166+
try {
167+
writer = new FileWriter(configDir, true);
168+
writer.append(modulePath.getAbsolutePath());
169+
writer.flush();
170+
171+
} catch (IOException e) {
172+
e.printStackTrace();
173+
} finally {
174+
if (writer != null) {
175+
try {
176+
writer.close();
177+
} catch (IOException e) {
178+
e.printStackTrace();
179+
}
180+
}
181+
}
182+
}
183+
184+
updateMessage(activity, dialog, " install success!!");
185+
SystemClock.sleep(300);
186+
187+
return null;
188+
}
189+
190+
private static void updateMessage(Activity activity, ProgressDialog dialog, String msg) {
191+
if (activity == null || dialog == null || TextUtils.isEmpty(msg)) {
192+
return;
193+
}
194+
Log.i(TAG, "update dialog message: " + msg);
195+
activity.runOnUiThread(() -> {
196+
dialog.setMessage(msg);
197+
});
198+
}
199+
}

0 commit comments

Comments
 (0)