Skip to content

Commit 3c090b3

Browse files
committed
Use ROOT_UID from FakeContext
Remove USER_ID from ServiceManager, and replace it by a constant in FakeContext. This is the same as android.os.Process.ROOT_UID, but this constant has been introduced in API 29. PR #3757 <#3757>
1 parent 31068ee commit 3c090b3

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

server/src/main/java/com/genymobile/scrcpy/FakeContext.java

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
public final class FakeContext extends ContextWrapper {
1010

1111
public static final String PACKAGE_NAME = "com.android.shell";
12+
public static final int ROOT_UID = 0; // Like android.os.Process.ROOT_UID, but before API 29
1213

1314
private static final FakeContext INSTANCE = new FakeContext();
1415

server/src/main/java/com/genymobile/scrcpy/wrappers/ActivityManager.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.genymobile.scrcpy.wrappers;
22

3+
import com.genymobile.scrcpy.FakeContext;
34
import com.genymobile.scrcpy.Ln;
45

56
import android.os.Binder;
@@ -48,10 +49,10 @@ private ContentProvider getContentProviderExternal(String name, IBinder token) {
4849
Object[] args;
4950
if (getContentProviderExternalMethodNewVersion) {
5051
// new version
51-
args = new Object[]{name, ServiceManager.USER_ID, token, null};
52+
args = new Object[]{name, FakeContext.ROOT_UID, token, null};
5253
} else {
5354
// old version
54-
args = new Object[]{name, ServiceManager.USER_ID, token};
55+
args = new Object[]{name, FakeContext.ROOT_UID, token};
5556
}
5657
// ContentProviderHolder providerHolder = getContentProviderExternal(...);
5758
Object providerHolder = method.invoke(manager, args);

server/src/main/java/com/genymobile/scrcpy/wrappers/ClipboardManager.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,19 @@ private static ClipData getPrimaryClip(Method method, boolean alternativeMethod,
6262
return (ClipData) method.invoke(manager, FakeContext.PACKAGE_NAME);
6363
}
6464
if (alternativeMethod) {
65-
return (ClipData) method.invoke(manager, FakeContext.PACKAGE_NAME, null, ServiceManager.USER_ID);
65+
return (ClipData) method.invoke(manager, FakeContext.PACKAGE_NAME, null, FakeContext.ROOT_UID);
6666
}
67-
return (ClipData) method.invoke(manager, FakeContext.PACKAGE_NAME, ServiceManager.USER_ID);
67+
return (ClipData) method.invoke(manager, FakeContext.PACKAGE_NAME, FakeContext.ROOT_UID);
6868
}
6969

7070
private static void setPrimaryClip(Method method, boolean alternativeMethod, IInterface manager, ClipData clipData)
7171
throws InvocationTargetException, IllegalAccessException {
7272
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
7373
method.invoke(manager, clipData, FakeContext.PACKAGE_NAME);
7474
} else if (alternativeMethod) {
75-
method.invoke(manager, clipData, FakeContext.PACKAGE_NAME, null, ServiceManager.USER_ID);
75+
method.invoke(manager, clipData, FakeContext.PACKAGE_NAME, null, FakeContext.ROOT_UID);
7676
} else {
77-
method.invoke(manager, clipData, FakeContext.PACKAGE_NAME, ServiceManager.USER_ID);
77+
method.invoke(manager, clipData, FakeContext.PACKAGE_NAME, FakeContext.ROOT_UID);
7878
}
7979
}
8080

@@ -109,9 +109,9 @@ private static void addPrimaryClipChangedListener(Method method, boolean alterna
109109
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
110110
method.invoke(manager, listener, FakeContext.PACKAGE_NAME);
111111
} else if (alternativeMethod) {
112-
method.invoke(manager, listener, FakeContext.PACKAGE_NAME, null, ServiceManager.USER_ID);
112+
method.invoke(manager, listener, FakeContext.PACKAGE_NAME, null, FakeContext.ROOT_UID);
113113
} else {
114-
method.invoke(manager, listener, FakeContext.PACKAGE_NAME, ServiceManager.USER_ID);
114+
method.invoke(manager, listener, FakeContext.PACKAGE_NAME, FakeContext.ROOT_UID);
115115
}
116116
}
117117

server/src/main/java/com/genymobile/scrcpy/wrappers/ContentProvider.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private static String getPutMethod(String table) {
138138
public String getValue(String table, String key) throws SettingsException {
139139
String method = getGetMethod(table);
140140
Bundle arg = new Bundle();
141-
arg.putInt(CALL_METHOD_USER_KEY, ServiceManager.USER_ID);
141+
arg.putInt(CALL_METHOD_USER_KEY, FakeContext.ROOT_UID);
142142
try {
143143
Bundle bundle = call(method, key, arg);
144144
if (bundle == null) {
@@ -154,7 +154,7 @@ public String getValue(String table, String key) throws SettingsException {
154154
public void putValue(String table, String key, String value) throws SettingsException {
155155
String method = getPutMethod(table);
156156
Bundle arg = new Bundle();
157-
arg.putInt(CALL_METHOD_USER_KEY, ServiceManager.USER_ID);
157+
arg.putInt(CALL_METHOD_USER_KEY, FakeContext.ROOT_UID);
158158
arg.putString(NAME_VALUE_TABLE_VALUE, value);
159159
try {
160160
call(method, key, arg);

server/src/main/java/com/genymobile/scrcpy/wrappers/ServiceManager.java

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
@SuppressLint("PrivateApi,DiscouragedPrivateApi")
1111
public final class ServiceManager {
1212

13-
public static final int USER_ID = 0;
14-
1513
private static final Method GET_SERVICE_METHOD;
1614
static {
1715
try {

0 commit comments

Comments
 (0)