IonVR Coming Soon, HTC M9 Dev Edition Gets Android 5.1 – XDA TV

The HTC M9 Developer Edition has received Android 5.1. That and … more

Android 5.1.1 Omni ROM For Motorola Xoom

Back in Feb 2011, the Motorola Xoom became the first device to be sold with Android 3.0 … more

CleanSlate Brings Fingerprint Scanner Mod to HTC One M9+

Work of XDA Recognized Developer tbalden, CleanSlate custom kernel for the HTC … more

Sunday Debate: Which Factors Caused HTC’s Woes?

Join us in a fun Sunday Debate on HTC’s situation. Come with your … more

[Q] Why am I receiving NoSuchMethod for adjustStreamVolume

56 posts
Thanks Meter: 8
 
By bkertz, Member on 18th August 2014, 02:28 AM
Post Reply Subscribe to Thread Email Thread
I wrote a module for myself to get started with xposed development when my phone (LG G2) was on Jelly Bean. I upgraded my phone to Kit Kat and noticed my module was no longer working and was firing a NoSuchMethod exception:

Code:
java.lang.NoSuchMethodError: android.media.AudioService#adjustStreamVolume(int,int,int)#exact
at de.robv.android.xposed.XposedHelpers.findMethodExact(XposedHelpers.java:179)
at de.robv.android.xposed.XposedHelpers.findAndHookMethod(XposedHelpers.java:129)
at de.robv.android.xposed.XposedHelpers.findAndHookMethod(XposedHelpers.java:136)
at com.bkdev.android.xposed.mods.ringtonesync.VolumeSync.handleLoadPackage(VolumeSync.java:21)
at de.robv.android.xposed.IXposedHookLoadPackage$Wrapper.handleLoadPackage(IXposedHookLoadPackage.java:20)
at de.robv.android.xposed.callbacks.XC_LoadPackage.call(XC_LoadPackage.java:34)
at de.robv.android.xposed.callbacks.XCallback.callAll(XCallback.java:70)
at de.robv.android.xposed.XposedBridge$2.beforeHookedMethod(XposedBridge.java:228)
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:611)
at com.android.server.ServerThread.initAndLoop(Native Method)
at com.android.server.SystemServer.main(SystemServer.java:1478)
at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:631)
at com.android.server.SystemServer.main(Native Method)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
I checked the API and it doesn't appear that adjustStreamVolume was deprecated or changed in any way, so I'm kind of confused as to why this would be happening. Maybe it's just my ignorance of xposed development so far, but here's my code with all of meat stripped out. From what I gather, the findAndHookMethod is the problem anyway. Any assistance as to why this is no longer working would be greatly appreciated. Let me know if more details are needed.


Code:
    
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
    	if (!lpparam.packageName.equals("android"))
            return;

//    	XposedBridge.log("In com.android.media");

    	findAndHookMethod("android.media.AudioService", lpparam.classLoader, "adjustStreamVolume", int.class, int.class, int.class, new XC_MethodHook() {
    		protected void afterHookedMethod(MethodHookParam param) throws Throwable {
    			XposedBridge.log("********Hooked 'adjustStreamVolume'********");
    			
    		}
    		
    	});
    	
    }
 
 
18th August 2014, 11:12 AM |#2  
Senior Member
Thanks Meter: 1,010
 
More
Try use InitZygote for "android".
18th August 2014, 03:03 PM |#3  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 8,294
 
More
Checking the source:
Code:
Select Code
    /** @see AudioManager#adjustStreamVolume(int, int, int) */
    public void adjustStreamVolume(int streamType, int direction, int flags,
            String callingPackage) {
         …
    }
The Following User Says Thank You to GermainZ For This Useful Post: [ View ]
18th August 2014, 04:56 PM |#4  
bkertz's Avatar
OP Member
Flag St. Louis
Thanks Meter: 8
 
More
@GermainZ

When I look at the developer reference for adjustStreamVolume in the AudioManager class, I don't see the extra parameter (String callingPackage) that you reference. Am I looking in the wrong place for the method I want to hook?

http://developer.android.com/referen...reamVolume(int, int, int)

Sent from my LG-LS980 using Tapatalk
18th August 2014, 05:04 PM |#5  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 8,294
 
More
Quote:
Originally Posted by bkertz

@GermainZ

When I look at the developer reference for adjustStreamVolume in the AudioManager class, I don't see the extra parameter (String callingPackage) that you reference. Am I looking in the wrong place for the method I want to hook?

http://developer.android.com/referen...reamVolume(int, int, int)

Sent from my LG-LS980 using Tapatalk

You're hooking AudioService, the page you're linking is the documentation for AudioManager.
The Following User Says Thank You to GermainZ For This Useful Post: [ View ]
18th August 2014, 06:00 PM |#6  
bkertz's Avatar
OP Member
Flag St. Louis
Thanks Meter: 8
 
More
Quote:
Originally Posted by GermainZ

You're hooking AudioService, the page you're linking is the documentation for AudioManager.

Well I really feel dumb now. It helps to look in the right place. Strange that this worked before for me. Do you have any recommendations between using AudioManager vs. AudioService? It appears AudioService is not on the developer pages.

Sent from my LG-LS980 using Tapatalk
18th August 2014, 06:02 PM |#7  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 8,294
 
More
Quote:
Originally Posted by bkertz

Well I really feel dumb now. It helps to look in the right place. Strange that this worked before for me. Do you have any recommendations between using AudioManager vs. AudioService? It appears AudioService is not on the developer pages.

Sent from my LG-LS980 using Tapatalk

Hook methods that are available in the SDK when you can. Hooking internal methods may stop working on newer versions since they can change at any time (they're internal methods after all).
The Following User Says Thank You to GermainZ For This Useful Post: [ View ]
18th August 2014, 06:53 PM |#8  
bkertz's Avatar
OP Member
Flag St. Louis
Thanks Meter: 8
 
More
Thanks.

Sent from my LG-LS980 using Tapatalk
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes