AppListFragment: disallow cloning on MIUI

This commit is contained in:
Peter Cai 2018-08-29 19:05:45 +08:00
parent 08155dca25
commit 443f191b00
No known key found for this signature in database
GPG key ID: 71F5FB4E4F3FD54F
3 changed files with 14 additions and 5 deletions

View file

@ -17,6 +17,7 @@ import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ContextMenu;
@ -218,7 +219,15 @@ public class AppListFragment extends Fragment {
switch (item.getItemId()) {
case MENU_ITEM_CLONE:
installOrUninstall(mSelectedApp, true);
if (Utility.isMIUI() && !mSelectedApp.isSystem()) {
// Cannot clone non-system apps on MIUI
new AlertDialog.Builder(getContext())
.setMessage(R.string.miui_cannot_clone)
.setPositiveButton(android.R.string.ok, null)
.show();
} else {
installOrUninstall(mSelectedApp, true);
}
return true;
case MENU_ITEM_UNINSTALL:
installOrUninstall(mSelectedApp, false);

View file

@ -127,10 +127,9 @@ 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 || isMIUI()) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
// 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");
}
@ -145,8 +144,6 @@ public class Utility {
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;

View file

@ -59,4 +59,7 @@
<string name="app_context_menu_title">Operations for %s</string>
<string name="freeze_all_success">All apps in \"Auto Freeze\" list have been frozen successfully.</string>
<string name="shortcut_create_success">Shortcut created on your launcher.</string>
<!-- MIUI -->
<string name="miui_cannot_clone">Cloning non-system apps to another profile is currently not possible on MIUI. Please clone your system\'s app store (e.g. <b>Play Store</b>) into the other profile and then install apps from there.</string>
</resources>