1 /*
2  * Copyright (C) 2018 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.wm;
18 
19 import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
20 import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
21 
22 import static com.android.server.wm.WindowManagerInternal.AppTransitionListener;
23 
24 import android.app.StatusBarManager;
25 import android.os.IBinder;
26 import android.view.View;
27 
28 import com.android.server.statusbar.StatusBarManagerInternal;
29 
30 /**
31  * Implements status bar specific behavior.
32  */
33 public class StatusBarController extends BarController {
34 
35     private final AppTransitionListener mAppTransitionListener = new AppTransitionListener() {
36 
37         private Runnable mAppTransitionPending = () -> {
38             StatusBarManagerInternal statusBar = getStatusBarInternal();
39             if (statusBar != null) {
40                 statusBar.appTransitionPending(mDisplayId);
41             }
42         };
43 
44         private Runnable mAppTransitionCancelled = () -> {
45             StatusBarManagerInternal statusBar = getStatusBarInternal();
46             if (statusBar != null) {
47                 statusBar.appTransitionCancelled(mDisplayId);
48             }
49         };
50 
51         private Runnable mAppTransitionFinished = () -> {
52             StatusBarManagerInternal statusBar = getStatusBarInternal();
53             if (statusBar != null) {
54                 statusBar.appTransitionFinished(mDisplayId);
55             }
56         };
57 
58         @Override
59         public void onAppTransitionPendingLocked() {
60             mHandler.post(mAppTransitionPending);
61         }
62 
63         @Override
64         public int onAppTransitionStartingLocked(int transit, long duration,
65                 long statusBarAnimationStartTime, long statusBarAnimationDuration) {
66             mHandler.post(() -> {
67                 StatusBarManagerInternal statusBar = getStatusBarInternal();
68                 if (statusBar != null) {
69                     statusBar.appTransitionStarting(mDisplayId,
70                             statusBarAnimationStartTime, statusBarAnimationDuration);
71                 }
72             });
73             return 0;
74         }
75 
76         @Override
77         public void onAppTransitionCancelledLocked(int transit) {
78             mHandler.post(mAppTransitionCancelled);
79         }
80 
81         @Override
82         public void onAppTransitionFinishedLocked(IBinder token) {
83             mHandler.post(mAppTransitionFinished);
84         }
85     };
86 
StatusBarController(int displayId)87     StatusBarController(int displayId) {
88         super("StatusBar",
89                 displayId,
90                 View.STATUS_BAR_TRANSIENT,
91                 View.STATUS_BAR_UNHIDE,
92                 View.STATUS_BAR_TRANSLUCENT,
93                 StatusBarManager.WINDOW_STATUS_BAR,
94                 FLAG_TRANSLUCENT_STATUS,
95                 View.STATUS_BAR_TRANSPARENT);
96     }
97 
setTopAppHidesStatusBar(boolean hidesStatusBar)98     void setTopAppHidesStatusBar(boolean hidesStatusBar) {
99         StatusBarManagerInternal statusBar = getStatusBarInternal();
100         if (statusBar != null) {
101             statusBar.setTopAppHidesStatusBar(hidesStatusBar);
102         }
103     }
104 
105     @Override
skipAnimation()106     protected boolean skipAnimation() {
107         return mWin.getAttrs().height == MATCH_PARENT;
108     }
109 
getAppTransitionListener()110     AppTransitionListener getAppTransitionListener() {
111         return mAppTransitionListener;
112     }
113 }
114