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; |
| 22 | import android.os.Binder; |
| 23 | import android.os.Bundle; |
| 24 | import android.os.IBinder; |
| 25 | import android.os.RemoteException; |
| 26 | import android.telephony.CellLocation; |
| 27 | import android.telephony.PhoneStateListener; |
| 28 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 29 | import android.telephony.SignalStrength; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.telephony.TelephonyManager; |
| 31 | import android.text.TextUtils; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 32 | import android.util.Log; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | |
| 34 | import java.util.ArrayList; |
| 35 | import java.io.FileDescriptor; |
| 36 | import java.io.PrintWriter; |
| 37 | |
| 38 | import com.android.internal.app.IBatteryStats; |
| 39 | import com.android.internal.telephony.ITelephonyRegistry; |
| 40 | import com.android.internal.telephony.IPhoneStateListener; |
| 41 | import com.android.internal.telephony.DefaultPhoneNotifier; |
| 42 | import com.android.internal.telephony.Phone; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | import com.android.internal.telephony.TelephonyIntents; |
| 44 | import com.android.server.am.BatteryStatsService; |
| 45 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | /** |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 47 | * Since phone process can be restarted, this class provides a centralized place |
| 48 | * that applications can register and be called back from. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | */ |
| 50 | class TelephonyRegistry extends ITelephonyRegistry.Stub { |
| 51 | private static final String TAG = "TelephonyRegistry"; |
| 52 | |
| 53 | private static class Record { |
| 54 | String pkgForDebug; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 55 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | IBinder binder; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 57 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | IPhoneStateListener callback; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 59 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | int events; |
| 61 | } |
| 62 | |
| 63 | private final Context mContext; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 64 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | private final ArrayList<Record> mRecords = new ArrayList(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 66 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | private final IBatteryStats mBatteryStats; |
| 68 | |
| 69 | private int mCallState = TelephonyManager.CALL_STATE_IDLE; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 70 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | private String mCallIncomingNumber = ""; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 72 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | private ServiceState mServiceState = new ServiceState(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 74 | |
| 75 | private SignalStrength mSignalStrength = new SignalStrength(); |
| 76 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | private boolean mMessageWaiting = false; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 78 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | private boolean mCallForwarding = false; |
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 int mDataActivity = TelephonyManager.DATA_ACTIVITY_NONE; |
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 int mDataConnectionState = TelephonyManager.DATA_CONNECTED; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 84 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | private boolean mDataConnectionPossible = false; |
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 String mDataConnectionReason = ""; |
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 String mDataConnectionApn = ""; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 90 | |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 91 | private String[] mDataConnectionApnTypes = null; |
| 92 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | private String mDataConnectionInterfaceName = ""; |
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 Bundle mCellLocation = new Bundle(); |
| 96 | |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 97 | static final int PHONE_STATE_PERMISSION_MASK = |
| 98 | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR | |
| 99 | PhoneStateListener.LISTEN_CALL_STATE | |
| 100 | PhoneStateListener.LISTEN_DATA_ACTIVITY | |
| 101 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE | |
| 102 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR; |
| 103 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 104 | // we keep a copy of all of the state so we can send it out when folks |
| 105 | // register for it |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | // |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 107 | // In these calls we call with the lock held. This is safe becasuse remote |
| 108 | // calls go through a oneway interface and local calls going through a |
| 109 | // handler before they get to app code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | |
| 111 | TelephonyRegistry(Context context) { |
| 112 | CellLocation.getEmpty().fillInNotifierBundle(mCellLocation); |
| 113 | mContext = context; |
| 114 | mBatteryStats = BatteryStatsService.getService(); |
| 115 | } |
| 116 | |
| 117 | public void listen(String pkgForDebug, IPhoneStateListener callback, int events, |
| 118 | boolean notifyNow) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 119 | // Log.d(TAG, "listen pkg=" + pkgForDebug + " events=0x" + |
| 120 | // Integer.toHexString(events)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | if (events != 0) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 122 | /* Checks permission and throws Security exception */ |
| 123 | checkListenerPermission(events); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | |
| 125 | synchronized (mRecords) { |
| 126 | // register |
| 127 | Record r = null; |
| 128 | find_and_add: { |
| 129 | IBinder b = callback.asBinder(); |
| 130 | final int N = mRecords.size(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 131 | for (int i = 0; i < N; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | r = mRecords.get(i); |
| 133 | if (b == r.binder) { |
| 134 | break find_and_add; |
| 135 | } |
| 136 | } |
| 137 | r = new Record(); |
| 138 | r.binder = b; |
| 139 | r.callback = callback; |
| 140 | r.pkgForDebug = pkgForDebug; |
| 141 | mRecords.add(r); |
| 142 | } |
| 143 | int send = events & (events ^ r.events); |
| 144 | r.events = events; |
| 145 | if (notifyNow) { |
| 146 | if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) { |
| 147 | sendServiceState(r, mServiceState); |
| 148 | } |
| 149 | if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) { |
| 150 | try { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 151 | int gsmSignalStrength = mSignalStrength.getGsmSignalStrength(); |
| 152 | r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1 |
| 153 | : gsmSignalStrength)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | } catch (RemoteException ex) { |
| 155 | remove(r.binder); |
| 156 | } |
| 157 | } |
| 158 | if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) { |
| 159 | try { |
| 160 | r.callback.onMessageWaitingIndicatorChanged(mMessageWaiting); |
| 161 | } catch (RemoteException ex) { |
| 162 | remove(r.binder); |
| 163 | } |
| 164 | } |
| 165 | if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) { |
| 166 | try { |
| 167 | r.callback.onCallForwardingIndicatorChanged(mCallForwarding); |
| 168 | } catch (RemoteException ex) { |
| 169 | remove(r.binder); |
| 170 | } |
| 171 | } |
| 172 | if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) { |
| 173 | sendCellLocation(r, mCellLocation); |
| 174 | } |
| 175 | if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) { |
| 176 | try { |
| 177 | r.callback.onCallStateChanged(mCallState, mCallIncomingNumber); |
| 178 | } catch (RemoteException ex) { |
| 179 | remove(r.binder); |
| 180 | } |
| 181 | } |
| 182 | if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) { |
| 183 | try { |
| 184 | r.callback.onDataConnectionStateChanged(mDataConnectionState); |
| 185 | } catch (RemoteException ex) { |
| 186 | remove(r.binder); |
| 187 | } |
| 188 | } |
| 189 | if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) { |
| 190 | try { |
| 191 | r.callback.onDataActivity(mDataActivity); |
| 192 | } catch (RemoteException ex) { |
| 193 | remove(r.binder); |
| 194 | } |
| 195 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 196 | if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) { |
| 197 | try { |
| 198 | r.callback.onSignalStrengthsChanged(mSignalStrength); |
| 199 | } catch (RemoteException ex) { |
| 200 | remove(r.binder); |
| 201 | } |
| 202 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | } else { |
| 206 | remove(callback.asBinder()); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | private void remove(IBinder binder) { |
| 211 | synchronized (mRecords) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 212 | final int recordCount = mRecords.size(); |
| 213 | for (int i = 0; i < recordCount; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | if (mRecords.get(i).binder == binder) { |
| 215 | mRecords.remove(i); |
| 216 | return; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | public void notifyCallState(int state, String incomingNumber) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 223 | if (!checkNotifyPermission("notifyCallState()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 224 | return; |
| 225 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | synchronized (mRecords) { |
| 227 | mCallState = state; |
| 228 | mCallIncomingNumber = incomingNumber; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 229 | for (int i = mRecords.size() - 1; i >= 0; i--) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | Record r = mRecords.get(i); |
| 231 | if ((r.events & PhoneStateListener.LISTEN_CALL_STATE) != 0) { |
| 232 | try { |
| 233 | r.callback.onCallStateChanged(state, incomingNumber); |
| 234 | } catch (RemoteException ex) { |
| 235 | remove(r.binder); |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | broadcastCallStateChanged(state, incomingNumber); |
| 241 | } |
| 242 | |
| 243 | public void notifyServiceState(ServiceState state) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 244 | if (!checkNotifyPermission("notifyServiceState()")){ |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 245 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 246 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | synchronized (mRecords) { |
| 248 | mServiceState = state; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 249 | for (int i = mRecords.size() - 1; i >= 0; i--) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | Record r = mRecords.get(i); |
| 251 | if ((r.events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) { |
| 252 | sendServiceState(r, state); |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | broadcastServiceStateChanged(state); |
| 257 | } |
| 258 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 259 | public void notifySignalStrength(SignalStrength signalStrength) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 260 | if (!checkNotifyPermission("notifySignalStrength()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 261 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 262 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 263 | synchronized (mRecords) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 264 | mSignalStrength = signalStrength; |
| 265 | for (int i = mRecords.size() - 1; i >= 0; i--) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | Record r = mRecords.get(i); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 267 | if ((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) { |
| 268 | sendSignalStrength(r, signalStrength); |
| 269 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | if ((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) { |
| 271 | try { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 272 | int gsmSignalStrength = signalStrength.getGsmSignalStrength(); |
| 273 | r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1 |
| 274 | : gsmSignalStrength)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | } catch (RemoteException ex) { |
| 276 | remove(r.binder); |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 281 | broadcastSignalStrengthChanged(signalStrength); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | public void notifyMessageWaitingChanged(boolean mwi) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 285 | if (!checkNotifyPermission("notifyMessageWaitingChanged()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 286 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 287 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | synchronized (mRecords) { |
| 289 | mMessageWaiting = mwi; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 290 | for (int i = mRecords.size() - 1; i >= 0; i--) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | Record r = mRecords.get(i); |
| 292 | if ((r.events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) { |
| 293 | try { |
| 294 | r.callback.onMessageWaitingIndicatorChanged(mwi); |
| 295 | } catch (RemoteException ex) { |
| 296 | remove(r.binder); |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | public void notifyCallForwardingChanged(boolean cfi) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 304 | if (!checkNotifyPermission("notifyCallForwardingChanged()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 305 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 306 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | synchronized (mRecords) { |
| 308 | mCallForwarding = cfi; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 309 | for (int i = mRecords.size() - 1; i >= 0; i--) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | Record r = mRecords.get(i); |
| 311 | if ((r.events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) { |
| 312 | try { |
| 313 | r.callback.onCallForwardingIndicatorChanged(cfi); |
| 314 | } catch (RemoteException ex) { |
| 315 | remove(r.binder); |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | public void notifyDataActivity(int state) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 323 | if (!checkNotifyPermission("notifyDataActivity()" )) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 324 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 325 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | synchronized (mRecords) { |
| 327 | mDataActivity = state; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 328 | for (int i = mRecords.size() - 1; i >= 0; i--) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | Record r = mRecords.get(i); |
| 330 | if ((r.events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) { |
| 331 | try { |
| 332 | r.callback.onDataActivity(state); |
| 333 | } catch (RemoteException ex) { |
| 334 | remove(r.binder); |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 341 | public void notifyDataConnection(int state, boolean isDataConnectivityPossible, |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 342 | String reason, String apn, String[] apnTypes, String interfaceName) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 343 | if (!checkNotifyPermission("notifyDataConnection()" )) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 344 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 345 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | synchronized (mRecords) { |
| 347 | mDataConnectionState = state; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 348 | mDataConnectionPossible = isDataConnectivityPossible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | mDataConnectionReason = reason; |
| 350 | mDataConnectionApn = apn; |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 351 | mDataConnectionApnTypes = apnTypes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | mDataConnectionInterfaceName = interfaceName; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 353 | for (int i = mRecords.size() - 1; i >= 0; i--) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | Record r = mRecords.get(i); |
| 355 | if ((r.events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) { |
| 356 | try { |
| 357 | r.callback.onDataConnectionStateChanged(state); |
| 358 | } catch (RemoteException ex) { |
| 359 | remove(r.binder); |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 364 | broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn, |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 365 | apnTypes, interfaceName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | public void notifyDataConnectionFailed(String reason) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 369 | if (!checkNotifyPermission("notifyDataConnectionFailed()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 370 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 371 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | /* |
| 373 | * This is commented out because there is on onDataConnectionFailed callback |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 374 | * on PhoneStateListener. There should be |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 375 | synchronized (mRecords) { |
| 376 | mDataConnectionFailedReason = reason; |
| 377 | final int N = mRecords.size(); |
| 378 | for (int i=N-1; i>=0; i--) { |
| 379 | Record r = mRecords.get(i); |
| 380 | if ((r.events & PhoneStateListener.LISTEN_DATA_CONNECTION_FAILED) != 0) { |
| 381 | // XXX |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | */ |
| 386 | broadcastDataConnectionFailed(reason); |
| 387 | } |
| 388 | |
| 389 | public void notifyCellLocation(Bundle cellLocation) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 390 | if (!checkNotifyPermission("notifyCellLocation()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 391 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 392 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | synchronized (mRecords) { |
| 394 | mCellLocation = cellLocation; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 395 | for (int i = mRecords.size() - 1; i >= 0; i--) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | Record r = mRecords.get(i); |
| 397 | if ((r.events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) { |
| 398 | sendCellLocation(r, cellLocation); |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 404 | /** |
| 405 | * Copy the service state object so they can't mess it up in the local calls |
| 406 | */ |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 407 | public void sendServiceState(Record r, ServiceState state) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | try { |
| 409 | r.callback.onServiceStateChanged(new ServiceState(state)); |
| 410 | } catch (RemoteException ex) { |
| 411 | remove(r.binder); |
| 412 | } |
| 413 | } |
| 414 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 415 | private void sendCellLocation(Record r, Bundle cellLocation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 | try { |
| 417 | r.callback.onCellLocationChanged(new Bundle(cellLocation)); |
| 418 | } catch (RemoteException ex) { |
| 419 | remove(r.binder); |
| 420 | } |
| 421 | } |
| 422 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 423 | private void sendSignalStrength(Record r, SignalStrength signalStrength) { |
| 424 | try { |
| 425 | r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength)); |
| 426 | } catch (RemoteException ex) { |
| 427 | remove(r.binder); |
| 428 | } |
| 429 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | |
| 431 | @Override |
| 432 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 433 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 434 | != PackageManager.PERMISSION_GRANTED) { |
| 435 | pw.println("Permission Denial: can't dump telephony.registry from from pid=" |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 436 | + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 437 | return; |
| 438 | } |
| 439 | synchronized (mRecords) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 440 | final int recordCount = mRecords.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | pw.println("last known state:"); |
| 442 | pw.println(" mCallState=" + mCallState); |
| 443 | pw.println(" mCallIncomingNumber=" + mCallIncomingNumber); |
| 444 | pw.println(" mServiceState=" + mServiceState); |
| 445 | pw.println(" mSignalStrength=" + mSignalStrength); |
| 446 | pw.println(" mMessageWaiting=" + mMessageWaiting); |
| 447 | pw.println(" mCallForwarding=" + mCallForwarding); |
| 448 | pw.println(" mDataActivity=" + mDataActivity); |
| 449 | pw.println(" mDataConnectionState=" + mDataConnectionState); |
| 450 | pw.println(" mDataConnectionPossible=" + mDataConnectionPossible); |
| 451 | pw.println(" mDataConnectionReason=" + mDataConnectionReason); |
| 452 | pw.println(" mDataConnectionApn=" + mDataConnectionApn); |
| 453 | pw.println(" mDataConnectionInterfaceName=" + mDataConnectionInterfaceName); |
| 454 | pw.println(" mCellLocation=" + mCellLocation); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 455 | pw.println("registrations: count=" + recordCount); |
| 456 | for (int i = 0; i < recordCount; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | Record r = mRecords.get(i); |
| 458 | pw.println(" " + r.pkgForDebug + " 0x" + Integer.toHexString(r.events)); |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | // |
| 464 | // the legacy intent broadcasting |
| 465 | // |
| 466 | |
| 467 | private void broadcastServiceStateChanged(ServiceState state) { |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 468 | long ident = Binder.clearCallingIdentity(); |
| 469 | try { |
| 470 | mBatteryStats.noteAirplaneMode(state.getState() == ServiceState.STATE_POWER_OFF); |
| 471 | } catch (RemoteException re) { |
| 472 | // Can't do much |
| 473 | } finally { |
| 474 | Binder.restoreCallingIdentity(ident); |
| 475 | } |
| 476 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); |
| 478 | Bundle data = new Bundle(); |
| 479 | state.fillInNotifierBundle(data); |
| 480 | intent.putExtras(data); |
| 481 | mContext.sendStickyBroadcast(intent); |
| 482 | } |
| 483 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 484 | private void broadcastSignalStrengthChanged(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 485 | long ident = Binder.clearCallingIdentity(); |
| 486 | try { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 487 | mBatteryStats.notePhoneSignalStrength(signalStrength); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 488 | } catch (RemoteException e) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 489 | /* The remote entity disappeared, we can safely ignore the exception. */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 490 | } finally { |
| 491 | Binder.restoreCallingIdentity(ident); |
| 492 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 495 | Bundle data = new Bundle(); |
| 496 | signalStrength.fillInNotifierBundle(data); |
| 497 | intent.putExtras(data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | mContext.sendStickyBroadcast(intent); |
| 499 | } |
| 500 | |
| 501 | private void broadcastCallStateChanged(int state, String incomingNumber) { |
| 502 | long ident = Binder.clearCallingIdentity(); |
| 503 | try { |
| 504 | if (state == TelephonyManager.CALL_STATE_IDLE) { |
| 505 | mBatteryStats.notePhoneOff(); |
| 506 | } else { |
| 507 | mBatteryStats.notePhoneOn(); |
| 508 | } |
| 509 | } catch (RemoteException e) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 510 | /* 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] | 511 | } finally { |
| 512 | Binder.restoreCallingIdentity(ident); |
| 513 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 514 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 516 | intent.putExtra(Phone.STATE_KEY, DefaultPhoneNotifier.convertCallState(state).toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 517 | if (!TextUtils.isEmpty(incomingNumber)) { |
| 518 | intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber); |
| 519 | } |
| 520 | mContext.sendBroadcast(intent, android.Manifest.permission.READ_PHONE_STATE); |
| 521 | } |
| 522 | |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 523 | private void broadcastDataConnectionStateChanged(int state, |
| 524 | boolean isDataConnectivityPossible, |
| 525 | String reason, String apn, String[] apnTypes, String interfaceName) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 526 | // Note: not reporting to the battery stats service here, because the |
| 527 | // status bar takes care of that after taking into account all of the |
| 528 | // required info. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 529 | Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED); |
| 530 | intent.putExtra(Phone.STATE_KEY, DefaultPhoneNotifier.convertDataState(state).toString()); |
| 531 | if (!isDataConnectivityPossible) { |
| 532 | intent.putExtra(Phone.NETWORK_UNAVAILABLE_KEY, true); |
| 533 | } |
| 534 | if (reason != null) { |
| 535 | intent.putExtra(Phone.STATE_CHANGE_REASON_KEY, reason); |
| 536 | } |
| 537 | intent.putExtra(Phone.DATA_APN_KEY, apn); |
Robert Greenwalt | 75e1d31 | 2009-08-19 11:18:53 -0700 | [diff] [blame^] | 538 | String types = new String(""); |
| 539 | if (apnTypes.length > 0) { |
| 540 | types = apnTypes[0]; |
| 541 | for (int i = 1; i < apnTypes.length; i++) { |
| 542 | types = types+","+apnTypes[i]; |
| 543 | } |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 544 | } |
| 545 | intent.putExtra(Phone.DATA_APN_TYPES_KEY, types); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | intent.putExtra(Phone.DATA_IFACE_NAME_KEY, interfaceName); |
| 547 | mContext.sendStickyBroadcast(intent); |
| 548 | } |
| 549 | |
| 550 | private void broadcastDataConnectionFailed(String reason) { |
| 551 | Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED); |
| 552 | intent.putExtra(Phone.FAILURE_REASON_KEY, reason); |
| 553 | mContext.sendStickyBroadcast(intent); |
| 554 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 555 | |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 556 | private boolean checkNotifyPermission(String method) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 557 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 558 | == PackageManager.PERMISSION_GRANTED) { |
| 559 | return true; |
| 560 | } |
| 561 | String msg = "Modify Phone State Permission Denial: " + method + " from pid=" |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 562 | + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid(); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 563 | Log.w(TAG, msg); |
| 564 | return false; |
| 565 | } |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 566 | |
| 567 | private void checkListenerPermission(int events) { |
| 568 | if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) { |
| 569 | mContext.enforceCallingOrSelfPermission( |
| 570 | android.Manifest.permission.ACCESS_COARSE_LOCATION, null); |
| 571 | |
| 572 | } |
| 573 | |
| 574 | if ((events & PHONE_STATE_PERMISSION_MASK) != 0) { |
| 575 | mContext.enforceCallingOrSelfPermission( |
| 576 | android.Manifest.permission.READ_PHONE_STATE, null); |
| 577 | } |
| 578 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | } |