diff --git a/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java b/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java index 18e8fc38ddb0..f47041df6ee3 100644 --- a/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java +++ b/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java @@ -85,7 +85,7 @@ public static EnforcedAdmin getProfileOrDeviceOwner( */ @RequiresApi(Build.VERSION_CODES.M) public static void sendShowAdminSupportDetailsIntent(Context context, EnforcedAdmin admin) { - final Intent intent = getShowAdminSupportDetailsIntent(context, admin); + final Intent intent = getShowAdminSupportDetailsIntent(admin); int targetUserId = UserHandle.myUserId(); if (admin != null) { if (admin.user != null @@ -98,9 +98,16 @@ && isCurrentUserOrProfile(context, admin.user.getIdentifier())) { } /** - * Gets the intent to trigger the {@code android.settings.ShowAdminSupportDetailsDialog}. + * @deprecated No context needed. Use {@link #getShowAdminSupportDetailsIntent(EnforcedAdmin)}. */ public static Intent getShowAdminSupportDetailsIntent(Context context, EnforcedAdmin admin) { + return getShowAdminSupportDetailsIntent(admin); + } + + /** + * Gets the intent to trigger the {@code android.settings.ShowAdminSupportDetailsDialog}. + */ + public static Intent getShowAdminSupportDetailsIntent(EnforcedAdmin admin) { final Intent intent = new Intent(Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS); if (admin != null) { if (admin.component != null) { diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractorTest.kt index a1f885c64312..c0e5a9bc9990 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractorTest.kt @@ -114,7 +114,7 @@ class DisabledByPolicyInteractorTest : SysuiTestCase() { DisabledByPolicyInteractor.PolicyResult.TileDisabled(ADMIN) ) - val expectedIntent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(context, ADMIN) + val expectedIntent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(ADMIN) assertThat(result).isTrue() verify(activityStarter).postStartActivityDismissingKeyguard(intentCaptor.capture(), any()) assertThat(intentCaptor.value.filterEquals(expectedIntent)).isTrue() diff --git a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileImpl.java b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileImpl.java index a4c69237693d..a59e4c09d430 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileImpl.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileImpl.java @@ -614,7 +614,7 @@ public void handleMessage(Message msg) { name = "handleClick"; if (mState.disabledByPolicy) { Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent( - mContext, mEnforcedAdmin); + mEnforcedAdmin); mActivityStarter.postStartActivityDismissingKeyguard(intent, 0); } else { mQSLogger.logHandleClick(mTileSpec, msg.arg1); diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java index 32deb30d926b..6b654beea149 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java @@ -34,11 +34,11 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.drawable.CircleFramedDrawable; -import com.android.systemui.res.R; import com.android.systemui.plugins.FalsingManager; import com.android.systemui.qs.PseudoGridView; import com.android.systemui.qs.QSUserSwitcherEvent; import com.android.systemui.qs.user.UserSwitchDialogController; +import com.android.systemui.res.R; import com.android.systemui.statusbar.phone.SystemUIDialog; import com.android.systemui.statusbar.policy.BaseUserSwitcherAdapter; import com.android.systemui.statusbar.policy.UserSwitcherController; @@ -186,7 +186,7 @@ public void onClick(View view) { (UserRecord) view.getTag(); if (userRecord.isDisabledByAdmin()) { final Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent( - mContext, userRecord.enforcedAdmin); + userRecord.enforcedAdmin); mController.startActivity(intent); } else if (userRecord.isSwitchToEnabled) { MetricsLogger.action(mContext, MetricsEvent.QS_SWITCH_USER); diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractor.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractor.kt index d1f8945cc091..87b89ea6810a 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractor.kt @@ -96,10 +96,7 @@ constructor( is PolicyResult.TileEnabled -> false is PolicyResult.TileDisabled -> { val intent = - RestrictedLockUtils.getShowAdminSupportDetailsIntent( - context, - policyResult.admin - ) + RestrictedLockUtils.getShowAdminSupportDetailsIntent(policyResult.admin) activityStarter.postStartActivityDismissingKeyguard(intent, 0) true } diff --git a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSliderController.java b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSliderController.java index 861a2edebf14..539b0c2dd599 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSliderController.java +++ b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSliderController.java @@ -19,6 +19,7 @@ import static com.android.systemui.Flags.hapticBrightnessSlider; import android.content.Context; +import android.content.Intent; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -33,6 +34,7 @@ import com.android.systemui.classifier.Classifier; import com.android.systemui.haptics.slider.HapticSliderViewBinder; import com.android.systemui.haptics.slider.SeekableSliderHapticPlugin; +import com.android.systemui.plugins.ActivityStarter; import com.android.systemui.plugins.FalsingManager; import com.android.systemui.res.R; import com.android.systemui.statusbar.VibratorHelper; @@ -62,6 +64,7 @@ public class BrightnessSliderController extends ViewController { + Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(admin); + mActivityStarter.postStartActivityDismissingKeyguard(intent, 0); + return true; + }); + } } private void setMirror(ToggleSlider toggleSlider) { @@ -259,18 +272,21 @@ public static class Factory { private final UiEventLogger mUiEventLogger; private final VibratorHelper mVibratorHelper; private final SystemClock mSystemClock; + private final ActivityStarter mActivityStarter; @Inject public Factory( FalsingManager falsingManager, UiEventLogger uiEventLogger, VibratorHelper vibratorHelper, - SystemClock clock + SystemClock clock, + ActivityStarter activityStarter ) { mFalsingManager = falsingManager; mUiEventLogger = uiEventLogger; mVibratorHelper = vibratorHelper; mSystemClock = clock; + mActivityStarter = activityStarter; } /** @@ -292,7 +308,8 @@ public BrightnessSliderController create( if (hapticBrightnessSlider()) { HapticSliderViewBinder.bind(viewRoot, plugin); } - return new BrightnessSliderController(root, mFalsingManager, mUiEventLogger, plugin); + return new BrightnessSliderController( + root, mFalsingManager, mUiEventLogger, plugin, mActivityStarter); } /** Get the layout to inflate based on what slider to use */ diff --git a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSliderView.java b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSliderView.java index c43d20cdf52f..92006a473ed8 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSliderView.java +++ b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSliderView.java @@ -31,7 +31,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.android.settingslib.RestrictedLockUtils; import com.android.systemui.Gefingerpoken; import com.android.systemui.res.R; @@ -120,9 +119,8 @@ public void setOnSeekBarChangeListener(OnSeekBarChangeListener seekListener) { * @param admin * @see ToggleSeekBar#setEnforcedAdmin */ - public void setEnforcedAdmin(RestrictedLockUtils.EnforcedAdmin admin) { - mSlider.setEnabled(admin == null); - mSlider.setEnforcedAdmin(admin); + void setAdminBlocker(ToggleSeekBar.AdminBlocker blocker) { + mSlider.setAdminBlocker(blocker); } /** diff --git a/packages/SystemUI/src/com/android/systemui/settings/brightness/ToggleSeekBar.java b/packages/SystemUI/src/com/android/systemui/settings/brightness/ToggleSeekBar.java index a5a0ae70045e..288ff09602f4 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/brightness/ToggleSeekBar.java +++ b/packages/SystemUI/src/com/android/systemui/settings/brightness/ToggleSeekBar.java @@ -17,20 +17,15 @@ package com.android.systemui.settings.brightness; import android.content.Context; -import android.content.Intent; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.accessibility.AccessibilityNodeInfo; import android.widget.SeekBar; -import com.android.settingslib.RestrictedLockUtils; -import com.android.systemui.Dependency; -import com.android.systemui.plugins.ActivityStarter; - public class ToggleSeekBar extends SeekBar { private String mAccessibilityLabel; - private RestrictedLockUtils.EnforcedAdmin mEnforcedAdmin = null; + private AdminBlocker mAdminBlocker; public ToggleSeekBar(Context context) { super(context); @@ -46,10 +41,7 @@ public ToggleSeekBar(Context context, AttributeSet attrs, int defStyleAttr) { @Override public boolean onTouchEvent(MotionEvent event) { - if (mEnforcedAdmin != null) { - Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent( - mContext, mEnforcedAdmin); - Dependency.get(ActivityStarter.class).postStartActivityDismissingKeyguard(intent, 0); + if (mAdminBlocker != null && mAdminBlocker.block()) { return true; } if (!isEnabled()) { @@ -71,7 +63,12 @@ public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { } } - public void setEnforcedAdmin(RestrictedLockUtils.EnforcedAdmin admin) { - mEnforcedAdmin = admin; + void setAdminBlocker(AdminBlocker blocker) { + mAdminBlocker = blocker; + setEnabled(blocker == null); + } + + interface AdminBlocker { + boolean block(); } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/settings/brightness/BrightnessSliderControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/settings/brightness/BrightnessSliderControllerTest.kt index ab90b9be3c1e..25ba09a0ce90 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/settings/brightness/BrightnessSliderControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/settings/brightness/BrightnessSliderControllerTest.kt @@ -25,6 +25,7 @@ import com.android.settingslib.RestrictedLockUtils import com.android.systemui.SysuiTestCase import com.android.systemui.classifier.FalsingManagerFake import com.android.systemui.haptics.slider.SeekableSliderHapticPlugin +import com.android.systemui.plugins.ActivityStarter import com.android.systemui.statusbar.VibratorHelper import com.android.systemui.statusbar.policy.BrightnessMirrorController import com.android.systemui.util.mockito.any @@ -66,6 +67,8 @@ class BrightnessSliderControllerTest : SysuiTestCase() { private lateinit var listener: ToggleSlider.Listener @Mock private lateinit var vibratorHelper: VibratorHelper + @Mock + private lateinit var activityStarter: ActivityStarter @Captor private lateinit var seekBarChangeCaptor: ArgumentCaptor @@ -91,6 +94,7 @@ class BrightnessSliderControllerTest : SysuiTestCase() { mFalsingManager, uiEventLogger, SeekableSliderHapticPlugin(vibratorHelper, systemClock), + activityStarter, ) mController.init() mController.setOnChangedListener(listener) @@ -120,7 +124,7 @@ class BrightnessSliderControllerTest : SysuiTestCase() { @Test fun testEnforceAdminRelayed() { mController.setEnforcedAdmin(enforcedAdmin) - verify(brightnessSliderView).setEnforcedAdmin(enforcedAdmin) + verify(brightnessSliderView).setAdminBlocker(notNull()) } @Test