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