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 android.content.ContentResolver;
20 import android.content.Context;
21 import android.content.res.Configuration;
22 import android.graphics.Rect;
23 import android.provider.Settings;
24 
25 import com.android.systemui.SystemUI;
26 import com.android.systemui.statusbar.CommandQueue;
27 
28 import java.io.FileDescriptor;
29 import java.io.PrintWriter;
30 
31 /**
32  * A proxy to a Recents implementation.
33  */
34 public class Recents extends SystemUI implements CommandQueue.Callbacks {
35 
36     private final RecentsImplementation mImpl;
37     private final CommandQueue mCommandQueue;
38 
Recents(Context context, RecentsImplementation impl, CommandQueue commandQueue)39     public Recents(Context context, RecentsImplementation impl, CommandQueue commandQueue) {
40         super(context);
41         mImpl = impl;
42         mCommandQueue = commandQueue;
43     }
44 
45     @Override
start()46     public void start() {
47         mCommandQueue.addCallback(this);
48         mImpl.onStart(mContext);
49     }
50 
51     @Override
onBootCompleted()52     public void onBootCompleted() {
53         mImpl.onBootCompleted();
54     }
55 
56     @Override
onConfigurationChanged(Configuration newConfig)57     public void onConfigurationChanged(Configuration newConfig) {
58         mImpl.onConfigurationChanged(newConfig);
59     }
60 
61     @Override
appTransitionFinished(int displayId)62     public void appTransitionFinished(int displayId) {
63         if (mContext.getDisplayId() == displayId) {
64             mImpl.onAppTransitionFinished();
65         }
66     }
67 
growRecents()68     public void growRecents() {
69         mImpl.growRecents();
70     }
71 
72     @Override
showRecentApps(boolean triggeredFromAltTab)73     public void showRecentApps(boolean triggeredFromAltTab) {
74         // Ensure the device has been provisioned before allowing the user to interact with
75         // recents
76         if (!isUserSetup()) {
77             return;
78         }
79 
80         mImpl.showRecentApps(triggeredFromAltTab);
81     }
82 
83     @Override
hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey)84     public void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
85         // Ensure the device has been provisioned before allowing the user to interact with
86         // recents
87         if (!isUserSetup()) {
88             return;
89         }
90 
91         mImpl.hideRecentApps(triggeredFromAltTab, triggeredFromHomeKey);
92     }
93 
94     @Override
toggleRecentApps()95     public void toggleRecentApps() {
96         // Ensure the device has been provisioned before allowing the user to interact with
97         // recents
98         if (!isUserSetup()) {
99             return;
100         }
101 
102         mImpl.toggleRecentApps();
103     }
104 
105     @Override
preloadRecentApps()106     public void preloadRecentApps() {
107         // Ensure the device has been provisioned before allowing the user to interact with
108         // recents
109         if (!isUserSetup()) {
110             return;
111         }
112 
113         mImpl.preloadRecentApps();
114     }
115 
116     @Override
cancelPreloadRecentApps()117     public void cancelPreloadRecentApps() {
118         // Ensure the device has been provisioned before allowing the user to interact with
119         // recents
120         if (!isUserSetup()) {
121             return;
122         }
123 
124         mImpl.cancelPreloadRecentApps();
125     }
126 
splitPrimaryTask(int stackCreateMode, Rect initialBounds, int metricsDockAction)127     public boolean splitPrimaryTask(int stackCreateMode, Rect initialBounds,
128             int metricsDockAction) {
129         // Ensure the device has been provisioned before allowing the user to interact with
130         // recents
131         if (!isUserSetup()) {
132             return false;
133         }
134 
135         return mImpl.splitPrimaryTask(stackCreateMode, initialBounds, metricsDockAction);
136     }
137 
138     /**
139      * @return whether this device is provisioned and the current user is set up.
140      */
isUserSetup()141     private boolean isUserSetup() {
142         ContentResolver cr = mContext.getContentResolver();
143         return (Settings.Global.getInt(cr, Settings.Global.DEVICE_PROVISIONED, 0) != 0) &&
144                 (Settings.Secure.getInt(cr, Settings.Secure.USER_SETUP_COMPLETE, 0) != 0);
145     }
146 
147     @Override
dump(FileDescriptor fd, PrintWriter pw, String[] args)148     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
149         mImpl.dump(pw);
150     }
151 }
152