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