mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-12-20 06:54:19 +01:00
Implement access to settings without Context
Expose methods to access the Android settings using private APIs. This allows to read and write settings values immediately without starting a new process to call "settings".
This commit is contained in:
@@ -16,6 +16,7 @@ public final class ServiceManager {
|
||||
private PowerManager powerManager;
|
||||
private StatusBarManager statusBarManager;
|
||||
private ClipboardManager clipboardManager;
|
||||
private ActivityManager activityManager;
|
||||
|
||||
public ServiceManager() {
|
||||
try {
|
||||
@@ -76,4 +77,21 @@ public final class ServiceManager {
|
||||
}
|
||||
return clipboardManager;
|
||||
}
|
||||
|
||||
public ActivityManager getActivityManager() {
|
||||
if (activityManager == null) {
|
||||
try {
|
||||
// On old Android versions, the ActivityManager is not exposed via AIDL,
|
||||
// so use ActivityManagerNative.getDefault()
|
||||
Class<?> cls = Class.forName("android.app.ActivityManagerNative");
|
||||
Method getDefaultMethod = cls.getDeclaredMethod("getDefault");
|
||||
IInterface am = (IInterface) getDefaultMethod.invoke(null);
|
||||
activityManager = new ActivityManager(am);
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
return activityManager;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user