From b88fbf932a1631792a422f8ac34e83e1d6ae74d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Hern=C3=A1ndez?= Date: Thu, 15 Jun 2023 18:37:52 +0200 Subject: [PATCH 1/6] Settings: don't try to allow NLSes with too-long component names * NotificationAccessConfirmationActivity (triggered through CompanionDeviceManager) -> Don't show the dialog, bail out early similarly to other invalid inputs. * NotificationAccessSettings (from Special App Access) -> No changes, but use the canonical constant now. * ApprovalPreferenceController (used in NotificationAccessDetails) -> Disable the toggle, unless the NLS was previously approved (in which case it can still be removed). Fixes: 260570119 Fixes: 286043036 Test: atest + manually Change-Id: Ifc048311746c027e3683cdcf65f1079d04cf7c56 Merged-In: Ifc048311746c027e3683cdcf65f1079d04cf7c56 --- .../ApprovalPreferenceController.java | 5 +++- ...otificationAccessConfirmationActivity.java | 4 ++- .../NotificationAccessSettings.java | 4 +-- .../ApprovalPreferenceControllerTest.java | 30 +++++++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java b/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java index 0767e65bbcb..6bee62cc688 100644 --- a/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java +++ b/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java @@ -81,6 +81,8 @@ public class ApprovalPreferenceController extends BasePreferenceController { final RestrictedSwitchPreference preference = (RestrictedSwitchPreference) pref; final CharSequence label = mPkgInfo.applicationInfo.loadLabel(mPm); + final boolean isAllowedCn = mCn.flattenToShortString().length() + <= NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH; final boolean isEnabled = isServiceEnabled(mCn); preference.setChecked(isEnabled); preference.setOnPreferenceChangeListener((p, newValue) -> { @@ -105,7 +107,8 @@ public class ApprovalPreferenceController extends BasePreferenceController { return false; } }); - preference.updateState(mCn.getPackageName(), mPkgInfo.applicationInfo.uid, isEnabled); + preference.updateState( + mCn.getPackageName(), mPkgInfo.applicationInfo.uid, isAllowedCn, isEnabled); } public void disable(final ComponentName cn) { diff --git a/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java b/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java index dfe6df2a5ca..a6b565ae6ba 100644 --- a/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java +++ b/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java @@ -67,7 +67,9 @@ public class NotificationAccessConfirmationActivity extends Activity mUserId = getIntent().getIntExtra(EXTRA_USER_ID, UserHandle.USER_NULL); CharSequence mAppLabel; - if (mComponentName == null || mComponentName.getPackageName() == null) { + if (mComponentName == null || mComponentName.getPackageName() == null + || mComponentName.flattenToString().length() + > NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) { finish(); return; } diff --git a/src/com/android/settings/notification/NotificationAccessSettings.java b/src/com/android/settings/notification/NotificationAccessSettings.java index 369c4f6dfaf..e2ef0ddccb4 100644 --- a/src/com/android/settings/notification/NotificationAccessSettings.java +++ b/src/com/android/settings/notification/NotificationAccessSettings.java @@ -66,7 +66,6 @@ public class NotificationAccessSettings extends EmptyTextSettings { private static final String TAG = "NotifAccessSettings"; static final String ALLOWED_KEY = "allowed"; static final String NOT_ALLOWED_KEY = "not_allowed"; - private static final int MAX_CN_LENGTH = 500; private static final ManagedServiceSettings.Config CONFIG = new ManagedServiceSettings.Config.Builder() @@ -150,7 +149,8 @@ public class NotificationAccessSettings extends EmptyTextSettings { for (ServiceInfo service : services) { final ComponentName cn = new ComponentName(service.packageName, service.name); boolean isAllowed = mNm.isNotificationListenerAccessGranted(cn); - if (!isAllowed && cn.flattenToString().length() > MAX_CN_LENGTH) { + if (!isAllowed && cn.flattenToString().length() + > NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) { continue; } diff --git a/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java index 249b713987c..4601a1cfbaa 100644 --- a/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java +++ b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java @@ -83,6 +83,36 @@ public class ApprovalPreferenceControllerTest { } + @Test + public void updateState_enabled() { + when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(), anyString())).thenReturn( + AppOpsManager.MODE_ALLOWED); + when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true); + RestrictedSwitchPreference pref = new RestrictedSwitchPreference( + mContext); + pref.setAppOps(mAppOpsManager); + + mController.updateState(pref); + + assertThat(pref.isEnabled()).isTrue(); + } + + @Test + public void updateState_invalidCn_disabled() { + ComponentName longCn = new ComponentName("com.example.package", + com.google.common.base.Strings.repeat("Blah", 150)); + mController.setCn(longCn); + when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(), anyString())).thenReturn( + AppOpsManager.MODE_ALLOWED); + RestrictedSwitchPreference pref = new RestrictedSwitchPreference( + mContext); + pref.setAppOps(mAppOpsManager); + + mController.updateState(pref); + + assertThat(pref.isEnabled()).isFalse(); + } + @Test public void updateState_checked() { when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(), anyString())).thenReturn( From f0367c98d0510f325f8fe76166b188be8820373c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Hern=C3=A1ndez?= Date: Thu, 15 Jun 2023 18:37:52 +0200 Subject: [PATCH 2/6] Settings: don't try to allow NLSes with too-long component names * NotificationAccessConfirmationActivity (triggered through CompanionDeviceManager) -> Don't show the dialog, bail out early similarly to other invalid inputs. * NotificationAccessSettings (from Special App Access) -> No changes, but use the canonical constant now. * ApprovalPreferenceController (used in NotificationAccessDetails) -> Disable the toggle, unless the NLS was previously approved (in which case it can still be removed). Fixes: 260570119 Fixes: 286043036 Test: atest + manually Change-Id: Ifc048311746c027e3683cdcf65f1079d04cf7c56 Merged-In: Ifc048311746c027e3683cdcf65f1079d04cf7c56 --- .../ApprovalPreferenceController.java | 3 +++ ...otificationAccessConfirmationActivity.java | 4 +++- .../NotificationAccessSettings.java | 4 ++-- .../ApprovalPreferenceControllerTest.java | 19 +++++++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java b/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java index a43b9fd9145..9235494f359 100644 --- a/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java +++ b/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java @@ -81,6 +81,9 @@ public class ApprovalPreferenceController extends BasePreferenceController { final SwitchPreference preference = (SwitchPreference) pref; final CharSequence label = mPkgInfo.applicationInfo.loadLabel(mPm); preference.setChecked(isServiceEnabled(mCn)); + final boolean isAllowedCn = mCn.flattenToShortString().length() + <= NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH; + preference.setEnabled(preference.isChecked() || isAllowedCn); preference.setOnPreferenceChangeListener((p, newValue) -> { final boolean access = (Boolean) newValue; if (!access) { diff --git a/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java b/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java index dfe6df2a5ca..a6b565ae6ba 100644 --- a/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java +++ b/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java @@ -67,7 +67,9 @@ public class NotificationAccessConfirmationActivity extends Activity mUserId = getIntent().getIntExtra(EXTRA_USER_ID, UserHandle.USER_NULL); CharSequence mAppLabel; - if (mComponentName == null || mComponentName.getPackageName() == null) { + if (mComponentName == null || mComponentName.getPackageName() == null + || mComponentName.flattenToString().length() + > NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) { finish(); return; } diff --git a/src/com/android/settings/notification/NotificationAccessSettings.java b/src/com/android/settings/notification/NotificationAccessSettings.java index ab2a177bcf8..00543a2f3c0 100644 --- a/src/com/android/settings/notification/NotificationAccessSettings.java +++ b/src/com/android/settings/notification/NotificationAccessSettings.java @@ -63,7 +63,6 @@ public class NotificationAccessSettings extends EmptyTextSettings { private static final String TAG = "NotifAccessSettings"; static final String ALLOWED_KEY = "allowed"; static final String NOT_ALLOWED_KEY = "not_allowed"; - private static final int MAX_CN_LENGTH = 500; private static final ManagedServiceSettings.Config CONFIG = new ManagedServiceSettings.Config.Builder() @@ -145,7 +144,8 @@ public class NotificationAccessSettings extends EmptyTextSettings { for (ServiceInfo service : services) { final ComponentName cn = new ComponentName(service.packageName, service.name); boolean isAllowed = mNm.isNotificationListenerAccessGranted(cn); - if (!isAllowed && cn.flattenToString().length() > MAX_CN_LENGTH) { + if (!isAllowed && cn.flattenToString().length() + > NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) { continue; } diff --git a/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java index 064f8134c67..5316adc1c3a 100644 --- a/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java +++ b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java @@ -77,6 +77,25 @@ public class ApprovalPreferenceControllerTest { mController.setPkgInfo(mPkgInfo); } + @Test + public void updateState_enabled() { + SwitchPreference pref = new SwitchPreference(mContext); + mController.updateState(pref); + assertThat(pref.isEnabled()).isTrue(); + } + + @Test + public void updateState_invalidCn_disabled() { + ComponentName longCn = new ComponentName("com.example.package", + com.google.common.base.Strings.repeat("Blah", 150)); + mController.setCn(longCn); + SwitchPreference pref = new SwitchPreference(mContext); + + mController.updateState(pref); + + assertThat(pref.isEnabled()).isFalse(); + } + @Test public void updateState_checked() { when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true); From 7c6f4ae19c18e8dbac364d10d0ea186e5aad0ddb Mon Sep 17 00:00:00 2001 From: Tetiana Meronyk Date: Mon, 26 Jun 2023 16:11:37 +0000 Subject: [PATCH 3/6] Remove "Allow guest to use phone" from devices without telephony. Bug: 282741809 Test: atest UserSettingsTest Change-Id: I8c24dc021f1461c00765b41bf80f352948d14e43 --- res/values/strings.xml | 2 +- .../settings/users/GuestTelephonyPreferenceController.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index bd4e0186b3c..57b146cb8e1 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -6419,7 +6419,7 @@ delete, guest, activity, remove, data, visitor, erase - Allow guest to use phone + Allow guest to make phone calls Call history will be shared with guest user diff --git a/src/com/android/settings/users/GuestTelephonyPreferenceController.java b/src/com/android/settings/users/GuestTelephonyPreferenceController.java index a935b8a4535..2aa808f4e5c 100644 --- a/src/com/android/settings/users/GuestTelephonyPreferenceController.java +++ b/src/com/android/settings/users/GuestTelephonyPreferenceController.java @@ -17,6 +17,7 @@ package com.android.settings.users; import android.content.Context; +import android.content.pm.PackageManager; import android.os.Bundle; import android.os.UserManager; @@ -73,6 +74,7 @@ public class GuestTelephonyPreferenceController extends TogglePreferenceControll public void updateState(Preference preference) { super.updateState(preference); mUserCaps.updateAddUserCapabilities(mContext); - preference.setVisible(isAvailable() && mUserCaps.mUserSwitcherEnabled); + preference.setVisible(isAvailable() && mUserCaps.mUserSwitcherEnabled && mContext + .getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)); } } From 2d3fed86d144bdec04a81e6fa370ad0f2ae64b06 Mon Sep 17 00:00:00 2001 From: Yasin Kilicdere Date: Tue, 27 Jun 2023 12:59:16 +0100 Subject: [PATCH 4/6] After deleting guest user, switch back to previous instead of user0. In Setting, after deleting or exiting the guest user, or failure to reset the guest user involves switching back to user0, which is not possible with HSUM (headless system user mode). With this CL we're now switching back to previous foreground user instead of system user. Bug: 283106632 Test: manual Change-Id: Id60063cca75d9fded7dfe0b7d7a4b871d67c4b0c --- src/com/android/settings/users/UserSettings.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java index d9fbc423f8d..93b7c781517 100644 --- a/src/com/android/settings/users/UserSettings.java +++ b/src/com/android/settings/users/UserSettings.java @@ -977,10 +977,10 @@ public class UserSettings extends SettingsPreferenceFragment return; } try { - getContext().getSystemService(UserManager.class) - .removeUserWhenPossible(UserHandle.of(UserHandle.myUserId()), - /* overrideDevicePolicy= */ false); - ActivityManager.getService().switchUser(UserHandle.USER_SYSTEM); + mUserManager.removeUserWhenPossible( + UserHandle.of(UserHandle.myUserId()), /* overrideDevicePolicy= */ false); + ActivityManager.getService().switchUser( + mUserManager.getPreviousForegroundUser().getIdentifier()); } catch (RemoteException re) { Log.e(TAG, "Unable to remove self user"); } @@ -1099,7 +1099,7 @@ public class UserSettings extends SettingsPreferenceFragment } mMetricsFeatureProvider.action(getActivity(), SettingsEnums.ACTION_USER_GUEST_EXIT_CONFIRMED); - switchToUserId(UserHandle.USER_SYSTEM); + switchToUserId(mUserManager.getPreviousForegroundUser().getIdentifier()); } private int createGuest() { @@ -1139,8 +1139,8 @@ public class UserSettings extends SettingsPreferenceFragment // Create a new guest in the foreground, and then immediately switch to it int newGuestUserId = createGuest(); if (newGuestUserId == UserHandle.USER_NULL) { - Log.e(TAG, "Could not create new guest, switching back to system user"); - switchToUserId(UserHandle.USER_SYSTEM); + Log.e(TAG, "Could not create new guest, switching back to previous user"); + switchToUserId(mUserManager.getPreviousForegroundUser().getIdentifier()); mUserManager.removeUser(oldGuestUserId); WindowManagerGlobal.getWindowManagerService().lockNow(/* options= */ null); return; From a2e032bb8efc7df06a443d431ae4640b3f5b16b2 Mon Sep 17 00:00:00 2001 From: Shawn Lin Date: Tue, 20 Jun 2023 14:22:47 +0800 Subject: [PATCH 5/6] Fix lock pattern is truncated during SUW in folded state Remove the bottom margin of the header view. Bug: 285290323 Test: 1. Go through SUW 2. Select lock pattern 3. Check if UI truncated Test: m RunSettingsRoboTests ROBOTEST_FILTER= com.android.settings.password.SetupChooseLockPatternTest Change-Id: I48ac3d897e6b876bd7a1c325cc4a5e797e140da2 --- .../settings/password/SetupChooseLockPattern.java | 6 ++++++ .../settings/password/SetupChooseLockPatternTest.java | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/com/android/settings/password/SetupChooseLockPattern.java b/src/com/android/settings/password/SetupChooseLockPattern.java index 2cad1813568..4424b4f6c2d 100644 --- a/src/com/android/settings/password/SetupChooseLockPattern.java +++ b/src/com/android/settings/password/SetupChooseLockPattern.java @@ -90,6 +90,12 @@ public class SetupChooseLockPattern extends ChooseLockPattern { } // Show the skip button during SUW but not during Settings > Biometric Enrollment mSkipOrClearButton.setOnClickListener(this::onSkipOrClearButtonClick); + + final View headerView = view.findViewById(R.id.sud_layout_header); + final ViewGroup.MarginLayoutParams lp = + (ViewGroup.MarginLayoutParams) headerView.getLayoutParams(); + lp.bottomMargin = 0; + view.setLayoutParams(lp); return view; } diff --git a/tests/robotests/src/com/android/settings/password/SetupChooseLockPatternTest.java b/tests/robotests/src/com/android/settings/password/SetupChooseLockPatternTest.java index c5e08137863..2f469867d0d 100644 --- a/tests/robotests/src/com/android/settings/password/SetupChooseLockPatternTest.java +++ b/tests/robotests/src/com/android/settings/password/SetupChooseLockPatternTest.java @@ -28,6 +28,7 @@ import android.content.res.Resources; import android.os.UserHandle; import android.util.TypedValue; import android.view.View; +import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; @@ -114,6 +115,14 @@ public class SetupChooseLockPatternTest { assertThat(button.getVisibility()).isEqualTo(View.VISIBLE); } + @Test + public void headerView_noBottomMargin() { + final View header = mActivity.findViewById(R.id.sud_layout_header); + final ViewGroup.MarginLayoutParams lp = + (ViewGroup.MarginLayoutParams) header.getLayoutParams(); + assertThat(lp.bottomMargin).isEqualTo(0); + } + private void verifyScreenLockOptionsShown() { final Button button = mActivity.findViewById(R.id.screen_lock_options); assertThat(button).isNotNull(); From c123b2e5a83848d9220a6a8fe560a3ebe1929199 Mon Sep 17 00:00:00 2001 From: SongFerng Wang Date: Wed, 28 Jun 2023 10:05:26 +0000 Subject: [PATCH 6/6] Revert "Update the wording for LE Audio" This reverts commit f4c5c8ef5e776e427db5fb473cb2add53da4bb4a. Reason for revert: at stage3, removing this summary. Bug: 289184862 Change-Id: I6b18a7e2dee9d8fcfb331e53d7a57cc43574da54 --- res/values/strings.xml | 2 -- .../bluetooth/BluetoothDetailsProfilesController.java | 4 ---- 2 files changed, 6 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 04d9f17de4b..9cf4bad3a8b 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1526,8 +1526,6 @@ Disconnect App? %1$s app will no longer connect to your %2$s - - Experimental. Improves audio quality. Forget device diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java index 701967bfb5e..00f18e8a87a 100644 --- a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java +++ b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java @@ -116,10 +116,6 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll pref.setTitle(profile.getNameResource(mCachedDevice.getDevice())); pref.setOnPreferenceClickListener(this); pref.setOrder(profile.getOrdinal()); - - if (profile instanceof LeAudioProfile) { - pref.setSummary(R.string.device_details_leaudio_toggle_summary); - } return pref; }