diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java b/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java index 1f5f7dd5694..32f505ecf00 100644 --- a/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java +++ b/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java @@ -17,8 +17,8 @@ package com.android.settings.homepage.contextualcards; import static com.android.settings.slices.CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI; +import static com.android.settings.slices.CustomSliceRegistry.CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI; import static com.android.settings.slices.CustomSliceRegistry.CONTEXTUAL_WIFI_SLICE_URI; -import static com.android.settings.slices.CustomSliceRegistry.NOTIFICATION_CHANNEL_SLICE_URI; import android.content.Context; import android.database.ContentObserver; @@ -208,7 +208,7 @@ public class ContextualCardLoader extends AsyncLoaderCompat private boolean isLargeCard(ContextualCard card) { return card.getSliceUri().equals(CONTEXTUAL_WIFI_SLICE_URI) || card.getSliceUri().equals(BLUETOOTH_DEVICES_SLICE_URI) - || card.getSliceUri().equals(NOTIFICATION_CHANNEL_SLICE_URI); + || card.getSliceUri().equals(CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI); } public interface CardContentLoaderListener { diff --git a/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java b/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java index 7bbe430e4b7..86fee03e556 100644 --- a/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java +++ b/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java @@ -56,10 +56,12 @@ public class SettingsContextualCardProvider extends ContextualCardProvider { .setCardName(CustomSliceRegistry.BATTERY_FIX_SLICE_URI.toString()) .setCardCategory(ContextualCard.Category.IMPORTANT) .build(); + final String contextualNotificationChannelSliceUri = + CustomSliceRegistry.CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI.toString(); final ContextualCard notificationChannelCard = ContextualCard.newBuilder() - .setSliceUri(CustomSliceRegistry.NOTIFICATION_CHANNEL_SLICE_URI.toString()) - .setCardName(CustomSliceRegistry.NOTIFICATION_CHANNEL_SLICE_URI.toString()) + .setSliceUri(contextualNotificationChannelSliceUri) + .setCardName(contextualNotificationChannelSliceUri) .setCardCategory(ContextualCard.Category.POSSIBLE) .build(); final ContextualCardList cards = ContextualCardList.newBuilder() @@ -72,4 +74,4 @@ public class SettingsContextualCardProvider extends ContextualCardProvider { return cards; } -} \ No newline at end of file +} diff --git a/src/com/android/settings/homepage/contextualcards/slices/ContextualNotificationChannelSlice.java b/src/com/android/settings/homepage/contextualcards/slices/ContextualNotificationChannelSlice.java new file mode 100644 index 00000000000..2025a06a71a --- /dev/null +++ b/src/com/android/settings/homepage/contextualcards/slices/ContextualNotificationChannelSlice.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.homepage.contextualcards.slices; + +import android.content.Context; +import android.net.Uri; + +import com.android.settings.R; +import com.android.settings.slices.CustomSliceRegistry; + +public class ContextualNotificationChannelSlice extends NotificationChannelSlice { + + public ContextualNotificationChannelSlice(Context context) { + super(context); + } + + @Override + public Uri getUri() { + return CustomSliceRegistry.CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI; + } + + @Override + protected CharSequence getSubTitle(String packageName, int uid) { + return mContext.getText(R.string.recently_installed_app); + } +} diff --git a/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java b/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java index ae8b80a8fff..c319dca8c5a 100644 --- a/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java +++ b/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java @@ -128,7 +128,7 @@ public class NotificationChannelSlice implements CustomSliceable { return leftChannel.getId().compareTo(rightChannel.getId()); }; - private final Context mContext; + protected final Context mContext; @VisibleForTesting NotificationBackend mNotificationBackend; private String mPackageName; @@ -413,7 +413,7 @@ public class NotificationChannelSlice implements CustomSliceable { return maxSentCountPackage; } - private CharSequence getSubTitle(String packageName, int uid) { + protected CharSequence getSubTitle(String packageName, int uid) { final int channelCount = mNotificationBackend.getChannelCount(packageName, uid); if (channelCount > DEFAULT_EXPANDED_ROW_COUNT) { diff --git a/src/com/android/settings/slices/CustomSliceRegistry.java b/src/com/android/settings/slices/CustomSliceRegistry.java index 6b1ead729c3..fe000d14cd3 100644 --- a/src/com/android/settings/slices/CustomSliceRegistry.java +++ b/src/com/android/settings/slices/CustomSliceRegistry.java @@ -36,6 +36,7 @@ import com.android.settings.homepage.contextualcards.deviceinfo.EmergencyInfoSli import com.android.settings.homepage.contextualcards.deviceinfo.StorageSlice; import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice; import com.android.settings.homepage.contextualcards.slices.BluetoothDevicesSlice; +import com.android.settings.homepage.contextualcards.slices.ContextualNotificationChannelSlice; import com.android.settings.homepage.contextualcards.slices.LowStorageSlice; import com.android.settings.homepage.contextualcards.slices.NotificationChannelSlice; import com.android.settings.location.LocationSlice; @@ -94,6 +95,16 @@ public class CustomSliceRegistry { .appendPath("bluetooth_devices") .build(); + /** + * Backing Uri for Contextual Notification channel Slice. + */ + public static final Uri CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI = new Uri.Builder() + .scheme(ContentResolver.SCHEME_CONTENT) + .authority(SettingsSliceProvider.SLICE_AUTHORITY) + .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION) + .appendPath("contextual_notification_channel") + .build(); + /** * Backing Uri for the Wifi Slice. */ @@ -318,6 +329,8 @@ public class CustomSliceRegistry { sUriToSlice.put(BATTERY_FIX_SLICE_URI, BatteryFixSlice.class); sUriToSlice.put(BLUETOOTH_DEVICES_SLICE_URI, BluetoothDevicesSlice.class); + sUriToSlice.put(CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI, + ContextualNotificationChannelSlice.class); sUriToSlice.put(CONTEXTUAL_WIFI_SLICE_URI, ContextualWifiSlice.class); sUriToSlice.put(DATA_USAGE_SLICE_URI, DataUsageSlice.class); sUriToSlice.put(DEVICE_INFO_SLICE_URI, DeviceInfoSlice.class); diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/ContextualNotificationChannelSliceTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/ContextualNotificationChannelSliceTest.java new file mode 100644 index 00000000000..f2b87be53ed --- /dev/null +++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/ContextualNotificationChannelSliceTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.homepage.contextualcards.slices; + +import static com.google.common.truth.Truth.assertThat; + +import android.content.Context; +import android.net.Uri; + +import com.android.settings.R; +import com.android.settings.slices.CustomSliceRegistry; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; + +@RunWith(RobolectricTestRunner.class) +public class ContextualNotificationChannelSliceTest { + + private Context mContext; + private ContextualNotificationChannelSlice mNotificationChannelSlice; + + @Before + public void setUp() { + mContext = RuntimeEnvironment.application; + mNotificationChannelSlice = new ContextualNotificationChannelSlice(mContext); + } + + @Test + public void getUri_shouldBeContextualNotificationChannelSliceUri() { + final Uri uri = mNotificationChannelSlice.getUri(); + + assertThat(uri).isEqualTo(CustomSliceRegistry.CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI); + } + + @Test + public void getSubTitle_shouldBeRecentlyInstalledApp() { + final CharSequence subTitle = mNotificationChannelSlice.getSubTitle("com.test.package", 0); + + assertThat(subTitle).isEqualTo(mContext.getText(R.string.recently_installed_app)); + } +}