Skip to content

Commit

Permalink
fixups: PACKAGE_SHELL constant where necessary, DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
RiggiG committed Dec 5, 2023
1 parent aa0c71c commit 391d604
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
4 changes: 2 additions & 2 deletions server/src/main/java/com/genymobile/scrcpy/AudioCapture.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 5 additions & 11 deletions server/src/main/java/com/genymobile/scrcpy/FakeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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");
}
Expand Down

0 comments on commit 391d604

Please sign in to comment.