I'm trying to write an app that is able to access the Android Keyguard app (the system app that holds the "lock screen"). I tried using reflection to get a reference to the running KeyguardUpdateMonitor instance, but so far, I've only received an java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
.
Here's the code that causes the issue:
try {
DexFile df = new DexFile(new File("/system/priv-app/Keyguard.apk"));
String packageName = "com.android.keyguard";
Context packageContext = context.createPackageContext(packageName,
Context.CONTEXT_INCLUDE_CODE
| Context.CONTEXT_IGNORE_SECURITY);
ClassLoader cl = packageContext.getClassLoader();
Class keyguardUpdateMonitor = df.loadClass(packageName
+ ".KeyguardUpdateMonitor", cl);
Method getKeyguardUpdateMonitorInstance
= keyguardUpdateMonitor.getMethod("getInstance", Context.class);
Object argumentsForGetInstance[] = new Object[1];
argumentsForGetInstance[0] = packageContext;
Object keyguardUpdateMonitorInstance
= getKeyguardUpdateMonitorInstance.invoke(null, packageContext);
...
}
This code is running within a Class that is instanciated in a Service.
The signature of the method I'm trying to call is public static KeyguardUpdateMonitor getInstance(Context context)
.
- Can I use reflection the way I intend to or do I NEED to have an own instance of the
KeyguardUpdateMonitor
? - Do I need special permissions?
- Is there a fundamental mistake in my idea? If yes, how can I access the Keyguard in Android (KitKat and upwards)?