blob: 5f37cc4520a3c1097f4655407526a48dfac50ac6 [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;
Dave Mankoffa5d8a392019-10-10 12:21:09 -040020import android.content.Context;
Winson Chung7048fea2014-03-18 12:21:24 -070021import android.content.res.Configuration;
Jorim Jaggi9ea2f7b2015-11-23 18:08:28 -080022import android.graphics.Rect;
Winsone9243562015-11-10 16:07:13 -080023import android.provider.Settings;
Gus Prevasab336792018-11-14 13:52:20 -050024
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
Dave Mankoff898e1bb2019-09-25 17:54:19 -040036 private final RecentsImplementation mImpl;
Dave Mankoffbcaca8a2019-10-31 18:04:08 -040037 private final CommandQueue mCommandQueue;
Dave Mankoff898e1bb2019-09-25 17:54:19 -040038
Dave Mankoffbcaca8a2019-10-31 18:04:08 -040039 public Recents(Context context, RecentsImplementation impl, CommandQueue commandQueue) {
Dave Mankoffa5d8a392019-10-10 12:21:09 -040040 super(context);
Dave Mankoff898e1bb2019-09-25 17:54:19 -040041 mImpl = impl;
Dave Mankoffbcaca8a2019-10-31 18:04:08 -040042 mCommandQueue = commandQueue;
Dave Mankoff898e1bb2019-09-25 17:54:19 -040043 }
Winsonc742f972015-11-12 11:32:21 -080044
Jorim Jaggid61f2272014-12-19 20:35:35 +010045 @Override
46 public void start() {
Dave Mankoffbcaca8a2019-10-31 18:04:08 -040047 mCommandQueue.addCallback(this);
Dave Mankoff95754e72019-11-14 11:39:18 -050048 mImpl.onStart(mContext);
Winson Chung5abdceb2014-06-05 10:58:05 -070049 }
50
Jorim Jaggid61f2272014-12-19 20:35:35 +010051 @Override
Winson Chung8bf05af2014-09-29 13:42:49 -070052 public void onBootCompleted() {
Winson190fe3bf2015-10-20 14:57:24 -070053 mImpl.onBootCompleted();
Winson Chung8bf05af2014-09-29 13:42:49 -070054 }
55
Winson Chung2dbcf092018-10-24 13:00:41 -070056 @Override
57 public void onConfigurationChanged(Configuration newConfig) {
58 mImpl.onConfigurationChanged(newConfig);
Winson Chung67f5c8b2018-09-24 12:09:19 -070059 }
60
Winson Chung2dbcf092018-10-24 13:00:41 -070061 @Override
Charles Chenf3d295c2018-11-30 18:15:21 +080062 public void appTransitionFinished(int displayId) {
63 if (mContext.getDisplayId() == displayId) {
64 mImpl.onAppTransitionFinished();
65 }
Winson Chung2dbcf092018-10-24 13:00:41 -070066 }
67
68 public void growRecents() {
69 mImpl.growRecents();
70 }
71
Jorim Jaggid61f2272014-12-19 20:35:35 +010072 @Override
Winson Chungdff7a732017-12-11 12:17:06 -080073 public void showRecentApps(boolean triggeredFromAltTab) {
Winsone9243562015-11-10 16:07:13 -080074 // Ensure the device has been provisioned before allowing the user to interact with
75 // recents
Winsone6309aa2016-01-08 11:19:21 -080076 if (!isUserSetup()) {
Winsone9243562015-11-10 16:07:13 -080077 return;
78 }
79
Winson Chung2dbcf092018-10-24 13:00:41 -070080 mImpl.showRecentApps(triggeredFromAltTab);
Winson Chung2002cf52014-12-08 17:26:44 -080081 }
Jorim Jaggid61f2272014-12-19 20:35:35 +010082
Jorim Jaggid61f2272014-12-19 20:35:35 +010083 @Override
Jason Monk764da992017-02-02 14:11:20 -050084 public void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
Winsone9243562015-11-10 16:07:13 -080085 // Ensure the device has been provisioned before allowing the user to interact with
86 // recents
Winsone6309aa2016-01-08 11:19:21 -080087 if (!isUserSetup()) {
Winsone9243562015-11-10 16:07:13 -080088 return;
89 }
90
Winson Chung2dbcf092018-10-24 13:00:41 -070091 mImpl.hideRecentApps(triggeredFromAltTab, triggeredFromHomeKey);
Winson Chung2002cf52014-12-08 17:26:44 -080092 }
Jorim Jaggid61f2272014-12-19 20:35:35 +010093
Jorim Jaggid61f2272014-12-19 20:35:35 +010094 @Override
Winson Chungebe1ba12017-05-18 15:47:14 -070095 public void toggleRecentApps() {
Winsone9243562015-11-10 16:07:13 -080096 // Ensure the device has been provisioned before allowing the user to interact with
97 // recents
Winsone6309aa2016-01-08 11:19:21 -080098 if (!isUserSetup()) {
Winsone9243562015-11-10 16:07:13 -080099 return;
100 }
101
Winson Chung2dbcf092018-10-24 13:00:41 -0700102 mImpl.toggleRecentApps();
Winson Chung2002cf52014-12-08 17:26:44 -0800103 }
Jorim Jaggid61f2272014-12-19 20:35:35 +0100104
Jorim Jaggid61f2272014-12-19 20:35:35 +0100105 @Override
Winson Chungebe1ba12017-05-18 15:47:14 -0700106 public void preloadRecentApps() {
Winsone9243562015-11-10 16:07:13 -0800107 // Ensure the device has been provisioned before allowing the user to interact with
108 // recents
Winsone6309aa2016-01-08 11:19:21 -0800109 if (!isUserSetup()) {
Winsone9243562015-11-10 16:07:13 -0800110 return;
111 }
112
Winson Chung2dbcf092018-10-24 13:00:41 -0700113 mImpl.preloadRecentApps();
Winson Chung7048fea2014-03-18 12:21:24 -0700114 }
115
Jorim Jaggid61f2272014-12-19 20:35:35 +0100116 @Override
Jason Monk764da992017-02-02 14:11:20 -0500117 public void cancelPreloadRecentApps() {
Winsone9243562015-11-10 16:07:13 -0800118 // Ensure the device has been provisioned before allowing the user to interact with
119 // recents
Winsone6309aa2016-01-08 11:19:21 -0800120 if (!isUserSetup()) {
Winsone9243562015-11-10 16:07:13 -0800121 return;
122 }
123
Winson Chung2dbcf092018-10-24 13:00:41 -0700124 mImpl.cancelPreloadRecentApps();
Winson Chungb1f74992014-08-08 12:53:09 -0700125 }
126
Winson Chung67f5c8b2018-09-24 12:09:19 -0700127 public boolean splitPrimaryTask(int stackCreateMode, Rect initialBounds,
Jorim Jaggi29379ec2016-04-11 23:43:42 -0700128 int metricsDockAction) {
Winsone6309aa2016-01-08 11:19:21 -0800129 // Ensure the device has been provisioned before allowing the user to interact with
130 // recents
131 if (!isUserSetup()) {
132 return false;
Jorim Jaggidd98d412015-11-18 15:57:38 -0800133 }
Winsone6309aa2016-01-08 11:19:21 -0800134
Winson Chung2dbcf092018-10-24 13:00:41 -0700135 return mImpl.splitPrimaryTask(stackCreateMode, initialBounds, metricsDockAction);
Winson190fe3bf2015-10-20 14:57:24 -0700136 }
Winson4727ab92015-11-02 14:35:34 -0800137
138 /**
Winsone6309aa2016-01-08 11:19:21 -0800139 * @return whether this device is provisioned and the current user is set up.
Winsone9243562015-11-10 16:07:13 -0800140 */
Winsone6309aa2016-01-08 11:19:21 -0800141 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);
Winsone9243562015-11-10 16:07:13 -0800145 }
146
Winson Chungee697562017-05-18 14:29:43 -0700147 @Override
148 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Winson Chung2dbcf092018-10-24 13:00:41 -0700149 mImpl.dump(pw);
Winson Chungee697562017-05-18 14:29:43 -0700150 }
Winson Chung7048fea2014-03-18 12:21:24 -0700151}