blob: e609bd7889d3903bba326b0473d1cb862d8e49d4 [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;
Svet Ganov16a16892015-04-16 10:32:04 -070020import android.app.AppOpsManager;
Wink Savillea12a7b32012-09-20 10:09:45 -070021import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
23import android.content.Intent;
Wink Savillea12a7b32012-09-20 10:09:45 -070024import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.pm.PackageManager;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070026import android.net.LinkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -070027import android.net.NetworkCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Binder;
29import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070030import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070032import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070034import android.os.UserHandle;
John Wang963db55d2012-03-30 16:04:06 -070035import android.telephony.CellInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070036import android.telephony.CellLocation;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020037import android.telephony.DisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070038import android.telephony.PhoneStateListener;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020039import android.telephony.PreciseCallState;
40import android.telephony.PreciseDataConnectionState;
41import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070042import android.telephony.Rlog;
43import android.telephony.ServiceState;
44import android.telephony.SignalStrength;
45import android.telephony.SubscriptionManager;
46import android.telephony.TelephonyManager;
47import android.telephony.VoLteServiceState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import android.text.TextUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070049import android.util.LocalLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050
51import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080052import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070054import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080055import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070056import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import com.android.internal.telephony.TelephonyIntents;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060058import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070059import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import com.android.server.am.BatteryStatsService;
61
Jack Yud19b6ae2017-04-05 14:12:09 -070062import java.io.FileDescriptor;
63import java.io.PrintWriter;
64import java.util.ArrayList;
65import java.util.Arrays;
66import java.util.List;
67
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068/**
Wink Savillee9b06d72009-05-18 21:47:50 -070069 * Since phone process can be restarted, this class provides a centralized place
70 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070071 *
72 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
73 * and 15973975 by saving the phoneId of the registrant and then using the
74 * phoneId when deciding to to make a callback. This is necessary because
75 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070076 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070077 * the dummy value conversion we properly do the callbacks.
78 *
79 * Eventually we may want to remove the notion of dummy value but for now this
80 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 */
82class TelephonyRegistry extends ITelephonyRegistry.Stub {
83 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070084 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070085 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070086 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087
88 private static class Record {
Svet Ganov16a16892015-04-16 10:32:04 -070089 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -080094 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -070095
Fyodor Kupolov309b2f632015-06-03 16:29:01 -070096 int callerUserId;
Wink Savillea12a7b32012-09-20 10:09:45 -070097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -070099
Wink Savilled09c4ca2014-11-22 10:08:16 -0800100 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700101
Wink Savilled09c4ca2014-11-22 10:08:16 -0800102 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800103
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700104 boolean canReadPhoneState;
105
Wink Savillea374c3d2014-11-11 11:48:04 -0800106 boolean matchPhoneStateListenerEvent(int events) {
107 return (callback != null) && ((events & this.events) != 0);
108 }
109
Wink Savilled09c4ca2014-11-22 10:08:16 -0800110 boolean matchOnSubscriptionsChangedListener() {
111 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800112 }
Wink Savillee380b982014-07-26 18:24:22 -0700113
Wink Savillea12a7b32012-09-20 10:09:45 -0700114 @Override
115 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700116 return "{callingPackage=" + callingPackage + " binder=" + binder
117 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800118 + " onSubscriptionsChangedListenererCallback="
119 + onSubscriptionsChangedListenerCallback
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700120 + " callerUserId=" + callerUserId + " subId=" + subId + " phoneId=" + phoneId
121 + " events=" + Integer.toHexString(events)
122 + " canReadPhoneState=" + canReadPhoneState + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700123 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 }
125
126 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700127
Joe Onorato163d8d92010-10-21 13:21:20 -0400128 // access should be inside synchronized (mRecords) for these two fields
129 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
130 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 private final IBatteryStats mBatteryStats;
133
Svet Ganov16a16892015-04-16 10:32:04 -0700134 private final AppOpsManager mAppOps;
135
Wink Savilled09c4ca2014-11-22 10:08:16 -0800136 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
137
Wink Savillefb40dd42014-06-12 17:02:31 -0700138 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700139
Wink Savillefb40dd42014-06-12 17:02:31 -0700140 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700141
Wink Savillefb40dd42014-06-12 17:02:31 -0700142 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700143
Wink Savillefb40dd42014-06-12 17:02:31 -0700144 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700145
fionaxu12312f62016-11-14 13:32:14 -0800146 private int[] mVoiceActivationState;
147
148 private int[] mDataActivationState;
149
Wink Savillefb40dd42014-06-12 17:02:31 -0700150 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700151
Wink Savillefb40dd42014-06-12 17:02:31 -0700152 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700153
Wink Savillefb40dd42014-06-12 17:02:31 -0700154 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700155
Wink Savillefb40dd42014-06-12 17:02:31 -0700156 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700157
Wink Savillefb40dd42014-06-12 17:02:31 -0700158 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700159
Yifan Bai57b39e32016-04-01 16:24:33 +0800160 private ArrayList<String>[] mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700161
Wink Savillefb40dd42014-06-12 17:02:31 -0700162 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700163
Wink Savillefb40dd42014-06-12 17:02:31 -0700164 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700165
Wink Savillefb40dd42014-06-12 17:02:31 -0700166 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167
Wink Savillefb40dd42014-06-12 17:02:31 -0700168 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700169
Nathan Harold016e9c62016-12-14 11:24:48 -0800170 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700171
Wink Savillefb40dd42014-06-12 17:02:31 -0700172 private ArrayList<List<CellInfo>> mCellInfo = null;
173
174 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
175
Wink Savilled09c4ca2014-11-22 10:08:16 -0800176 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700177
Wink Savilled09c4ca2014-11-22 10:08:16 -0800178 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700179
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200180 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
181
182 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
183
184 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
185
186 private PreciseCallState mPreciseCallState = new PreciseCallState();
187
Andrew Flynn1f452642015-04-14 22:16:04 -0400188 private boolean mCarrierNetworkChangeState = false;
189
Jack Yud19b6ae2017-04-05 14:12:09 -0700190 private final LocalLog mLocalLog = new LocalLog(100);
191
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200192 private PreciseDataConnectionState mPreciseDataConnectionState =
193 new PreciseDataConnectionState();
194
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700195 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700196 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700197 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
198 PhoneStateListener.LISTEN_VOLTE_STATE;
199
200 static final int CHECK_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700201 PhoneStateListener.LISTEN_CALL_STATE |
202 PhoneStateListener.LISTEN_DATA_ACTIVITY |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700203 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700204
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200205 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
206 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
207 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
208
Wink Savillea12a7b32012-09-20 10:09:45 -0700209 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700210 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700211
212 private final Handler mHandler = new Handler() {
213 @Override
214 public void handleMessage(Message msg) {
215 switch (msg.what) {
216 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700217 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700218 int numPhones = TelephonyManager.getDefault().getPhoneCount();
219 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700220 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700221 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700222 }
223 break;
224 }
xinhee9f16402014-09-25 16:39:28 -0700225 case MSG_UPDATE_DEFAULT_SUB: {
226 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700227 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700228 if (VDBG) {
229 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
230 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
231 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
232 }
233
234 //Due to possible risk condition,(notify call back using the new
235 //defaultSubId comes before new defaultSubId update) we need to recall all
236 //possible missed notify callback
237 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700238 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800239 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700240 checkPossibleMissNotify(r, newDefaultPhoneId);
241 }
242 }
243 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700244 }
245 mDefaultSubId = newDefaultSubId;
246 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700247 }
248 }
249 }
250 };
251
252 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
253 @Override
254 public void onReceive(Context context, Intent intent) {
255 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700256 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700257 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700258 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700259 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700260 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700261 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700262 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800263 PhoneConstants.SUBSCRIPTION_KEY,
264 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700265 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
266 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700267 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700268 log("onReceive:current mDefaultSubId=" + mDefaultSubId
269 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
270 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700271 }
xinhee9f16402014-09-25 16:39:28 -0700272
Junda Liu985f52c2015-02-23 16:06:51 -0800273 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700274 || (newDefaultPhoneId != mDefaultPhoneId))) {
275 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
276 newDefaultPhoneId, 0, newDefaultSubIdObj));
277 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700278 }
279 }
280 };
281
Wink Savillee9b06d72009-05-18 21:47:50 -0700282 // we keep a copy of all of the state so we can send it out when folks
283 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700285 // In these calls we call with the lock held. This is safe becasuse remote
286 // calls go through a oneway interface and local calls going through a
287 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800288
289 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700290 CellLocation location = CellLocation.getEmpty();
291
Wink Savillefb40dd42014-06-12 17:02:31 -0700292 mContext = context;
293 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700294
Wink Savillefb40dd42014-06-12 17:02:31 -0700295 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700296 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700297 mNumPhones = numPhones;
Yifan Bai57b39e32016-04-01 16:24:33 +0800298 mConnectedApns = new ArrayList[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700299 mCallState = new int[numPhones];
300 mDataActivity = new int[numPhones];
301 mDataConnectionState = new int[numPhones];
302 mDataConnectionNetworkType = new int[numPhones];
303 mCallIncomingNumber = new String[numPhones];
304 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800305 mVoiceActivationState = new int[numPhones];
306 mDataActivationState = new int[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700307 mSignalStrength = new SignalStrength[numPhones];
308 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700309 mCallForwarding = new boolean[numPhones];
310 mCellLocation = new Bundle[numPhones];
311 mDataConnectionLinkProperties = new LinkProperties[numPhones];
312 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
313 mCellInfo = new ArrayList<List<CellInfo>>();
314 for (int i = 0; i < numPhones; i++) {
315 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
316 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
317 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800318 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
319 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700320 mCallIncomingNumber[i] = "";
321 mServiceState[i] = new ServiceState();
322 mSignalStrength[i] = new SignalStrength();
323 mMessageWaiting[i] = false;
324 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700325 mCellLocation[i] = new Bundle();
326 mCellInfo.add(i, null);
Yifan Bai57b39e32016-04-01 16:24:33 +0800327 mConnectedApns[i] = new ArrayList<String>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700328 }
329
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700330 // Note that location can be null for non-phone builds like
331 // like the generic one.
332 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700333 for (int i = 0; i < numPhones; i++) {
334 location.fillInNotifierBundle(mCellLocation[i]);
335 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700336 }
Svet Ganov16a16892015-04-16 10:32:04 -0700337
338 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 }
340
Svetoslav Ganova0027152013-06-25 14:59:53 -0700341 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700342 // Watch for interesting updates
343 final IntentFilter filter = new IntentFilter();
344 filter.addAction(Intent.ACTION_USER_SWITCHED);
345 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700346 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700347 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700348 mContext.registerReceiver(mBroadcastReceiver, filter);
349 }
350
351 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700352 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800353 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700354 int callerUserId = UserHandle.getCallingUserId();
Wink Savillea374c3d2014-11-11 11:48:04 -0800355 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700356 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
357 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800358 + " callback.asBinder=" + callback.asBinder());
359 }
360
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700361 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700362 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700363 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
364 "addOnSubscriptionsChangedListener");
Amit Mahajana9e72a72015-07-30 16:04:13 -0700365 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700366 } catch (SecurityException e) {
367 mContext.enforceCallingOrSelfPermission(
368 android.Manifest.permission.READ_PHONE_STATE,
369 "addOnSubscriptionsChangedListener");
Svet Ganov16a16892015-04-16 10:32:04 -0700370
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700371 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
372 callingPackage) != AppOpsManager.MODE_ALLOWED) {
373 return;
374 }
Svet Ganov16a16892015-04-16 10:32:04 -0700375 }
376
Fyodor Kupolovac038a92015-06-09 13:14:54 -0700377 Record r;
Wink Savillea374c3d2014-11-11 11:48:04 -0800378
Wink Savilled09c4ca2014-11-22 10:08:16 -0800379 synchronized (mRecords) {
380 // register
381 find_and_add: {
382 IBinder b = callback.asBinder();
383 final int N = mRecords.size();
384 for (int i = 0; i < N; i++) {
385 r = mRecords.get(i);
386 if (b == r.binder) {
387 break find_and_add;
Wink Savillea374c3d2014-11-11 11:48:04 -0800388 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800389 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800390 r = new Record();
391 r.binder = b;
392 mRecords.add(r);
393 if (DBG) log("listen oscl: add new record");
Wink Savillea374c3d2014-11-11 11:48:04 -0800394 }
395
Wink Savilled09c4ca2014-11-22 10:08:16 -0800396 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700397 r.callingPackage = callingPackage;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700398 r.callerUserId = callerUserId;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800399 r.events = 0;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700400 r.canReadPhoneState = true; // permission has been enforced above
Wink Savilled09c4ca2014-11-22 10:08:16 -0800401 if (DBG) {
402 log("listen oscl: Register r=" + r);
403 }
404 // Always notify when registration occurs if there has been a notification.
405 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800406 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800407 if (VDBG) log("listen oscl: send to r=" + r);
408 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
409 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800410 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800411 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800412 remove(r.binder);
413 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800414 } else {
415 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800416 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800417 }
418 }
419
420 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800421 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800422 IOnSubscriptionsChangedListener callback) {
423 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800424 remove(callback.asBinder());
425 }
426
Wink Savillea374c3d2014-11-11 11:48:04 -0800427 @Override
428 public void notifySubscriptionInfoChanged() {
429 if (VDBG) log("notifySubscriptionInfoChanged:");
430 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800431 if (!hasNotifySubscriptionInfoChangedOccurred) {
432 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
433 + mRecords.size());
434 }
435 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800436 mRemoveList.clear();
437 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800438 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800439 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800440 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
441 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
442 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800443 } catch (RemoteException ex) {
444 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
445 mRemoveList.add(r.binder);
446 }
447 }
448 }
449 handleRemoveListLocked();
450 }
451 }
452
453 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
455 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800456 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
457 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700458 }
459
460 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700461 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700462 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700463 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700464 }
465
Svet Ganov16a16892015-04-16 10:32:04 -0700466 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700467 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700468 int callerUserId = UserHandle.getCallingUserId();
Wink Savillee380b982014-07-26 18:24:22 -0700469 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700470 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700471 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
472 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700473 }
xinhe75c2c152014-10-16 11:49:45 -0700474
475 if (events != PhoneStateListener.LISTEN_NONE) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700476 /* Checks permission and throws Security exception */
477 checkListenerPermission(events);
Svet Ganov16a16892015-04-16 10:32:04 -0700478
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700479 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700480 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700481 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700482 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -0700483 // SKIP checking for run-time permission since caller or self has PRIVILEGED
484 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700485 } catch (SecurityException e) {
486 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
487 callingPackage) != AppOpsManager.MODE_ALLOWED) {
488 return;
489 }
Svet Ganov16a16892015-04-16 10:32:04 -0700490 }
491 }
492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 synchronized (mRecords) {
494 // register
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700495 Record r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 find_and_add: {
497 IBinder b = callback.asBinder();
498 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700499 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 r = mRecords.get(i);
501 if (b == r.binder) {
502 break find_and_add;
503 }
504 }
505 r = new Record();
506 r.binder = b;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 mRecords.add(r);
Wink Savillee380b982014-07-26 18:24:22 -0700508 if (DBG) log("listen: add new record");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 }
xinhe43c50292014-09-18 17:56:48 -0700510
xinhe75c2c152014-10-16 11:49:45 -0700511 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700512 r.callingPackage = callingPackage;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700513 r.callerUserId = callerUserId;
514 boolean isPhoneStateEvent = (events & (CHECK_PHONE_STATE_PERMISSION_MASK
515 | ENFORCE_PHONE_STATE_PERMISSION_MASK)) != 0;
516 r.canReadPhoneState = isPhoneStateEvent && canReadPhoneState(callingPackage);
xinhe75c2c152014-10-16 11:49:45 -0700517 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
518 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800519 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800520 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700521 } else {//APP specify subID
522 r.subId = subId;
523 }
524 r.phoneId = SubscriptionManager.getPhoneId(r.subId);
525
xinhe43c50292014-09-18 17:56:48 -0700526 int phoneId = r.phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700528 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700529 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700530 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700531 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400533 try {
Wink Savillee380b982014-07-26 18:24:22 -0700534 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700535 r.callback.onServiceStateChanged(
536 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400537 } catch (RemoteException ex) {
538 remove(r.binder);
539 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 }
541 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
542 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700543 int gsmSignalStrength = mSignalStrength[phoneId]
544 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700545 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
546 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 } catch (RemoteException ex) {
548 remove(r.binder);
549 }
550 }
551 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
552 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700553 r.callback.onMessageWaitingIndicatorChanged(
554 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 } catch (RemoteException ex) {
556 remove(r.binder);
557 }
558 }
559 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
560 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700561 r.callback.onCallForwardingIndicatorChanged(
562 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 } catch (RemoteException ex) {
564 remove(r.binder);
565 }
566 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700567 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400568 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700569 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700570 + mCellLocation[phoneId]);
571 r.callback.onCellLocationChanged(
572 new Bundle(mCellLocation[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400573 } catch (RemoteException ex) {
574 remove(r.binder);
575 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 }
577 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
578 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700579 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700580 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 } catch (RemoteException ex) {
582 remove(r.binder);
583 }
584 }
585 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
586 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700587 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
588 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 } catch (RemoteException ex) {
590 remove(r.binder);
591 }
592 }
593 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
594 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700595 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 } catch (RemoteException ex) {
597 remove(r.binder);
598 }
599 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700600 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
601 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700602 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700603 } catch (RemoteException ex) {
604 remove(r.binder);
605 }
606 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700607 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
608 try {
609 r.callback.onOtaspChanged(mOtaspMode);
610 } catch (RemoteException ex) {
611 remove(r.binder);
612 }
613 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700614 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700615 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700616 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700617 + mCellInfo.get(phoneId));
618 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
John Wang963db55d2012-03-30 16:04:06 -0700619 } catch (RemoteException ex) {
620 remove(r.binder);
621 }
622 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200623 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
624 try {
625 r.callback.onPreciseCallStateChanged(mPreciseCallState);
626 } catch (RemoteException ex) {
627 remove(r.binder);
628 }
629 }
630 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
631 try {
632 r.callback.onPreciseDataConnectionStateChanged(
633 mPreciseDataConnectionState);
634 } catch (RemoteException ex) {
635 remove(r.binder);
636 }
637 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400638 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
639 try {
640 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
641 } catch (RemoteException ex) {
642 remove(r.binder);
643 }
644 }
fionaxu12312f62016-11-14 13:32:14 -0800645 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
646 try {
647 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
648 } catch (RemoteException ex) {
649 remove(r.binder);
650 }
651 }
652 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
653 try {
654 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
655 } catch (RemoteException ex) {
656 remove(r.binder);
657 }
658 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 }
660 }
661 } else {
xinhe75c2c152014-10-16 11:49:45 -0700662 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 remove(callback.asBinder());
664 }
665 }
666
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700667 private boolean canReadPhoneState(String callingPackage) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700668 if (mContext.checkCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700669 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) ==
670 PackageManager.PERMISSION_GRANTED) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700671 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700672 return true;
673 }
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700674 boolean canReadPhoneState = mContext.checkCallingOrSelfPermission(
675 android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
676 if (canReadPhoneState &&
677 mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
678 callingPackage) != AppOpsManager.MODE_ALLOWED) {
679 return false;
680 }
681 return canReadPhoneState;
682 }
683
684 private String getCallIncomingNumber(Record record, int phoneId) {
685 // Hide the number if record's process has no READ_PHONE_STATE permission
686 return record.canReadPhoneState ? mCallIncomingNumber[phoneId] : "";
687 }
688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689 private void remove(IBinder binder) {
690 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700691 final int recordCount = mRecords.size();
692 for (int i = 0; i < recordCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 if (mRecords.get(i).binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800694 if (DBG) {
695 Record r = mRecords.get(i);
Svet Ganov16a16892015-04-16 10:32:04 -0700696 log("remove: binder=" + binder + "r.callingPackage" + r.callingPackage
xinheac11ae92014-12-18 10:02:14 -0800697 + "r.callback" + r.callback);
698 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699 mRecords.remove(i);
700 return;
701 }
702 }
703 }
704 }
705
706 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700707 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700708 return;
709 }
xinhe43c50292014-09-18 17:56:48 -0700710
711 if (VDBG) {
712 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
713 }
714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800715 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700716 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800717 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800718 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700720 String incomingNumberOrEmpty = r.canReadPhoneState ? incomingNumber : "";
721 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400723 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800724 }
725 }
726 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400727 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800728 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700729
730 // Called only by Telecomm to communicate call state across different phone accounts. So
731 // there is no need to add a valid subId or slotId.
Wink Savilled09c4ca2014-11-22 10:08:16 -0800732 broadcastCallStateChanged(state, incomingNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700733 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700734 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 }
736
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700737 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
738 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700739 if (!checkNotifyPermission("notifyCallState()")) {
740 return;
741 }
Wink Savillee380b982014-07-26 18:24:22 -0700742 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700743 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700744 + " state=" + state + " incomingNumber=" + incomingNumber);
745 }
746 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700747 if (validatePhoneId(phoneId)) {
748 mCallState[phoneId] = state;
749 mCallIncomingNumber[phoneId] = incomingNumber;
750 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800751 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700752 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800753 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700754 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700755 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
756 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700757 } catch (RemoteException ex) {
758 mRemoveList.add(r.binder);
759 }
760 }
761 }
762 }
763 handleRemoveListLocked();
764 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700765 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700766 }
767
Wink Saville63f03dd2014-10-23 10:44:45 -0700768 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700769 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700770 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700771 }
xinhe43c50292014-09-18 17:56:48 -0700772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700774 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
775 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700776 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700777 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700778 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700779 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700780 if (validatePhoneId(phoneId)) {
781 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700782
Wink Savillefb40dd42014-06-12 17:02:31 -0700783 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700784 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700785 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700786 + " phoneId=" + phoneId + " state=" + state);
787 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800788 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800789 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700790 try {
Wink Savillee380b982014-07-26 18:24:22 -0700791 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700792 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700793 + " subId=" + subId + " phoneId=" + phoneId
794 + " state=" + state);
795 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700796 r.callback.onServiceStateChanged(new ServiceState(state));
797 } catch (RemoteException ex) {
798 mRemoveList.add(r.binder);
799 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400800 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800801 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700802 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700803 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400805 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700807 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 }
809
fionaxu12312f62016-11-14 13:32:14 -0800810 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
811 int activationType, int activationState) {
812 if (!checkNotifyPermission("notifySimActivationState()")){
813 return;
814 }
815 if (VDBG) {
816 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
817 + "type=" + activationType + " state=" + activationState);
818 }
819 synchronized (mRecords) {
820 if (validatePhoneId(phoneId)) {
821 switch (activationType) {
822 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
823 mVoiceActivationState[phoneId] = activationState;
824 break;
825 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
826 mDataActivationState[phoneId] = activationState;
827 break;
828 default:
829 return;
830 }
831 for (Record r : mRecords) {
832 if (VDBG) {
833 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
834 + " phoneId=" + phoneId + "type=" + activationType
835 + " state=" + activationState);
836 }
837 try {
838 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
839 r.matchPhoneStateListenerEvent(
840 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
841 idMatch(r.subId, subId, phoneId)) {
842 if (DBG) {
843 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
844 + " subId=" + subId + " phoneId=" + phoneId
845 + " state=" + activationState);
846 }
847 r.callback.onVoiceActivationStateChanged(activationState);
848 }
849 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
850 r.matchPhoneStateListenerEvent(
851 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
852 idMatch(r.subId, subId, phoneId)) {
853 if (DBG) {
854 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
855 + " subId=" + subId + " phoneId=" + phoneId
856 + " state=" + activationState);
857 }
858 r.callback.onDataActivationStateChanged(activationState);
859 }
860 } catch (RemoteException ex) {
861 mRemoveList.add(r.binder);
862 }
863 }
864 } else {
865 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
866 }
867 handleRemoveListLocked();
868 }
869 }
870
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700871 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
872 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700873 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700874 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700875 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000876 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700877 log("notifySignalStrengthForPhoneId: subId=" + subId
878 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000879 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800881 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700882 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700883 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700884 mSignalStrength[phoneId] = signalStrength;
885 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000886 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700887 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000888 + " phoneId=" + phoneId + " ss=" + signalStrength);
889 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800890 if (r.matchPhoneStateListenerEvent(
891 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800892 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700893 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000894 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700895 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000896 + " subId=" + subId + " phoneId=" + phoneId
897 + " ss=" + signalStrength);
898 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700899 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
900 } catch (RemoteException ex) {
901 mRemoveList.add(r.binder);
902 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400903 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800904 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800905 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700906 try {
907 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700908 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000909 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700910 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000911 + " subId=" + subId + " phoneId=" + phoneId
912 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
913 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700914 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700915 } catch (RemoteException ex) {
916 mRemoveList.add(r.binder);
917 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800918 }
919 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700920 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700921 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400923 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700925 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 }
927
Andrew Flynn1f452642015-04-14 22:16:04 -0400928 @Override
929 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +0000930 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
931
Andrew Flynn1f452642015-04-14 22:16:04 -0400932 if (VDBG) {
933 log("notifyCarrierNetworkChange: active=" + active);
934 }
935
936 synchronized (mRecords) {
937 mCarrierNetworkChangeState = active;
938 for (Record r : mRecords) {
939 if (r.matchPhoneStateListenerEvent(
940 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
941 try {
942 r.callback.onCarrierNetworkChange(active);
943 } catch (RemoteException ex) {
944 mRemoveList.add(r.binder);
945 }
946 }
947 }
948 handleRemoveListLocked();
949 }
950 }
951
Wink Savilleb208a242012-07-25 14:08:09 -0700952 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800953 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700954 }
955
Wink Saville63f03dd2014-10-23 10:44:45 -0700956 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700957 if (!checkNotifyPermission("notifyCellInfo()")) {
958 return;
959 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700960 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700961 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700962 + " cellInfo=" + cellInfo);
963 }
John Wang963db55d2012-03-30 16:04:06 -0700964
965 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700966 int phoneId = SubscriptionManager.getPhoneId(subId);
967 if (validatePhoneId(phoneId)) {
968 mCellInfo.set(phoneId, cellInfo);
969 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -0700970 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
xinhe8b79fb62014-11-05 14:55:03 -0800971 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700972 try {
973 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700974 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -0700975 }
976 r.callback.onCellInfoChanged(cellInfo);
977 } catch (RemoteException ex) {
978 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700979 }
John Wang963db55d2012-03-30 16:04:06 -0700980 }
981 }
982 }
983 handleRemoveListLocked();
984 }
985 }
986
xinhe43c50292014-09-18 17:56:48 -0700987 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700988 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700989 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700990 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700991 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700992 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -0700993 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -0700994 + " mwi=" + mwi);
995 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800996 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700997 if (validatePhoneId(phoneId)) {
998 mMessageWaiting[phoneId] = mwi;
999 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001000 if (r.matchPhoneStateListenerEvent(
1001 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001002 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001003 try {
1004 r.callback.onMessageWaitingIndicatorChanged(mwi);
1005 } catch (RemoteException ex) {
1006 mRemoveList.add(r.binder);
1007 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001008 }
1009 }
1010 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001011 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001012 }
1013 }
1014
1015 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001016 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001017 }
1018
Wink Saville63f03dd2014-10-23 10:44:45 -07001019 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001020 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001021 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001022 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001023 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001024 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001025 + " cfi=" + cfi);
1026 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001027 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001028 int phoneId = SubscriptionManager.getPhoneId(subId);
1029 if (validatePhoneId(phoneId)) {
1030 mCallForwarding[phoneId] = cfi;
1031 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001032 if (r.matchPhoneStateListenerEvent(
1033 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001034 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001035 try {
1036 r.callback.onCallForwardingIndicatorChanged(cfi);
1037 } catch (RemoteException ex) {
1038 mRemoveList.add(r.binder);
1039 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001040 }
1041 }
1042 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001043 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 }
1045 }
1046
1047 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001048 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001049 }
1050
Wink Saville63f03dd2014-10-23 10:44:45 -07001051 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001052 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001053 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001054 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001056 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001057 if (validatePhoneId(phoneId)) {
1058 mDataActivity[phoneId] = state;
1059 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001060 // Notify by correct subId.
1061 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1062 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001063 try {
1064 r.callback.onDataActivity(state);
1065 } catch (RemoteException ex) {
1066 mRemoveList.add(r.binder);
1067 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 }
1069 }
1070 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001071 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 }
1073 }
1074
Jack Yubaeec622017-05-01 17:01:11 -07001075 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001076 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001077 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001078 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001079 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001080 networkCapabilities, networkType, roaming);
1081 }
1082
Wink Saville63f03dd2014-10-23 10:44:45 -07001083 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001084 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001085 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1086 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001087 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001088 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001089 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001090 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001091 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001092 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001093 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001094 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001095 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001096 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001098 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001099 if (validatePhoneId(phoneId)) {
1100 boolean modified = false;
1101 if (state == TelephonyManager.DATA_CONNECTED) {
Yifan Bai57b39e32016-04-01 16:24:33 +08001102 if (!mConnectedApns[phoneId].contains(apnType)) {
1103 mConnectedApns[phoneId].add(apnType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001104 if (mDataConnectionState[phoneId] != state) {
1105 mDataConnectionState[phoneId] = state;
1106 modified = true;
1107 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001109 } else {
Yifan Bai57b39e32016-04-01 16:24:33 +08001110 if (mConnectedApns[phoneId].remove(apnType)) {
1111 if (mConnectedApns[phoneId].isEmpty()) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001112 mDataConnectionState[phoneId] = state;
1113 modified = true;
1114 } else {
1115 // leave mDataConnectionState as is and
1116 // send out the new status for the APN in question.
Wink Savillebaf21da2014-11-19 16:03:09 -08001117 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001118 }
1119 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001120 mDataConnectionLinkProperties[phoneId] = linkProperties;
1121 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
1122 if (mDataConnectionNetworkType[phoneId] != networkType) {
1123 mDataConnectionNetworkType[phoneId] = networkType;
1124 // need to tell registered listeners about the new network type
1125 modified = true;
1126 }
1127 if (modified) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001128 String str = "onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
1129 + ", " + mDataConnectionNetworkType[phoneId] + ")";
1130 log(str);
1131 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001132 for (Record r : mRecords) {
1133 if (r.matchPhoneStateListenerEvent(
1134 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1135 idMatch(r.subId, subId, phoneId)) {
1136 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001137 if (DBG) {
1138 log("Notify data connection state changed on sub: " + subId);
1139 }
1140 r.callback.onDataConnectionStateChanged(
1141 mDataConnectionState[phoneId],
Wink Savilled09c4ca2014-11-22 10:08:16 -08001142 mDataConnectionNetworkType[phoneId]);
1143 } catch (RemoteException ex) {
1144 mRemoveList.add(r.binder);
1145 }
1146 }
1147 }
1148 handleRemoveListLocked();
1149 }
1150 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1151 apnType, apn, reason, linkProperties, "");
1152 for (Record r : mRecords) {
1153 if (r.matchPhoneStateListenerEvent(
1154 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1155 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001156 r.callback.onPreciseDataConnectionStateChanged(
1157 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001158 } catch (RemoteException ex) {
1159 mRemoveList.add(r.binder);
1160 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001161 }
1162 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001163 }
1164 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001165 }
Jack Yubaeec622017-05-01 17:01:11 -07001166 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001167 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001168 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1169 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 }
1171
Robert Greenwalt02648a42010-05-18 10:52:51 -07001172 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001173 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001174 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001175 }
1176
Wink Saville63f03dd2014-10-23 10:44:45 -07001177 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001178 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001179 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001180 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001181 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001182 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001183 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001184 + " reason=" + reason + " apnType=" + apnType);
1185 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001187 mPreciseDataConnectionState = new PreciseDataConnectionState(
1188 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1189 apnType, "", reason, null, "");
1190 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001191 if (r.matchPhoneStateListenerEvent(
1192 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001193 try {
1194 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1195 } catch (RemoteException ex) {
1196 mRemoveList.add(r.binder);
1197 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198 }
1199 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001200 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001201 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001202 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001203 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1204 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 }
1206
1207 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001208 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001209 }
1210
Wink Saville63f03dd2014-10-23 10:44:45 -07001211 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001212 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001213 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001214 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001215 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001216 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001217 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001218 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001219 + " cellLocation=" + cellLocation);
1220 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001222 int phoneId = SubscriptionManager.getPhoneId(subId);
1223 if (validatePhoneId(phoneId)) {
1224 mCellLocation[phoneId] = cellLocation;
1225 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001226 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
xinhe8b79fb62014-11-05 14:55:03 -08001227 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001228 try {
1229 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001230 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001231 + " r=" + r);
1232 }
1233 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1234 } catch (RemoteException ex) {
1235 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001236 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001237 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001238 }
1239 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001240 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001241 }
1242 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243
Wink Savillefd2d0132010-10-28 14:22:26 -07001244 public void notifyOtaspChanged(int otaspMode) {
1245 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1246 return;
1247 }
1248 synchronized (mRecords) {
1249 mOtaspMode = otaspMode;
1250 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001251 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001252 try {
1253 r.callback.onOtaspChanged(otaspMode);
1254 } catch (RemoteException ex) {
1255 mRemoveList.add(r.binder);
1256 }
1257 }
1258 }
1259 handleRemoveListLocked();
1260 }
1261 }
1262
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001263 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1264 int backgroundCallState) {
1265 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1266 return;
1267 }
1268 synchronized (mRecords) {
1269 mRingingCallState = ringingCallState;
1270 mForegroundCallState = foregroundCallState;
1271 mBackgroundCallState = backgroundCallState;
1272 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1273 backgroundCallState,
1274 DisconnectCause.NOT_VALID,
1275 PreciseDisconnectCause.NOT_VALID);
1276 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001277 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001278 try {
1279 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1280 } catch (RemoteException ex) {
1281 mRemoveList.add(r.binder);
1282 }
1283 }
1284 }
1285 handleRemoveListLocked();
1286 }
1287 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1288 DisconnectCause.NOT_VALID,
1289 PreciseDisconnectCause.NOT_VALID);
1290 }
1291
1292 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1293 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1294 return;
1295 }
1296 synchronized (mRecords) {
1297 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1298 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1299 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001300 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001301 try {
1302 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1303 } catch (RemoteException ex) {
1304 mRemoveList.add(r.binder);
1305 }
1306 }
1307 }
1308 handleRemoveListLocked();
1309 }
1310 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1311 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1312 }
1313
1314 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1315 String apn, String failCause) {
1316 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1317 return;
1318 }
1319 synchronized (mRecords) {
1320 mPreciseDataConnectionState = new PreciseDataConnectionState(
1321 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1322 apnType, apn, reason, null, failCause);
1323 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001324 if (r.matchPhoneStateListenerEvent(
1325 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001326 try {
1327 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1328 } catch (RemoteException ex) {
1329 mRemoveList.add(r.binder);
1330 }
1331 }
1332 }
1333 handleRemoveListLocked();
1334 }
1335 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1336 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1337 }
1338
Wink Savillefb40dd42014-06-12 17:02:31 -07001339 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1340 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1341 return;
1342 }
1343 synchronized (mRecords) {
1344 mVoLteServiceState = lteState;
1345 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001346 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001347 try {
1348 r.callback.onVoLteServiceStateChanged(
1349 new VoLteServiceState(mVoLteServiceState));
1350 } catch (RemoteException ex) {
1351 mRemoveList.add(r.binder);
1352 }
1353 }
1354 }
1355 handleRemoveListLocked();
1356 }
1357 }
1358
Wink Saville63f03dd2014-10-23 10:44:45 -07001359 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001360 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1361 return;
1362 }
1363
1364 synchronized (mRecords) {
1365 for (Record r : mRecords) {
1366 if (VDBG) {
1367 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1368 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001369 if ((r.matchPhoneStateListenerEvent(
1370 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
New Author Steven Liu485f2092014-09-11 10:18:45 -05001371 ((r.subId == subId) ||
Wink Savilled09c4ca2014-11-22 10:08:16 -08001372 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001373 try {
1374 r.callback.onOemHookRawEvent(rawData);
1375 } catch (RemoteException ex) {
1376 mRemoveList.add(r.binder);
1377 }
1378 }
1379 }
1380 handleRemoveListLocked();
1381 }
1382 }
1383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001384 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001385 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1386 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1387
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001388 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001391 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001393 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301394 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001395 pw.println("Phone Id=" + i);
1396 pw.increaseIndent();
1397 pw.println("mCallState=" + mCallState[i]);
1398 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1399 pw.println("mServiceState=" + mServiceState[i]);
1400 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1401 pw.println("mDataActivationState= " + mDataActivationState[i]);
1402 pw.println("mSignalStrength=" + mSignalStrength[i]);
1403 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1404 pw.println("mCallForwarding=" + mCallForwarding[i]);
1405 pw.println("mDataActivity=" + mDataActivity[i]);
1406 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001407 pw.println("mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1408 pw.println("mDataConnectionNetworkCapabilities=" +
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301409 mDataConnectionNetworkCapabilities[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001410 pw.println("mCellLocation=" + mCellLocation[i]);
1411 pw.println("mCellInfo=" + mCellInfo.get(i));
1412 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301413 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001414 pw.println("mConnectedApns=" + Arrays.toString(mConnectedApns));
1415 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1416 pw.println("mPreciseCallState=" + mPreciseCallState);
1417 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1418 pw.println("mRingingCallState=" + mRingingCallState);
1419 pw.println("mForegroundCallState=" + mForegroundCallState);
1420 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1421 pw.println("mVoLteServiceState=" + mVoLteServiceState);
1422
1423 pw.decreaseIndent();
1424
1425 pw.println("local logs:");
1426 pw.increaseIndent();
1427 mLocalLog.dump(fd, pw, args);
1428 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001429 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001430 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001431 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001432 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001433 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001434 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435 }
1436 }
1437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001438 //
1439 // the legacy intent broadcasting
1440 //
1441
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001442 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001443 long ident = Binder.clearCallingIdentity();
1444 try {
1445 mBatteryStats.notePhoneState(state.getState());
1446 } catch (RemoteException re) {
1447 // Can't do much
1448 } finally {
1449 Binder.restoreCallingIdentity(ident);
1450 }
1451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001452 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001453 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001454 Bundle data = new Bundle();
1455 state.fillInNotifierBundle(data);
1456 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001457 // Pass the subscription along with the intent.
1458 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001459 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001460 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 }
1462
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001463 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1464 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001465 long ident = Binder.clearCallingIdentity();
1466 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001467 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001468 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001469 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001470 } finally {
1471 Binder.restoreCallingIdentity(ident);
1472 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001474 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001475 Bundle data = new Bundle();
1476 signalStrength.fillInNotifierBundle(data);
1477 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001478 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001479 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001480 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001481 }
1482
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001483 /**
1484 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1485 * a valid subId, in which case this function fires a subId-specific intent, or it
1486 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1487 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1488 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001489 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1490 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001491 long ident = Binder.clearCallingIdentity();
1492 try {
1493 if (state == TelephonyManager.CALL_STATE_IDLE) {
1494 mBatteryStats.notePhoneOff();
1495 } else {
1496 mBatteryStats.notePhoneOn();
1497 }
1498 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001499 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001500 } finally {
1501 Binder.restoreCallingIdentity(ident);
1502 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001505 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001506 PhoneConstantConversions.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507 if (!TextUtils.isEmpty(incomingNumber)) {
1508 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1509 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001510
1511 // If a valid subId was specified, we should fire off a subId-specific state
1512 // change intent and include the subId.
1513 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1514 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1515 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1516 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001517 // If the phoneId is invalid, the broadcast is for overall call state.
1518 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1519 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1520 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001521
Brad Ebinger51de96a2017-04-21 17:05:18 -07001522 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1523 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1524
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001525 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1526 // that have the runtime one
1527 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1528 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001529 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001530 android.Manifest.permission.READ_PHONE_STATE,
1531 AppOpsManager.OP_READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532 }
1533
Robert Greenwalt42acef32009-08-12 16:08:25 -07001534 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001535 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001536 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001537 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001538 // Note: not reporting to the battery stats service here, because the
1539 // status bar takes care of that after taking into account all of the
1540 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001541 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001542 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001543 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001544 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001545 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001546 }
1547 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001548 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001550 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001551 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001552 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001553 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001554 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001555 }
1556 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001557 if (networkCapabilities != null) {
1558 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001559 }
Wink Savillea639b312012-07-10 12:37:54 -07001560 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001561
Wink Savillea639b312012-07-10 12:37:54 -07001562 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1563 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001564 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001565 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001566 }
1567
Wink Savillefb40dd42014-06-12 17:02:31 -07001568 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001569 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001571 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1572 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001573 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001574 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001575 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001576
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001577 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1578 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1579 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1580 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1581 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1582 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1583 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1584 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1585 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1586 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1587 }
1588
1589 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001590 String apnType, String apn, String reason, LinkProperties linkProperties,
1591 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001592 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1593 intent.putExtra(PhoneConstants.STATE_KEY, state);
1594 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1595 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1596 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1597 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001598 if (linkProperties != null) {
1599 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1600 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001601 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1602
1603 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1604 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1605 }
1606
Andrew Flynnceaed682015-06-09 12:36:58 +00001607 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
1608 if (checkNotifyPermission()) {
1609 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001610 }
1611
Andrew Flynnceaed682015-06-09 12:36:58 +00001612 enforceCarrierPrivilege();
Andrew Flynn1f452642015-04-14 22:16:04 -04001613 }
1614
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001615 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001616 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001617 return true;
1618 }
1619 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001620 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001621 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001622 return false;
1623 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001624
Andrew Flynn1f452642015-04-14 22:16:04 -04001625 private boolean checkNotifyPermission() {
1626 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1627 == PackageManager.PERMISSION_GRANTED;
1628 }
1629
Andrew Flynnceaed682015-06-09 12:36:58 +00001630 private void enforceCarrierPrivilege() {
Andrew Flynn1f452642015-04-14 22:16:04 -04001631 TelephonyManager tm = TelephonyManager.getDefault();
1632 String[] pkgs = mContext.getPackageManager().getPackagesForUid(Binder.getCallingUid());
1633 for (String pkg : pkgs) {
1634 if (tm.checkCarrierPrivilegesForPackage(pkg) ==
1635 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001636 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001637 }
1638 }
1639
Andrew Flynnceaed682015-06-09 12:36:58 +00001640 String msg = "Carrier Privilege Permission Denial: from pid=" + Binder.getCallingPid()
1641 + ", uid=" + Binder.getCallingUid();
1642 if (DBG) log(msg);
1643 throw new SecurityException(msg);
Andrew Flynn1f452642015-04-14 22:16:04 -04001644 }
1645
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001646 private void checkListenerPermission(int events) {
1647 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1648 mContext.enforceCallingOrSelfPermission(
1649 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1650
1651 }
1652
John Wang963db55d2012-03-30 16:04:06 -07001653 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1654 mContext.enforceCallingOrSelfPermission(
1655 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1656
1657 }
1658
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001659 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001660 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -07001661 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001662 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -07001663 // SKIP checking for run-time permission since caller or self has PRIVILEGED
1664 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001665 } catch (SecurityException e) {
1666 mContext.enforceCallingOrSelfPermission(
1667 android.Manifest.permission.READ_PHONE_STATE, null);
1668 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001669 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001670
1671 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1672 mContext.enforceCallingOrSelfPermission(
1673 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1674
1675 }
New Author Steven Liu485f2092014-09-11 10:18:45 -05001676
1677 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1678 mContext.enforceCallingOrSelfPermission(
1679 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1680 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001681 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001682
1683 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001684 int size = mRemoveList.size();
1685 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1686 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001687 for (IBinder b: mRemoveList) {
1688 remove(b);
1689 }
1690 mRemoveList.clear();
1691 }
1692 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001693
1694 private boolean validateEventsAndUserLocked(Record r, int events) {
1695 int foregroundUser;
1696 long callingIdentity = Binder.clearCallingIdentity();
1697 boolean valid = false;
1698 try {
1699 foregroundUser = ActivityManager.getCurrentUser();
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001700 valid = r.callerUserId == foregroundUser && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001701 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001702 log("validateEventsAndUserLocked: valid=" + valid
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001703 + " r.callerUserId=" + r.callerUserId + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001704 + " r.events=" + r.events + " events=" + events);
1705 }
1706 } finally {
1707 Binder.restoreCallingIdentity(callingIdentity);
1708 }
1709 return valid;
1710 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001711
1712 private boolean validatePhoneId(int phoneId) {
1713 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001714 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001715 return valid;
1716 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001717
1718 private static void log(String s) {
1719 Rlog.d(TAG, s);
1720 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001721
xinhe8b79fb62014-11-05 14:55:03 -08001722 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001723
1724 if(subId < 0) {
1725 // Invalid case, we need compare phoneId with default one.
1726 return (mDefaultPhoneId == phoneId);
1727 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001728 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001729 return (subId == mDefaultSubId);
1730 } else {
1731 return (rSubId == subId);
1732 }
1733 }
1734
1735 private void checkPossibleMissNotify(Record r, int phoneId) {
1736 int events = r.events;
1737
1738 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1739 try {
1740 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1741 mServiceState[phoneId]);
1742 r.callback.onServiceStateChanged(
1743 new ServiceState(mServiceState[phoneId]));
1744 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001745 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001746 }
1747 }
1748
1749 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1750 try {
1751 SignalStrength signalStrength = mSignalStrength[phoneId];
1752 if (DBG) {
1753 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1754 }
1755 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1756 } catch (RemoteException ex) {
1757 mRemoveList.add(r.binder);
1758 }
1759 }
1760
1761 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1762 try {
1763 int gsmSignalStrength = mSignalStrength[phoneId]
1764 .getGsmSignalStrength();
1765 if (DBG) {
1766 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1767 gsmSignalStrength);
1768 }
1769 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1770 : gsmSignalStrength));
1771 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001772 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001773 }
1774 }
1775
1776 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1777 try {
1778 if (DBG_LOC) {
1779 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1780 + mCellInfo.get(phoneId));
1781 }
1782 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1783 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001784 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001785 }
1786 }
1787
1788 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1789 try {
1790 if (VDBG) {
1791 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1792 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1793 }
1794 r.callback.onMessageWaitingIndicatorChanged(
1795 mMessageWaiting[phoneId]);
1796 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001797 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001798 }
1799 }
1800
1801 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1802 try {
1803 if (VDBG) {
1804 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1805 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1806 }
1807 r.callback.onCallForwardingIndicatorChanged(
1808 mCallForwarding[phoneId]);
1809 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001810 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001811 }
1812 }
1813
1814 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1815 try {
1816 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1817 + mCellLocation[phoneId]);
1818 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1819 } catch (RemoteException ex) {
1820 mRemoveList.add(r.binder);
1821 }
1822 }
1823
1824 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1825 try {
1826 if (DBG) {
1827 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1828 + "=" + mDataConnectionState[phoneId]
1829 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1830 + ")");
1831 }
1832 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1833 mDataConnectionNetworkType[phoneId]);
1834 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001835 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001836 }
1837 }
1838 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001839}