Skip to content

Commit 2c7868e

Browse files
author
tiann
committed
Add support for TaiChi
1 parent 0d0b4f2 commit 2c7868e

File tree

3 files changed

+75
-7
lines changed

3 files changed

+75
-7
lines changed

app/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
<provider
5151
android:name=".VXP"
52+
android:exported="true"
5253
android:authorities="eu.faircode.xlua.vxp"
5354
android:process=":vxp" />
5455
</application>

app/src/main/java/eu/faircode/xlua/Util.java

+36-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package eu.faircode.xlua;
2121

22+
import android.annotation.SuppressLint;
2223
import android.app.Dialog;
2324
import android.app.Notification;
2425
import android.app.NotificationChannel;
@@ -28,23 +29,25 @@
2829
import android.content.pm.PackageInfo;
2930
import android.content.pm.PackageManager;
3031
import android.content.res.Resources;
32+
import android.net.Uri;
3133
import android.os.Build;
34+
import android.os.Bundle;
3235
import android.os.Process;
3336
import android.os.UserHandle;
3437
import android.text.TextUtils;
3538
import android.util.Log;
3639
import android.util.TypedValue;
3740

38-
import java.lang.reflect.Constructor;
39-
import java.lang.reflect.Method;
40-
import java.security.MessageDigest;
41-
4241
import androidx.appcompat.app.AlertDialog;
4342
import androidx.lifecycle.Lifecycle;
4443
import androidx.lifecycle.LifecycleObserver;
4544
import androidx.lifecycle.LifecycleOwner;
4645
import androidx.lifecycle.OnLifecycleEvent;
4746

47+
import java.lang.reflect.Constructor;
48+
import java.lang.reflect.Method;
49+
import java.security.MessageDigest;
50+
4851
class Util {
4952
private final static String TAG = "XLua.Util";
5053

@@ -167,8 +170,36 @@ static void cancelAsUser(Context context, String tag, int id, int userid) throws
167170
Log.i(TAG, "Cancelled " + tag + ":" + id + " as " + userid);
168171
}
169172

173+
private static Boolean isExp;
174+
private static boolean isExpModuleActive() {
175+
if (isExp != null) {
176+
return isExp;
177+
}
178+
try {
179+
@SuppressLint("PrivateApi") Context context = (Context) Class.forName("android.app.ActivityThread")
180+
.getDeclaredMethod("currentApplication", new Class[0]).invoke(null, new Object[0]);
181+
if (context == null) {
182+
return isExp = false;
183+
}
184+
try {
185+
Bundle call = context.getContentResolver().call(Uri.parse("content://me.weishu.exposed.CP/"), "active", null, null);
186+
if (call == null) {
187+
return isExp = false;
188+
}
189+
isExp = call.getBoolean("active", false);
190+
return isExp;
191+
} catch (Throwable th) {
192+
return isExp = false;
193+
}
194+
} catch (Throwable th2) {
195+
return isExp = false;
196+
}
197+
}
198+
170199
static boolean isVirtualXposed() {
171-
return !TextUtils.isEmpty(System.getProperty("vxp"));
200+
return !TextUtils.isEmpty(System.getProperty("vxp"))
201+
|| !TextUtils.isEmpty(System.getProperty("exp"))
202+
|| isExpModuleActive();
172203
}
173204

174205
public static int resolveColor(Context context, int attr) {

app/src/main/java/eu/faircode/xlua/XProvider.java

+38-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import java.io.File;
4949
import java.lang.reflect.Method;
5050
import java.util.ArrayList;
51+
import java.util.Collection;
5152
import java.util.Collections;
5253
import java.util.Comparator;
5354
import java.util.HashMap;
@@ -332,6 +333,40 @@ public int compare(XHook h1, XHook h2) {
332333
return result;
333334
}
334335

336+
private static List<String> getExpApps(Context context) {
337+
try {
338+
Bundle call = context.getContentResolver().call(Uri.parse("content://me.weishu.exposed.CP/"), "apps", null, null);
339+
if (call == null) {
340+
return Collections.emptyList();
341+
}
342+
ArrayList<String> stringArrayList = call.getStringArrayList("apps");
343+
if (stringArrayList == null) {
344+
return Collections.emptyList();
345+
}
346+
return stringArrayList;
347+
} catch (Throwable th) {
348+
return Collections.emptyList();
349+
}
350+
}
351+
352+
private static Collection<ApplicationInfo> getApplications(Context context) {
353+
List<String> expApps = getExpApps(context);
354+
PackageManager packageManager = context.getPackageManager();
355+
if (expApps.isEmpty()) {
356+
return packageManager.getInstalledApplications(0);
357+
} else {
358+
List<ApplicationInfo> apps = new ArrayList<>();
359+
for (String expApp : expApps) {
360+
try {
361+
apps.add(packageManager.getApplicationInfo(expApp, 0));
362+
} catch (PackageManager.NameNotFoundException e) {
363+
e.printStackTrace();
364+
}
365+
}
366+
return apps;
367+
}
368+
}
369+
335370
private static Cursor getApps(Context context, String[] selection, boolean marshall) throws Throwable {
336371
Map<String, XApp> apps = new HashMap<>();
337372

@@ -342,8 +377,9 @@ private static Cursor getApps(Context context, String[] selection, boolean marsh
342377
long ident = Binder.clearCallingIdentity();
343378
try {
344379
// Get installed apps for current user
345-
PackageManager pm = Util.createContextForUser(context, userid).getPackageManager();
346-
for (ApplicationInfo ai : pm.getInstalledApplications(0))
380+
Context contextForUser = Util.createContextForUser(context, userid);
381+
PackageManager pm = contextForUser.getPackageManager();
382+
for (ApplicationInfo ai : getApplications(contextForUser))
347383
if (!ai.packageName.startsWith(BuildConfig.APPLICATION_ID))
348384
try {
349385
int esetting = pm.getApplicationEnabledSetting(ai.packageName);

0 commit comments

Comments
 (0)