diff options
author | 2024-04-03 16:32:37 +0000 | |
---|---|---|
committer | 2024-04-04 15:27:48 +0000 | |
commit | e9faee16da8ef82333c50ca08cfe91c2b15f50e8 (patch) | |
tree | a1769d7f4a79c9273041877599f2228906ffe398 | |
parent | bddca4947a28891f947b36eb4f0d73198b73f5bb (diff) |
Update search indexable for private profile
Bug: 286539356
Test: manual
Change-Id: I997125e399e387ad49843d7851270c0700a106ea
5 files changed, 98 insertions, 32 deletions
diff --git a/PermissionController/src/com/android/permissioncontroller/safetycenter/SafetyCenterConstants.java b/PermissionController/src/com/android/permissioncontroller/safetycenter/SafetyCenterConstants.java index cf96967ff..8ca76d006 100644 --- a/PermissionController/src/com/android/permissioncontroller/safetycenter/SafetyCenterConstants.java +++ b/PermissionController/src/com/android/permissioncontroller/safetycenter/SafetyCenterConstants.java @@ -38,6 +38,9 @@ public class SafetyCenterConstants { /** Suffix used to identify a source in the Safety Center work profile */ public static final String WORK_PROFILE_SUFFIX = "work"; + /** Suffix used to identify a source in the Safety Center private profile */ + public static final String PRIVATE_PROFILE_SUFFIX = "private"; + /** Intent extra representing the preference key of a search result */ public static final String EXTRA_SETTINGS_FRAGMENT_ARGS_KEY = ":settings:fragment_args_key"; diff --git a/PermissionController/src/com/android/permissioncontroller/safetycenter/service/SafetyCenterSearchIndexablesProvider.kt b/PermissionController/src/com/android/permissioncontroller/safetycenter/service/SafetyCenterSearchIndexablesProvider.kt index 88dd8a6e3..c5e59d3df 100644 --- a/PermissionController/src/com/android/permissioncontroller/safetycenter/service/SafetyCenterSearchIndexablesProvider.kt +++ b/PermissionController/src/com/android/permissioncontroller/safetycenter/service/SafetyCenterSearchIndexablesProvider.kt @@ -22,6 +22,7 @@ import android.content.res.Resources import android.database.Cursor import android.database.MatrixCursor import android.os.Build +import android.os.UserHandle import android.os.UserManager import android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS import android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS @@ -46,6 +47,7 @@ import com.android.modules.utils.build.SdkLevel import com.android.permissioncontroller.R import com.android.permissioncontroller.permission.service.BaseSearchIndexablesProvider import com.android.permissioncontroller.safetycenter.SafetyCenterConstants.PERSONAL_PROFILE_SUFFIX +import com.android.permissioncontroller.safetycenter.SafetyCenterConstants.PRIVATE_PROFILE_SUFFIX import com.android.permissioncontroller.safetycenter.SafetyCenterConstants.WORK_PROFILE_SUFFIX import com.android.permissioncontroller.safetycenter.ui.SafetyCenterUiFlags import com.android.permissioncontroller.safetycenter.ui.model.PrivacyControlsViewModel.Pref @@ -111,7 +113,6 @@ class SafetyCenterSearchIndexablesProvider : BaseSearchIndexablesProvider() { val context = requireContext() val safetyCenterManager = context.getSystemService(SafetyCenterManager::class.java) ?: return cursor - val userManager = context.getSystemService(UserManager::class.java) ?: return cursor val keysToRemove = mutableSetOf<String>() if (safetyCenterManager.isSafetyCenterEnabled) { @@ -124,7 +125,7 @@ class SafetyCenterSearchIndexablesProvider : BaseSearchIndexablesProvider() { keysToRemove, staticEntryGroupsAreRemovable = SdkLevel.isAtLeastU() ) - keepActiveEntriesFromRemoval(safetyCenterManager, userManager, keysToRemove) + keepActiveEntriesFromRemoval(safetyCenterManager, context, keysToRemove) } else { collectAllRemovableKeys( safetyCenterManager, @@ -171,18 +172,19 @@ class SafetyCenterSearchIndexablesProvider : BaseSearchIndexablesProvider() { var isPersonalEntryAdded = false var isWorkEntryAdded = false - fun MatrixCursor.addIndexableRow(title: CharSequence, isWorkProfile: Boolean) = + fun MatrixCursor.addIndexableRow(title: CharSequence, profileType: ProfileType) = newRow() .add(COLUMN_RANK, 0) .add(COLUMN_TITLE, title) .add(COLUMN_KEYWORDS, searchTerms?.let { "$title, $it" } ?: title) - .add(COLUMN_KEY, safetySource.id.addSuffix(isWorkProfile)) + .add(COLUMN_KEY, safetySource.id.addSuffix(profileType)) .add(COLUMN_INTENT_ACTION, Intent.ACTION_SAFETY_CENTER) .add(COLUMN_SCREEN_TITLE, screenTitle) if (safetySource.id == BIOMETRIC_SOURCE_ID) { - // correct Biometric Unlock title is only available when - // Biometric SafetySource have sent the data to SafetyCenter + // Correct Biometric Unlock title is only available when Biometric SafetySource have + // sent the data to SafetyCenter. Only the main user and the work profile send data for + // the Biometric Safety Source. context.getSystemService(UserManager::class.java)?.let { userManager -> safetyCenterManager.safetyEntries .associateBy { it.entryId } @@ -191,23 +193,31 @@ class SafetyCenterSearchIndexablesProvider : BaseSearchIndexablesProvider() { val isWorkProfile = userManager.isManagedProfile(it.key.userId) if (isWorkProfile) { isWorkEntryAdded = true + addIndexableRow(it.value.title, ProfileType.MANAGED) } else { + addIndexableRow(it.value.title, ProfileType.PRIMARY) isPersonalEntryAdded = true } - addIndexableRow(it.value.title, isWorkProfile) } } } if (!isPersonalEntryAdded) { safetyCenterResourcesApk.getNotEmptyStringOrNull(safetySource.titleResId)?.let { - addIndexableRow(title = it, isWorkProfile = false) + addIndexableRow(title = it, ProfileType.PRIMARY) } } - if (!isWorkEntryAdded && safetySource.profile == SafetySource.PROFILE_ALL) { - safetyCenterResourcesApk.getNotEmptyStringOrNull(safetySource.titleForWorkResId)?.let { - addIndexableRow(title = it, isWorkProfile = true) + if (safetySource.profile == SafetySource.PROFILE_ALL) { + if (!isWorkEntryAdded) { + safetyCenterResourcesApk + .getNotEmptyStringOrNull(safetySource.titleForWorkResId) + ?.let { addIndexableRow(title = it, ProfileType.MANAGED) } + } + if (safetySource.id != BIOMETRIC_SOURCE_ID && isPrivateProfileSupported()) { + safetyCenterResourcesApk + .getNotEmptyStringOrNull(safetySource.titleForPrivateProfileResId) + ?.let { addIndexableRow(title = it, ProfileType.PRIVATE) } } } } @@ -219,8 +229,14 @@ class SafetyCenterSearchIndexablesProvider : BaseSearchIndexablesProvider() { null } - private fun String.addSuffix(isWorkProfile: Boolean): String = - "${this}_${if (isWorkProfile) WORK_PROFILE_SUFFIX else PERSONAL_PROFILE_SUFFIX}" + private fun String.addSuffix(profileType: ProfileType): String = + "${this}_${ + when (profileType) { + ProfileType.MANAGED -> WORK_PROFILE_SUFFIX + ProfileType.PRIVATE -> PRIVATE_PROFILE_SUFFIX + ProfileType.PRIMARY -> PERSONAL_PROFILE_SUFFIX + } + }" private val SafetyCenterManager.safetySourcesGroupsWithEntries: Sequence<SafetySourcesGroup> get() = @@ -249,9 +265,12 @@ class SafetyCenterSearchIndexablesProvider : BaseSearchIndexablesProvider() { .asSequence() .filter { it.type != SAFETY_SOURCE_TYPE_ISSUE_ONLY } .forEach { safetySource -> - keysToRemove.add(safetySource.id.addSuffix(isWorkProfile = false)) + keysToRemove.add(safetySource.id.addSuffix(ProfileType.PRIMARY)) if (safetySource.profile == SafetySource.PROFILE_ALL) { - keysToRemove.add(safetySource.id.addSuffix(isWorkProfile = true)) + keysToRemove.add(safetySource.id.addSuffix(ProfileType.MANAGED)) + if (isPrivateProfileSupported()) { + keysToRemove.add(safetySource.id.addSuffix(ProfileType.PRIVATE)) + } } } } @@ -259,7 +278,7 @@ class SafetyCenterSearchIndexablesProvider : BaseSearchIndexablesProvider() { private fun keepActiveEntriesFromRemoval( safetyCenterManager: SafetyCenterManager, - userManager: UserManager, + context: Context, keysToRemove: MutableSet<String> ) { val safetyCenterData = safetyCenterManager.safetyCenterData @@ -268,9 +287,7 @@ class SafetyCenterSearchIndexablesProvider : BaseSearchIndexablesProvider() { if (entryGroup != null && SafetyCenterUiFlags.getShowSubpages()) { keysToRemove.remove(entryGroup.id) } - entryOrGroup.entries.forEach { - keepEntryFromRemoval(it.entryId, userManager, keysToRemove) - } + entryOrGroup.entries.forEach { keepEntryFromRemoval(it.entryId, context, keysToRemove) } } if (!SdkLevel.isAtLeastU()) { return @@ -281,18 +298,25 @@ class SafetyCenterSearchIndexablesProvider : BaseSearchIndexablesProvider() { .forEach { staticEntry -> val entryId = SafetyCenterBundles.getStaticEntryId(safetyCenterData, staticEntry) if (entryId != null) { - keepEntryFromRemoval(entryId, userManager, keysToRemove) + keepEntryFromRemoval(entryId, context, keysToRemove) } } } private fun keepEntryFromRemoval( entryId: SafetyCenterEntryId, - userManager: UserManager, + context: Context, keysToRemove: MutableSet<String> ) { - val isWorkProfile = userManager.isManagedProfile(entryId.userId) - keysToRemove.remove(entryId.safetySourceId.addSuffix(isWorkProfile)) + val userContext = context.createContextAsUser(UserHandle.of(entryId.userId), /* flags= */ 0) + val userUserManager = userContext.getSystemService(UserManager::class.java) ?: return + if (userUserManager.isManagedProfile) { + keysToRemove.remove(entryId.safetySourceId.addSuffix(ProfileType.MANAGED)) + } else if (isPrivateProfileSupported() && userUserManager.isPrivateProfile) { + keysToRemove.remove(entryId.safetySourceId.addSuffix(ProfileType.PRIVATE)) + } else { + keysToRemove.remove(entryId.safetySourceId.addSuffix(ProfileType.PRIMARY)) + } } private val SafetyCenterManager.safetyEntriesOrGroups: Sequence<SafetyCenterEntryOrGroup> @@ -308,6 +332,12 @@ class SafetyCenterSearchIndexablesProvider : BaseSearchIndexablesProvider() { private val SafetyCenterEntry.entryId: SafetyCenterEntryId get() = SafetyCenterIds.entryIdFromString(id) + private fun isPrivateProfileSupported(): Boolean { + return SdkLevel.isAtLeastV() && + com.android.permission.flags.Flags.privateProfileSupported() && + android.os.Flags.allowPrivateProfile() + } + companion object { private const val BIOMETRIC_SOURCE_ID = "AndroidBiometrics" @@ -339,4 +369,10 @@ class SafetyCenterSearchIndexablesProvider : BaseSearchIndexablesProvider() { return safetyCenterDisabled || subpagesDisabled } } + + enum class ProfileType { + PRIMARY, + MANAGED, + PRIVATE + } } diff --git a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterActivity.java b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterActivity.java index ae67250a5..b873bc114 100644 --- a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterActivity.java +++ b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterActivity.java @@ -26,6 +26,7 @@ import static com.android.permissioncontroller.PermissionControllerStatsLog.PRIV import static com.android.permissioncontroller.safetycenter.SafetyCenterConstants.EXTRA_SETTINGS_FRAGMENT_ARGS_KEY; import static com.android.permissioncontroller.safetycenter.SafetyCenterConstants.PERSONAL_PROFILE_SUFFIX; import static com.android.permissioncontroller.safetycenter.SafetyCenterConstants.PRIVACY_SOURCES_GROUP_ID; +import static com.android.permissioncontroller.safetycenter.SafetyCenterConstants.PRIVATE_PROFILE_SUFFIX; import static com.android.permissioncontroller.safetycenter.SafetyCenterConstants.WORK_PROFILE_SUFFIX; import android.app.ActionBar; @@ -271,6 +272,8 @@ public final class SafetyCenterActivity extends CollapsingToolbarBaseActivity { splitKey = preferenceKey.split("_" + PERSONAL_PROFILE_SUFFIX); } else if (preferenceKey.endsWith(WORK_PROFILE_SUFFIX)) { splitKey = preferenceKey.split("_" + WORK_PROFILE_SUFFIX); + } else if (preferenceKey.endsWith(PRIVATE_PROFILE_SUFFIX)) { + splitKey = preferenceKey.split("_" + PRIVATE_PROFILE_SUFFIX); } else { return ""; } diff --git a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetySubpageEntryPreference.kt b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetySubpageEntryPreference.kt index f4761d3a9..b89abde13 100644 --- a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetySubpageEntryPreference.kt +++ b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetySubpageEntryPreference.kt @@ -18,6 +18,7 @@ package com.android.permissioncontroller.safetycenter.ui import android.content.Context import android.os.Build +import android.os.UserHandle import android.os.UserManager import android.safetycenter.SafetyCenterEntry import android.safetycenter.SafetyCenterEntry.IconAction.ICON_ACTION_TYPE_GEAR @@ -28,8 +29,10 @@ import android.widget.TextView import androidx.annotation.RequiresApi import androidx.preference.Preference import androidx.preference.PreferenceViewHolder +import com.android.modules.utils.build.SdkLevel import com.android.permissioncontroller.R import com.android.permissioncontroller.safetycenter.SafetyCenterConstants.PERSONAL_PROFILE_SUFFIX +import com.android.permissioncontroller.safetycenter.SafetyCenterConstants.PRIVATE_PROFILE_SUFFIX import com.android.permissioncontroller.safetycenter.SafetyCenterConstants.WORK_PROFILE_SUFFIX import com.android.permissioncontroller.safetycenter.ui.model.SafetyCenterViewModel import com.android.permissioncontroller.safetycenter.ui.view.SafetyEntryCommonViewsManager.Companion.changeEnabledState @@ -93,10 +96,21 @@ class SafetySubpageEntryPreference( private fun setupPreferenceKey() { val entryId: SafetyCenterEntryId = SafetyCenterIds.entryIdFromString(entry.id) - val isWorkProfile = - context.getSystemService(UserManager::class.java)!!.isManagedProfile(entryId.userId) - val keySuffix = if (isWorkProfile) WORK_PROFILE_SUFFIX else PERSONAL_PROFILE_SUFFIX - setKey("${entryId.safetySourceId}_$keySuffix") + val userContext = context.createContextAsUser(UserHandle.of(entryId.userId), /* flags= */ 0) + val userUserManager = userContext.getSystemService(UserManager::class.java) ?: return + if (userUserManager.isManagedProfile) { + setKey("${entryId.safetySourceId}_$WORK_PROFILE_SUFFIX") + } else if (isPrivateProfileSupported() && userUserManager.isPrivateProfile) { + setKey("${entryId.safetySourceId}_$PRIVATE_PROFILE_SUFFIX") + } else { + setKey("${entryId.safetySourceId}_$PERSONAL_PROFILE_SUFFIX") + } + } + + private fun isPrivateProfileSupported(): Boolean { + return SdkLevel.isAtLeastV() && + com.android.permission.flags.Flags.privateProfileSupported() && + android.os.Flags.allowPrivateProfile() } override fun onBindViewHolder(holder: PreferenceViewHolder) { diff --git a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/StaticSafetyEntryPreference.java b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/StaticSafetyEntryPreference.java index 8864da07b..87d8744a8 100644 --- a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/StaticSafetyEntryPreference.java +++ b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/StaticSafetyEntryPreference.java @@ -19,9 +19,11 @@ package com.android.permissioncontroller.safetycenter.ui; import static android.os.Build.VERSION_CODES.TIRAMISU; import static com.android.permissioncontroller.safetycenter.SafetyCenterConstants.PERSONAL_PROFILE_SUFFIX; +import static com.android.permissioncontroller.safetycenter.SafetyCenterConstants.PRIVATE_PROFILE_SUFFIX; import static com.android.permissioncontroller.safetycenter.SafetyCenterConstants.WORK_PROFILE_SUFFIX; import android.content.Context; +import android.os.UserHandle; import android.os.UserManager; import android.safetycenter.SafetyCenterStaticEntry; import android.text.TextUtils; @@ -31,6 +33,7 @@ import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.preference.Preference; +import com.android.modules.utils.build.SdkLevel; import com.android.permissioncontroller.safetycenter.ui.model.SafetyCenterViewModel; import com.android.safetycenter.internaldata.SafetyCenterEntryId; @@ -81,17 +84,24 @@ public class StaticSafetyEntryPreference extends Preference implements Comparabl } private void setupPreferenceKey(SafetyCenterEntryId entryId) { - boolean isWorkProfile = - getContext() - .getSystemService(UserManager.class) - .isManagedProfile(entryId.getUserId()); - if (isWorkProfile) { + Context userContext = getContext() + .createContextAsUser(UserHandle.of(entryId.getUserId()), /* flags= */ 0); + UserManager userUserManager = userContext.getSystemService(UserManager.class); + if (userUserManager.isManagedProfile()) { setKey(String.format("%s_%s", entryId.getSafetySourceId(), WORK_PROFILE_SUFFIX)); + } else if (isPrivateProfileSupported() && userUserManager.isPrivateProfile()) { + setKey(String.format("%s_%s", entryId.getSafetySourceId(), PRIVATE_PROFILE_SUFFIX)); } else { setKey(String.format("%s_%s", entryId.getSafetySourceId(), PERSONAL_PROFILE_SUFFIX)); } } + private Boolean isPrivateProfileSupported() { + return SdkLevel.isAtLeastV() + && com.android.permission.flags.Flags.privateProfileSupported() + && android.os.Flags.allowPrivateProfile(); + } + @Override public boolean isSameItem(Preference preference) { return preference instanceof StaticSafetyEntryPreference |