blob: cfaf016f7a1e1d2d5440ac65bd596b64a08525ed [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package com.android.server;
18
Wink Savillea12a7b32012-09-20 10:09:45 -070019import android.app.ActivityManager;
20import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.Context;
22import android.content.Intent;
Wink Savillea12a7b32012-09-20 10:09:45 -070023import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.content.pm.PackageManager;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070025import android.net.LinkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -070026import android.net.NetworkCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.os.Binder;
28import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070029import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070031import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070033import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.telephony.CellLocation;
Wink Saville070e0612014-04-15 22:04:10 -070035import android.telephony.DataConnectionRealTimeInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.telephony.PhoneStateListener;
37import android.telephony.ServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -070038import android.telephony.SignalStrength;
John Wang963db55d2012-03-30 16:04:06 -070039import android.telephony.CellInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.telephony.TelephonyManager;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020041import android.telephony.DisconnectCause;
42import android.telephony.PreciseCallState;
43import android.telephony.PreciseDataConnectionState;
44import android.telephony.PreciseDisconnectCause;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import android.text.TextUtils;
Joe Onorato8a9b2202010-02-26 18:56:32 -080046import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047
48import java.util.ArrayList;
Wink Savilleb208a242012-07-25 14:08:09 -070049import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import java.io.FileDescriptor;
51import java.io.PrintWriter;
52
53import com.android.internal.app.IBatteryStats;
54import com.android.internal.telephony.ITelephonyRegistry;
55import com.android.internal.telephony.IPhoneStateListener;
56import com.android.internal.telephony.DefaultPhoneNotifier;
Wink Savillea639b312012-07-10 12:37:54 -070057import com.android.internal.telephony.PhoneConstants;
Wink Savillec9330dd2011-01-12 13:37:38 -080058import com.android.internal.telephony.ServiceStateTracker;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import com.android.internal.telephony.TelephonyIntents;
60import com.android.server.am.BatteryStatsService;
61
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062/**
Wink Savillee9b06d72009-05-18 21:47:50 -070063 * Since phone process can be restarted, this class provides a centralized place
64 * that applications can register and be called back from.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 */
66class TelephonyRegistry extends ITelephonyRegistry.Stub {
67 private static final String TAG = "TelephonyRegistry";
Wink Savillec9acde92011-09-21 11:05:43 -070068 private static final boolean DBG = false;
Wink Savillea12a7b32012-09-20 10:09:45 -070069 private static final boolean DBG_LOC = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070
71 private static class Record {
72 String pkgForDebug;
Wink Savillee9b06d72009-05-18 21:47:50 -070073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 IPhoneStateListener callback;
Wink Savillee9b06d72009-05-18 21:47:50 -070077
Wink Savillea12a7b32012-09-20 10:09:45 -070078 int callerUid;
79
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -070081
82 @Override
83 public String toString() {
84 return "{pkgForDebug=" + pkgForDebug + " callerUid=" + callerUid +
85 " events=" + Integer.toHexString(events) + "}";
86 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 }
88
89 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -070090
Joe Onorato163d8d92010-10-21 13:21:20 -040091 // access should be inside synchronized (mRecords) for these two fields
92 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
93 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -070094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 private final IBatteryStats mBatteryStats;
96
97 private int mCallState = TelephonyManager.CALL_STATE_IDLE;
Wink Savillee9b06d72009-05-18 21:47:50 -070098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 private String mCallIncomingNumber = "";
Wink Savillee9b06d72009-05-18 21:47:50 -0700100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 private ServiceState mServiceState = new ServiceState();
Wink Savillee9b06d72009-05-18 21:47:50 -0700102
103 private SignalStrength mSignalStrength = new SignalStrength();
104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 private boolean mMessageWaiting = false;
Wink Savillee9b06d72009-05-18 21:47:50 -0700106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 private boolean mCallForwarding = false;
Wink Savillee9b06d72009-05-18 21:47:50 -0700108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 private int mDataActivity = TelephonyManager.DATA_ACTIVITY_NONE;
Wink Savillee9b06d72009-05-18 21:47:50 -0700110
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800111 private int mDataConnectionState = TelephonyManager.DATA_UNKNOWN;
Wink Savillee9b06d72009-05-18 21:47:50 -0700112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 private boolean mDataConnectionPossible = false;
Wink Savillee9b06d72009-05-18 21:47:50 -0700114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 private String mDataConnectionReason = "";
Wink Savillee9b06d72009-05-18 21:47:50 -0700116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 private String mDataConnectionApn = "";
Wink Savillee9b06d72009-05-18 21:47:50 -0700118
Robert Greenwalt02648a42010-05-18 10:52:51 -0700119 private ArrayList<String> mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700120
Wink Savillef61101f2010-09-16 16:36:42 -0700121 private LinkProperties mDataConnectionLinkProperties;
122
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -0700123 private NetworkCapabilities mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 private Bundle mCellLocation = new Bundle();
126
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700127 private int mDataConnectionNetworkType;
128
Wink Savillec9330dd2011-01-12 13:37:38 -0800129 private int mOtaspMode = ServiceStateTracker.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700130
Wink Savilleb208a242012-07-25 14:08:09 -0700131 private List<CellInfo> mCellInfo = null;
John Wang963db55d2012-03-30 16:04:06 -0700132
Wink Saville070e0612014-04-15 22:04:10 -0700133 private DataConnectionRealTimeInfo mDcRtInfo = new DataConnectionRealTimeInfo();
134
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200135 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
136
137 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
138
139 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
140
141 private PreciseCallState mPreciseCallState = new PreciseCallState();
142
143 private PreciseDataConnectionState mPreciseDataConnectionState =
144 new PreciseDataConnectionState();
145
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700146 static final int PHONE_STATE_PERMISSION_MASK =
147 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
148 PhoneStateListener.LISTEN_CALL_STATE |
149 PhoneStateListener.LISTEN_DATA_ACTIVITY |
150 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
151 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR;
152
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200153 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
154 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
155 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
156
Wink Savillea12a7b32012-09-20 10:09:45 -0700157 private static final int MSG_USER_SWITCHED = 1;
158
159 private final Handler mHandler = new Handler() {
160 @Override
161 public void handleMessage(Message msg) {
162 switch (msg.what) {
163 case MSG_USER_SWITCHED: {
Dianne Hackborn40e9f292012-11-27 19:12:23 -0800164 if (DBG) Slog.d(TAG, "MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillea12a7b32012-09-20 10:09:45 -0700165 TelephonyRegistry.this.notifyCellLocation(mCellLocation);
166 break;
167 }
168 }
169 }
170 };
171
172 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
173 @Override
174 public void onReceive(Context context, Intent intent) {
175 String action = intent.getAction();
176 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
177 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED,
178 intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0), 0));
179 }
180 }
181 };
182
Wink Savillee9b06d72009-05-18 21:47:50 -0700183 // we keep a copy of all of the state so we can send it out when folks
184 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700186 // In these calls we call with the lock held. This is safe becasuse remote
187 // calls go through a oneway interface and local calls going through a
188 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189
190 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700191 CellLocation location = CellLocation.getEmpty();
192
193 // Note that location can be null for non-phone builds like
194 // like the generic one.
195 if (location != null) {
196 location.fillInNotifierBundle(mCellLocation);
197 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 mContext = context;
199 mBatteryStats = BatteryStatsService.getService();
Robert Greenwalt02648a42010-05-18 10:52:51 -0700200 mConnectedApns = new ArrayList<String>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 }
202
Svetoslav Ganova0027152013-06-25 14:59:53 -0700203 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700204 // Watch for interesting updates
205 final IntentFilter filter = new IntentFilter();
206 filter.addAction(Intent.ACTION_USER_SWITCHED);
207 filter.addAction(Intent.ACTION_USER_REMOVED);
208 mContext.registerReceiver(mBroadcastReceiver, filter);
209 }
210
211 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
213 boolean notifyNow) {
Wink Savillea12a7b32012-09-20 10:09:45 -0700214 int callerUid = UserHandle.getCallingUserId();
215 int myUid = UserHandle.myUserId();
216 if (DBG) {
217 Slog.d(TAG, "listen: E pkg=" + pkgForDebug + " events=0x" + Integer.toHexString(events)
218 + " myUid=" + myUid
219 + " callerUid=" + callerUid);
220 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 if (events != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700222 /* Checks permission and throws Security exception */
223 checkListenerPermission(events);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224
225 synchronized (mRecords) {
226 // register
227 Record r = null;
228 find_and_add: {
229 IBinder b = callback.asBinder();
230 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700231 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 r = mRecords.get(i);
233 if (b == r.binder) {
234 break find_and_add;
235 }
236 }
237 r = new Record();
238 r.binder = b;
239 r.callback = callback;
240 r.pkgForDebug = pkgForDebug;
Wink Savillea12a7b32012-09-20 10:09:45 -0700241 r.callerUid = callerUid;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 mRecords.add(r);
Wink Savillea12a7b32012-09-20 10:09:45 -0700243 if (DBG) Slog.i(TAG, "listen: add new record=" + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 }
245 int send = events & (events ^ r.events);
246 r.events = events;
247 if (notifyNow) {
248 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400249 try {
250 r.callback.onServiceStateChanged(new ServiceState(mServiceState));
251 } catch (RemoteException ex) {
252 remove(r.binder);
253 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 }
255 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
256 try {
Wink Savillee9b06d72009-05-18 21:47:50 -0700257 int gsmSignalStrength = mSignalStrength.getGsmSignalStrength();
258 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
259 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 } catch (RemoteException ex) {
261 remove(r.binder);
262 }
263 }
264 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
265 try {
266 r.callback.onMessageWaitingIndicatorChanged(mMessageWaiting);
267 } catch (RemoteException ex) {
268 remove(r.binder);
269 }
270 }
271 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
272 try {
273 r.callback.onCallForwardingIndicatorChanged(mCallForwarding);
274 } catch (RemoteException ex) {
275 remove(r.binder);
276 }
277 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700278 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400279 try {
Wink Savillea12a7b32012-09-20 10:09:45 -0700280 if (DBG_LOC) Slog.d(TAG, "listen: mCellLocation=" + mCellLocation);
Joe Onorato163d8d92010-10-21 13:21:20 -0400281 r.callback.onCellLocationChanged(new Bundle(mCellLocation));
282 } catch (RemoteException ex) {
283 remove(r.binder);
284 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 }
286 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
287 try {
288 r.callback.onCallStateChanged(mCallState, mCallIncomingNumber);
289 } catch (RemoteException ex) {
290 remove(r.binder);
291 }
292 }
293 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
294 try {
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700295 r.callback.onDataConnectionStateChanged(mDataConnectionState,
296 mDataConnectionNetworkType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 } catch (RemoteException ex) {
298 remove(r.binder);
299 }
300 }
301 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
302 try {
303 r.callback.onDataActivity(mDataActivity);
304 } catch (RemoteException ex) {
305 remove(r.binder);
306 }
307 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700308 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
309 try {
310 r.callback.onSignalStrengthsChanged(mSignalStrength);
311 } catch (RemoteException ex) {
312 remove(r.binder);
313 }
314 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700315 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
316 try {
317 r.callback.onOtaspChanged(mOtaspMode);
318 } catch (RemoteException ex) {
319 remove(r.binder);
320 }
321 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700322 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700323 try {
Wink Savillea12a7b32012-09-20 10:09:45 -0700324 if (DBG_LOC) Slog.d(TAG, "listen: mCellInfo=" + mCellInfo);
Wink Savilleb208a242012-07-25 14:08:09 -0700325 r.callback.onCellInfoChanged(mCellInfo);
John Wang963db55d2012-03-30 16:04:06 -0700326 } catch (RemoteException ex) {
327 remove(r.binder);
328 }
329 }
Wink Saville070e0612014-04-15 22:04:10 -0700330 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO) != 0) {
331 try {
332 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
333 } catch (RemoteException ex) {
334 remove(r.binder);
335 }
336 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200337 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
338 try {
339 r.callback.onPreciseCallStateChanged(mPreciseCallState);
340 } catch (RemoteException ex) {
341 remove(r.binder);
342 }
343 }
344 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
345 try {
346 r.callback.onPreciseDataConnectionStateChanged(
347 mPreciseDataConnectionState);
348 } catch (RemoteException ex) {
349 remove(r.binder);
350 }
351 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 }
353 }
354 } else {
355 remove(callback.asBinder());
356 }
357 }
358
359 private void remove(IBinder binder) {
360 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700361 final int recordCount = mRecords.size();
362 for (int i = 0; i < recordCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 if (mRecords.get(i).binder == binder) {
364 mRecords.remove(i);
365 return;
366 }
367 }
368 }
369 }
370
371 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700372 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700373 return;
374 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 synchronized (mRecords) {
376 mCallState = state;
377 mCallIncomingNumber = incomingNumber;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700378 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 if ((r.events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
380 try {
381 r.callback.onCallStateChanged(state, incomingNumber);
382 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400383 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 }
385 }
386 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400387 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 }
389 broadcastCallStateChanged(state, incomingNumber);
390 }
391
392 public void notifyServiceState(ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700393 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700394 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700395 }
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700396 long ident = Binder.clearCallingIdentity();
397 try {
398 mBatteryStats.notePhoneState(state.getState());
399 } catch (RemoteException re) {
400 // Can't do much
401 } finally {
402 Binder.restoreCallingIdentity(ident);
403 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 synchronized (mRecords) {
405 mServiceState = state;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700406 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 if ((r.events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400408 try {
409 r.callback.onServiceStateChanged(new ServiceState(state));
410 } catch (RemoteException ex) {
411 mRemoveList.add(r.binder);
412 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 }
414 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400415 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 }
417 broadcastServiceStateChanged(state);
418 }
419
Wink Savillee9b06d72009-05-18 21:47:50 -0700420 public void notifySignalStrength(SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700421 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700422 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700423 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800424 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700425 mSignalStrength = signalStrength;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700426 for (Record r : mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700427 if ((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400428 try {
429 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
430 } catch (RemoteException ex) {
431 mRemoveList.add(r.binder);
432 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700433 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 if ((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
435 try {
Wink Savillee9b06d72009-05-18 21:47:50 -0700436 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
437 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
438 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400440 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 }
442 }
443 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400444 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700446 broadcastSignalStrengthChanged(signalStrength);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 }
448
Wink Savilleb208a242012-07-25 14:08:09 -0700449 public void notifyCellInfo(List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700450 if (!checkNotifyPermission("notifyCellInfo()")) {
451 return;
452 }
453
454 synchronized (mRecords) {
455 mCellInfo = cellInfo;
456 for (Record r : mRecords) {
Wink Savillea12a7b32012-09-20 10:09:45 -0700457 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700458 try {
Wink Savillea12a7b32012-09-20 10:09:45 -0700459 if (DBG_LOC) {
460 Slog.d(TAG, "notifyCellInfo: mCellInfo=" + mCellInfo + " r=" + r);
461 }
Wink Savilleb208a242012-07-25 14:08:09 -0700462 r.callback.onCellInfoChanged(cellInfo);
John Wang963db55d2012-03-30 16:04:06 -0700463 } catch (RemoteException ex) {
464 mRemoveList.add(r.binder);
465 }
466 }
467 }
468 handleRemoveListLocked();
469 }
470 }
471
Wink Saville070e0612014-04-15 22:04:10 -0700472 public void notifyDataConnectionRealTimeInfo(DataConnectionRealTimeInfo dcRtInfo) {
473 if (!checkNotifyPermission("notifyDataConnectionRealTimeInfo()")) {
474 return;
475 }
476
477 synchronized (mRecords) {
478 mDcRtInfo = dcRtInfo;
479 for (Record r : mRecords) {
480 if (validateEventsAndUserLocked(r,
481 PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO)) {
482 try {
483 if (DBG_LOC) {
484 Slog.d(TAG, "notifyDataConnectionRealTimeInfo: mDcRtInfo="
485 + mDcRtInfo + " r=" + r);
486 }
487 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
488 } catch (RemoteException ex) {
489 mRemoveList.add(r.binder);
490 }
491 }
492 }
493 handleRemoveListLocked();
494 }
495 }
496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 public void notifyMessageWaitingChanged(boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700498 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700499 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700500 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 synchronized (mRecords) {
502 mMessageWaiting = mwi;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700503 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 if ((r.events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
505 try {
506 r.callback.onMessageWaitingIndicatorChanged(mwi);
507 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400508 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 }
510 }
511 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400512 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 }
514 }
515
516 public void notifyCallForwardingChanged(boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700517 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700518 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700519 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 synchronized (mRecords) {
521 mCallForwarding = cfi;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700522 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523 if ((r.events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
524 try {
525 r.callback.onCallForwardingIndicatorChanged(cfi);
526 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400527 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 }
529 }
530 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400531 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 }
533 }
534
535 public void notifyDataActivity(int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700536 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700537 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700538 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 synchronized (mRecords) {
540 mDataActivity = state;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700541 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 if ((r.events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
543 try {
544 r.callback.onDataActivity(state);
545 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400546 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 }
548 }
549 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400550 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 }
552 }
553
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700554 public void notifyDataConnection(int state, boolean isDataConnectivityPossible,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700555 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -0700556 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700557 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700558 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700559 }
Wink Savillec9acde92011-09-21 11:05:43 -0700560 if (DBG) {
561 Slog.i(TAG, "notifyDataConnection: state=" + state + " isDataConnectivityPossible="
Wink Saville26f5a382010-11-24 16:44:29 -0800562 + isDataConnectivityPossible + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -0700563 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
564 + " mRecords.size()=" + mRecords.size() + " mRecords=" + mRecords);
Wink Savillec9acde92011-09-21 11:05:43 -0700565 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700567 boolean modified = false;
568 if (state == TelephonyManager.DATA_CONNECTED) {
569 if (!mConnectedApns.contains(apnType)) {
570 mConnectedApns.add(apnType);
571 if (mDataConnectionState != state) {
572 mDataConnectionState = state;
573 modified = true;
574 }
575 }
576 } else {
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800577 if (mConnectedApns.remove(apnType)) {
578 if (mConnectedApns.isEmpty()) {
579 mDataConnectionState = state;
580 modified = true;
581 } else {
582 // leave mDataConnectionState as is and
583 // send out the new status for the APN in question.
584 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700585 }
586 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700587 mDataConnectionPossible = isDataConnectivityPossible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 mDataConnectionReason = reason;
Wink Savillef61101f2010-09-16 16:36:42 -0700589 mDataConnectionLinkProperties = linkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -0700590 mDataConnectionNetworkCapabilities = networkCapabilities;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700591 if (mDataConnectionNetworkType != networkType) {
592 mDataConnectionNetworkType = networkType;
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800593 // need to tell registered listeners about the new network type
Robert Greenwalt02648a42010-05-18 10:52:51 -0700594 modified = true;
595 }
596 if (modified) {
Wink Savillec9acde92011-09-21 11:05:43 -0700597 if (DBG) {
598 Slog.d(TAG, "onDataConnectionStateChanged(" + mDataConnectionState
yoonsung.name6fa1202011-08-20 21:39:12 -0700599 + ", " + mDataConnectionNetworkType + ")");
Wink Savillec9acde92011-09-21 11:05:43 -0700600 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700601 for (Record r : mRecords) {
602 if ((r.events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
603 try {
yoonsung.name6fa1202011-08-20 21:39:12 -0700604 r.callback.onDataConnectionStateChanged(mDataConnectionState,
605 mDataConnectionNetworkType);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700606 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400607 mRemoveList.add(r.binder);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700608 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 }
610 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400611 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200613 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
614 apnType, apn, reason, linkProperties, "");
615 for (Record r : mRecords) {
616 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
617 try {
618 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
619 } catch (RemoteException ex) {
620 mRemoveList.add(r.binder);
621 }
622 }
623 }
624 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700626 broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -0700627 apnType, linkProperties, networkCapabilities, roaming);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200628 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
629 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 }
631
Robert Greenwalt02648a42010-05-18 10:52:51 -0700632 public void notifyDataConnectionFailed(String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700633 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700634 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700635 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200637 mPreciseDataConnectionState = new PreciseDataConnectionState(
638 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
639 apnType, "", reason, null, "");
640 for (Record r : mRecords) {
641 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
642 try {
643 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
644 } catch (RemoteException ex) {
645 mRemoveList.add(r.binder);
646 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 }
648 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200649 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700651 broadcastDataConnectionFailed(reason, apnType);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200652 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
653 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 }
655
656 public void notifyCellLocation(Bundle cellLocation) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700657 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700658 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700659 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800660 synchronized (mRecords) {
661 mCellLocation = cellLocation;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700662 for (Record r : mRecords) {
Wink Savillea12a7b32012-09-20 10:09:45 -0700663 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400664 try {
Wink Savillea12a7b32012-09-20 10:09:45 -0700665 if (DBG_LOC) {
666 Slog.d(TAG, "notifyCellLocation: mCellLocation=" + mCellLocation
667 + " r=" + r);
668 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400669 r.callback.onCellLocationChanged(new Bundle(cellLocation));
670 } catch (RemoteException ex) {
671 mRemoveList.add(r.binder);
672 }
673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 }
675 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400676 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -0700677 }
678 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679
Wink Savillefd2d0132010-10-28 14:22:26 -0700680 public void notifyOtaspChanged(int otaspMode) {
681 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
682 return;
683 }
684 synchronized (mRecords) {
685 mOtaspMode = otaspMode;
686 for (Record r : mRecords) {
687 if ((r.events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
688 try {
689 r.callback.onOtaspChanged(otaspMode);
690 } catch (RemoteException ex) {
691 mRemoveList.add(r.binder);
692 }
693 }
694 }
695 handleRemoveListLocked();
696 }
697 }
698
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200699 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
700 int backgroundCallState) {
701 if (!checkNotifyPermission("notifyPreciseCallState()")) {
702 return;
703 }
704 synchronized (mRecords) {
705 mRingingCallState = ringingCallState;
706 mForegroundCallState = foregroundCallState;
707 mBackgroundCallState = backgroundCallState;
708 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
709 backgroundCallState,
710 DisconnectCause.NOT_VALID,
711 PreciseDisconnectCause.NOT_VALID);
712 for (Record r : mRecords) {
713 if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
714 try {
715 r.callback.onPreciseCallStateChanged(mPreciseCallState);
716 } catch (RemoteException ex) {
717 mRemoveList.add(r.binder);
718 }
719 }
720 }
721 handleRemoveListLocked();
722 }
723 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
724 DisconnectCause.NOT_VALID,
725 PreciseDisconnectCause.NOT_VALID);
726 }
727
728 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
729 if (!checkNotifyPermission("notifyDisconnectCause()")) {
730 return;
731 }
732 synchronized (mRecords) {
733 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
734 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
735 for (Record r : mRecords) {
736 if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
737 try {
738 r.callback.onPreciseCallStateChanged(mPreciseCallState);
739 } catch (RemoteException ex) {
740 mRemoveList.add(r.binder);
741 }
742 }
743 }
744 handleRemoveListLocked();
745 }
746 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
747 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
748 }
749
750 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
751 String apn, String failCause) {
752 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
753 return;
754 }
755 synchronized (mRecords) {
756 mPreciseDataConnectionState = new PreciseDataConnectionState(
757 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
758 apnType, apn, reason, null, failCause);
759 for (Record r : mRecords) {
760 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
761 try {
762 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
763 } catch (RemoteException ex) {
764 mRemoveList.add(r.binder);
765 }
766 }
767 }
768 handleRemoveListLocked();
769 }
770 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
771 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
772 }
773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 @Override
775 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
776 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
777 != PackageManager.PERMISSION_GRANTED) {
778 pw.println("Permission Denial: can't dump telephony.registry from from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -0700779 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 return;
781 }
782 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700783 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 pw.println("last known state:");
785 pw.println(" mCallState=" + mCallState);
786 pw.println(" mCallIncomingNumber=" + mCallIncomingNumber);
787 pw.println(" mServiceState=" + mServiceState);
788 pw.println(" mSignalStrength=" + mSignalStrength);
789 pw.println(" mMessageWaiting=" + mMessageWaiting);
790 pw.println(" mCallForwarding=" + mCallForwarding);
791 pw.println(" mDataActivity=" + mDataActivity);
792 pw.println(" mDataConnectionState=" + mDataConnectionState);
793 pw.println(" mDataConnectionPossible=" + mDataConnectionPossible);
794 pw.println(" mDataConnectionReason=" + mDataConnectionReason);
795 pw.println(" mDataConnectionApn=" + mDataConnectionApn);
Wink Savillef61101f2010-09-16 16:36:42 -0700796 pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties);
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -0700797 pw.println(" mDataConnectionNetworkCapabilities=" +
798 mDataConnectionNetworkCapabilities);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 pw.println(" mCellLocation=" + mCellLocation);
John Wang963db55d2012-03-30 16:04:06 -0700800 pw.println(" mCellInfo=" + mCellInfo);
Wink Saville070e0612014-04-15 22:04:10 -0700801 pw.println(" mDcRtInfo=" + mDcRtInfo);
Wink Savillee9b06d72009-05-18 21:47:50 -0700802 pw.println("registrations: count=" + recordCount);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700803 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 pw.println(" " + r.pkgForDebug + " 0x" + Integer.toHexString(r.events));
805 }
806 }
807 }
808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800809 //
810 // the legacy intent broadcasting
811 //
812
813 private void broadcastServiceStateChanged(ServiceState state) {
814 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
815 Bundle data = new Bundle();
816 state.fillInNotifierBundle(data);
817 intent.putExtras(data);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700818 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 }
820
Wink Savillee9b06d72009-05-18 21:47:50 -0700821 private void broadcastSignalStrengthChanged(SignalStrength signalStrength) {
Dianne Hackborn627bba72009-03-24 22:32:56 -0700822 long ident = Binder.clearCallingIdentity();
823 try {
Wink Savillee9b06d72009-05-18 21:47:50 -0700824 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -0700825 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700826 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700827 } finally {
828 Binder.restoreCallingIdentity(ident);
829 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Dianne Hackborn1c633fc2009-12-08 19:45:14 -0800832 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
Wink Savillee9b06d72009-05-18 21:47:50 -0700833 Bundle data = new Bundle();
834 signalStrength.fillInNotifierBundle(data);
835 intent.putExtras(data);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700836 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 }
838
839 private void broadcastCallStateChanged(int state, String incomingNumber) {
840 long ident = Binder.clearCallingIdentity();
841 try {
842 if (state == TelephonyManager.CALL_STATE_IDLE) {
843 mBatteryStats.notePhoneOff();
844 } else {
845 mBatteryStats.notePhoneOn();
846 }
847 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700848 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 } finally {
850 Binder.restoreCallingIdentity(ident);
851 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800853 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -0700854 intent.putExtra(PhoneConstants.STATE_KEY,
855 DefaultPhoneNotifier.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800856 if (!TextUtils.isEmpty(incomingNumber)) {
857 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
858 }
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700859 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
860 android.Manifest.permission.READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 }
862
Robert Greenwalt42acef32009-08-12 16:08:25 -0700863 private void broadcastDataConnectionStateChanged(int state,
864 boolean isDataConnectivityPossible,
Wink Savillef61101f2010-09-16 16:36:42 -0700865 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -0700866 NetworkCapabilities networkCapabilities, boolean roaming) {
Dianne Hackborn627bba72009-03-24 22:32:56 -0700867 // Note: not reporting to the battery stats service here, because the
868 // status bar takes care of that after taking into account all of the
869 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -0700871 intent.putExtra(PhoneConstants.STATE_KEY,
872 DefaultPhoneNotifier.convertDataState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800873 if (!isDataConnectivityPossible) {
Wink Savillea639b312012-07-10 12:37:54 -0700874 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800875 }
876 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -0700877 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800878 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700879 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -0700880 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -0700881 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700882 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -0700883 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700884 }
885 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -0700886 if (networkCapabilities != null) {
887 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -0700888 }
Wink Savillea639b312012-07-10 12:37:54 -0700889 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -0700890
Wink Savillea639b312012-07-10 12:37:54 -0700891 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
892 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700893 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800894 }
895
Robert Greenwalt02648a42010-05-18 10:52:51 -0700896 private void broadcastDataConnectionFailed(String reason, String apnType) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -0700898 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
899 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700900 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700902
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200903 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
904 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
905 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
906 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
907 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
908 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
909 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
910 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
911 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
912 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
913 }
914
915 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
916 String apnType, String apn, String reason, LinkProperties linkProperties, String failCause) {
917 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
918 intent.putExtra(PhoneConstants.STATE_KEY, state);
919 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
920 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
921 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
922 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
923 if (linkProperties != null) intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
924 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
925
926 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
927 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
928 }
929
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700930 private boolean checkNotifyPermission(String method) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700931 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
932 == PackageManager.PERMISSION_GRANTED) {
933 return true;
934 }
935 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -0700936 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillec9acde92011-09-21 11:05:43 -0700937 if (DBG) Slog.w(TAG, msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700938 return false;
939 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700940
941 private void checkListenerPermission(int events) {
942 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
943 mContext.enforceCallingOrSelfPermission(
944 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
945
946 }
947
John Wang963db55d2012-03-30 16:04:06 -0700948 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
949 mContext.enforceCallingOrSelfPermission(
950 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
951
952 }
953
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700954 if ((events & PHONE_STATE_PERMISSION_MASK) != 0) {
955 mContext.enforceCallingOrSelfPermission(
956 android.Manifest.permission.READ_PHONE_STATE, null);
957 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200958
959 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
960 mContext.enforceCallingOrSelfPermission(
961 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
962
963 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700964 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400965
966 private void handleRemoveListLocked() {
967 if (mRemoveList.size() > 0) {
968 for (IBinder b: mRemoveList) {
969 remove(b);
970 }
971 mRemoveList.clear();
972 }
973 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700974
975 private boolean validateEventsAndUserLocked(Record r, int events) {
976 int foregroundUser;
977 long callingIdentity = Binder.clearCallingIdentity();
978 boolean valid = false;
979 try {
980 foregroundUser = ActivityManager.getCurrentUser();
981 valid = r.callerUid == foregroundUser && (r.events & events) != 0;
982 if (DBG | DBG_LOC) {
983 Slog.d(TAG, "validateEventsAndUserLocked: valid=" + valid
984 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
985 + " r.events=" + r.events + " events=" + events);
986 }
987 } finally {
988 Binder.restoreCallingIdentity(callingIdentity);
989 }
990 return valid;
991 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800992}