summaryrefslogtreecommitdiff
path: root/PermissionController/src/com/android/permissioncontroller/safetycenter
diff options
context:
space:
mode:
authorElliot Sisteron <elliotsisteron@google.com>2023-04-21 11:56:43 +0000
committerElliot Sisteron <elliotsisteron@google.com>2023-04-21 14:49:31 +0000
commit0eb9295246084d7107c6ae0601517096b5d57f0d (patch)
treeecfc0259b461bb3547786fb760e2ac2615166528 /PermissionController/src/com/android/permissioncontroller/safetycenter
parent8debbd87e5513927d45482077602e480127d9664 (diff)
downloadPermission-0eb9295246084d7107c6ae0601517096b5d57f0d.tar.gz
Add support for static entries for settings search.
Now that we've added ids for static entries, we can use that to support indexing removal & highlighting. Note that the highlighting works for static entries with this CL, but for some reason not the scrolling. I've opened b/279149620 to investigate, I believe this might be related to b/270929985#comment8. Bug: 278872430 Test: manual Change-Id: I4a702bccca013bc3f7a506665f3212e5762504ae
Diffstat (limited to 'PermissionController/src/com/android/permissioncontroller/safetycenter')
-rw-r--r--PermissionController/src/com/android/permissioncontroller/safetycenter/SafetyCenterConstants.java3
-rw-r--r--PermissionController/src/com/android/permissioncontroller/safetycenter/service/SafetyCenterSearchIndexablesProvider.kt56
-rw-r--r--PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterActivity.java4
-rw-r--r--PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterDashboardFragment.java9
-rw-r--r--PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyEntryPreference.java2
-rw-r--r--PermissionController/src/com/android/permissioncontroller/safetycenter/ui/StaticSafetyEntryPreference.java21
6 files changed, 65 insertions, 30 deletions
diff --git a/PermissionController/src/com/android/permissioncontroller/safetycenter/SafetyCenterConstants.java b/PermissionController/src/com/android/permissioncontroller/safetycenter/SafetyCenterConstants.java
index 2909a40b5..cf96967ff 100644
--- a/PermissionController/src/com/android/permissioncontroller/safetycenter/SafetyCenterConstants.java
+++ b/PermissionController/src/com/android/permissioncontroller/safetycenter/SafetyCenterConstants.java
@@ -24,9 +24,6 @@ public class SafetyCenterConstants {
public static final String QUICK_SETTINGS_SAFETY_CENTER_FRAGMENT =
"QUICK_SETTINGS_SAFETY_CENTER_FRAGMENT";
- public static final String EXPAND_ISSUE_GROUP_SAVED_INSTANCE_STATE_KEY =
- "expand_issue_group_saved_instance_state_key";
-
public static final String EXPAND_ISSUE_GROUP_QS_FRAGMENT_KEY =
"expand_issue_group_qs_fragment_key";
diff --git a/PermissionController/src/com/android/permissioncontroller/safetycenter/service/SafetyCenterSearchIndexablesProvider.kt b/PermissionController/src/com/android/permissioncontroller/safetycenter/service/SafetyCenterSearchIndexablesProvider.kt
index a7e101087..8e5e63452 100644
--- a/PermissionController/src/com/android/permissioncontroller/safetycenter/service/SafetyCenterSearchIndexablesProvider.kt
+++ b/PermissionController/src/com/android/permissioncontroller/safetycenter/service/SafetyCenterSearchIndexablesProvider.kt
@@ -49,6 +49,7 @@ import com.android.permissioncontroller.safetycenter.SafetyCenterConstants.PERSO
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
+import com.android.safetycenter.internaldata.SafetyCenterBundles
import com.android.safetycenter.internaldata.SafetyCenterEntryId
import com.android.safetycenter.internaldata.SafetyCenterIds
import com.android.safetycenter.resources.SafetyCenterResourcesContext
@@ -111,17 +112,13 @@ class SafetyCenterSearchIndexablesProvider : BaseSearchIndexablesProvider() {
if (safetyCenterManager.isSafetyCenterEnabled) {
// SafetyCenterStaticEntry doesn't provide an ID, so we never remove these entries from
- // search as we have no way to know if they're actually surfaced in the UI.
- // We make the assumption that *every* SafetyCenterStaticEntry is always going to be
- // shown in the UI. This means that some entries may surface in search when they
- // shouldn't.
- // In practice this means that things like "for work" static entries in static groups
- // will always show in Settings search, even when there is no associated work profile.
- // TODO(b/278872430): Fix this by adding an ID to the SafetyCenterStaticEntry objects.
+ // search as we have no way to know if they're actually surfaced in the UI on T.
+ // On U+, we implemented a workaround that provides an ID for these entries using
+ // SafetyCenterData#getExtras().
collectAllRemovableKeys(
safetyCenterManager,
keysToRemove,
- staticEntryGroupsAreRemovable = false
+ staticEntryGroupsAreRemovable = SdkLevel.isAtLeastU()
)
keepActiveEntriesFromRemoval(safetyCenterManager, userManager, keysToRemove)
} else {
@@ -236,15 +233,21 @@ class SafetyCenterSearchIndexablesProvider : BaseSearchIndexablesProvider() {
it.type != SAFETY_SOURCES_GROUP_TYPE_STATELESS || staticEntryGroupsAreRemovable
}
.forEach { safetySourcesGroup ->
- if (SdkLevel.isAtLeastU()) {
+ if (
+ SdkLevel.isAtLeastU() &&
+ safetySourcesGroup.type == SAFETY_SOURCES_GROUP_TYPE_STATEFUL
+ ) {
keysToRemove.add(safetySourcesGroup.id)
}
- safetySourcesGroup.safetySources.asSequence().forEach { safetySource ->
- keysToRemove.add(safetySource.id.addSuffix(isWorkProfile = false))
- if (safetySource.profile == SafetySource.PROFILE_ALL) {
- keysToRemove.add(safetySource.id.addSuffix(isWorkProfile = true))
+ safetySourcesGroup.safetySources
+ .asSequence()
+ .filter { it.type != SAFETY_SOURCE_TYPE_ISSUE_ONLY }
+ .forEach { safetySource ->
+ keysToRemove.add(safetySource.id.addSuffix(isWorkProfile = false))
+ if (safetySource.profile == SafetySource.PROFILE_ALL) {
+ keysToRemove.add(safetySource.id.addSuffix(isWorkProfile = true))
+ }
}
- }
}
}
@@ -253,24 +256,35 @@ class SafetyCenterSearchIndexablesProvider : BaseSearchIndexablesProvider() {
userManager: UserManager,
keysToRemove: MutableSet<String>
) {
- safetyCenterManager.safetyEntriesOrGroups.forEach { entryOrGroup ->
+ val safetyCenterData = safetyCenterManager.safetyCenterData
+ safetyCenterData.entriesOrGroups.forEach { entryOrGroup ->
val entryGroup = entryOrGroup.entryGroup
if (entryGroup != null && SafetyCenterUiFlags.getShowSubpages()) {
keysToRemove.remove(entryGroup.id)
- // Note that we will discard static or issue-only entry groups here; and only keep
- // dynamic ones. This is desirable as highlighting isn't implemented for static
- // entries; and most static entries are now within subpages anyway.
}
- entryOrGroup.entries.forEach { keepEntryFromRemoval(it, userManager, keysToRemove) }
+ entryOrGroup.entries.forEach {
+ keepEntryFromRemoval(it.entryId, userManager, keysToRemove)
+ }
}
+ if (!SdkLevel.isAtLeastU()) {
+ return
+ }
+ safetyCenterData.staticEntryGroups
+ .asSequence()
+ .flatMap { it.staticEntries.asSequence() }
+ .forEach { staticEntry ->
+ val entryId = SafetyCenterBundles.getStaticEntryId(safetyCenterData, staticEntry)
+ if (entryId != null) {
+ keepEntryFromRemoval(entryId, userManager, keysToRemove)
+ }
+ }
}
private fun keepEntryFromRemoval(
- safetyCenterEntry: SafetyCenterEntry,
+ entryId: SafetyCenterEntryId,
userManager: UserManager,
keysToRemove: MutableSet<String>
) {
- val entryId = safetyCenterEntry.entryId
val isWorkProfile = userManager.isManagedProfile(entryId.userId)
keysToRemove.remove(entryId.safetySourceId.addSuffix(isWorkProfile))
}
diff --git a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterActivity.java b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterActivity.java
index 4fd8ae393..9bfaa5f35 100644
--- a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterActivity.java
+++ b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterActivity.java
@@ -244,6 +244,10 @@ public final class SafetyCenterActivity extends CollapsingToolbarBaseActivity {
List<SafetySourcesGroup> groups = safetyCenterConfig.getSafetySourcesGroups();
for (SafetySourcesGroup group : groups) {
+ if (group.getType() != SafetySourcesGroup.SAFETY_SOURCES_GROUP_TYPE_STATEFUL) {
+ // Hidden and static groups are not opened in a subpage.
+ continue;
+ }
for (SafetySource source : group.getSafetySources()) {
if (Objects.equals(source.getId(), splitKey[0])) {
return group.getId();
diff --git a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterDashboardFragment.java b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterDashboardFragment.java
index 02b9a46ff..dd90fd559 100644
--- a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterDashboardFragment.java
+++ b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterDashboardFragment.java
@@ -47,6 +47,7 @@ import androidx.preference.PreferenceGroup;
import com.android.permissioncontroller.R;
import com.android.permissioncontroller.safetycenter.ui.model.SafetyCenterUiData;
import com.android.permissioncontroller.safetycenter.ui.model.StatusUiData;
+import com.android.safetycenter.internaldata.SafetyCenterBundles;
import com.android.safetycenter.resources.SafetyCenterResourcesContext;
import kotlin.Unit;
@@ -188,7 +189,7 @@ public final class SafetyCenterDashboardFragment extends SafetyCenterFragment {
if (!mIsQuickSettingsFragment) {
updateSafetyEntries(context, data.getEntriesOrGroups());
- updateStaticSafetyEntries(context, data.getStaticEntryGroups());
+ updateStaticSafetyEntries(context, data);
}
}
@@ -273,11 +274,10 @@ public final class SafetyCenterDashboardFragment extends SafetyCenterFragment {
}));
}
- private void updateStaticSafetyEntries(
- Context context, List<SafetyCenterStaticEntryGroup> staticEntryGroups) {
+ private void updateStaticSafetyEntries(Context context, SafetyCenterData data) {
mStaticEntriesGroup.removeAll();
- for (SafetyCenterStaticEntryGroup group : staticEntryGroups) {
+ for (SafetyCenterStaticEntryGroup group : data.getStaticEntryGroups()) {
PreferenceCategory category = new ComparablePreferenceCategory(context);
category.setTitle(group.getTitle());
mStaticEntriesGroup.addPreference(category);
@@ -288,6 +288,7 @@ public final class SafetyCenterDashboardFragment extends SafetyCenterFragment {
context,
requireActivity().getTaskId(),
entry,
+ SafetyCenterBundles.getStaticEntryId(data, entry),
getSafetyCenterViewModel()));
}
}
diff --git a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyEntryPreference.java b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyEntryPreference.java
index f97914815..249354ad1 100644
--- a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyEntryPreference.java
+++ b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyEntryPreference.java
@@ -35,8 +35,6 @@ import com.android.permissioncontroller.safetycenter.ui.view.SafetyEntryView;
@RequiresApi(TIRAMISU)
public final class SafetyEntryPreference extends Preference implements ComparablePreference {
- private static final String TAG = SafetyEntryPreference.class.getSimpleName();
-
private final PositionInCardList mPosition;
private final SafetyCenterEntry mEntry;
private final SafetyCenterViewModel mViewModel;
diff --git a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/StaticSafetyEntryPreference.java b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/StaticSafetyEntryPreference.java
index 63ae5df33..8864da07b 100644
--- a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/StaticSafetyEntryPreference.java
+++ b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/StaticSafetyEntryPreference.java
@@ -18,7 +18,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.WORK_PROFILE_SUFFIX;
+
import android.content.Context;
+import android.os.UserManager;
import android.safetycenter.SafetyCenterStaticEntry;
import android.text.TextUtils;
import android.util.Log;
@@ -28,6 +32,7 @@ import androidx.annotation.RequiresApi;
import androidx.preference.Preference;
import com.android.permissioncontroller.safetycenter.ui.model.SafetyCenterViewModel;
+import com.android.safetycenter.internaldata.SafetyCenterEntryId;
/** A preference which displays a visual representation of a {@link SafetyCenterStaticEntry}. */
@RequiresApi(TIRAMISU)
@@ -42,6 +47,7 @@ public class StaticSafetyEntryPreference extends Preference implements Comparabl
Context context,
@Nullable Integer launchTaskId,
SafetyCenterStaticEntry entry,
+ @Nullable SafetyCenterEntryId entryId,
SafetyCenterViewModel viewModel) {
super(context);
mEntry = entry;
@@ -69,6 +75,21 @@ public class StaticSafetyEntryPreference extends Preference implements Comparabl
return true;
});
}
+ if (entryId != null) {
+ setupPreferenceKey(entryId);
+ }
+ }
+
+ private void setupPreferenceKey(SafetyCenterEntryId entryId) {
+ boolean isWorkProfile =
+ getContext()
+ .getSystemService(UserManager.class)
+ .isManagedProfile(entryId.getUserId());
+ if (isWorkProfile) {
+ setKey(String.format("%s_%s", entryId.getSafetySourceId(), WORK_PROFILE_SUFFIX));
+ } else {
+ setKey(String.format("%s_%s", entryId.getSafetySourceId(), PERSONAL_PROFILE_SUFFIX));
+ }
}
@Override