245 lines
9.4 KiB
Java
245 lines
9.4 KiB
Java
package com.xuebiping.bolizhuzi.utils;
|
|
|
|
import android.content.ComponentName;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.net.Uri;
|
|
import android.os.Build;
|
|
import android.provider.Settings;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
|
|
import com.fengliyan.uikit.toast.MaleToast;
|
|
import com.xuebiping.bolizhuzi.BuildConfig;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
|
|
|
|
public class PermissionUtil {
|
|
public static void jumpPermissionPage(Context context) {
|
|
String manufacturer = Build.MANUFACTURER.toLowerCase();
|
|
switch (manufacturer) {
|
|
case "xiaomi":
|
|
goXiaoMiManager(context);
|
|
break;
|
|
case "huawei":
|
|
goHuaWeiManager(context);
|
|
break;
|
|
case "oppo":
|
|
goOppoManager(context);
|
|
break;
|
|
case "meizu":
|
|
goMeizuManager(context);
|
|
break;
|
|
case "samsung":
|
|
goSamsungManager(context);
|
|
break;
|
|
case "sony":
|
|
goSonyManager(context);
|
|
break;
|
|
case "lg":
|
|
goLGManager(context);
|
|
break;
|
|
case "letv":
|
|
goLetvManager(context);
|
|
break;
|
|
case "qiku":
|
|
case "360":
|
|
go360Manager(context);
|
|
break;
|
|
case "vivo":
|
|
goVivoManager(context);
|
|
break;
|
|
default:
|
|
goAppDetailSetting(context);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private static void goXiaoMiManager(Context context) {
|
|
String rom = checkMIUI();
|
|
try{
|
|
Intent intent =new Intent();
|
|
if ("V5".equals(rom)) {
|
|
Uri packageURI = Uri.parse("package:" + BuildConfig.APPLICATION_ID);
|
|
intent =new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI);
|
|
} else if ("V6".equals(rom) || "V7".equals(rom)) {
|
|
intent.setAction("miui.intent.action.APP_PERM_EDITOR");
|
|
intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
|
|
intent.putExtra("extra_pkgname", BuildConfig.APPLICATION_ID);
|
|
} else if ("V8".equals(rom) || "V9".equals(rom)||"V10".equals(rom) || "V11".equals(rom)|| "V12".equals(rom)) {
|
|
intent.setAction("miui.intent.action.APP_PERM_EDITOR");
|
|
intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");
|
|
intent.putExtra("extra_pkgname", BuildConfig.APPLICATION_ID);
|
|
} else {
|
|
goAppDetailSetting(context);
|
|
}
|
|
context.startActivity(intent);
|
|
}catch (Exception e) {
|
|
goAppDetailSetting(context);
|
|
}
|
|
}
|
|
|
|
private static void goHuaWeiManager(Context context) {
|
|
try {
|
|
Intent intent =new Intent(BuildConfig.APPLICATION_ID);
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
ComponentName comp = new ComponentName("com.huawei.systemmanager", "com.huawei.permissionmanager.ui.MainActivity");
|
|
intent.setComponent(comp);
|
|
context.startActivity(intent);
|
|
} catch (Exception e) {
|
|
goAppDetailSetting(context);
|
|
}
|
|
}
|
|
|
|
private static void goOppoManager(Context context) {
|
|
try {
|
|
Intent intent =new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
ComponentName comp = new ComponentName("com.coloros.securitypermission", "com.coloros.securitypermission.permission.PermissionAppAllPermissionActivity");
|
|
intent.setComponent(comp);
|
|
context.startActivity(intent);
|
|
} catch (Exception e) {
|
|
goAppDetailSetting(context);
|
|
}
|
|
}
|
|
|
|
private static void goMeizuManager(Context context) {
|
|
try {
|
|
Intent intent = new Intent("com.meizu.safe.security.SHOW_APPSEC");
|
|
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
|
intent.putExtra("packageName", BuildConfig.APPLICATION_ID);
|
|
context.startActivity(intent);
|
|
} catch (Exception e) {
|
|
goAppDetailSetting(context);
|
|
}
|
|
}
|
|
private static void goSamsungManager(Context context) {
|
|
goAppDetailSetting(context);
|
|
}
|
|
|
|
private static void goSonyManager(Context context) {
|
|
try {
|
|
Intent intent =new Intent(BuildConfig.APPLICATION_ID);
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
ComponentName comp = new ComponentName("com.sonymobile.cta", "com.sonymobile.cta.SomcCTAMainActivity");
|
|
intent.setComponent(comp);
|
|
context.startActivity(intent);
|
|
} catch (Exception e) {
|
|
goAppDetailSetting(context);
|
|
}
|
|
}
|
|
|
|
private static void goLGManager(Context context) {
|
|
try {
|
|
Intent intent = new Intent("android.intent.action.MAIN");
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
intent.putExtra("packageName", BuildConfig.APPLICATION_ID);
|
|
ComponentName comp =new ComponentName("com.android.settings", "com.android.settings.Settings.AccessLockSummaryActivity");
|
|
intent.setComponent(comp);
|
|
context.startActivity(intent);
|
|
} catch (Exception e) {
|
|
goAppDetailSetting(context);
|
|
}
|
|
}
|
|
|
|
private static void goLetvManager(Context context) {
|
|
try {
|
|
Intent intent =new Intent();
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
intent.putExtra("packageName", BuildConfig.APPLICATION_ID);
|
|
ComponentName comp =new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.PermissionAndApps");
|
|
intent.setComponent(comp);
|
|
context.startActivity(intent);
|
|
} catch (Exception e) {
|
|
goAppDetailSetting(context);
|
|
}
|
|
}
|
|
|
|
private static void go360Manager(Context context) {
|
|
try {
|
|
Intent intent = new Intent("android.intent.action.MAIN");
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
intent.putExtra("packageName", BuildConfig.APPLICATION_ID);
|
|
ComponentName comp =new ComponentName("com.android.settings", "com.android.settings.Settings.AccessLockSummaryActivity");
|
|
intent.setComponent(comp);
|
|
context.startActivity(intent);
|
|
} catch (Exception e) {
|
|
goAppDetailSetting(context);
|
|
}
|
|
}
|
|
|
|
private static void goVivoManager(Context context) {
|
|
try {
|
|
/* Intent intent = new Intent();
|
|
intent.setClassName("com.vivo.permissionmanager","com.vivo.permissionmanager.activity.SoftPermissionDetailActivity");
|
|
intent.setAction("secure.intent.action.softPermissionDetail");
|
|
intent.putExtra("packageName","BuildConfig.APPLICATION_ID");
|
|
context.startActivity(intent);*/
|
|
goAppDetailSetting(context);
|
|
} catch (Exception e) {
|
|
goAppDetailSetting(context);
|
|
}
|
|
}
|
|
|
|
public static void goAppDetailSetting(Context context) {
|
|
Intent intent = new Intent();
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
if(Build.VERSION.SDK_INT >= 9){
|
|
intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
|
|
intent.setData(Uri.fromParts("package", context.getPackageName(), null));
|
|
} else if(Build.VERSION.SDK_INT <= 8){
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
intent.setClassName("com.android.settings","com.android.settings.InstalledAppDetails");
|
|
intent.putExtra("com.android.settings.ApplicationPkgName", context.getPackageName());
|
|
}
|
|
try{
|
|
context.startActivity(intent);
|
|
}catch (Exception e) {
|
|
MaleToast.showMessage(context,"页面调转失败");
|
|
}
|
|
}
|
|
public static void goLocationSetting(Context context) {
|
|
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
|
context.startActivity(intent);
|
|
}
|
|
|
|
public static String checkMIUI() {
|
|
String versionCode = "";
|
|
String manufacturer = Build.MANUFACTURER;
|
|
String model = Build.MODEL;
|
|
Log.i("PermissionUtil","Build.MANUFACTURER = " + manufacturer + " ,Build.MODEL = " + Build.MODEL);
|
|
if (!TextUtils.isEmpty(manufacturer) && manufacturer.equals("Xiaomi")) {
|
|
versionCode = getSystemProperty("ro.miui.ui.version.name");
|
|
}
|
|
return versionCode;
|
|
}
|
|
|
|
public static String getSystemProperty(String propName) {
|
|
String line;
|
|
BufferedReader input = null;
|
|
try {
|
|
Process p = Runtime.getRuntime().exec("getprop " + propName);
|
|
input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
|
|
line = input.readLine();
|
|
input.close();
|
|
} catch (IOException ex) {
|
|
Log.i("PermissionUtil","Unable to read sysprop " + propName, ex);
|
|
return null;
|
|
} finally {
|
|
if (input != null) {
|
|
try {
|
|
input.close();
|
|
} catch (IOException e) {
|
|
Log.i("PermissionUtil","Exception while closing InputStream", e);
|
|
}
|
|
}
|
|
}
|
|
return line;
|
|
}
|
|
|
|
|
|
}
|