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

Search This thread

ie5x

Member
Nov 15, 2007
43
3
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?
 
Last edited:

rovo89

Senior Recognized Developer
Jan 4, 2012
2,585
81,434
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.
 
  • Like
Reactions: ie5x

ie5x

Member
Nov 15, 2007
43
3
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 :confused:.

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

Inactive Recognized Developer / Retired Forum Mod
Aug 3, 2012
6,170
8,805
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).
 
  • Like
Reactions: ie5x

ie5x

Member
Nov 15, 2007
43
3
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.
 
  • Like
Reactions: aodlove999

ie5x

Member
Nov 15, 2007
43
3
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 :silly:. 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

Senior Recognized Developer
Jan 4, 2012
2,585
81,434
Turned out both Chrome and AOSP browser on Kitkat weren't using DownloadManager enqueue :silly:. 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.
 

ie5x

Member
Nov 15, 2007
43
3
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.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    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.
    1
    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).
    1
    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.