Merge "Merge Advanced Security and Privacy Category keys"
This commit is contained in:
@@ -26,6 +26,7 @@ import android.util.Pair;
|
|||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import com.android.settings.homepage.HighlightableMenu;
|
import com.android.settings.homepage.HighlightableMenu;
|
||||||
|
import com.android.settings.safetycenter.SafetyCenterManagerWrapper;
|
||||||
import com.android.settingslib.applications.InterestingConfigChanges;
|
import com.android.settingslib.applications.InterestingConfigChanges;
|
||||||
import com.android.settingslib.drawer.CategoryKey;
|
import com.android.settingslib.drawer.CategoryKey;
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
@@ -38,6 +39,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class CategoryManager {
|
public class CategoryManager {
|
||||||
@@ -151,6 +153,7 @@ public class CategoryManager {
|
|||||||
mCategoryByKeyMap.put(category.key, category);
|
mCategoryByKeyMap.put(category.key, category);
|
||||||
}
|
}
|
||||||
backwardCompatCleanupForCategory(mTileByComponentCache, mCategoryByKeyMap);
|
backwardCompatCleanupForCategory(mTileByComponentCache, mCategoryByKeyMap);
|
||||||
|
mergeSecurityPrivacyKeys(context, mTileByComponentCache, mCategoryByKeyMap);
|
||||||
sortCategories(context, mCategoryByKeyMap);
|
sortCategories(context, mCategoryByKeyMap);
|
||||||
filterDuplicateTiles(mCategoryByKeyMap);
|
filterDuplicateTiles(mCategoryByKeyMap);
|
||||||
if (firstLoading) {
|
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,
|
* Sort the tiles injected from all apps such that if they have the same priority value,
|
||||||
* they wil lbe sorted by package name.
|
* they wil lbe sorted by package name.
|
||||||
|
@@ -22,6 +22,8 @@ import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYH
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
@@ -32,6 +34,7 @@ import android.util.Pair;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.settings.safetycenter.SafetyCenterManagerWrapper;
|
||||||
import com.android.settingslib.drawer.ActivityTile;
|
import com.android.settingslib.drawer.ActivityTile;
|
||||||
import com.android.settingslib.drawer.CategoryKey;
|
import com.android.settingslib.drawer.CategoryKey;
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
@@ -41,6 +44,8 @@ import com.android.settingslib.drawer.Tile;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -54,8 +59,11 @@ public class CategoryManagerTest {
|
|||||||
private Map<Pair<String, String>, Tile> mTileByComponentCache;
|
private Map<Pair<String, String>, Tile> mTileByComponentCache;
|
||||||
private Map<String, DashboardCategory> mCategoryByKeyMap;
|
private Map<String, DashboardCategory> mCategoryByKeyMap;
|
||||||
|
|
||||||
|
@Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = ApplicationProvider.getApplicationContext();
|
mContext = ApplicationProvider.getApplicationContext();
|
||||||
mActivityInfo = new ActivityInfo();
|
mActivityInfo = new ActivityInfo();
|
||||||
mActivityInfo.packageName = "pkg";
|
mActivityInfo.packageName = "pkg";
|
||||||
@@ -64,6 +72,7 @@ public class CategoryManagerTest {
|
|||||||
mTileByComponentCache = new HashMap<>();
|
mTileByComponentCache = new HashMap<>();
|
||||||
mCategoryByKeyMap = new HashMap<>();
|
mCategoryByKeyMap = new HashMap<>();
|
||||||
mCategoryManager = CategoryManager.get(mContext);
|
mCategoryManager = CategoryManager.get(mContext);
|
||||||
|
SafetyCenterManagerWrapper.sInstance = mSafetyCenterManagerWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -131,6 +140,90 @@ public class CategoryManagerTest {
|
|||||||
assertThat(mCategoryByKeyMap.get(oldCategory).getTilesCount()).isEqualTo(1);
|
assertThat(mCategoryByKeyMap.get(oldCategory).getTilesCount()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mergeSecurityPrivacyKeys_safetyCenterEnabled_shouldNotChangeOtherKeys() {
|
||||||
|
when(mSafetyCenterManagerWrapper.isEnabled(mContext)).thenReturn(true);
|
||||||
|
|
||||||
|
final Tile tile1 = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_ACCOUNT);
|
||||||
|
final String oldCategory = "com.android.settings.category.wireless";
|
||||||
|
final Tile tile2 = new ActivityTile(mActivityInfo, oldCategory);
|
||||||
|
final DashboardCategory category1 = new DashboardCategory(CategoryKey.CATEGORY_ACCOUNT);
|
||||||
|
category1.addTile(tile1);
|
||||||
|
final DashboardCategory category2 = new DashboardCategory(oldCategory);
|
||||||
|
category2.addTile(tile2);
|
||||||
|
mCategoryByKeyMap.put(CategoryKey.CATEGORY_ACCOUNT, category1);
|
||||||
|
mCategoryByKeyMap.put(oldCategory, category2);
|
||||||
|
mTileByComponentCache.put(new Pair<>("PACKAGE", "CLASS1"), tile1);
|
||||||
|
mTileByComponentCache.put(new Pair<>("PACKAGE", "CLASS2"), tile2);
|
||||||
|
|
||||||
|
mCategoryManager.mergeSecurityPrivacyKeys(
|
||||||
|
mContext, mTileByComponentCache, mCategoryByKeyMap);
|
||||||
|
|
||||||
|
assertThat(mCategoryByKeyMap.size()).isEqualTo(2);
|
||||||
|
assertThat(mCategoryByKeyMap.get(CategoryKey.CATEGORY_ACCOUNT).getTilesCount())
|
||||||
|
.isEqualTo(1);
|
||||||
|
assertThat(mCategoryByKeyMap.get(oldCategory).getTilesCount()).isEqualTo(1);
|
||||||
|
assertThat(mCategoryByKeyMap.get(CategoryKey.CATEGORY_MORE_SECURITY_PRIVACY_SETTINGS))
|
||||||
|
.isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mergeSecurityPrivacyKeys_safetyCenterEnabled_shouldChangeSecurityPrivacyKeys() {
|
||||||
|
when(mSafetyCenterManagerWrapper.isEnabled(mContext)).thenReturn(true);
|
||||||
|
|
||||||
|
final Tile tileWithSecurityCategory =
|
||||||
|
new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS);
|
||||||
|
final Tile tileWithPrivacyCategory =
|
||||||
|
new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_PRIVACY);
|
||||||
|
final DashboardCategory categoryAdvancedSecurity =
|
||||||
|
new DashboardCategory(CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS);
|
||||||
|
categoryAdvancedSecurity.addTile(tileWithSecurityCategory);
|
||||||
|
final DashboardCategory categoryPrivacy =
|
||||||
|
new DashboardCategory(CategoryKey.CATEGORY_PRIVACY);
|
||||||
|
categoryPrivacy.addTile(tileWithPrivacyCategory);
|
||||||
|
mCategoryByKeyMap.put(
|
||||||
|
CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS, categoryAdvancedSecurity);
|
||||||
|
mCategoryByKeyMap.put(CategoryKey.CATEGORY_PRIVACY, categoryPrivacy);
|
||||||
|
mTileByComponentCache.put(new Pair<>("PACKAGE", "CLASS1"), tileWithSecurityCategory);
|
||||||
|
mTileByComponentCache.put(new Pair<>("PACKAGE", "CLASS2"), tileWithPrivacyCategory);
|
||||||
|
|
||||||
|
mCategoryManager.mergeSecurityPrivacyKeys(
|
||||||
|
mContext, mTileByComponentCache, mCategoryByKeyMap);
|
||||||
|
|
||||||
|
assertThat(
|
||||||
|
mCategoryByKeyMap
|
||||||
|
.get(CategoryKey.CATEGORY_MORE_SECURITY_PRIVACY_SETTINGS)
|
||||||
|
.getTilesCount())
|
||||||
|
.isEqualTo(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mergeSecurityPrivacyKeys_safetyCenterDisabled_shouldNotChangeSecurityPrivacyKeys() {
|
||||||
|
when(mSafetyCenterManagerWrapper.isEnabled(mContext)).thenReturn(false);
|
||||||
|
|
||||||
|
final Tile tileWithSecurityCategory =
|
||||||
|
new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS);
|
||||||
|
final Tile tileWithPrivacyCategory =
|
||||||
|
new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_PRIVACY);
|
||||||
|
final DashboardCategory categoryAdvancedSecurity =
|
||||||
|
new DashboardCategory(CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS);
|
||||||
|
categoryAdvancedSecurity.addTile(tileWithSecurityCategory);
|
||||||
|
final DashboardCategory categoryPrivacy =
|
||||||
|
new DashboardCategory(CategoryKey.CATEGORY_PRIVACY);
|
||||||
|
categoryPrivacy.addTile(tileWithPrivacyCategory);
|
||||||
|
mCategoryByKeyMap.put(
|
||||||
|
CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS, categoryAdvancedSecurity);
|
||||||
|
mCategoryByKeyMap.put(CategoryKey.CATEGORY_PRIVACY, categoryPrivacy);
|
||||||
|
mTileByComponentCache.put(new Pair<>("PACKAGE", "CLASS1"), tileWithSecurityCategory);
|
||||||
|
mTileByComponentCache.put(new Pair<>("PACKAGE", "CLASS2"), tileWithPrivacyCategory);
|
||||||
|
|
||||||
|
mCategoryManager.mergeSecurityPrivacyKeys(
|
||||||
|
mContext, mTileByComponentCache, mCategoryByKeyMap);
|
||||||
|
|
||||||
|
assertThat(mCategoryByKeyMap.get(CategoryKey.CATEGORY_MORE_SECURITY_PRIVACY_SETTINGS))
|
||||||
|
.isNull();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sortCategories_singlePackage_shouldReorderBasedOnPriority() {
|
public void sortCategories_singlePackage_shouldReorderBasedOnPriority() {
|
||||||
// Create some fake tiles that are not sorted.
|
// Create some fake tiles that are not sorted.
|
||||||
|
Reference in New Issue
Block a user