|
75 | 75 | import android.graphics.RectF; |
76 | 76 | import android.graphics.Region; |
77 | 77 | import android.hardware.display.DisplayManager; |
78 | | -import android.os.BatteryStats; |
79 | 78 | import android.os.Binder; |
80 | 79 | import android.os.Bundle; |
81 | 80 | import android.os.Debug; |
|
93 | 92 | import android.os.StrictMode; |
94 | 93 | import android.os.SystemClock; |
95 | 94 | import android.os.SystemProperties; |
96 | | -import android.os.TokenWatcher; |
97 | 95 | import android.os.Trace; |
98 | 96 | import android.os.WorkSource; |
99 | 97 | import android.provider.Settings; |
@@ -279,55 +277,19 @@ public class WindowManagerService extends IWindowManager.Stub |
279 | 277 | private static final String SYSTEM_SECURE = "ro.secure"; |
280 | 278 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
281 | 279 |
|
282 | | - /** |
283 | | - * Condition waited on by {@link #reenableKeyguard} to know the call to |
284 | | - * the window policy has finished. |
285 | | - * This is set to true only if mKeyguardTokenWatcher.acquired() has |
286 | | - * actually disabled the keyguard. |
287 | | - */ |
288 | | - private boolean mKeyguardDisabled = false; |
| 280 | + final private KeyguardDisableHandler mKeyguardDisableHandler; |
289 | 281 |
|
290 | 282 | private final boolean mHeadless; |
291 | 283 |
|
292 | | - private static final int ALLOW_DISABLE_YES = 1; |
293 | | - private static final int ALLOW_DISABLE_NO = 0; |
294 | | - private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
295 | | - private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
296 | | - |
297 | 284 | private static final float THUMBNAIL_ANIMATION_DECELERATE_FACTOR = 1.5f; |
298 | 285 |
|
299 | | - final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
300 | | - new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
301 | | - @Override |
302 | | - public void acquired() { |
303 | | - if (shouldAllowDisableKeyguard()) { |
304 | | - mPolicy.enableKeyguard(false); |
305 | | - mKeyguardDisabled = true; |
306 | | - } else { |
307 | | - Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
308 | | - } |
309 | | - } |
310 | | - @Override |
311 | | - public void released() { |
312 | | - mPolicy.enableKeyguard(true); |
313 | | - synchronized (mKeyguardTokenWatcher) { |
314 | | - mKeyguardDisabled = false; |
315 | | - mKeyguardTokenWatcher.notifyAll(); |
316 | | - } |
317 | | - } |
318 | | - }; |
319 | | - |
320 | 286 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
321 | 287 | @Override |
322 | 288 | public void onReceive(Context context, Intent intent) { |
323 | 289 | final String action = intent.getAction(); |
324 | 290 | if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals(action)) { |
325 | | - mPolicy.enableKeyguard(true); |
326 | | - synchronized(mKeyguardTokenWatcher) { |
327 | | - // lazily evaluate this next time we're asked to disable keyguard |
328 | | - mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
329 | | - mKeyguardDisabled = false; |
330 | | - } |
| 291 | + mKeyguardDisableHandler.sendEmptyMessage( |
| 292 | + KeyguardDisableHandler.KEYGUARD_POLICY_CHANGED); |
331 | 293 | } else if (Intent.ACTION_USER_SWITCHED.equals(action)) { |
332 | 294 | final int newUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0); |
333 | 295 | Slog.v(TAG, "Switching user from " + mCurrentUserId + " to " + newUserId); |
@@ -898,6 +860,8 @@ private WindowManagerService(Context context, PowerManagerService pm, |
898 | 860 | mDisplayManager = DisplayManager.getInstance(); |
899 | 861 | mHeadless = displayManager.isHeadless(); |
900 | 862 |
|
| 863 | + mKeyguardDisableHandler = new KeyguardDisableHandler(mContext, mPolicy); |
| 864 | + |
901 | 865 | mPowerManager = pm; |
902 | 866 | mPowerManager.setPolicy(mPolicy); |
903 | 867 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
@@ -5062,59 +5026,26 @@ public void moveAppTokensToBottom(List<IBinder> tokens) { |
5062 | 5026 | // Misc IWindowSession methods |
5063 | 5027 | // ------------------------------------------------------------- |
5064 | 5028 |
|
5065 | | - private boolean shouldAllowDisableKeyguard() |
5066 | | - { |
5067 | | - // We fail safe and prevent disabling keyguard in the unlikely event this gets |
5068 | | - // called before DevicePolicyManagerService has started. |
5069 | | - if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
5070 | | - DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
5071 | | - Context.DEVICE_POLICY_SERVICE); |
5072 | | - if (dpm != null) { |
5073 | | - mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
5074 | | - == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
5075 | | - ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
5076 | | - } |
5077 | | - } |
5078 | | - return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
5079 | | - } |
5080 | | - |
| 5029 | + @Override |
5081 | 5030 | public void disableKeyguard(IBinder token, String tag) { |
5082 | 5031 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
5083 | 5032 | != PackageManager.PERMISSION_GRANTED) { |
5084 | 5033 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
5085 | 5034 | } |
5086 | 5035 |
|
5087 | | - synchronized (mKeyguardTokenWatcher) { |
5088 | | - mKeyguardTokenWatcher.acquire(token, tag); |
5089 | | - } |
| 5036 | + mKeyguardDisableHandler.sendMessage(mKeyguardDisableHandler.obtainMessage( |
| 5037 | + KeyguardDisableHandler.KEYGUARD_DISABLE, new Pair<IBinder, String>(token, tag))); |
5090 | 5038 | } |
5091 | 5039 |
|
| 5040 | + @Override |
5092 | 5041 | public void reenableKeyguard(IBinder token) { |
5093 | 5042 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
5094 | 5043 | != PackageManager.PERMISSION_GRANTED) { |
5095 | 5044 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
5096 | 5045 | } |
5097 | 5046 |
|
5098 | | - synchronized (mKeyguardTokenWatcher) { |
5099 | | - mKeyguardTokenWatcher.release(token); |
5100 | | - |
5101 | | - if (!mKeyguardTokenWatcher.isAcquired()) { |
5102 | | - // If we are the last one to reenable the keyguard wait until |
5103 | | - // we have actually finished reenabling until returning. |
5104 | | - // It is possible that reenableKeyguard() can be called before |
5105 | | - // the previous disableKeyguard() is handled, in which case |
5106 | | - // neither mKeyguardTokenWatcher.acquired() or released() would |
5107 | | - // be called. In that case mKeyguardDisabled will be false here |
5108 | | - // and we have nothing to wait for. |
5109 | | - while (mKeyguardDisabled) { |
5110 | | - try { |
5111 | | - mKeyguardTokenWatcher.wait(); |
5112 | | - } catch (InterruptedException e) { |
5113 | | - Thread.currentThread().interrupt(); |
5114 | | - } |
5115 | | - } |
5116 | | - } |
5117 | | - } |
| 5047 | + mKeyguardDisableHandler.sendMessage(mKeyguardDisableHandler.obtainMessage( |
| 5048 | + KeyguardDisableHandler.KEYGUARD_REENABLE, token)); |
5118 | 5049 | } |
5119 | 5050 |
|
5120 | 5051 | /** |
@@ -10416,7 +10347,6 @@ public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
10416 | 10347 | // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection). |
10417 | 10348 | public void monitor() { |
10418 | 10349 | synchronized (mWindowMap) { } |
10419 | | - synchronized (mKeyguardTokenWatcher) { } |
10420 | 10350 | } |
10421 | 10351 |
|
10422 | 10352 | public interface OnHardKeyboardStatusChangeListener { |
|
0 commit comments