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