From 77f8e503c3e74288e404fed0b39219b11af95c9f Mon Sep 17 00:00:00 2001 From: Oli Thompson Date: Fri, 8 Mar 2024 13:14:54 +0000 Subject: [PATCH] add a check if the app store link intent can be opened in the profile. Bug: 245269933 Test: manually tested Change-Id: I5240c2a5e2444444738fe1d226c11e9d56ab8c87 --- .../settings/applications/AppStoreUtil.java | 1 + .../InteractAcrossProfilesDetails.java | 27 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/com/android/settings/applications/AppStoreUtil.java b/src/com/android/settings/applications/AppStoreUtil.java index b73b14ae709..636669c7c0a 100644 --- a/src/com/android/settings/applications/AppStoreUtil.java +++ b/src/com/android/settings/applications/AppStoreUtil.java @@ -83,6 +83,7 @@ public class AppStoreUtil { } /** Convenience method that looks up the installerPackageName for you. */ + @Nullable public static Intent getAppStoreLink(Context context, String packageName) { String installerPackageName = getInstallerPackageName(context, packageName); return getAppStoreLink(context, installerPackageName, packageName); diff --git a/src/com/android/settings/applications/specialaccess/interactacrossprofiles/InteractAcrossProfilesDetails.java b/src/com/android/settings/applications/specialaccess/interactacrossprofiles/InteractAcrossProfilesDetails.java index faa1b5109af..81e84393d41 100644 --- a/src/com/android/settings/applications/specialaccess/interactacrossprofiles/InteractAcrossProfilesDetails.java +++ b/src/com/android/settings/applications/specialaccess/interactacrossprofiles/InteractAcrossProfilesDetails.java @@ -384,20 +384,21 @@ public class InteractAcrossProfilesDetails extends AppInfoBase } private void handleInstallBannerClick() { - if (mInstallAppIntent == null) { - logEvent( - DevicePolicyEnums.CROSS_PROFILE_SETTINGS_PAGE_INSTALL_BANNER_NO_INTENT_CLICKED); - return; - } - if (!mInstalledInWork) { + if (mInstallAppIntent != null + && !mInstalledInWork + && isInstallableInProfile(mInstallAppIntent, mWorkProfile)) { logEvent(DevicePolicyEnums.CROSS_PROFILE_SETTINGS_PAGE_INSTALL_BANNER_CLICKED); mContext.startActivityAsUser(mInstallAppIntent, mWorkProfile); return; } - if (!mInstalledInPersonal) { + if (mInstallAppIntent != null + && !mInstalledInPersonal + && isInstallableInProfile(mInstallAppIntent, mPersonalProfile)) { logEvent(DevicePolicyEnums.CROSS_PROFILE_SETTINGS_PAGE_INSTALL_BANNER_CLICKED); mContext.startActivityAsUser(mInstallAppIntent, mPersonalProfile); + return; } + logEvent(DevicePolicyEnums.CROSS_PROFILE_SETTINGS_PAGE_INSTALL_BANNER_NO_INTENT_CLICKED); } /** @@ -447,7 +448,8 @@ public class InteractAcrossProfilesDetails extends AppInfoBase R.string.interact_across_profiles_install_personal_app_title, mAppLabel), mAppLabel)); - if (mInstallAppIntent != null) { + if (mInstallAppIntent != null + && isInstallableInProfile(mInstallAppIntent, mPersonalProfile)) { mInstallBanner.setSummary( R.string.interact_across_profiles_install_app_summary); } @@ -461,7 +463,8 @@ public class InteractAcrossProfilesDetails extends AppInfoBase R.string.interact_across_profiles_install_work_app_title, mAppLabel), mAppLabel)); - if (mInstallAppIntent != null) { + if (mInstallAppIntent != null + && isInstallableInProfile(mInstallAppIntent, mWorkProfile)) { mInstallBanner.setSummary( R.string.interact_across_profiles_install_app_summary); } @@ -488,6 +491,12 @@ public class InteractAcrossProfilesDetails extends AppInfoBase return info != null; } + private boolean isInstallableInProfile(Intent intent, UserHandle profile) { + return !mContext.getPackageManager() + .queryIntentActivitiesAsUser(intent, /* flags= */ 0, profile) + .isEmpty(); + } + private void refreshUiForConfigurableApps() { mInstallBanner.setVisible(false); mSwitchPref.setEnabled(true);