diff --git a/app/src/main/java/net/typeblog/shelter/util/Utility.java b/app/src/main/java/net/typeblog/shelter/util/Utility.java index 5b7b75d..570aba8 100644 --- a/app/src/main/java/net/typeblog/shelter/util/Utility.java +++ b/app/src/main/java/net/typeblog/shelter/util/Utility.java @@ -26,6 +26,8 @@ import net.typeblog.shelter.services.IShelterService; import net.typeblog.shelter.ui.DummyActivity; import net.typeblog.shelter.ui.MainActivity; +import java.io.BufferedReader; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -125,9 +127,10 @@ public class Utility { manager.clearUserRestriction(adminComponent, UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES); manager.clearUserRestriction(adminComponent, UserManager.DISALLOW_UNINSTALL_APPS); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O || isMIUI()) { // Polyfill for UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES // Don't use this on Android Oreo and later, it will crash + // TODO: WIP: Maybe this is needed on MIUI manager.setSecureSetting(adminComponent, Settings.Secure.INSTALL_NON_MARKET_APPS, "1"); } @@ -136,6 +139,20 @@ public class Utility { manager.addUserRestriction(adminComponent, UserManager.ALLOW_PARENT_PROFILE_APP_LINKING); } + // Detect if the device is MIUI + public static boolean isMIUI() { + try { + Process proc = Runtime.getRuntime().exec("getprop ro.miui.ui.version.name"); + BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream())); + String line = reader.readLine().trim(); + // TODO: Remove this after trying on MIUI + android.util.Log.d("Utility", "ro.miui.ui.version.name = " + line); + return !line.isEmpty(); + } catch (Exception e) { + return false; + } + } + // From public static Bitmap drawableToBitmap(Drawable drawable) { if (drawable instanceof BitmapDrawable) {