From 7e1a9138c3cdfd0ef68429e20f74200cfd49c62c Mon Sep 17 00:00:00 2001 From: Manish Singh Date: Fri, 12 Jan 2024 13:14:32 +0000 Subject: [PATCH 1/6] Don't surface BiometricsSafetySource for private profile The biometric lock for pirvate profile is handled separately. Bug: 286539356 Test: manual Change-Id: Iec0a98a40f0ff0c303f450a340720782a4e37f00 --- .../settings/safetycenter/BiometricsSafetySource.java | 10 ++++++++++ .../safetycenter/SafetyCenterManagerWrapper.java | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/safetycenter/BiometricsSafetySource.java b/src/com/android/settings/safetycenter/BiometricsSafetySource.java index 94db71f143e..8e1c78644d9 100644 --- a/src/com/android/settings/safetycenter/BiometricsSafetySource.java +++ b/src/com/android/settings/safetycenter/BiometricsSafetySource.java @@ -62,6 +62,16 @@ public final class BiometricsSafetySource { } final Context profileParentContext = context.createContextAsUser(profileParentUserHandle, 0); + if (android.os.Flags.allowPrivateProfile() && userManager.isPrivateProfile()) { + // SC always expects a response from the source if the broadcast has been sent for this + // source, therefore, we need to send a null SafetySourceData. + SafetyCenterManagerWrapper.get().setSafetySourceData( + context, + SAFETY_SOURCE_ID, + /* safetySourceData= */ null, + safetyEvent); + return; + } final BiometricNavigationUtils biometricNavigationUtils = new BiometricNavigationUtils(userId); diff --git a/src/com/android/settings/safetycenter/SafetyCenterManagerWrapper.java b/src/com/android/settings/safetycenter/SafetyCenterManagerWrapper.java index e7205260833..55eb4f14dc1 100644 --- a/src/com/android/settings/safetycenter/SafetyCenterManagerWrapper.java +++ b/src/com/android/settings/safetycenter/SafetyCenterManagerWrapper.java @@ -22,6 +22,8 @@ import android.safetycenter.SafetyEvent; import android.safetycenter.SafetySourceData; import android.util.Log; +import androidx.annotation.Nullable; + import com.android.internal.annotations.VisibleForTesting; /** A wrapper for the SafetyCenterManager system service. */ @@ -49,7 +51,7 @@ public class SafetyCenterManagerWrapper { /** Sets the latest safety source data for Safety Center. */ public void setSafetySourceData(Context context, String safetySourceId, - SafetySourceData safetySourceData, + @Nullable SafetySourceData safetySourceData, SafetyEvent safetyEvent) { SafetyCenterManager safetyCenterManager = context.getSystemService(SafetyCenterManager.class); From e221abaa48898e69701f3a504df5f88dc92a25d3 Mon Sep 17 00:00:00 2001 From: Arnab Sen Date: Thu, 7 Dec 2023 13:44:52 +0530 Subject: [PATCH 2/6] Stylus: Introduce Show Stylus Hover Pointer Setting (2/2) Currently, the stylus hover icon can only be shown when config_enableStylusPointerIcon is set to true. This means that the users do not have a choice of turning the feature on or off. This CL introduces the capability to do the same. This CL adds the toggle in the StylusDevicesController to be shown when stylus is connected. The toggle is mapped to the STYLUS_POINTER_ENABLED secure setting which InputManagerService listens to turn on and off the stylus pointer icon. Test: manual Steps: 1. Change the value of config_enableStylusPointerIcon as true. 2. Build the images and flash it to a stylus supporting device. 3. After the device is booted, hover over the screen, the stylus pointer should appear. 4. Go to Settings > Connected Devices > Stylus and tap on "Show pointer while hovering" toggle. 5. Try hovering over the screen, check no pointer icon is shown 6. Repeat Step#4, check that stylus pointer appears. Run - make RunSettingsRoboTests \ ROBOTEST_FILTER=StylusDevicesControllerTest - atest SettingsProviderTest Change-Id: Idfff9b4307370cc510a5f94bd57777c30c96e854 --- res/values/strings.xml | 3 ++ .../stylus/StylusDevicesController.java | 35 ++++++++++++++ .../stylus/StylusDevicesControllerTest.java | 48 ++++++++++++++++++- 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 7291fad3a93..c5d000bde9a 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -12882,4 +12882,7 @@ + + + Show pointer while hovering diff --git a/src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java b/src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java index d8e88877ead..cd23103c5e4 100644 --- a/src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java +++ b/src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java @@ -24,6 +24,7 @@ import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.UserInfo; +import android.hardware.input.InputSettings; import android.os.Process; import android.os.UserHandle; import android.os.UserManager; @@ -73,6 +74,8 @@ public class StylusDevicesController extends AbstractPreferenceController implem static final String KEY_IGNORE_BUTTON = "ignore_button"; @VisibleForTesting static final String KEY_DEFAULT_NOTES = "default_notes"; + @VisibleForTesting + static final String KEY_SHOW_STYLUS_POINTER_ICON = "show_stylus_pointer_icon"; private static final String TAG = "StylusDevicesController"; @@ -181,6 +184,26 @@ public class StylusDevicesController extends AbstractPreferenceController implem return pref; } + @Nullable + private SwitchPreferenceCompat createShowStylusPointerIconPreference( + SwitchPreferenceCompat preference) { + if (!mContext.getResources() + .getBoolean(com.android.internal.R.bool.config_enableStylusPointerIcon)) { + // If the config is not enabled, no need to show the preference to user + return null; + } + SwitchPreferenceCompat pref = preference == null ? new SwitchPreferenceCompat(mContext) + : preference; + pref.setKey(KEY_SHOW_STYLUS_POINTER_ICON); + pref.setTitle(mContext.getString(R.string.show_stylus_pointer_icon)); + pref.setIcon(R.drawable.ic_stylus); + pref.setOnPreferenceClickListener(this); + pref.setChecked(Settings.Secure.getInt(mContext.getContentResolver(), + Settings.Secure.STYLUS_POINTER_ICON_ENABLED, + InputSettings.DEFAULT_STYLUS_POINTER_ICON_ENABLED) == 1); + return pref; + } + @Override public boolean onPreferenceClick(Preference preference) { String key = preference.getKey(); @@ -213,6 +236,11 @@ public class StylusDevicesController extends AbstractPreferenceController implem Secure.STYLUS_BUTTONS_ENABLED, ((TwoStatePreference) preference).isChecked() ? 0 : 1); break; + case KEY_SHOW_STYLUS_POINTER_ICON: + Settings.Secure.putInt(mContext.getContentResolver(), + Secure.STYLUS_POINTER_ICON_ENABLED, + ((SwitchPreferenceCompat) preference).isChecked() ? 1 : 0); + break; } return true; } @@ -268,6 +296,13 @@ public class StylusDevicesController extends AbstractPreferenceController implem if (buttonPref == null) { mPreferencesContainer.addPreference(createButtonPressPreference()); } + SwitchPreferenceCompat currShowStylusPointerIconPref = mPreferencesContainer + .findPreference(KEY_SHOW_STYLUS_POINTER_ICON); + Preference showStylusPointerIconPref = + createShowStylusPointerIconPreference(currShowStylusPointerIconPref); + if (currShowStylusPointerIconPref == null && showStylusPointerIconPref != null) { + mPreferencesContainer.addPreference(showStylusPointerIconPref); + } } private boolean currentInputMethodSupportsHandwriting() { diff --git a/tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java index a540d286203..135be4bc055 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java @@ -221,7 +221,7 @@ public class StylusDevicesControllerTest { showScreen(controller); - assertThat(mPreferenceContainer.getPreferenceCount()).isEqualTo(3); + assertThat(mPreferenceContainer.getPreferenceCount()).isEqualTo(4); } @Test @@ -249,11 +249,12 @@ public class StylusDevicesControllerTest { @Test public void btStylusInputDevice_showsAllPreferences() { showScreen(mController); + Preference defaultNotesPref = mPreferenceContainer.getPreference(0); Preference handwritingPref = mPreferenceContainer.getPreference(1); Preference buttonPref = mPreferenceContainer.getPreference(2); + Preference stylusPointerIconPref = mPreferenceContainer.getPreference(3); - assertThat(mPreferenceContainer.getPreferenceCount()).isEqualTo(3); assertThat(defaultNotesPref.getTitle().toString()).isEqualTo( mContext.getString(R.string.stylus_default_notes_app)); assertThat(defaultNotesPref.isVisible()).isTrue(); @@ -263,6 +264,9 @@ public class StylusDevicesControllerTest { assertThat(buttonPref.getTitle().toString()).isEqualTo( mContext.getString(R.string.stylus_ignore_button)); assertThat(buttonPref.isVisible()).isTrue(); + assertThat(stylusPointerIconPref.getTitle().toString()).isEqualTo( + mContext.getString(R.string.show_stylus_pointer_icon)); + assertThat(stylusPointerIconPref.isVisible()).isTrue(); } @Test @@ -551,6 +555,46 @@ public class StylusDevicesControllerTest { Secure.STYLUS_BUTTONS_ENABLED, -1)).isEqualTo(1); } + @Test + public void stylusPointerIconPreference_checkedWhenFlagTrue() { + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.STYLUS_POINTER_ICON_ENABLED, 1); + + showScreen(mController); + SwitchPreferenceCompat stylusPointerIconPref = + (SwitchPreferenceCompat) mPreferenceContainer.getPreference(3); + + assertThat(stylusPointerIconPref.isChecked()).isEqualTo(true); + } + + @Test + public void stylusPointerIconPreference_uncheckedWhenFlagFalse() { + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.STYLUS_POINTER_ICON_ENABLED, 0); + + showScreen(mController); + SwitchPreferenceCompat stylusPointerIconPref = + (SwitchPreferenceCompat) mPreferenceContainer.getPreference(3); + + assertThat(stylusPointerIconPref.isChecked()).isEqualTo(false); + } + + @Test + public void stylusPointerIconPreference_updatesFlagOnClick() { + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.STYLUS_POINTER_ICON_ENABLED, 0); + + showScreen(mController); + SwitchPreferenceCompat stylusPointerIconPref = + (SwitchPreferenceCompat) mPreferenceContainer.getPreference(3); + + stylusPointerIconPref.performClick(); + + assertThat(stylusPointerIconPref.isChecked()).isEqualTo(true); + assertThat(Settings.Secure.getInt(mContext.getContentResolver(), + Secure.STYLUS_POINTER_ICON_ENABLED, -1)).isEqualTo(1); + } + private void showScreen(StylusDevicesController controller) { controller.displayPreference(mScreen); } From d91824db270ef41f560ce33f847f142ca93a38a4 Mon Sep 17 00:00:00 2001 From: Omer Ozer Date: Wed, 7 Feb 2024 19:04:03 +0000 Subject: [PATCH 3/6] Disable nfc foreground tests when the role flag is disabled. Bug: 315194263 Test: SettingsRoboTests:com.android.settings.nfc.NfcForegroundPreferenceControllerTest Change-Id: I21037ac3323d4a0322c10450be0dfbb8c9d0d3a0 --- .../nfc/NfcForegroundPreferenceControllerTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/robotests/src/com/android/settings/nfc/NfcForegroundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/nfc/NfcForegroundPreferenceControllerTest.java index 63fa320fbe2..56326ef185f 100644 --- a/tests/robotests/src/com/android/settings/nfc/NfcForegroundPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/nfc/NfcForegroundPreferenceControllerTest.java @@ -25,6 +25,9 @@ import static org.mockito.Mockito.when; import android.app.settings.SettingsEnums; import android.content.Context; import android.content.pm.PackageManager; +import android.platform.test.annotations.RequiresFlagsDisabled; +import android.platform.test.flag.junit.CheckFlagsRule; +import android.platform.test.flag.junit.DeviceFlagsValueProvider; import androidx.preference.ListPreference; import androidx.preference.PreferenceScreen; @@ -33,6 +36,7 @@ import com.android.settings.R; import com.android.settings.testutils.FakeFeatureFactory; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -43,10 +47,14 @@ import org.robolectric.RuntimeEnvironment; import java.util.ArrayList; @RunWith(RobolectricTestRunner.class) +@RequiresFlagsDisabled(android.permission.flags.Flags.FLAG_WALLET_ROLE_ENABLED) public class NfcForegroundPreferenceControllerTest { private static final String PREF_KEY = PaymentSettingsTest.FOREGROUND_KEY; + @Rule + public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); + @Mock private PaymentBackend mPaymentBackend; @Mock From 286055906182d78dfac410d3db6471a6e1c81c38 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Wed, 7 Feb 2024 21:35:57 +0000 Subject: [PATCH 4/6] [String changes] Updating strings as per the suggestion in b/318837875. Change-Id: I13a0fd0c46d918ca5dfba8158955c24879b01b47 Test: Manual --- res/values/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 7291fad3a93..51fa5507a07 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -11613,9 +11613,9 @@ other {# SIMs are available on this device, but only one can be used at a time} } - Activating + Turning on - Couldn\u2019t activate this SIM right now + Couldn\u2019t turn on this SIM right now From 2e536580896e901e69d80d6ecaaee02a8398e8a8 Mon Sep 17 00:00:00 2001 From: Hyunho Date: Tue, 6 Feb 2024 04:33:59 +0000 Subject: [PATCH 5/6] Click the 'convert to eSIM' menu to finish the pSIM setting Bug: b/319527964 Test: manual done Change-Id: I07facccf53c5ee258f0148f64643eb6e1c3d9118 --- .../network/telephony/ConvertToEsimPreferenceController.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/com/android/settings/network/telephony/ConvertToEsimPreferenceController.java b/src/com/android/settings/network/telephony/ConvertToEsimPreferenceController.java index 441c2498152..08e993b6cde 100644 --- a/src/com/android/settings/network/telephony/ConvertToEsimPreferenceController.java +++ b/src/com/android/settings/network/telephony/ConvertToEsimPreferenceController.java @@ -20,6 +20,7 @@ import static androidx.lifecycle.Lifecycle.Event.ON_START; import static androidx.lifecycle.Lifecycle.Event.ON_STOP; import android.Manifest; +import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -143,6 +144,7 @@ public class ConvertToEsimPreferenceController extends TelephonyBasePreferenceCo Intent intent = new Intent(EuiccManager.ACTION_CONVERT_TO_EMBEDDED_SUBSCRIPTION); intent.putExtra("subId", mSubId); mContext.startActivity(intent); + ((Activity) mContext).finish(); return true; } From 185542bd965d2d6f46521fbe9299f6317f4c6293 Mon Sep 17 00:00:00 2001 From: Elliot Sisteron Date: Mon, 5 Feb 2024 13:04:58 +0000 Subject: [PATCH 6/6] Enable Safety Center & Security unit tests on presubmit. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See b/323650746 and b/323649900 for issues that should’ve been caught by pre-submit. Bug: 323649900 Bug: 323650746 Change-Id: I77d664b6fce6a3f76a4c9a6b39202f6e9d47da33 Test: atest SettingsUnitTests --- TEST_MAPPING | 12 +++++++++--- .../settings/testutils/FakeFeatureFactory.java | 16 +++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/TEST_MAPPING b/TEST_MAPPING index 9722a85360a..fd6bcbf2851 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -6,14 +6,20 @@ { "name": "SettingsUnitTests", "options": [ - { - "include-filter": "com.android.settings.password" - }, { "include-filter": "com.android.settings.biometrics" }, { "include-filter": "com.android.settings.biometrics2" + }, + { + "include-filter": "com.android.settings.password" + }, + { + "include-filter": "com.android.settings.safetycenter" + }, + { + "include-filter": "com.android.settings.security" } ] } diff --git a/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java b/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java index bf2c84a5a72..6c4c5b4eae7 100644 --- a/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java +++ b/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java @@ -101,18 +101,20 @@ public class FakeFeatureFactory extends FeatureFactory { public FastPairFeatureProvider mFastPairFeatureProvider; public PrivateSpaceLoginFeatureProvider mPrivateSpaceLoginFeatureProvider; - /** - * Call this in {@code @Before} method of the test class to use fake factory. - */ + /** Call this in {@code @Before} method of the test class to use fake factory. */ public static FakeFeatureFactory setupForTest() { FakeFeatureFactory factory = new FakeFeatureFactory(); - setFactory(getAppContext(), factory); + try { + setFactory(getAppContext(), factory); + } catch (NoSuchMethodError ex) { + // The getAppContext() @JvmStatic method doesn't appear to generated in AOSP. Falling + // back to using the companion object method instead. + setFactory(FeatureFactory.Companion.getAppContext(), factory); + } return factory; } - /** - * FeatureFactory constructor. - */ + /** FeatureFactory constructor. */ public FakeFeatureFactory() { supportFeatureProvider = mock(SupportFeatureProvider.class); metricsFeatureProvider = mock(MetricsFeatureProvider.class);