diff --git a/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java b/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java index b20e8a87ad..e2c4a2cc85 100644 --- a/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java +++ b/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java @@ -78,12 +78,12 @@ private static void startWorkaroundAndroid11() { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addCategory(Intent.CATEGORY_LAUNCHER); - intent.setComponent(new ComponentName(FakeContext.getPackageNameStatic(), "com.android.shell.HeapDumpActivity")); + intent.setComponent(new ComponentName(FakeContext.PACKAGE_SHELL, "com.android.shell.HeapDumpActivity")); ServiceManager.getActivityManager().startActivityAsUserWithFeature(intent); } private static void stopWorkaroundAndroid11() { - ServiceManager.getActivityManager().forceStopPackage(FakeContext.getPackageNameStatic()); + ServiceManager.getActivityManager().forceStopPackage(FakeContext.PACKAGE_SHELL); } private void tryStartRecording(int attempts, int delayMs) throws AudioCaptureForegroundException { diff --git a/server/src/main/java/com/genymobile/scrcpy/FakeContext.java b/server/src/main/java/com/genymobile/scrcpy/FakeContext.java index b4f87aadfa..ba12917691 100644 --- a/server/src/main/java/com/genymobile/scrcpy/FakeContext.java +++ b/server/src/main/java/com/genymobile/scrcpy/FakeContext.java @@ -10,7 +10,7 @@ public final class FakeContext extends ContextWrapper { - public static final String PACKAGE_NAME = "com.android.shell"; + public static final String PACKAGE_SHELL = "com.android.shell"; public static final int ROOT_UID = 0; // Like android.os.Process.ROOT_UID, but before API 29 private static final FakeContext INSTANCE = new FakeContext(); @@ -25,32 +25,26 @@ private FakeContext() { @Override public String getPackageName() { - if (Os.getuid() == 1000) { - return "android"; - } - return PACKAGE_NAME; + return getPackageNameStatic(); } @Override public String getOpPackageName() { - if (Os.getuid() == 1000) { - return "android"; - } - return PACKAGE_NAME; + return getPackageNameStatic(); } public static String getPackageNameStatic() { if (Os.getuid() == 1000) { return "android"; } - return PACKAGE_NAME; + return PACKAGE_SHELL; } @TargetApi(Build.VERSION_CODES.S) @Override public AttributionSource getAttributionSource() { AttributionSource.Builder builder = new AttributionSource.Builder(Process.SHELL_UID); - builder.setPackageName(PACKAGE_NAME); + builder.setPackageName(PACKAGE_SHELL); if (Os.getuid() == 1000) { builder.setPackageName("android"); }