Gaming Console with Lollipop? Ouya Gets an Android TV Port

Android is a very flexible platform, and it can be used on a large variety of … more

Android App Review: Manage Your Connections Automagically – XDA TV

Material Design is all the buzz in the Android world right now. … more

Official TWRP Recovery Lands on Micromax Canvas Magnus

With the recent release of Android One, Micromax and MediaTek released fully buildable … more

Update Overload: SuperSU Heavily Updated

There are apps and apps out there. Very few can reach the level of popularity required to stay at … more

Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

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

OP ie5x

17th June 2014, 05:51 AM   |  #1  
OP Junior Member
Thanks Meter: 1
 
28 posts
Join Date:Joined: Nov 2007
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 by ie5x; 17th June 2014 at 06:17 AM. Reason: Corrected the hook name.
17th June 2014, 06:45 PM   |  #2  
OP Junior Member
Thanks Meter: 1
 
28 posts
Join Date:Joined: Nov 2007
Question
Anyone?
17th June 2014, 07:48 PM   |  #3  
rovo89's Avatar
Senior Recognized Developer
Thanks Meter: 15,039
 
2,385 posts
Join Date:Joined: Jan 2012
More
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.
The Following User Says Thank You to rovo89 For This Useful Post: [ View ]
18th June 2014, 05:15 AM   |  #4  
OP Junior Member
Thanks Meter: 1
 
28 posts
Join Date:Joined: Nov 2007
Quote:
Originally Posted by rovo89

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!
18th June 2014, 11:39 PM   |  #5  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,227
 
5,874 posts
Join Date:Joined: Aug 2012
Donate to Me
More
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: [ View ]
19th June 2014, 05:02 AM   |  #6  
OP Junior Member
Thanks Meter: 1
 
28 posts
Join Date:Joined: Nov 2007
Quote:
Originally Posted by GermainZ

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.
19th June 2014, 06:53 AM   |  #7  
OP Junior Member
Thanks Meter: 1
 
28 posts
Join Date:Joined: Nov 2007
Quote:
Originally Posted by ie5x

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.
19th June 2014, 11:13 AM   |  #8  
rovo89's Avatar
Senior Recognized Developer
Thanks Meter: 15,039
 
2,385 posts
Join Date:Joined: Jan 2012
More
Quote:
Originally Posted by ie5x

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.
19th June 2014, 11:48 AM   |  #9  
OP Junior Member
Thanks Meter: 1
 
28 posts
Join Date:Joined: Nov 2007
Quote:
Originally Posted by rovo89

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.

Post Reply Subscribe to Thread

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

Advanced Search
Display Modes