diff options
author | Roman Birg <roman@cyngn.com> | 2016-02-08 15:59:34 -0800 |
---|---|---|
committer | Roman Birg <roman@cyngn.com> | 2016-02-08 18:45:18 -0800 |
commit | 61cdfc02db3594dca416b96548a39da552b44b5a (patch) | |
tree | fd5559ecfd705508644698cd85ae9b6963909c02 /packages/SystemUI | |
parent | deb5c35ebe59b0ca822b93fbc80df3054f7589da (diff) | |
download | frameworks_base-61cdfc02db3594dca416b96548a39da552b44b5a.zip frameworks_base-61cdfc02db3594dca416b96548a39da552b44b5a.tar.gz frameworks_base-61cdfc02db3594dca416b96548a39da552b44b5a.tar.bz2 |
SystemUI: improve lockscreen tile behavior with profiles
Disable (grey out) the lock screen tile when a profile is already
disabling it. Profiles takes precedence over the internal setting.
Also simplify lockscreen disable logic - using a null'd Boolean without
synchonization will lead to things falling out of place.
Ref: CYNGNOS-1930
Change-Id: Ia4cb7926e418a4d72426be65e5bfb11dc44bee5e
Signed-off-by: Roman Birg <roman@cyngn.com>
Diffstat (limited to 'packages/SystemUI')
3 files changed, 59 insertions, 48 deletions
diff --git a/packages/SystemUI/res/values/cm_strings.xml b/packages/SystemUI/res/values/cm_strings.xml index dcd02a2..c5fb1b2 100644 --- a/packages/SystemUI/res/values/cm_strings.xml +++ b/packages/SystemUI/res/values/cm_strings.xml @@ -121,6 +121,7 @@ <string name="quick_settings_lockscreen_label">Lock screen</string> <string name="quick_settings_ambient_display_label">Ambient display</string> <string name="quick_settings_lockscreen_label_enforced">Lock screen enforced</string> + <string name="quick_settings_lockscreen_label_locked_by_profile">Disabled by profile</string> <!-- Content description of the screen timeout tile in quick settings (not shown on the screen). [CHAR LIMIT=NONE] --> <string name="accessibility_quick_settings_screen_timeout">Screen timeout: <xliff:g id="timeout" example="30 seconds">%s</xliff:g>.</string> diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java index 110edd8..4042ef9 100755 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java @@ -203,7 +203,6 @@ public class KeyguardViewMediator extends SystemUI { private AudioManager mAudioManager; private StatusBarManager mStatusBarManager; private boolean mSwitchingUser; - private ProfileManager mProfileManager; private boolean mSystemReady; private boolean mBootCompleted; private boolean mBootSendUserPresent; @@ -290,7 +289,7 @@ public class KeyguardViewMediator extends SystemUI { /** * Whether we are disabling the lock screen internally */ - private Boolean mInternallyDisabled = null; + private boolean mInternallyDisabled = false; /** * we send this intent when the keyguard is dismissed. @@ -627,7 +626,6 @@ public class KeyguardViewMediator extends SystemUI { mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard"); mShowKeyguardWakeLock.setReferenceCounted(false); - mProfileManager = ProfileManager.getInstance(mContext); mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(DELAYED_KEYGUARD_ACTION)); mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(DISMISS_KEYGUARD_SECURELY_ACTION), android.Manifest.permission.CONTROL_KEYGUARD, null); @@ -693,18 +691,12 @@ public class KeyguardViewMediator extends SystemUI { getPersistedDefaultOldSetting() ? 1 : 0, UserHandle.USER_CURRENT) == 0; - if (mKeyguardBound) { - if (mInternallyDisabled == null) { - // if it's enabled on boot, don't go through the notions of - // setting it enabled, as it might cause a flicker, just set the state - if (newDisabledState) { - setKeyguardEnabledInternal(false); // will set mInternallyDisabled - } else { - mInternallyDisabled = false; + synchronized (KeyguardViewMediator.this) { + if (mKeyguardBound) { + if (newDisabledState != mInternallyDisabled) { + // it was updated, + setKeyguardEnabledInternal(!newDisabledState); } - } else if (newDisabledState != mInternallyDisabled) { - // it was updated, - setKeyguardEnabledInternal(!newDisabledState); } } } @@ -920,12 +912,9 @@ public class KeyguardViewMediator extends SystemUI { if (DEBUG) Log.d(TAG, "isKeyguardDisabled: keyguard is disabled internally"); return true; } - Profile profile = mProfileManager.getActiveProfile(); - if (profile != null) { - if (profile.getScreenLockMode().getValue() == Profile.LockMode.DISABLE) { - if (DEBUG) Log.d(TAG, "isKeyguardDisabled: keyguard is disabled by profile"); - return true; - } + if (isProfileDisablingKeyguard()) { + if (DEBUG) Log.d(TAG, "isKeyguardDisabled: keyguard is disabled by profile"); + return true; } return false; } @@ -961,6 +950,10 @@ public class KeyguardViewMediator extends SystemUI { */ public void setKeyguardEnabledInternal(boolean enabled) { mInternallyDisabled = !enabled; + if (!mUpdateMonitor.isSimPinSecure()) { + // disable when sim is ready + return; + } setKeyguardEnabled(enabled); if (mInternallyDisabled) { mNeedToReshowWhenReenabled = false; @@ -971,7 +964,7 @@ public class KeyguardViewMediator extends SystemUI { return !mInternallyDisabled; } - private boolean isProfileDisablingKeyguard() { + public boolean isProfileDisablingKeyguard() { final Profile activeProfile = ProfileManager.getInstance(mContext).getActiveProfile(); return activeProfile != null && activeProfile.getScreenLockMode().getValue() == Profile.LockMode.DISABLE; @@ -1558,6 +1551,10 @@ public class KeyguardViewMediator extends SystemUI { private void playSound(int soundId) { if (soundId == 0) return; + if (mInternallyDisabled) { + Log.d(TAG, "suppressing lock screen sounds because it is disabled"); + return; + } final ContentResolver cr = mContext.getContentResolver(); if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) { diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/LockscreenToggleTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/LockscreenToggleTile.java index 2d764ba..a24c249 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/LockscreenToggleTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/LockscreenToggleTile.java @@ -23,6 +23,9 @@ import com.android.systemui.SystemUIApplication; import com.android.systemui.keyguard.KeyguardViewMediator; import com.android.systemui.qs.QSTile; import com.android.systemui.statusbar.policy.KeyguardMonitor; + +import cyanogenmod.app.Profile; +import cyanogenmod.app.ProfileManager; import cyanogenmod.providers.CMSettings; import org.cyanogenmod.internal.logging.CMMetricsLogger; @@ -32,7 +35,6 @@ public class LockscreenToggleTile extends QSTile<QSTile.BooleanState> private static final Intent LOCK_SCREEN_SETTINGS = new Intent("android.settings.LOCK_SCREEN_SETTINGS"); - private KeyguardViewMediator mKeyguardViewMediator; private KeyguardMonitor mKeyguard; private boolean mListening; @@ -42,21 +44,13 @@ public class LockscreenToggleTile extends QSTile<QSTile.BooleanState> super(host); mKeyguard = host.getKeyguardMonitor(); - mKeyguardViewMediator = - ((SystemUIApplication) - mContext.getApplicationContext()).getComponent(KeyguardViewMediator.class); mSettingsObserver = new KeyguardViewMediator.LockscreenEnabledSettingsObserver(mContext, mUiHandler) { @Override public void update() { - boolean newState = CMSettings.Secure.getIntForUser( - mContext.getContentResolver(), - CMSettings.Secure.LOCKSCREEN_INTERNALLY_ENABLED, - getPersistedDefaultOldSetting() ? 1 : 0, - UserHandle.USER_CURRENT) != 0; - refreshState(newState); + refreshState(); } }; @@ -97,24 +91,43 @@ public class LockscreenToggleTile extends QSTile<QSTile.BooleanState> @Override protected void handleUpdateState(BooleanState state, Object arg) { - final boolean lockscreenEnforced = mKeyguardViewMediator.lockscreenEnforcedByDevicePolicy(); - final boolean lockscreenEnabled = lockscreenEnforced || - arg != null ? (Boolean) arg : mKeyguardViewMediator.getKeyguardEnabledInternal(); - - state.value = lockscreenEnabled; - state.visible = mKeyguardViewMediator.isKeyguardBound(); - state.enabled = !mKeyguard.isShowing() || !mKeyguard.isSecure(); - state.label = mContext.getString(lockscreenEnforced - ? R.string.quick_settings_lockscreen_label_enforced - : R.string.quick_settings_lockscreen_label); - if (lockscreenEnabled) { - state.icon = ResourceIcon.get(R.drawable.ic_qs_lock_screen_on); - state.contentDescription = mContext.getString( - R.string.accessibility_quick_settings_lock_screen_on); + KeyguardViewMediator mediator = ((SystemUIApplication) + mContext.getApplicationContext()).getComponent(KeyguardViewMediator.class); + + if (mediator == null) { + state.visible = false; + state.value = false; + state.enabled = false; } else { - state.icon = ResourceIcon.get(R.drawable.ic_qs_lock_screen_off); - state.contentDescription = mContext.getString( - R.string.accessibility_quick_settings_lock_screen_off); + final boolean lockscreenEnforced = mediator.lockscreenEnforcedByDevicePolicy(); + final boolean lockscreenEnabled = lockscreenEnforced || + arg != null ? (Boolean) arg : mediator.getKeyguardEnabledInternal(); + + state.visible = mediator.isKeyguardBound(); + + if (mediator.isProfileDisablingKeyguard()) { + state.label = mContext.getString( + R.string.quick_settings_lockscreen_label_locked_by_profile); + state.value = false; + state.enabled = false; + } else { + state.value = lockscreenEnabled; + state.enabled = !mKeyguard.isShowing() || !mKeyguard.isSecure(); + + state.label = mContext.getString(lockscreenEnforced + ? R.string.quick_settings_lockscreen_label_enforced + : R.string.quick_settings_lockscreen_label); + } + // update icon + if (lockscreenEnabled) { + state.icon = ResourceIcon.get(R.drawable.ic_qs_lock_screen_on); + state.contentDescription = mContext.getString( + R.string.accessibility_quick_settings_lock_screen_on); + } else { + state.icon = ResourceIcon.get(R.drawable.ic_qs_lock_screen_off); + state.contentDescription = mContext.getString( + R.string.accessibility_quick_settings_lock_screen_off); + } } } |