• 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 android.content.ContentResolver;
20 import android.content.res.Configuration;
21 import android.graphics.Rect;
22 import android.provider.Settings;
23 
24 import com.android.systemui.R;
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 RecentsImplementation mImpl;
37 
38     @Override
start()39     public void start() {
40         getComponent(CommandQueue.class).addCallback(this);
41         putComponent(Recents.class, this);
42         mImpl = createRecentsImplementationFromConfig();
43         mImpl.onStart(mContext, this);
44     }
45 
46     @Override
onBootCompleted()47     public void onBootCompleted() {
48         mImpl.onBootCompleted();
49     }
50 
51     @Override
onConfigurationChanged(Configuration newConfig)52     public void onConfigurationChanged(Configuration newConfig) {
53         mImpl.onConfigurationChanged(newConfig);
54     }
55 
56     @Override
appTransitionFinished(int displayId)57     public void appTransitionFinished(int displayId) {
58         if (mContext.getDisplayId() == displayId) {
59             mImpl.onAppTransitionFinished();
60         }
61     }
62 
growRecents()63     public void growRecents() {
64         mImpl.growRecents();
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 
splitPrimaryTask(int stackCreateMode, Rect initialBounds, int metricsDockAction)122     public boolean splitPrimaryTask(int stackCreateMode, Rect initialBounds,
123             int metricsDockAction) {
124         // Ensure the device has been provisioned before allowing the user to interact with
125         // recents
126         if (!isUserSetup()) {
127             return false;
128         }
129 
130         return mImpl.splitPrimaryTask(stackCreateMode, initialBounds, metricsDockAction);
131     }
132 
133     /**
134      * @return whether this device is provisioned and the current user is set up.
135      */
isUserSetup()136     private boolean isUserSetup() {
137         ContentResolver cr = mContext.getContentResolver();
138         return (Settings.Global.getInt(cr, Settings.Global.DEVICE_PROVISIONED, 0) != 0) &&
139                 (Settings.Secure.getInt(cr, Settings.Secure.USER_SETUP_COMPLETE, 0) != 0);
140     }
141 
142     /**
143      * @return The recents implementation from the config.
144      */
createRecentsImplementationFromConfig()145     private RecentsImplementation createRecentsImplementationFromConfig() {
146         final String clsName = mContext.getString(R.string.config_recentsComponent);
147         if (clsName == null || clsName.length() == 0) {
148             throw new RuntimeException("No recents component configured", null);
149         }
150         Class<?> cls = null;
151         try {
152             cls = mContext.getClassLoader().loadClass(clsName);
153         } catch (Throwable t) {
154             throw new RuntimeException("Error loading recents component: " + clsName, t);
155         }
156         try {
157             RecentsImplementation impl = (RecentsImplementation) cls.newInstance();
158             return impl;
159         } catch (Throwable t) {
160             throw new RuntimeException("Error creating recents component: " + clsName, t);
161         }
162     }
163 
164     @Override
dump(FileDescriptor fd, PrintWriter pw, String[] args)165     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
166         mImpl.dump(pw);
167     }
168 }
169