From 8b0efe7d89d8d2a24d2434bb46d7bd425a8491e4 Mon Sep 17 00:00:00 2001 From: Jordan Demeulenaere Date: Mon, 5 Dec 2022 15:50:50 +0100 Subject: [PATCH 1/2] Fix NPE in QSSecurityFooterUtils Bug: 261424600 Test: Manual Change-Id: I28a14ab9798d66c43d6d9d08259f6a6e80ea5c5d --- .../android/systemui/qs/QSSecurityFooterUtils.java | 2 +- .../android/systemui/qs/QSSecurityFooterTest.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooterUtils.java b/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooterUtils.java index 67bc769985975..068b9ea6bdb80 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooterUtils.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooterUtils.java @@ -247,7 +247,7 @@ public class QSSecurityFooterUtils implements DialogInterface.OnClickListener { Icon icon; ContentDescription contentDescription = null; - if (isParentalControlsEnabled) { + if (isParentalControlsEnabled && securityModel.getDeviceAdminIcon() != null) { icon = new Icon.Loaded(securityModel.getDeviceAdminIcon(), contentDescription); } else if (vpnName != null || vpnNameWorkProfile != null) { if (securityModel.isVpnBranded()) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java index 5e9c1aaad3091..906c20b1d0321 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java @@ -703,28 +703,32 @@ public class QSSecurityFooterTest extends SysuiTestCase { public void testParentalControls() { // Make sure the security footer is visible, so that the images are updated. when(mSecurityController.isProfileOwnerOfOrganizationOwnedDevice()).thenReturn(true); - when(mSecurityController.isParentalControlsEnabled()).thenReturn(true); + // We use the default icon when there is no admin icon. + when(mSecurityController.getIcon(any())).thenReturn(null); + mFooter.refreshState(); + TestableLooper.get(this).processAllMessages(); + assertEquals(mContext.getString(R.string.quick_settings_disclosure_parental_controls), + mFooterText.getText()); + assertEquals(DEFAULT_ICON_ID, mPrimaryFooterIcon.getLastImageResource()); + Drawable testDrawable = new VectorDrawable(); when(mSecurityController.getIcon(any())).thenReturn(testDrawable); assertNotNull(mSecurityController.getIcon(null)); mFooter.refreshState(); - TestableLooper.get(this).processAllMessages(); assertEquals(mContext.getString(R.string.quick_settings_disclosure_parental_controls), mFooterText.getText()); assertEquals(View.VISIBLE, mPrimaryFooterIcon.getVisibility()); - assertEquals(testDrawable, mPrimaryFooterIcon.getDrawable()); // Ensure the primary icon is back to default after parental controls are gone when(mSecurityController.isParentalControlsEnabled()).thenReturn(false); mFooter.refreshState(); TestableLooper.get(this).processAllMessages(); - assertEquals(DEFAULT_ICON_ID, mPrimaryFooterIcon.getLastImageResource()); } From 05bfd051303f0b500c87c5ba756fa0940836573b Mon Sep 17 00:00:00 2001 From: Jordan Demeulenaere Date: Mon, 5 Dec 2022 16:05:04 +0100 Subject: [PATCH 2/2] Fix parental control dialog This CL fixes a bug introduced by ag/19712818: when inflating the parental control dialog, we should use the Quick Settings context (which is always using dark mode) and not the application context. Otherwise, if we are in light mode, then the color of the text is the same as the background and it looks like there is not content in the dialog. In dark mode, everything was looking fine because the text color from the application context would be light. Bug: 260108168 Test: Manual Change-Id: Ibc9d5374d44955493a41b477482d5585546c7eb1 --- .../src/com/android/systemui/qs/QSSecurityFooterUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooterUtils.java b/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooterUtils.java index 068b9ea6bdb80..5dbf0f8dcdceb 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooterUtils.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooterUtils.java @@ -476,7 +476,7 @@ public class QSSecurityFooterUtils implements DialogInterface.OnClickListener { @VisibleForTesting View createDialogView(Context quickSettingsContext) { if (mSecurityController.isParentalControlsEnabled()) { - return createParentalControlsDialogView(); + return createParentalControlsDialogView(quickSettingsContext); } return createOrganizationDialogView(quickSettingsContext); } @@ -579,8 +579,8 @@ public class QSSecurityFooterUtils implements DialogInterface.OnClickListener { return dialogView; } - private View createParentalControlsDialogView() { - View dialogView = LayoutInflater.from(mContext) + private View createParentalControlsDialogView(Context quickSettingsContext) { + View dialogView = LayoutInflater.from(quickSettingsContext) .inflate(R.layout.quick_settings_footer_dialog_parental_controls, null, false); DeviceAdminInfo info = mSecurityController.getDeviceAdminInfo();