Add restricted settings UI in Settings accessibility screeen
If OP_ACCESS_RESTRICTED_SETTINGS is rejected, it means accessibility page for that app is gray out and app info won't show "unlock restricted settings menu" If OP_ACCESS_RESTRICTED_SETTINGS is ignored, it means accessibility page for that app is gray out, but app info shows "unlock restricted settings menu" If OP_ACCESS_RESTRICTED_SETTINGS is allowed(default), it means users can access accessibility page for that app. OP_ACCESS_RESTRICTED_SETTINGS will be changed to ignored if user visited the restricted settings dialog. OP_ACCESS_RESTRICTED_SETTINGS will be changed to allowed if user passes the confirmation screen. Bug: 202130031 Test: Tested the UI and it works correctly Change-Id: I3dfb94cee440658b4726a1c3f7265f93cd19ed3e
This commit is contained in:
@@ -19,6 +19,8 @@ package com.android.settings.applications.appinfo;
|
||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AppOpsManager;
|
||||
import android.app.KeyguardManager;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.BroadcastReceiver;
|
||||
@@ -30,8 +32,13 @@ import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.hardware.biometrics.BiometricManager;
|
||||
import android.hardware.biometrics.BiometricPrompt;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.text.TextUtils;
|
||||
@@ -82,6 +89,7 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
@VisibleForTesting
|
||||
static final int UNINSTALL_UPDATES = 2;
|
||||
static final int INSTALL_INSTANT_APP_MENU = 3;
|
||||
static final int ACCESS_RESTRICTED_SETTINGS = 4;
|
||||
|
||||
// Result code identifiers
|
||||
@VisibleForTesting
|
||||
@@ -261,6 +269,7 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
if (!refreshUi()) {
|
||||
setIntentAndFinish(true, true);
|
||||
}
|
||||
getActivity().invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -381,6 +390,9 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||
menu.add(0, UNINSTALL_ALL_USERS_MENU, 1, R.string.uninstall_all_users_text)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||
menu.add(0, ACCESS_RESTRICTED_SETTINGS, 0,
|
||||
R.string.app_restricted_settings_lockscreen_title)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -390,6 +402,7 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
}
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
menu.findItem(UNINSTALL_ALL_USERS_MENU).setVisible(shouldShowUninstallForAll(mAppEntry));
|
||||
menu.findItem(ACCESS_RESTRICTED_SETTINGS).setVisible(shouldShowAccessRestrictedSettings());
|
||||
mUpdatedSysApp = (mAppEntry.info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
|
||||
final MenuItem uninstallUpdatesItem = menu.findItem(UNINSTALL_UPDATES);
|
||||
final boolean uninstallUpdateDisabled = getContext().getResources().getBoolean(
|
||||
@@ -404,6 +417,46 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
}
|
||||
}
|
||||
|
||||
private static void showLockScreen(Context context, Runnable successRunnable) {
|
||||
final KeyguardManager keyguardManager = context.getSystemService(
|
||||
KeyguardManager.class);
|
||||
|
||||
if (keyguardManager.isKeyguardSecure()) {
|
||||
final BiometricPrompt.AuthenticationCallback authenticationCallback =
|
||||
new BiometricPrompt.AuthenticationCallback() {
|
||||
@Override
|
||||
public void onAuthenticationSucceeded(
|
||||
BiometricPrompt.AuthenticationResult result) {
|
||||
successRunnable.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationError(int errorCode, CharSequence errString) {
|
||||
//Do nothing
|
||||
}
|
||||
};
|
||||
|
||||
final BiometricPrompt.Builder builder = new BiometricPrompt.Builder(context)
|
||||
.setTitle(context.getText(R.string.app_restricted_settings_lockscreen_title));
|
||||
|
||||
if (context.getSystemService(BiometricManager.class).canAuthenticate(
|
||||
BiometricManager.Authenticators.DEVICE_CREDENTIAL
|
||||
| BiometricManager.Authenticators.BIOMETRIC_WEAK)
|
||||
== BiometricManager.BIOMETRIC_SUCCESS) {
|
||||
builder.setAllowedAuthenticators(BiometricManager.Authenticators.DEVICE_CREDENTIAL
|
||||
| BiometricManager.Authenticators.BIOMETRIC_WEAK);
|
||||
}
|
||||
|
||||
final BiometricPrompt bp = builder.build();
|
||||
final Handler handler = new Handler(Looper.getMainLooper());
|
||||
bp.authenticate(new CancellationSignal(),
|
||||
runnable -> handler.post(runnable),
|
||||
authenticationCallback);
|
||||
} else {
|
||||
successRunnable.run();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
@@ -413,6 +466,17 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
case UNINSTALL_UPDATES:
|
||||
uninstallPkg(mAppEntry.info.packageName, false, false);
|
||||
return true;
|
||||
case ACCESS_RESTRICTED_SETTINGS:
|
||||
showLockScreen(getContext(), () -> {
|
||||
final AppOpsManager appOpsManager = getContext().getSystemService(
|
||||
AppOpsManager.class);
|
||||
appOpsManager.setMode(AppOpsManager.OP_ACCESS_RESTRICTED_SETTINGS,
|
||||
getUid(),
|
||||
getPackageName(),
|
||||
AppOpsManager.MODE_ALLOWED);
|
||||
getActivity().invalidateOptionsMenu();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
@@ -436,6 +500,18 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldShowAccessRestrictedSettings() {
|
||||
try {
|
||||
final int mode = getSystemService(AppOpsManager.class).noteOpNoThrow(
|
||||
AppOpsManager.OP_ACCESS_RESTRICTED_SETTINGS, getUid(),
|
||||
getPackageName());
|
||||
return mode == AppOpsManager.MODE_IGNORED;
|
||||
} catch (Exception e) {
|
||||
// Fallback in case if app ops is not available in testing.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean shouldShowUninstallForAll(AppEntry appEntry) {
|
||||
boolean showIt = true;
|
||||
|
Reference in New Issue
Block a user