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