* This does not guarantee the setting is available. + *
+ * {@link #getSliceHighlightMenuRes} should also be overridden when returning true. * * @return {@code true} if the controller should be used as a Slice. */ @@ -131,4 +133,12 @@ public interface Sliceable { default Class extends SliceBackgroundWorker> getBackgroundWorkerClass() { return null; } + + /** + * @return a resource ID that indicates which menu entry should be highlighted in multi-pane + * mode. + */ + default int getSliceHighlightMenuRes() { + return 0; + } } diff --git a/src/com/android/settings/slices/SlicesDatabaseAccessor.java b/src/com/android/settings/slices/SlicesDatabaseAccessor.java index c0bb8de63da..75f0220f7ba 100644 --- a/src/com/android/settings/slices/SlicesDatabaseAccessor.java +++ b/src/com/android/settings/slices/SlicesDatabaseAccessor.java @@ -50,6 +50,7 @@ public class SlicesDatabaseAccessor { IndexColumns.CONTROLLER, IndexColumns.SLICE_TYPE, IndexColumns.UNAVAILABLE_SLICE_SUBTITLE, + IndexColumns.HIGHLIGHT_MENU_RESOURCE, }; private final Context mContext; @@ -163,6 +164,8 @@ public class SlicesDatabaseAccessor { cursor.getColumnIndex(IndexColumns.SLICE_TYPE)); final String unavailableSliceSubtitle = cursor.getString( cursor.getColumnIndex(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE)); + final int highlightMenuRes = cursor.getInt( + cursor.getColumnIndex(IndexColumns.HIGHLIGHT_MENU_RESOURCE)); if (isIntentOnly) { sliceType = SliceData.SliceType.INTENT; @@ -180,6 +183,7 @@ public class SlicesDatabaseAccessor { .setUri(uri) .setSliceType(sliceType) .setUnavailableSliceSubtitle(unavailableSliceSubtitle) + .setHighlightMenuRes(highlightMenuRes) .build(); } diff --git a/src/com/android/settings/slices/SlicesDatabaseHelper.java b/src/com/android/settings/slices/SlicesDatabaseHelper.java index fe4420b26b0..69ad702913c 100644 --- a/src/com/android/settings/slices/SlicesDatabaseHelper.java +++ b/src/com/android/settings/slices/SlicesDatabaseHelper.java @@ -36,7 +36,7 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "slices_index.db"; private static final String SHARED_PREFS_TAG = "slices_shared_prefs"; - private static final int DATABASE_VERSION = 8; + private static final int DATABASE_VERSION = 9; public interface Tables { String TABLE_SLICES_INDEX = "slices_index"; @@ -103,39 +103,43 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper { * Whether the slice should be exposed publicly. */ String PUBLIC_SLICE = "public_slice"; + + /** + * Resource ID for the menu entry of the setting. + */ + String HIGHLIGHT_MENU_RESOURCE = "highlight_menu"; } private static final String CREATE_SLICES_TABLE = - "CREATE VIRTUAL TABLE " + Tables.TABLE_SLICES_INDEX + " USING fts4" + - "(" + - IndexColumns.KEY + - ", " + - IndexColumns.SLICE_URI + - ", " + - IndexColumns.TITLE + - ", " + - IndexColumns.SUMMARY + - ", " + - IndexColumns.SCREENTITLE + - ", " + - IndexColumns.KEYWORDS + - ", " + - IndexColumns.ICON_RESOURCE + - ", " + - IndexColumns.FRAGMENT + - ", " + - IndexColumns.CONTROLLER + - ", " + - IndexColumns.SLICE_TYPE + - ", " + - IndexColumns.UNAVAILABLE_SLICE_SUBTITLE + - ", " - + - IndexColumns.PUBLIC_SLICE - + - " INTEGER DEFAULT 0 " - + - ");"; + "CREATE VIRTUAL TABLE " + Tables.TABLE_SLICES_INDEX + " USING fts4" + + "(" + + IndexColumns.KEY + + ", " + + IndexColumns.SLICE_URI + + ", " + + IndexColumns.TITLE + + ", " + + IndexColumns.SUMMARY + + ", " + + IndexColumns.SCREENTITLE + + ", " + + IndexColumns.KEYWORDS + + ", " + + IndexColumns.ICON_RESOURCE + + ", " + + IndexColumns.FRAGMENT + + ", " + + IndexColumns.CONTROLLER + + ", " + + IndexColumns.SLICE_TYPE + + ", " + + IndexColumns.UNAVAILABLE_SLICE_SUBTITLE + + ", " + + IndexColumns.PUBLIC_SLICE + + ", " + + IndexColumns.HIGHLIGHT_MENU_RESOURCE + + " INTEGER DEFAULT 0 " + + ");"; private final Context mContext; diff --git a/src/com/android/settings/slices/SlicesIndexer.java b/src/com/android/settings/slices/SlicesIndexer.java index e527fd657ab..ac30c6c0a41 100644 --- a/src/com/android/settings/slices/SlicesIndexer.java +++ b/src/com/android/settings/slices/SlicesIndexer.java @@ -116,6 +116,7 @@ class SlicesIndexer implements Runnable { values.put(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE, dataRow.getUnavailableSliceSubtitle()); values.put(IndexColumns.PUBLIC_SLICE, dataRow.isPublicSlice()); + values.put(IndexColumns.HIGHLIGHT_MENU_RESOURCE, dataRow.getHighlightMenuRes()); database.replaceOrThrow(Tables.TABLE_SLICES_INDEX, null /* nullColumnHack */, values); diff --git a/src/com/android/settings/sound/MediaControlsPreferenceController.java b/src/com/android/settings/sound/MediaControlsPreferenceController.java index ad09e2a6bee..e180b34fe34 100644 --- a/src/com/android/settings/sound/MediaControlsPreferenceController.java +++ b/src/com/android/settings/sound/MediaControlsPreferenceController.java @@ -23,6 +23,7 @@ import android.provider.Settings; import androidx.annotation.VisibleForTesting; +import com.android.settings.R; import com.android.settings.core.TogglePreferenceController; /** @@ -50,4 +51,9 @@ public class MediaControlsPreferenceController extends TogglePreferenceControlle public int getAvailabilityStatus() { return AVAILABLE; } + + @Override + public int getSliceHighlightMenuRes() { + return R.string.menu_key_sound; + } } diff --git a/src/com/android/settings/sound/MediaControlsRecommendationController.java b/src/com/android/settings/sound/MediaControlsRecommendationController.java index 682cb5bc1e6..842a1417a15 100644 --- a/src/com/android/settings/sound/MediaControlsRecommendationController.java +++ b/src/com/android/settings/sound/MediaControlsRecommendationController.java @@ -21,6 +21,7 @@ import static android.provider.Settings.Secure.MEDIA_CONTROLS_RECOMMENDATION; import android.content.Context; import android.provider.Settings; +import com.android.settings.R; import com.android.settings.core.TogglePreferenceController; /** @@ -50,4 +51,9 @@ public class MediaControlsRecommendationController extends TogglePreferenceContr public int getAvailabilityStatus() { return AVAILABLE; } + + @Override + public int getSliceHighlightMenuRes() { + return R.string.menu_key_sound; + } } diff --git a/src/com/android/settings/users/AddUserWhenLockedPreferenceController.java b/src/com/android/settings/users/AddUserWhenLockedPreferenceController.java index f931fa4f662..ce5533e5c64 100644 --- a/src/com/android/settings/users/AddUserWhenLockedPreferenceController.java +++ b/src/com/android/settings/users/AddUserWhenLockedPreferenceController.java @@ -20,6 +20,7 @@ import android.provider.Settings; import androidx.preference.Preference; +import com.android.settings.R; import com.android.settings.core.TogglePreferenceController; import com.android.settingslib.RestrictedSwitchPreference; @@ -69,4 +70,9 @@ public class AddUserWhenLockedPreferenceController extends TogglePreferenceContr return Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.ADD_USERS_WHEN_LOCKED, isChecked ? 1 : 0); } + + @Override + public int getSliceHighlightMenuRes() { + return R.string.menu_key_system; + } } diff --git a/src/com/android/settings/uwb/UwbPreferenceController.java b/src/com/android/settings/uwb/UwbPreferenceController.java index 8b330a9422f..ad040ed6043 100644 --- a/src/com/android/settings/uwb/UwbPreferenceController.java +++ b/src/com/android/settings/uwb/UwbPreferenceController.java @@ -162,5 +162,10 @@ public class UwbPreferenceController extends TogglePreferenceController implemen return mContext.getResources().getString(R.string.uwb_settings_summary); } } + + @Override + public int getSliceHighlightMenuRes() { + return R.string.menu_key_connected_devices; + } } diff --git a/src/com/android/settings/wifi/CellularFallbackPreferenceController.java b/src/com/android/settings/wifi/CellularFallbackPreferenceController.java index eab50a62e45..59ad44088ec 100644 --- a/src/com/android/settings/wifi/CellularFallbackPreferenceController.java +++ b/src/com/android/settings/wifi/CellularFallbackPreferenceController.java @@ -22,6 +22,7 @@ import android.provider.Settings; import android.telephony.SubscriptionManager; import com.android.internal.annotations.VisibleForTesting; +import com.android.settings.R; import com.android.settings.core.TogglePreferenceController; /** @@ -51,6 +52,11 @@ public class CellularFallbackPreferenceController extends TogglePreferenceContro Settings.Global.NETWORK_AVOID_BAD_WIFI, isChecked ? "1" : null); } + @Override + public int getSliceHighlightMenuRes() { + return R.string.menu_key_network; + } + private boolean avoidBadWifiConfig() { final int activeDataSubscriptionId = getActiveDataSubscriptionId(); if (activeDataSubscriptionId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { diff --git a/src/com/android/settings/wifi/NotifyOpenNetworksPreferenceController.java b/src/com/android/settings/wifi/NotifyOpenNetworksPreferenceController.java index 6455f5b97cc..4b7506d4606 100644 --- a/src/com/android/settings/wifi/NotifyOpenNetworksPreferenceController.java +++ b/src/com/android/settings/wifi/NotifyOpenNetworksPreferenceController.java @@ -26,6 +26,7 @@ import android.provider.Settings; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; +import com.android.settings.R; import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.TogglePreferenceController; import com.android.settingslib.core.lifecycle.LifecycleObserver; @@ -85,6 +86,11 @@ public class NotifyOpenNetworksPreferenceController extends TogglePreferenceCont return true; } + @Override + public int getSliceHighlightMenuRes() { + return R.string.menu_key_network; + } + class SettingObserver extends ContentObserver { private final Uri NETWORKS_AVAILABLE_URI = Settings.Global.getUriFor( Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON); diff --git a/src/com/android/settings/wifi/WifiWakeupPreferenceController.java b/src/com/android/settings/wifi/WifiWakeupPreferenceController.java index e9fd35004da..2cc7f8ef5d9 100644 --- a/src/com/android/settings/wifi/WifiWakeupPreferenceController.java +++ b/src/com/android/settings/wifi/WifiWakeupPreferenceController.java @@ -135,6 +135,11 @@ public class WifiWakeupPreferenceController extends TogglePreferenceController i } } + @Override + public int getSliceHighlightMenuRes() { + return R.string.menu_key_network; + } + @VisibleForTesting CharSequence getNoLocationSummary() { AnnotationSpan.LinkInfo linkInfo = new AnnotationSpan.LinkInfo("link", null); diff --git a/src/com/android/settings/wifi/details2/WifiAutoConnectPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiAutoConnectPreferenceController2.java index ffbb68289b5..8226bc07848 100644 --- a/src/com/android/settings/wifi/details2/WifiAutoConnectPreferenceController2.java +++ b/src/com/android/settings/wifi/details2/WifiAutoConnectPreferenceController2.java @@ -18,6 +18,7 @@ package com.android.settings.wifi.details2; import android.content.Context; +import com.android.settings.R; import com.android.settings.core.TogglePreferenceController; import com.android.wifitrackerlib.WifiEntry; @@ -54,4 +55,9 @@ public class WifiAutoConnectPreferenceController2 extends TogglePreferenceContro mWifiEntry.setAutoJoinEnabled(isChecked); return true; } + + @Override + public int getSliceHighlightMenuRes() { + return R.string.menu_key_network; + } } diff --git a/src/com/android/settings/wifi/slice/WifiSlice.java b/src/com/android/settings/wifi/slice/WifiSlice.java index f6604dd6f6e..29a2bd6cb32 100644 --- a/src/com/android/settings/wifi/slice/WifiSlice.java +++ b/src/com/android/settings/wifi/slice/WifiSlice.java @@ -33,6 +33,7 @@ import android.net.Uri; import android.net.wifi.WifiManager; import android.os.Bundle; import android.text.TextUtils; +import android.util.FeatureFlagUtils; import androidx.annotation.VisibleForTesting; import androidx.core.graphics.drawable.IconCompat; @@ -44,6 +45,8 @@ import com.android.settings.R; import com.android.settings.SubSettings; import com.android.settings.Utils; import com.android.settings.core.SubSettingLauncher; +import com.android.settings.network.NetworkProviderSettings; +import com.android.settings.network.WifiSwitchPreferenceController; import com.android.settings.slices.CustomSliceable; import com.android.settings.slices.SliceBackgroundWorker; import com.android.settings.slices.SliceBuilderUtils; @@ -269,15 +272,28 @@ public class WifiSlice implements CustomSliceable { public Intent getIntent() { final String screenTitle = mContext.getText(R.string.wifi_settings).toString(); final Uri contentUri = new Uri.Builder().appendPath(KEY_WIFI).build(); - final Intent intent = SliceBuilderUtils.buildSearchResultPageIntent(mContext, - WifiSettings.class.getName(), KEY_WIFI, screenTitle, - SettingsEnums.DIALOG_WIFI_AP_EDIT) + final String className; + final String key; + if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL)) { + className = NetworkProviderSettings.class.getName(); + key = WifiSwitchPreferenceController.KEY; + } else { + className = WifiSettings.class.getName(); + key = KEY_WIFI; + } + final Intent intent = SliceBuilderUtils.buildSearchResultPageIntent(mContext, className, + key, screenTitle, SettingsEnums.DIALOG_WIFI_AP_EDIT, this) .setClassName(mContext.getPackageName(), SubSettings.class.getName()) .setData(contentUri); return intent; } + @Override + public int getSliceHighlightMenuRes() { + return R.string.menu_key_network; + } + private boolean isWifiEnabled() { switch (mWifiManager.getWifiState()) { case WifiManager.WIFI_STATE_ENABLED: diff --git a/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java b/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java index 17471b5d90c..063be35fe77 100644 --- a/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java +++ b/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java @@ -16,6 +16,9 @@ package com.android.settings.notification; +import static android.os.UserHandle.USER_SYSTEM; +import static android.provider.Settings.*; + import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertFalse; @@ -24,6 +27,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import android.app.INotificationManager; import android.app.role.RoleManager; import android.app.usage.UsageEvents; import android.bluetooth.BluetoothAdapter; @@ -33,6 +37,7 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Parcel; +import android.provider.Settings; import com.android.settings.notification.NotificationBackend.AppRow; import com.android.settingslib.bluetooth.CachedBluetoothDevice; @@ -63,11 +68,16 @@ public class NotificationBackendTest { @Mock CachedBluetoothDeviceManager mCbm; ComponentName mCn = new ComponentName("a", "b"); + @Mock + INotificationManager mInm; + NotificationBackend mNotificationBackend; @Before public void setUp() { MockitoAnnotations.initMocks(this); when(mBm.getCachedDeviceManager()).thenReturn(mCbm); + mNotificationBackend = new NotificationBackend(); + mNotificationBackend.setNm(mInm); } @Test @@ -101,6 +111,46 @@ public class NotificationBackendTest { assertTrue(appRow.systemApp); } + @Test + public void testMarkAppRow_fixedPermission() throws Exception { + Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), + Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); + + PackageInfo pi = new PackageInfo(); + pi.packageName = "test"; + pi.applicationInfo = new ApplicationInfo(); + pi.applicationInfo.packageName = "test"; + pi.applicationInfo.uid = 123; + + when(mInm.isPermissionFixed(pi.packageName, 0)).thenReturn(true); + + AppRow appRow = new NotificationBackend().loadAppRow(RuntimeEnvironment.application, + mock(PackageManager.class), mock(RoleManager.class), pi); + + assertTrue(appRow.systemApp); + assertTrue(appRow.lockedImportance); + } + + @Test + public void testMarkAppRow_notFixedPermission() throws Exception { + Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), + Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); + + PackageInfo pi = new PackageInfo(); + pi.packageName = "test"; + pi.applicationInfo = new ApplicationInfo(); + pi.applicationInfo.packageName = "test"; + pi.applicationInfo.uid = 123; + + when(mInm.isPermissionFixed(pi.packageName, 0)).thenReturn(false); + + AppRow appRow = new NotificationBackend().loadAppRow(RuntimeEnvironment.application, + mock(PackageManager.class), mock(RoleManager.class), pi); + + assertFalse(appRow.systemApp); + assertFalse(appRow.lockedImportance); + } + @Test public void testMarkAppRow_notDefaultPackage() { PackageInfo pi = new PackageInfo(); diff --git a/tests/robotests/src/com/android/settings/notification/app/AllowSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/AllowSoundPreferenceControllerTest.java index be663d8f8c8..5260ff64c1d 100644 --- a/tests/robotests/src/com/android/settings/notification/app/AllowSoundPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/AllowSoundPreferenceControllerTest.java @@ -165,20 +165,6 @@ public class AllowSoundPreferenceControllerTest { assertFalse(pref.isEnabled()); } - @Test - public void testUpdateState_notBlockable_oem() { - NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - NotificationChannel channel = mock(NotificationChannel.class); - when(channel.getId()).thenReturn(""); - when(channel.isImportanceLockedByOEM()).thenReturn(true); - mController.onResume(appRow, channel, null, null, null, null, null); - - Preference pref = new RestrictedSwitchPreference(mContext); - mController.updateState(pref); - - assertTrue(pref.isEnabled()); - } - @Test public void testUpdateState_configurable() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); diff --git a/tests/robotests/src/com/android/settings/notification/app/BadgePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/BadgePreferenceControllerTest.java index 9cdf64dc79d..d8717764111 100644 --- a/tests/robotests/src/com/android/settings/notification/app/BadgePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/BadgePreferenceControllerTest.java @@ -217,20 +217,6 @@ public class BadgePreferenceControllerTest { assertFalse(pref.isEnabled()); } - @Test - public void testUpdateState_channelNotBlockable() { - NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - NotificationChannel channel = mock(NotificationChannel.class); - when(channel.getId()).thenReturn(""); - when(channel.isImportanceLockedByOEM()).thenReturn(true); - mController.onResume(appRow, channel, null, null, null, null, null); - - Preference pref = new RestrictedSwitchPreference(mContext); - mController.updateState(pref); - - assertTrue(pref.isEnabled()); - } - @Test public void testUpdateState_channel() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); diff --git a/tests/robotests/src/com/android/settings/notification/app/BlockPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/BlockPreferenceControllerTest.java index d65f91dd0b1..0c2eebe8070 100644 --- a/tests/robotests/src/com/android/settings/notification/app/BlockPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/BlockPreferenceControllerTest.java @@ -200,68 +200,40 @@ public class BlockPreferenceControllerTest { } @Test - public void testIsEnabled_lockedApp() { + public void testIsEnabled_cannotBlockAppOrGroupOrChannel() { + mController.setOverrideCanBlock(false); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - appRow.lockedImportance = true; - appRow.systemApp = true; mController.onResume(appRow, null, null, null, null, null, null); mController.updateState(mPreference); assertFalse(mPreference.getSwitchBar().isEnabled()); } @Test - public void testIsEnabled_GroupNotBlockable() { + public void testIsEnabled_importanceLocked_app() { + mController.setOverrideCanConfigure(false); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - appRow.systemApp = true; - mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null, - null); - mController.updateState(mPreference); - assertFalse(mPreference.getSwitchBar().isEnabled()); - } - - @Test - public void testIsEnabled_systemAppNotBlockable() { - NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - appRow.systemApp = true; mController.onResume(appRow, null, null, null, null, null, null); mController.updateState(mPreference); assertFalse(mPreference.getSwitchBar().isEnabled()); } @Test - public void testIsEnabled_systemAppBlockable() { + public void testIsEnabled_importanceLocked_group() { + mController.setOverrideCanConfigure(false); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - appRow.systemApp = true; - NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT); - channel.setBlockable(true); - mController.onResume(appRow, channel, null, null, null, null, null); + mController.onResume( + appRow, null, new NotificationChannelGroup("a", "a"), null, null, null, null); mController.updateState(mPreference); - assertTrue(mPreference.getSwitchBar().isEnabled()); - } - - @Test - public void testIsEnabled_lockedChannel() { - NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByOEM()).thenReturn(true); - when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); - mController.onResume(appRow, channel, null, null, null, null, null); - - mController.updateState(mPreference); - assertFalse(mPreference.getSwitchBar().isEnabled()); } @Test - public void testIsEnabled_defaultAppChannel() { + public void testIsEnabled_importanceLocked_channel() { + mController.setOverrideCanConfigure(false); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true); - when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); - mController.onResume(appRow, channel, null, null, null, null, null); - + mController.onResume(appRow, new NotificationChannel("a", "a", IMPORTANCE_LOW), null, null, + null, null, null); mController.updateState(mPreference); - assertFalse(mPreference.getSwitchBar().isEnabled()); } diff --git a/tests/robotests/src/com/android/settings/notification/app/BubblePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/BubblePreferenceControllerTest.java index e04402cd97a..09f6b7d634a 100644 --- a/tests/robotests/src/com/android/settings/notification/app/BubblePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/BubblePreferenceControllerTest.java @@ -297,21 +297,6 @@ public class BubblePreferenceControllerTest { assertFalse(pref.isEnabled()); } - @Test - public void updateState_channel_channelNotBlockable() { - Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON); - NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - appRow.pkg = "a"; - NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true); - mController.onResume(appRow, channel, null, null, null, null, null); - - Preference pref = new RestrictedSwitchPreference(mContext); - mController.updateState(pref); - - assertTrue(pref.isEnabled()); - } - @Test public void updateState_channel() { Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON); diff --git a/tests/robotests/src/com/android/settings/notification/app/ConversationPriorityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/ConversationPriorityPreferenceControllerTest.java index 692a4b18b5c..9bd2f153c05 100644 --- a/tests/robotests/src/com/android/settings/notification/app/ConversationPriorityPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/ConversationPriorityPreferenceControllerTest.java @@ -146,9 +146,9 @@ public class ConversationPriorityPreferenceControllerTest { @Test public void testUpdateState_notConfigurable() { + mController.setOverrideCanConfigure(false); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByOEM()).thenReturn(true); when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); mController.onResume(appRow, channel, null, null, null, null, null); @@ -159,26 +159,10 @@ public class ConversationPriorityPreferenceControllerTest { } @Test - public void testUpdateState_systemButConfigurable() { + public void testUpdateState_Configurable() { + mController.setOverrideCanConfigure(true); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - appRow.systemApp = true; NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByOEM()).thenReturn(false); - when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); - mController.onResume(appRow, channel, null, null, null, null, null); - - Preference pref = new ConversationPriorityPreference(mContext, null); - mController.updateState(pref); - - assertTrue(pref.isEnabled()); - } - - @Test - public void testUpdateState_defaultApp() { - NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - appRow.systemApp = true; - NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true); when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); mController.onResume(appRow, channel, null, null, null, null, null); diff --git a/tests/robotests/src/com/android/settings/notification/app/DndPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/DndPreferenceControllerTest.java index 22a7b0946bc..7357bb3f12f 100644 --- a/tests/robotests/src/com/android/settings/notification/app/DndPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/DndPreferenceControllerTest.java @@ -138,8 +138,8 @@ public class DndPreferenceControllerTest { @Test public void testUpdateState_notBlockable() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.lockedImportance = true; NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByOEM()).thenReturn(true); mController.onResume(appRow, channel, null, null, null, null, null); Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application); diff --git a/tests/robotests/src/com/android/settings/notification/app/HighImportancePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/HighImportancePreferenceControllerTest.java index 0db46789d19..5189beb6fbb 100644 --- a/tests/robotests/src/com/android/settings/notification/app/HighImportancePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/HighImportancePreferenceControllerTest.java @@ -166,9 +166,9 @@ public class HighImportancePreferenceControllerTest { @Test public void testUpdateState_notConfigurable() { + mController.setOverrideCanConfigure(false); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByOEM()).thenReturn(true); when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); mController.onResume(appRow, channel, null, null, null, null, null); @@ -179,26 +179,10 @@ public class HighImportancePreferenceControllerTest { } @Test - public void testUpdateState_systemButConfigurable() { + public void testUpdateState_Configurable() { + mController.setOverrideCanConfigure(true); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - appRow.systemApp = true; NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByOEM()).thenReturn(false); - when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); - mController.onResume(appRow, channel, null, null, null, null, null); - - Preference pref = new RestrictedSwitchPreference(mContext, null); - mController.updateState(pref); - - assertTrue(pref.isEnabled()); - } - - @Test - public void testUpdateState_defaultApp() { - NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - appRow.systemApp = true; - NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true); when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); mController.onResume(appRow, channel, null, null, null, null, null); diff --git a/tests/robotests/src/com/android/settings/notification/app/ImportancePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/ImportancePreferenceControllerTest.java index 223fa23324b..34f777a5cbd 100644 --- a/tests/robotests/src/com/android/settings/notification/app/ImportancePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/ImportancePreferenceControllerTest.java @@ -183,9 +183,9 @@ public class ImportancePreferenceControllerTest { @Test public void testUpdateState_notConfigurable() { + mController.setOverrideCanConfigure(false); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByOEM()).thenReturn(true); when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); mController.onResume(appRow, channel, null, null, null, null, null); @@ -196,26 +196,10 @@ public class ImportancePreferenceControllerTest { } @Test - public void testUpdateState_systemButConfigurable() { + public void testUpdateState_Configurable() { + mController.setOverrideCanConfigure(true); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - appRow.systemApp = true; NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByOEM()).thenReturn(false); - when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); - mController.onResume(appRow, channel, null, null, null, null, null); - - Preference pref = new ImportancePreference(mContext, null); - mController.updateState(pref); - - assertTrue(pref.isEnabled()); - } - - @Test - public void testUpdateState_defaultApp() { - NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - appRow.systemApp = true; - NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true); when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); mController.onResume(appRow, channel, null, null, null, null, null); diff --git a/tests/robotests/src/com/android/settings/notification/app/LightsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/LightsPreferenceControllerTest.java index e51a9e003ba..d977d8b091c 100644 --- a/tests/robotests/src/com/android/settings/notification/app/LightsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/LightsPreferenceControllerTest.java @@ -181,19 +181,6 @@ public class LightsPreferenceControllerTest { assertFalse(pref.isEnabled()); } - @Test - public void testUpdateState_notBlockable() { - NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByOEM()).thenReturn(true); - mController.onResume(appRow, channel, null, null, null, null, null); - - Preference pref = new RestrictedSwitchPreference(mContext); - mController.updateState(pref); - - assertTrue(pref.isEnabled()); - } - @Test public void testUpdateState_lightsOn() { NotificationChannel channel = mock(NotificationChannel.class); diff --git a/tests/robotests/src/com/android/settings/notification/app/MinImportancePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/MinImportancePreferenceControllerTest.java index 3907db22f92..b3d5cf01d81 100644 --- a/tests/robotests/src/com/android/settings/notification/app/MinImportancePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/MinImportancePreferenceControllerTest.java @@ -166,9 +166,9 @@ public class MinImportancePreferenceControllerTest { @Test public void testUpdateState_notConfigurable() { + mController.setOverrideCanConfigure(false); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByOEM()).thenReturn(true); when(channel.getImportance()).thenReturn(IMPORTANCE_LOW); mController.onResume(appRow, channel, null, null, null, null, null); @@ -179,26 +179,11 @@ public class MinImportancePreferenceControllerTest { } @Test - public void testUpdateState_systemButConfigurable() { + public void testUpdateState_Configurable() { + mController.setOverrideCanConfigure(true); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - appRow.systemApp = true; NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByOEM()).thenReturn(false); - when(channel.getImportance()).thenReturn(IMPORTANCE_LOW); - mController.onResume(appRow, channel, null, null, null, null, null); - - Preference pref = new RestrictedSwitchPreference(mContext, null); - mController.updateState(pref); - - assertTrue(pref.isEnabled()); - } - - @Test - public void testUpdateState_defaultApp() { - NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - appRow.systemApp = true; - NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true); + when(channel.isBlockable()).thenReturn(true); when(channel.getImportance()).thenReturn(IMPORTANCE_LOW); mController.onResume(appRow, channel, null, null, null, null, null); diff --git a/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java index 1fb9942fcb2..8d31fe53354 100644 --- a/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java @@ -22,6 +22,7 @@ import static android.app.NotificationManager.IMPORTANCE_LOW; import static android.app.NotificationManager.IMPORTANCE_MIN; import static android.app.NotificationManager.IMPORTANCE_NONE; import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED; +import static android.os.UserHandle.USER_SYSTEM; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -38,6 +39,7 @@ import android.app.NotificationChannelGroup; import android.app.NotificationManager; import android.content.Context; import android.os.UserManager; +import android.provider.Settings; import androidx.preference.Preference; @@ -221,6 +223,109 @@ public class NotificationPreferenceControllerTest { verify(mBackend, times(1)).updateChannel(any(), anyInt(), any()); } + @Test + public void testIsChannelBlockable_postMigration_locked() { + Settings.Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), + Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); + + mController = new TestPreferenceController(mContext, mBackend); + + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.lockedImportance = true; + NotificationChannel channel = mock(NotificationChannel.class); + when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); + mController.onResume(appRow, channel, null, null, null, null, null); + assertFalse(mController.isChannelBlockable()); + } + + @Test + public void testIsChannelBlockable_postMigration_locked_butChannelOff() { + Settings.Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), + Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); + + mController = new TestPreferenceController(mContext, mBackend); + + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.lockedImportance = true; + NotificationChannel channel = mock(NotificationChannel.class); + when(channel.getImportance()).thenReturn(IMPORTANCE_NONE); + mController.onResume(appRow, channel, null, null, null, null, null); + assertTrue(mController.isChannelBlockable()); + } + + @Test + public void testIsChannelBlockable_postMigration_locked_butChannelBlockable() { + Settings.Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), + Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); + + mController = new TestPreferenceController(mContext, mBackend); + + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.lockedImportance = true; + NotificationChannel channel = mock(NotificationChannel.class); + when(channel.isBlockable()).thenReturn(true); + when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); + mController.onResume(appRow, channel, null, null, null, null, null); + assertTrue(mController.isChannelBlockable()); + } + + @Test + public void testIsChannelGroupBlockable_postMigration_locked() { + Settings.Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), + Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); + + mController = new TestPreferenceController(mContext, mBackend); + + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.lockedImportance = true; + NotificationChannelGroup channelGroup = mock(NotificationChannelGroup.class); + mController.onResume(appRow, null, channelGroup, null, null, null, null); + assertFalse(mController.isChannelGroupBlockable()); + } + + @Test + public void testIsChannelGroupBlockable_postMigration_locked_butChannelGroupOff() { + Settings.Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), + Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); + + mController = new TestPreferenceController(mContext, mBackend); + + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.lockedImportance = true; + NotificationChannelGroup channelGroup = mock(NotificationChannelGroup.class); + when(channelGroup.isBlocked()).thenReturn(true); + mController.onResume(appRow, null, channelGroup, null, null, null, null); + assertTrue(mController.isChannelGroupBlockable()); + } + + @Test + public void testIsAppBlockable_postMigration_locked() { + Settings.Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), + Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); + + mController = new TestPreferenceController(mContext, mBackend); + + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.lockedImportance = true; + appRow.banned = false; + mController.onResume(appRow, null, null, null, null, null, null); + assertFalse(mController.isAppBlockable()); + } + + @Test + public void testIsAppBlockable_postMigration_locked_butAppOff() { + Settings.Secure.putIntForUser(RuntimeEnvironment.application.getContentResolver(), + Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 1, USER_SYSTEM); + + mController = new TestPreferenceController(mContext, mBackend); + + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.lockedImportance = true; + appRow.banned = true; + mController.onResume(appRow, null, null, null, null, null, null); + assertFalse(mController.isAppBlockable()); + } + @Test public void testIsBlockable_oemAllowlist() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); diff --git a/tests/robotests/src/com/android/settings/notification/app/SoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/SoundPreferenceControllerTest.java index c79b97d3ba2..273bcdbe213 100644 --- a/tests/robotests/src/com/android/settings/notification/app/SoundPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/SoundPreferenceControllerTest.java @@ -182,20 +182,6 @@ public class SoundPreferenceControllerTest { assertFalse(pref.isEnabled()); } - @Test - public void testUpdateState_notBlockable() { - NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); - NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByOEM()).thenReturn(true); - mController.onResume(appRow, channel, null, null, null, null, null); - - AttributeSet attributeSet = Robolectric.buildAttributeSet().build(); - Preference pref = new NotificationSoundPreference(mContext, attributeSet); - mController.updateState(pref); - - assertTrue(pref.isEnabled()); - } - @Test public void testUpdateState_configurable() { Uri sound = Settings.System.DEFAULT_ALARM_ALERT_URI; diff --git a/tests/robotests/src/com/android/settings/notification/app/VibrationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/VibrationPreferenceControllerTest.java index 0fb5e72eb51..ad6df604654 100644 --- a/tests/robotests/src/com/android/settings/notification/app/VibrationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/VibrationPreferenceControllerTest.java @@ -162,10 +162,9 @@ public class VibrationPreferenceControllerTest { } @Test - public void testUpdateState_notBlockable() { + public void testUpdateState_blockable() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); NotificationChannel channel = mock(NotificationChannel.class); - when(channel.isImportanceLockedByOEM()).thenReturn(true); mController.onResume(appRow, channel, null, null, null, null, null); Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application); diff --git a/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java index c99d5c99d8e..6749c1761b8 100644 --- a/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java +++ b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java @@ -724,6 +724,7 @@ public class SettingsSliceProviderTest { .setIcon(SliceTestUtils.FAKE_ICON) .setFragmentName(SliceTestUtils.FAKE_FRAGMENT_NAME) .setPreferenceControllerClassName(SliceTestUtils.FAKE_CONTROLLER_NAME) + .setHighlightMenuRes(SliceTestUtils.FAKE_HIGHLIGHT_MENU_RES) .build(); } diff --git a/tests/robotests/src/com/android/settings/slices/SliceBroadcastReceiverTest.java b/tests/robotests/src/com/android/settings/slices/SliceBroadcastReceiverTest.java index 1809906a968..f47c5f95edf 100644 --- a/tests/robotests/src/com/android/settings/slices/SliceBroadcastReceiverTest.java +++ b/tests/robotests/src/com/android/settings/slices/SliceBroadcastReceiverTest.java @@ -333,6 +333,8 @@ public class SliceBroadcastReceiverTest { values.put(SlicesDatabaseHelper.IndexColumns.FRAGMENT, SliceTestUtils.FAKE_FRAGMENT_NAME); values.put(SlicesDatabaseHelper.IndexColumns.CONTROLLER, controllerClass); values.put(SlicesDatabaseHelper.IndexColumns.SLICE_URI, buildUri(key).toSafeString()); + values.put(SlicesDatabaseHelper.IndexColumns.HIGHLIGHT_MENU_RESOURCE, + SliceTestUtils.FAKE_HIGHLIGHT_MENU_RES); mDb.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values); } diff --git a/tests/robotests/src/com/android/settings/slices/SliceTestUtils.java b/tests/robotests/src/com/android/settings/slices/SliceTestUtils.java index 1c9164a6a84..97beeb32471 100644 --- a/tests/robotests/src/com/android/settings/slices/SliceTestUtils.java +++ b/tests/robotests/src/com/android/settings/slices/SliceTestUtils.java @@ -35,6 +35,7 @@ class SliceTestUtils { public static final int FAKE_ICON = 1234; public static final String FAKE_FRAGMENT_NAME = FakeIndexProvider.class.getName(); public static final String FAKE_CONTROLLER_NAME = FakeToggleController.class.getName(); + public static final int FAKE_HIGHLIGHT_MENU_RES = FakeToggleController.HIGHLIGHT_MENU_RES; public static void insertSliceToDb(Context context, String key) { @@ -75,6 +76,8 @@ class SliceTestUtils { values.put(SlicesDatabaseHelper.IndexColumns.UNAVAILABLE_SLICE_SUBTITLE, customizedUnavailableSliceSubtitle); values.put(SlicesDatabaseHelper.IndexColumns.PUBLIC_SLICE, isPublicSlice); + values.put(SlicesDatabaseHelper.IndexColumns.HIGHLIGHT_MENU_RESOURCE, + FAKE_HIGHLIGHT_MENU_RES); db.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values); db.close(); diff --git a/tests/robotests/src/com/android/settings/slices/SlicesDatabaseAccessorTest.java b/tests/robotests/src/com/android/settings/slices/SlicesDatabaseAccessorTest.java index f7b1f1c99d3..f00f8b1e138 100644 --- a/tests/robotests/src/com/android/settings/slices/SlicesDatabaseAccessorTest.java +++ b/tests/robotests/src/com/android/settings/slices/SlicesDatabaseAccessorTest.java @@ -104,6 +104,7 @@ public class SlicesDatabaseAccessorTest { assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME); assertThat(data.getUri()).isNull(); assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME); + assertThat(data.getHighlightMenuRes()).isEqualTo(SliceTestUtils.FAKE_HIGHLIGHT_MENU_RES); assertThat(data.getUnavailableSliceSubtitle()).isNull(); } @@ -125,6 +126,7 @@ public class SlicesDatabaseAccessorTest { assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME); assertThat(data.getUri()).isNull(); assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME); + assertThat(data.getHighlightMenuRes()).isEqualTo(SliceTestUtils.FAKE_HIGHLIGHT_MENU_RES); } @Test(expected = IllegalStateException.class) @@ -159,6 +161,7 @@ public class SlicesDatabaseAccessorTest { assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME); assertThat(data.getUri()).isEqualTo(uri); assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME); + assertThat(data.getHighlightMenuRes()).isEqualTo(SliceTestUtils.FAKE_HIGHLIGHT_MENU_RES); } @Test(expected = IllegalStateException.class) @@ -303,6 +306,7 @@ public class SlicesDatabaseAccessorTest { assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME); assertThat(data.getUri()).isNull(); assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME); + assertThat(data.getHighlightMenuRes()).isEqualTo(SliceTestUtils.FAKE_HIGHLIGHT_MENU_RES); assertThat(data.getUnavailableSliceSubtitle()).isNull(); } @@ -324,6 +328,7 @@ public class SlicesDatabaseAccessorTest { assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME); assertThat(data.getUri()).isNull(); assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME); + assertThat(data.getHighlightMenuRes()).isEqualTo(SliceTestUtils.FAKE_HIGHLIGHT_MENU_RES); assertThat(data.getUnavailableSliceSubtitle()).isEqualTo(subtitle); } diff --git a/tests/robotests/src/com/android/settings/slices/SlicesIndexerTest.java b/tests/robotests/src/com/android/settings/slices/SlicesIndexerTest.java index 87d0cd40104..60ddef546ce 100644 --- a/tests/robotests/src/com/android/settings/slices/SlicesIndexerTest.java +++ b/tests/robotests/src/com/android/settings/slices/SlicesIndexerTest.java @@ -44,17 +44,18 @@ import java.util.List; @RunWith(RobolectricTestRunner.class) public class SlicesIndexerTest { - private final String[] KEYS = new String[]{"key1", "key2", "key3"}; - private final String[] TITLES = new String[]{"title1", "title2", "title3"}; - private final String SUMMARY = "subtitle"; - private final String SCREEN_TITLE = "screen title"; - private final String KEYWORDS = "a, b, c"; - private final String FRAGMENT_NAME = "fragment name"; - private final int ICON = 1234; // I declare a thumb war - private final Uri URI = Uri.parse("content://com.android.settings.slices/test"); - private final String PREF_CONTROLLER = "com.android.settings.slices.tester"; - private final int SLICE_TYPE = SliceData.SliceType.SLIDER; - private final String UNAVAILABLE_SLICE_SUBTITLE = "subtitleOfUnavailableSlice"; + private static final String[] KEYS = new String[]{"key1", "key2", "key3"}; + private static final String[] TITLES = new String[]{"title1", "title2", "title3"}; + private static final String SUMMARY = "subtitle"; + private static final String SCREEN_TITLE = "screen title"; + private static final String KEYWORDS = "a, b, c"; + private static final String FRAGMENT_NAME = "fragment name"; + private static final int ICON = 1234; // I declare a thumb war + private static final Uri URI = Uri.parse("content://com.android.settings.slices/test"); + private static final String PREF_CONTROLLER = "com.android.settings.slices.tester"; + private static final int SLICE_TYPE = SliceData.SliceType.SLIDER; + private static final String UNAVAILABLE_SLICE_SUBTITLE = "subtitleOfUnavailableSlice"; + private static final int HIGHLIGHT_MENU_KEY = 5678; // I declare a thumb war private Context mContext; @@ -145,6 +146,9 @@ public class SlicesIndexerTest { .isEqualTo(UNAVAILABLE_SLICE_SUBTITLE); assertThat(cursor.getInt( cursor.getColumnIndex(IndexColumns.PUBLIC_SLICE))).isEqualTo(0); + assertThat(cursor.getInt( + cursor.getColumnIndex(IndexColumns.HIGHLIGHT_MENU_RESOURCE))) + .isEqualTo(HIGHLIGHT_MENU_KEY); cursor.moveToNext(); } } finally { @@ -191,6 +195,9 @@ public class SlicesIndexerTest { .isEqualTo(UNAVAILABLE_SLICE_SUBTITLE); assertThat(cursor.getInt( cursor.getColumnIndex(IndexColumns.PUBLIC_SLICE))).isEqualTo(1); + assertThat(cursor.getInt( + cursor.getColumnIndex(IndexColumns.HIGHLIGHT_MENU_RESOURCE))) + .isEqualTo(HIGHLIGHT_MENU_KEY); cursor.moveToNext(); } } finally { @@ -224,7 +231,8 @@ public class SlicesIndexerTest { .setUri(URI) .setPreferenceControllerClassName(PREF_CONTROLLER) .setSliceType(SLICE_TYPE) - .setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE); + .setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE) + .setHighlightMenuRes(HIGHLIGHT_MENU_KEY); if (isPublicSlice) { builder.setIsPublicSlice(true); diff --git a/tests/robotests/src/com/android/settings/testutils/FakeToggleController.java b/tests/robotests/src/com/android/settings/testutils/FakeToggleController.java index 68124512cfc..4e968a29c70 100644 --- a/tests/robotests/src/com/android/settings/testutils/FakeToggleController.java +++ b/tests/robotests/src/com/android/settings/testutils/FakeToggleController.java @@ -27,6 +27,7 @@ import com.android.settings.slices.SliceBackgroundWorker; public class FakeToggleController extends TogglePreferenceController { public static final String AVAILABILITY_KEY = "fake_toggle_availability_key"; + public static final int HIGHLIGHT_MENU_RES = 5678; public static final IntentFilter INTENT_FILTER = new IntentFilter( WifiManager.WIFI_AP_STATE_CHANGED_ACTION); @@ -70,6 +71,11 @@ public class FakeToggleController extends TogglePreferenceController { return true; } + @Override + public int getSliceHighlightMenuRes() { + return HIGHLIGHT_MENU_RES; + } + @Override public Class extends SliceBackgroundWorker> getBackgroundWorkerClass() { return TestWorker.class; diff --git a/tests/unit/src/com/android/settings/core/TogglePreferenceControllerTest.java b/tests/unit/src/com/android/settings/core/TogglePreferenceControllerTest.java index 8817a176203..13e8c13c5fa 100644 --- a/tests/unit/src/com/android/settings/core/TogglePreferenceControllerTest.java +++ b/tests/unit/src/com/android/settings/core/TogglePreferenceControllerTest.java @@ -119,6 +119,11 @@ public class TogglePreferenceControllerTest { return true; } + @Override + public int getSliceHighlightMenuRes() { + return 5678; + } + @Override public int getAvailabilityStatus() { return AVAILABLE; diff --git a/tests/unit/src/com/android/settings/network/ProviderModelSliceHelperTest.java b/tests/unit/src/com/android/settings/network/ProviderModelSliceHelperTest.java index 7d4323051c3..df6a38b20a1 100644 --- a/tests/unit/src/com/android/settings/network/ProviderModelSliceHelperTest.java +++ b/tests/unit/src/com/android/settings/network/ProviderModelSliceHelperTest.java @@ -302,6 +302,11 @@ public class ProviderModelSliceHelperTest { public Intent getIntent() { return new Intent(); } + + @Override + public int getSliceHighlightMenuRes() { + return 0; + } } private class MockProviderModelSliceHelper extends ProviderModelSliceHelper { diff --git a/tests/unit/src/com/android/settings/slices/SliceTestUtils.java b/tests/unit/src/com/android/settings/slices/SliceTestUtils.java index 1b035cd57a7..40a827a8a99 100644 --- a/tests/unit/src/com/android/settings/slices/SliceTestUtils.java +++ b/tests/unit/src/com/android/settings/slices/SliceTestUtils.java @@ -35,6 +35,7 @@ class SliceTestUtils { public static final int FAKE_ICON = 1234; public static final String FAKE_FRAGMENT_NAME = FakeIndexProvider.class.getName(); public static final String FAKE_CONTROLLER_NAME = FakeToggleController.class.getName(); + public static final int FAKE_HIGHLIGHT_MENU_RES = FakeToggleController.HIGHLIGHT_MENU_RES; public static void insertSliceToDb(Context context, String key) { @@ -75,6 +76,8 @@ class SliceTestUtils { values.put(SlicesDatabaseHelper.IndexColumns.UNAVAILABLE_SLICE_SUBTITLE, customizedUnavailableSliceSubtitle); values.put(SlicesDatabaseHelper.IndexColumns.PUBLIC_SLICE, isPublicSlice); + values.put(SlicesDatabaseHelper.IndexColumns.HIGHLIGHT_MENU_RESOURCE, + FAKE_HIGHLIGHT_MENU_RES); db.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values); db.close(); diff --git a/tests/unit/src/com/android/settings/slices/SpecialCaseSliceManagerTest.java b/tests/unit/src/com/android/settings/slices/SpecialCaseSliceManagerTest.java index 4fcbd15d16e..490b7bd62c6 100644 --- a/tests/unit/src/com/android/settings/slices/SpecialCaseSliceManagerTest.java +++ b/tests/unit/src/com/android/settings/slices/SpecialCaseSliceManagerTest.java @@ -143,5 +143,10 @@ public class SpecialCaseSliceManagerTest { public Intent getIntent() { return null; } + + @Override + public int getSliceHighlightMenuRes() { + return 0; + } } } diff --git a/tests/unit/src/com/android/settings/testutils/FakeToggleController.java b/tests/unit/src/com/android/settings/testutils/FakeToggleController.java index 9eda8b6a802..c232479d61c 100644 --- a/tests/unit/src/com/android/settings/testutils/FakeToggleController.java +++ b/tests/unit/src/com/android/settings/testutils/FakeToggleController.java @@ -27,6 +27,7 @@ import com.android.settings.slices.SliceBackgroundWorker; public class FakeToggleController extends TogglePreferenceController { public static final String AVAILABILITY_KEY = "fake_toggle_availability_key"; + public static final int HIGHLIGHT_MENU_RES = 5678; public static final IntentFilter INTENT_FILTER = new IntentFilter( WifiManager.WIFI_AP_STATE_CHANGED_ACTION); @@ -70,6 +71,11 @@ public class FakeToggleController extends TogglePreferenceController { return true; } + @Override + public int getSliceHighlightMenuRes() { + return HIGHLIGHT_MENU_RES; + } + @Override public Class extends SliceBackgroundWorker> getBackgroundWorkerClass() { return TestWorker.class;