Merge Advanced Security and Privacy Category keys

Test: atest CategoryManagerTest
Bug: b/260060884
Change-Id: I376aa8af6c19cfcca2b84d6ccbd5cd497fa298b8
This commit is contained in:
Prabal Singh
2023-02-07 19:53:19 +00:00
parent 50b0e0b196
commit 44d858e405
2 changed files with 126 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ import android.util.Pair;
import androidx.annotation.VisibleForTesting;
import com.android.settings.homepage.HighlightableMenu;
import com.android.settings.safetycenter.SafetyCenterManagerWrapper;
import com.android.settingslib.applications.InterestingConfigChanges;
import com.android.settingslib.drawer.CategoryKey;
import com.android.settingslib.drawer.DashboardCategory;
@@ -38,6 +39,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
public class CategoryManager {
@@ -151,6 +153,7 @@ public class CategoryManager {
mCategoryByKeyMap.put(category.key, category);
}
backwardCompatCleanupForCategory(mTileByComponentCache, mCategoryByKeyMap);
mergeSecurityPrivacyKeys(context, mTileByComponentCache, mCategoryByKeyMap);
sortCategories(context, mCategoryByKeyMap);
filterDuplicateTiles(mCategoryByKeyMap);
if (firstLoading) {
@@ -224,6 +227,36 @@ public class CategoryManager {
}
}
/**
* Merges {@link CategoryKey#CATEGORY_SECURITY_ADVANCED_SETTINGS} and {@link
* CategoryKey#CATEGORY_PRIVACY} into {@link
* CategoryKey#CATEGORY_MORE_SECURITY_PRIVACY_SETTINGS}
*/
@VisibleForTesting
synchronized void mergeSecurityPrivacyKeys(
Context context,
Map<Pair<String, String>, Tile> tileByComponentCache,
Map<String, DashboardCategory> categoryByKeyMap) {
if (!SafetyCenterManagerWrapper.get().isEnabled(context)) {
return;
}
for (Entry<Pair<String, String>, Tile> tileEntry : tileByComponentCache.entrySet()) {
Tile tile = tileEntry.getValue();
if (Objects.equals(tile.getCategory(), CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS)
|| Objects.equals(tile.getCategory(), CategoryKey.CATEGORY_PRIVACY)) {
final String newCategoryKey = CategoryKey.CATEGORY_MORE_SECURITY_PRIVACY_SETTINGS;
tile.setCategory(newCategoryKey);
// move tile to new category.
DashboardCategory newCategory = categoryByKeyMap.get(newCategoryKey);
if (newCategory == null) {
newCategory = new DashboardCategory(newCategoryKey);
categoryByKeyMap.put(newCategoryKey, newCategory);
}
newCategory.addTile(tile);
}
}
}
/**
* Sort the tiles injected from all apps such that if they have the same priority value,
* they wil lbe sorted by package name.