From a92deac94d8b5ebe30cefd4db6fbcf93e41f7939 Mon Sep 17 00:00:00 2001 From: Sunny Shao Date: Mon, 15 Jun 2020 17:14:28 +0800 Subject: [PATCH 1/8] Workaround for Recent app icon disappear - Use the ic_home_xxxx.xml to replace the original icon. Bug: 157623047 Test: manual review Change-Id: Iffd084cac6a0a40d13d9fd1a8944ef957db450c6 Merged-In: I7a78ba47a0383a5e4c65bd461a15a8425beb1acb --- AndroidManifest.xml | 16 ++++----- color-check-baseline.xml | 32 ++++++++++++++++++ res/drawable/ic_homepage_night_display.xml | 33 +++++++++++++++++++ res/drawable/ic_homepage_notification.xml | 33 +++++++++++++++++++ res/drawable/ic_notifications_white.xml | 19 +++++++++++ .../ic_settings_night_display_white.xml | 19 +++++++++++ 6 files changed, 144 insertions(+), 8 deletions(-) create mode 100644 res/drawable/ic_homepage_night_display.xml create mode 100644 res/drawable/ic_homepage_notification.xml create mode 100644 res/drawable/ic_notifications_white.xml create mode 100644 res/drawable/ic_settings_night_display_white.xml diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 4f3caed4285..1b7eed87722 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -218,7 +218,7 @@ + android:icon="@drawable/ic_homepage_connected_device"> @@ -253,7 +253,7 @@ @@ -272,7 +272,7 @@ @@ -491,7 +491,7 @@ + android:icon="@drawable/ic_homepage_network"> @@ -737,7 +737,7 @@ @@ -908,7 +908,7 @@ android:name="Settings$NightDisplaySettingsActivity" android:label="@string/night_display_title" android:enabled="@*android:bool/config_nightDisplayAvailable" - android:icon="@drawable/ic_settings_night_display"> + android:icon="@drawable/ic_homepage_night_display"> @@ -1224,7 +1224,7 @@ @@ -2178,7 +2178,7 @@ + android:icon="@drawable/ic_homepage_battery"> diff --git a/color-check-baseline.xml b/color-check-baseline.xml index 75f46e5eff9..f959f918a74 100644 --- a/color-check-baseline.xml +++ b/color-check-baseline.xml @@ -2321,6 +2321,38 @@ column="13"/> + + + + + + + + + + + + + + + + + + diff --git a/res/drawable/ic_homepage_notification.xml b/res/drawable/ic_homepage_notification.xml new file mode 100644 index 00000000000..d8c8d6dcf3c --- /dev/null +++ b/res/drawable/ic_homepage_notification.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + diff --git a/res/drawable/ic_notifications_white.xml b/res/drawable/ic_notifications_white.xml new file mode 100644 index 00000000000..1a37b56c062 --- /dev/null +++ b/res/drawable/ic_notifications_white.xml @@ -0,0 +1,19 @@ + + diff --git a/res/drawable/ic_settings_night_display_white.xml b/res/drawable/ic_settings_night_display_white.xml new file mode 100644 index 00000000000..8424b31295c --- /dev/null +++ b/res/drawable/ic_settings_night_display_white.xml @@ -0,0 +1,19 @@ + + From 72c2fa5a3d7f6913a387d78b195ad941303f46c6 Mon Sep 17 00:00:00 2001 From: Yanting Yang Date: Wed, 17 Jun 2020 23:49:09 +0800 Subject: [PATCH 2/8] Avoid NPE when screen title is null MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The screen title of Settings pages could be empty, e.g., Mobile network detail page. It will cause NPE when Settings generates the slice object, and then results in the Settings Search showing empty view for slice search result. It’s a bad user experience, we need to add the null check to avoid it. Bug: 157986273 Test: robotests Change-Id: I8bf6a081c6b3e97ccb173424ff4a310ae863ae2f --- src/com/android/settings/slices/SliceBuilderUtils.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/slices/SliceBuilderUtils.java b/src/com/android/settings/slices/SliceBuilderUtils.java index 391e9fdf741..552927e1da2 100644 --- a/src/com/android/settings/slices/SliceBuilderUtils.java +++ b/src/com/android/settings/slices/SliceBuilderUtils.java @@ -220,9 +220,11 @@ public class SliceBuilderUtils { public static Intent getContentIntent(Context context, SliceData sliceData) { final Uri contentUri = new Uri.Builder().appendPath(sliceData.getKey()).build(); + final String screenTitle = TextUtils.isEmpty(sliceData.getScreenTitle()) ? null + : sliceData.getScreenTitle().toString(); final Intent intent = buildSearchResultPageIntent(context, sliceData.getFragmentClassName(), sliceData.getKey(), - sliceData.getScreenTitle().toString(), 0 /* TODO */); + screenTitle, 0 /* TODO */); intent.setClassName(context.getPackageName(), SubSettings.class.getName()); intent.setData(contentUri); return intent; @@ -399,7 +401,8 @@ public class SliceBuilderUtils { keywords.add(data.getTitle()); - if (!TextUtils.equals(data.getTitle(), data.getScreenTitle())) { + if (!TextUtils.isEmpty(data.getScreenTitle()) + && !TextUtils.equals(data.getTitle(), data.getScreenTitle())) { keywords.add(data.getScreenTitle().toString()); } From 51fb73e512a270d0b1d4318ddaf84cd14df2a4ef Mon Sep 17 00:00:00 2001 From: Beverly Date: Wed, 17 Jun 2020 11:57:19 -0400 Subject: [PATCH 3/8] Launch work dnd setting for work-profile apps Test: manual Fixes: 159178762 Change-Id: Ifa4c7f776e19f3aec87b5ef1f858c92cff46b30b --- .../zen/ZenModeAddBypassingAppsPreferenceController.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/com/android/settings/notification/zen/ZenModeAddBypassingAppsPreferenceController.java b/src/com/android/settings/notification/zen/ZenModeAddBypassingAppsPreferenceController.java index 15a46fe1e1e..a861ab27673 100644 --- a/src/com/android/settings/notification/zen/ZenModeAddBypassingAppsPreferenceController.java +++ b/src/com/android/settings/notification/zen/ZenModeAddBypassingAppsPreferenceController.java @@ -20,6 +20,7 @@ import android.app.Application; import android.app.settings.SettingsEnums; import android.content.Context; import android.os.Bundle; +import android.os.UserHandle; import androidx.annotation.VisibleForTesting; import androidx.core.text.BidiFormatter; @@ -152,6 +153,7 @@ public class ZenModeAddBypassingAppsPreferenceController extends AbstractPrefere .setDestination(AppChannelsBypassingDndSettings.class.getName()) .setArguments(args) .setResultListener(mHostFragment, 0) + .setUserHandle(new UserHandle(UserHandle.getUserId(entry.info.uid))) .setSourceMetricsCategory( SettingsEnums.NOTIFICATION_ZEN_MODE_OVERRIDING_APP) .launch(); From 0625bb481520a8813075ab7809e59afcfc73f6b6 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Fri, 12 Jun 2020 11:59:45 +0800 Subject: [PATCH 4/8] Fix the overlapping problem of the burst of slice updates Implement a throttle in SliceBackgroundWorker to control slice updates. Test: robotest Fixes: 152366832 Change-Id: I8b65d1b57973e036b932172627aca506f4fae3a4 --- .../slices/SettingsSliceProvider.java | 6 +- .../slices/SliceBackgroundWorker.java | 79 ++++++++++++++++++- .../slices/BluetoothUpdateWorkerTest.java | 3 +- .../media/MediaDeviceUpdateWorkerTest.java | 3 +- .../media/MediaOutputIndicatorWorkerTest.java | 4 +- .../slices/ShadowSliceBackgroundWorker.java | 33 ++++++++ .../wifi/slice/WifiScanWorkerTest.java | 7 +- 7 files changed, 124 insertions(+), 11 deletions(-) create mode 100644 tests/robotests/src/com/android/settings/slices/ShadowSliceBackgroundWorker.java diff --git a/src/com/android/settings/slices/SettingsSliceProvider.java b/src/com/android/settings/slices/SettingsSliceProvider.java index 6c245ce80b4..75061a5dac5 100644 --- a/src/com/android/settings/slices/SettingsSliceProvider.java +++ b/src/com/android/settings/slices/SettingsSliceProvider.java @@ -243,7 +243,7 @@ public class SettingsSliceProvider extends SliceProvider { .createWifiCallingPreferenceSlice(sliceUri); } - SliceData cachedSliceData = mSliceWeakDataCache.get(sliceUri); + final SliceData cachedSliceData = mSliceWeakDataCache.get(sliceUri); if (cachedSliceData == null) { loadSliceInBackground(sliceUri); return getSliceStub(sliceUri); @@ -466,14 +466,14 @@ public class SettingsSliceProvider extends SliceProvider { final SliceBackgroundWorker worker = SliceBackgroundWorker.getInstance( getContext(), sliceable, uri); mPinnedWorkers.put(uri, worker); - worker.onSlicePinned(); + worker.pin(); } private void stopBackgroundWorker(Uri uri) { final SliceBackgroundWorker worker = mPinnedWorkers.get(uri); if (worker != null) { Log.d(TAG, "Stopping background worker for: " + uri); - worker.onSliceUnpinned(); + worker.unpin(); mPinnedWorkers.remove(uri); } } diff --git a/src/com/android/settings/slices/SliceBackgroundWorker.java b/src/com/android/settings/slices/SliceBackgroundWorker.java index 6bafc00f9fc..6eb154e9558 100644 --- a/src/com/android/settings/slices/SliceBackgroundWorker.java +++ b/src/com/android/settings/slices/SliceBackgroundWorker.java @@ -20,6 +20,12 @@ import android.annotation.MainThread; import android.annotation.Nullable; import android.content.Context; import android.net.Uri; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; +import android.os.Message; +import android.os.Process; +import android.os.SystemClock; import android.util.ArrayMap; import android.util.Log; @@ -47,6 +53,8 @@ public abstract class SliceBackgroundWorker implements Closeable { private static final String TAG = "SliceBackgroundWorker"; + private static final long SLICE_UPDATE_THROTTLE_INTERVAL = 300L; + private static final Map LIVE_WORKERS = new ArrayMap<>(); private final Context mContext; @@ -164,6 +172,75 @@ public abstract class SliceBackgroundWorker implements Closeable { * Notify that data was updated and attempt to sync changes to the Slice. */ protected final void notifySliceChange() { - mContext.getContentResolver().notifyChange(mUri, null); + NotifySliceChangeHandler.getInstance().updateSlice(this); } + + void pin() { + onSlicePinned(); + } + + void unpin() { + onSliceUnpinned(); + NotifySliceChangeHandler.getInstance().cancelSliceUpdate(this); + } + + private static class NotifySliceChangeHandler extends Handler { + + private static final int MSG_UPDATE_SLICE = 1000; + + private static NotifySliceChangeHandler sHandler; + + private final Map mLastUpdateTimeLookup = new ArrayMap<>(); + + private static NotifySliceChangeHandler getInstance() { + if (sHandler == null) { + final HandlerThread workerThread = new HandlerThread("NotifySliceChangeHandler", + Process.THREAD_PRIORITY_BACKGROUND); + workerThread.start(); + sHandler = new NotifySliceChangeHandler(workerThread.getLooper()); + } + return sHandler; + } + + private NotifySliceChangeHandler(Looper looper) { + super(looper); + } + + @Override + public void handleMessage(Message msg) { + if (msg.what != MSG_UPDATE_SLICE) { + return; + } + + final SliceBackgroundWorker worker = (SliceBackgroundWorker) msg.obj; + final Uri uri = worker.getUri(); + final Context context = worker.getContext(); + mLastUpdateTimeLookup.put(uri, SystemClock.uptimeMillis()); + context.getContentResolver().notifyChange(uri, null); + } + + private void updateSlice(SliceBackgroundWorker worker) { + if (hasMessages(MSG_UPDATE_SLICE, worker)) { + return; + } + + final Message message = obtainMessage(MSG_UPDATE_SLICE, worker); + final long lastUpdateTime = mLastUpdateTimeLookup.getOrDefault(worker.getUri(), 0L); + if (lastUpdateTime == 0L) { + // Postpone the first update triggering by onSlicePinned() to avoid being too close + // to the first Slice bind. + sendMessageDelayed(message, SLICE_UPDATE_THROTTLE_INTERVAL); + } else if (SystemClock.uptimeMillis() - lastUpdateTime + > SLICE_UPDATE_THROTTLE_INTERVAL) { + sendMessage(message); + } else { + sendMessageAtTime(message, lastUpdateTime + SLICE_UPDATE_THROTTLE_INTERVAL); + } + } + + private void cancelSliceUpdate(SliceBackgroundWorker worker) { + removeMessages(MSG_UPDATE_SLICE, worker); + mLastUpdateTimeLookup.remove(worker.getUri()); + } + }; } diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothUpdateWorkerTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothUpdateWorkerTest.java index 4da5c094f13..e34737b7d85 100644 --- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothUpdateWorkerTest.java +++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothUpdateWorkerTest.java @@ -25,6 +25,7 @@ import android.content.ContentResolver; import android.content.Context; import android.net.Uri; +import com.android.settings.slices.ShadowSliceBackgroundWorker; import com.android.settings.testutils.shadow.ShadowBluetoothAdapter; import org.junit.Before; @@ -35,7 +36,7 @@ import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; @RunWith(RobolectricTestRunner.class) -@Config(shadows = {ShadowBluetoothAdapter.class}) +@Config(shadows = {ShadowBluetoothAdapter.class, ShadowSliceBackgroundWorker.class}) public class BluetoothUpdateWorkerTest { private static final Uri URI = Uri.parse("content://com.android.settings.slices/test"); diff --git a/tests/robotests/src/com/android/settings/media/MediaDeviceUpdateWorkerTest.java b/tests/robotests/src/com/android/settings/media/MediaDeviceUpdateWorkerTest.java index 624bbd8101f..be86b6e3984 100644 --- a/tests/robotests/src/com/android/settings/media/MediaDeviceUpdateWorkerTest.java +++ b/tests/robotests/src/com/android/settings/media/MediaDeviceUpdateWorkerTest.java @@ -34,6 +34,7 @@ import android.media.MediaRoute2ProviderService; import android.media.RoutingSessionInfo; import android.net.Uri; +import com.android.settings.slices.ShadowSliceBackgroundWorker; import com.android.settings.testutils.shadow.ShadowAudioManager; import com.android.settings.testutils.shadow.ShadowBluetoothAdapter; import com.android.settings.testutils.shadow.ShadowBluetoothUtils; @@ -57,7 +58,7 @@ import java.util.List; @RunWith(RobolectricTestRunner.class) @Config(shadows = {ShadowAudioManager.class, ShadowBluetoothAdapter.class, - ShadowBluetoothUtils.class}) + ShadowBluetoothUtils.class, ShadowSliceBackgroundWorker.class}) public class MediaDeviceUpdateWorkerTest { private static final Uri URI = Uri.parse("content://com.android.settings.slices/test"); diff --git a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java index 0aec9529b3c..423c7acf098 100644 --- a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java +++ b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java @@ -39,6 +39,7 @@ import android.media.session.MediaSessionManager; import android.media.session.PlaybackState; import android.net.Uri; +import com.android.settings.slices.ShadowSliceBackgroundWorker; import com.android.settings.testutils.shadow.ShadowBluetoothAdapter; import com.android.settings.testutils.shadow.ShadowBluetoothUtils; import com.android.settingslib.bluetooth.BluetoothEventManager; @@ -59,7 +60,8 @@ import java.util.ArrayList; import java.util.List; @RunWith(RobolectricTestRunner.class) -@Config(shadows = {ShadowBluetoothAdapter.class, ShadowBluetoothUtils.class}) +@Config(shadows = {ShadowBluetoothAdapter.class, ShadowBluetoothUtils.class, + ShadowSliceBackgroundWorker.class}) public class MediaOutputIndicatorWorkerTest { private static final Uri URI = Uri.parse("content://com.android.settings.slices/test"); private static final String TEST_PACKAGE_NAME = "com.android.test"; diff --git a/tests/robotests/src/com/android/settings/slices/ShadowSliceBackgroundWorker.java b/tests/robotests/src/com/android/settings/slices/ShadowSliceBackgroundWorker.java new file mode 100644 index 00000000000..7bf8358a850 --- /dev/null +++ b/tests/robotests/src/com/android/settings/slices/ShadowSliceBackgroundWorker.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2020 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.slices; + +import org.robolectric.annotation.Implementation; +import org.robolectric.annotation.Implements; +import org.robolectric.annotation.RealObject; + +@Implements(SliceBackgroundWorker.class) +public class ShadowSliceBackgroundWorker { + + @RealObject + private SliceBackgroundWorker mRealWorker; + + @Implementation + protected final void notifySliceChange() { + mRealWorker.getContext().getContentResolver().notifyChange(mRealWorker.getUri(), null); + } +} diff --git a/tests/robotests/src/com/android/settings/wifi/slice/WifiScanWorkerTest.java b/tests/robotests/src/com/android/settings/wifi/slice/WifiScanWorkerTest.java index d40331c3332..33195438fe0 100644 --- a/tests/robotests/src/com/android/settings/wifi/slice/WifiScanWorkerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/slice/WifiScanWorkerTest.java @@ -43,6 +43,7 @@ import android.net.wifi.WifiManager; import android.os.Bundle; import android.os.UserHandle; +import com.android.settings.slices.ShadowSliceBackgroundWorker; import com.android.settings.testutils.shadow.ShadowWifiManager; import com.android.settingslib.wifi.AccessPoint; import com.android.settingslib.wifi.WifiTracker; @@ -63,10 +64,8 @@ import java.util.Arrays; import java.util.List; @RunWith(RobolectricTestRunner.class) -@Config(shadows = { - ShadowWifiManager.class, - WifiScanWorkerTest.ShadowWifiTracker.class, -}) +@Config(shadows = {ShadowSliceBackgroundWorker.class, ShadowWifiManager.class, + WifiScanWorkerTest.ShadowWifiTracker.class}) public class WifiScanWorkerTest { private Context mContext; From 22ed240aab5df0d1b7daadef77f38067e0e7b45e Mon Sep 17 00:00:00 2001 From: Peter_Liang Date: Tue, 16 Jun 2020 17:28:20 +0800 Subject: [PATCH 5/8] Fix the dark theme obscures the center marker of audio balance slider. Root Cause: The color of center marker is wrong. Next: The color of center marker is white when dark theme is enabled; Otherwise, it's black. Bug: 159028208 Test: manual test & make RunSettingsRoboTests ROBOTEST_FILTER=BalanceSeekBarPreferenceTest & make RunSettingsRoboTests ROBOTEST_FILTER=BalanceSeekBarTest Change-Id: Id2d548778d1275709448f4c009a8469216950d8c Merged-In: Id2d548778d1275709448f4c009a8469216950d8c (cherry picked from commit 34a873884dfa5e213d7096e52dc16929581f191b) --- src/com/android/settings/accessibility/BalanceSeekBar.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/accessibility/BalanceSeekBar.java b/src/com/android/settings/accessibility/BalanceSeekBar.java index b108e18d2f0..ecc226bd67d 100644 --- a/src/com/android/settings/accessibility/BalanceSeekBar.java +++ b/src/com/android/settings/accessibility/BalanceSeekBar.java @@ -16,6 +16,8 @@ package com.android.settings.accessibility; +import static com.android.settings.Utils.isNightMode; + import android.content.Context; import android.content.res.ColorStateList; import android.content.res.Resources; @@ -113,8 +115,7 @@ public class BalanceSeekBar extends SeekBar { res.getDimensionPixelSize(R.dimen.balance_seekbar_center_marker_width), res.getDimensionPixelSize(R.dimen.balance_seekbar_center_marker_height)); mCenterMarkerPaint = new Paint(); - // TODO use a more suitable colour? - mCenterMarkerPaint.setColor(Color.BLACK); + mCenterMarkerPaint.setColor(isNightMode(context) ? Color.WHITE : Color.BLACK); mCenterMarkerPaint.setStyle(Paint.Style.FILL); // Remove the progress colour setProgressTintList(ColorStateList.valueOf(Color.TRANSPARENT)); From 03a42fd844c27501d75d822f5063d78a1dc4985d Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Thu, 18 Jun 2020 16:25:38 -0400 Subject: [PATCH 6/8] Update notification subtext Test: atest Fixes: 159274325 Change-Id: Iff98b4b056bf7a3c6386063d6588a26607ee7525 --- res/values/strings.xml | 3 + res/xml/app_and_notification.xml | 4 +- ...igureNotificationPreferenceController.java | 48 --------------- ...eNotificationPreferenceControllerTest.java | 59 ------------------- 4 files changed, 5 insertions(+), 109 deletions(-) delete mode 100644 src/com/android/settings/notification/ConfigureNotificationPreferenceController.java delete mode 100644 tests/robotests/src/com/android/settings/notification/ConfigureNotificationPreferenceControllerTest.java diff --git a/res/values/strings.xml b/res/values/strings.xml index 847335750f8..1b653594aac 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -8806,6 +8806,9 @@ Additional settings in the app + + Notification history, bubbles, recently sent + On for all apps diff --git a/res/xml/app_and_notification.xml b/res/xml/app_and_notification.xml index 98b98442b21..bd2e85ce127 100644 --- a/res/xml/app_and_notification.xml +++ b/res/xml/app_and_notification.xml @@ -57,9 +57,9 @@ + android:fragment="com.android.settings.notification.ConfigureNotificationSettings"/> Date: Fri, 19 Jun 2020 11:15:07 +0800 Subject: [PATCH 7/8] Remove the feature flag of contextual home V2 Bug: 159393461 Test: robotest & rebuild Change-Id: If5f030b4c8bd5ef61bb722da9ae7f3ace0ac6e0e --- .../android/settings/core/FeatureFlags.java | 1 - .../ContextualCardManager.java | 26 +----- .../ContextualCardManagerTest.java | 84 ------------------- 3 files changed, 1 insertion(+), 110 deletions(-) diff --git a/src/com/android/settings/core/FeatureFlags.java b/src/com/android/settings/core/FeatureFlags.java index 331e5728bb1..d2ad30d7bad 100644 --- a/src/com/android/settings/core/FeatureFlags.java +++ b/src/com/android/settings/core/FeatureFlags.java @@ -29,5 +29,4 @@ public class FeatureFlags { public static final String CONTROLLER_ENHANCEMENT = "settings_controller_loading_enhancement"; public static final String CONDITIONAL_CARDS = "settings_conditionals"; public static final String TETHER_ALL_IN_ONE = "settings_tether_all_in_one"; - public static final String CONTEXTUAL_HOME2 = "settings_contextual_home2"; } diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java b/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java index fc666ec7319..ac35017baab 100644 --- a/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java +++ b/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java @@ -19,14 +19,11 @@ package com.android.settings.homepage.contextualcards; import static com.android.settings.homepage.contextualcards.ContextualCardLoader.CARD_CONTENT_LOADER_ID; import static com.android.settings.intelligence.ContextualCardProto.ContextualCard.Category.STICKY_VALUE; import static com.android.settings.intelligence.ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE; -import static com.android.settings.slices.CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI; -import static com.android.settings.slices.CustomSliceRegistry.CONTEXTUAL_WIFI_SLICE_URI; import static java.util.stream.Collectors.groupingBy; import android.app.settings.SettingsEnums; import android.content.Context; -import android.net.Uri; import android.os.Bundle; import android.provider.Settings; import android.text.format.DateUtils; @@ -55,7 +52,6 @@ import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStop; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Set; @@ -85,8 +81,6 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo static final String KEY_CONTEXTUAL_CARDS = "key_contextual_cards"; private static final String TAG = "ContextualCardManager"; - private static final List STICKY_CARDS = - Arrays.asList(CONTEXTUAL_WIFI_SLICE_URI, BLUETOOTH_DEVICES_SLICE_URI); private final Context mContext; private final Lifecycle mLifecycle; @@ -364,29 +358,11 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo private List getCardsWithStickyViewType(List cards) { final List result = new ArrayList<>(cards); - int replaceCount = 0; for (int index = 0; index < result.size(); index++) { final ContextualCard card = cards.get(index); - if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.CONTEXTUAL_HOME2)) { - if (card.getCategory() == STICKY_VALUE) { - result.set(index, card.mutate().setViewType( - SliceContextualCardRenderer.VIEW_TYPE_STICKY).build()); - } - continue; - } - - if (replaceCount > STICKY_CARDS.size() - 1) { - break; - } - - if (card.getCardType() != ContextualCard.CardType.SLICE) { - continue; - } - - if (STICKY_CARDS.contains(card.getSliceUri())) { + if (card.getCategory() == STICKY_VALUE) { result.set(index, card.mutate().setViewType( SliceContextualCardRenderer.VIEW_TYPE_STICKY).build()); - replaceCount++; } } return result; diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java index 127b9e29466..69333d7ad9d 100644 --- a/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java +++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java @@ -610,7 +610,6 @@ public class ContextualCardManagerTest { @Test public void getCardsWithViewType_hasOneStickySlice_shouldHaveOneStickyCard() { - FeatureFlagUtils.setEnabled(mContext, FeatureFlags.CONTEXTUAL_HOME2, true); final List cards = new ArrayList<>(); cards.add(buildContextualCard(CustomSliceRegistry.CONTEXTUAL_WIFI_SLICE_URI.toString())); cards.add(buildContextualCard(CustomSliceRegistry.LOW_STORAGE_SLICE_URI.toString())); @@ -627,89 +626,6 @@ public class ContextualCardManagerTest { assertThat(result.get(1).getViewType()).isEqualTo(VIEW_TYPE_FULL_WIDTH); } - @Test - public void getCardsWithViewType_hasWifiSlice_shouldHaveOneStickyCard() { - FeatureFlagUtils.setEnabled(mContext, FeatureFlags.CONTEXTUAL_HOME2, false); - final List cards = new ArrayList<>(); - cards.add(buildContextualCard(CustomSliceRegistry.CONTEXTUAL_WIFI_SLICE_URI.toString())); - cards.add(buildContextualCard(CustomSliceRegistry.LOW_STORAGE_SLICE_URI.toString())); - final List categories = Arrays.asList( - ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE, - ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE - ); - final List cardListWithWifi = buildCategoriedCards(cards, categories); - - final List result = mManager.getCardsWithViewType(cardListWithWifi); - - assertThat(result).hasSize(cards.size()); - assertThat(result.get(0).getViewType()).isEqualTo(VIEW_TYPE_STICKY); - assertThat(result.get(1).getViewType()).isEqualTo(VIEW_TYPE_FULL_WIDTH); - } - - @Test - public void getCardsWithViewType_hasBluetoothDeviceSlice_shouldHaveOneStickyCard() { - FeatureFlagUtils.setEnabled(mContext, FeatureFlags.CONTEXTUAL_HOME2, false); - final List cards = new ArrayList<>(); - cards.add(buildContextualCard(CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI.toString())); - cards.add(buildContextualCard(CustomSliceRegistry.LOW_STORAGE_SLICE_URI.toString())); - final List categories = Arrays.asList( - ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE, - ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE - ); - final List cardListWithBT = buildCategoriedCards(cards, categories); - - final List result = mManager.getCardsWithViewType(cardListWithBT); - - assertThat(result).hasSize(cards.size()); - assertThat(result.get(0).getViewType()).isEqualTo(VIEW_TYPE_STICKY); - assertThat(result.get(1).getViewType()).isEqualTo(VIEW_TYPE_FULL_WIDTH); - } - - @Test - public void getCardsWithViewType_hasWifiAndBtDeviceSlice_shouldHaveTwoStickyCards() { - FeatureFlagUtils.setEnabled(mContext, FeatureFlags.CONTEXTUAL_HOME2, false); - final List cards = new ArrayList<>(); - cards.add(buildContextualCard(CustomSliceRegistry.CONTEXTUAL_WIFI_SLICE_URI.toString())); - cards.add(buildContextualCard(CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI.toString())); - cards.add(buildContextualCard(CustomSliceRegistry.LOW_STORAGE_SLICE_URI.toString())); - final List categories = Arrays.asList( - ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE, - ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE, - ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE - ); - final List cardListWithWifiBT = buildCategoriedCards(cards, categories); - - final List result = mManager.getCardsWithViewType(cardListWithWifiBT); - - assertThat(result).hasSize(cards.size()); - assertThat(result.stream() - .filter(card -> card.getViewType() == VIEW_TYPE_STICKY) - .count()) - .isEqualTo(2); - } - - @Test - public void getCardsWithViewType_noWifiOrBtDeviceSlice_shouldNotHaveStickyCard() { - FeatureFlagUtils.setEnabled(mContext, FeatureFlags.CONTEXTUAL_HOME2, false); - final List categories = Arrays.asList( - ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE, - ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE, - ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE, - ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE, - ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE - ); - final List cardListWithoutWifiBT = - buildCategoriedCards(getContextualCardList(), categories); - - final List result = mManager.getCardsWithViewType(cardListWithoutWifiBT); - - assertThat(result).hasSize(cardListWithoutWifiBT.size()); - assertThat(result.stream() - .filter(card -> card.getViewType() == VIEW_TYPE_STICKY) - .count()) - .isEqualTo(0); - } - @Test public void getCardsToKeep_hasSavedCard_shouldResetSavedCards() { final List savedCardNames = new ArrayList<>(); From efb029c06749bf419f9f3f719d65cac1d8be5a8e Mon Sep 17 00:00:00 2001 From: markchien Date: Fri, 19 Jun 2020 08:31:59 +0800 Subject: [PATCH 8/8] Remove unused resource from TetherServiceTest TetherService is no longer query resource by itself after ag/11524847. That CL miss to remove unused getResources code. Now remove unused resource in this change. Bug: 146918263 Test: atest TetherServiceTest Change-Id: I3b0da2672246997aee16b11576ce5ae9bfe596dc --- .../wifi/tether/TetherServiceTest.java | 33 ------------------- 1 file changed, 33 deletions(-) diff --git a/tests/unit/src/com/android/settings/wifi/tether/TetherServiceTest.java b/tests/unit/src/com/android/settings/wifi/tether/TetherServiceTest.java index be030bf7dac..9d9cc340a8b 100644 --- a/tests/unit/src/com/android/settings/wifi/tether/TetherServiceTest.java +++ b/tests/unit/src/com/android/settings/wifi/tether/TetherServiceTest.java @@ -50,7 +50,6 @@ import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; -import android.content.res.Resources; import android.net.TetheringManager; import android.net.wifi.WifiManager; import android.os.Bundle; @@ -78,13 +77,11 @@ public class TetherServiceTest extends ServiceTestCase { private static final String TEST_RESPONSE_ACTION = "testProvisioningResponseAction"; private static final String TEST_NO_UI_ACTION = "testNoUiProvisioningRequestAction"; private static final int BOGUS_RECEIVER_RESULT = -5; - private static final int TEST_CHECK_PERIOD = 100; private static final int MS_PER_HOUR = 60 * 60 * 1000; private static final int SHORT_TIMEOUT = 100; private static final int PROVISION_TIMEOUT = 1000; private TetherService mService; - private MockResources mResources; private MockTetherServiceWrapper mWrapper; int mLastReceiverResultCode = BOGUS_RECEIVER_RESULT; private int mLastTetherRequestType = TETHERING_INVALID; @@ -109,7 +106,6 @@ public class TetherServiceTest extends ServiceTestCase { super.setUp(); MockitoAnnotations.initMocks(this); - mResources = new MockResources(); mContext = new TestContextWrapper(getContext()); setContext(mContext); @@ -302,41 +298,12 @@ public class TetherServiceTest extends ServiceTestCase { } } - private static class MockResources extends android.test.mock.MockResources { - @Override - public int getInteger(int id) { - switch(id) { - case com.android.internal.R.integer.config_mobile_hotspot_provision_check_period: - return TEST_CHECK_PERIOD; - default: - return 0; - } - } - - @Override - public String getString(int id) { - switch(id) { - case com.android.internal.R.string.config_mobile_hotspot_provision_response: - return TEST_RESPONSE_ACTION; - case com.android.internal.R.string.config_mobile_hotspot_provision_app_no_ui: - return TEST_NO_UI_ACTION; - default: - return null; - } - } - } - private class TestContextWrapper extends ContextWrapper { public TestContextWrapper(Context base) { super(base); } - @Override - public Resources getResources() { - return mResources; - } - @Override public SharedPreferences getSharedPreferences(String name, int mode) { // Stub out prefs to control the persisted tether type list.