From f952e89d4bf09343c377aa51fe23281ff82a1069 Mon Sep 17 00:00:00 2001 From: Simon Wingrove Date: Mon, 18 Jul 2022 11:54:22 +0000 Subject: [PATCH 1/4] Bool to note Pending Intent bug fixed A workaround can be used to cover for the fact that PendingIntents sent by Settings might differ only by Intent extras (and thus be wrong). This bool notes that the issue is fixed so the workaround code can be dropped. Bug: 238605613 Test: manually Merged-In: I478dd5fbd53d1dafd049e392a186d9796dd179cb Change-Id: Ife355166df080ce7371a95b5cea28575227153f0 --- color-check-baseline.xml | 80 ++++++++++++++++++++++++++++------------ res/values/bools.xml | 23 ++++++++++++ 2 files changed, 79 insertions(+), 24 deletions(-) create mode 100644 res/values/bools.xml diff --git a/color-check-baseline.xml b/color-check-baseline.xml index edd2d59be96..b4915b937bd 100644 --- a/color-check-baseline.xml +++ b/color-check-baseline.xml @@ -4397,22 +4397,6 @@ column="9"/> - - - - @@ -4441,7 +4425,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~"> @@ -4457,7 +4441,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~"> @@ -4473,10 +4457,26 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~"> + + + + @@ -4749,6 +4749,38 @@ column="40"/> + + + + + + + + @@ -4777,7 +4809,7 @@ errorLine2=" ^"> @@ -4793,7 +4825,7 @@ errorLine2=" ^"> diff --git a/res/values/bools.xml b/res/values/bools.xml new file mode 100644 index 00000000000..25c3e0d0957 --- /dev/null +++ b/res/values/bools.xml @@ -0,0 +1,23 @@ + + + + + true + From 8b1e21f92998c85e728a502fe52be23a7e3696ee Mon Sep 17 00:00:00 2001 From: Weng Su Date: Tue, 26 Jul 2022 01:48:16 +0800 Subject: [PATCH 2/4] Restrict WifiScanModeActivity for guest user - Don't show WifiScanModeActivity if the user is a guest. Bug: 235601169 Test: manual test make RunSettingsRoboTests ROBOTEST_FILTER=WifiScanModeActivityTest Change-Id: I8f1d162d9b15116c3deb3656b9af6851d4514947 --- .../settings/wifi/WifiScanModeActivity.java | 22 ++++++++++++- .../wifi/WifiScanModeActivityTest.java | 33 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/wifi/WifiScanModeActivity.java b/src/com/android/settings/wifi/WifiScanModeActivity.java index d37213522aa..c10ee27fddb 100644 --- a/src/com/android/settings/wifi/WifiScanModeActivity.java +++ b/src/com/android/settings/wifi/WifiScanModeActivity.java @@ -18,11 +18,15 @@ package com.android.settings.wifi; import android.app.Dialog; import android.app.settings.SettingsEnums; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.net.wifi.WifiManager; import android.os.Bundle; +import android.os.UserManager; import android.text.TextUtils; +import android.util.EventLog; +import android.util.Log; import android.view.WindowManager; import androidx.annotation.VisibleForTesting; @@ -39,6 +43,7 @@ import com.android.settingslib.wifi.WifiPermissionChecker; * This activity requests users permission to allow scanning even when Wi-Fi is turned off */ public class WifiScanModeActivity extends FragmentActivity { + private static final String TAG = "WifiScanModeActivity"; private DialogFragment mDialog; @VisibleForTesting String mApp; @@ -78,7 +83,15 @@ public class WifiScanModeActivity extends FragmentActivity { mApp = Utils.getApplicationLabel(getApplicationContext(), packageName).toString(); } - private void createDialog() { + @VisibleForTesting + void createDialog() { + if (isGuestUser(getApplicationContext())) { + Log.e(TAG, "Guest user is not allowed to configure Wi-Fi Scan Mode!"); + EventLog.writeEvent(0x534e4554, "235601169", -1 /* UID */, "User is a guest"); + finish(); + return; + } + if (mDialog == null) { mDialog = AlertDialogFragment.newInstance(mApp); mDialog.show(getSupportFragmentManager(), "dialog"); @@ -169,4 +182,11 @@ public class WifiScanModeActivity extends FragmentActivity { ((WifiScanModeActivity) getActivity()).doNegativeClick(); } } + + private static boolean isGuestUser(Context context) { + if (context == null) return false; + final UserManager userManager = context.getSystemService(UserManager.class); + if (userManager == null) return false; + return userManager.isGuestUser(); + } } diff --git a/tests/robotests/src/com/android/settings/wifi/WifiScanModeActivityTest.java b/tests/robotests/src/com/android/settings/wifi/WifiScanModeActivityTest.java index 1e3afdbf32f..5937997ac17 100644 --- a/tests/robotests/src/com/android/settings/wifi/WifiScanModeActivityTest.java +++ b/tests/robotests/src/com/android/settings/wifi/WifiScanModeActivityTest.java @@ -18,11 +18,17 @@ package com.android.settings.wifi; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import android.content.Context; +import android.os.UserManager; import android.text.TextUtils; +import androidx.test.core.app.ApplicationProvider; + import com.android.settings.testutils.shadow.ShadowUtils; import com.android.settingslib.wifi.WifiPermissionChecker; @@ -32,6 +38,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.Spy; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.robolectric.Robolectric; @@ -47,6 +54,10 @@ public class WifiScanModeActivityTest { @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule(); + @Spy + Context mContext = ApplicationProvider.getApplicationContext(); + @Mock + UserManager mUserManager; @Mock WifiPermissionChecker mWifiPermissionChecker; @@ -54,7 +65,11 @@ public class WifiScanModeActivityTest { @Before public void setUp() { + when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager); + when(mUserManager.isGuestUser()).thenReturn(false); + mActivity = spy(Robolectric.setupActivity(WifiScanModeActivity.class)); + when(mActivity.getApplicationContext()).thenReturn(mContext); mActivity.mWifiPermissionChecker = mWifiPermissionChecker; } @@ -87,4 +102,22 @@ public class WifiScanModeActivityTest { assertThat(mActivity.mApp).isEqualTo(APP_LABEL); } + + @Test + public void createDialog_isNotGuestUser_shouldNotFinishDialog() { + when(mUserManager.isGuestUser()).thenReturn(false); + + mActivity.createDialog(); + + verify(mActivity, never()).finish(); + } + + @Test + public void createDialog_isGuestUser_shouldFinishDialog() { + when(mUserManager.isGuestUser()).thenReturn(true); + + mActivity.createDialog(); + + verify(mActivity).finish(); + } } From e4dc6c972f462564538cd72979a518b4f52f55a7 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Mon, 25 Jul 2022 10:58:04 -0400 Subject: [PATCH 3/4] Only show the channel toast if users expressly ask for it Test: NotificationChannelWarningsPreferenceControllerTest.java Bug: 231150048 Change-Id: I4797a2184561ae3dcd03e62bfb78a90686458c6b --- ...icationChannelWarningsPreferenceController.java | 7 +------ ...ionChannelWarningsPreferenceControllerTest.java | 14 +------------- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/src/com/android/settings/development/NotificationChannelWarningsPreferenceController.java b/src/com/android/settings/development/NotificationChannelWarningsPreferenceController.java index 775b70871f2..22b3f8360c4 100644 --- a/src/com/android/settings/development/NotificationChannelWarningsPreferenceController.java +++ b/src/com/android/settings/development/NotificationChannelWarningsPreferenceController.java @@ -38,10 +38,6 @@ public class NotificationChannelWarningsPreferenceController extends final static int SETTING_VALUE_ON = 1; @VisibleForTesting final static int SETTING_VALUE_OFF = 0; - @VisibleForTesting - final static int DEBUGGING_ENABLED = 1; - @VisibleForTesting - final static int DEBUGGING_DISABLED = 0; public NotificationChannelWarningsPreferenceController(Context context) { super(context); @@ -64,9 +60,8 @@ public class NotificationChannelWarningsPreferenceController extends @Override public void updateState(Preference preference) { - final int defaultWarningEnabled = isDebuggable() ? DEBUGGING_ENABLED : DEBUGGING_DISABLED; final int mode = Settings.Global.getInt(mContext.getContentResolver(), - Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS, defaultWarningEnabled); + Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS, 0); ((SwitchPreference) mPreference).setChecked(mode != SETTING_VALUE_OFF); } diff --git a/tests/robotests/src/com/android/settings/development/NotificationChannelWarningsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/NotificationChannelWarningsPreferenceControllerTest.java index 7d08c66bb6c..1887247d44f 100644 --- a/tests/robotests/src/com/android/settings/development/NotificationChannelWarningsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/NotificationChannelWarningsPreferenceControllerTest.java @@ -102,7 +102,7 @@ public class NotificationChannelWarningsPreferenceControllerTest { } @Test - public void updateState_settingUndefinedDebuggingEnabled_preferenceShouldBeChecked() { + public void updateState_settingUndefinedDebuggingEnabled_preferenceShouldNotBeChecked() { mController = spy(mController); doReturn(true).when(mController).isDebuggable(); Settings.Global.putString(mContext.getContentResolver(), @@ -110,18 +110,6 @@ public class NotificationChannelWarningsPreferenceControllerTest { mController.updateState(mPreference); - verify(mPreference).setChecked(true); - } - - @Test - public void updateState_settingUndefinedDebuggingDisabled_preferenceShouldNotBeChecked() { - mController = spy(mController); - doReturn(false).when(mController).isDebuggable(); - Settings.Global.putString(mContext.getContentResolver(), - Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS, "NotAnInteger"); - - mController.updateState(mPreference); - verify(mPreference).setChecked(false); } From 0f7b80f47f230d43809445c35149172dd80ff645 Mon Sep 17 00:00:00 2001 From: Tsung-Mao Fang Date: Mon, 25 Jul 2022 15:06:34 +0800 Subject: [PATCH 4/4] Set an action name for wallpaer index Since Android T+, app has to assign an action name for opening a external app page. Test: Manual test wallpaper search result and can open. Fix: 239867167 Change-Id: I4579aaf6e831ff82721c958e6b91ede4cabda2c8 --- res/values/config.xml | 4 ++++ .../settings/display/WallpaperPreferenceController.java | 9 +++++++++ .../settings/wallpaper/WallpaperSuggestionActivity.java | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/res/values/config.xml b/res/values/config.xml index c7ef595e3ae..078c7591771 100755 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -49,6 +49,10 @@ com.android.settings.Settings$WallpaperSettingsActivity + + + + com.android.wallpaper.LAUNCH_SOURCE diff --git a/src/com/android/settings/display/WallpaperPreferenceController.java b/src/com/android/settings/display/WallpaperPreferenceController.java index 00687b2aaba..9972bf9cabe 100644 --- a/src/com/android/settings/display/WallpaperPreferenceController.java +++ b/src/com/android/settings/display/WallpaperPreferenceController.java @@ -41,6 +41,8 @@ public class WallpaperPreferenceController extends BasePreferenceController { private final String mWallpaperPackage; private final String mWallpaperClass; private final String mStylesAndWallpaperClass; + private final String mWallpaperActionName; + private final String mStylesAndWallpaperActionName; private final String mWallpaperLaunchExtra; public WallpaperPreferenceController(Context context, String key) { @@ -49,6 +51,9 @@ public class WallpaperPreferenceController extends BasePreferenceController { mWallpaperClass = mContext.getString(R.string.config_wallpaper_picker_class); mStylesAndWallpaperClass = mContext.getString(R.string.config_styles_and_wallpaper_picker_class); + mWallpaperActionName = mContext.getString(R.string.config_wallpaper_picker_action); + mStylesAndWallpaperActionName = + mContext.getString(R.string.config_styles_and_wallpaper_picker_action); mWallpaperLaunchExtra = mContext.getString(R.string.config_wallpaper_picker_launch_extra); } @@ -72,6 +77,10 @@ public class WallpaperPreferenceController extends BasePreferenceController { return areStylesAvailable() ? mStylesAndWallpaperClass : mWallpaperClass; } + public String getComponentActionName() { + return areStylesAvailable() ? mStylesAndWallpaperActionName : mWallpaperActionName; + } + public String getKeywords() { StringBuilder sb = new StringBuilder(mContext.getString(R.string.keywords_wallpaper)); if (areStylesAvailable()) { diff --git a/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java b/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java index c2b3fa09a89..675e10fc2a0 100644 --- a/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java +++ b/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java @@ -84,7 +84,7 @@ public class WallpaperSuggestionActivity extends StyleSuggestionActivityBase imp ComponentName component = controller.getComponentName(); data.intentTargetPackage = component.getPackageName(); data.intentTargetClass = component.getClassName(); - data.intentAction = Intent.ACTION_MAIN; + data.intentAction = controller.getComponentActionName(); data.key = SUPPORT_SEARCH_INDEX_KEY; data.keywords = controller.getKeywords(); result.add(data);