5454import android .Manifest ;
5555import android .app .ActivityManagerNative ;
5656import android .app .IActivityManager ;
57+ import android .app .admin .DevicePolicyManager ;
5758import android .content .Context ;
5859import android .content .pm .ActivityInfo ;
5960import android .content .pm .PackageManager ;
8687import android .provider .Settings ;
8788import android .util .DisplayMetrics ;
8889import android .util .EventLog ;
90+ import android .util .Log ;
8991import android .util .Slog ;
9092import android .util .SparseIntArray ;
9193import android .view .Display ;
@@ -4171,13 +4173,31 @@ public void moveAppTokensToBottom(List<IBinder> tokens) {
41714173 // Misc IWindowSession methods
41724174 // -------------------------------------------------------------
41734175
4176+ private boolean allowDisableKeyguard ()
4177+ {
4178+ // We fail safe if this gets called before the service has started.
4179+ boolean allow = false ;
4180+ DevicePolicyManager dpm = (DevicePolicyManager ) mContext .getSystemService (
4181+ Context .DEVICE_POLICY_SERVICE );
4182+ if (dpm != null ) {
4183+ allow = dpm .getPasswordQuality (null )
4184+ == DevicePolicyManager .PASSWORD_QUALITY_UNSPECIFIED ;
4185+ }
4186+ return allow ;
4187+ }
4188+
41744189 public void disableKeyguard (IBinder token , String tag ) {
41754190 if (mContext .checkCallingOrSelfPermission (android .Manifest .permission .DISABLE_KEYGUARD )
41764191 != PackageManager .PERMISSION_GRANTED ) {
41774192 throw new SecurityException ("Requires DISABLE_KEYGUARD permission" );
41784193 }
4179- synchronized (mKeyguardTokenWatcher ) {
4180- mKeyguardTokenWatcher .acquire (token , tag );
4194+
4195+ if (allowDisableKeyguard ()) {
4196+ synchronized (mKeyguardTokenWatcher ) {
4197+ mKeyguardTokenWatcher .acquire (token , tag );
4198+ }
4199+ } else {
4200+ Log .w (TAG , tag + ": disableKeyguard() ignored while DevicePolicyAmin is enabled." );
41814201 }
41824202 }
41834203
@@ -4186,25 +4206,30 @@ public void reenableKeyguard(IBinder token) {
41864206 != PackageManager .PERMISSION_GRANTED ) {
41874207 throw new SecurityException ("Requires DISABLE_KEYGUARD permission" );
41884208 }
4189- synchronized (mKeyguardTokenWatcher ) {
4190- mKeyguardTokenWatcher .release (token );
4191-
4192- if (!mKeyguardTokenWatcher .isAcquired ()) {
4193- // If we are the last one to reenable the keyguard wait until
4194- // we have actaully finished reenabling until returning.
4195- // It is possible that reenableKeyguard() can be called before
4196- // the previous disableKeyguard() is handled, in which case
4197- // neither mKeyguardTokenWatcher.acquired() or released() would
4198- // be called. In that case mKeyguardDisabled will be false here
4199- // and we have nothing to wait for.
4200- while (mKeyguardDisabled ) {
4201- try {
4202- mKeyguardTokenWatcher .wait ();
4203- } catch (InterruptedException e ) {
4204- Thread .currentThread ().interrupt ();
4209+
4210+ if (allowDisableKeyguard ()) {
4211+ synchronized (mKeyguardTokenWatcher ) {
4212+ mKeyguardTokenWatcher .release (token );
4213+
4214+ if (!mKeyguardTokenWatcher .isAcquired ()) {
4215+ // If we are the last one to reenable the keyguard wait until
4216+ // we have actaully finished reenabling until returning.
4217+ // It is possible that reenableKeyguard() can be called before
4218+ // the previous disableKeyguard() is handled, in which case
4219+ // neither mKeyguardTokenWatcher.acquired() or released() would
4220+ // be called. In that case mKeyguardDisabled will be false here
4221+ // and we have nothing to wait for.
4222+ while (mKeyguardDisabled ) {
4223+ try {
4224+ mKeyguardTokenWatcher .wait ();
4225+ } catch (InterruptedException e ) {
4226+ Thread .currentThread ().interrupt ();
4227+ }
42054228 }
42064229 }
42074230 }
4231+ } else {
4232+ Log .w (TAG , "reenableKeyguard() ignored while DevicePolicyAmin is enabled." );
42084233 }
42094234 }
42104235
0 commit comments