导航菜单

页面标题

页面副标题

Fix Locker v1.5 - PermissionActivity.java 源代码

正在查看: Fix Locker v1.5 应用的 PermissionActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.user.a4keygen.activity;

import android.app.AppOpsManager;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.user.a4keygen.R;
import com.user.a4keygen.receiver.DeviceAdmin;
import com.user.a4keygen.services.NfplAccessibilityService;
import com.user.a4keygen.sharedprefrence.SharedPrefManager;
import com.user.a4keygen.util.AutoStartPermissionHelper;
import com.user.a4keygen.util.BatteryManagerUtil;

public class PermissionActivity extends AppCompatActivity {
    private static final int ACCESSIBILITY_ENABLED = 1;
    private static final int REQUEST_CODE_ENABLE_ACCESSIBLITY = 105;
    private static final int REQUEST_CODE_ENABLE_ADMIN = 101;
    private static final int REQUEST_CODE_ENABLE_BATTERYMANAGER = 109;
    private static final int REQUEST_CODE_ENABLE_BATTERYOPTI = 103;
    private static final int REQUEST_CODE_ENABLE_DEVICE_AUTOSTART = 104;
    private static final int REQUEST_CODE_ENABLE_OVERLAY = 102;
    private static final int REQUEST_CODE_ENABLE_RUNTIME = 106;
    private static final int REQUEST_CODE_USAGE_ACCESS = 108;
    private static final int REQUEST_CODE_WRITE_SETTING = 107;
    private Button btndone;
    private CardView cardAccessiblityPermission;
    private CardView cardAutoStart;
    private CardView cardBattery;
    private CardView cardBatteryPower;
    private CardView cardDeviceAdmin;
    private CardView cardOverlay;
    private CardView cardRuntime;
    private CardView cardUsageAccess;
    private CardView cardWriteSetting;
    private DevicePolicyManager dpm;
    private TextView tvAccessiblityPermission;
    private TextView tvAutoStart;
    private TextView tvBattery;
    private TextView tvBatteryPower;
    private TextView tvDeviceAdmin;
    private TextView tvOverlay;
    private TextView tvRuntime;
    private TextView tvUsageAccess;
    private TextView tvWriteSetting;
    private int isAutostartChecked = 0;
    private int isNotificationScreenChecked = 0;
    private int isBatteryScreenChecked = 0;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_permission);
        initialize();
        checkAllpermissions();
        this.btndone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                PermissionActivity.this.startActivity(new Intent((Context) PermissionActivity.this, (Class<?>) LockingActvity.class));
            }
        });
        this.cardBattery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (PermissionActivity.this.isIgnoringBatteryOptimize()) {
                    PermissionActivity.this.tvBattery.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
                    return;
                }
                if (Build.VERSION.SDK_INT < 23) {
                    PermissionActivity.this.tvBattery.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
                    return;
                }
                Intent intent = new Intent();
                intent.setAction("android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS");
                intent.setData(Uri.parse("package:" + PermissionActivity.this.getPackageName()));
                PermissionActivity.this.startActivityForResult(intent, 103);
            }
        });
        this.cardRuntime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (PermissionActivity.this.checkRuntimePermission()) {
                    PermissionActivity.this.tvRuntime.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
                }
            }
        });
        this.cardOverlay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (PermissionActivity.this.checkOverlayPermission()) {
                    PermissionActivity.this.tvOverlay.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
                } else if (Build.VERSION.SDK_INT < 23 || Settings.canDrawOverlays(PermissionActivity.this)) {
                    PermissionActivity.this.tvOverlay.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
                } else {
                    PermissionActivity.this.startActivityForResult(new Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION", Uri.parse("package:" + PermissionActivity.this.getPackageName())), 102);
                }
            }
        });
        this.cardUsageAccess.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (PermissionActivity.this.isUsageAccessGranted()) {
                    PermissionActivity.this.tvUsageAccess.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
                } else {
                    PermissionActivity.this.startActivityForResult(new Intent("android.settings.USAGE_ACCESS_SETTINGS"), 108);
                }
            }
        });
        this.cardDeviceAdmin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (PermissionActivity.this.isActiveAdmin()) {
                    PermissionActivity.this.tvDeviceAdmin.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
                    return;
                }
                ComponentName componentName = new ComponentName((Context) PermissionActivity.this, (Class<?>) DeviceAdmin.class);
                Intent intent = new Intent("android.app.action.ADD_DEVICE_ADMIN");
                intent.putExtra("android.app.extra.DEVICE_ADMIN", componentName);
                intent.putExtra("android.app.extra.ADD_EXPLANATION", PermissionActivity.this.getString(R.string.lblDeviceAdmindescription));
                PermissionActivity.this.startActivityForResult(intent, 101);
            }
        });
        this.cardWriteSetting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (PermissionActivity.this.isActiveWriteSettingPermission()) {
                    PermissionActivity.this.tvWriteSetting.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
                }
            }
        });
        this.cardAccessiblityPermission.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ?? r3 = PermissionActivity.this;
                if (r3.isAccessibilitySettingsOn(r3)) {
                    PermissionActivity.this.tvAccessiblityPermission.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
                } else {
                    PermissionActivity.this.startActivityForResult(new Intent("android.settings.ACCESSIBILITY_SETTINGS"), 105);
                }
            }
        });
        this.cardAutoStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (PermissionActivity.this.isAutostartChecked == 0) {
                    PermissionActivity.this.isAutostartChecked = 1;
                    AutoStartPermissionHelper.getInstance().getAutoStartPermission(PermissionActivity.this);
                } else {
                    PermissionActivity.this.tvAutoStart.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
                }
            }
        });
        this.cardBatteryPower.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                PermissionActivity.this.isBatteryScreenChecked = 1;
                String messageText = BatteryManagerUtil.getInstance().getMessageText(PermissionActivity.this);
                final String packageName = BatteryManagerUtil.getInstance().getPackageName(PermissionActivity.this);
                AlertDialog.Builder builder = new AlertDialog.Builder(PermissionActivity.this);
                builder.setMessage(messageText).setTitle("Battery Permission!").setCancelable(false).setPositiveButton("Go to Settings", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                        SharedPrefManager.getInstance(PermissionActivity.this).setBatteryPwrUsgChecked(true);
                        PermissionActivity.this.startActivityForResult(new Intent(packageName), 109);
                    }
                });
                builder.show();
            }
        });
    }

    private void initialize() {
        this.btndone = (Button) findViewById(R.id.btndone);
        this.tvBattery = (TextView) findViewById(R.id.tvBattery);
        this.tvAutoStart = (TextView) findViewById(R.id.tvAutoStart);
        this.tvBatteryPower = (TextView) findViewById(R.id.tvBatteryPower);
        this.tvRuntime = (TextView) findViewById(R.id.tvRunTime);
        this.tvOverlay = (TextView) findViewById(R.id.tvOverlay);
        this.tvUsageAccess = (TextView) findViewById(R.id.tvUsageAccess);
        this.tvDeviceAdmin = (TextView) findViewById(R.id.tvDeviceAdmin);
        this.tvWriteSetting = (TextView) findViewById(R.id.tvWriteSetting);
        this.tvAccessiblityPermission = (TextView) findViewById(R.id.tvAccessiblityPermission);
        this.cardBattery = findViewById(R.id.cardBattery);
        this.cardRuntime = findViewById(R.id.cardRuntime);
        this.cardOverlay = findViewById(R.id.cardOverlay);
        this.cardUsageAccess = findViewById(R.id.cardUsageAccess);
        this.cardDeviceAdmin = findViewById(R.id.cardDeviceAdmin);
        this.cardBatteryPower = findViewById(R.id.cardBatteryPower);
        this.cardWriteSetting = findViewById(R.id.cardWriteSetting);
        this.cardAccessiblityPermission = findViewById(R.id.cardAccessiblityPermission);
        this.cardAutoStart = findViewById(R.id.cardAutoStart);
        SharedPrefManager.getInstance(this).saveSetupCompleted("I");
        this.dpm = (DevicePolicyManager) getSystemService("device_policy");
    }

    private boolean checkAllpermissions() {
        boolean z;
        try {
            if (isIgnoringBatteryOptimize()) {
                this.tvBattery.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
                z = true;
            } else {
                this.tvBattery.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_cross_red_24, 0, 0);
                z = false;
            }
            if (checkRuntimePermission()) {
                this.tvRuntime.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
            } else {
                this.tvRuntime.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_cross_red_24, 0, 0);
                z = false;
            }
            if (checkOverlayPermission()) {
                this.tvOverlay.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
            } else {
                this.tvOverlay.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_cross_red_24, 0, 0);
                z = false;
            }
            if (isActiveAdmin()) {
                this.tvDeviceAdmin.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
            } else {
                this.tvDeviceAdmin.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_cross_red_24, 0, 0);
                z = false;
            }
            if (isAccessibilitySettingsOn(this)) {
                this.tvAccessiblityPermission.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
            } else {
                this.tvAccessiblityPermission.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_cross_red_24, 0, 0);
                z = false;
            }
            if (isActiveWriteSettingPermission()) {
                this.tvWriteSetting.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
            } else {
                this.tvWriteSetting.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_cross_red_24, 0, 0);
                z = false;
            }
            if (isUsageAccessGranted()) {
                this.tvUsageAccess.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
            } else {
                this.tvUsageAccess.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_cross_red_24, 0, 0);
                z = false;
            }
            if ("samsung".equalsIgnoreCase(Build.BRAND)) {
                if (SharedPrefManager.getInstance(this).isBatteryPwrUsgStartChecked()) {
                    this.tvBatteryPower.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
                } else {
                    this.tvBatteryPower.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_cross_red_24, 0, 0);
                    z = false;
                }
            }
            if (this.isAutostartChecked == 1) {
                this.tvAutoStart.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
                return z;
            }
            this.tvAutoStart.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_cross_red_24, 0, 0);
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public boolean isAccessibilitySettingsOn(Context context) {
        int i;
        String string;
        String str = context.getPackageName() + "/" + NfplAccessibilityService.class.getCanonicalName();
        try {
            i = Settings.Secure.getInt(context.getApplicationContext().getContentResolver(), "accessibility_enabled");
        } catch (Settings.SettingNotFoundException e) {
            Log.e("AU", "Error finding setting, default accessibility to not found: " + e.getMessage());
            i = 0;
        }
        TextUtils.SimpleStringSplitter simpleStringSplitter = new TextUtils.SimpleStringSplitter(':');
        if (i == 1 && (string = Settings.Secure.getString(context.getApplicationContext().getContentResolver(), "enabled_accessibility_services")) != null) {
            simpleStringSplitter.setString(string);
            while (simpleStringSplitter.hasNext()) {
                if (simpleStringSplitter.next().equalsIgnoreCase(str)) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean isActiveAdmin() {
        return this.dpm.isAdminActive(new ComponentName((Context) this, (Class<?>) DeviceAdmin.class));
    }

    public boolean isActiveWriteSettingPermission() {
        if (Build.VERSION.SDK_INT >= 23 && !Settings.System.canWrite(this)) {
            Intent intent = new Intent("android.settings.action.MANAGE_WRITE_SETTINGS");
            intent.setData(Uri.parse("package:" + getPackageName()));
            startActivityForResult(intent, 107);
        }
        return true;
    }

    public boolean checkRuntimePermission() {
        if (Build.VERSION.SDK_INT < 23 || ContextCompat.checkSelfPermission(this, "android.permission.PROCESS_OUTGOING_CALLS") == 0) {
            return true;
        }
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, "android.permission.PROCESS_OUTGOING_CALLS")) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setCancelable(true);
            builder.setTitle(getString(R.string.titlePermission));
            builder.setMessage(getString(R.string.contentPermission));
            builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    ActivityCompat.requestPermissions(PermissionActivity.this, new String[]{"android.permission.PROCESS_OUTGOING_CALLS"}, 106);
                }
            });
            builder.create().show();
            return false;
        }
        ActivityCompat.requestPermissions(this, new String[]{"android.permission.PROCESS_OUTGOING_CALLS"}, 106);
        return false;
    }

    public boolean checkOverlayPermission() {
        try {
            if (Build.VERSION.SDK_INT >= 23) {
                return Settings.canDrawOverlays(this);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public boolean isIgnoringBatteryOptimize() {
        try {
            if (Build.VERSION.SDK_INT >= 23) {
                return ((PowerManager) getSystemService("power")).isIgnoringBatteryOptimizations(getPackageName());
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public boolean isUsageAccessGranted() {
        try {
            ApplicationInfo applicationInfo = getPackageManager().getApplicationInfo(getPackageName(), 0);
            return (Build.VERSION.SDK_INT > 19 ? ((AppOpsManager) getSystemService("appops")).checkOpNoThrow("android:get_usage_stats", applicationInfo.uid, applicationInfo.packageName) : 0) == 0;
        } catch (PackageManager.NameNotFoundException unused) {
            return false;
        }
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i2 != -1) {
            Log.e("tag", "else called");
            if (i == 109) {
                this.tvBatteryPower.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
                return;
            }
            if (i == 102) {
                if (checkOverlayPermission()) {
                    Toast.makeText((Context) this, (CharSequence) "OVERLAY ENABLE", 1).show();
                    this.tvOverlay.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
                    return;
                }
                return;
            }
            if (i == 108) {
                if (isUsageAccessGranted()) {
                    Toast.makeText((Context) this, (CharSequence) "usage access enable", 1).show();
                    this.tvUsageAccess.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
                    return;
                }
                return;
            }
            if (i == 105 && isAccessibilitySettingsOn(this)) {
                Toast.makeText((Context) this, (CharSequence) "accessiblty enable", 1).show();
                this.tvAccessiblityPermission.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
                return;
            }
            return;
        }
        if (i == 102) {
            Toast.makeText((Context) this, (CharSequence) "OVERLAY ENABLE", 1).show();
            this.tvOverlay.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
            return;
        }
        if (i == 103) {
            Toast.makeText((Context) this, (CharSequence) "Battery optimisation off", 1).show();
            this.tvBattery.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
            return;
        }
        if (i == 101) {
            Toast.makeText((Context) this, (CharSequence) "Your now admin", 1).show();
            this.tvDeviceAdmin.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
            return;
        }
        if (i == 104) {
            this.isAutostartChecked = 1;
            Toast.makeText((Context) this, (CharSequence) "app autostart enable", 1).show();
            return;
        }
        if (i == 105) {
            Toast.makeText((Context) this, (CharSequence) "accessiblty enable", 1).show();
            this.tvAccessiblityPermission.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
        } else if (i == 107) {
            Toast.makeText((Context) this, (CharSequence) "app write setting enable", 1).show();
            this.tvWriteSetting.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
        } else if (i == 108) {
            Toast.makeText((Context) this, (CharSequence) "usage access enable", 1).show();
            this.tvUsageAccess.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_check_circle_24, 0, 0);
        }
    }

    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        if (i != 106) {
            return;
        }
        if (iArr.length > 0 && iArr[0] == 0) {
            checkAllpermissions();
        } else {
            checkAllpermissions();
        }
    }
}