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