Merge "add a check if the app store link intent can be opened in the profile." into main

This commit is contained in:
Oli Thompson
2024-03-12 11:07:48 +00:00
committed by Android (Google) Code Review
2 changed files with 19 additions and 9 deletions

View File

@@ -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);

View File

@@ -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);