Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
Remove Dependency#get call from ToggleSeekBar.
Browse files Browse the repository at this point in the history
RestrictedLockUtils#getShowAdminSupportDetailsIntent signature change
such that it no longer requires a context.

Flag: NA
Bug: 138786270
Test: built and flashed
(cherry picked from commit 4db275f0e5709bf94c13e6fee06cd90d83e1c988)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:50341746d3b69ba34033e863c9f53c30c56aaa44)
Merged-In: If4ab3030cfa1f9faed5d099077e5e3bab2cba622
Change-Id: If4ab3030cfa1f9faed5d099077e5e3bab2cba622
  • Loading branch information
Dave Mankoff authored and muhomorr committed Aug 12, 2024
1 parent 62ba028 commit 0875559
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -62,6 +64,7 @@ public class BrightnessSliderController extends ViewController<BrightnessSliderV
private final UiEventLogger mUiEventLogger;

private final SeekableSliderHapticPlugin mBrightnessSliderHapticPlugin;
private final ActivityStarter mActivityStarter;

private final Gefingerpoken mOnInterceptListener = new Gefingerpoken() {
@Override
Expand All @@ -84,11 +87,13 @@ public boolean onTouchEvent(MotionEvent ev) {
BrightnessSliderView brightnessSliderView,
FalsingManager falsingManager,
UiEventLogger uiEventLogger,
SeekableSliderHapticPlugin brightnessSliderHapticPlugin) {
SeekableSliderHapticPlugin brightnessSliderHapticPlugin,
ActivityStarter activityStarter) {
super(brightnessSliderView);
mFalsingManager = falsingManager;
mUiEventLogger = uiEventLogger;
mBrightnessSliderHapticPlugin = brightnessSliderHapticPlugin;
mActivityStarter = activityStarter;
}

/**
Expand Down Expand Up @@ -131,7 +136,15 @@ private boolean copyEventToMirror(MotionEvent ev) {

@Override
public void setEnforcedAdmin(RestrictedLockUtils.EnforcedAdmin admin) {
mView.setEnforcedAdmin(admin);
if (admin == null) {
mView.setAdminBlocker(null);
} else {
mView.setAdminBlocker(() -> {
Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(admin);
mActivityStarter.postStartActivityDismissingKeyguard(intent, 0);
return true;
});
}
}

private void setMirror(ToggleSlider toggleSlider) {
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()) {
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<SeekBar.OnSeekBarChangeListener>
Expand All @@ -91,6 +94,7 @@ class BrightnessSliderControllerTest : SysuiTestCase() {
mFalsingManager,
uiEventLogger,
SeekableSliderHapticPlugin(vibratorHelper, systemClock),
activityStarter,
)
mController.init()
mController.setOnChangedListener(listener)
Expand Down Expand Up @@ -120,7 +124,7 @@ class BrightnessSliderControllerTest : SysuiTestCase() {
@Test
fun testEnforceAdminRelayed() {
mController.setEnforcedAdmin(enforcedAdmin)
verify(brightnessSliderView).setEnforcedAdmin(enforcedAdmin)
verify(brightnessSliderView).setAdminBlocker(notNull())
}

@Test
Expand Down

0 comments on commit 0875559

Please sign in to comment.