THE RAKE 1
Trying to get the returned boolean value from the abstract getIccLockEnabled() method. The method is located in the abstract IccCard interface of the com.android.internal.telephony package. I do this:
Class cls = Class.forName("com.android.internal.telephony.IccCard"); Method method = cls.getMethod("getIccLockEnabled"); boolean value = method.invoke(cls); Log.i("ICC_LOCK_STATUS", value ? "Заблокировано" : "Разблокировано"); Log:
java.lang.IllegalArgumentException: Expected receiver of type com.android.internal.telephony.IccCard, but got java.lang.Class<com.android.internal.telephony.IccCard> .
THE RAKE 2
In connection with the answer and comments, I realized that I need to find a class that will inherit from IccCard and I found it - this is IccCardProxy . New code:
Class iccCard = Class.forName("com.android.internal.telephony.IccCard"); Class proxy = Class.forName("com.android.internal.telephony.uicc.IccCardProxy"); Method method = iccCard.getMethod("getIccLockEnabled"); boolean value = method.invoke(proxy.newInstance()); Log.i("ICC_LOCK_STATUS", value ? "Заблокировано" : "Разблокировано"); Log:
java.lang.InstantiationException: class com.android.internal.telephony.uicc.IccCardProxy has no zero argument constructor .
THE RAKE 3
I looked at what the IccCardProxy class constructor looks like - it accepts android.content.Context , com.android.internal.telephony.CommandsInterface and int . New code:
Class iccCard = Class.forName("com.android.internal.telephony.IccCard"); Class proxy = Class.forName("com.android.internal.telephony.uicc.IccCardProxy"); Class commandsBoss = Class.forName("com.android.internal.telephony.CommandsInterface"); Method method = iccCard.getMethod("getIccLockEnabled"); Constructor ctr = proxy.getConstructor(new Class[]{android.content.Context.class, commandsBoss, int.class}); boolean value = method.invoke(ctr.newInstance(MainActivity.this, commandsBoss.newInstance(), 4)); Log.i("ICC_LOCK_STATUS", value ? "Заблокировано" : "Разблокировано"); Log:
java.lang.InstantiationException: interface com.android.internal.telephony.CommandsInterface cannot be instantiated Since CommandsInterface , like IccCard , is an interface, I need to find a class that inherits it in order to get it
.
THE RAKE 4
A class that inherits from CommandsInterface found. This is RIL (Radio Interface Layer) . New code
Class iccCard = Class.forName("com.android.internal.telephony.IccCard"); Class proxy = Class.forName("com.android.internal.telephony.uicc.IccCardProxy"); Class commandsBoss = Class.forName("com.android.internal.telephony.CommandsInterface"); Class ril = Class.forName("com.android.internal.telephony.RIL"); Method method = iccCard.getMethod("getIccLockEnabled"); Constructor ctr = proxy.getConstructor(new Class[]{android.content.Context.class, commandsBoss, int.class}); boolean value = method.invoke(ctr.newInstance(MainActivity.this, ril.newInstance(), 4)); Log.i("ICC_LOCK_STATUS", value ? "Заблокировано" : "Разблокировано"); Log:
java.lang.InstantiationException: class com.android.internal.telephony.RIL has no zero argument constructor .
THE RAKE 5
He derived the number of constructors in the RIL class - 2. The types of the parameters of the first constructor are android.content.Context , int , int . The second is android.content.Context , int , int , java.lang.Integer . I decided to pass the parameters to the first constructor. New code
Class iccCard = Class.forName("com.android.internal.telephony.IccCard"); Class proxy = Class.forName("com.android.internal.telephony.uicc.IccCardProxy"); Class commandsBoss = Class.forName("com.android.internal.telephony.CommandsInterface"); Class ril = Class.forName("com.android.internal.telephony.RIL"); Method method = iccCard.getMethod("getIccLockEnabled"); Constructor ctr = proxy.getConstructor(new Class[]{android.content.Context.class, commandsBoss, int.class}); Constructor ril_constructor = ril.getConstructor(new Class[]{android.content.Context.class, int.class, int.class}); boolean value = method.invoke(ctr.newInstance(MainActivity.this, (ril_constructor.newInstance(MainActivity.this, 4, 6)), 4)); Log.i("ICC_LOCK_STATUS", value ? "Заблокировано" : "Разблокировано"); Log:
java.lang.reflect.InvocationTargetException I think that you need to send parameters to both designers. How to do it? Or a mistake in something else? Help, I'm specifically confused, I need to pass an object of type CommandsInterface to the method, and I'm trying to send it to an instance from the parameters of the RIL constructor. But I don’t understand what’s wrong, I’ve almost “hacked” this system. It feels like Google has left the opportunity to do this, but he mocked :)
.
THE RAKE 6
In connection with updating the response, I realized that there is a UiccController class with getInstance() and getUiccCard , it seems to have done right, but there was a log
class ... has no zero argument constructor And, deriving the number of designers, I get 0. New code:
Class iccCard = Class.forName("com.android.internal.telephony.IccCard"); Class uiccController = Class.forName("com.android.internal.telephony.uicc.UiccController"); Method getInstance = uiccController.getMethod("getInstance"); Method getUiccCard = uiccController.getMethod("getUiccCard"); Constructor[] uicc_constructor = uiccController.getConstructors(); log(""+uicc_constructor.length); .
THE RAKE 7
It turns out on the model under test (for which the application is being made) the constructor of the UiccController class with the access modifier private . This means that you need to use the getDeclaredConstructor() method. Now it returns the number of constructors - 1. I found out the types of parameters for this constructor - android.content.Context [Lcom.android.internal.telephony.CommandsInterface; The context is clear, but what about CommandsInterface ? I'm trying to do it like this
Class iccCard = Class.forName("com.android.internal.telephony.IccCard"); Class uiccController = Class.forName("com.android.internal.telephony.uicc.UiccController"); Class commandsInterface = Class.forName("com.android.internal.telephony.CommandsInterface"); Method getInstance = uiccController.getMethod("getInstance"); Method getUiccCard = uiccController.getMethod("getUiccCard"); Constructor uicc_constructor = uiccController.getDeclaredConstructor(new Class[]{android.content.Context.class, commandsInterface}); In theory, everything is correct, in the body of the constructor I put the context and the CommandsInterface class. But, I get this log:
java.lang.NoSuchMethodException: <init> [class android.content.Context, interface com.android.internal.telephony.CommandsInterface] What's wrong? I am strained by the letter L in front of the second parameter of the constructor. Is that the case? What kind of L ?
.
THE RAKE 8
New code, final. Almost all!
Class uiccController = Class.forName("com.android.internal.telephony.uicc.UiccController"); log("Класс найден"); Method getInstance = uiccController.getMethod("getInstance"); log("Метод найден"); Object instance = getInstance.invoke(null); log("instance взят"); Method getCard = instance.getClass().getMethod("getUiccCard"); log("Метод найден"); Object card = getCard.invoke(instance); log("принято"); Method getLockEnabled = card.getClass().getMethod("getIccLockEnabled"); log("выполняем метод"); boolean result = (Boolean) getLockEnabled.invoke(card); log("принят отаювет!"); log(result?"true":"false"); Log: InvocationTargetException . The third line is not executed.
Object instance = getInstance.invoke(null);