Skip to content

Commit

Permalink
Move constants to ServiceManager
Browse files Browse the repository at this point in the history
PACKAGE_NAME and USER_ID could be use by several "managers", so move
them to the service manager.
  • Loading branch information
rom1v committed May 1, 2020
1 parent 2f74ec2 commit dbb0df6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
import java.lang.reflect.Method;

public class ClipboardManager {

private static final String PACKAGE_NAME = "com.android.shell";
private static final int USER_ID = 0;

private final IInterface manager;
private Method getPrimaryClipMethod;
private Method setPrimaryClipMethod;
Expand Down Expand Up @@ -46,17 +42,17 @@ private Method getSetPrimaryClipMethod() throws NoSuchMethodException {

private static ClipData getPrimaryClip(Method method, IInterface manager) throws InvocationTargetException, IllegalAccessException {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
return (ClipData) method.invoke(manager, PACKAGE_NAME);
return (ClipData) method.invoke(manager, ServiceManager.PACKAGE_NAME);
}
return (ClipData) method.invoke(manager, PACKAGE_NAME, USER_ID);
return (ClipData) method.invoke(manager, ServiceManager.PACKAGE_NAME, ServiceManager.USER_ID);
}

private static void setPrimaryClip(Method method, IInterface manager, ClipData clipData)
throws InvocationTargetException, IllegalAccessException {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
method.invoke(manager, clipData, PACKAGE_NAME);
method.invoke(manager, clipData, ServiceManager.PACKAGE_NAME);
} else {
method.invoke(manager, clipData, PACKAGE_NAME, USER_ID);
method.invoke(manager, clipData, ServiceManager.PACKAGE_NAME, ServiceManager.USER_ID);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

@SuppressLint("PrivateApi,DiscouragedPrivateApi")
public final class ServiceManager {

public static final String PACKAGE_NAME = "com.android.shell";
public static final int USER_ID = 0;

private final Method getServiceMethod;

private WindowManager windowManager;
Expand Down

0 comments on commit dbb0df6

Please sign in to comment.