blob: 0fc4fe72bd548d2b723ea16f2c1c5dd74ea5cfb5 [file] [log] [blame]
Winson Chung7048fea2014-03-18 12:21:24 -07001/*
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
17package com.android.systemui.recents;
18
Winsone6309aa2016-01-08 11:19:21 -080019import android.content.ContentResolver;
Winson Chung7048fea2014-03-18 12:21:24 -070020import android.content.res.Configuration;
Jorim Jaggi9ea2f7b2015-11-23 18:08:28 -080021import android.graphics.Rect;
Winsone9243562015-11-10 16:07:13 -080022import android.provider.Settings;
Gus Prevasab336792018-11-14 13:52:20 -050023
Jorim Jaggiaa6c5742016-03-01 14:10:14 +010024import com.android.systemui.R;
Jorim Jaggid61f2272014-12-19 20:35:35 +010025import com.android.systemui.SystemUI;
Jason Monk764da992017-02-02 14:11:20 -050026import com.android.systemui.statusbar.CommandQueue;
Gus Prevasab336792018-11-14 13:52:20 -050027
Winson Chungee697562017-05-18 14:29:43 -070028import java.io.FileDescriptor;
29import java.io.PrintWriter;
Winson Chung740c3ac2014-11-12 16:14:38 -080030
Winson190fe3bf2015-10-20 14:57:24 -070031/**
Winson Chung2dbcf092018-10-24 13:00:41 -070032 * A proxy to a Recents implementation.
Winson190fe3bf2015-10-20 14:57:24 -070033 */
Winson Chung2dbcf092018-10-24 13:00:41 -070034public class Recents extends SystemUI implements CommandQueue.Callbacks {
Winson190fe3bf2015-10-20 14:57:24 -070035
Winson Chung2dbcf092018-10-24 13:00:41 -070036 private RecentsImplementation mImpl;
Winsonc742f972015-11-12 11:32:21 -080037
Jorim Jaggid61f2272014-12-19 20:35:35 +010038 @Override
39 public void start() {
Jason Monkd7c98552018-12-04 11:14:50 -050040 getComponent(CommandQueue.class).addCallback(this);
Jorim Jaggid61f2272014-12-19 20:35:35 +010041 putComponent(Recents.class, this);
Winson Chung2dbcf092018-10-24 13:00:41 -070042 mImpl = createRecentsImplementationFromConfig();
43 mImpl.onStart(mContext, this);
Winson Chung5abdceb2014-06-05 10:58:05 -070044 }
45
Jorim Jaggid61f2272014-12-19 20:35:35 +010046 @Override
Winson Chung8bf05af2014-09-29 13:42:49 -070047 public void onBootCompleted() {
Winson190fe3bf2015-10-20 14:57:24 -070048 mImpl.onBootCompleted();
Winson Chung8bf05af2014-09-29 13:42:49 -070049 }
50
Winson Chung2dbcf092018-10-24 13:00:41 -070051 @Override
52 public void onConfigurationChanged(Configuration newConfig) {
53 mImpl.onConfigurationChanged(newConfig);
Winson Chung67f5c8b2018-09-24 12:09:19 -070054 }
55
Winson Chung2dbcf092018-10-24 13:00:41 -070056 @Override
Charles Chenf3d295c2018-11-30 18:15:21 +080057 public void appTransitionFinished(int displayId) {
58 if (mContext.getDisplayId() == displayId) {
59 mImpl.onAppTransitionFinished();
60 }
Winson Chung2dbcf092018-10-24 13:00:41 -070061 }
62
63 public void growRecents() {
64 mImpl.growRecents();
65 }
66
Jorim Jaggid61f2272014-12-19 20:35:35 +010067 @Override
Winson Chungdff7a732017-12-11 12:17:06 -080068 public void showRecentApps(boolean triggeredFromAltTab) {
Winsone9243562015-11-10 16:07:13 -080069 // Ensure the device has been provisioned before allowing the user to interact with
70 // recents
Winsone6309aa2016-01-08 11:19:21 -080071 if (!isUserSetup()) {
Winsone9243562015-11-10 16:07:13 -080072 return;
73 }
74
Winson Chung2dbcf092018-10-24 13:00:41 -070075 mImpl.showRecentApps(triggeredFromAltTab);
Winson Chung2002cf52014-12-08 17:26:44 -080076 }
Jorim Jaggid61f2272014-12-19 20:35:35 +010077
Jorim Jaggid61f2272014-12-19 20:35:35 +010078 @Override
Jason Monk764da992017-02-02 14:11:20 -050079 public void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
Winsone9243562015-11-10 16:07:13 -080080 // Ensure the device has been provisioned before allowing the user to interact with
81 // recents
Winsone6309aa2016-01-08 11:19:21 -080082 if (!isUserSetup()) {
Winsone9243562015-11-10 16:07:13 -080083 return;
84 }
85
Winson Chung2dbcf092018-10-24 13:00:41 -070086 mImpl.hideRecentApps(triggeredFromAltTab, triggeredFromHomeKey);
Winson Chung2002cf52014-12-08 17:26:44 -080087 }
Jorim Jaggid61f2272014-12-19 20:35:35 +010088
Jorim Jaggid61f2272014-12-19 20:35:35 +010089 @Override
Winson Chungebe1ba12017-05-18 15:47:14 -070090 public void toggleRecentApps() {
Winsone9243562015-11-10 16:07:13 -080091 // Ensure the device has been provisioned before allowing the user to interact with
92 // recents
Winsone6309aa2016-01-08 11:19:21 -080093 if (!isUserSetup()) {
Winsone9243562015-11-10 16:07:13 -080094 return;
95 }
96
Winson Chung2dbcf092018-10-24 13:00:41 -070097 mImpl.toggleRecentApps();
Winson Chung2002cf52014-12-08 17:26:44 -080098 }
Jorim Jaggid61f2272014-12-19 20:35:35 +010099
Jorim Jaggid61f2272014-12-19 20:35:35 +0100100 @Override
Winson Chungebe1ba12017-05-18 15:47:14 -0700101 public void preloadRecentApps() {
Winsone9243562015-11-10 16:07:13 -0800102 // Ensure the device has been provisioned before allowing the user to interact with
103 // recents
Winsone6309aa2016-01-08 11:19:21 -0800104 if (!isUserSetup()) {
Winsone9243562015-11-10 16:07:13 -0800105 return;
106 }
107
Winson Chung2dbcf092018-10-24 13:00:41 -0700108 mImpl.preloadRecentApps();
Winson Chung7048fea2014-03-18 12:21:24 -0700109 }
110
Jorim Jaggid61f2272014-12-19 20:35:35 +0100111 @Override
Jason Monk764da992017-02-02 14:11:20 -0500112 public void cancelPreloadRecentApps() {
Winsone9243562015-11-10 16:07:13 -0800113 // Ensure the device has been provisioned before allowing the user to interact with
114 // recents
Winsone6309aa2016-01-08 11:19:21 -0800115 if (!isUserSetup()) {
Winsone9243562015-11-10 16:07:13 -0800116 return;
117 }
118
Winson Chung2dbcf092018-10-24 13:00:41 -0700119 mImpl.cancelPreloadRecentApps();
Winson Chungb1f74992014-08-08 12:53:09 -0700120 }
121
Winson Chung67f5c8b2018-09-24 12:09:19 -0700122 public boolean splitPrimaryTask(int stackCreateMode, Rect initialBounds,
Jorim Jaggi29379ec2016-04-11 23:43:42 -0700123 int metricsDockAction) {
Winsone6309aa2016-01-08 11:19:21 -0800124 // Ensure the device has been provisioned before allowing the user to interact with
125 // recents
126 if (!isUserSetup()) {
127 return false;
Jorim Jaggidd98d412015-11-18 15:57:38 -0800128 }
Winsone6309aa2016-01-08 11:19:21 -0800129
Winson Chung2dbcf092018-10-24 13:00:41 -0700130 return mImpl.splitPrimaryTask(stackCreateMode, initialBounds, metricsDockAction);
Winson190fe3bf2015-10-20 14:57:24 -0700131 }
Winson4727ab92015-11-02 14:35:34 -0800132
133 /**
Winsone6309aa2016-01-08 11:19:21 -0800134 * @return whether this device is provisioned and the current user is set up.
Winsone9243562015-11-10 16:07:13 -0800135 */
Winsone6309aa2016-01-08 11:19:21 -0800136 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);
Winsone9243562015-11-10 16:07:13 -0800140 }
141
Winson Chung2dbcf092018-10-24 13:00:41 -0700142 /**
143 * @return The recents implementation from the config.
144 */
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
Winson Chungee697562017-05-18 14:29:43 -0700164 @Override
165 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Winson Chung2dbcf092018-10-24 13:00:41 -0700166 mImpl.dump(pw);
Winson Chungee697562017-05-18 14:29:43 -0700167 }
Winson Chung7048fea2014-03-18 12:21:24 -0700168}