资源列表-GPRS

1.GPRS的调用是通过ConnectivityManager.setMobileDataEnabled方法

2.官方把方法定义为private类型来对外禁用,需要java中的反射调用

3.反射机制会不会在smali文件中体现出调用底层方法的痕迹呢?

4.关键代码:

private ConnectivityManager mCM;

mCM = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);    

Class cmClass       = mCM.getClass();    

Class[] argClasses  = new Class[1];    

argClasses[0]       = boolean.class;    

try    

{    

        Method method = cmClass.getMethod(methodName, argClasses);    

    method.invoke(mCM, isEnable);    

} catch (Exception e)    

{    

      e.printStackTrace();    

}    

 5.反编译出来的smali文件长这样:

.method private setGprsEnabled(Ljava/lang/String;Z)V
    .locals 8
    .param p1, "methodName"    # Ljava/lang/String;
    .param p2, "isEnable"    # Z

    .prologue
    const/4 v6, 0x1

    const/4 v5, 0x0

    .line 78
    iget-object v4, p0, Lcom/example/gprstest/MainActivity;->mCM:Landroid/net/ConnectivityManager;

    invoke-virtual {v4}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v1

    .line 79
    .local v1, "cmClass":Ljava/lang/Class;
    new-array v0, v6, [Ljava/lang/Class;

    .line 80
    .local v0, "argClasses":[Ljava/lang/Class;
    sget-object v4, Ljava/lang/Boolean;->TYPE:Ljava/lang/Class;

    aput-object v4, v0, v5

    .line 84
    :try_start_0
    invoke-virtual {v1, p1, v0}, Ljava/lang/Class;->getMethod(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;

    move-result-object v3

    .line 85
    .local v3, "method":Ljava/lang/reflect/Method;
    iget-object v4, p0, Lcom/example/gprstest/MainActivity;->mCM:Landroid/net/ConnectivityManager;

    const/4 v5, 0x1

    new-array v5, v5, [Ljava/lang/Object;

    const/4 v6, 0x0

    invoke-static {p2}, Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean;

    move-result-object v7

    aput-object v7, v5, v6

    invoke-virtual {v3, v4, v5}, Ljava/lang/reflect/Method;->invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 90
    .end local v3    # "method":Ljava/lang/reflect/Method;
    :goto_0
    return-void

    .line 86
    :catch_0
    move-exception v2

    .line 88
    .local v2, "e":Ljava/lang/Exception;
    invoke-virtual {v2}, Ljava/lang/Exception;->printStackTrace()V

    goto :goto_0
.end method

6.只有反射的痕迹......如何知道底层的调用?

7.最后附上以后学习可以参考的网址:

http://zwz94.blog.163.com/blog/static/3206039520140259468250/

http://www.blogjava.net/midea0978/archive/2012/01/04/367847.html

http://bbs.pediy.com/showthread.php?p=1117963

 

好吧,经过学长解答,具体的反射函数需要在寄存器中查看...

posted @ 2016-04-28 10:10  O_din  阅读(377)  评论(0编辑  收藏  举报