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