package com.oasisfeng.variants;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.os.Environment;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * MIUI related functions
 *
 * Created by Oasis on 2015/9/29.
 */
public class Miui {

	public static boolean isMiuiRom() {
		if (sMiuiVerName == null) sMiuiVerName = getMiuiVerName();
		return ! sMiuiVerName.isEmpty();
	}

	private static String getMiuiVerName() {
		final Properties prop = new Properties();
		final File file = new File(Environment.getRootDirectory(), "build.prop");
		try {
			prop.load(new FileInputStream(file));
		} catch (final IOException e) {
			try {	// Try again once more
				prop.load(new FileInputStream(file));
			} catch (final IOException ex) {
				return "";
			}
		}
		final String ver_name = prop.getProperty("ro.miui.ui.version.name");
		return ver_name == null ? "" : ver_name;
	}
	private static String sMiuiVerName;

	public static boolean startRootSettings(final Context context) {
		try {
			context.startActivity(new Intent("miui.intent.action.ROOT_MANAGER").addCategory(Intent.CATEGORY_DEFAULT));
			return true;
		} catch (final ActivityNotFoundException e) {
			return false;
		}
	}

	public static boolean startAutoStartSettings(final Context context) {
		try {
			context.startActivity(new Intent("miui.intent.action.OP_AUTO_START").addCategory(Intent.CATEGORY_DEFAULT));
			return true;
		} catch (final ActivityNotFoundException e) {
			return false;
		}
	}

	public static boolean startAppPermissionSettings(final Context context, final String pkg) {
		try {
			context.startActivity(new Intent("miui.intent.action.APP_PERM_EDITOR").putExtra("extra_pkgname", pkg));
			return true;
		} catch (final ActivityNotFoundException e) {
			return false;
		}
	}
}

@@ -1612,29 +1612,28 @@
  static 
-boolean start
+Intent build
 AppPermi
@@ -1649,85 +1649,44 @@
 ings
-(final Context context, final String pkg) %7B%0A%09%09try %7B%0A%09%09%09context.startActivity(
+Intent(final String pkg) %7B%0A%09%09return 
 new 
@@ -1764,95 +1764,9 @@
 pkg)
-);%0A%09%09%09return true;%0A%09%09%7D catch (final ActivityNotFoundException e) %7B%0A%09%09%09return false;%0A%09%09%7D
+;
 %0A%09%7D%0A

Replace Miui.startAppPermissionSettings() with buildAppPermissionSettingsIntent() to allow caller to resolve the activity.