blob: 6747be340d46e9084e9cc5e30e5701784e1b47fd [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
zxuan35a47022018-01-04 11:24:04 -0800150 private boolean[] mUserMobileDataState;
151
Wink Savillefb40dd42014-06-12 17:02:31 -0700152 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700153
Wink Savillefb40dd42014-06-12 17:02:31 -0700154 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700155
Wink Savillefb40dd42014-06-12 17:02:31 -0700156 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700157
Wink Savillefb40dd42014-06-12 17:02:31 -0700158 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700159
Wink Savillefb40dd42014-06-12 17:02:31 -0700160 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700161
Yifan Bai57b39e32016-04-01 16:24:33 +0800162 private ArrayList<String>[] mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700163
Wink Savillefb40dd42014-06-12 17:02:31 -0700164 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700165
Wink Savillefb40dd42014-06-12 17:02:31 -0700166 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700167
Wink Savillefb40dd42014-06-12 17:02:31 -0700168 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169
Wink Savillefb40dd42014-06-12 17:02:31 -0700170 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700171
Nathan Harold016e9c62016-12-14 11:24:48 -0800172 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700173
Wink Savillefb40dd42014-06-12 17:02:31 -0700174 private ArrayList<List<CellInfo>> mCellInfo = null;
175
176 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
177
Wink Savilled09c4ca2014-11-22 10:08:16 -0800178 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700179
Wink Savilled09c4ca2014-11-22 10:08:16 -0800180 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700181
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200182 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
183
184 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
185
186 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
187
188 private PreciseCallState mPreciseCallState = new PreciseCallState();
189
Andrew Flynn1f452642015-04-14 22:16:04 -0400190 private boolean mCarrierNetworkChangeState = false;
191
Jack Yud19b6ae2017-04-05 14:12:09 -0700192 private final LocalLog mLocalLog = new LocalLog(100);
193
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200194 private PreciseDataConnectionState mPreciseDataConnectionState =
195 new PreciseDataConnectionState();
196
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700197 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700198 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700199 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
200 PhoneStateListener.LISTEN_VOLTE_STATE;
201
202 static final int CHECK_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700203 PhoneStateListener.LISTEN_CALL_STATE |
204 PhoneStateListener.LISTEN_DATA_ACTIVITY |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700205 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700206
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200207 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
208 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
209 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
210
Wink Savillea12a7b32012-09-20 10:09:45 -0700211 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700212 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700213
214 private final Handler mHandler = new Handler() {
215 @Override
216 public void handleMessage(Message msg) {
217 switch (msg.what) {
218 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700219 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700220 int numPhones = TelephonyManager.getDefault().getPhoneCount();
221 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700222 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700223 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700224 }
225 break;
226 }
xinhee9f16402014-09-25 16:39:28 -0700227 case MSG_UPDATE_DEFAULT_SUB: {
228 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700229 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700230 if (VDBG) {
231 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
232 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
233 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
234 }
235
236 //Due to possible risk condition,(notify call back using the new
237 //defaultSubId comes before new defaultSubId update) we need to recall all
238 //possible missed notify callback
239 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700240 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800241 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700242 checkPossibleMissNotify(r, newDefaultPhoneId);
243 }
244 }
245 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700246 }
247 mDefaultSubId = newDefaultSubId;
248 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700249 }
250 }
251 }
252 };
253
254 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
255 @Override
256 public void onReceive(Context context, Intent intent) {
257 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700258 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700259 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700260 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700261 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700262 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700263 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700264 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800265 PhoneConstants.SUBSCRIPTION_KEY,
266 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700267 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
268 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700269 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700270 log("onReceive:current mDefaultSubId=" + mDefaultSubId
271 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
272 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700273 }
xinhee9f16402014-09-25 16:39:28 -0700274
Junda Liu985f52c2015-02-23 16:06:51 -0800275 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700276 || (newDefaultPhoneId != mDefaultPhoneId))) {
277 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
278 newDefaultPhoneId, 0, newDefaultSubIdObj));
279 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700280 }
281 }
282 };
283
Wink Savillee9b06d72009-05-18 21:47:50 -0700284 // we keep a copy of all of the state so we can send it out when folks
285 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700287 // In these calls we call with the lock held. This is safe becasuse remote
288 // calls go through a oneway interface and local calls going through a
289 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290
291 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700292 CellLocation location = CellLocation.getEmpty();
293
Wink Savillefb40dd42014-06-12 17:02:31 -0700294 mContext = context;
295 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700296
Wink Savillefb40dd42014-06-12 17:02:31 -0700297 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700298 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700299 mNumPhones = numPhones;
Yifan Bai57b39e32016-04-01 16:24:33 +0800300 mConnectedApns = new ArrayList[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700301 mCallState = new int[numPhones];
302 mDataActivity = new int[numPhones];
303 mDataConnectionState = new int[numPhones];
304 mDataConnectionNetworkType = new int[numPhones];
305 mCallIncomingNumber = new String[numPhones];
306 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800307 mVoiceActivationState = new int[numPhones];
308 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800309 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700310 mSignalStrength = new SignalStrength[numPhones];
311 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700312 mCallForwarding = new boolean[numPhones];
313 mCellLocation = new Bundle[numPhones];
314 mDataConnectionLinkProperties = new LinkProperties[numPhones];
315 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
316 mCellInfo = new ArrayList<List<CellInfo>>();
317 for (int i = 0; i < numPhones; i++) {
318 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
319 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
320 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800321 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
322 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700323 mCallIncomingNumber[i] = "";
324 mServiceState[i] = new ServiceState();
325 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800326 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700327 mMessageWaiting[i] = false;
328 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700329 mCellLocation[i] = new Bundle();
330 mCellInfo.add(i, null);
Yifan Bai57b39e32016-04-01 16:24:33 +0800331 mConnectedApns[i] = new ArrayList<String>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700332 }
333
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700334 // Note that location can be null for non-phone builds like
335 // like the generic one.
336 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700337 for (int i = 0; i < numPhones; i++) {
338 location.fillInNotifierBundle(mCellLocation[i]);
339 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700340 }
Svet Ganov16a16892015-04-16 10:32:04 -0700341
342 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 }
344
Svetoslav Ganova0027152013-06-25 14:59:53 -0700345 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700346 // Watch for interesting updates
347 final IntentFilter filter = new IntentFilter();
348 filter.addAction(Intent.ACTION_USER_SWITCHED);
349 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700350 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700351 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700352 mContext.registerReceiver(mBroadcastReceiver, filter);
353 }
354
355 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700356 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800357 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700358 int callerUserId = UserHandle.getCallingUserId();
Wink Savillea374c3d2014-11-11 11:48:04 -0800359 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700360 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
361 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800362 + " callback.asBinder=" + callback.asBinder());
363 }
364
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700365 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700366 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700367 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
368 "addOnSubscriptionsChangedListener");
Amit Mahajana9e72a72015-07-30 16:04:13 -0700369 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700370 } catch (SecurityException e) {
371 mContext.enforceCallingOrSelfPermission(
372 android.Manifest.permission.READ_PHONE_STATE,
373 "addOnSubscriptionsChangedListener");
Svet Ganov16a16892015-04-16 10:32:04 -0700374
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700375 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
376 callingPackage) != AppOpsManager.MODE_ALLOWED) {
377 return;
378 }
Svet Ganov16a16892015-04-16 10:32:04 -0700379 }
380
Fyodor Kupolovac038a92015-06-09 13:14:54 -0700381 Record r;
Wink Savillea374c3d2014-11-11 11:48:04 -0800382
Wink Savilled09c4ca2014-11-22 10:08:16 -0800383 synchronized (mRecords) {
384 // register
385 find_and_add: {
386 IBinder b = callback.asBinder();
387 final int N = mRecords.size();
388 for (int i = 0; i < N; i++) {
389 r = mRecords.get(i);
390 if (b == r.binder) {
391 break find_and_add;
Wink Savillea374c3d2014-11-11 11:48:04 -0800392 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800393 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800394 r = new Record();
395 r.binder = b;
396 mRecords.add(r);
397 if (DBG) log("listen oscl: add new record");
Wink Savillea374c3d2014-11-11 11:48:04 -0800398 }
399
Wink Savilled09c4ca2014-11-22 10:08:16 -0800400 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700401 r.callingPackage = callingPackage;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700402 r.callerUserId = callerUserId;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800403 r.events = 0;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700404 r.canReadPhoneState = true; // permission has been enforced above
Wink Savilled09c4ca2014-11-22 10:08:16 -0800405 if (DBG) {
406 log("listen oscl: Register r=" + r);
407 }
408 // Always notify when registration occurs if there has been a notification.
409 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800410 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800411 if (VDBG) log("listen oscl: send to r=" + r);
412 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
413 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800414 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800415 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800416 remove(r.binder);
417 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800418 } else {
419 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800420 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800421 }
422 }
423
424 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800425 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800426 IOnSubscriptionsChangedListener callback) {
427 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800428 remove(callback.asBinder());
429 }
430
Wink Savillea374c3d2014-11-11 11:48:04 -0800431 @Override
432 public void notifySubscriptionInfoChanged() {
433 if (VDBG) log("notifySubscriptionInfoChanged:");
434 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800435 if (!hasNotifySubscriptionInfoChangedOccurred) {
436 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
437 + mRecords.size());
438 }
439 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800440 mRemoveList.clear();
441 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800442 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800443 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800444 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
445 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
446 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800447 } catch (RemoteException ex) {
448 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
449 mRemoveList.add(r.binder);
450 }
451 }
452 }
453 handleRemoveListLocked();
454 }
455 }
456
457 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
459 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800460 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
461 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700462 }
463
464 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700465 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700466 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700467 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700468 }
469
Svet Ganov16a16892015-04-16 10:32:04 -0700470 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700471 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700472 int callerUserId = UserHandle.getCallingUserId();
Wink Savillee380b982014-07-26 18:24:22 -0700473 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700474 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700475 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
476 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700477 }
xinhe75c2c152014-10-16 11:49:45 -0700478
479 if (events != PhoneStateListener.LISTEN_NONE) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700480 /* Checks permission and throws Security exception */
481 checkListenerPermission(events);
Svet Ganov16a16892015-04-16 10:32:04 -0700482
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700483 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700484 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700485 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700486 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -0700487 // SKIP checking for run-time permission since caller or self has PRIVILEGED
488 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700489 } catch (SecurityException e) {
490 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
491 callingPackage) != AppOpsManager.MODE_ALLOWED) {
492 return;
493 }
Svet Ganov16a16892015-04-16 10:32:04 -0700494 }
495 }
496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 synchronized (mRecords) {
498 // register
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700499 Record r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 find_and_add: {
501 IBinder b = callback.asBinder();
502 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700503 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 r = mRecords.get(i);
505 if (b == r.binder) {
506 break find_and_add;
507 }
508 }
509 r = new Record();
510 r.binder = b;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 mRecords.add(r);
Wink Savillee380b982014-07-26 18:24:22 -0700512 if (DBG) log("listen: add new record");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 }
xinhe43c50292014-09-18 17:56:48 -0700514
xinhe75c2c152014-10-16 11:49:45 -0700515 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700516 r.callingPackage = callingPackage;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700517 r.callerUserId = callerUserId;
518 boolean isPhoneStateEvent = (events & (CHECK_PHONE_STATE_PERMISSION_MASK
519 | ENFORCE_PHONE_STATE_PERMISSION_MASK)) != 0;
520 r.canReadPhoneState = isPhoneStateEvent && canReadPhoneState(callingPackage);
xinhe75c2c152014-10-16 11:49:45 -0700521 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
522 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800523 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800524 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700525 } else {//APP specify subID
526 r.subId = subId;
527 }
528 r.phoneId = SubscriptionManager.getPhoneId(r.subId);
529
xinhe43c50292014-09-18 17:56:48 -0700530 int phoneId = r.phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700532 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700533 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700534 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700535 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400537 try {
Wink Savillee380b982014-07-26 18:24:22 -0700538 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700539 r.callback.onServiceStateChanged(
540 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400541 } catch (RemoteException ex) {
542 remove(r.binder);
543 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 }
545 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
546 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700547 int gsmSignalStrength = mSignalStrength[phoneId]
548 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700549 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
550 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 } catch (RemoteException ex) {
552 remove(r.binder);
553 }
554 }
555 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
556 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700557 r.callback.onMessageWaitingIndicatorChanged(
558 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 } catch (RemoteException ex) {
560 remove(r.binder);
561 }
562 }
563 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
564 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700565 r.callback.onCallForwardingIndicatorChanged(
566 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 } catch (RemoteException ex) {
568 remove(r.binder);
569 }
570 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700571 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400572 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700573 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700574 + mCellLocation[phoneId]);
575 r.callback.onCellLocationChanged(
576 new Bundle(mCellLocation[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400577 } catch (RemoteException ex) {
578 remove(r.binder);
579 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 }
581 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
582 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700583 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700584 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 } catch (RemoteException ex) {
586 remove(r.binder);
587 }
588 }
589 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
590 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700591 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
592 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 } catch (RemoteException ex) {
594 remove(r.binder);
595 }
596 }
597 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
598 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700599 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 } catch (RemoteException ex) {
601 remove(r.binder);
602 }
603 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700604 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
605 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700606 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700607 } catch (RemoteException ex) {
608 remove(r.binder);
609 }
610 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700611 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
612 try {
613 r.callback.onOtaspChanged(mOtaspMode);
614 } catch (RemoteException ex) {
615 remove(r.binder);
616 }
617 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700618 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700619 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700620 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700621 + mCellInfo.get(phoneId));
622 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
John Wang963db55d2012-03-30 16:04:06 -0700623 } catch (RemoteException ex) {
624 remove(r.binder);
625 }
626 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200627 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
628 try {
629 r.callback.onPreciseCallStateChanged(mPreciseCallState);
630 } catch (RemoteException ex) {
631 remove(r.binder);
632 }
633 }
634 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
635 try {
636 r.callback.onPreciseDataConnectionStateChanged(
637 mPreciseDataConnectionState);
638 } catch (RemoteException ex) {
639 remove(r.binder);
640 }
641 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400642 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
643 try {
644 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
645 } catch (RemoteException ex) {
646 remove(r.binder);
647 }
648 }
fionaxu12312f62016-11-14 13:32:14 -0800649 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
650 try {
651 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
652 } catch (RemoteException ex) {
653 remove(r.binder);
654 }
655 }
656 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
657 try {
658 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
659 } catch (RemoteException ex) {
660 remove(r.binder);
661 }
662 }
zxuan35a47022018-01-04 11:24:04 -0800663 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
664 try {
665 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
666 } catch (RemoteException ex) {
667 remove(r.binder);
668 }
669 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 }
671 }
672 } else {
xinhe75c2c152014-10-16 11:49:45 -0700673 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 remove(callback.asBinder());
675 }
676 }
677
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700678 private boolean canReadPhoneState(String callingPackage) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700679 if (mContext.checkCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700680 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) ==
681 PackageManager.PERMISSION_GRANTED) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700682 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700683 return true;
684 }
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700685 boolean canReadPhoneState = mContext.checkCallingOrSelfPermission(
686 android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
687 if (canReadPhoneState &&
688 mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
689 callingPackage) != AppOpsManager.MODE_ALLOWED) {
690 return false;
691 }
692 return canReadPhoneState;
693 }
694
695 private String getCallIncomingNumber(Record record, int phoneId) {
696 // Hide the number if record's process has no READ_PHONE_STATE permission
697 return record.canReadPhoneState ? mCallIncomingNumber[phoneId] : "";
698 }
699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800700 private void remove(IBinder binder) {
701 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700702 final int recordCount = mRecords.size();
703 for (int i = 0; i < recordCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800704 if (mRecords.get(i).binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800705 if (DBG) {
706 Record r = mRecords.get(i);
Svet Ganov16a16892015-04-16 10:32:04 -0700707 log("remove: binder=" + binder + "r.callingPackage" + r.callingPackage
xinheac11ae92014-12-18 10:02:14 -0800708 + "r.callback" + r.callback);
709 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 mRecords.remove(i);
711 return;
712 }
713 }
714 }
715 }
716
717 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700718 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700719 return;
720 }
xinhe43c50292014-09-18 17:56:48 -0700721
722 if (VDBG) {
723 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
724 }
725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800726 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700727 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800728 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800729 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700731 String incomingNumberOrEmpty = r.canReadPhoneState ? incomingNumber : "";
732 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400734 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 }
736 }
737 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400738 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700740
741 // Called only by Telecomm to communicate call state across different phone accounts. So
742 // there is no need to add a valid subId or slotId.
Wink Savilled09c4ca2014-11-22 10:08:16 -0800743 broadcastCallStateChanged(state, incomingNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700744 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700745 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746 }
747
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700748 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
749 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700750 if (!checkNotifyPermission("notifyCallState()")) {
751 return;
752 }
Wink Savillee380b982014-07-26 18:24:22 -0700753 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700754 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700755 + " state=" + state + " incomingNumber=" + incomingNumber);
756 }
757 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700758 if (validatePhoneId(phoneId)) {
759 mCallState[phoneId] = state;
760 mCallIncomingNumber[phoneId] = incomingNumber;
761 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800762 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700763 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800764 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700765 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700766 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
767 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700768 } catch (RemoteException ex) {
769 mRemoveList.add(r.binder);
770 }
771 }
772 }
773 }
774 handleRemoveListLocked();
775 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700776 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700777 }
778
Wink Saville63f03dd2014-10-23 10:44:45 -0700779 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700780 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700781 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700782 }
xinhe43c50292014-09-18 17:56:48 -0700783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700785 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
786 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700787 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700788 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700789 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700790 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700791 if (validatePhoneId(phoneId)) {
792 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700793
Wink Savillefb40dd42014-06-12 17:02:31 -0700794 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700795 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700796 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700797 + " phoneId=" + phoneId + " state=" + state);
798 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800799 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800800 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700801 try {
Wink Savillee380b982014-07-26 18:24:22 -0700802 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700803 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700804 + " subId=" + subId + " phoneId=" + phoneId
805 + " state=" + state);
806 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700807 r.callback.onServiceStateChanged(new ServiceState(state));
808 } catch (RemoteException ex) {
809 mRemoveList.add(r.binder);
810 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400811 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700813 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700814 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800815 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400816 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800817 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700818 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 }
820
fionaxu12312f62016-11-14 13:32:14 -0800821 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
822 int activationType, int activationState) {
823 if (!checkNotifyPermission("notifySimActivationState()")){
824 return;
825 }
826 if (VDBG) {
827 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
828 + "type=" + activationType + " state=" + activationState);
829 }
830 synchronized (mRecords) {
831 if (validatePhoneId(phoneId)) {
832 switch (activationType) {
833 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
834 mVoiceActivationState[phoneId] = activationState;
835 break;
836 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
837 mDataActivationState[phoneId] = activationState;
838 break;
839 default:
840 return;
841 }
842 for (Record r : mRecords) {
843 if (VDBG) {
844 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
845 + " phoneId=" + phoneId + "type=" + activationType
846 + " state=" + activationState);
847 }
848 try {
849 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
850 r.matchPhoneStateListenerEvent(
851 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
852 idMatch(r.subId, subId, phoneId)) {
853 if (DBG) {
854 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
855 + " subId=" + subId + " phoneId=" + phoneId
856 + " state=" + activationState);
857 }
858 r.callback.onVoiceActivationStateChanged(activationState);
859 }
860 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
861 r.matchPhoneStateListenerEvent(
862 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
863 idMatch(r.subId, subId, phoneId)) {
864 if (DBG) {
865 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
866 + " subId=" + subId + " phoneId=" + phoneId
867 + " state=" + activationState);
868 }
869 r.callback.onDataActivationStateChanged(activationState);
870 }
871 } catch (RemoteException ex) {
872 mRemoveList.add(r.binder);
873 }
874 }
875 } else {
876 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
877 }
878 handleRemoveListLocked();
879 }
880 }
881
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700882 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
883 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700884 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700885 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700886 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000887 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700888 log("notifySignalStrengthForPhoneId: subId=" + subId
889 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000890 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700893 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700894 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700895 mSignalStrength[phoneId] = signalStrength;
896 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000897 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700898 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000899 + " phoneId=" + phoneId + " ss=" + signalStrength);
900 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800901 if (r.matchPhoneStateListenerEvent(
902 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800903 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700904 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000905 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700906 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000907 + " subId=" + subId + " phoneId=" + phoneId
908 + " ss=" + signalStrength);
909 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700910 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
911 } catch (RemoteException ex) {
912 mRemoveList.add(r.binder);
913 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400914 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800915 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800916 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700917 try {
918 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700919 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000920 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700921 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000922 + " subId=" + subId + " phoneId=" + phoneId
923 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
924 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700925 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700926 } catch (RemoteException ex) {
927 mRemoveList.add(r.binder);
928 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 }
930 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700931 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700932 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400934 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700936 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 }
938
Andrew Flynn1f452642015-04-14 22:16:04 -0400939 @Override
940 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +0000941 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
942
Andrew Flynn1f452642015-04-14 22:16:04 -0400943 if (VDBG) {
944 log("notifyCarrierNetworkChange: active=" + active);
945 }
946
947 synchronized (mRecords) {
948 mCarrierNetworkChangeState = active;
949 for (Record r : mRecords) {
950 if (r.matchPhoneStateListenerEvent(
951 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
952 try {
953 r.callback.onCarrierNetworkChange(active);
954 } catch (RemoteException ex) {
955 mRemoveList.add(r.binder);
956 }
957 }
958 }
959 handleRemoveListLocked();
960 }
961 }
962
Wink Savilleb208a242012-07-25 14:08:09 -0700963 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800964 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700965 }
966
Wink Saville63f03dd2014-10-23 10:44:45 -0700967 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700968 if (!checkNotifyPermission("notifyCellInfo()")) {
969 return;
970 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700971 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700972 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700973 + " cellInfo=" + cellInfo);
974 }
John Wang963db55d2012-03-30 16:04:06 -0700975
976 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700977 int phoneId = SubscriptionManager.getPhoneId(subId);
978 if (validatePhoneId(phoneId)) {
979 mCellInfo.set(phoneId, cellInfo);
980 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -0700981 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
xinhe8b79fb62014-11-05 14:55:03 -0800982 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700983 try {
984 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700985 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -0700986 }
987 r.callback.onCellInfoChanged(cellInfo);
988 } catch (RemoteException ex) {
989 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700990 }
John Wang963db55d2012-03-30 16:04:06 -0700991 }
992 }
993 }
994 handleRemoveListLocked();
995 }
996 }
997
xinhe43c50292014-09-18 17:56:48 -0700998 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700999 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001000 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001001 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001002 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001003 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001004 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001005 + " mwi=" + mwi);
1006 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001007 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001008 if (validatePhoneId(phoneId)) {
1009 mMessageWaiting[phoneId] = mwi;
1010 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001011 if (r.matchPhoneStateListenerEvent(
1012 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001013 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001014 try {
1015 r.callback.onMessageWaitingIndicatorChanged(mwi);
1016 } catch (RemoteException ex) {
1017 mRemoveList.add(r.binder);
1018 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001019 }
1020 }
1021 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001022 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001023 }
1024 }
1025
zxuan35a47022018-01-04 11:24:04 -08001026 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1027 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1028 return;
1029 }
1030 if (VDBG) {
1031 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1032 + " state=" + state);
1033 }
1034 synchronized (mRecords) {
1035 if (validatePhoneId(phoneId)) {
1036 mMessageWaiting[phoneId] = state;
1037 for (Record r : mRecords) {
1038 if (r.matchPhoneStateListenerEvent(
1039 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1040 idMatch(r.subId, subId, phoneId)) {
1041 try {
1042 r.callback.onUserMobileDataStateChanged(state);
1043 } catch (RemoteException ex) {
1044 mRemoveList.add(r.binder);
1045 }
1046 }
1047 }
1048 }
1049 handleRemoveListLocked();
1050 }
1051 }
1052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001054 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001055 }
1056
Wink Saville63f03dd2014-10-23 10:44:45 -07001057 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001058 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001059 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001060 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001061 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001062 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001063 + " cfi=" + cfi);
1064 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001066 int phoneId = SubscriptionManager.getPhoneId(subId);
1067 if (validatePhoneId(phoneId)) {
1068 mCallForwarding[phoneId] = cfi;
1069 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001070 if (r.matchPhoneStateListenerEvent(
1071 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001072 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001073 try {
1074 r.callback.onCallForwardingIndicatorChanged(cfi);
1075 } catch (RemoteException ex) {
1076 mRemoveList.add(r.binder);
1077 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 }
1079 }
1080 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001081 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 }
1083 }
1084
1085 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001086 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001087 }
1088
Wink Saville63f03dd2014-10-23 10:44:45 -07001089 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001090 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001091 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001092 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001094 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001095 if (validatePhoneId(phoneId)) {
1096 mDataActivity[phoneId] = state;
1097 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001098 // Notify by correct subId.
1099 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1100 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001101 try {
1102 r.callback.onDataActivity(state);
1103 } catch (RemoteException ex) {
1104 mRemoveList.add(r.binder);
1105 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 }
1107 }
1108 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001109 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 }
1111 }
1112
Jack Yubaeec622017-05-01 17:01:11 -07001113 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001114 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001115 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001116 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001117 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001118 networkCapabilities, networkType, roaming);
1119 }
1120
Wink Saville63f03dd2014-10-23 10:44:45 -07001121 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001122 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001123 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1124 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001125 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001126 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001127 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001128 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001129 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001130 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001131 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001132 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001133 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001134 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001136 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001137 if (validatePhoneId(phoneId)) {
1138 boolean modified = false;
1139 if (state == TelephonyManager.DATA_CONNECTED) {
Yifan Bai57b39e32016-04-01 16:24:33 +08001140 if (!mConnectedApns[phoneId].contains(apnType)) {
1141 mConnectedApns[phoneId].add(apnType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001142 if (mDataConnectionState[phoneId] != state) {
1143 mDataConnectionState[phoneId] = state;
1144 modified = true;
1145 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001147 } else {
Yifan Bai57b39e32016-04-01 16:24:33 +08001148 if (mConnectedApns[phoneId].remove(apnType)) {
1149 if (mConnectedApns[phoneId].isEmpty()) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001150 mDataConnectionState[phoneId] = state;
1151 modified = true;
1152 } else {
1153 // leave mDataConnectionState as is and
1154 // send out the new status for the APN in question.
Wink Savillebaf21da2014-11-19 16:03:09 -08001155 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001156 }
1157 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001158 mDataConnectionLinkProperties[phoneId] = linkProperties;
1159 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
1160 if (mDataConnectionNetworkType[phoneId] != networkType) {
1161 mDataConnectionNetworkType[phoneId] = networkType;
1162 // need to tell registered listeners about the new network type
1163 modified = true;
1164 }
1165 if (modified) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001166 String str = "onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
1167 + ", " + mDataConnectionNetworkType[phoneId] + ")";
1168 log(str);
1169 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001170 for (Record r : mRecords) {
1171 if (r.matchPhoneStateListenerEvent(
1172 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1173 idMatch(r.subId, subId, phoneId)) {
1174 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001175 if (DBG) {
1176 log("Notify data connection state changed on sub: " + subId);
1177 }
1178 r.callback.onDataConnectionStateChanged(
1179 mDataConnectionState[phoneId],
Wink Savilled09c4ca2014-11-22 10:08:16 -08001180 mDataConnectionNetworkType[phoneId]);
1181 } catch (RemoteException ex) {
1182 mRemoveList.add(r.binder);
1183 }
1184 }
1185 }
1186 handleRemoveListLocked();
1187 }
1188 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1189 apnType, apn, reason, linkProperties, "");
1190 for (Record r : mRecords) {
1191 if (r.matchPhoneStateListenerEvent(
1192 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1193 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001194 r.callback.onPreciseDataConnectionStateChanged(
1195 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001196 } catch (RemoteException ex) {
1197 mRemoveList.add(r.binder);
1198 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001199 }
1200 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001201 }
1202 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 }
Jack Yubaeec622017-05-01 17:01:11 -07001204 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001205 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001206 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1207 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 }
1209
Robert Greenwalt02648a42010-05-18 10:52:51 -07001210 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001211 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001212 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001213 }
1214
Wink Saville63f03dd2014-10-23 10:44:45 -07001215 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001216 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001217 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001218 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001219 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001220 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001221 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001222 + " reason=" + reason + " apnType=" + apnType);
1223 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001225 mPreciseDataConnectionState = new PreciseDataConnectionState(
1226 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1227 apnType, "", reason, null, "");
1228 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001229 if (r.matchPhoneStateListenerEvent(
1230 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001231 try {
1232 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1233 } catch (RemoteException ex) {
1234 mRemoveList.add(r.binder);
1235 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001236 }
1237 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001238 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001240 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001241 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1242 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 }
1244
1245 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001246 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001247 }
1248
Wink Saville63f03dd2014-10-23 10:44:45 -07001249 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001250 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001251 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001252 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001253 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001254 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001255 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001256 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001257 + " cellLocation=" + cellLocation);
1258 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001259 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001260 int phoneId = SubscriptionManager.getPhoneId(subId);
1261 if (validatePhoneId(phoneId)) {
1262 mCellLocation[phoneId] = cellLocation;
1263 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001264 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
xinhe8b79fb62014-11-05 14:55:03 -08001265 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001266 try {
1267 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001268 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001269 + " r=" + r);
1270 }
1271 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1272 } catch (RemoteException ex) {
1273 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001274 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001275 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276 }
1277 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001278 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001279 }
1280 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001281
Wink Savillefd2d0132010-10-28 14:22:26 -07001282 public void notifyOtaspChanged(int otaspMode) {
1283 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1284 return;
1285 }
1286 synchronized (mRecords) {
1287 mOtaspMode = otaspMode;
1288 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001289 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001290 try {
1291 r.callback.onOtaspChanged(otaspMode);
1292 } catch (RemoteException ex) {
1293 mRemoveList.add(r.binder);
1294 }
1295 }
1296 }
1297 handleRemoveListLocked();
1298 }
1299 }
1300
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001301 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1302 int backgroundCallState) {
1303 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1304 return;
1305 }
1306 synchronized (mRecords) {
1307 mRingingCallState = ringingCallState;
1308 mForegroundCallState = foregroundCallState;
1309 mBackgroundCallState = backgroundCallState;
1310 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1311 backgroundCallState,
1312 DisconnectCause.NOT_VALID,
1313 PreciseDisconnectCause.NOT_VALID);
1314 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001315 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001316 try {
1317 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1318 } catch (RemoteException ex) {
1319 mRemoveList.add(r.binder);
1320 }
1321 }
1322 }
1323 handleRemoveListLocked();
1324 }
1325 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1326 DisconnectCause.NOT_VALID,
1327 PreciseDisconnectCause.NOT_VALID);
1328 }
1329
1330 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1331 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1332 return;
1333 }
1334 synchronized (mRecords) {
1335 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1336 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1337 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001338 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001339 try {
1340 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1341 } catch (RemoteException ex) {
1342 mRemoveList.add(r.binder);
1343 }
1344 }
1345 }
1346 handleRemoveListLocked();
1347 }
1348 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1349 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1350 }
1351
1352 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1353 String apn, String failCause) {
1354 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1355 return;
1356 }
1357 synchronized (mRecords) {
1358 mPreciseDataConnectionState = new PreciseDataConnectionState(
1359 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1360 apnType, apn, reason, null, failCause);
1361 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001362 if (r.matchPhoneStateListenerEvent(
1363 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001364 try {
1365 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1366 } catch (RemoteException ex) {
1367 mRemoveList.add(r.binder);
1368 }
1369 }
1370 }
1371 handleRemoveListLocked();
1372 }
1373 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1374 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1375 }
1376
Wink Savillefb40dd42014-06-12 17:02:31 -07001377 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1378 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1379 return;
1380 }
1381 synchronized (mRecords) {
1382 mVoLteServiceState = lteState;
1383 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001384 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001385 try {
1386 r.callback.onVoLteServiceStateChanged(
1387 new VoLteServiceState(mVoLteServiceState));
1388 } catch (RemoteException ex) {
1389 mRemoveList.add(r.binder);
1390 }
1391 }
1392 }
1393 handleRemoveListLocked();
1394 }
1395 }
1396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001397 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001398 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1399 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1400
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001401 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001403 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001404 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001405 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001406 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301407 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001408 pw.println("Phone Id=" + i);
1409 pw.increaseIndent();
1410 pw.println("mCallState=" + mCallState[i]);
1411 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1412 pw.println("mServiceState=" + mServiceState[i]);
1413 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1414 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001415 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001416 pw.println("mSignalStrength=" + mSignalStrength[i]);
1417 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1418 pw.println("mCallForwarding=" + mCallForwarding[i]);
1419 pw.println("mDataActivity=" + mDataActivity[i]);
1420 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001421 pw.println("mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1422 pw.println("mDataConnectionNetworkCapabilities=" +
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301423 mDataConnectionNetworkCapabilities[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001424 pw.println("mCellLocation=" + mCellLocation[i]);
1425 pw.println("mCellInfo=" + mCellInfo.get(i));
1426 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301427 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001428 pw.println("mConnectedApns=" + Arrays.toString(mConnectedApns));
1429 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1430 pw.println("mPreciseCallState=" + mPreciseCallState);
1431 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1432 pw.println("mRingingCallState=" + mRingingCallState);
1433 pw.println("mForegroundCallState=" + mForegroundCallState);
1434 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1435 pw.println("mVoLteServiceState=" + mVoLteServiceState);
1436
1437 pw.decreaseIndent();
1438
1439 pw.println("local logs:");
1440 pw.increaseIndent();
1441 mLocalLog.dump(fd, pw, args);
1442 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001443 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001444 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001445 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001446 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001447 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001448 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001449 }
1450 }
1451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001452 //
1453 // the legacy intent broadcasting
1454 //
1455
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001456 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001457 long ident = Binder.clearCallingIdentity();
1458 try {
1459 mBatteryStats.notePhoneState(state.getState());
1460 } catch (RemoteException re) {
1461 // Can't do much
1462 } finally {
1463 Binder.restoreCallingIdentity(ident);
1464 }
1465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001466 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001467 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001468 Bundle data = new Bundle();
1469 state.fillInNotifierBundle(data);
1470 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001471 // Pass the subscription along with the intent.
1472 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001473 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001474 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 }
1476
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001477 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1478 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001479 long ident = Binder.clearCallingIdentity();
1480 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001481 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001482 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001483 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001484 } finally {
1485 Binder.restoreCallingIdentity(ident);
1486 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001489 Bundle data = new Bundle();
1490 signalStrength.fillInNotifierBundle(data);
1491 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001492 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001493 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001494 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 }
1496
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001497 /**
1498 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1499 * a valid subId, in which case this function fires a subId-specific intent, or it
1500 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1501 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1502 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001503 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1504 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001505 long ident = Binder.clearCallingIdentity();
1506 try {
1507 if (state == TelephonyManager.CALL_STATE_IDLE) {
1508 mBatteryStats.notePhoneOff();
1509 } else {
1510 mBatteryStats.notePhoneOn();
1511 }
1512 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001513 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514 } finally {
1515 Binder.restoreCallingIdentity(ident);
1516 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001518 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001519 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001520 PhoneConstantConversions.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 if (!TextUtils.isEmpty(incomingNumber)) {
1522 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1523 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001524
1525 // If a valid subId was specified, we should fire off a subId-specific state
1526 // change intent and include the subId.
1527 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1528 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1529 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1530 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001531 // If the phoneId is invalid, the broadcast is for overall call state.
1532 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1533 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1534 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001535
Brad Ebinger51de96a2017-04-21 17:05:18 -07001536 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1537 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1538
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001539 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1540 // that have the runtime one
1541 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1542 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001543 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001544 android.Manifest.permission.READ_PHONE_STATE,
1545 AppOpsManager.OP_READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001546 }
1547
Robert Greenwalt42acef32009-08-12 16:08:25 -07001548 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001549 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001550 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001551 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001552 // Note: not reporting to the battery stats service here, because the
1553 // status bar takes care of that after taking into account all of the
1554 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001556 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001557 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001558 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001559 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560 }
1561 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001562 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001564 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001565 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001566 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001567 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001568 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001569 }
1570 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001571 if (networkCapabilities != null) {
1572 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001573 }
Wink Savillea639b312012-07-10 12:37:54 -07001574 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001575
Wink Savillea639b312012-07-10 12:37:54 -07001576 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1577 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001578 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001579 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 }
1581
Wink Savillefb40dd42014-06-12 17:02:31 -07001582 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001583 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001584 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001585 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1586 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001587 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001588 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001590
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001591 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1592 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1593 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1594 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1595 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1596 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1597 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1598 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1599 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1600 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1601 }
1602
1603 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001604 String apnType, String apn, String reason, LinkProperties linkProperties,
1605 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001606 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1607 intent.putExtra(PhoneConstants.STATE_KEY, state);
1608 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1609 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1610 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1611 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001612 if (linkProperties != null) {
1613 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1614 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001615 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1616
1617 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1618 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1619 }
1620
Andrew Flynnceaed682015-06-09 12:36:58 +00001621 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
1622 if (checkNotifyPermission()) {
1623 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001624 }
1625
Andrew Flynnceaed682015-06-09 12:36:58 +00001626 enforceCarrierPrivilege();
Andrew Flynn1f452642015-04-14 22:16:04 -04001627 }
1628
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001629 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001630 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001631 return true;
1632 }
1633 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001634 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001635 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001636 return false;
1637 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001638
Andrew Flynn1f452642015-04-14 22:16:04 -04001639 private boolean checkNotifyPermission() {
1640 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1641 == PackageManager.PERMISSION_GRANTED;
1642 }
1643
Andrew Flynnceaed682015-06-09 12:36:58 +00001644 private void enforceCarrierPrivilege() {
Andrew Flynn1f452642015-04-14 22:16:04 -04001645 TelephonyManager tm = TelephonyManager.getDefault();
1646 String[] pkgs = mContext.getPackageManager().getPackagesForUid(Binder.getCallingUid());
1647 for (String pkg : pkgs) {
1648 if (tm.checkCarrierPrivilegesForPackage(pkg) ==
1649 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001650 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001651 }
1652 }
1653
Andrew Flynnceaed682015-06-09 12:36:58 +00001654 String msg = "Carrier Privilege Permission Denial: from pid=" + Binder.getCallingPid()
1655 + ", uid=" + Binder.getCallingUid();
1656 if (DBG) log(msg);
1657 throw new SecurityException(msg);
Andrew Flynn1f452642015-04-14 22:16:04 -04001658 }
1659
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001660 private void checkListenerPermission(int events) {
1661 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1662 mContext.enforceCallingOrSelfPermission(
1663 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1664
1665 }
1666
John Wang963db55d2012-03-30 16:04:06 -07001667 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1668 mContext.enforceCallingOrSelfPermission(
1669 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1670
1671 }
1672
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001673 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001674 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -07001675 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001676 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -07001677 // SKIP checking for run-time permission since caller or self has PRIVILEGED
1678 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001679 } catch (SecurityException e) {
1680 mContext.enforceCallingOrSelfPermission(
1681 android.Manifest.permission.READ_PHONE_STATE, null);
1682 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001683 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001684
1685 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1686 mContext.enforceCallingOrSelfPermission(
1687 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1688
1689 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001690 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001691
1692 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001693 int size = mRemoveList.size();
1694 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1695 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001696 for (IBinder b: mRemoveList) {
1697 remove(b);
1698 }
1699 mRemoveList.clear();
1700 }
1701 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001702
1703 private boolean validateEventsAndUserLocked(Record r, int events) {
1704 int foregroundUser;
1705 long callingIdentity = Binder.clearCallingIdentity();
1706 boolean valid = false;
1707 try {
1708 foregroundUser = ActivityManager.getCurrentUser();
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001709 valid = r.callerUserId == foregroundUser && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001710 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001711 log("validateEventsAndUserLocked: valid=" + valid
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001712 + " r.callerUserId=" + r.callerUserId + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001713 + " r.events=" + r.events + " events=" + events);
1714 }
1715 } finally {
1716 Binder.restoreCallingIdentity(callingIdentity);
1717 }
1718 return valid;
1719 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001720
1721 private boolean validatePhoneId(int phoneId) {
1722 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001723 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001724 return valid;
1725 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001726
1727 private static void log(String s) {
1728 Rlog.d(TAG, s);
1729 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001730
xinhe8b79fb62014-11-05 14:55:03 -08001731 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001732
1733 if(subId < 0) {
1734 // Invalid case, we need compare phoneId with default one.
1735 return (mDefaultPhoneId == phoneId);
1736 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001737 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001738 return (subId == mDefaultSubId);
1739 } else {
1740 return (rSubId == subId);
1741 }
1742 }
1743
1744 private void checkPossibleMissNotify(Record r, int phoneId) {
1745 int events = r.events;
1746
1747 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1748 try {
1749 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1750 mServiceState[phoneId]);
1751 r.callback.onServiceStateChanged(
1752 new ServiceState(mServiceState[phoneId]));
1753 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001754 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001755 }
1756 }
1757
1758 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1759 try {
1760 SignalStrength signalStrength = mSignalStrength[phoneId];
1761 if (DBG) {
1762 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1763 }
1764 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1765 } catch (RemoteException ex) {
1766 mRemoveList.add(r.binder);
1767 }
1768 }
1769
1770 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1771 try {
1772 int gsmSignalStrength = mSignalStrength[phoneId]
1773 .getGsmSignalStrength();
1774 if (DBG) {
1775 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1776 gsmSignalStrength);
1777 }
1778 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1779 : gsmSignalStrength));
1780 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001781 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001782 }
1783 }
1784
1785 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1786 try {
1787 if (DBG_LOC) {
1788 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1789 + mCellInfo.get(phoneId));
1790 }
1791 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1792 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001793 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001794 }
1795 }
1796
zxuan35a47022018-01-04 11:24:04 -08001797 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
1798 try {
1799 if (VDBG) {
1800 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
1801 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
1802 }
1803 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
1804 } catch (RemoteException ex) {
1805 mRemoveList.add(r.binder);
1806 }
1807 }
1808
xinhee9f16402014-09-25 16:39:28 -07001809 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1810 try {
1811 if (VDBG) {
1812 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1813 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1814 }
1815 r.callback.onMessageWaitingIndicatorChanged(
1816 mMessageWaiting[phoneId]);
1817 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001818 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001819 }
1820 }
1821
1822 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1823 try {
1824 if (VDBG) {
1825 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1826 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1827 }
1828 r.callback.onCallForwardingIndicatorChanged(
1829 mCallForwarding[phoneId]);
1830 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001831 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001832 }
1833 }
1834
1835 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1836 try {
1837 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1838 + mCellLocation[phoneId]);
1839 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1840 } catch (RemoteException ex) {
1841 mRemoveList.add(r.binder);
1842 }
1843 }
1844
1845 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1846 try {
1847 if (DBG) {
1848 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1849 + "=" + mDataConnectionState[phoneId]
1850 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1851 + ")");
1852 }
1853 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1854 mDataConnectionNetworkType[phoneId]);
1855 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001856 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001857 }
1858 }
1859 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001860}