Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,810,588 Members 46,592 Now Online
XDA Developers Android and Mobile Development Forum

[Q] android.app.DownloadManager.Request.enqueue callbacks not invoked in Kitkat

Tip us?
 
ie5x
Old
(Last edited by ie5x; 17th June 2014 at 05:17 AM.) Reason: Corrected the hook name.
#1  
Junior Member - OP
Thanks Meter 0
Posts: 21
Join Date: Nov 2007
Question [Q] android.app.DownloadManager.Request.enqueue callbacks not invoked in Kitkat

Hi,

I am developing a module for which I have hooked android.app.DownloadManager.enqueue callback. The code is like this -
Code:
Unhook hook = findAndHookMethod(android.app.DownloadManager.class,
							"enqueue",
							"android.app.DownloadManager.Request",
		    		new XC_MethodHook() {
	            @Override
	            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
	            	log("After enqueue.");
	            }
});
This code is invoked from initZygote. It was working perfectly fine in Jellybean 4.1.2 on my older Xperia J. However, the callback is not invoked in Xperia Z running Kitkat 4.4.2 ROM. The callback does get attached successfully since the "hook" value is not null. I have tried moving the invoke into handlePackageLoad when the "android" package is loaded, but still no luck.

Any suggestions?
 
ie5x
Old
#2  
Junior Member - OP
Thanks Meter 0
Posts: 21
Join Date: Nov 2007
Anyone?
 
rovo89
Old
#3  
rovo89's Avatar
Senior Recognized Developer
Thanks Meter 14,104
Posts: 2,367
Join Date: Jan 2012
Have you made sure that the enque() method is actually called? You can easily test this with the Xposed Installer, just download any module. It also uses this method. Make sure you place the hook in initZygote(), otherwise it won't be active in the installer process.
Tired of updating your mod for every new ROM release?
You want give users the possibility to combine different mods without creating tons of different files for all possible combinations?
Then have a look at my Xposed framework - modifications without APK changes!
The Following User Says Thank You to rovo89 For This Useful Post: [ Click to Expand ]
 
ie5x
Old
#4  
Junior Member - OP
Thanks Meter 0
Posts: 21
Join Date: Nov 2007
Quote:
Originally Posted by rovo89 View Post
Have you made sure that the enque() method is actually called? You can easily test this with the Xposed Installer, just download any module. It also uses this method. Make sure you place the hook in initZygote(), otherwise it won't be active in the installer process.
Hi @rovo89, yes I did put this call in initZygote. I took the clue from XposedBridge code which hooks up android.app package methods in there. Also, I found this issue when I installed my app on Xperia Z Kitkat ROM and found it not working when the various ways to invoke enqueue did not call the hooks. I typically use Chrome/AOSP browsers to download an image to SD card to test this. In Jellybean (on my earlier Xperia J), the hooks get invoked as expected. Its just that in Kitkat, even though the "hookMethod" returns a Unhook reference, the hooks are never called.

Interestingly, this is only affecting the DownloadManager class method hooks. I have also hooked methods in downloadprovider class and it gets called alright. This is really a very confusing situation .

Is it possible for you to give this a try please? The code snippet I pasted should be good enough, otherwise I can rig up a sample. Thanks!
 
GermainZ
Old
#5  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,401
Posts: 5,478
Join Date: Aug 2012
You're hooking the wrong method, then. Look for the method that actually gets called for DownloadManager (check its source, make a test app, possibly use Xposed Method Finder, etc).
The Following User Says Thank You to GermainZ For This Useful Post: [ Click to Expand ]
 
ie5x
Old
#6  
Junior Member - OP
Thanks Meter 0
Posts: 21
Join Date: Nov 2007
Quote:
Originally Posted by GermainZ View Post
You're hooking the wrong method, then. Look for the method that actually gets called for DownloadManager (check its source, make a test app, possibly use Xposed Method Finder, etc).
Thanks for pointing me to the tool. Although based on the source code from KK/JB trunks, I am pretty confident that any app using DM must use enqueue, its still worth to be sure. I will upload a sample app here to help understand and debug this issue.
 
ie5x
Old
#7  
Junior Member - OP
Thanks Meter 0
Posts: 21
Join Date: Nov 2007
Quote:
Originally Posted by ie5x View Post
Thanks for pointing me to the tool. Although based on the source code from KK/JB trunks, I am pretty confident that any app using DM must use enqueue, its still worth to be sure. I will upload a sample app here to help understand and debug this issue.
Turned out both Chrome and AOSP browser on Kitkat weren't using DownloadManager enqueue . They natively handle downloads and only use DM for reporting downloaded files in its queue. This was unexpected because these apps used DM in Jellybean. A custom test app calling enqueue successfully invoked the callbacks. Thanks for your help!

This thread can be closed.
 
rovo89
Old
#8  
rovo89's Avatar
Senior Recognized Developer
Thanks Meter 14,104
Posts: 2,367
Join Date: Jan 2012
Quote:
Originally Posted by ie5x View Post
Turned out both Chrome and AOSP browser on Kitkat weren't using DownloadManager enqueue . They natively handle downloads and only use DM for reporting downloaded files in its queue. This was unexpected because these apps used DM in Jellybean. A custom test app calling enqueue successfully invoked the callbacks. Thanks for your help!

This thread can be closed.
That's why I suggested trying it with Xposed Installer, because I know for sure that it uses DM.enqueue(). Just tried it and it worked fine.
Tired of updating your mod for every new ROM release?
You want give users the possibility to combine different mods without creating tons of different files for all possible combinations?
Then have a look at my Xposed framework - modifications without APK changes!
 
ie5x
Old
#9  
Junior Member - OP
Thanks Meter 0
Posts: 21
Join Date: Nov 2007
Quote:
Originally Posted by rovo89 View Post
That's why I suggested trying it with Xposed Installer, because I know for sure that it uses DM.enqueue(). Just tried it and it worked fine.
I was being too sure for my own good. Went through a lot of code for Chrome and AOSP browsers and up to Jelly Bean my hooks were working damn fine. Couldn't doubt that the behavior would be different for Kitkat. Well, lessons learned the hard way are the hardest to forget .

Thanks again @rovo89 for helping me out.

Tags
callback not working kitkat
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes