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 | |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 19 | import android.app.AlarmManager; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 20 | import android.app.StatusBarManager; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 21 | import android.bluetooth.BluetoothAdapter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.BroadcastReceiver; |
| 23 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.Intent; |
| 25 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.media.AudioManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.os.Handler; |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 28 | import android.os.UserHandle; |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 29 | import android.provider.Settings.Global; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 30 | import android.telecom.TelecomManager; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 31 | import android.util.Log; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 33 | import com.android.internal.telephony.IccCardConstants; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 34 | import com.android.internal.telephony.TelephonyIntents; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 35 | import com.android.systemui.R; |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 36 | import com.android.systemui.statusbar.policy.CastController; |
| 37 | import com.android.systemui.statusbar.policy.CastController.CastDevice; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 38 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | /** |
| 40 | * 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] | 41 | * bar at boot time. It goes through the normal API for icons, even though it probably |
| 42 | * strictly doesn't need to. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | */ |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 44 | public class PhoneStatusBarPolicy { |
| 45 | private static final String TAG = "PhoneStatusBarPolicy"; |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 46 | private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 47 | |
Daniel Sandler | b1e8dab | 2011-09-26 20:06:19 -0400 | [diff] [blame] | 48 | private static final boolean SHOW_SYNC_ICON = false; |
| 49 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 50 | private static final String SLOT_SYNC_ACTIVE = "sync_active"; |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 51 | private static final String SLOT_CAST = "cast"; |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 52 | private static final String SLOT_BLUETOOTH = "bluetooth"; |
| 53 | private static final String SLOT_TTY = "tty"; |
| 54 | private static final String SLOT_ZEN = "zen"; |
| 55 | private static final String SLOT_VOLUME = "volume"; |
| 56 | private static final String SLOT_CDMA_ERI = "cdma_eri"; |
| 57 | private static final String SLOT_ALARM_CLOCK = "alarm_clock"; |
| 58 | |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 59 | private final Context mContext; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 60 | private final StatusBarManager mService; |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 61 | private final Handler mHandler = new Handler(); |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 62 | private final CastController mCast; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | // Assume it's all good unless we hear otherwise. We don't always seem |
| 65 | // to get broadcasts that it *is* there. |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 66 | IccCardConstants.State mSimState = IccCardConstants.State.READY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 68 | private boolean mZenVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | private boolean mVolumeVisible; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 70 | |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 71 | private int mZen; |
John Spurlock | ba2c6a0 | 2014-05-19 09:44:06 -0400 | [diff] [blame] | 72 | |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 73 | private boolean mBluetoothEnabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 75 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { |
| 77 | @Override |
| 78 | public void onReceive(Context context, Intent intent) { |
| 79 | String action = intent.getAction(); |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 80 | if (action.equals(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)) { |
| 81 | updateAlarm(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | } |
| 83 | else if (action.equals(Intent.ACTION_SYNC_STATE_CHANGED)) { |
| 84 | updateSyncState(intent); |
| 85 | } |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 86 | else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) || |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 87 | action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | updateBluetooth(intent); |
| 89 | } |
Eric Laurent | bffc3d1 | 2012-05-07 17:43:49 -0700 | [diff] [blame] | 90 | else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 91 | updateVolumeZen(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | } |
| 93 | else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) { |
| 94 | updateSimState(intent); |
| 95 | } |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 96 | else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 97 | updateTTY(intent); |
| 98 | } |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 99 | else if (action.equals(Intent.ACTION_USER_SWITCHED)) { |
| 100 | updateAlarm(); |
| 101 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | } |
| 103 | }; |
| 104 | |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 105 | public PhoneStatusBarPolicy(Context context, CastController cast) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | mContext = context; |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 107 | mCast = cast; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 108 | mService = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 110 | // listen for broadcasts |
| 111 | IntentFilter filter = new IntentFilter(); |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 112 | filter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED); |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 113 | filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED); |
| 114 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 115 | filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); |
| 116 | filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); |
| 117 | filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 118 | filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED); |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 119 | filter.addAction(Intent.ACTION_USER_SWITCHED); |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 120 | mContext.registerReceiver(mIntentReceiver, filter, null, mHandler); |
| 121 | |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 122 | // TTY status |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 123 | mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0, null); |
| 124 | mService.setIconVisibility(SLOT_TTY, false); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 125 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 126 | // Cdma Roaming Indicator, ERI |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 127 | mService.setIcon(SLOT_CDMA_ERI, R.drawable.stat_sys_roaming_cdma_0, 0, null); |
| 128 | mService.setIconVisibility(SLOT_CDMA_ERI, false); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 129 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | // bluetooth status |
Nick Pelly | f242b7b | 2009-10-08 00:12:45 +0200 | [diff] [blame] | 131 | BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 132 | int bluetoothIcon = R.drawable.stat_sys_data_bluetooth; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 133 | if (adapter != null) { |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 134 | mBluetoothEnabled = (adapter.getState() == BluetoothAdapter.STATE_ON); |
| 135 | if (adapter.getConnectionState() == BluetoothAdapter.STATE_CONNECTED) { |
| 136 | bluetoothIcon = R.drawable.stat_sys_data_bluetooth_connected; |
| 137 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | } |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 139 | mService.setIcon(SLOT_BLUETOOTH, bluetoothIcon, 0, null); |
| 140 | mService.setIconVisibility(SLOT_BLUETOOTH, mBluetoothEnabled); |
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 | |
| 146 | // Sync state |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 147 | mService.setIcon(SLOT_SYNC_ACTIVE, R.drawable.stat_sys_sync, 0, null); |
| 148 | mService.setIconVisibility(SLOT_SYNC_ACTIVE, false); |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 149 | // "sync_failing" is obsolete: b/1297963 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 151 | // zen |
| 152 | mService.setIcon(SLOT_ZEN, R.drawable.stat_sys_zen_important, 0, null); |
| 153 | mService.setIconVisibility(SLOT_ZEN, false); |
| 154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | // volume |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 156 | mService.setIcon(SLOT_VOLUME, R.drawable.stat_sys_ringer_vibrate, 0, null); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 157 | mService.setIconVisibility(SLOT_VOLUME, false); |
| 158 | updateVolumeZen(); |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 159 | |
| 160 | // cast |
| 161 | mService.setIcon(SLOT_CAST, R.drawable.stat_sys_cast, 0, null); |
| 162 | mService.setIconVisibility(SLOT_CAST, false); |
| 163 | mCast.addCallback(mCastCallback); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | } |
| 165 | |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 166 | public void setZenMode(int zen) { |
John Spurlock | ba2c6a0 | 2014-05-19 09:44:06 -0400 | [diff] [blame] | 167 | mZen = zen; |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 168 | updateVolumeZen(); |
John Spurlock | ba2c6a0 | 2014-05-19 09:44:06 -0400 | [diff] [blame] | 169 | } |
| 170 | |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 171 | private void updateAlarm() { |
| 172 | AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); |
| 173 | boolean alarmSet = alarmManager.getNextAlarmClock(UserHandle.USER_CURRENT) != null; |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 174 | mService.setIconVisibility(SLOT_ALARM_CLOCK, alarmSet); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | private final void updateSyncState(Intent intent) { |
Daniel Sandler | b1e8dab | 2011-09-26 20:06:19 -0400 | [diff] [blame] | 178 | if (!SHOW_SYNC_ICON) return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | boolean isActive = intent.getBooleanExtra("active", false); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 180 | mService.setIconVisibility(SLOT_SYNC_ACTIVE, isActive); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | } |
| 182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | private final void updateSimState(Intent intent) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 184 | String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE); |
| 185 | if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) { |
| 186 | mSimState = IccCardConstants.State.ABSENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | } |
Rakesh Pallerla | f099a5f | 2013-02-06 11:44:23 +0530 | [diff] [blame] | 188 | else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) { |
| 189 | mSimState = IccCardConstants.State.CARD_IO_ERROR; |
| 190 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 191 | else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) { |
| 192 | mSimState = IccCardConstants.State.READY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 194 | else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) { |
| 195 | final String lockedReason = |
| 196 | intent.getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON); |
| 197 | if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) { |
| 198 | mSimState = IccCardConstants.State.PIN_REQUIRED; |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 199 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 200 | else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) { |
| 201 | mSimState = IccCardConstants.State.PUK_REQUIRED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | } |
| 203 | else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 204 | mSimState = IccCardConstants.State.NETWORK_LOCKED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | } |
| 206 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 207 | mSimState = IccCardConstants.State.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | } |
| 210 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 211 | private final void updateVolumeZen() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 213 | |
| 214 | boolean zenVisible = false; |
| 215 | int zenIconId = 0; |
| 216 | String zenDescription = null; |
| 217 | |
| 218 | boolean volumeVisible = false; |
| 219 | int volumeIconId = 0; |
| 220 | String volumeDescription = null; |
| 221 | |
| 222 | if (mZen == Global.ZEN_MODE_NO_INTERRUPTIONS) { |
| 223 | zenVisible = true; |
| 224 | zenIconId = R.drawable.stat_sys_zen_none; |
| 225 | zenDescription = mContext.getString(R.string.zen_no_interruptions); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 226 | } else if (mZen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) { |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 227 | zenVisible = true; |
| 228 | zenIconId = R.drawable.stat_sys_zen_important; |
| 229 | zenDescription = mContext.getString(R.string.zen_important_interruptions); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 230 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 232 | if (mZen != Global.ZEN_MODE_NO_INTERRUPTIONS && |
| 233 | audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) { |
| 234 | volumeVisible = true; |
| 235 | volumeIconId = R.drawable.stat_sys_ringer_vibrate; |
| 236 | volumeDescription = mContext.getString(R.string.accessibility_ringer_vibrate); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | } |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 238 | |
| 239 | if (zenVisible) { |
| 240 | mService.setIcon(SLOT_ZEN, zenIconId, 0, zenDescription); |
| 241 | } |
| 242 | if (zenVisible != mZenVisible) { |
| 243 | mService.setIconVisibility(SLOT_ZEN, zenVisible); |
| 244 | mZenVisible = zenVisible; |
| 245 | } |
| 246 | |
| 247 | if (volumeVisible) { |
| 248 | mService.setIcon(SLOT_VOLUME, volumeIconId, 0, volumeDescription); |
| 249 | } |
| 250 | if (volumeVisible != mVolumeVisible) { |
| 251 | mService.setIconVisibility(SLOT_VOLUME, volumeVisible); |
| 252 | mVolumeVisible = volumeVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
| 256 | private final void updateBluetooth(Intent intent) { |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 257 | int iconId = R.drawable.stat_sys_data_bluetooth; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 258 | String contentDescription = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | String action = intent.getAction(); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 260 | if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { |
Nick Pelly | b24e11b | 2009-09-08 17:40:43 -0700 | [diff] [blame] | 261 | int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 262 | mBluetoothEnabled = state == BluetoothAdapter.STATE_ON; |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 263 | } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) { |
Jaikumar Ganesh | 0b63a6a | 2011-07-11 14:34:34 -0700 | [diff] [blame] | 264 | int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 265 | BluetoothAdapter.STATE_DISCONNECTED); |
| 266 | if (state == BluetoothAdapter.STATE_CONNECTED) { |
| 267 | iconId = R.drawable.stat_sys_data_bluetooth_connected; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 268 | contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected); |
| 269 | } else { |
| 270 | contentDescription = mContext.getString( |
| 271 | R.string.accessibility_bluetooth_disconnected); |
Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 272 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | } else { |
| 274 | return; |
| 275 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 276 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 277 | mService.setIcon(SLOT_BLUETOOTH, iconId, 0, contentDescription); |
| 278 | mService.setIconVisibility(SLOT_BLUETOOTH, mBluetoothEnabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | } |
| 280 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 281 | private final void updateTTY(Intent intent) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 282 | int currentTtyMode = intent.getIntExtra(TelecomManager.EXTRA_CURRENT_TTY_MODE, |
| 283 | TelecomManager.TTY_MODE_OFF); |
| 284 | boolean enabled = currentTtyMode != TelecomManager.TTY_MODE_OFF; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 285 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 286 | if (DEBUG) Log.v(TAG, "updateTTY: enabled: " + enabled); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 287 | |
| 288 | if (enabled) { |
| 289 | // TTY is on |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 290 | if (DEBUG) Log.v(TAG, "updateTTY: set TTY on"); |
| 291 | mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0, |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 292 | mContext.getString(R.string.accessibility_tty_enabled)); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 293 | mService.setIconVisibility(SLOT_TTY, true); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 294 | } else { |
| 295 | // TTY is off |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 296 | if (DEBUG) Log.v(TAG, "updateTTY: set TTY off"); |
| 297 | mService.setIconVisibility(SLOT_TTY, false); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 298 | } |
| 299 | } |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 300 | |
| 301 | private void updateCast() { |
| 302 | boolean isCasting = false; |
| 303 | for (CastDevice device : mCast.getCastDevices()) { |
| 304 | if (device.state == CastDevice.STATE_CONNECTING |
| 305 | || device.state == CastDevice.STATE_CONNECTED) { |
| 306 | isCasting = true; |
| 307 | break; |
| 308 | } |
| 309 | } |
| 310 | if (DEBUG) Log.v(TAG, "updateCast: isCasting: " + isCasting); |
| 311 | if (isCasting) { |
| 312 | mService.setIcon(SLOT_CAST, R.drawable.stat_sys_cast, 0, |
| 313 | mContext.getString(R.string.accessibility_casting)); |
| 314 | } |
| 315 | mService.setIconVisibility(SLOT_CAST, isCasting); |
| 316 | } |
| 317 | |
| 318 | private final CastController.Callback mCastCallback = new CastController.Callback() { |
| 319 | @Override |
| 320 | public void onCastDevicesChanged() { |
| 321 | updateCast(); |
| 322 | } |
| 323 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | } |