blob: 72c2eaf15de367f062b89a53d74719a7a513c457 [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;
Wink Savillef4cd25b2014-07-08 19:03:20 -070036import android.telephony.Rlog;
Wink Savillefb40dd42014-06-12 17:02:31 -070037import android.telephony.TelephonyManager;
38import android.telephony.SubscriptionManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.telephony.PhoneStateListener;
40import android.telephony.ServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -070041import android.telephony.SignalStrength;
John Wang963db55d2012-03-30 16:04:06 -070042import android.telephony.CellInfo;
Wink Savillefb40dd42014-06-12 17:02:31 -070043import android.telephony.VoLteServiceState;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020044import android.telephony.DisconnectCause;
45import android.telephony.PreciseCallState;
46import android.telephony.PreciseDataConnectionState;
47import android.telephony.PreciseDisconnectCause;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import android.text.TextUtils;
Wink Saville47d8d1b2014-07-10 13:01:52 -070049import android.text.format.Time;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050
51import java.util.ArrayList;
Wink Savilleb208a242012-07-25 14:08:09 -070052import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import java.io.FileDescriptor;
54import java.io.PrintWriter;
55
56import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080057import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import com.android.internal.telephony.ITelephonyRegistry;
59import com.android.internal.telephony.IPhoneStateListener;
60import com.android.internal.telephony.DefaultPhoneNotifier;
Wink Savillea639b312012-07-10 12:37:54 -070061import com.android.internal.telephony.PhoneConstants;
Wink Savillec9330dd2011-01-12 13:37:38 -080062import com.android.internal.telephony.ServiceStateTracker;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import com.android.internal.telephony.TelephonyIntents;
64import com.android.server.am.BatteryStatsService;
65
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066/**
Wink Savillee9b06d72009-05-18 21:47:50 -070067 * Since phone process can be restarted, this class provides a centralized place
68 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070069 *
70 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
71 * and 15973975 by saving the phoneId of the registrant and then using the
72 * phoneId when deciding to to make a callback. This is necessary because
73 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070074 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070075 * the dummy value conversion we properly do the callbacks.
76 *
77 * Eventually we may want to remove the notion of dummy value but for now this
78 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 */
80class TelephonyRegistry extends ITelephonyRegistry.Stub {
81 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070082 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070083 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070084 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085
86 private static class Record {
87 String pkgForDebug;
Wink Savillee9b06d72009-05-18 21:47:50 -070088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -080092 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -070093
Wink Savillea12a7b32012-09-20 10:09:45 -070094 int callerUid;
95
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -070097
Wink Savilled09c4ca2014-11-22 10:08:16 -080098 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -070099
Wink Savilled09c4ca2014-11-22 10:08:16 -0800100 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800101
102 boolean matchPhoneStateListenerEvent(int events) {
103 return (callback != null) && ((events & this.events) != 0);
104 }
105
Wink Savilled09c4ca2014-11-22 10:08:16 -0800106 boolean matchOnSubscriptionsChangedListener() {
107 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800108 }
Wink Savillee380b982014-07-26 18:24:22 -0700109
Wink Savillea12a7b32012-09-20 10:09:45 -0700110 @Override
111 public String toString() {
Wink Savillea374c3d2014-11-11 11:48:04 -0800112 return "{pkgForDebug=" + pkgForDebug + " binder=" + binder + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800113 + " onSubscriptionsChangedListenererCallback="
114 + onSubscriptionsChangedListenerCallback
Wink Savillea374c3d2014-11-11 11:48:04 -0800115 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
116 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700117 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 }
119
120 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700121
Joe Onorato163d8d92010-10-21 13:21:20 -0400122 // access should be inside synchronized (mRecords) for these two fields
123 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
124 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 private final IBatteryStats mBatteryStats;
127
Wink Savilled09c4ca2014-11-22 10:08:16 -0800128 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
129
Wink Savillefb40dd42014-06-12 17:02:31 -0700130 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700131
Wink Savillefb40dd42014-06-12 17:02:31 -0700132 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700133
Wink Savillefb40dd42014-06-12 17:02:31 -0700134 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700135
Wink Savillefb40dd42014-06-12 17:02:31 -0700136 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700137
Wink Savillefb40dd42014-06-12 17:02:31 -0700138 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700139
Wink Savillefb40dd42014-06-12 17:02:31 -0700140 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700141
Wink Savillefb40dd42014-06-12 17:02:31 -0700142 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700143
Wink Savillefb40dd42014-06-12 17:02:31 -0700144 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700145
Wink Savillefb40dd42014-06-12 17:02:31 -0700146 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700147
Wink Savillefb40dd42014-06-12 17:02:31 -0700148 private boolean[] mDataConnectionPossible;
Wink Savillee9b06d72009-05-18 21:47:50 -0700149
Wink Savillefb40dd42014-06-12 17:02:31 -0700150 private String[] mDataConnectionReason;
151
152 private String[] mDataConnectionApn;
Wink Savillee9b06d72009-05-18 21:47:50 -0700153
Robert Greenwalt02648a42010-05-18 10:52:51 -0700154 private ArrayList<String> mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700155
Wink Savillefb40dd42014-06-12 17:02:31 -0700156 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700157
Wink Savillefb40dd42014-06-12 17:02:31 -0700158 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700159
Wink Savillefb40dd42014-06-12 17:02:31 -0700160 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161
Wink Savillefb40dd42014-06-12 17:02:31 -0700162 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700163
Wink Savillec9330dd2011-01-12 13:37:38 -0800164 private int mOtaspMode = ServiceStateTracker.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700165
Wink Savillefb40dd42014-06-12 17:02:31 -0700166 private ArrayList<List<CellInfo>> mCellInfo = null;
167
168 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
169
Wink Savilled09c4ca2014-11-22 10:08:16 -0800170 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700171
Wink Savilled09c4ca2014-11-22 10:08:16 -0800172 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700173
Wink Saville070e0612014-04-15 22:04:10 -0700174 private DataConnectionRealTimeInfo mDcRtInfo = new DataConnectionRealTimeInfo();
175
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200176 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
177
178 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
179
180 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
181
182 private PreciseCallState mPreciseCallState = new PreciseCallState();
183
184 private PreciseDataConnectionState mPreciseDataConnectionState =
185 new PreciseDataConnectionState();
186
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700187 static final int PHONE_STATE_PERMISSION_MASK =
188 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
189 PhoneStateListener.LISTEN_CALL_STATE |
190 PhoneStateListener.LISTEN_DATA_ACTIVITY |
191 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
Wink Savillefb40dd42014-06-12 17:02:31 -0700192 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
193 PhoneStateListener.LISTEN_VOLTE_STATE;;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700194
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200195 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
196 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
197 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
198
Wink Savillea12a7b32012-09-20 10:09:45 -0700199 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700200 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700201
202 private final Handler mHandler = new Handler() {
203 @Override
204 public void handleMessage(Message msg) {
205 switch (msg.what) {
206 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700207 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700208 int numPhones = TelephonyManager.getDefault().getPhoneCount();
209 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700210 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700211 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700212 }
213 break;
214 }
xinhee9f16402014-09-25 16:39:28 -0700215 case MSG_UPDATE_DEFAULT_SUB: {
216 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700217 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700218 if (VDBG) {
219 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
220 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
221 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
222 }
223
224 //Due to possible risk condition,(notify call back using the new
225 //defaultSubId comes before new defaultSubId update) we need to recall all
226 //possible missed notify callback
227 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700228 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800229 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700230 checkPossibleMissNotify(r, newDefaultPhoneId);
231 }
232 }
233 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700234 }
235 mDefaultSubId = newDefaultSubId;
236 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700237 }
238 }
239 }
240 };
241
242 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
243 @Override
244 public void onReceive(Context context, Intent intent) {
245 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700246 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700247 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700248 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700249 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700250 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700251 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700252 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
xinhee9f16402014-09-25 16:39:28 -0700253 PhoneConstants.SUBSCRIPTION_KEY, SubscriptionManager.getDefaultSubId()));
254 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
255 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700256 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700257 log("onReceive:current mDefaultSubId=" + mDefaultSubId
258 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
259 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700260 }
xinhee9f16402014-09-25 16:39:28 -0700261
262 if(validatePhoneId(newDefaultPhoneId) && (newDefaultSubIdObj.equals(mDefaultSubId)
263 || (newDefaultPhoneId != mDefaultPhoneId))) {
264 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
265 newDefaultPhoneId, 0, newDefaultSubIdObj));
266 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700267 }
268 }
269 };
270
Wink Savillee9b06d72009-05-18 21:47:50 -0700271 // we keep a copy of all of the state so we can send it out when folks
272 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700274 // In these calls we call with the lock held. This is safe becasuse remote
275 // calls go through a oneway interface and local calls going through a
276 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277
278 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700279 CellLocation location = CellLocation.getEmpty();
280
Wink Savillefb40dd42014-06-12 17:02:31 -0700281 mContext = context;
282 mBatteryStats = BatteryStatsService.getService();
283 mConnectedApns = new ArrayList<String>();
284
Wink Savillefb40dd42014-06-12 17:02:31 -0700285 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700286 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700287 mNumPhones = numPhones;
288 mCallState = new int[numPhones];
289 mDataActivity = new int[numPhones];
290 mDataConnectionState = new int[numPhones];
291 mDataConnectionNetworkType = new int[numPhones];
292 mCallIncomingNumber = new String[numPhones];
293 mServiceState = new ServiceState[numPhones];
294 mSignalStrength = new SignalStrength[numPhones];
295 mMessageWaiting = new boolean[numPhones];
296 mDataConnectionPossible = new boolean[numPhones];
297 mDataConnectionReason = new String[numPhones];
298 mDataConnectionApn = new String[numPhones];
299 mCallForwarding = new boolean[numPhones];
300 mCellLocation = new Bundle[numPhones];
301 mDataConnectionLinkProperties = new LinkProperties[numPhones];
302 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
303 mCellInfo = new ArrayList<List<CellInfo>>();
304 for (int i = 0; i < numPhones; i++) {
305 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
306 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
307 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
308 mCallIncomingNumber[i] = "";
309 mServiceState[i] = new ServiceState();
310 mSignalStrength[i] = new SignalStrength();
311 mMessageWaiting[i] = false;
312 mCallForwarding[i] = false;
313 mDataConnectionPossible[i] = false;
314 mDataConnectionReason[i] = "";
315 mDataConnectionApn[i] = "";
316 mCellLocation[i] = new Bundle();
317 mCellInfo.add(i, null);
318 }
319
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700320 // Note that location can be null for non-phone builds like
321 // like the generic one.
322 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700323 for (int i = 0; i < numPhones; i++) {
324 location.fillInNotifierBundle(mCellLocation[i]);
325 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700326 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700327 mConnectedApns = new ArrayList<String>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800328 }
329
Svetoslav Ganova0027152013-06-25 14:59:53 -0700330 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700331 // Watch for interesting updates
332 final IntentFilter filter = new IntentFilter();
333 filter.addAction(Intent.ACTION_USER_SWITCHED);
334 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700335 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700336 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700337 mContext.registerReceiver(mBroadcastReceiver, filter);
338 }
339
340 @Override
Wink Savilled09c4ca2014-11-22 10:08:16 -0800341 public void registerOnSubscriptionsChangedListener(String pkgForDebug,
342 IOnSubscriptionsChangedListener callback) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800343 int callerUid = UserHandle.getCallingUserId();
344 int myUid = UserHandle.myUserId();
345 if (VDBG) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800346 log("listen oscl: E pkg=" + pkgForDebug + " myUid=" + myUid
347 + " callerUid=" + callerUid + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800348 + " callback.asBinder=" + callback.asBinder());
349 }
350
Wink Savilled09c4ca2014-11-22 10:08:16 -0800351 /* Checks permission and throws Security exception */
352 checkOnSubscriptionsChangedListenerPermission();
353 Record r = null;
Wink Savillea374c3d2014-11-11 11:48:04 -0800354
Wink Savilled09c4ca2014-11-22 10:08:16 -0800355 synchronized (mRecords) {
356 // register
357 find_and_add: {
358 IBinder b = callback.asBinder();
359 final int N = mRecords.size();
360 for (int i = 0; i < N; i++) {
361 r = mRecords.get(i);
362 if (b == r.binder) {
363 break find_and_add;
Wink Savillea374c3d2014-11-11 11:48:04 -0800364 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800365 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800366 r = new Record();
367 r.binder = b;
368 mRecords.add(r);
369 if (DBG) log("listen oscl: add new record");
Wink Savillea374c3d2014-11-11 11:48:04 -0800370 }
371
Wink Savilled09c4ca2014-11-22 10:08:16 -0800372 r.onSubscriptionsChangedListenerCallback = callback;
373 r.pkgForDebug = pkgForDebug;
374 r.callerUid = callerUid;
375 r.events = 0;
376 if (DBG) {
377 log("listen oscl: Register r=" + r);
378 }
379 // Always notify when registration occurs if there has been a notification.
380 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800381 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800382 if (VDBG) log("listen oscl: send to r=" + r);
383 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
384 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800385 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800386 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800387 remove(r.binder);
388 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800389 } else {
390 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800391 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800392 }
393 }
394
395 @Override
Wink Savilled09c4ca2014-11-22 10:08:16 -0800396 public void unregisterOnSubscriptionsChangedListener(String pkgForDebug,
397 IOnSubscriptionsChangedListener callback) {
398 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800399 remove(callback.asBinder());
400 }
401
Wink Savilled09c4ca2014-11-22 10:08:16 -0800402 private void checkOnSubscriptionsChangedListenerPermission() {
403 mContext.enforceCallingOrSelfPermission(
404 SubscriptionManager.OnSubscriptionsChangedListener
405 .PERMISSION_ON_SUBSCRIPTIONS_CHANGED, null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800406 }
407
408 @Override
409 public void notifySubscriptionInfoChanged() {
410 if (VDBG) log("notifySubscriptionInfoChanged:");
411 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800412 if (!hasNotifySubscriptionInfoChangedOccurred) {
413 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
414 + mRecords.size());
415 }
416 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800417 mRemoveList.clear();
418 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800419 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800420 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800421 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
422 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
423 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800424 } catch (RemoteException ex) {
425 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
426 mRemoveList.add(r.binder);
427 }
428 }
429 }
430 handleRemoveListLocked();
431 }
432 }
433
434 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
436 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800437 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
438 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700439 }
440
441 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700442 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700443 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700444 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700445 }
446
447 private void listen(String pkgForDebug, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700448 boolean notifyNow, int subId) {
Wink Savillea12a7b32012-09-20 10:09:45 -0700449 int callerUid = UserHandle.getCallingUserId();
450 int myUid = UserHandle.myUserId();
Wink Savillee380b982014-07-26 18:24:22 -0700451 if (VDBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700452 log("listen: E pkg=" + pkgForDebug + " events=0x" + Integer.toHexString(events)
xinhe43c50292014-09-18 17:56:48 -0700453 + " notifyNow=" + notifyNow + " subId=" + subId + " myUid=" + myUid
Wink Savillea12a7b32012-09-20 10:09:45 -0700454 + " callerUid=" + callerUid);
455 }
xinhe75c2c152014-10-16 11:49:45 -0700456
457 if (events != PhoneStateListener.LISTEN_NONE) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700458 /* Checks permission and throws Security exception */
459 checkListenerPermission(events);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460 synchronized (mRecords) {
461 // register
462 Record r = null;
463 find_and_add: {
464 IBinder b = callback.asBinder();
465 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700466 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 r = mRecords.get(i);
468 if (b == r.binder) {
469 break find_and_add;
470 }
471 }
472 r = new Record();
473 r.binder = b;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800474 mRecords.add(r);
Wink Savillee380b982014-07-26 18:24:22 -0700475 if (DBG) log("listen: add new record");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 }
xinhe43c50292014-09-18 17:56:48 -0700477
xinhe75c2c152014-10-16 11:49:45 -0700478 r.callback = callback;
479 r.pkgForDebug = pkgForDebug;
480 r.callerUid = callerUid;
481 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
482 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800483 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800484 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700485 } else {//APP specify subID
486 r.subId = subId;
487 }
488 r.phoneId = SubscriptionManager.getPhoneId(r.subId);
489
xinhe43c50292014-09-18 17:56:48 -0700490 int phoneId = r.phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700492 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700493 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700494 }
495 if (VDBG) toStringLogSSC("listen");
Wink Savillefb40dd42014-06-12 17:02:31 -0700496 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400498 try {
Wink Savillee380b982014-07-26 18:24:22 -0700499 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700500 r.callback.onServiceStateChanged(
501 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400502 } catch (RemoteException ex) {
503 remove(r.binder);
504 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 }
506 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
507 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700508 int gsmSignalStrength = mSignalStrength[phoneId]
509 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700510 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
511 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 } catch (RemoteException ex) {
513 remove(r.binder);
514 }
515 }
516 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
517 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700518 r.callback.onMessageWaitingIndicatorChanged(
519 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 } catch (RemoteException ex) {
521 remove(r.binder);
522 }
523 }
524 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
525 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700526 r.callback.onCallForwardingIndicatorChanged(
527 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 } catch (RemoteException ex) {
529 remove(r.binder);
530 }
531 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700532 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400533 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700534 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700535 + mCellLocation[phoneId]);
536 r.callback.onCellLocationChanged(
537 new Bundle(mCellLocation[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400538 } catch (RemoteException ex) {
539 remove(r.binder);
540 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 }
542 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
543 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700544 r.callback.onCallStateChanged(mCallState[phoneId],
545 mCallIncomingNumber[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 } catch (RemoteException ex) {
547 remove(r.binder);
548 }
549 }
550 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
551 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700552 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
553 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 } catch (RemoteException ex) {
555 remove(r.binder);
556 }
557 }
558 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
559 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700560 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 } catch (RemoteException ex) {
562 remove(r.binder);
563 }
564 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700565 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
566 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700567 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700568 } catch (RemoteException ex) {
569 remove(r.binder);
570 }
571 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700572 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
573 try {
574 r.callback.onOtaspChanged(mOtaspMode);
575 } catch (RemoteException ex) {
576 remove(r.binder);
577 }
578 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700579 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700580 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700581 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700582 + mCellInfo.get(phoneId));
583 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
John Wang963db55d2012-03-30 16:04:06 -0700584 } catch (RemoteException ex) {
585 remove(r.binder);
586 }
587 }
Wink Saville070e0612014-04-15 22:04:10 -0700588 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO) != 0) {
589 try {
590 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
591 } catch (RemoteException ex) {
592 remove(r.binder);
593 }
594 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200595 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
596 try {
597 r.callback.onPreciseCallStateChanged(mPreciseCallState);
598 } catch (RemoteException ex) {
599 remove(r.binder);
600 }
601 }
602 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
603 try {
604 r.callback.onPreciseDataConnectionStateChanged(
605 mPreciseDataConnectionState);
606 } catch (RemoteException ex) {
607 remove(r.binder);
608 }
609 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 }
611 }
612 } else {
xinhe75c2c152014-10-16 11:49:45 -0700613 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 remove(callback.asBinder());
615 }
616 }
617
618 private void remove(IBinder binder) {
619 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700620 final int recordCount = mRecords.size();
621 for (int i = 0; i < recordCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 if (mRecords.get(i).binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800623 if (DBG) {
624 Record r = mRecords.get(i);
625 log("remove: binder=" + binder + "r.pkgForDebug" + r.pkgForDebug
626 + "r.callback" + r.callback);
627 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 mRecords.remove(i);
629 return;
630 }
631 }
632 }
633 }
634
635 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700636 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700637 return;
638 }
xinhe43c50292014-09-18 17:56:48 -0700639
640 if (VDBG) {
641 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
642 }
643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700645 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800646 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800647 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800648 try {
649 r.callback.onCallStateChanged(state, incomingNumber);
650 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400651 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 }
653 }
654 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400655 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800657 broadcastCallStateChanged(state, incomingNumber,
658 SubscriptionManager.DEFAULT_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 }
660
Wink Saville63f03dd2014-10-23 10:44:45 -0700661 public void notifyCallStateForSubscriber(int subId, int state, String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700662 if (!checkNotifyPermission("notifyCallState()")) {
663 return;
664 }
Wink Savillee380b982014-07-26 18:24:22 -0700665 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700666 log("notifyCallStateForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700667 + " state=" + state + " incomingNumber=" + incomingNumber);
668 }
669 synchronized (mRecords) {
670 int phoneId = SubscriptionManager.getPhoneId(subId);
671 if (validatePhoneId(phoneId)) {
672 mCallState[phoneId] = state;
673 mCallIncomingNumber[phoneId] = incomingNumber;
674 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800675 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700676 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800677 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700678 try {
679 r.callback.onCallStateChanged(state, incomingNumber);
680 } catch (RemoteException ex) {
681 mRemoveList.add(r.binder);
682 }
683 }
684 }
685 }
686 handleRemoveListLocked();
687 }
688 broadcastCallStateChanged(state, incomingNumber, subId);
689 }
690
Wink Saville63f03dd2014-10-23 10:44:45 -0700691 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700692 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700693 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700694 }
xinhe43c50292014-09-18 17:56:48 -0700695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800696 synchronized (mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700697 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700698 log("notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
Wink Saville47d8d1b2014-07-10 13:01:52 -0700699 + " state=" + state);
700 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700701 if (validatePhoneId(phoneId)) {
702 mServiceState[phoneId] = state;
Wink Savillebc027272014-09-08 14:50:58 -0700703 logServiceStateChanged("notifyServiceStateForSubscriber", subId, phoneId, state);
704 if (VDBG) toStringLogSSC("notifyServiceStateForSubscriber");
Wink Saville47d8d1b2014-07-10 13:01:52 -0700705
Wink Savillefb40dd42014-06-12 17:02:31 -0700706 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700707 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700708 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700709 + " phoneId=" + phoneId + " state=" + state);
710 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800711 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800712 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700713 try {
Wink Savillee380b982014-07-26 18:24:22 -0700714 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700715 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700716 + " subId=" + subId + " phoneId=" + phoneId
717 + " state=" + state);
718 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700719 r.callback.onServiceStateChanged(new ServiceState(state));
720 } catch (RemoteException ex) {
721 mRemoveList.add(r.binder);
722 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400723 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800724 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700725 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700726 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400728 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700730 broadcastServiceStateChanged(state, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 }
732
Wink Savillee9b06d72009-05-18 21:47:50 -0700733 public void notifySignalStrength(SignalStrength signalStrength) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800734 notifySignalStrengthForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
735 signalStrength);
Wink Savillefb40dd42014-06-12 17:02:31 -0700736 }
737
Wink Saville63f03dd2014-10-23 10:44:45 -0700738 public void notifySignalStrengthForSubscriber(int subId, SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700739 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700740 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700741 }
Wink Savillee380b982014-07-26 18:24:22 -0700742 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700743 log("notifySignalStrengthForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700744 + " signalStrength=" + signalStrength);
Wink Savillebc027272014-09-08 14:50:58 -0700745 toStringLogSSC("notifySignalStrengthForSubscriber");
Wink Savillefb40dd42014-06-12 17:02:31 -0700746 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700748 int phoneId = SubscriptionManager.getPhoneId(subId);
749 if (validatePhoneId(phoneId)) {
Wink Savillebc027272014-09-08 14:50:58 -0700750 if (VDBG) log("notifySignalStrengthForSubscriber: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700751 mSignalStrength[phoneId] = signalStrength;
752 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700753 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700754 log("notifySignalStrengthForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700755 + " phoneId=" + phoneId + " ss=" + signalStrength);
756 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800757 if (r.matchPhoneStateListenerEvent(
758 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800759 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700760 try {
Wink Savillee380b982014-07-26 18:24:22 -0700761 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700762 log("notifySignalStrengthForSubscriber: callback.onSsS r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700763 + " subId=" + subId + " phoneId=" + phoneId
764 + " ss=" + signalStrength);
765 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700766 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
767 } catch (RemoteException ex) {
768 mRemoveList.add(r.binder);
769 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400770 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800771 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800772 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700773 try {
774 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700775 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Wink Savillee380b982014-07-26 18:24:22 -0700776 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700777 log("notifySignalStrengthForSubscriber: callback.onSS r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700778 + " subId=" + subId + " phoneId=" + phoneId
779 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
780 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700781 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700782 } catch (RemoteException ex) {
783 mRemoveList.add(r.binder);
784 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800785 }
786 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700787 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700788 log("notifySignalStrengthForSubscriber: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400790 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700792 broadcastSignalStrengthChanged(signalStrength, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800793 }
794
Wink Savilleb208a242012-07-25 14:08:09 -0700795 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800796 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700797 }
798
Wink Saville63f03dd2014-10-23 10:44:45 -0700799 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700800 if (!checkNotifyPermission("notifyCellInfo()")) {
801 return;
802 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700803 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700804 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700805 + " cellInfo=" + cellInfo);
806 }
John Wang963db55d2012-03-30 16:04:06 -0700807
808 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700809 int phoneId = SubscriptionManager.getPhoneId(subId);
810 if (validatePhoneId(phoneId)) {
811 mCellInfo.set(phoneId, cellInfo);
812 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -0700813 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
xinhe8b79fb62014-11-05 14:55:03 -0800814 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700815 try {
816 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700817 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -0700818 }
819 r.callback.onCellInfoChanged(cellInfo);
820 } catch (RemoteException ex) {
821 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700822 }
John Wang963db55d2012-03-30 16:04:06 -0700823 }
824 }
825 }
826 handleRemoveListLocked();
827 }
828 }
829
Wink Saville070e0612014-04-15 22:04:10 -0700830 public void notifyDataConnectionRealTimeInfo(DataConnectionRealTimeInfo dcRtInfo) {
831 if (!checkNotifyPermission("notifyDataConnectionRealTimeInfo()")) {
832 return;
833 }
834
835 synchronized (mRecords) {
836 mDcRtInfo = dcRtInfo;
837 for (Record r : mRecords) {
838 if (validateEventsAndUserLocked(r,
839 PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO)) {
840 try {
841 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700842 log("notifyDataConnectionRealTimeInfo: mDcRtInfo="
Wink Saville070e0612014-04-15 22:04:10 -0700843 + mDcRtInfo + " r=" + r);
844 }
845 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
846 } catch (RemoteException ex) {
847 mRemoveList.add(r.binder);
848 }
849 }
850 }
851 handleRemoveListLocked();
852 }
853 }
854
xinhe43c50292014-09-18 17:56:48 -0700855 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700856 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700857 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700858 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700859 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700860 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -0700861 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -0700862 + " mwi=" + mwi);
863 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800864 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700865 if (validatePhoneId(phoneId)) {
866 mMessageWaiting[phoneId] = mwi;
867 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800868 if (r.matchPhoneStateListenerEvent(
869 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -0800870 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700871 try {
872 r.callback.onMessageWaitingIndicatorChanged(mwi);
873 } catch (RemoteException ex) {
874 mRemoveList.add(r.binder);
875 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800876 }
877 }
878 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400879 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800880 }
881 }
882
883 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800884 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -0700885 }
886
Wink Saville63f03dd2014-10-23 10:44:45 -0700887 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700888 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700889 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700890 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700891 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700892 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700893 + " cfi=" + cfi);
894 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700896 int phoneId = SubscriptionManager.getPhoneId(subId);
897 if (validatePhoneId(phoneId)) {
898 mCallForwarding[phoneId] = cfi;
899 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800900 if (r.matchPhoneStateListenerEvent(
901 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -0800902 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700903 try {
904 r.callback.onCallForwardingIndicatorChanged(cfi);
905 } catch (RemoteException ex) {
906 mRemoveList.add(r.binder);
907 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908 }
909 }
910 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400911 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 }
913 }
914
915 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800916 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -0700917 }
918
Wink Saville63f03dd2014-10-23 10:44:45 -0700919 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700920 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700921 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700922 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700924 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -0800925 if (validatePhoneId(phoneId)) {
926 mDataActivity[phoneId] = state;
927 for (Record r : mRecords) {
928 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY)) {
929 try {
930 r.callback.onDataActivity(state);
931 } catch (RemoteException ex) {
932 mRemoveList.add(r.binder);
933 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 }
935 }
936 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400937 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 }
939 }
940
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700941 public void notifyDataConnection(int state, boolean isDataConnectivityPossible,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700942 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -0700943 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800944 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
xinhe43c50292014-09-18 17:56:48 -0700945 isDataConnectivityPossible,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -0700946 networkCapabilities, networkType, roaming);
947 }
948
Wink Saville63f03dd2014-10-23 10:44:45 -0700949 public void notifyDataConnectionForSubscriber(int subId, int state,
Wink Savillefb40dd42014-06-12 17:02:31 -0700950 boolean isDataConnectivityPossible, String reason, String apn, String apnType,
951 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
952 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700953 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700954 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700955 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700956 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700957 log("notifyDataConnectionForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700958 + " state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible
959 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -0700960 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -0800961 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -0700962 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700964 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -0800965 if (validatePhoneId(phoneId)) {
966 boolean modified = false;
967 if (state == TelephonyManager.DATA_CONNECTED) {
968 if (!mConnectedApns.contains(apnType)) {
969 mConnectedApns.add(apnType);
970 if (mDataConnectionState[phoneId] != state) {
971 mDataConnectionState[phoneId] = state;
972 modified = true;
973 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800974 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800975 } else {
976 if (mConnectedApns.remove(apnType)) {
977 if (mConnectedApns.isEmpty()) {
978 mDataConnectionState[phoneId] = state;
979 modified = true;
980 } else {
981 // leave mDataConnectionState as is and
982 // send out the new status for the APN in question.
Wink Savillebaf21da2014-11-19 16:03:09 -0800983 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200984 }
985 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800986 mDataConnectionPossible[phoneId] = isDataConnectivityPossible;
987 mDataConnectionReason[phoneId] = reason;
988 mDataConnectionLinkProperties[phoneId] = linkProperties;
989 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
990 if (mDataConnectionNetworkType[phoneId] != networkType) {
991 mDataConnectionNetworkType[phoneId] = networkType;
992 // need to tell registered listeners about the new network type
993 modified = true;
994 }
995 if (modified) {
996 if (DBG) {
997 log("onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
998 + ", " + mDataConnectionNetworkType[phoneId] + ")");
999 }
1000 for (Record r : mRecords) {
1001 if (r.matchPhoneStateListenerEvent(
1002 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1003 idMatch(r.subId, subId, phoneId)) {
1004 try {
1005 log("Notify data connection state changed on sub: " +
1006 subId);
1007 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1008 mDataConnectionNetworkType[phoneId]);
1009 } catch (RemoteException ex) {
1010 mRemoveList.add(r.binder);
1011 }
1012 }
1013 }
1014 handleRemoveListLocked();
1015 }
1016 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1017 apnType, apn, reason, linkProperties, "");
1018 for (Record r : mRecords) {
1019 if (r.matchPhoneStateListenerEvent(
1020 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1021 try {
1022 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1023 } catch (RemoteException ex) {
1024 mRemoveList.add(r.binder);
1025 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001026 }
1027 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001028 }
1029 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001030 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001031 broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001032 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001033 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1034 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 }
1036
Robert Greenwalt02648a42010-05-18 10:52:51 -07001037 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001038 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001039 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001040 }
1041
Wink Saville63f03dd2014-10-23 10:44:45 -07001042 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001043 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001044 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001045 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001046 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001047 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001048 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001049 + " reason=" + reason + " apnType=" + apnType);
1050 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001052 mPreciseDataConnectionState = new PreciseDataConnectionState(
1053 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1054 apnType, "", reason, null, "");
1055 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001056 if (r.matchPhoneStateListenerEvent(
1057 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001058 try {
1059 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1060 } catch (RemoteException ex) {
1061 mRemoveList.add(r.binder);
1062 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 }
1064 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001065 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001067 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001068 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1069 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070 }
1071
1072 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001073 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001074 }
1075
Wink Saville63f03dd2014-10-23 10:44:45 -07001076 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001077 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001078 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001079 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001080 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001081 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001082 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001083 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001084 + " cellLocation=" + cellLocation);
1085 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001087 int phoneId = SubscriptionManager.getPhoneId(subId);
1088 if (validatePhoneId(phoneId)) {
1089 mCellLocation[phoneId] = cellLocation;
1090 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001091 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
xinhe8b79fb62014-11-05 14:55:03 -08001092 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001093 try {
1094 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001095 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001096 + " r=" + r);
1097 }
1098 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1099 } catch (RemoteException ex) {
1100 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001101 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001102 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 }
1104 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001105 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001106 }
1107 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108
Wink Savillefd2d0132010-10-28 14:22:26 -07001109 public void notifyOtaspChanged(int otaspMode) {
1110 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1111 return;
1112 }
1113 synchronized (mRecords) {
1114 mOtaspMode = otaspMode;
1115 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001116 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001117 try {
1118 r.callback.onOtaspChanged(otaspMode);
1119 } catch (RemoteException ex) {
1120 mRemoveList.add(r.binder);
1121 }
1122 }
1123 }
1124 handleRemoveListLocked();
1125 }
1126 }
1127
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001128 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1129 int backgroundCallState) {
1130 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1131 return;
1132 }
1133 synchronized (mRecords) {
1134 mRingingCallState = ringingCallState;
1135 mForegroundCallState = foregroundCallState;
1136 mBackgroundCallState = backgroundCallState;
1137 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1138 backgroundCallState,
1139 DisconnectCause.NOT_VALID,
1140 PreciseDisconnectCause.NOT_VALID);
1141 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001142 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001143 try {
1144 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1145 } catch (RemoteException ex) {
1146 mRemoveList.add(r.binder);
1147 }
1148 }
1149 }
1150 handleRemoveListLocked();
1151 }
1152 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1153 DisconnectCause.NOT_VALID,
1154 PreciseDisconnectCause.NOT_VALID);
1155 }
1156
1157 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1158 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1159 return;
1160 }
1161 synchronized (mRecords) {
1162 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1163 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1164 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001165 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001166 try {
1167 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1168 } catch (RemoteException ex) {
1169 mRemoveList.add(r.binder);
1170 }
1171 }
1172 }
1173 handleRemoveListLocked();
1174 }
1175 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1176 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1177 }
1178
1179 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1180 String apn, String failCause) {
1181 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1182 return;
1183 }
1184 synchronized (mRecords) {
1185 mPreciseDataConnectionState = new PreciseDataConnectionState(
1186 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1187 apnType, apn, reason, null, failCause);
1188 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001189 if (r.matchPhoneStateListenerEvent(
1190 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001191 try {
1192 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1193 } catch (RemoteException ex) {
1194 mRemoveList.add(r.binder);
1195 }
1196 }
1197 }
1198 handleRemoveListLocked();
1199 }
1200 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1201 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1202 }
1203
Wink Savillefb40dd42014-06-12 17:02:31 -07001204 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1205 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1206 return;
1207 }
1208 synchronized (mRecords) {
1209 mVoLteServiceState = lteState;
1210 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001211 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001212 try {
1213 r.callback.onVoLteServiceStateChanged(
1214 new VoLteServiceState(mVoLteServiceState));
1215 } catch (RemoteException ex) {
1216 mRemoveList.add(r.binder);
1217 }
1218 }
1219 }
1220 handleRemoveListLocked();
1221 }
1222 }
1223
Wink Saville63f03dd2014-10-23 10:44:45 -07001224 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001225 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1226 return;
1227 }
1228
1229 synchronized (mRecords) {
1230 for (Record r : mRecords) {
1231 if (VDBG) {
1232 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1233 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001234 if ((r.matchPhoneStateListenerEvent(
1235 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
New Author Steven Liu485f2092014-09-11 10:18:45 -05001236 ((r.subId == subId) ||
Wink Savilled09c4ca2014-11-22 10:08:16 -08001237 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001238 try {
1239 r.callback.onOemHookRawEvent(rawData);
1240 } catch (RemoteException ex) {
1241 mRemoveList.add(r.binder);
1242 }
1243 }
1244 }
1245 handleRemoveListLocked();
1246 }
1247 }
1248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 @Override
1250 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1251 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1252 != PackageManager.PERMISSION_GRANTED) {
1253 pw.println("Permission Denial: can't dump telephony.registry from from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001254 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001255 return;
1256 }
1257 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001258 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001259 pw.println("last known state:");
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301260 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1261 pw.println(" Phone Id=" + i);
1262 pw.println(" mCallState=" + mCallState[i]);
1263 pw.println(" mCallIncomingNumber=" + mCallIncomingNumber[i]);
1264 pw.println(" mServiceState=" + mServiceState[i]);
1265 pw.println(" mSignalStrength=" + mSignalStrength[i]);
1266 pw.println(" mMessageWaiting=" + mMessageWaiting[i]);
1267 pw.println(" mCallForwarding=" + mCallForwarding[i]);
1268 pw.println(" mDataActivity=" + mDataActivity[i]);
1269 pw.println(" mDataConnectionState=" + mDataConnectionState[i]);
1270 pw.println(" mDataConnectionPossible=" + mDataConnectionPossible[i]);
1271 pw.println(" mDataConnectionReason=" + mDataConnectionReason[i]);
1272 pw.println(" mDataConnectionApn=" + mDataConnectionApn[i]);
1273 pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1274 pw.println(" mDataConnectionNetworkCapabilities=" +
1275 mDataConnectionNetworkCapabilities[i]);
1276 pw.println(" mCellLocation=" + mCellLocation[i]);
1277 pw.println(" mCellInfo=" + mCellInfo.get(i));
1278 }
Wink Saville070e0612014-04-15 22:04:10 -07001279 pw.println(" mDcRtInfo=" + mDcRtInfo);
Wink Savillee9b06d72009-05-18 21:47:50 -07001280 pw.println("registrations: count=" + recordCount);
Robert Greenwalt02648a42010-05-18 10:52:51 -07001281 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -07001282 pw.println(" " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 }
1284 }
1285 }
1286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 //
1288 // the legacy intent broadcasting
1289 //
1290
Wink Saville63f03dd2014-10-23 10:44:45 -07001291 private void broadcastServiceStateChanged(ServiceState state, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001292 long ident = Binder.clearCallingIdentity();
1293 try {
1294 mBatteryStats.notePhoneState(state.getState());
1295 } catch (RemoteException re) {
1296 // Can't do much
1297 } finally {
1298 Binder.restoreCallingIdentity(ident);
1299 }
1300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
1302 Bundle data = new Bundle();
1303 state.fillInNotifierBundle(data);
1304 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001305 // Pass the subscription along with the intent.
1306 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001307 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001308 }
1309
Wink Saville63f03dd2014-10-23 10:44:45 -07001310 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001311 long ident = Binder.clearCallingIdentity();
1312 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001313 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001314 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001315 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001316 } finally {
1317 Binder.restoreCallingIdentity(ident);
1318 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08001321 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
Wink Savillee9b06d72009-05-18 21:47:50 -07001322 Bundle data = new Bundle();
1323 signalStrength.fillInNotifierBundle(data);
1324 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001325 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001326 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001327 }
1328
Wink Saville63f03dd2014-10-23 10:44:45 -07001329 private void broadcastCallStateChanged(int state, String incomingNumber, int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001330 long ident = Binder.clearCallingIdentity();
1331 try {
1332 if (state == TelephonyManager.CALL_STATE_IDLE) {
1333 mBatteryStats.notePhoneOff();
1334 } else {
1335 mBatteryStats.notePhoneOn();
1336 }
1337 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001338 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001339 } finally {
1340 Binder.restoreCallingIdentity(ident);
1341 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001344 intent.putExtra(PhoneConstants.STATE_KEY,
1345 DefaultPhoneNotifier.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001346 if (!TextUtils.isEmpty(incomingNumber)) {
1347 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1348 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001349 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001350 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1351 android.Manifest.permission.READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 }
1353
Robert Greenwalt42acef32009-08-12 16:08:25 -07001354 private void broadcastDataConnectionStateChanged(int state,
1355 boolean isDataConnectivityPossible,
Wink Savillef61101f2010-09-16 16:36:42 -07001356 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001357 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001358 // Note: not reporting to the battery stats service here, because the
1359 // status bar takes care of that after taking into account all of the
1360 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001361 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001362 intent.putExtra(PhoneConstants.STATE_KEY,
1363 DefaultPhoneNotifier.convertDataState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001364 if (!isDataConnectivityPossible) {
Wink Savillea639b312012-07-10 12:37:54 -07001365 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001366 }
1367 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001368 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001369 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001370 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001371 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001372 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001373 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001374 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001375 }
1376 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001377 if (networkCapabilities != null) {
1378 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001379 }
Wink Savillea639b312012-07-10 12:37:54 -07001380 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001381
Wink Savillea639b312012-07-10 12:37:54 -07001382 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1383 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001384 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001385 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001386 }
1387
Wink Savillefb40dd42014-06-12 17:02:31 -07001388 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001389 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001391 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1392 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001393 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001394 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001395 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001396
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001397 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1398 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1399 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1400 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1401 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1402 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1403 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1404 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1405 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1406 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1407 }
1408
1409 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001410 String apnType, String apn, String reason, LinkProperties linkProperties,
1411 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001412 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1413 intent.putExtra(PhoneConstants.STATE_KEY, state);
1414 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1415 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1416 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1417 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001418 if (linkProperties != null) {
1419 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1420 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001421 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1422
1423 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1424 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1425 }
1426
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001427 private boolean checkNotifyPermission(String method) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001428 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1429 == PackageManager.PERMISSION_GRANTED) {
1430 return true;
1431 }
1432 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001433 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001434 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001435 return false;
1436 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001437
1438 private void checkListenerPermission(int events) {
1439 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1440 mContext.enforceCallingOrSelfPermission(
1441 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1442
1443 }
1444
John Wang963db55d2012-03-30 16:04:06 -07001445 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1446 mContext.enforceCallingOrSelfPermission(
1447 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1448
1449 }
1450
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001451 if ((events & PHONE_STATE_PERMISSION_MASK) != 0) {
1452 mContext.enforceCallingOrSelfPermission(
1453 android.Manifest.permission.READ_PHONE_STATE, null);
1454 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001455
1456 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1457 mContext.enforceCallingOrSelfPermission(
1458 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1459
1460 }
New Author Steven Liu485f2092014-09-11 10:18:45 -05001461
1462 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1463 mContext.enforceCallingOrSelfPermission(
1464 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1465 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001466 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001467
1468 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001469 int size = mRemoveList.size();
1470 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1471 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001472 for (IBinder b: mRemoveList) {
1473 remove(b);
1474 }
1475 mRemoveList.clear();
1476 }
1477 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001478
1479 private boolean validateEventsAndUserLocked(Record r, int events) {
1480 int foregroundUser;
1481 long callingIdentity = Binder.clearCallingIdentity();
1482 boolean valid = false;
1483 try {
1484 foregroundUser = ActivityManager.getCurrentUser();
Wink Savillea374c3d2014-11-11 11:48:04 -08001485 valid = r.callerUid == foregroundUser && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001486 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001487 log("validateEventsAndUserLocked: valid=" + valid
Wink Savillea12a7b32012-09-20 10:09:45 -07001488 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
1489 + " r.events=" + r.events + " events=" + events);
1490 }
1491 } finally {
1492 Binder.restoreCallingIdentity(callingIdentity);
1493 }
1494 return valid;
1495 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001496
1497 private boolean validatePhoneId(int phoneId) {
1498 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001499 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001500 return valid;
1501 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001502
1503 private static void log(String s) {
1504 Rlog.d(TAG, s);
1505 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001506
1507 private static class LogSSC {
1508 private Time mTime;
1509 private String mS;
Wink Saville63f03dd2014-10-23 10:44:45 -07001510 private int mSubId;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001511 private int mPhoneId;
1512 private ServiceState mState;
1513
Wink Saville63f03dd2014-10-23 10:44:45 -07001514 public void set(Time t, String s, int subId, int phoneId, ServiceState state) {
Wink Saville47d8d1b2014-07-10 13:01:52 -07001515 mTime = t; mS = s; mSubId = subId; mPhoneId = phoneId; mState = state;
1516 }
1517
1518 @Override
1519 public String toString() {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001520 return mS + " Time " + mTime.toString() + " mSubId " + mSubId + " mPhoneId "
1521 + mPhoneId + " mState " + mState;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001522 }
1523 }
1524
1525 private LogSSC logSSC [] = new LogSSC[10];
1526 private int next = 0;
1527
Wink Saville63f03dd2014-10-23 10:44:45 -07001528 private void logServiceStateChanged(String s, int subId, int phoneId, ServiceState state) {
Wink Saville47d8d1b2014-07-10 13:01:52 -07001529 if (logSSC == null || logSSC.length == 0) {
1530 return;
1531 }
1532 if (logSSC[next] == null) {
1533 logSSC[next] = new LogSSC();
1534 }
1535 Time t = new Time();
1536 t.setToNow();
1537 logSSC[next].set(t, s, subId, phoneId, state);
1538 if (++next >= logSSC.length) {
1539 next = 0;
1540 }
1541 }
1542
1543 private void toStringLogSSC(String prompt) {
1544 if (logSSC == null || logSSC.length == 0 || (next == 0 && logSSC[next] == null)) {
1545 log(prompt + ": logSSC is empty");
1546 } else {
1547 // There is at least one element
1548 log(prompt + ": logSSC.length=" + logSSC.length + " next=" + next);
1549 int i = next;
1550 if (logSSC[i] == null) {
1551 // logSSC is not full so back to the beginning
1552 i = 0;
1553 }
1554 do {
1555 log(logSSC[i].toString());
1556 if (++i >= logSSC.length) {
1557 i = 0;
1558 }
1559 } while (i != next);
Wink Savillee380b982014-07-26 18:24:22 -07001560 log(prompt + ": ----------------");
Wink Saville47d8d1b2014-07-10 13:01:52 -07001561 }
1562 }
xinhee9f16402014-09-25 16:39:28 -07001563
xinhe8b79fb62014-11-05 14:55:03 -08001564 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001565
1566 if(subId < 0) {
1567 // Invalid case, we need compare phoneId with default one.
1568 return (mDefaultPhoneId == phoneId);
1569 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001570 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001571 return (subId == mDefaultSubId);
1572 } else {
1573 return (rSubId == subId);
1574 }
1575 }
1576
1577 private void checkPossibleMissNotify(Record r, int phoneId) {
1578 int events = r.events;
1579
1580 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1581 try {
1582 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1583 mServiceState[phoneId]);
1584 r.callback.onServiceStateChanged(
1585 new ServiceState(mServiceState[phoneId]));
1586 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001587 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001588 }
1589 }
1590
1591 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1592 try {
1593 SignalStrength signalStrength = mSignalStrength[phoneId];
1594 if (DBG) {
1595 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1596 }
1597 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1598 } catch (RemoteException ex) {
1599 mRemoveList.add(r.binder);
1600 }
1601 }
1602
1603 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1604 try {
1605 int gsmSignalStrength = mSignalStrength[phoneId]
1606 .getGsmSignalStrength();
1607 if (DBG) {
1608 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1609 gsmSignalStrength);
1610 }
1611 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1612 : gsmSignalStrength));
1613 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001614 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001615 }
1616 }
1617
1618 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1619 try {
1620 if (DBG_LOC) {
1621 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1622 + mCellInfo.get(phoneId));
1623 }
1624 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1625 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001626 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001627 }
1628 }
1629
1630 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1631 try {
1632 if (VDBG) {
1633 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1634 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1635 }
1636 r.callback.onMessageWaitingIndicatorChanged(
1637 mMessageWaiting[phoneId]);
1638 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001639 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001640 }
1641 }
1642
1643 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1644 try {
1645 if (VDBG) {
1646 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1647 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1648 }
1649 r.callback.onCallForwardingIndicatorChanged(
1650 mCallForwarding[phoneId]);
1651 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001652 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001653 }
1654 }
1655
1656 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1657 try {
1658 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1659 + mCellLocation[phoneId]);
1660 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1661 } catch (RemoteException ex) {
1662 mRemoveList.add(r.binder);
1663 }
1664 }
1665
1666 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1667 try {
1668 if (DBG) {
1669 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1670 + "=" + mDataConnectionState[phoneId]
1671 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1672 + ")");
1673 }
1674 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1675 mDataConnectionNetworkType[phoneId]);
1676 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001677 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001678 }
1679 }
1680 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001681}