diff options
Diffstat (limited to 'src')
7 files changed, 58 insertions, 24 deletions
diff --git a/src/com/android/packageinstaller/permission/service/PermissionSearchIndexablesProvider.java b/src/com/android/packageinstaller/permission/service/PermissionSearchIndexablesProvider.java index 4be2b1a3..59647446 100644 --- a/src/com/android/packageinstaller/permission/service/PermissionSearchIndexablesProvider.java +++ b/src/com/android/packageinstaller/permission/service/PermissionSearchIndexablesProvider.java @@ -42,8 +42,6 @@ public class PermissionSearchIndexablesProvider extends BaseSearchIndexablesProv public static final String ACTION_MANAGE_PERMISSION_APPS = "com.android.permissioncontroller.settingssearch.action.MANAGE_PERMISSION_APPS"; - public static final String ACTION_REVIEW_PERMISSION_USAGE = - "com.android.permissioncontroller.settingssearch.action.REVIEW_PERMISSION_USAGE"; @Override public Cursor queryRawData(String[] projection) { @@ -67,12 +65,6 @@ public class PermissionSearchIndexablesProvider extends BaseSearchIndexablesProv .add(COLUMN_INTENT_ACTION, ACTION_MANAGE_PERMISSION_APPS); } - cursor.newRow().add(COLUMN_RANK, 0) - .add(COLUMN_TITLE, context.getString(R.string.permission_usage_title)) - .add(COLUMN_KEYWORDS, context.getString(R.string.permission_search_keyword)) - .add(COLUMN_KEY, createRawDataKey("permissions usage", context)) - .add(COLUMN_INTENT_ACTION, ACTION_REVIEW_PERMISSION_USAGE); - return cursor; } diff --git a/src/com/android/packageinstaller/permission/ui/ManagePermissionsActivityTrampoline.java b/src/com/android/packageinstaller/permission/ui/ManagePermissionsActivityTrampoline.java index 570782b5..b12be7bd 100644 --- a/src/com/android/packageinstaller/permission/ui/ManagePermissionsActivityTrampoline.java +++ b/src/com/android/packageinstaller/permission/ui/ManagePermissionsActivityTrampoline.java @@ -45,19 +45,14 @@ public class ManagePermissionsActivityTrampoline extends Activity { Intent newIntent = new Intent(this, ManagePermissionsActivity.class) .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); - switch (action) { - case PermissionSearchIndexablesProvider.ACTION_REVIEW_PERMISSION_USAGE: - newIntent.setAction(Intent.ACTION_REVIEW_PERMISSION_USAGE); - break; - case PermissionSearchIndexablesProvider.ACTION_MANAGE_PERMISSION_APPS: - newIntent - .setAction(Intent.ACTION_MANAGE_PERMISSION_APPS) - .putExtra(Intent.EXTRA_PERMISSION_NAME, - PermissionSearchIndexablesProvider.getOriginalKey(intent)); - break; - default: - finish(); - return; + if (action.equals(PermissionSearchIndexablesProvider.ACTION_MANAGE_PERMISSION_APPS)) { + newIntent + .setAction(Intent.ACTION_MANAGE_PERMISSION_APPS) + .putExtra(Intent.EXTRA_PERMISSION_NAME, + PermissionSearchIndexablesProvider.getOriginalKey(intent)); + } else { + finish(); + return; } startActivity(newIntent); diff --git a/src/com/android/packageinstaller/role/model/AssistantRoleBehavior.java b/src/com/android/packageinstaller/role/model/AssistantRoleBehavior.java index f79522ea..bd08349e 100644 --- a/src/com/android/packageinstaller/role/model/AssistantRoleBehavior.java +++ b/src/com/android/packageinstaller/role/model/AssistantRoleBehavior.java @@ -18,6 +18,7 @@ package com.android.packageinstaller.role.model; import android.app.ActivityManager; import android.app.Application; +import android.app.role.RoleManager; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -25,6 +26,7 @@ import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.content.res.Resources; import android.content.res.XmlResourceParser; +import android.os.Process; import android.os.UserHandle; import android.provider.Settings; import android.service.voice.VoiceInteractionService; @@ -59,6 +61,20 @@ public class AssistantRoleBehavior implements RoleBehavior { private static final Intent ASSIST_ACTIVITY_PROBE = new Intent(Intent.ACTION_ASSIST); @Override + public void onRoleAdded(@NonNull Role role, @NonNull Context context) { + PackageManager packageManager = context.getPackageManager(); + if (packageManager.isDeviceUpgrading()) { + RoleManager roleManager = context.getSystemService(RoleManager.class); + List<String> packageNames = roleManager.getRoleHolders(role.getName()); + if (packageNames.isEmpty()) { + // If the device was upgraded, and there isn't any legacy role holders, it means + // user selected "None" in Settings and we need to keep that. + role.onNoneHolderSelectedAsUser(Process.myUserHandle(), context); + } + } + } + + @Override public boolean isAvailableAsUser(@NonNull Role role, @NonNull UserHandle user, @NonNull Context context) { return !UserUtils.isWorkProfile(user, context); diff --git a/src/com/android/packageinstaller/role/model/Role.java b/src/com/android/packageinstaller/role/model/Role.java index e3332db0..281e964a 100644 --- a/src/com/android/packageinstaller/role/model/Role.java +++ b/src/com/android/packageinstaller/role/model/Role.java @@ -254,6 +254,17 @@ public class Role { } /** + * Callback when this role is added to the system for the first time. + * + * @param context the {@code Context} to retrieve system services + */ + public void onRoleAdded(@NonNull Context context) { + if (mBehavior != null) { + mBehavior.onRoleAdded(this, context); + } + } + + /** * Check whether this role is available. * * @param user the user to check for diff --git a/src/com/android/packageinstaller/role/model/RoleBehavior.java b/src/com/android/packageinstaller/role/model/RoleBehavior.java index 41ffb455..a43d7ad5 100644 --- a/src/com/android/packageinstaller/role/model/RoleBehavior.java +++ b/src/com/android/packageinstaller/role/model/RoleBehavior.java @@ -36,6 +36,11 @@ import java.util.List; public interface RoleBehavior { /** + * @see Role#onRoleAdded(Context) + */ + default void onRoleAdded(@NonNull Role role, @NonNull Context context) {} + + /** * @see Role#isAvailableAsUser(UserHandle, Context) */ default boolean isAvailableAsUser(@NonNull Role role, @NonNull UserHandle user, diff --git a/src/com/android/packageinstaller/role/service/RoleControllerServiceImpl.java b/src/com/android/packageinstaller/role/service/RoleControllerServiceImpl.java index bee43205..d45d6bb3 100644 --- a/src/com/android/packageinstaller/role/service/RoleControllerServiceImpl.java +++ b/src/com/android/packageinstaller/role/service/RoleControllerServiceImpl.java @@ -89,6 +89,14 @@ public class RoleControllerServiceImpl extends RoleControllerService { // Set the available role names in RoleManager. mRoleManager.setRoleNamesFromController(roleNames); + int addedRoleNamesSize = addedRoleNames.size(); + for (int i = 0; i < addedRoleNamesSize; i++) { + String roleName = addedRoleNames.valueAt(i); + + Role role = roleMap.get(roleName); + role.onRoleAdded(this); + } + // Go through the holders of all roles. int rolesSize = roles.size(); for (int rolesIndex = 0; rolesIndex < rolesSize; rolesIndex++) { diff --git a/src/com/android/packageinstaller/role/ui/RequestRoleFragment.java b/src/com/android/packageinstaller/role/ui/RequestRoleFragment.java index 7991a2fb..d4a09bc5 100644 --- a/src/com/android/packageinstaller/role/ui/RequestRoleFragment.java +++ b/src/com/android/packageinstaller/role/ui/RequestRoleFragment.java @@ -226,7 +226,7 @@ public class RequestRoleFragment extends DialogFragment { // Postponed to onStart() so that the list view in dialog is created. mViewModel = ViewModelProviders.of(this, new RequestRoleViewModel.Factory(mRole, requireActivity().getApplication())).get(RequestRoleViewModel.class); - mViewModel.getRoleLiveData().observe(this, mAdapter::replace); + mViewModel.getRoleLiveData().observe(this, this::onRoleDataChanged); mViewModel.getManageRoleHolderStateLiveData().observe(this, this::onManageRoleHolderStateChanged); } @@ -262,6 +262,12 @@ public class RequestRoleFragment extends DialogFragment { setDeniedOnceAndFinish(); } + private void onRoleDataChanged( + @NonNull List<Pair<ApplicationInfo, Boolean>> qualifyingApplications) { + mAdapter.replace(qualifyingApplications); + updateUi(); + } + private void onItemClicked(int position) { mAdapter.onItemClicked(position); updateUi(); @@ -344,8 +350,9 @@ public class RequestRoleFragment extends DialogFragment { boolean dontAskAgain = mDontAskAgainCheck != null && mDontAskAgainCheck.isChecked(); mAdapter.setDontAskAgain(dontAskAgain); AlertDialog dialog = getDialog(); - dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(enabled && (dontAskAgain - || !mAdapter.isHolderApplicationChecked())); + boolean hasRoleData = mViewModel.getRoleLiveData().getValue() != null; + dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(enabled && hasRoleData + && (dontAskAgain || !mAdapter.isHolderApplicationChecked())); dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setEnabled(enabled); } |