• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

[Q] Does anybody uses Volley to send http request in Xposed module?

Search This thread

coom

Member
Apr 21, 2015
6
0
Volley is an HTTP library that makes networking for Android apps easier and faster.

We need to set the context before sending requests, according to nameless-technology.blogspot.com /2013/11/custom-system-service-using-xposedbridge.html, my testing code was:

Code:
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
            ...
   protected void beforeHookedMethod(MethodHookParam param) throws
            Throwable {
        ...
        Context context = (Context) param.getResult();
        RequestQueue queue = Volley.newRequestQueue(context);
        StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        msgs_g = response;
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                msgs_g = "That didn't work!";
            }
        });
        queue.add(stringRequest);


However, when the module was loading, there's an exception:

Code:
java.lang.NullPointerException
	at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:45)
	at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:105)
	at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:115)
	at xptest.tk.xpvolley.Sendoh$1.beforeHookedMethod(Sendoh.java:61)
	at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:611)
 

C3C076

Recognized Contributor
Dec 15, 2012
7,749
24,702
Bratislava
ceco.sk.eu.org
From code you provided it's not clear what method exactly you are hooking. But some remarks, anyway:
- are you sure original method returns context?
- I'm not sure whether using getResult() in before hook is a good practice, as you are basically asking for a return value when method was not executed, yet.
You should try after hook instead
 

coom

Member
Apr 21, 2015
6
0
From code you provided it's not clear what method exactly you are hooking. But some remarks, anyway:
- are you sure original method returns context?
- I'm not sure whether using getResult() in before hook is a good practice, as you are basically asking for a return value when method was not executed, yet.
You should try after hook instead

@C3C076 Thanks for your reply.

I just modified the code from `beforeHookedMethod` to `afterHookedMethod`, at this time, I got nothing in my log.

What I want to hook is the function `dispatchSensorEvent` in the `android.hardware.SystemSensorManager$SensorEventQueue` class. Actually I don't whether this method returns context, thanks for reminding me.

Finally I used `AsyncTask` with `DefaultHttpClient` to get the data from the web site, I still use `beforeHookedMethod`.