Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

Commit

Permalink
require unlocking to use work mode tile
Browse files Browse the repository at this point in the history
Straight forward patch as this is already done for other tiles by @thestinger and for LocationTile.java even from Google itself. Requiring unlocking to use the work mode tile is useful because it would be annoying when someone could just disable your work profile (useful together with Shelter to run apps in a sandbox). Also, this tile becomes automatically added to the lock screen when you setup a work profile.

Tested on AOSP 10 on sargo. Ref: https://github.com/hashbang/os
  • Loading branch information
ypid authored and thestinger committed Dec 2, 2019
1 parent 3b38fb3 commit 4a757e6
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,23 @@
import android.widget.Switch;

import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.plugins.qs.QSTile.BooleanState;
import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.tileimpl.QSTileImpl;
import com.android.systemui.statusbar.phone.ManagedProfileController;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.statusbar.policy.KeyguardMonitor;

import javax.inject.Inject;

/** Quick settings tile: Work profile on/off */
public class WorkModeTile extends QSTileImpl<BooleanState> implements
ManagedProfileController.Callback {
private final Icon mIcon = ResourceIcon.get(R.drawable.stat_sys_managed_profile_status);
private final KeyguardMonitor mKeyguard;
private final KeyguardCallback mKeyguardCallback = new KeyguardCallback();

private final ManagedProfileController mProfileController;

Expand All @@ -42,6 +47,7 @@ public WorkModeTile(QSHost host, ManagedProfileController managedProfileControll
super(host);
mProfileController = managedProfileController;
mProfileController.observe(getLifecycle(), this);
mKeyguard = Dependency.get(KeyguardMonitor.class);
}

@Override
Expand All @@ -51,6 +57,11 @@ public BooleanState newTileState() {

@Override
public void handleSetListening(boolean listening) {
if (listening) {
mKeyguard.addCallback(mKeyguardCallback);
} else {
mKeyguard.removeCallback(mKeyguardCallback);
}
}

@Override
Expand All @@ -60,6 +71,13 @@ public Intent getLongClickIntent() {

@Override
public void handleClick() {
if (mKeyguard.isSecure() && mKeyguard.isShowing()) {
Dependency.get(ActivityStarter.class).postQSRunnableDismissingKeyguard(() -> {
mHost.openPanels();
mProfileController.setWorkModeEnabled(!mState.value);
});
return;
}
mProfileController.setWorkModeEnabled(!mState.value);
}

Expand Down Expand Up @@ -128,4 +146,11 @@ protected String composeChangeAnnouncement() {
return mContext.getString(R.string.accessibility_quick_settings_work_mode_changed_off);
}
}

private final class KeyguardCallback implements KeyguardMonitor.Callback {
@Override
public void onKeyguardShowingChanged() {
refreshState();
}
}
}

0 comments on commit 4a757e6

Please sign in to comment.