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