1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.server.am;
18 
19 import android.graphics.Rect;
20 import android.os.Handler;
21 
22 import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS;
23 
24 /**
25  * When resizing the docked stack, a caller can temporarily supply task bounds that are different
26  * from the stack bounds. In order to return to a sane state if the caller crashes or has a bug,
27  * this class manages this cycle.
28  */
29 class ResizeDockedStackTimeout {
30 
31     private static final long TIMEOUT_MS = 10 * 1000;
32     private final ActivityManagerService mService;
33     private final ActivityStackSupervisor mSupervisor;
34     private final Handler mHandler;
35     private final Rect mCurrentDockedBounds = new Rect();
36 
37     private final Runnable mTimeoutRunnable = new Runnable() {
38         @Override
39         public void run() {
40             synchronized (mService) {
41                 mSupervisor.resizeDockedStackLocked(mCurrentDockedBounds, null, null, null, null,
42                         PRESERVE_WINDOWS);
43             }
44         }
45     };
46 
ResizeDockedStackTimeout(ActivityManagerService service, ActivityStackSupervisor supervisor, Handler handler)47     ResizeDockedStackTimeout(ActivityManagerService service, ActivityStackSupervisor supervisor,
48             Handler handler) {
49         mService = service;
50         mSupervisor = supervisor;
51         mHandler = handler;
52     }
53 
notifyResizing(Rect dockedBounds, boolean hasTempBounds)54     void notifyResizing(Rect dockedBounds, boolean hasTempBounds) {
55         mHandler.removeCallbacks(mTimeoutRunnable);
56         if (!hasTempBounds) {
57             return;
58         }
59         mCurrentDockedBounds.set(dockedBounds);
60         mHandler.postDelayed(mTimeoutRunnable, TIMEOUT_MS);
61     }
62 
63 }
64