Skip to content

Commit

Permalink
Hide warnings on XiaoMi devices
Browse files Browse the repository at this point in the history
  • Loading branch information
yume-chan committed Aug 13, 2023
1 parent a4e7a7e commit f75f9b9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.media.MediaCodec;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.view.Surface;

import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.media.MediaCodec;
import android.media.MediaCodecInfo;
import android.media.MediaFormat;
import android.os.Looper;
import android.os.SystemClock;
import android.view.Surface;

Expand Down
9 changes: 9 additions & 0 deletions server/src/main/java/com/genymobile/scrcpy/Workarounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,17 @@ private static void fillAppContext() {
}
}

@SuppressLint("PrivateApi")
public static Context getSystemContext() throws ReflectiveOperationException {
if (systemContext == null) {
try {
// Hide warnings on XiaoMi devices
Class<?> themeManagerStubClass = Class.forName("android.content.res.ThemeManagerStub");
Field sResourceField = themeManagerStubClass.getDeclaredField("sResource");
sResourceField.setAccessible(true);
sResourceField.set(null, null);
} catch (ReflectiveOperationException ignore) { }

Object activityThread = getActivityThread();
Method getSystemContextMethod = activityThreadClass.getDeclaredMethod("getSystemContext");
systemContext = (Context) getSystemContextMethod.invoke(activityThread);
Expand Down

0 comments on commit f75f9b9

Please sign in to comment.