Skip to content

Commit

Permalink
fix(dex): Workaround for systemMain exception on miui
Browse files Browse the repository at this point in the history
* Ref: Genymobile/scrcpy#994

Change-Id: I700cee9418881880941fcf75fd813a1e2037173e
  • Loading branch information
XayahSuSuSu committed Feb 21, 2024
1 parent 180ed78 commit 89df645
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions dex/app/src/main/java/com/xayah/dex/HiddenApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@
import android.content.pm.PackageManager;
import android.os.Looper;

import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.util.Objects;

public class HiddenApi {
public static Context getContext() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Looper.prepare();
PrintStream stderr = System.err;
try {
System.setErr(new PrintStream("/dev/null"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Object thread = Class.forName("android.app.ActivityThread").getMethod("systemMain").invoke(null);
Context context = (Context) Class.forName("android.app.ActivityThread").getMethod("getSystemContext").invoke(thread);
Objects.requireNonNull(Looper.myLooper()).quit();
System.setErr(stderr);
return context;
}

Expand Down

0 comments on commit 89df645

Please sign in to comment.