Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 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 | |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 19 | import android.content.ContentResolver; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 20 | import android.content.res.Configuration; |
Jorim Jaggi | 9ea2f7b | 2015-11-23 18:08:28 -0800 | [diff] [blame] | 21 | import android.graphics.Rect; |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 22 | import android.provider.Settings; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 23 | |
Jorim Jaggi | aa6c574 | 2016-03-01 14:10:14 +0100 | [diff] [blame] | 24 | import com.android.systemui.R; |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 25 | import com.android.systemui.SystemUI; |
Jason Monk | 764da99 | 2017-02-02 14:11:20 -0500 | [diff] [blame] | 26 | import com.android.systemui.statusbar.CommandQueue; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 27 | |
Winson Chung | ee69756 | 2017-05-18 14:29:43 -0700 | [diff] [blame] | 28 | import java.io.FileDescriptor; |
| 29 | import java.io.PrintWriter; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 30 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 31 | /** |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 32 | * A proxy to a Recents implementation. |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 33 | */ |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 34 | public class Recents extends SystemUI implements CommandQueue.Callbacks { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 35 | |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 36 | private RecentsImplementation mImpl; |
Winson | c742f97 | 2015-11-12 11:32:21 -0800 | [diff] [blame] | 37 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 38 | @Override |
| 39 | public void start() { |
Jason Monk | d7c9855 | 2018-12-04 11:14:50 -0500 | [diff] [blame] | 40 | getComponent(CommandQueue.class).addCallback(this); |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 41 | putComponent(Recents.class, this); |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 42 | mImpl = createRecentsImplementationFromConfig(); |
| 43 | mImpl.onStart(mContext, this); |
Winson Chung | 5abdceb | 2014-06-05 10:58:05 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 46 | @Override |
Winson Chung | 8bf05af | 2014-09-29 13:42:49 -0700 | [diff] [blame] | 47 | public void onBootCompleted() { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 48 | mImpl.onBootCompleted(); |
Winson Chung | 8bf05af | 2014-09-29 13:42:49 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 51 | @Override |
| 52 | public void onConfigurationChanged(Configuration newConfig) { |
| 53 | mImpl.onConfigurationChanged(newConfig); |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 56 | @Override |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 57 | public void appTransitionFinished(int displayId) { |
| 58 | if (mContext.getDisplayId() == displayId) { |
| 59 | mImpl.onAppTransitionFinished(); |
| 60 | } |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | public void growRecents() { |
| 64 | mImpl.growRecents(); |
| 65 | } |
| 66 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 67 | @Override |
Winson Chung | dff7a73 | 2017-12-11 12:17:06 -0800 | [diff] [blame] | 68 | public void showRecentApps(boolean triggeredFromAltTab) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 69 | // Ensure the device has been provisioned before allowing the user to interact with |
| 70 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 71 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 72 | return; |
| 73 | } |
| 74 | |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 75 | mImpl.showRecentApps(triggeredFromAltTab); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 76 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 77 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 78 | @Override |
Jason Monk | 764da99 | 2017-02-02 14:11:20 -0500 | [diff] [blame] | 79 | public void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 80 | // Ensure the device has been provisioned before allowing the user to interact with |
| 81 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 82 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 83 | return; |
| 84 | } |
| 85 | |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 86 | mImpl.hideRecentApps(triggeredFromAltTab, triggeredFromHomeKey); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 87 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 88 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 89 | @Override |
Winson Chung | ebe1ba1 | 2017-05-18 15:47:14 -0700 | [diff] [blame] | 90 | public void toggleRecentApps() { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 91 | // Ensure the device has been provisioned before allowing the user to interact with |
| 92 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 93 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 94 | return; |
| 95 | } |
| 96 | |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 97 | mImpl.toggleRecentApps(); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 98 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 99 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 100 | @Override |
Winson Chung | ebe1ba1 | 2017-05-18 15:47:14 -0700 | [diff] [blame] | 101 | public void preloadRecentApps() { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 102 | // Ensure the device has been provisioned before allowing the user to interact with |
| 103 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 104 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 105 | return; |
| 106 | } |
| 107 | |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 108 | mImpl.preloadRecentApps(); |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 111 | @Override |
Jason Monk | 764da99 | 2017-02-02 14:11:20 -0500 | [diff] [blame] | 112 | public void cancelPreloadRecentApps() { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 113 | // Ensure the device has been provisioned before allowing the user to interact with |
| 114 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 115 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 116 | return; |
| 117 | } |
| 118 | |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 119 | mImpl.cancelPreloadRecentApps(); |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 122 | public boolean splitPrimaryTask(int stackCreateMode, Rect initialBounds, |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 123 | int metricsDockAction) { |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 124 | // Ensure the device has been provisioned before allowing the user to interact with |
| 125 | // recents |
| 126 | if (!isUserSetup()) { |
| 127 | return false; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 128 | } |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 129 | |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 130 | return mImpl.splitPrimaryTask(stackCreateMode, initialBounds, metricsDockAction); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 131 | } |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 132 | |
| 133 | /** |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 134 | * @return whether this device is provisioned and the current user is set up. |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 135 | */ |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 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); |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 140 | } |
| 141 | |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 142 | /** |
| 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 Chung | ee69756 | 2017-05-18 14:29:43 -0700 | [diff] [blame] | 164 | @Override |
| 165 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 166 | mImpl.dump(pw); |
Winson Chung | ee69756 | 2017-05-18 14:29:43 -0700 | [diff] [blame] | 167 | } |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 168 | } |