Skip to content

Commit 0395041

Browse files
committed
Add overloaded getUsers methods to IUserManager and update HiddenUserManager
Introduced new overloaded getUsers methods in IUserManager to support different parameter combinations. Updated HiddenUserManager to dynamically invoke the appropriate getUsers method via reflection, providing compatibility with multiple method signatures and improved error handling.
1 parent 0922ad3 commit 0395041

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

hidden-api/src/main/java/android/os/IUserManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
public interface IUserManager extends IInterface {
88

9+
List<UserInfo> getUsers(boolean excludeDying) throws RemoteException;
10+
11+
List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying) throws RemoteException;
12+
913
List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying, boolean excludePreCreated) throws RemoteException;
1014

1115
UserInfo getUserInfo(int userId);

platform/src/main/kotlin/com/dergoogler/mmrl/platform/hiddenApi/HiddenUserManager.kt

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
@file:Suppress("UNCHECKED_CAST")
2+
13
package com.dergoogler.mmrl.platform.hiddenApi
24

35
import android.content.Context
46
import android.content.pm.UserInfo
57
import android.os.IUserManager
68
import android.os.Process
79
import android.os.RemoteException
10+
import android.util.Log
811
import com.dergoogler.mmrl.platform.PlatformManager.getSystemService
912
import com.dergoogler.mmrl.platform.stub.IServiceManager
1013

@@ -22,7 +25,41 @@ class HiddenUserManager(
2225
excludePartial: Boolean = true,
2326
excludeDying: Boolean = true,
2427
excludePreCreated: Boolean = true,
25-
): List<UserInfo> = userManager.getUsers(excludePartial, excludeDying, excludePreCreated)
28+
): List<UserInfo> {
29+
try {
30+
return userManager::class.java
31+
.getMethod(
32+
"getUsers",
33+
Boolean::class.javaPrimitiveType,
34+
Boolean::class.javaPrimitiveType,
35+
Boolean::class.javaPrimitiveType
36+
)
37+
.invoke(
38+
userManager,
39+
excludePartial,
40+
excludeDying,
41+
excludePreCreated
42+
) as List<UserInfo>
43+
} catch (e: NoSuchMethodException) {
44+
Log.w("HiddenUserManager", "Error getting users, falling back to old method.", e)
45+
46+
return try {
47+
userManager::class.java
48+
.getMethod(
49+
"getUsers",
50+
Boolean::class.javaPrimitiveType,
51+
Boolean::class.javaPrimitiveType
52+
)
53+
.invoke(userManager, excludePartial, excludeDying) as List<UserInfo>
54+
} catch (e2: NoSuchMethodException) {
55+
Log.w("HiddenUserManager", "Error getting users, falling back to old method.", e2)
56+
57+
userManager::class.java
58+
.getMethod("getUsers", Boolean::class.javaPrimitiveType)
59+
.invoke(userManager, excludePartial) as List<UserInfo>
60+
}
61+
}
62+
}
2663

2764
@Throws(RemoteException::class)
2865
fun getUsers(): List<UserInfo> = getUsers(

0 commit comments

Comments
 (0)