粘贴为Smali代码时,其他条件在OnRequestPermissions中不起作用

时间:2018-07-21 14:39:31

标签: java android smali

拒绝权限时,我正在尝试关闭应用程序。我要求获得读取IMEI号码的权限,以使应用手机专用于阻止共享。如果授予了权限且IMEI与我需要的不同,则应用程序会按预期关闭自己,但是当权限被拒绝(而不是关闭)时,应用程序会正常运行。应用是预先构建的,我正在通过反编译为smali对其进行修改。我不确定出什么问题了,这是Java等效代码:

public void onRequestPermissionsResult(int requestCode,
                                       String permissions[], int[] grantResults) {
    switch (requestCode) {
        case 1: {

            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                // permission was granted, yay! Do the
                // contacts-related task you need to do.

                TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
                String imei="";
                if (android.os.Build.VERSION.SDK_INT >= 26) {
                    imei=telephonyManager.getImei();
                }
                else
                {
                    imei=telephonyManager.getDeviceId();
                }

                if (!imei.equals("MY IMEI NUMBER")) {

                    android.os.Process.killProcess(android.os.Process.myPid());
                }
            } else {

                // permission denied, boo! Disable the
                // functionality that depends on this permission.
                // ;

                android.os.Process.killProcess(android.os.Process.myPid());
            }
            return;
        }

        // other 'case' lines to check for other
        // permissions this app might request
    }
}

这是smali的代码,除了else条件代码以外,其他代码都可以正常工作。你能建议做什么吗?

.method public onRequestPermissionsResult(I[Ljava/lang/String;[I)V
    .locals 4
    .param p1, "requestCode"    # I
    .param p2, "permissions"    # [Ljava/lang/String;
    .param p3, "grantResults"    # [I

    .prologue
    .line 38
    packed-switch p1, :pswitch_data_0

    .line 75
    :cond_0
    :goto_0
    return-void

    .line 42
    :pswitch_0
    array-length v2, p3

    if-lez v2, :cond_0

    const/4 v2, 0x0

    aget v2, p3, v2

    if-nez v2, :cond_0

    .line 48
    const-string v2, "phone"

    invoke-virtual {p0, v2}, Lcom/example/shahbaztalpur/example/search;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Landroid/telephony/TelephonyManager;

    .line 49
    .local v1, "telephonyManager":Landroid/telephony/TelephonyManager;
    const-string v0, ""

    .line 50
    .local v0, "imei":Ljava/lang/String;
    sget v2, Landroid/os/Build$VERSION;->SDK_INT:I

    const/16 v3, 0x1a

    if-lt v2, v3, :cond_1

    .line 51
    invoke-virtual {v1}, Landroid/telephony/TelephonyManager;->getImei()Ljava/lang/String;

    move-result-object v0

    .line 58
    :goto_1
    const-string v2, "MY IMEI"

    invoke-virtual {v0, v2}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v2

    if-nez v2, :cond_0

    .line 59
    const-string v2, "imei"

    invoke-static {v2, v0}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 60
    invoke-static {}, Landroid/os/Process;->myPid()I

    move-result v2

    invoke-static {v2}, Landroid/os/Process;->killProcess(I)V

    goto :goto_0

    .line 55
    :cond_1
    invoke-virtual {v1}, Landroid/telephony/TelephonyManager;->getDeviceId()Ljava/lang/String;

    move-result-object v0

    goto :goto_1

    .line 38

    // code at else starts here
    .end local v0    # "imei":Ljava/lang/String;
    .end local v1    # "telephonyManager":Landroid/telephony/TelephonyManager;
    :cond_2
    invoke-static {}, Landroid/os/Process;->myPid()I

    move-result v2

    invoke-static {v2}, Landroid/os/Process;->killProcess(I)V

    goto :goto_0

    .line 25
    nop

    // code of else finishes here


    :pswitch_data_0
    .packed-switch 0x1
        :pswitch_0
    .end packed-switch
.end method

0 个答案:

没有答案