The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.content.Intent; |
| 21 | import android.content.pm.PackageManager; |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 22 | import android.net.LinkCapabilities; |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 23 | import android.net.LinkProperties; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.os.Binder; |
| 25 | import android.os.Bundle; |
| 26 | import android.os.IBinder; |
| 27 | import android.os.RemoteException; |
| 28 | import android.telephony.CellLocation; |
| 29 | import android.telephony.PhoneStateListener; |
| 30 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 31 | import android.telephony.SignalStrength; |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 32 | import android.telephony.CellInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.telephony.TelephonyManager; |
| 34 | import android.text.TextUtils; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 35 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
| 37 | import java.util.ArrayList; |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame^] | 38 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import java.io.FileDescriptor; |
| 40 | import java.io.PrintWriter; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 41 | import java.net.NetworkInterface; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
| 43 | import com.android.internal.app.IBatteryStats; |
| 44 | import com.android.internal.telephony.ITelephonyRegistry; |
| 45 | import com.android.internal.telephony.IPhoneStateListener; |
| 46 | import com.android.internal.telephony.DefaultPhoneNotifier; |
| 47 | import com.android.internal.telephony.Phone; |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 48 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | c9330dd | 2011-01-12 13:37:38 -0800 | [diff] [blame] | 49 | import com.android.internal.telephony.ServiceStateTracker; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import com.android.internal.telephony.TelephonyIntents; |
| 51 | import com.android.server.am.BatteryStatsService; |
| 52 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | /** |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 54 | * Since phone process can be restarted, this class provides a centralized place |
| 55 | * that applications can register and be called back from. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | */ |
| 57 | class TelephonyRegistry extends ITelephonyRegistry.Stub { |
| 58 | private static final String TAG = "TelephonyRegistry"; |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 59 | private static final boolean DBG = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | |
| 61 | private static class Record { |
| 62 | String pkgForDebug; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 63 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | IBinder binder; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 65 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | IPhoneStateListener callback; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 67 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | int events; |
| 69 | } |
| 70 | |
| 71 | private final Context mContext; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 72 | |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 73 | // access should be inside synchronized (mRecords) for these two fields |
| 74 | private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>(); |
| 75 | private final ArrayList<Record> mRecords = new ArrayList<Record>(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 76 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | private final IBatteryStats mBatteryStats; |
| 78 | |
| 79 | private int mCallState = TelephonyManager.CALL_STATE_IDLE; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 80 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | private String mCallIncomingNumber = ""; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 82 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | private ServiceState mServiceState = new ServiceState(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 84 | |
| 85 | private SignalStrength mSignalStrength = new SignalStrength(); |
| 86 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | private boolean mMessageWaiting = false; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 88 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | private boolean mCallForwarding = false; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 90 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | private int mDataActivity = TelephonyManager.DATA_ACTIVITY_NONE; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 92 | |
Robert Greenwalt | 8e7e0a9 | 2010-11-09 10:24:40 -0800 | [diff] [blame] | 93 | private int mDataConnectionState = TelephonyManager.DATA_UNKNOWN; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 94 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | private boolean mDataConnectionPossible = false; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 96 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | private String mDataConnectionReason = ""; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 98 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | private String mDataConnectionApn = ""; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 100 | |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 101 | private ArrayList<String> mConnectedApns; |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 102 | |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 103 | private LinkProperties mDataConnectionLinkProperties; |
| 104 | |
| 105 | private LinkCapabilities mDataConnectionLinkCapabilities; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | private Bundle mCellLocation = new Bundle(); |
| 108 | |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame] | 109 | private int mDataConnectionNetworkType; |
| 110 | |
Wink Saville | c9330dd | 2011-01-12 13:37:38 -0800 | [diff] [blame] | 111 | private int mOtaspMode = ServiceStateTracker.OTASP_UNKNOWN; |
Wink Saville | fd2d013 | 2010-10-28 14:22:26 -0700 | [diff] [blame] | 112 | |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame^] | 113 | private List<CellInfo> mCellInfo = null; |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 114 | |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 115 | static final int PHONE_STATE_PERMISSION_MASK = |
| 116 | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR | |
| 117 | PhoneStateListener.LISTEN_CALL_STATE | |
| 118 | PhoneStateListener.LISTEN_DATA_ACTIVITY | |
| 119 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE | |
| 120 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR; |
| 121 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 122 | // we keep a copy of all of the state so we can send it out when folks |
| 123 | // register for it |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | // |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 125 | // In these calls we call with the lock held. This is safe becasuse remote |
| 126 | // calls go through a oneway interface and local calls going through a |
| 127 | // handler before they get to app code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | |
| 129 | TelephonyRegistry(Context context) { |
David 'Digit' Turner | 4ef8ec3 | 2009-09-25 11:33:24 -0700 | [diff] [blame] | 130 | CellLocation location = CellLocation.getEmpty(); |
| 131 | |
| 132 | // Note that location can be null for non-phone builds like |
| 133 | // like the generic one. |
| 134 | if (location != null) { |
| 135 | location.fillInNotifierBundle(mCellLocation); |
| 136 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | mContext = context; |
| 138 | mBatteryStats = BatteryStatsService.getService(); |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 139 | mConnectedApns = new ArrayList<String>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | public void listen(String pkgForDebug, IPhoneStateListener callback, int events, |
| 143 | boolean notifyNow) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 144 | // Slog.d(TAG, "listen pkg=" + pkgForDebug + " events=0x" + |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 145 | // Integer.toHexString(events)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | if (events != 0) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 147 | /* Checks permission and throws Security exception */ |
| 148 | checkListenerPermission(events); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | |
| 150 | synchronized (mRecords) { |
| 151 | // register |
| 152 | Record r = null; |
| 153 | find_and_add: { |
| 154 | IBinder b = callback.asBinder(); |
| 155 | final int N = mRecords.size(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 156 | for (int i = 0; i < N; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | r = mRecords.get(i); |
| 158 | if (b == r.binder) { |
| 159 | break find_and_add; |
| 160 | } |
| 161 | } |
| 162 | r = new Record(); |
| 163 | r.binder = b; |
| 164 | r.callback = callback; |
| 165 | r.pkgForDebug = pkgForDebug; |
| 166 | mRecords.add(r); |
| 167 | } |
| 168 | int send = events & (events ^ r.events); |
| 169 | r.events = events; |
| 170 | if (notifyNow) { |
| 171 | if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 172 | try { |
| 173 | r.callback.onServiceStateChanged(new ServiceState(mServiceState)); |
| 174 | } catch (RemoteException ex) { |
| 175 | remove(r.binder); |
| 176 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | } |
| 178 | if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) { |
| 179 | try { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 180 | int gsmSignalStrength = mSignalStrength.getGsmSignalStrength(); |
| 181 | r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1 |
| 182 | : gsmSignalStrength)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | } catch (RemoteException ex) { |
| 184 | remove(r.binder); |
| 185 | } |
| 186 | } |
| 187 | if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) { |
| 188 | try { |
| 189 | r.callback.onMessageWaitingIndicatorChanged(mMessageWaiting); |
| 190 | } catch (RemoteException ex) { |
| 191 | remove(r.binder); |
| 192 | } |
| 193 | } |
| 194 | if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) { |
| 195 | try { |
| 196 | r.callback.onCallForwardingIndicatorChanged(mCallForwarding); |
| 197 | } catch (RemoteException ex) { |
| 198 | remove(r.binder); |
| 199 | } |
| 200 | } |
| 201 | if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 202 | try { |
| 203 | r.callback.onCellLocationChanged(new Bundle(mCellLocation)); |
| 204 | } catch (RemoteException ex) { |
| 205 | remove(r.binder); |
| 206 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | } |
| 208 | if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) { |
| 209 | try { |
| 210 | r.callback.onCallStateChanged(mCallState, mCallIncomingNumber); |
| 211 | } catch (RemoteException ex) { |
| 212 | remove(r.binder); |
| 213 | } |
| 214 | } |
| 215 | if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) { |
| 216 | try { |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame] | 217 | r.callback.onDataConnectionStateChanged(mDataConnectionState, |
| 218 | mDataConnectionNetworkType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | } catch (RemoteException ex) { |
| 220 | remove(r.binder); |
| 221 | } |
| 222 | } |
| 223 | if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) { |
| 224 | try { |
| 225 | r.callback.onDataActivity(mDataActivity); |
| 226 | } catch (RemoteException ex) { |
| 227 | remove(r.binder); |
| 228 | } |
| 229 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 230 | if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) { |
| 231 | try { |
| 232 | r.callback.onSignalStrengthsChanged(mSignalStrength); |
| 233 | } catch (RemoteException ex) { |
| 234 | remove(r.binder); |
| 235 | } |
| 236 | } |
Wink Saville | fd2d013 | 2010-10-28 14:22:26 -0700 | [diff] [blame] | 237 | if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) { |
| 238 | try { |
| 239 | r.callback.onOtaspChanged(mOtaspMode); |
| 240 | } catch (RemoteException ex) { |
| 241 | remove(r.binder); |
| 242 | } |
| 243 | } |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 244 | if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) { |
| 245 | try { |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame^] | 246 | r.callback.onCellInfoChanged(mCellInfo); |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 247 | } catch (RemoteException ex) { |
| 248 | remove(r.binder); |
| 249 | } |
| 250 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | } else { |
| 254 | remove(callback.asBinder()); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | private void remove(IBinder binder) { |
| 259 | synchronized (mRecords) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 260 | final int recordCount = mRecords.size(); |
| 261 | for (int i = 0; i < recordCount; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | if (mRecords.get(i).binder == binder) { |
| 263 | mRecords.remove(i); |
| 264 | return; |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | public void notifyCallState(int state, String incomingNumber) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 271 | if (!checkNotifyPermission("notifyCallState()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 272 | return; |
| 273 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | synchronized (mRecords) { |
| 275 | mCallState = state; |
| 276 | mCallIncomingNumber = incomingNumber; |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 277 | for (Record r : mRecords) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | if ((r.events & PhoneStateListener.LISTEN_CALL_STATE) != 0) { |
| 279 | try { |
| 280 | r.callback.onCallStateChanged(state, incomingNumber); |
| 281 | } catch (RemoteException ex) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 282 | mRemoveList.add(r.binder); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 286 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | } |
| 288 | broadcastCallStateChanged(state, incomingNumber); |
| 289 | } |
| 290 | |
| 291 | public void notifyServiceState(ServiceState state) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 292 | if (!checkNotifyPermission("notifyServiceState()")){ |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 293 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 294 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | synchronized (mRecords) { |
| 296 | mServiceState = state; |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 297 | for (Record r : mRecords) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 298 | if ((r.events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 299 | try { |
| 300 | r.callback.onServiceStateChanged(new ServiceState(state)); |
| 301 | } catch (RemoteException ex) { |
| 302 | mRemoveList.add(r.binder); |
| 303 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | } |
| 305 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 306 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | } |
| 308 | broadcastServiceStateChanged(state); |
| 309 | } |
| 310 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 311 | public void notifySignalStrength(SignalStrength signalStrength) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 312 | if (!checkNotifyPermission("notifySignalStrength()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 313 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 314 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | synchronized (mRecords) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 316 | mSignalStrength = signalStrength; |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 317 | for (Record r : mRecords) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 318 | if ((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 319 | try { |
| 320 | r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength)); |
| 321 | } catch (RemoteException ex) { |
| 322 | mRemoveList.add(r.binder); |
| 323 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 324 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | if ((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) { |
| 326 | try { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 327 | int gsmSignalStrength = signalStrength.getGsmSignalStrength(); |
| 328 | r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1 |
| 329 | : gsmSignalStrength)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | } catch (RemoteException ex) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 331 | mRemoveList.add(r.binder); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 335 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 337 | broadcastSignalStrengthChanged(signalStrength); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame^] | 340 | public void notifyCellInfo(List<CellInfo> cellInfo) { |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 341 | if (!checkNotifyPermission("notifyCellInfo()")) { |
| 342 | return; |
| 343 | } |
| 344 | |
| 345 | synchronized (mRecords) { |
| 346 | mCellInfo = cellInfo; |
| 347 | for (Record r : mRecords) { |
| 348 | if ((r.events & PhoneStateListener.LISTEN_CELL_INFO) != 0) { |
| 349 | try { |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame^] | 350 | r.callback.onCellInfoChanged(cellInfo); |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 351 | } catch (RemoteException ex) { |
| 352 | mRemoveList.add(r.binder); |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | handleRemoveListLocked(); |
| 357 | } |
| 358 | } |
| 359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | public void notifyMessageWaitingChanged(boolean mwi) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 361 | if (!checkNotifyPermission("notifyMessageWaitingChanged()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 362 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 363 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | synchronized (mRecords) { |
| 365 | mMessageWaiting = mwi; |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 366 | for (Record r : mRecords) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | if ((r.events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) { |
| 368 | try { |
| 369 | r.callback.onMessageWaitingIndicatorChanged(mwi); |
| 370 | } catch (RemoteException ex) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 371 | mRemoveList.add(r.binder); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 375 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
| 379 | public void notifyCallForwardingChanged(boolean cfi) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 380 | if (!checkNotifyPermission("notifyCallForwardingChanged()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 381 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 382 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | synchronized (mRecords) { |
| 384 | mCallForwarding = cfi; |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 385 | for (Record r : mRecords) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | if ((r.events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) { |
| 387 | try { |
| 388 | r.callback.onCallForwardingIndicatorChanged(cfi); |
| 389 | } catch (RemoteException ex) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 390 | mRemoveList.add(r.binder); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 394 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | |
| 398 | public void notifyDataActivity(int state) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 399 | if (!checkNotifyPermission("notifyDataActivity()" )) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 400 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 401 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | synchronized (mRecords) { |
| 403 | mDataActivity = state; |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 404 | for (Record r : mRecords) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | if ((r.events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) { |
| 406 | try { |
| 407 | r.callback.onDataActivity(state); |
| 408 | } catch (RemoteException ex) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 409 | mRemoveList.add(r.binder); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 413 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 417 | public void notifyDataConnection(int state, boolean isDataConnectivityPossible, |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 418 | String reason, String apn, String apnType, LinkProperties linkProperties, |
Robert Greenwalt | a6d4248 | 2011-09-02 15:19:31 -0700 | [diff] [blame] | 419 | LinkCapabilities linkCapabilities, int networkType, boolean roaming) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 420 | if (!checkNotifyPermission("notifyDataConnection()" )) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 421 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 422 | } |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 423 | if (DBG) { |
| 424 | Slog.i(TAG, "notifyDataConnection: state=" + state + " isDataConnectivityPossible=" |
Wink Saville | 26f5a38 | 2010-11-24 16:44:29 -0800 | [diff] [blame] | 425 | + isDataConnectivityPossible + " reason='" + reason |
| 426 | + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType); |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 427 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 428 | synchronized (mRecords) { |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 429 | boolean modified = false; |
| 430 | if (state == TelephonyManager.DATA_CONNECTED) { |
| 431 | if (!mConnectedApns.contains(apnType)) { |
| 432 | mConnectedApns.add(apnType); |
| 433 | if (mDataConnectionState != state) { |
| 434 | mDataConnectionState = state; |
| 435 | modified = true; |
| 436 | } |
| 437 | } |
| 438 | } else { |
Robert Greenwalt | 8e7e0a9 | 2010-11-09 10:24:40 -0800 | [diff] [blame] | 439 | if (mConnectedApns.remove(apnType)) { |
| 440 | if (mConnectedApns.isEmpty()) { |
| 441 | mDataConnectionState = state; |
| 442 | modified = true; |
| 443 | } else { |
| 444 | // leave mDataConnectionState as is and |
| 445 | // send out the new status for the APN in question. |
| 446 | } |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 447 | } |
| 448 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 449 | mDataConnectionPossible = isDataConnectivityPossible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | mDataConnectionReason = reason; |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 451 | mDataConnectionLinkProperties = linkProperties; |
| 452 | mDataConnectionLinkCapabilities = linkCapabilities; |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 453 | if (mDataConnectionNetworkType != networkType) { |
| 454 | mDataConnectionNetworkType = networkType; |
Robert Greenwalt | 8e7e0a9 | 2010-11-09 10:24:40 -0800 | [diff] [blame] | 455 | // need to tell registered listeners about the new network type |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 456 | modified = true; |
| 457 | } |
| 458 | if (modified) { |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 459 | if (DBG) { |
| 460 | Slog.d(TAG, "onDataConnectionStateChanged(" + mDataConnectionState |
yoonsung.nam | e6fa120 | 2011-08-20 21:39:12 -0700 | [diff] [blame] | 461 | + ", " + mDataConnectionNetworkType + ")"); |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 462 | } |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 463 | for (Record r : mRecords) { |
| 464 | if ((r.events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) { |
| 465 | try { |
yoonsung.nam | e6fa120 | 2011-08-20 21:39:12 -0700 | [diff] [blame] | 466 | r.callback.onDataConnectionStateChanged(mDataConnectionState, |
| 467 | mDataConnectionNetworkType); |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 468 | } catch (RemoteException ex) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 469 | mRemoveList.add(r.binder); |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 470 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | } |
| 472 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 473 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | } |
| 475 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 476 | broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn, |
Robert Greenwalt | a6d4248 | 2011-09-02 15:19:31 -0700 | [diff] [blame] | 477 | apnType, linkProperties, linkCapabilities, roaming); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | } |
| 479 | |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 480 | public void notifyDataConnectionFailed(String reason, String apnType) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 481 | if (!checkNotifyPermission("notifyDataConnectionFailed()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 482 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 483 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | /* |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 485 | * This is commented out because there is no onDataConnectionFailed callback |
| 486 | * in PhoneStateListener. There should be. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | synchronized (mRecords) { |
| 488 | mDataConnectionFailedReason = reason; |
| 489 | final int N = mRecords.size(); |
| 490 | for (int i=N-1; i>=0; i--) { |
| 491 | Record r = mRecords.get(i); |
| 492 | if ((r.events & PhoneStateListener.LISTEN_DATA_CONNECTION_FAILED) != 0) { |
| 493 | // XXX |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | */ |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 498 | broadcastDataConnectionFailed(reason, apnType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | public void notifyCellLocation(Bundle cellLocation) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 502 | if (!checkNotifyPermission("notifyCellLocation()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 503 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 504 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | synchronized (mRecords) { |
| 506 | mCellLocation = cellLocation; |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 507 | for (Record r : mRecords) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | if ((r.events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 509 | try { |
| 510 | r.callback.onCellLocationChanged(new Bundle(cellLocation)); |
| 511 | } catch (RemoteException ex) { |
| 512 | mRemoveList.add(r.binder); |
| 513 | } |
| 514 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | } |
| 516 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 517 | handleRemoveListLocked(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 518 | } |
| 519 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | |
Wink Saville | fd2d013 | 2010-10-28 14:22:26 -0700 | [diff] [blame] | 521 | public void notifyOtaspChanged(int otaspMode) { |
| 522 | if (!checkNotifyPermission("notifyOtaspChanged()" )) { |
| 523 | return; |
| 524 | } |
| 525 | synchronized (mRecords) { |
| 526 | mOtaspMode = otaspMode; |
| 527 | for (Record r : mRecords) { |
| 528 | if ((r.events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) { |
| 529 | try { |
| 530 | r.callback.onOtaspChanged(otaspMode); |
| 531 | } catch (RemoteException ex) { |
| 532 | mRemoveList.add(r.binder); |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | handleRemoveListLocked(); |
| 537 | } |
| 538 | } |
| 539 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | @Override |
| 541 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 542 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 543 | != PackageManager.PERMISSION_GRANTED) { |
| 544 | pw.println("Permission Denial: can't dump telephony.registry from from pid=" |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 545 | + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | return; |
| 547 | } |
| 548 | synchronized (mRecords) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 549 | final int recordCount = mRecords.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | pw.println("last known state:"); |
| 551 | pw.println(" mCallState=" + mCallState); |
| 552 | pw.println(" mCallIncomingNumber=" + mCallIncomingNumber); |
| 553 | pw.println(" mServiceState=" + mServiceState); |
| 554 | pw.println(" mSignalStrength=" + mSignalStrength); |
| 555 | pw.println(" mMessageWaiting=" + mMessageWaiting); |
| 556 | pw.println(" mCallForwarding=" + mCallForwarding); |
| 557 | pw.println(" mDataActivity=" + mDataActivity); |
| 558 | pw.println(" mDataConnectionState=" + mDataConnectionState); |
| 559 | pw.println(" mDataConnectionPossible=" + mDataConnectionPossible); |
| 560 | pw.println(" mDataConnectionReason=" + mDataConnectionReason); |
| 561 | pw.println(" mDataConnectionApn=" + mDataConnectionApn); |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 562 | pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties); |
| 563 | pw.println(" mDataConnectionLinkCapabilities=" + mDataConnectionLinkCapabilities); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | pw.println(" mCellLocation=" + mCellLocation); |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 565 | pw.println(" mCellInfo=" + mCellInfo); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 566 | pw.println("registrations: count=" + recordCount); |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 567 | for (Record r : mRecords) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | pw.println(" " + r.pkgForDebug + " 0x" + Integer.toHexString(r.events)); |
| 569 | } |
| 570 | } |
| 571 | } |
| 572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 573 | // |
| 574 | // the legacy intent broadcasting |
| 575 | // |
| 576 | |
| 577 | private void broadcastServiceStateChanged(ServiceState state) { |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 578 | long ident = Binder.clearCallingIdentity(); |
| 579 | try { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 580 | mBatteryStats.notePhoneState(state.getState()); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 581 | } catch (RemoteException re) { |
| 582 | // Can't do much |
| 583 | } finally { |
| 584 | Binder.restoreCallingIdentity(ident); |
| 585 | } |
| 586 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); |
| 588 | Bundle data = new Bundle(); |
| 589 | state.fillInNotifierBundle(data); |
| 590 | intent.putExtras(data); |
| 591 | mContext.sendStickyBroadcast(intent); |
| 592 | } |
| 593 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 594 | private void broadcastSignalStrengthChanged(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 595 | long ident = Binder.clearCallingIdentity(); |
| 596 | try { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 597 | mBatteryStats.notePhoneSignalStrength(signalStrength); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 598 | } catch (RemoteException e) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 599 | /* The remote entity disappeared, we can safely ignore the exception. */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 600 | } finally { |
| 601 | Binder.restoreCallingIdentity(ident); |
| 602 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 603 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 604 | Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED); |
Dianne Hackborn | 1c633fc | 2009-12-08 19:45:14 -0800 | [diff] [blame] | 605 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 606 | Bundle data = new Bundle(); |
| 607 | signalStrength.fillInNotifierBundle(data); |
| 608 | intent.putExtras(data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | mContext.sendStickyBroadcast(intent); |
| 610 | } |
| 611 | |
| 612 | private void broadcastCallStateChanged(int state, String incomingNumber) { |
| 613 | long ident = Binder.clearCallingIdentity(); |
| 614 | try { |
| 615 | if (state == TelephonyManager.CALL_STATE_IDLE) { |
| 616 | mBatteryStats.notePhoneOff(); |
| 617 | } else { |
| 618 | mBatteryStats.notePhoneOn(); |
| 619 | } |
| 620 | } catch (RemoteException e) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 621 | /* The remote entity disappeared, we can safely ignore the exception. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 622 | } finally { |
| 623 | Binder.restoreCallingIdentity(ident); |
| 624 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 625 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 626 | Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 627 | intent.putExtra(PhoneConstants.STATE_KEY, |
| 628 | DefaultPhoneNotifier.convertCallState(state).toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | if (!TextUtils.isEmpty(incomingNumber)) { |
| 630 | intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber); |
| 631 | } |
| 632 | mContext.sendBroadcast(intent, android.Manifest.permission.READ_PHONE_STATE); |
| 633 | } |
| 634 | |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 635 | private void broadcastDataConnectionStateChanged(int state, |
| 636 | boolean isDataConnectivityPossible, |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 637 | String reason, String apn, String apnType, LinkProperties linkProperties, |
Robert Greenwalt | a6d4248 | 2011-09-02 15:19:31 -0700 | [diff] [blame] | 638 | LinkCapabilities linkCapabilities, boolean roaming) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 639 | // Note: not reporting to the battery stats service here, because the |
| 640 | // status bar takes care of that after taking into account all of the |
| 641 | // required info. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 643 | intent.putExtra(PhoneConstants.STATE_KEY, |
| 644 | DefaultPhoneNotifier.convertDataState(state).toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 645 | if (!isDataConnectivityPossible) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 646 | intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 647 | } |
| 648 | if (reason != null) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 649 | intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 650 | } |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 651 | if (linkProperties != null) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 652 | intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties); |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 653 | String iface = linkProperties.getInterfaceName(); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 654 | if (iface != null) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 655 | intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 656 | } |
| 657 | } |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 658 | if (linkCapabilities != null) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 659 | intent.putExtra(PhoneConstants.DATA_LINK_CAPABILITIES_KEY, linkCapabilities); |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 660 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 661 | if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true); |
Robert Greenwalt | a6d4248 | 2011-09-02 15:19:31 -0700 | [diff] [blame] | 662 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 663 | intent.putExtra(PhoneConstants.DATA_APN_KEY, apn); |
| 664 | intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 665 | mContext.sendStickyBroadcast(intent); |
| 666 | } |
| 667 | |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 668 | private void broadcastDataConnectionFailed(String reason, String apnType) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 670 | intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason); |
| 671 | intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 672 | mContext.sendStickyBroadcast(intent); |
| 673 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 674 | |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 675 | private boolean checkNotifyPermission(String method) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 676 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 677 | == PackageManager.PERMISSION_GRANTED) { |
| 678 | return true; |
| 679 | } |
| 680 | String msg = "Modify Phone State Permission Denial: " + method + " from pid=" |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 681 | + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid(); |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 682 | if (DBG) Slog.w(TAG, msg); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 683 | return false; |
| 684 | } |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 685 | |
| 686 | private void checkListenerPermission(int events) { |
| 687 | if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) { |
| 688 | mContext.enforceCallingOrSelfPermission( |
| 689 | android.Manifest.permission.ACCESS_COARSE_LOCATION, null); |
| 690 | |
| 691 | } |
| 692 | |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 693 | if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) { |
| 694 | mContext.enforceCallingOrSelfPermission( |
| 695 | android.Manifest.permission.ACCESS_COARSE_LOCATION, null); |
| 696 | |
| 697 | } |
| 698 | |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 699 | if ((events & PHONE_STATE_PERMISSION_MASK) != 0) { |
| 700 | mContext.enforceCallingOrSelfPermission( |
| 701 | android.Manifest.permission.READ_PHONE_STATE, null); |
| 702 | } |
| 703 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 704 | |
| 705 | private void handleRemoveListLocked() { |
| 706 | if (mRemoveList.size() > 0) { |
| 707 | for (IBinder b: mRemoveList) { |
| 708 | remove(b); |
| 709 | } |
| 710 | mRemoveList.clear(); |
| 711 | } |
| 712 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | } |