• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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.systemui.recents;
18 
19 import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
20 import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
21 import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
22 
23 import android.app.ActivityManager;
24 import android.app.trust.TrustManager;
25 import android.content.Context;
26 import android.graphics.Point;
27 import android.graphics.Rect;
28 import android.hardware.display.DisplayManager;
29 import android.os.Handler;
30 import android.os.RemoteException;
31 import android.util.Log;
32 import android.view.Display;
33 import android.widget.Toast;
34 
35 import com.android.systemui.Dependency;
36 import com.android.systemui.R;
37 import com.android.systemui.SysUiServiceProvider;
38 import com.android.systemui.shared.recents.IOverviewProxy;
39 import com.android.systemui.shared.system.ActivityManagerWrapper;
40 import com.android.systemui.stackdivider.Divider;
41 import com.android.systemui.statusbar.phone.StatusBar;
42 
43 /**
44  * An implementation of the Recents interface which proxies to the OverviewProxyService.
45  */
46 public class OverviewProxyRecentsImpl implements RecentsImplementation {
47 
48     private final static String TAG = "OverviewProxyRecentsImpl";
49 
50     private SysUiServiceProvider mSysUiServiceProvider;
51     private Context mContext;
52     private Handler mHandler;
53     private TrustManager mTrustManager;
54     private OverviewProxyService mOverviewProxyService;
55 
56     @Override
onStart(Context context, SysUiServiceProvider sysUiServiceProvider)57     public void onStart(Context context, SysUiServiceProvider sysUiServiceProvider) {
58         mContext = context;
59         mSysUiServiceProvider = sysUiServiceProvider;
60         mHandler = new Handler();
61         mTrustManager = (TrustManager) context.getSystemService(Context.TRUST_SERVICE);
62         mOverviewProxyService = Dependency.get(OverviewProxyService.class);
63     }
64 
65     @Override
showRecentApps(boolean triggeredFromAltTab)66     public void showRecentApps(boolean triggeredFromAltTab) {
67         IOverviewProxy overviewProxy = mOverviewProxyService.getProxy();
68         if (overviewProxy != null) {
69             try {
70                 overviewProxy.onOverviewShown(triggeredFromAltTab);
71                 return;
72             } catch (RemoteException e) {
73                 Log.e(TAG, "Failed to send overview show event to launcher.", e);
74             }
75         } else {
76             // Do nothing
77         }
78     }
79 
80     @Override
hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey)81     public void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
82         IOverviewProxy overviewProxy = mOverviewProxyService.getProxy();
83         if (overviewProxy != null) {
84             try {
85                 overviewProxy.onOverviewHidden(triggeredFromAltTab, triggeredFromHomeKey);
86                 return;
87             } catch (RemoteException e) {
88                 Log.e(TAG, "Failed to send overview hide event to launcher.", e);
89             }
90         } else {
91             // Do nothing
92         }
93     }
94 
95     @Override
toggleRecentApps()96     public void toggleRecentApps() {
97         // If connected to launcher service, let it handle the toggle logic
98         IOverviewProxy overviewProxy = mOverviewProxyService.getProxy();
99         if (overviewProxy != null) {
100             final Runnable toggleRecents = () -> {
101                 try {
102                     if (mOverviewProxyService.getProxy() != null) {
103                         mOverviewProxyService.getProxy().onOverviewToggle();
104                     }
105                 } catch (RemoteException e) {
106                     Log.e(TAG, "Cannot send toggle recents through proxy service.", e);
107                 }
108             };
109             // Preload only if device for current user is unlocked
110             final StatusBar statusBar = mSysUiServiceProvider.getComponent(StatusBar.class);
111             if (statusBar != null && statusBar.isKeyguardShowing()) {
112                 statusBar.executeRunnableDismissingKeyguard(() -> {
113                         // Flush trustmanager before checking device locked per user
114                         mTrustManager.reportKeyguardShowingChanged();
115                         mHandler.post(toggleRecents);
116                     }, null,  true /* dismissShade */, false /* afterKeyguardGone */,
117                     true /* deferred */);
118             } else {
119                 toggleRecents.run();
120             }
121             return;
122         } else {
123             // Do nothing
124         }
125     }
126 
127     @Override
splitPrimaryTask(int stackCreateMode, Rect initialBounds, int metricsDockAction)128     public boolean splitPrimaryTask(int stackCreateMode, Rect initialBounds,
129             int metricsDockAction) {
130         Point realSize = new Point();
131         if (initialBounds == null) {
132             mContext.getSystemService(DisplayManager.class).getDisplay(Display.DEFAULT_DISPLAY)
133                     .getRealSize(realSize);
134             initialBounds = new Rect(0, 0, realSize.x, realSize.y);
135         }
136 
137         ActivityManager.RunningTaskInfo runningTask =
138                 ActivityManagerWrapper.getInstance().getRunningTask();
139         final int activityType = runningTask != null
140                 ? runningTask.configuration.windowConfiguration.getActivityType()
141                 : ACTIVITY_TYPE_UNDEFINED;
142         boolean screenPinningActive = ActivityManagerWrapper.getInstance().isScreenPinningActive();
143         boolean isRunningTaskInHomeOrRecentsStack =
144                 activityType == ACTIVITY_TYPE_HOME || activityType == ACTIVITY_TYPE_RECENTS;
145         if (runningTask != null && !isRunningTaskInHomeOrRecentsStack && !screenPinningActive) {
146             if (runningTask.supportsSplitScreenMultiWindow) {
147                 if (ActivityManagerWrapper.getInstance().setTaskWindowingModeSplitScreenPrimary(
148                         runningTask.id, stackCreateMode, initialBounds)) {
149                     // The overview service is handling split screen, so just skip the wait for the
150                     // first draw and notify the divider to start animating now
151                     final Divider divider = mSysUiServiceProvider.getComponent(Divider.class);
152                     if (divider != null) {
153                         divider.onRecentsDrawn();
154                     }
155                     return true;
156                 }
157             } else {
158                 Toast.makeText(mContext, R.string.dock_non_resizeble_failed_to_dock_text,
159                         Toast.LENGTH_SHORT).show();
160             }
161         }
162         return false;
163     }
164 }
165