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