Java : get private method fails

111 views
Skip to first unread message

Joni Hariyanto

unread,
Jan 10, 2015, 11:30:55 PM1/10/15
to tas...@googlegroups.com
I need to access private method of window service as listed here :

I did it this way :
1. wm = CONTEXT - getSystemService - window
2. wmclass = wm - getClass
3. newInt = Integer - new (0)
4. intclass = newInt - getClass
5. classarray = ArrayList<Class> - new (1)
6. classarray - add - 0 - intclass
7. priv = wmclass - getDeclaredMethod - getAnimationScale - classarray

It fails on step 7, I don't know how to store Java error (the log only says ErrExit).
Any clue is appreciated.

Thanks alot :D

Pent

unread,
Jan 11, 2015, 3:26:02 AM1/11/15
to tas...@googlegroups.com
You can enable System or SD log in Menu / Prefs / More and should get more info then.

I hope to show the errors in the task edit screen before too long.

Pent

Joni Hariyanto

unread,
Jan 11, 2015, 6:10:12 AM1/11/15
to tas...@googlegroups.com
Did that, but the log isn't helpful.
I think I supplied the Class[] param wrong.

The method expects an int, so I also tried filling these for the Class[] param :
- Integer[].class
- classarray.class
- and simply classarray as above
None works.
What should I use exactly for the Class[] param ?

Thanks.

Pent

unread,
Jan 11, 2015, 7:11:36 AM1/11/15
to tas...@googlegroups.com

I think I supplied the Class[] param wrong.

Looks like it. Needs to be Class[] not an array list. And probably the
value classarray[0] needs to be an Integer.TYPE not an Integer.class.

I don't know if you're going to be able to declare that with Tasker.

I think easiest will be to wait until private functions are listable
in Tasker, maybe next version.

Pent

Joni Hariyanto

unread,
Jan 11, 2015, 8:09:09 AM1/11/15
to tas...@googlegroups.com
tasker+java.png

Pent

unread,
Jan 11, 2015, 9:36:10 AM1/11/15
to tas...@googlegroups.com
I tried the same and in the log I see:

D/Tasker  (32336): 15.34.09#E: targetClass: class java.lang.Class
D/Tasker  (32336): 15.34.09#E: object: interface android.view.IWindowManager
D/Tasker  (32336): 15.34.09#E: method: public java.lang.reflect.Method java.lang.Class.getDeclaredMethod(java.lang.String,java.lang.Class<?>[]) throws java.lang.NoSuchMethodException
D/Tasker  (32336): 15.34.09#E: arg0 class java.lang.String value getAnimationScale
D/Tasker  (32336): 15.34.09#E: arg1 class [Ljava.lang.Class; value [Ljava.lang.Class;@e964d0a
W/Tasker  (32336): 15.34.09#E: warning: Java Function: java.lang.reflect.InvocationTargetException
D/Tasker  (32336): 15.34.09#: Caused by: java.lang.NoSuchMethodException: getAnimationScale [class java.lang.Integer]
D/Tasker  (32336): 15.34.09#: java.lang.Class.getMethod(Class.java:664)
D/Tasker  (32336): 15.34.09#: java.lang.Class.getDeclaredMethod(Class.java:626)
D/Tasker  (32336): 15.34.09#: java.lang.reflect.Method.invoke(Native Method)
D/Tasker  (32336): 15.34.09#: java.lang.reflect.Method.invoke(Method.java:372)
D/Tasker  (32336): 15.34.09#: net.dinglisch.android.tasker.ExecuteService.doJavaFunc(ExecuteService.java:16151)
D/Tasker  (32336): 15.34.09#: net.dinglisch.android.tasker.ExecuteService.execute(ExecuteService.java:2786)

(it's safest to use double-quotes " around string constants like "getAnimationScale" BTW)

Pent

Pent

unread,
Jan 11, 2015, 9:37:50 AM1/11/15
to tas...@googlegroups.com
p.s. I used getClass() on an int to get Integer.class, but as I said, I believe Integer.TYPE is necessary and not supported
in Tasker if I remember right, therefore waiting till private methods can be selected is probably best.

Pent

David Wang

unread,
Feb 9, 2015, 12:58:08 AM2/9/15
to tas...@googlegroups.com
It seems that you must have declared specific permissions at first, depending on the real code here. And this example also mentioned this point.

Though you may get some private/internal/hidden class of Android using reflection,  the permission limitation is still exist(Maybe you can refer to the "Java" section of help files inTasker 4.7b2 to find a way as work around).


P.S: I had created a demo task to call private/hidden/internal class/method. See the demo here.
Reply all
Reply to author
Forward
0 new messages