The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 17 | package com.android.systemui.statusbar.phone; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 19 | import android.app.ActivityManagerNative; |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 20 | import android.app.AlarmManager; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 21 | import android.app.IUserSwitchObserver; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 22 | import android.app.StatusBarManager; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 23 | import android.bluetooth.BluetoothAdapter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.BroadcastReceiver; |
| 25 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.content.Intent; |
| 27 | import android.content.IntentFilter; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 28 | import android.content.pm.UserInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.media.AudioManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.os.Handler; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 31 | import android.os.IRemoteCallback; |
| 32 | import android.os.RemoteException; |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 33 | import android.os.UserHandle; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 34 | import android.os.UserManager; |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 35 | import android.provider.Settings.Global; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 36 | import android.telecom.TelecomManager; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 37 | import android.util.Log; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 39 | import com.android.internal.telephony.IccCardConstants; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 40 | import com.android.internal.telephony.TelephonyIntents; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 41 | import com.android.systemui.R; |
John Spurlock | 3c4076a | 2015-02-24 12:12:25 -0500 | [diff] [blame] | 42 | import com.android.systemui.qs.tiles.DndTile; |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 43 | import com.android.systemui.statusbar.policy.CastController; |
| 44 | import com.android.systemui.statusbar.policy.CastController.CastDevice; |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 45 | import com.android.systemui.statusbar.policy.HotspotController; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 46 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | /** |
| 48 | * This class contains all of the policy about which icons are installed in the status |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 49 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | */ |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 52 | public class PhoneStatusBarPolicy { |
| 53 | private static final String TAG = "PhoneStatusBarPolicy"; |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 54 | private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 55 | |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 56 | private static final String SLOT_CAST = "cast"; |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 57 | private static final String SLOT_HOTSPOT = "hotspot"; |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 58 | 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 Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 62 | private static final String SLOT_ALARM_CLOCK = "alarm_clock"; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 63 | private static final String SLOT_MANAGED_PROFILE = "managed_profile"; |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 64 | |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 65 | private final Context mContext; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 66 | private final StatusBarManager mService; |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 67 | private final Handler mHandler = new Handler(); |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 68 | private final CastController mCast; |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 69 | private final HotspotController mHotspot; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | // Assume it's all good unless we hear otherwise. We don't always seem |
| 72 | // to get broadcasts that it *is* there. |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 73 | IccCardConstants.State mSimState = IccCardConstants.State.READY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 75 | private boolean mZenVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | private boolean mVolumeVisible; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 77 | |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 78 | private int mZen; |
John Spurlock | ba2c6a0 | 2014-05-19 09:44:06 -0400 | [diff] [blame] | 79 | |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 80 | private boolean mBluetoothEnabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 82 | private boolean mManagedProfileFocused = false; |
| 83 | private boolean mManagedProfileIconVisible = true; |
| 84 | |
| 85 | private boolean mKeyguardVisible = true; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 86 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { |
| 88 | @Override |
| 89 | public void onReceive(Context context, Intent intent) { |
| 90 | String action = intent.getAction(); |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 91 | if (action.equals(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)) { |
| 92 | updateAlarm(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | } |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 94 | else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) || |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 95 | action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) { |
Jorim Jaggi | 2d75f9f | 2014-10-08 17:10:58 -0700 | [diff] [blame] | 96 | updateBluetooth(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | } |
John Spurlock | bcc1087 | 2014-11-28 15:29:21 -0500 | [diff] [blame] | 98 | else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) || |
| 99 | action.equals(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)) { |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 100 | updateVolumeZen(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | } |
| 102 | else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) { |
| 103 | updateSimState(intent); |
| 104 | } |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 105 | else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 106 | updateTTY(intent); |
| 107 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | } |
| 109 | }; |
| 110 | |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 111 | public PhoneStatusBarPolicy(Context context, CastController cast, HotspotController hotspot) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | mContext = context; |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 113 | mCast = cast; |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 114 | mHotspot = hotspot; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 115 | mService = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 117 | // listen for broadcasts |
| 118 | IntentFilter filter = new IntentFilter(); |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 119 | filter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED); |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 120 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
John Spurlock | bcc1087 | 2014-11-28 15:29:21 -0500 | [diff] [blame] | 121 | filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION); |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 122 | filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); |
| 123 | filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); |
| 124 | filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 125 | filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED); |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 126 | mContext.registerReceiver(mIntentReceiver, filter, null, mHandler); |
| 127 | |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 128 | // listen for user / profile change. |
| 129 | try { |
| 130 | ActivityManagerNative.getDefault().registerUserSwitchObserver(mUserSwitchListener); |
| 131 | } catch (RemoteException e) { |
| 132 | // Ignore |
| 133 | } |
| 134 | |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 135 | // TTY status |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 136 | mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0, null); |
| 137 | mService.setIconVisibility(SLOT_TTY, false); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 138 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | // bluetooth status |
Jorim Jaggi | 2d75f9f | 2014-10-08 17:10:58 -0700 | [diff] [blame] | 140 | updateBluetooth(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | // Alarm clock |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 143 | mService.setIcon(SLOT_ALARM_CLOCK, R.drawable.stat_sys_alarm, 0, null); |
| 144 | mService.setIconVisibility(SLOT_ALARM_CLOCK, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 146 | // 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | // volume |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 151 | mService.setIcon(SLOT_VOLUME, R.drawable.stat_sys_ringer_vibrate, 0, null); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 152 | mService.setIconVisibility(SLOT_VOLUME, false); |
| 153 | updateVolumeZen(); |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 154 | |
| 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 Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 159 | |
| 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 Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 164 | |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | } |
| 169 | |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 170 | public void setZenMode(int zen) { |
John Spurlock | ba2c6a0 | 2014-05-19 09:44:06 -0400 | [diff] [blame] | 171 | mZen = zen; |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 172 | updateVolumeZen(); |
John Spurlock | ba2c6a0 | 2014-05-19 09:44:06 -0400 | [diff] [blame] | 173 | } |
| 174 | |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 175 | private void updateAlarm() { |
| 176 | AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); |
John Spurlock | 5b13e92 | 2015-01-07 11:04:58 -0500 | [diff] [blame] | 177 | boolean alarmSet = alarmManager.getNextAlarmClock(UserHandle.USER_CURRENT) != null; |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 178 | mService.setIconVisibility(SLOT_ALARM_CLOCK, alarmSet); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | } |
| 180 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | private final void updateSimState(Intent intent) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 182 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | } |
Rakesh Pallerla | f099a5f | 2013-02-06 11:44:23 +0530 | [diff] [blame] | 186 | else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) { |
| 187 | mSimState = IccCardConstants.State.CARD_IO_ERROR; |
| 188 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 189 | else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) { |
| 190 | mSimState = IccCardConstants.State.READY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 192 | 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; |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 197 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 198 | else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) { |
| 199 | mSimState = IccCardConstants.State.PUK_REQUIRED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | } |
| 201 | else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 202 | mSimState = IccCardConstants.State.NETWORK_LOCKED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | } |
| 204 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 205 | mSimState = IccCardConstants.State.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | } |
| 208 | |
John Spurlock | bcc1087 | 2014-11-28 15:29:21 -0500 | [diff] [blame] | 209 | private final void updateVolumeZen() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 211 | |
| 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 Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 220 | if (DndTile.isVisible(mContext) || DndTile.isCombinedIcon(mContext)) { |
John Spurlock | 3c4076a | 2015-02-24 12:12:25 -0500 | [diff] [blame] | 221 | zenVisible = mZen != Global.ZEN_MODE_OFF; |
John Spurlock | 4ec8b60 | 2015-05-11 17:46:28 -0400 | [diff] [blame^] | 222 | zenIconId = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS |
| 223 | ? R.drawable.stat_sys_dnd_total_silence : R.drawable.stat_sys_dnd; |
John Spurlock | 3c4076a | 2015-02-24 12:12:25 -0500 | [diff] [blame] | 224 | zenDescription = mContext.getString(R.string.quick_settings_dnd_label); |
| 225 | } else if (mZen == Global.ZEN_MODE_NO_INTERRUPTIONS) { |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 226 | zenVisible = true; |
| 227 | zenIconId = R.drawable.stat_sys_zen_none; |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 228 | zenDescription = mContext.getString(R.string.interruption_level_none); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 229 | } else if (mZen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) { |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 230 | zenVisible = true; |
| 231 | zenIconId = R.drawable.stat_sys_zen_important; |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 232 | zenDescription = mContext.getString(R.string.interruption_level_priority); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 233 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 235 | if (DndTile.isVisible(mContext) && !DndTile.isCombinedIcon(mContext) |
John Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 236 | && audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT) { |
| 237 | volumeVisible = true; |
| 238 | volumeIconId = R.drawable.stat_sys_ringer_silent; |
| 239 | volumeDescription = mContext.getString(R.string.accessibility_ringer_silent); |
John Spurlock | 4f1163c | 2015-04-02 17:41:21 -0400 | [diff] [blame] | 240 | } else if (mZen != Global.ZEN_MODE_NO_INTERRUPTIONS && mZen != Global.ZEN_MODE_ALARMS && |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 241 | audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE) { |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 242 | volumeVisible = true; |
| 243 | volumeIconId = R.drawable.stat_sys_ringer_vibrate; |
| 244 | volumeDescription = mContext.getString(R.string.accessibility_ringer_vibrate); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | } |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 246 | |
| 247 | if (zenVisible) { |
| 248 | mService.setIcon(SLOT_ZEN, zenIconId, 0, zenDescription); |
| 249 | } |
| 250 | if (zenVisible != mZenVisible) { |
| 251 | mService.setIconVisibility(SLOT_ZEN, zenVisible); |
| 252 | mZenVisible = zenVisible; |
| 253 | } |
| 254 | |
| 255 | if (volumeVisible) { |
| 256 | mService.setIcon(SLOT_VOLUME, volumeIconId, 0, volumeDescription); |
| 257 | } |
| 258 | if (volumeVisible != mVolumeVisible) { |
| 259 | mService.setIconVisibility(SLOT_VOLUME, volumeVisible); |
| 260 | mVolumeVisible = volumeVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
Jorim Jaggi | 2d75f9f | 2014-10-08 17:10:58 -0700 | [diff] [blame] | 264 | private final void updateBluetooth() { |
| 265 | BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 266 | int iconId = R.drawable.stat_sys_data_bluetooth; |
Jorim Jaggi | 2d75f9f | 2014-10-08 17:10:58 -0700 | [diff] [blame] | 267 | String contentDescription = |
| 268 | mContext.getString(R.string.accessibility_bluetooth_disconnected); |
| 269 | if (adapter != null) { |
| 270 | mBluetoothEnabled = (adapter.getState() == BluetoothAdapter.STATE_ON); |
| 271 | if (adapter.getConnectionState() == BluetoothAdapter.STATE_CONNECTED) { |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 272 | iconId = R.drawable.stat_sys_data_bluetooth_connected; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 273 | contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected); |
Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 274 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | } else { |
Jorim Jaggi | 2d75f9f | 2014-10-08 17:10:58 -0700 | [diff] [blame] | 276 | mBluetoothEnabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 278 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 279 | mService.setIcon(SLOT_BLUETOOTH, iconId, 0, contentDescription); |
| 280 | mService.setIconVisibility(SLOT_BLUETOOTH, mBluetoothEnabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 283 | private final void updateTTY(Intent intent) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 284 | int currentTtyMode = intent.getIntExtra(TelecomManager.EXTRA_CURRENT_TTY_MODE, |
| 285 | TelecomManager.TTY_MODE_OFF); |
| 286 | boolean enabled = currentTtyMode != TelecomManager.TTY_MODE_OFF; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 287 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 288 | if (DEBUG) Log.v(TAG, "updateTTY: enabled: " + enabled); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 289 | |
| 290 | if (enabled) { |
| 291 | // TTY is on |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 292 | if (DEBUG) Log.v(TAG, "updateTTY: set TTY on"); |
| 293 | mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0, |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 294 | mContext.getString(R.string.accessibility_tty_enabled)); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 295 | mService.setIconVisibility(SLOT_TTY, true); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 296 | } else { |
| 297 | // TTY is off |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 298 | if (DEBUG) Log.v(TAG, "updateTTY: set TTY off"); |
| 299 | mService.setIconVisibility(SLOT_TTY, false); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 300 | } |
| 301 | } |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 302 | |
| 303 | private void updateCast() { |
| 304 | boolean isCasting = false; |
| 305 | for (CastDevice device : mCast.getCastDevices()) { |
| 306 | if (device.state == CastDevice.STATE_CONNECTING |
| 307 | || device.state == CastDevice.STATE_CONNECTED) { |
| 308 | isCasting = true; |
| 309 | break; |
| 310 | } |
| 311 | } |
| 312 | if (DEBUG) Log.v(TAG, "updateCast: isCasting: " + isCasting); |
| 313 | if (isCasting) { |
| 314 | mService.setIcon(SLOT_CAST, R.drawable.stat_sys_cast, 0, |
| 315 | mContext.getString(R.string.accessibility_casting)); |
| 316 | } |
| 317 | mService.setIconVisibility(SLOT_CAST, isCasting); |
| 318 | } |
| 319 | |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 320 | private void profileChanged(int userId) { |
| 321 | UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); |
| 322 | UserInfo user = null; |
| 323 | if (userId == UserHandle.USER_CURRENT) { |
| 324 | try { |
| 325 | user = ActivityManagerNative.getDefault().getCurrentUser(); |
| 326 | } catch (RemoteException e) { |
| 327 | // Ignore |
| 328 | } |
| 329 | } else { |
| 330 | user = userManager.getUserInfo(userId); |
| 331 | } |
| 332 | |
| 333 | mManagedProfileFocused = user != null && user.isManagedProfile(); |
| 334 | if (DEBUG) Log.v(TAG, "profileChanged: mManagedProfileFocused: " + mManagedProfileFocused); |
| 335 | // Actually update the icon later when transition starts. |
| 336 | } |
| 337 | |
| 338 | private void updateManagedProfile() { |
| 339 | if (DEBUG) Log.v(TAG, "updateManagedProfile: mManagedProfileFocused: " |
| 340 | + mManagedProfileFocused |
| 341 | + " mKeyguardVisible: " + mKeyguardVisible); |
| 342 | boolean showIcon = mManagedProfileFocused && !mKeyguardVisible; |
| 343 | if (mManagedProfileIconVisible != showIcon) { |
| 344 | mService.setIconVisibility(SLOT_MANAGED_PROFILE, showIcon); |
| 345 | mManagedProfileIconVisible = showIcon; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | private final IUserSwitchObserver.Stub mUserSwitchListener = |
| 350 | new IUserSwitchObserver.Stub() { |
| 351 | @Override |
| 352 | public void onUserSwitching(int newUserId, IRemoteCallback reply) { |
| 353 | } |
| 354 | |
| 355 | @Override |
| 356 | public void onUserSwitchComplete(int newUserId) throws RemoteException { |
| 357 | updateAlarm(); |
| 358 | profileChanged(newUserId); |
| 359 | } |
| 360 | |
| 361 | @Override |
| 362 | public void onForegroundProfileSwitch(int newProfileId) { |
| 363 | profileChanged(newProfileId); |
| 364 | } |
| 365 | }; |
| 366 | |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 367 | private final HotspotController.Callback mHotspotCallback = new HotspotController.Callback() { |
| 368 | @Override |
| 369 | public void onHotspotChanged(boolean enabled) { |
| 370 | mService.setIconVisibility(SLOT_HOTSPOT, enabled); |
| 371 | } |
| 372 | }; |
| 373 | |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 374 | private final CastController.Callback mCastCallback = new CastController.Callback() { |
| 375 | @Override |
| 376 | public void onCastDevicesChanged() { |
| 377 | updateCast(); |
| 378 | } |
| 379 | }; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 380 | |
| 381 | public void appTransitionStarting(long startTime, long duration) { |
| 382 | updateManagedProfile(); |
| 383 | } |
| 384 | |
| 385 | public void setKeyguardShowing(boolean visible) { |
| 386 | mKeyguardVisible = visible; |
| 387 | updateManagedProfile(); |
| 388 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | } |