blob: 6a6266e5f8880bae2c5e46e984e03e8494d9f8ba [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;
John Spurlock604a5ee2015-06-01 12:27:22 -040021import android.app.AlarmManager.AlarmClockInfo;
Kenny Guy3094d4a2015-04-01 19:14:10 +010022import android.app.IUserSwitchObserver;
Joe Onorato798ac4c2010-05-27 16:39:00 -040023import android.app.StatusBarManager;
Nick Pellybd022f42009-08-14 18:33:38 -070024import android.bluetooth.BluetoothAdapter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.BroadcastReceiver;
26import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.content.Intent;
28import android.content.IntentFilter;
Kenny Guy3094d4a2015-04-01 19:14:10 +010029import android.content.pm.UserInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.media.AudioManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.Handler;
Kenny Guy3094d4a2015-04-01 19:14:10 +010032import android.os.IRemoteCallback;
33import android.os.RemoteException;
Adrian Roosc42a1e12014-07-07 23:35:53 +020034import android.os.UserHandle;
Kenny Guy3094d4a2015-04-01 19:14:10 +010035import android.os.UserManager;
John Spurlockae641c92014-06-30 18:11:40 -040036import android.provider.Settings.Global;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070037import android.telecom.TelecomManager;
John Spurlockcd686b52013-06-05 10:13:46 -040038import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
Wink Savillea639b312012-07-10 12:37:54 -070040import com.android.internal.telephony.IccCardConstants;
Wink Saville04e71b32009-04-02 11:00:54 -070041import com.android.internal.telephony.TelephonyIntents;
Joe Onorato798ac4c2010-05-27 16:39:00 -040042import com.android.systemui.R;
John Spurlock3c4076a2015-02-24 12:12:25 -050043import com.android.systemui.qs.tiles.DndTile;
John Spurlock96fe98d2014-08-27 09:36:02 -040044import com.android.systemui.statusbar.policy.CastController;
45import com.android.systemui.statusbar.policy.CastController.CastDevice;
Jason Monk952d5d82014-10-27 15:28:22 -040046import com.android.systemui.statusbar.policy.HotspotController;
Joe Onorato798ac4c2010-05-27 16:39:00 -040047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048/**
49 * This class contains all of the policy about which icons are installed in the status
Joe Onorato798ac4c2010-05-27 16:39:00 -040050 * bar at boot time. It goes through the normal API for icons, even though it probably
51 * strictly doesn't need to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 */
Joe Onoratofd52b182010-11-10 18:00:52 -080053public class PhoneStatusBarPolicy {
54 private static final String TAG = "PhoneStatusBarPolicy";
John Spurlocka37e9c82014-07-08 09:40:31 -040055 private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070056
John Spurlock96fe98d2014-08-27 09:36:02 -040057 private static final String SLOT_CAST = "cast";
Jason Monk952d5d82014-10-27 15:28:22 -040058 private static final String SLOT_HOTSPOT = "hotspot";
John Spurlocka37e9c82014-07-08 09:40:31 -040059 private static final String SLOT_BLUETOOTH = "bluetooth";
60 private static final String SLOT_TTY = "tty";
61 private static final String SLOT_ZEN = "zen";
62 private static final String SLOT_VOLUME = "volume";
John Spurlocka37e9c82014-07-08 09:40:31 -040063 private static final String SLOT_ALARM_CLOCK = "alarm_clock";
Kenny Guy3094d4a2015-04-01 19:14:10 +010064 private static final String SLOT_MANAGED_PROFILE = "managed_profile";
John Spurlocka37e9c82014-07-08 09:40:31 -040065
Dianne Hackborn4840e142009-03-24 22:40:29 -070066 private final Context mContext;
Joe Onorato798ac4c2010-05-27 16:39:00 -040067 private final StatusBarManager mService;
Joe Onorato10523b4d2010-10-25 10:42:46 -070068 private final Handler mHandler = new Handler();
John Spurlock96fe98d2014-08-27 09:36:02 -040069 private final CastController mCast;
Jason Monk952d5d82014-10-27 15:28:22 -040070 private final HotspotController mHotspot;
John Spurlock15782262015-05-29 15:35:53 -040071 private final AlarmManager mAlarmManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 // Assume it's all good unless we hear otherwise. We don't always seem
74 // to get broadcasts that it *is* there.
Wink Savillea639b312012-07-10 12:37:54 -070075 IccCardConstants.State mSimState = IccCardConstants.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076
John Spurlocka37e9c82014-07-08 09:40:31 -040077 private boolean mZenVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 private boolean mVolumeVisible;
John Spurlock604a5ee2015-06-01 12:27:22 -040079 private boolean mCurrentUserSetup;
Wink Saville04e71b32009-04-02 11:00:54 -070080
John Spurlockae641c92014-06-30 18:11:40 -040081 private int mZen;
John Spurlockba2c6a02014-05-19 09:44:06 -040082
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -040083 private boolean mBluetoothEnabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084
Kenny Guy3094d4a2015-04-01 19:14:10 +010085 private boolean mManagedProfileFocused = false;
86 private boolean mManagedProfileIconVisible = true;
87
88 private boolean mKeyguardVisible = true;
Wink Savillee9b06d72009-05-18 21:47:50 -070089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
91 @Override
92 public void onReceive(Context context, Intent intent) {
93 String action = intent.getAction();
Adrian Roosc42a1e12014-07-07 23:35:53 +020094 if (action.equals(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)) {
95 updateAlarm();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 }
Nick Pellyde893f52009-09-08 13:15:33 -070097 else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) ||
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -070098 action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -070099 updateBluetooth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 }
John Spurlockbcc10872014-11-28 15:29:21 -0500101 else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
102 action.equals(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400103 updateVolumeZen();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 }
105 else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
106 updateSimState(intent);
107 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700108 else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) {
Wink Saville04e71b32009-04-02 11:00:54 -0700109 updateTTY(intent);
110 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 }
112 };
113
Jason Monk952d5d82014-10-27 15:28:22 -0400114 public PhoneStatusBarPolicy(Context context, CastController cast, HotspotController hotspot) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 mContext = context;
John Spurlock96fe98d2014-08-27 09:36:02 -0400116 mCast = cast;
Jason Monk952d5d82014-10-27 15:28:22 -0400117 mHotspot = hotspot;
John Spurlock15782262015-05-29 15:35:53 -0400118 mService = (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE);
119 mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400121 // listen for broadcasts
122 IntentFilter filter = new IntentFilter();
Adrian Roosc42a1e12014-07-07 23:35:53 +0200123 filter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400124 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
John Spurlockbcc10872014-11-28 15:29:21 -0500125 filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400126 filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
127 filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
128 filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700129 filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400130 mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
131
Kenny Guy3094d4a2015-04-01 19:14:10 +0100132 // listen for user / profile change.
133 try {
134 ActivityManagerNative.getDefault().registerUserSwitchObserver(mUserSwitchListener);
135 } catch (RemoteException e) {
136 // Ignore
137 }
138
Wink Saville04e71b32009-04-02 11:00:54 -0700139 // TTY status
John Spurlocka37e9c82014-07-08 09:40:31 -0400140 mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0, null);
141 mService.setIconVisibility(SLOT_TTY, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 // bluetooth status
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700144 updateBluetooth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 // Alarm clock
John Spurlocka37e9c82014-07-08 09:40:31 -0400147 mService.setIcon(SLOT_ALARM_CLOCK, R.drawable.stat_sys_alarm, 0, null);
148 mService.setIconVisibility(SLOT_ALARM_CLOCK, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149
John Spurlocka37e9c82014-07-08 09:40:31 -0400150 // zen
151 mService.setIcon(SLOT_ZEN, R.drawable.stat_sys_zen_important, 0, null);
152 mService.setIconVisibility(SLOT_ZEN, false);
153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 // volume
John Spurlockad494bc2014-07-19 15:56:19 -0400155 mService.setIcon(SLOT_VOLUME, R.drawable.stat_sys_ringer_vibrate, 0, null);
John Spurlocka37e9c82014-07-08 09:40:31 -0400156 mService.setIconVisibility(SLOT_VOLUME, false);
157 updateVolumeZen();
John Spurlock96fe98d2014-08-27 09:36:02 -0400158
159 // cast
160 mService.setIcon(SLOT_CAST, R.drawable.stat_sys_cast, 0, null);
161 mService.setIconVisibility(SLOT_CAST, false);
162 mCast.addCallback(mCastCallback);
Jason Monk952d5d82014-10-27 15:28:22 -0400163
164 // hotspot
Jason Monk08187a42015-06-09 14:33:51 -0400165 mService.setIcon(SLOT_HOTSPOT, R.drawable.stat_sys_hotspot, 0,
166 mContext.getString(R.string.accessibility_status_bar_hotspot));
Jason Monk952d5d82014-10-27 15:28:22 -0400167 mService.setIconVisibility(SLOT_HOTSPOT, mHotspot.isHotspotEnabled());
168 mHotspot.addCallback(mHotspotCallback);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100169
170 // managed profile
171 mService.setIcon(SLOT_MANAGED_PROFILE, R.drawable.stat_sys_managed_profile_status, 0, null);
172 mService.setIconVisibility(SLOT_MANAGED_PROFILE, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 }
174
John Spurlockae641c92014-06-30 18:11:40 -0400175 public void setZenMode(int zen) {
John Spurlockba2c6a02014-05-19 09:44:06 -0400176 mZen = zen;
John Spurlocka37e9c82014-07-08 09:40:31 -0400177 updateVolumeZen();
John Spurlockba2c6a02014-05-19 09:44:06 -0400178 }
179
Adrian Roosc42a1e12014-07-07 23:35:53 +0200180 private void updateAlarm() {
John Spurlock604a5ee2015-06-01 12:27:22 -0400181 final AlarmClockInfo alarm = mAlarmManager.getNextAlarmClock(UserHandle.USER_CURRENT);
182 final boolean hasAlarm = alarm != null && alarm.getTriggerTime() > 0;
John Spurlock15782262015-05-29 15:35:53 -0400183 final boolean zenNone = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS;
John Spurlock15782262015-05-29 15:35:53 -0400184 mService.setIcon(SLOT_ALARM_CLOCK, zenNone ? R.drawable.stat_sys_alarm_dim
185 : R.drawable.stat_sys_alarm, 0, null);
John Spurlock604a5ee2015-06-01 12:27:22 -0400186 mService.setIconVisibility(SLOT_ALARM_CLOCK, mCurrentUserSetup && hasAlarm);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 }
188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 private final void updateSimState(Intent intent) {
Wink Savillea639b312012-07-10 12:37:54 -0700190 String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
191 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
192 mSimState = IccCardConstants.State.ABSENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 }
Rakesh Pallerlaf099a5f2013-02-06 11:44:23 +0530194 else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) {
195 mSimState = IccCardConstants.State.CARD_IO_ERROR;
196 }
Wink Savillea639b312012-07-10 12:37:54 -0700197 else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
198 mSimState = IccCardConstants.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 }
Wink Savillea639b312012-07-10 12:37:54 -0700200 else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
201 final String lockedReason =
202 intent.getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON);
203 if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
204 mSimState = IccCardConstants.State.PIN_REQUIRED;
johnwang347c5a22009-08-24 22:11:11 -0700205 }
Wink Savillea639b312012-07-10 12:37:54 -0700206 else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
207 mSimState = IccCardConstants.State.PUK_REQUIRED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 }
209 else {
Wink Savillea639b312012-07-10 12:37:54 -0700210 mSimState = IccCardConstants.State.NETWORK_LOCKED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 }
212 } else {
Wink Savillea639b312012-07-10 12:37:54 -0700213 mSimState = IccCardConstants.State.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 }
216
John Spurlockbcc10872014-11-28 15:29:21 -0500217 private final void updateVolumeZen() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
John Spurlocka37e9c82014-07-08 09:40:31 -0400219
220 boolean zenVisible = false;
221 int zenIconId = 0;
222 String zenDescription = null;
223
224 boolean volumeVisible = false;
225 int volumeIconId = 0;
226 String volumeDescription = null;
227
John Spurlockf88d8082015-03-25 18:09:51 -0400228 if (DndTile.isVisible(mContext) || DndTile.isCombinedIcon(mContext)) {
John Spurlock3c4076a2015-02-24 12:12:25 -0500229 zenVisible = mZen != Global.ZEN_MODE_OFF;
John Spurlock4ec8b602015-05-11 17:46:28 -0400230 zenIconId = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS
231 ? R.drawable.stat_sys_dnd_total_silence : R.drawable.stat_sys_dnd;
John Spurlock3c4076a2015-02-24 12:12:25 -0500232 zenDescription = mContext.getString(R.string.quick_settings_dnd_label);
233 } else if (mZen == Global.ZEN_MODE_NO_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400234 zenVisible = true;
235 zenIconId = R.drawable.stat_sys_zen_none;
John Spurlockd9c75db2015-04-28 11:19:13 -0400236 zenDescription = mContext.getString(R.string.interruption_level_none);
John Spurlockae641c92014-06-30 18:11:40 -0400237 } else if (mZen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400238 zenVisible = true;
239 zenIconId = R.drawable.stat_sys_zen_important;
John Spurlockd9c75db2015-04-28 11:19:13 -0400240 zenDescription = mContext.getString(R.string.interruption_level_priority);
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700241 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242
John Spurlockd9c75db2015-04-28 11:19:13 -0400243 if (DndTile.isVisible(mContext) && !DndTile.isCombinedIcon(mContext)
John Spurlocka48d7792015-03-03 17:35:57 -0500244 && audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT) {
245 volumeVisible = true;
246 volumeIconId = R.drawable.stat_sys_ringer_silent;
247 volumeDescription = mContext.getString(R.string.accessibility_ringer_silent);
John Spurlock4f1163c2015-04-02 17:41:21 -0400248 } else if (mZen != Global.ZEN_MODE_NO_INTERRUPTIONS && mZen != Global.ZEN_MODE_ALARMS &&
John Spurlock661f2cf2014-11-17 10:29:10 -0500249 audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400250 volumeVisible = true;
251 volumeIconId = R.drawable.stat_sys_ringer_vibrate;
252 volumeDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 }
John Spurlocka37e9c82014-07-08 09:40:31 -0400254
255 if (zenVisible) {
256 mService.setIcon(SLOT_ZEN, zenIconId, 0, zenDescription);
257 }
258 if (zenVisible != mZenVisible) {
259 mService.setIconVisibility(SLOT_ZEN, zenVisible);
260 mZenVisible = zenVisible;
261 }
262
263 if (volumeVisible) {
264 mService.setIcon(SLOT_VOLUME, volumeIconId, 0, volumeDescription);
265 }
266 if (volumeVisible != mVolumeVisible) {
267 mService.setIconVisibility(SLOT_VOLUME, volumeVisible);
268 mVolumeVisible = volumeVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 }
John Spurlock15782262015-05-29 15:35:53 -0400270 updateAlarm();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 }
272
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700273 private final void updateBluetooth() {
274 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
Joe Onorato798ac4c2010-05-27 16:39:00 -0400275 int iconId = R.drawable.stat_sys_data_bluetooth;
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700276 String contentDescription =
277 mContext.getString(R.string.accessibility_bluetooth_disconnected);
278 if (adapter != null) {
279 mBluetoothEnabled = (adapter.getState() == BluetoothAdapter.STATE_ON);
280 if (adapter.getConnectionState() == BluetoothAdapter.STATE_CONNECTED) {
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700281 iconId = R.drawable.stat_sys_data_bluetooth_connected;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700282 contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800283 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 } else {
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700285 mBluetoothEnabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700287
John Spurlocka37e9c82014-07-08 09:40:31 -0400288 mService.setIcon(SLOT_BLUETOOTH, iconId, 0, contentDescription);
289 mService.setIconVisibility(SLOT_BLUETOOTH, mBluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290 }
291
Wink Savillee9b06d72009-05-18 21:47:50 -0700292 private final void updateTTY(Intent intent) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700293 int currentTtyMode = intent.getIntExtra(TelecomManager.EXTRA_CURRENT_TTY_MODE,
294 TelecomManager.TTY_MODE_OFF);
295 boolean enabled = currentTtyMode != TelecomManager.TTY_MODE_OFF;
Wink Saville04e71b32009-04-02 11:00:54 -0700296
John Spurlocka37e9c82014-07-08 09:40:31 -0400297 if (DEBUG) Log.v(TAG, "updateTTY: enabled: " + enabled);
Wink Saville04e71b32009-04-02 11:00:54 -0700298
299 if (enabled) {
300 // TTY is on
John Spurlocka37e9c82014-07-08 09:40:31 -0400301 if (DEBUG) Log.v(TAG, "updateTTY: set TTY on");
302 mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700303 mContext.getString(R.string.accessibility_tty_enabled));
John Spurlocka37e9c82014-07-08 09:40:31 -0400304 mService.setIconVisibility(SLOT_TTY, true);
Wink Saville04e71b32009-04-02 11:00:54 -0700305 } else {
306 // TTY is off
John Spurlocka37e9c82014-07-08 09:40:31 -0400307 if (DEBUG) Log.v(TAG, "updateTTY: set TTY off");
308 mService.setIconVisibility(SLOT_TTY, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700309 }
310 }
John Spurlock96fe98d2014-08-27 09:36:02 -0400311
312 private void updateCast() {
313 boolean isCasting = false;
314 for (CastDevice device : mCast.getCastDevices()) {
315 if (device.state == CastDevice.STATE_CONNECTING
316 || device.state == CastDevice.STATE_CONNECTED) {
317 isCasting = true;
318 break;
319 }
320 }
321 if (DEBUG) Log.v(TAG, "updateCast: isCasting: " + isCasting);
322 if (isCasting) {
323 mService.setIcon(SLOT_CAST, R.drawable.stat_sys_cast, 0,
324 mContext.getString(R.string.accessibility_casting));
325 }
326 mService.setIconVisibility(SLOT_CAST, isCasting);
327 }
328
Kenny Guy3094d4a2015-04-01 19:14:10 +0100329 private void profileChanged(int userId) {
330 UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
331 UserInfo user = null;
332 if (userId == UserHandle.USER_CURRENT) {
333 try {
334 user = ActivityManagerNative.getDefault().getCurrentUser();
335 } catch (RemoteException e) {
336 // Ignore
337 }
338 } else {
339 user = userManager.getUserInfo(userId);
340 }
341
342 mManagedProfileFocused = user != null && user.isManagedProfile();
343 if (DEBUG) Log.v(TAG, "profileChanged: mManagedProfileFocused: " + mManagedProfileFocused);
344 // Actually update the icon later when transition starts.
345 }
346
347 private void updateManagedProfile() {
348 if (DEBUG) Log.v(TAG, "updateManagedProfile: mManagedProfileFocused: "
349 + mManagedProfileFocused
350 + " mKeyguardVisible: " + mKeyguardVisible);
351 boolean showIcon = mManagedProfileFocused && !mKeyguardVisible;
352 if (mManagedProfileIconVisible != showIcon) {
353 mService.setIconVisibility(SLOT_MANAGED_PROFILE, showIcon);
354 mManagedProfileIconVisible = showIcon;
355 }
356 }
357
358 private final IUserSwitchObserver.Stub mUserSwitchListener =
359 new IUserSwitchObserver.Stub() {
360 @Override
361 public void onUserSwitching(int newUserId, IRemoteCallback reply) {
362 }
363
364 @Override
365 public void onUserSwitchComplete(int newUserId) throws RemoteException {
366 updateAlarm();
367 profileChanged(newUserId);
368 }
369
370 @Override
371 public void onForegroundProfileSwitch(int newProfileId) {
372 profileChanged(newProfileId);
373 }
374 };
375
Jason Monk952d5d82014-10-27 15:28:22 -0400376 private final HotspotController.Callback mHotspotCallback = new HotspotController.Callback() {
377 @Override
378 public void onHotspotChanged(boolean enabled) {
379 mService.setIconVisibility(SLOT_HOTSPOT, enabled);
380 }
381 };
382
John Spurlock96fe98d2014-08-27 09:36:02 -0400383 private final CastController.Callback mCastCallback = new CastController.Callback() {
384 @Override
385 public void onCastDevicesChanged() {
386 updateCast();
387 }
388 };
Kenny Guy3094d4a2015-04-01 19:14:10 +0100389
390 public void appTransitionStarting(long startTime, long duration) {
391 updateManagedProfile();
392 }
393
394 public void setKeyguardShowing(boolean visible) {
395 mKeyguardVisible = visible;
396 updateManagedProfile();
397 }
John Spurlock604a5ee2015-06-01 12:27:22 -0400398
399 public void setCurrentUserSetup(boolean userSetup) {
400 if (mCurrentUserSetup == userSetup) return;
401 mCurrentUserSetup = userSetup;
402 updateAlarm();
403 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404}