John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [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.statusbar.phone; |
| 18 | |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Adrian Roos | 62692b2 | 2015-09-11 17:46:23 -0700 | [diff] [blame] | 20 | import android.app.PendingIntent; |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 21 | import android.content.ComponentName; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 24 | import android.content.res.Resources; |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 25 | import android.os.Handler; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 26 | import android.os.HandlerThread; |
| 27 | import android.os.Looper; |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 28 | import android.os.Process; |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 29 | import android.os.UserHandle; |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 30 | import android.provider.Settings; |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 31 | import android.provider.Settings.Secure; |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 32 | import android.text.TextUtils; |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 33 | import android.util.Log; |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 34 | import android.view.View; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 35 | |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 36 | import com.android.systemui.R; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 37 | import com.android.systemui.qs.QSTile; |
Jason Monk | d5a204f | 2015-12-21 08:50:01 -0500 | [diff] [blame] | 38 | import com.android.systemui.qs.external.CustomTile; |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 39 | import com.android.systemui.qs.external.TileLifecycleManager; |
Jason Monk | d5a204f | 2015-12-21 08:50:01 -0500 | [diff] [blame] | 40 | import com.android.systemui.qs.external.TileServices; |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 41 | import com.android.systemui.qs.tiles.AirplaneModeTile; |
| 42 | import com.android.systemui.qs.tiles.BatteryTile; |
| 43 | import com.android.systemui.qs.tiles.BluetoothTile; |
| 44 | import com.android.systemui.qs.tiles.CastTile; |
| 45 | import com.android.systemui.qs.tiles.CellularTile; |
| 46 | import com.android.systemui.qs.tiles.ColorInversionTile; |
Jason Monk | 9a4ce13 | 2016-01-21 15:27:17 -0500 | [diff] [blame] | 47 | import com.android.systemui.qs.tiles.DataSaverTile; |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 48 | import com.android.systemui.qs.tiles.DndTile; |
| 49 | import com.android.systemui.qs.tiles.FlashlightTile; |
| 50 | import com.android.systemui.qs.tiles.HotspotTile; |
| 51 | import com.android.systemui.qs.tiles.IntentTile; |
| 52 | import com.android.systemui.qs.tiles.LocationTile; |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 53 | import com.android.systemui.qs.tiles.RotationLockTile; |
| 54 | import com.android.systemui.qs.tiles.UserTile; |
| 55 | import com.android.systemui.qs.tiles.WifiTile; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 56 | import com.android.systemui.qs.tiles.WorkModeTile; |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 57 | import com.android.systemui.statusbar.policy.BatteryController; |
| 58 | import com.android.systemui.statusbar.policy.BluetoothController; |
| 59 | import com.android.systemui.statusbar.policy.CastController; |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 60 | import com.android.systemui.statusbar.policy.NextAlarmController; |
Jason Monk | 5dbd4aa | 2016-02-07 13:13:39 -0500 | [diff] [blame] | 61 | import com.android.systemui.statusbar.policy.NightModeController; |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 62 | import com.android.systemui.statusbar.policy.FlashlightController; |
| 63 | import com.android.systemui.statusbar.policy.HotspotController; |
| 64 | import com.android.systemui.statusbar.policy.KeyguardMonitor; |
| 65 | import com.android.systemui.statusbar.policy.LocationController; |
| 66 | import com.android.systemui.statusbar.policy.NetworkController; |
| 67 | import com.android.systemui.statusbar.policy.RotationLockController; |
| 68 | import com.android.systemui.statusbar.policy.SecurityController; |
| 69 | import com.android.systemui.statusbar.policy.UserInfoController; |
| 70 | import com.android.systemui.statusbar.policy.UserSwitcherController; |
| 71 | import com.android.systemui.statusbar.policy.ZenModeController; |
Jason Monk | 5dbd4aa | 2016-02-07 13:13:39 -0500 | [diff] [blame] | 72 | import com.android.systemui.tuner.NightModeTile; |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 73 | import com.android.systemui.tuner.TunerService; |
| 74 | import com.android.systemui.tuner.TunerService.Tunable; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 75 | |
| 76 | import java.util.ArrayList; |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 77 | import java.util.Arrays; |
| 78 | import java.util.Collection; |
| 79 | import java.util.LinkedHashMap; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 80 | import java.util.List; |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 81 | import java.util.Map; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 82 | |
| 83 | /** Platform implementation of the quick settings tile host **/ |
Jason Monk | d5a204f | 2015-12-21 08:50:01 -0500 | [diff] [blame] | 84 | public final class QSTileHost implements QSTile.Host, Tunable { |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 85 | private static final String TAG = "QSTileHost"; |
| 86 | private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
| 87 | |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 88 | public static final String TILES_SETTING = "sysui_qs_tiles"; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 89 | |
| 90 | private final Context mContext; |
| 91 | private final PhoneStatusBar mStatusBar; |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 92 | private final LinkedHashMap<String, QSTile<?>> mTiles = new LinkedHashMap<>(); |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 93 | protected final ArrayList<String> mTileSpecs = new ArrayList<>(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 94 | private final BluetoothController mBluetooth; |
| 95 | private final LocationController mLocation; |
| 96 | private final RotationLockController mRotation; |
| 97 | private final NetworkController mNetwork; |
| 98 | private final ZenModeController mZen; |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 99 | private final HotspotController mHotspot; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 100 | private final CastController mCast; |
| 101 | private final Looper mLooper; |
Adrian Roos | b83777b | 2014-06-30 15:11:53 +0200 | [diff] [blame] | 102 | private final FlashlightController mFlashlight; |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 103 | private final UserSwitcherController mUserSwitcherController; |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 104 | private final UserInfoController mUserInfoController; |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 105 | private final KeyguardMonitor mKeyguard; |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 106 | private final SecurityController mSecurity; |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 107 | private final BatteryController mBattery; |
Jason Monk | 66c89c1 | 2016-01-06 08:51:26 -0500 | [diff] [blame] | 108 | private final StatusBarIconController mIconController; |
Jason Monk | d5a204f | 2015-12-21 08:50:01 -0500 | [diff] [blame] | 109 | private final TileServices mServices; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 110 | |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 111 | private final List<Callback> mCallbacks = new ArrayList<>(); |
Jason Monk | 5dbd4aa | 2016-02-07 13:13:39 -0500 | [diff] [blame] | 112 | private final NightModeController mNightModeController; |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 113 | private final AutoTileManager mAutoTiles; |
| 114 | private final ManagedProfileController mProfileController; |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 115 | private final NextAlarmController mNextAlarmController; |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 116 | private View mHeader; |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 117 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 118 | public QSTileHost(Context context, PhoneStatusBar statusBar, |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 119 | BluetoothController bluetooth, LocationController location, |
| 120 | RotationLockController rotation, NetworkController network, |
| 121 | ZenModeController zen, HotspotController hotspot, |
| 122 | CastController cast, FlashlightController flashlight, |
| 123 | UserSwitcherController userSwitcher, UserInfoController userInfo, |
| 124 | KeyguardMonitor keyguard, SecurityController security, |
| 125 | BatteryController battery, StatusBarIconController iconController, |
| 126 | NextAlarmController nextAlarmController) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 127 | mContext = context; |
| 128 | mStatusBar = statusBar; |
| 129 | mBluetooth = bluetooth; |
| 130 | mLocation = location; |
| 131 | mRotation = rotation; |
| 132 | mNetwork = network; |
| 133 | mZen = zen; |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 134 | mHotspot = hotspot; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 135 | mCast = cast; |
Adrian Roos | b83777b | 2014-06-30 15:11:53 +0200 | [diff] [blame] | 136 | mFlashlight = flashlight; |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 137 | mUserSwitcherController = userSwitcher; |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 138 | mUserInfoController = userInfo; |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 139 | mKeyguard = keyguard; |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 140 | mSecurity = security; |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 141 | mBattery = battery; |
Jason Monk | 66c89c1 | 2016-01-06 08:51:26 -0500 | [diff] [blame] | 142 | mIconController = iconController; |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 143 | mNextAlarmController = nextAlarmController; |
Jason Monk | 5dbd4aa | 2016-02-07 13:13:39 -0500 | [diff] [blame] | 144 | mNightModeController = new NightModeController(mContext, true); |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 145 | mProfileController = new ManagedProfileController(this); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 146 | |
Jorim Jaggi | 1ecd7cd | 2014-11-03 16:18:03 +0100 | [diff] [blame] | 147 | final HandlerThread ht = new HandlerThread(QSTileHost.class.getSimpleName(), |
| 148 | Process.THREAD_PRIORITY_BACKGROUND); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 149 | ht.start(); |
| 150 | mLooper = ht.getLooper(); |
| 151 | |
Jason Monk | d5a204f | 2015-12-21 08:50:01 -0500 | [diff] [blame] | 152 | mServices = new TileServices(this, mLooper); |
| 153 | |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 154 | TunerService.get(mContext).addTunable(this, TILES_SETTING); |
Rubin Xu | cedcd28 | 2016-02-15 14:44:44 +0000 | [diff] [blame] | 155 | // AutoTileManager can modify mTiles so make sure mTiles has already been initialized. |
| 156 | mAutoTiles = new AutoTileManager(context, this); |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 157 | } |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 158 | |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 159 | public NextAlarmController getNextAlarmController() { |
| 160 | return mNextAlarmController; |
| 161 | } |
| 162 | |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 163 | public void setHeaderView(View view) { |
| 164 | mHeader = view; |
| 165 | } |
| 166 | |
Jason Monk | deba7a4 | 2015-12-08 16:14:10 -0500 | [diff] [blame] | 167 | public PhoneStatusBar getPhoneStatusBar() { |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 168 | return mStatusBar; |
| 169 | } |
| 170 | |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 171 | public void destroy() { |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 172 | mAutoTiles.destroy(); |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 173 | TunerService.get(mContext).removeTunable(this); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | @Override |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 177 | public void addCallback(Callback callback) { |
| 178 | mCallbacks.add(callback); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | @Override |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 182 | public void removeCallback(Callback callback) { |
| 183 | mCallbacks.remove(callback); |
| 184 | } |
| 185 | |
| 186 | @Override |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 187 | public Collection<QSTile<?>> getTiles() { |
| 188 | return mTiles.values(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | @Override |
Jason Monk | ee43cdf | 2015-06-19 14:20:46 -0400 | [diff] [blame] | 192 | public void startActivityDismissingKeyguard(final Intent intent) { |
| 193 | mStatusBar.postStartActivityDismissingKeyguard(intent, 0); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | @Override |
Adrian Roos | 62692b2 | 2015-09-11 17:46:23 -0700 | [diff] [blame] | 197 | public void startActivityDismissingKeyguard(PendingIntent intent) { |
| 198 | mStatusBar.postStartActivityDismissingKeyguard(intent); |
| 199 | } |
| 200 | |
| 201 | @Override |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 202 | public void startRunnableDismissingKeyguard(Runnable runnable) { |
| 203 | mStatusBar.postQSRunnableDismissingKeyguard(runnable); |
| 204 | } |
| 205 | |
| 206 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 207 | public void warn(String message, Throwable t) { |
| 208 | // already logged |
| 209 | } |
| 210 | |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 211 | public void animateExpandQS() { |
| 212 | // TODO: Better path to animated panel expansion. |
| 213 | mHeader.performClick(); |
| 214 | } |
| 215 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 216 | @Override |
| 217 | public void collapsePanels() { |
| 218 | mStatusBar.postAnimateCollapsePanels(); |
| 219 | } |
| 220 | |
| 221 | @Override |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 222 | public void openPanels() { |
| 223 | mStatusBar.postAnimateOpenPanels(); |
| 224 | } |
| 225 | |
| 226 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 227 | public Looper getLooper() { |
| 228 | return mLooper; |
| 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public Context getContext() { |
| 233 | return mContext; |
| 234 | } |
| 235 | |
| 236 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 237 | public BluetoothController getBluetoothController() { |
| 238 | return mBluetooth; |
| 239 | } |
| 240 | |
| 241 | @Override |
| 242 | public LocationController getLocationController() { |
| 243 | return mLocation; |
| 244 | } |
| 245 | |
| 246 | @Override |
| 247 | public RotationLockController getRotationLockController() { |
| 248 | return mRotation; |
| 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public NetworkController getNetworkController() { |
| 253 | return mNetwork; |
| 254 | } |
| 255 | |
| 256 | @Override |
| 257 | public ZenModeController getZenModeController() { |
| 258 | return mZen; |
| 259 | } |
| 260 | |
| 261 | @Override |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 262 | public HotspotController getHotspotController() { |
| 263 | return mHotspot; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | @Override |
| 267 | public CastController getCastController() { |
| 268 | return mCast; |
| 269 | } |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 270 | |
| 271 | @Override |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 272 | public FlashlightController getFlashlightController() { |
| 273 | return mFlashlight; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 274 | } |
Adrian Roos | b83777b | 2014-06-30 15:11:53 +0200 | [diff] [blame] | 275 | |
| 276 | @Override |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 277 | public KeyguardMonitor getKeyguardMonitor() { |
| 278 | return mKeyguard; |
Adrian Roos | b83777b | 2014-06-30 15:11:53 +0200 | [diff] [blame] | 279 | } |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 280 | |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 281 | @Override |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 282 | public UserSwitcherController getUserSwitcherController() { |
| 283 | return mUserSwitcherController; |
| 284 | } |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 285 | |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 286 | @Override |
| 287 | public UserInfoController getUserInfoController() { |
| 288 | return mUserInfoController; |
| 289 | } |
| 290 | |
| 291 | @Override |
| 292 | public BatteryController getBatteryController() { |
| 293 | return mBattery; |
| 294 | } |
| 295 | |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 296 | public SecurityController getSecurityController() { |
| 297 | return mSecurity; |
| 298 | } |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 299 | |
Jason Monk | d5a204f | 2015-12-21 08:50:01 -0500 | [diff] [blame] | 300 | public TileServices getTileServices() { |
| 301 | return mServices; |
| 302 | } |
| 303 | |
Jason Monk | 66c89c1 | 2016-01-06 08:51:26 -0500 | [diff] [blame] | 304 | public StatusBarIconController getIconController() { |
| 305 | return mIconController; |
| 306 | } |
| 307 | |
Jason Monk | 5dbd4aa | 2016-02-07 13:13:39 -0500 | [diff] [blame] | 308 | public NightModeController getNightModeController() { |
| 309 | return mNightModeController; |
Jason Monk | f0c6f64 | 2016-01-20 22:24:50 -0500 | [diff] [blame] | 310 | } |
| 311 | |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 312 | public ManagedProfileController getManagedProfileController() { |
| 313 | return mProfileController; |
| 314 | } |
| 315 | |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 316 | @Override |
| 317 | public void onTuningChanged(String key, String newValue) { |
| 318 | if (!TILES_SETTING.equals(key)) { |
| 319 | return; |
| 320 | } |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 321 | if (DEBUG) Log.d(TAG, "Recreating tiles"); |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 322 | final List<String> tileSpecs = loadTileSpecs(mContext, newValue); |
Jason Monk | 11a7744 | 2015-05-12 19:29:02 -0400 | [diff] [blame] | 323 | if (tileSpecs.equals(mTileSpecs)) return; |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 324 | for (Map.Entry<String, QSTile<?>> tile : mTiles.entrySet()) { |
| 325 | if (!tileSpecs.contains(tile.getKey())) { |
| 326 | if (DEBUG) Log.d(TAG, "Destroying tile: " + tile.getKey()); |
| 327 | tile.getValue().destroy(); |
| 328 | } |
| 329 | } |
| 330 | final LinkedHashMap<String, QSTile<?>> newTiles = new LinkedHashMap<>(); |
| 331 | for (String tileSpec : tileSpecs) { |
| 332 | if (mTiles.containsKey(tileSpec)) { |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 333 | QSTile<?> tile = mTiles.get(tileSpec); |
| 334 | if (DEBUG) Log.d(TAG, "Adding " + tile); |
Jason Monk | 9d02a43 | 2016-01-20 16:33:46 -0500 | [diff] [blame] | 335 | tile.removeCallbacks(); |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 336 | newTiles.put(tileSpec, tile); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 337 | } else { |
| 338 | if (DEBUG) Log.d(TAG, "Creating tile: " + tileSpec); |
| 339 | try { |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 340 | QSTile<?> tile = createTile(tileSpec); |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 341 | if (tile != null && tile.isAvailable()) { |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 342 | tile.setTileSpec(tileSpec); |
| 343 | newTiles.put(tileSpec, tile); |
| 344 | } |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 345 | } catch (Throwable t) { |
| 346 | Log.w(TAG, "Error creating tile for spec: " + tileSpec, t); |
| 347 | } |
| 348 | } |
| 349 | } |
Jason Monk | 11a7744 | 2015-05-12 19:29:02 -0400 | [diff] [blame] | 350 | mTileSpecs.clear(); |
| 351 | mTileSpecs.addAll(tileSpecs); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 352 | mTiles.clear(); |
| 353 | mTiles.putAll(newTiles); |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 354 | for (int i = 0; i < mCallbacks.size(); i++) { |
| 355 | mCallbacks.get(i).onTilesChanged(); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 359 | @Override |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 360 | public void removeTile(String tileSpec) { |
| 361 | ArrayList<String> specs = new ArrayList<>(mTileSpecs); |
| 362 | specs.remove(tileSpec); |
| 363 | Settings.Secure.putStringForUser(mContext.getContentResolver(), TILES_SETTING, |
| 364 | TextUtils.join(",", specs), ActivityManager.getCurrentUser()); |
| 365 | } |
| 366 | |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 367 | public void addTile(String spec) { |
| 368 | if (mTileSpecs.contains(spec)) { |
| 369 | return; |
| 370 | } |
| 371 | ArrayList<String> specs = new ArrayList<>(mTileSpecs); |
| 372 | specs.add(spec); |
| 373 | Settings.Secure.putStringForUser(mContext.getContentResolver(), TILES_SETTING, |
| 374 | TextUtils.join(",", specs), ActivityManager.getCurrentUser()); |
| 375 | } |
| 376 | |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 377 | public void addTile(ComponentName tile) { |
| 378 | List<String> newSpecs = new ArrayList<>(mTileSpecs); |
| 379 | newSpecs.add(0, CustomTile.toSpec(tile)); |
| 380 | changeTiles(mTileSpecs, newSpecs); |
| 381 | } |
| 382 | |
| 383 | public void removeTile(ComponentName tile) { |
| 384 | List<String> newSpecs = new ArrayList<>(mTileSpecs); |
| 385 | newSpecs.remove(CustomTile.toSpec(tile)); |
| 386 | changeTiles(mTileSpecs, newSpecs); |
| 387 | } |
| 388 | |
| 389 | public void changeTiles(List<String> previousTiles, List<String> newTiles) { |
| 390 | final int NP = previousTiles.size(); |
| 391 | final int NA = newTiles.size(); |
| 392 | for (int i = 0; i < NP; i++) { |
| 393 | String tileSpec = previousTiles.get(i); |
| 394 | if (!tileSpec.startsWith(CustomTile.PREFIX)) continue; |
| 395 | if (!newTiles.contains(tileSpec)) { |
| 396 | Intent intent = new Intent().setComponent( |
| 397 | CustomTile.getComponentFromSpec(tileSpec)); |
| 398 | TileLifecycleManager lifecycleManager = new TileLifecycleManager(new Handler(), |
| 399 | mContext, intent, new UserHandle(ActivityManager.getCurrentUser())); |
| 400 | lifecycleManager.onStopListening(); |
| 401 | lifecycleManager.onTileRemoved(); |
| 402 | lifecycleManager.flushMessagesAndUnbind(); |
| 403 | } |
| 404 | } |
| 405 | for (int i = 0; i < NA; i++) { |
| 406 | String tileSpec = newTiles.get(i); |
| 407 | if (!tileSpec.startsWith(CustomTile.PREFIX)) continue; |
| 408 | if (!previousTiles.contains(tileSpec)) { |
| 409 | Intent intent = new Intent().setComponent( |
| 410 | CustomTile.getComponentFromSpec(tileSpec)); |
| 411 | TileLifecycleManager lifecycleManager = new TileLifecycleManager(new Handler(), |
| 412 | mContext, intent, new UserHandle(ActivityManager.getCurrentUser())); |
| 413 | lifecycleManager.onTileAdded(); |
| 414 | lifecycleManager.flushMessagesAndUnbind(); |
| 415 | } |
| 416 | } |
| 417 | if (DEBUG) Log.d(TAG, "saveCurrentTiles " + newTiles); |
| 418 | Secure.putStringForUser(getContext().getContentResolver(), QSTileHost.TILES_SETTING, |
| 419 | TextUtils.join(",", newTiles), ActivityManager.getCurrentUser()); |
| 420 | } |
| 421 | |
Jason Monk | 5db8a41 | 2015-10-21 15:16:23 -0700 | [diff] [blame] | 422 | public QSTile<?> createTile(String tileSpec) { |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 423 | if (tileSpec.equals("wifi")) return new WifiTile(this); |
| 424 | else if (tileSpec.equals("bt")) return new BluetoothTile(this); |
| 425 | else if (tileSpec.equals("cell")) return new CellularTile(this); |
| 426 | else if (tileSpec.equals("dnd")) return new DndTile(this); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 427 | else if (tileSpec.equals("inversion")) return new ColorInversionTile(this); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 428 | else if (tileSpec.equals("airplane")) return new AirplaneModeTile(this); |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 429 | else if (tileSpec.equals("work")) return new WorkModeTile(this); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 430 | else if (tileSpec.equals("rotation")) return new RotationLockTile(this); |
| 431 | else if (tileSpec.equals("flashlight")) return new FlashlightTile(this); |
| 432 | else if (tileSpec.equals("location")) return new LocationTile(this); |
| 433 | else if (tileSpec.equals("cast")) return new CastTile(this); |
| 434 | else if (tileSpec.equals("hotspot")) return new HotspotTile(this); |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 435 | else if (tileSpec.equals("user")) return new UserTile(this); |
| 436 | else if (tileSpec.equals("battery")) return new BatteryTile(this); |
Jason Monk | 9a4ce13 | 2016-01-21 15:27:17 -0500 | [diff] [blame] | 437 | else if (tileSpec.equals("saver")) return new DataSaverTile(this); |
Jason Monk | 5dbd4aa | 2016-02-07 13:13:39 -0500 | [diff] [blame] | 438 | else if (tileSpec.equals(NightModeTile.NIGHT_MODE_SPEC)) |
| 439 | return new NightModeTile(this); |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 440 | // Intent tiles. |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 441 | else if (tileSpec.startsWith(IntentTile.PREFIX)) return IntentTile.create(this,tileSpec); |
Jason Monk | 5db8a41 | 2015-10-21 15:16:23 -0700 | [diff] [blame] | 442 | else if (tileSpec.startsWith(CustomTile.PREFIX)) return CustomTile.create(this,tileSpec); |
Jason Monk | 2b37190f | 2016-01-06 10:19:04 -0500 | [diff] [blame] | 443 | else { |
| 444 | Log.w(TAG, "Bad tile spec: " + tileSpec); |
| 445 | return null; |
| 446 | } |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 447 | } |
| 448 | |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 449 | public static List<String> loadTileSpecs(Context context, String tileList) { |
| 450 | final Resources res = context.getResources(); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 451 | final String defaultTileList = res.getString(R.string.quick_settings_tiles_default); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 452 | if (tileList == null) { |
| 453 | tileList = res.getString(R.string.quick_settings_tiles); |
| 454 | if (DEBUG) Log.d(TAG, "Loaded tile specs from config: " + tileList); |
| 455 | } else { |
| 456 | if (DEBUG) Log.d(TAG, "Loaded tile specs from setting: " + tileList); |
| 457 | } |
| 458 | final ArrayList<String> tiles = new ArrayList<String>(); |
| 459 | boolean addedDefault = false; |
| 460 | for (String tile : tileList.split(",")) { |
| 461 | tile = tile.trim(); |
| 462 | if (tile.isEmpty()) continue; |
| 463 | if (tile.equals("default")) { |
| 464 | if (!addedDefault) { |
| 465 | tiles.addAll(Arrays.asList(defaultTileList.split(","))); |
| 466 | addedDefault = true; |
| 467 | } |
| 468 | } else { |
| 469 | tiles.add(tile); |
| 470 | } |
| 471 | } |
| 472 | return tiles; |
| 473 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 474 | } |