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