blob: 0e8e844393702d05927a149774424c082d766641 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 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
Joe Onoratofd52b182010-11-10 18:00:52 -080017package com.android.systemui.statusbar.phone;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
Kenny Guy3094d4a2015-04-01 19:14:10 +010019import android.app.ActivityManagerNative;
Adrian Roosc42a1e12014-07-07 23:35:53 +020020import android.app.AlarmManager;
Kenny Guy3094d4a2015-04-01 19:14:10 +010021import android.app.IUserSwitchObserver;
Joe Onorato798ac4c2010-05-27 16:39:00 -040022import android.app.StatusBarManager;
Nick Pellybd022f42009-08-14 18:33:38 -070023import android.bluetooth.BluetoothAdapter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.content.BroadcastReceiver;
25import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.content.Intent;
27import android.content.IntentFilter;
Kenny Guy3094d4a2015-04-01 19:14:10 +010028import android.content.pm.UserInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.media.AudioManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.os.Handler;
Kenny Guy3094d4a2015-04-01 19:14:10 +010031import android.os.IRemoteCallback;
32import android.os.RemoteException;
Adrian Roosc42a1e12014-07-07 23:35:53 +020033import android.os.UserHandle;
Kenny Guy3094d4a2015-04-01 19:14:10 +010034import android.os.UserManager;
John Spurlockae641c92014-06-30 18:11:40 -040035import android.provider.Settings.Global;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070036import android.telecom.TelecomManager;
John Spurlockcd686b52013-06-05 10:13:46 -040037import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038
Wink Savillea639b312012-07-10 12:37:54 -070039import com.android.internal.telephony.IccCardConstants;
Wink Saville04e71b32009-04-02 11:00:54 -070040import com.android.internal.telephony.TelephonyIntents;
Joe Onorato798ac4c2010-05-27 16:39:00 -040041import com.android.systemui.R;
John Spurlock3c4076a2015-02-24 12:12:25 -050042import com.android.systemui.qs.tiles.DndTile;
John Spurlock96fe98d2014-08-27 09:36:02 -040043import com.android.systemui.statusbar.policy.CastController;
44import com.android.systemui.statusbar.policy.CastController.CastDevice;
Jason Monk952d5d82014-10-27 15:28:22 -040045import com.android.systemui.statusbar.policy.HotspotController;
Joe Onorato798ac4c2010-05-27 16:39:00 -040046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047/**
48 * This class contains all of the policy about which icons are installed in the status
Joe Onorato798ac4c2010-05-27 16:39:00 -040049 * bar at boot time. It goes through the normal API for icons, even though it probably
50 * strictly doesn't need to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051 */
Joe Onoratofd52b182010-11-10 18:00:52 -080052public class PhoneStatusBarPolicy {
53 private static final String TAG = "PhoneStatusBarPolicy";
John Spurlocka37e9c82014-07-08 09:40:31 -040054 private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070055
John Spurlock96fe98d2014-08-27 09:36:02 -040056 private static final String SLOT_CAST = "cast";
Jason Monk952d5d82014-10-27 15:28:22 -040057 private static final String SLOT_HOTSPOT = "hotspot";
John Spurlocka37e9c82014-07-08 09:40:31 -040058 private static final String SLOT_BLUETOOTH = "bluetooth";
59 private static final String SLOT_TTY = "tty";
60 private static final String SLOT_ZEN = "zen";
61 private static final String SLOT_VOLUME = "volume";
John Spurlocka37e9c82014-07-08 09:40:31 -040062 private static final String SLOT_ALARM_CLOCK = "alarm_clock";
Kenny Guy3094d4a2015-04-01 19:14:10 +010063 private static final String SLOT_MANAGED_PROFILE = "managed_profile";
John Spurlocka37e9c82014-07-08 09:40:31 -040064
Dianne Hackborn4840e142009-03-24 22:40:29 -070065 private final Context mContext;
Joe Onorato798ac4c2010-05-27 16:39:00 -040066 private final StatusBarManager mService;
Joe Onorato10523b4d2010-10-25 10:42:46 -070067 private final Handler mHandler = new Handler();
John Spurlock96fe98d2014-08-27 09:36:02 -040068 private final CastController mCast;
Jason Monk952d5d82014-10-27 15:28:22 -040069 private final HotspotController mHotspot;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 // Assume it's all good unless we hear otherwise. We don't always seem
72 // to get broadcasts that it *is* there.
Wink Savillea639b312012-07-10 12:37:54 -070073 IccCardConstants.State mSimState = IccCardConstants.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074
John Spurlocka37e9c82014-07-08 09:40:31 -040075 private boolean mZenVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 private boolean mVolumeVisible;
Wink Saville04e71b32009-04-02 11:00:54 -070077
John Spurlockae641c92014-06-30 18:11:40 -040078 private int mZen;
John Spurlockba2c6a02014-05-19 09:44:06 -040079
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -040080 private boolean mBluetoothEnabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081
Kenny Guy3094d4a2015-04-01 19:14:10 +010082 private boolean mManagedProfileFocused = false;
83 private boolean mManagedProfileIconVisible = true;
84
85 private boolean mKeyguardVisible = true;
Wink Savillee9b06d72009-05-18 21:47:50 -070086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
88 @Override
89 public void onReceive(Context context, Intent intent) {
90 String action = intent.getAction();
Adrian Roosc42a1e12014-07-07 23:35:53 +020091 if (action.equals(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)) {
92 updateAlarm();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 }
Nick Pellyde893f52009-09-08 13:15:33 -070094 else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) ||
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -070095 action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -070096 updateBluetooth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 }
John Spurlockbcc10872014-11-28 15:29:21 -050098 else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
99 action.equals(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400100 updateVolumeZen();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 }
102 else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
103 updateSimState(intent);
104 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700105 else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) {
Wink Saville04e71b32009-04-02 11:00:54 -0700106 updateTTY(intent);
107 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 }
109 };
110
Jason Monk952d5d82014-10-27 15:28:22 -0400111 public PhoneStatusBarPolicy(Context context, CastController cast, HotspotController hotspot) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 mContext = context;
John Spurlock96fe98d2014-08-27 09:36:02 -0400113 mCast = cast;
Jason Monk952d5d82014-10-27 15:28:22 -0400114 mHotspot = hotspot;
Joe Onorato798ac4c2010-05-27 16:39:00 -0400115 mService = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400117 // listen for broadcasts
118 IntentFilter filter = new IntentFilter();
Adrian Roosc42a1e12014-07-07 23:35:53 +0200119 filter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400120 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
John Spurlockbcc10872014-11-28 15:29:21 -0500121 filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400122 filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
123 filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
124 filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700125 filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400126 mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
127
Kenny Guy3094d4a2015-04-01 19:14:10 +0100128 // listen for user / profile change.
129 try {
130 ActivityManagerNative.getDefault().registerUserSwitchObserver(mUserSwitchListener);
131 } catch (RemoteException e) {
132 // Ignore
133 }
134
Wink Saville04e71b32009-04-02 11:00:54 -0700135 // TTY status
John Spurlocka37e9c82014-07-08 09:40:31 -0400136 mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0, null);
137 mService.setIconVisibility(SLOT_TTY, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 // bluetooth status
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700140 updateBluetooth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 // Alarm clock
John Spurlocka37e9c82014-07-08 09:40:31 -0400143 mService.setIcon(SLOT_ALARM_CLOCK, R.drawable.stat_sys_alarm, 0, null);
144 mService.setIconVisibility(SLOT_ALARM_CLOCK, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145
John Spurlocka37e9c82014-07-08 09:40:31 -0400146 // zen
147 mService.setIcon(SLOT_ZEN, R.drawable.stat_sys_zen_important, 0, null);
148 mService.setIconVisibility(SLOT_ZEN, false);
149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 // volume
John Spurlockad494bc2014-07-19 15:56:19 -0400151 mService.setIcon(SLOT_VOLUME, R.drawable.stat_sys_ringer_vibrate, 0, null);
John Spurlocka37e9c82014-07-08 09:40:31 -0400152 mService.setIconVisibility(SLOT_VOLUME, false);
153 updateVolumeZen();
John Spurlock96fe98d2014-08-27 09:36:02 -0400154
155 // cast
156 mService.setIcon(SLOT_CAST, R.drawable.stat_sys_cast, 0, null);
157 mService.setIconVisibility(SLOT_CAST, false);
158 mCast.addCallback(mCastCallback);
Jason Monk952d5d82014-10-27 15:28:22 -0400159
160 // hotspot
161 mService.setIcon(SLOT_HOTSPOT, R.drawable.stat_sys_hotspot, 0, null);
162 mService.setIconVisibility(SLOT_HOTSPOT, mHotspot.isHotspotEnabled());
163 mHotspot.addCallback(mHotspotCallback);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100164
165 // managed profile
166 mService.setIcon(SLOT_MANAGED_PROFILE, R.drawable.stat_sys_managed_profile_status, 0, null);
167 mService.setIconVisibility(SLOT_MANAGED_PROFILE, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 }
169
John Spurlockae641c92014-06-30 18:11:40 -0400170 public void setZenMode(int zen) {
John Spurlockba2c6a02014-05-19 09:44:06 -0400171 mZen = zen;
John Spurlocka37e9c82014-07-08 09:40:31 -0400172 updateVolumeZen();
John Spurlockba2c6a02014-05-19 09:44:06 -0400173 }
174
Adrian Roosc42a1e12014-07-07 23:35:53 +0200175 private void updateAlarm() {
176 AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
John Spurlock5b13e922015-01-07 11:04:58 -0500177 boolean alarmSet = alarmManager.getNextAlarmClock(UserHandle.USER_CURRENT) != null;
John Spurlocka37e9c82014-07-08 09:40:31 -0400178 mService.setIconVisibility(SLOT_ALARM_CLOCK, alarmSet);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 }
180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 private final void updateSimState(Intent intent) {
Wink Savillea639b312012-07-10 12:37:54 -0700182 String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
183 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
184 mSimState = IccCardConstants.State.ABSENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 }
Rakesh Pallerlaf099a5f2013-02-06 11:44:23 +0530186 else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) {
187 mSimState = IccCardConstants.State.CARD_IO_ERROR;
188 }
Wink Savillea639b312012-07-10 12:37:54 -0700189 else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
190 mSimState = IccCardConstants.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 }
Wink Savillea639b312012-07-10 12:37:54 -0700192 else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
193 final String lockedReason =
194 intent.getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON);
195 if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
196 mSimState = IccCardConstants.State.PIN_REQUIRED;
johnwang347c5a22009-08-24 22:11:11 -0700197 }
Wink Savillea639b312012-07-10 12:37:54 -0700198 else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
199 mSimState = IccCardConstants.State.PUK_REQUIRED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 }
201 else {
Wink Savillea639b312012-07-10 12:37:54 -0700202 mSimState = IccCardConstants.State.NETWORK_LOCKED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 }
204 } else {
Wink Savillea639b312012-07-10 12:37:54 -0700205 mSimState = IccCardConstants.State.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 }
208
John Spurlockbcc10872014-11-28 15:29:21 -0500209 private final void updateVolumeZen() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
John Spurlocka37e9c82014-07-08 09:40:31 -0400211
212 boolean zenVisible = false;
213 int zenIconId = 0;
214 String zenDescription = null;
215
216 boolean volumeVisible = false;
217 int volumeIconId = 0;
218 String volumeDescription = null;
219
John Spurlockf88d8082015-03-25 18:09:51 -0400220 if (DndTile.isVisible(mContext) || DndTile.isCombinedIcon(mContext)) {
John Spurlock3c4076a2015-02-24 12:12:25 -0500221 zenVisible = mZen != Global.ZEN_MODE_OFF;
222 zenIconId = R.drawable.stat_sys_dnd;
223 zenDescription = mContext.getString(R.string.quick_settings_dnd_label);
224 } else if (mZen == Global.ZEN_MODE_NO_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400225 zenVisible = true;
226 zenIconId = R.drawable.stat_sys_zen_none;
John Spurlockd9c75db2015-04-28 11:19:13 -0400227 zenDescription = mContext.getString(R.string.interruption_level_none);
John Spurlockae641c92014-06-30 18:11:40 -0400228 } else if (mZen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400229 zenVisible = true;
230 zenIconId = R.drawable.stat_sys_zen_important;
John Spurlockd9c75db2015-04-28 11:19:13 -0400231 zenDescription = mContext.getString(R.string.interruption_level_priority);
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700232 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233
John Spurlockd9c75db2015-04-28 11:19:13 -0400234 if (DndTile.isVisible(mContext) && !DndTile.isCombinedIcon(mContext)
John Spurlocka48d7792015-03-03 17:35:57 -0500235 && audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT) {
236 volumeVisible = true;
237 volumeIconId = R.drawable.stat_sys_ringer_silent;
238 volumeDescription = mContext.getString(R.string.accessibility_ringer_silent);
John Spurlock4f1163c2015-04-02 17:41:21 -0400239 } else if (mZen != Global.ZEN_MODE_NO_INTERRUPTIONS && mZen != Global.ZEN_MODE_ALARMS &&
John Spurlock661f2cf2014-11-17 10:29:10 -0500240 audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400241 volumeVisible = true;
242 volumeIconId = R.drawable.stat_sys_ringer_vibrate;
243 volumeDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 }
John Spurlocka37e9c82014-07-08 09:40:31 -0400245
246 if (zenVisible) {
247 mService.setIcon(SLOT_ZEN, zenIconId, 0, zenDescription);
248 }
249 if (zenVisible != mZenVisible) {
250 mService.setIconVisibility(SLOT_ZEN, zenVisible);
251 mZenVisible = zenVisible;
252 }
253
254 if (volumeVisible) {
255 mService.setIcon(SLOT_VOLUME, volumeIconId, 0, volumeDescription);
256 }
257 if (volumeVisible != mVolumeVisible) {
258 mService.setIconVisibility(SLOT_VOLUME, volumeVisible);
259 mVolumeVisible = volumeVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 }
261 }
262
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700263 private final void updateBluetooth() {
264 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
Joe Onorato798ac4c2010-05-27 16:39:00 -0400265 int iconId = R.drawable.stat_sys_data_bluetooth;
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700266 String contentDescription =
267 mContext.getString(R.string.accessibility_bluetooth_disconnected);
268 if (adapter != null) {
269 mBluetoothEnabled = (adapter.getState() == BluetoothAdapter.STATE_ON);
270 if (adapter.getConnectionState() == BluetoothAdapter.STATE_CONNECTED) {
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700271 iconId = R.drawable.stat_sys_data_bluetooth_connected;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700272 contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800273 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 } else {
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700275 mBluetoothEnabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700277
John Spurlocka37e9c82014-07-08 09:40:31 -0400278 mService.setIcon(SLOT_BLUETOOTH, iconId, 0, contentDescription);
279 mService.setIconVisibility(SLOT_BLUETOOTH, mBluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 }
281
Wink Savillee9b06d72009-05-18 21:47:50 -0700282 private final void updateTTY(Intent intent) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700283 int currentTtyMode = intent.getIntExtra(TelecomManager.EXTRA_CURRENT_TTY_MODE,
284 TelecomManager.TTY_MODE_OFF);
285 boolean enabled = currentTtyMode != TelecomManager.TTY_MODE_OFF;
Wink Saville04e71b32009-04-02 11:00:54 -0700286
John Spurlocka37e9c82014-07-08 09:40:31 -0400287 if (DEBUG) Log.v(TAG, "updateTTY: enabled: " + enabled);
Wink Saville04e71b32009-04-02 11:00:54 -0700288
289 if (enabled) {
290 // TTY is on
John Spurlocka37e9c82014-07-08 09:40:31 -0400291 if (DEBUG) Log.v(TAG, "updateTTY: set TTY on");
292 mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700293 mContext.getString(R.string.accessibility_tty_enabled));
John Spurlocka37e9c82014-07-08 09:40:31 -0400294 mService.setIconVisibility(SLOT_TTY, true);
Wink Saville04e71b32009-04-02 11:00:54 -0700295 } else {
296 // TTY is off
John Spurlocka37e9c82014-07-08 09:40:31 -0400297 if (DEBUG) Log.v(TAG, "updateTTY: set TTY off");
298 mService.setIconVisibility(SLOT_TTY, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700299 }
300 }
John Spurlock96fe98d2014-08-27 09:36:02 -0400301
302 private void updateCast() {
303 boolean isCasting = false;
304 for (CastDevice device : mCast.getCastDevices()) {
305 if (device.state == CastDevice.STATE_CONNECTING
306 || device.state == CastDevice.STATE_CONNECTED) {
307 isCasting = true;
308 break;
309 }
310 }
311 if (DEBUG) Log.v(TAG, "updateCast: isCasting: " + isCasting);
312 if (isCasting) {
313 mService.setIcon(SLOT_CAST, R.drawable.stat_sys_cast, 0,
314 mContext.getString(R.string.accessibility_casting));
315 }
316 mService.setIconVisibility(SLOT_CAST, isCasting);
317 }
318
Kenny Guy3094d4a2015-04-01 19:14:10 +0100319 private void profileChanged(int userId) {
320 UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
321 UserInfo user = null;
322 if (userId == UserHandle.USER_CURRENT) {
323 try {
324 user = ActivityManagerNative.getDefault().getCurrentUser();
325 } catch (RemoteException e) {
326 // Ignore
327 }
328 } else {
329 user = userManager.getUserInfo(userId);
330 }
331
332 mManagedProfileFocused = user != null && user.isManagedProfile();
333 if (DEBUG) Log.v(TAG, "profileChanged: mManagedProfileFocused: " + mManagedProfileFocused);
334 // Actually update the icon later when transition starts.
335 }
336
337 private void updateManagedProfile() {
338 if (DEBUG) Log.v(TAG, "updateManagedProfile: mManagedProfileFocused: "
339 + mManagedProfileFocused
340 + " mKeyguardVisible: " + mKeyguardVisible);
341 boolean showIcon = mManagedProfileFocused && !mKeyguardVisible;
342 if (mManagedProfileIconVisible != showIcon) {
343 mService.setIconVisibility(SLOT_MANAGED_PROFILE, showIcon);
344 mManagedProfileIconVisible = showIcon;
345 }
346 }
347
348 private final IUserSwitchObserver.Stub mUserSwitchListener =
349 new IUserSwitchObserver.Stub() {
350 @Override
351 public void onUserSwitching(int newUserId, IRemoteCallback reply) {
352 }
353
354 @Override
355 public void onUserSwitchComplete(int newUserId) throws RemoteException {
356 updateAlarm();
357 profileChanged(newUserId);
358 }
359
360 @Override
361 public void onForegroundProfileSwitch(int newProfileId) {
362 profileChanged(newProfileId);
363 }
364 };
365
Jason Monk952d5d82014-10-27 15:28:22 -0400366 private final HotspotController.Callback mHotspotCallback = new HotspotController.Callback() {
367 @Override
368 public void onHotspotChanged(boolean enabled) {
369 mService.setIconVisibility(SLOT_HOTSPOT, enabled);
370 }
371 };
372
John Spurlock96fe98d2014-08-27 09:36:02 -0400373 private final CastController.Callback mCastCallback = new CastController.Callback() {
374 @Override
375 public void onCastDevicesChanged() {
376 updateCast();
377 }
378 };
Kenny Guy3094d4a2015-04-01 19:14:10 +0100379
380 public void appTransitionStarting(long startTime, long duration) {
381 updateManagedProfile();
382 }
383
384 public void setKeyguardShowing(boolean visible) {
385 mKeyguardVisible = visible;
386 updateManagedProfile();
387 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388}