blob: 6743484b91c4635531ff889a19d5f10d1a1a62dd [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;
Hall Liu5fb337f2017-11-22 17:38:15 -080038import android.telephony.LocationAccessPolicy;
Jack Yud19b6ae2017-04-05 14:12:09 -070039import android.telephony.PhoneStateListener;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020040import android.telephony.PreciseCallState;
41import android.telephony.PreciseDataConnectionState;
42import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070043import android.telephony.Rlog;
44import android.telephony.ServiceState;
45import android.telephony.SignalStrength;
46import android.telephony.SubscriptionManager;
47import android.telephony.TelephonyManager;
48import android.telephony.VoLteServiceState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.text.TextUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070050import android.util.LocalLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
52import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080053import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070055import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080056import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070057import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import com.android.internal.telephony.TelephonyIntents;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060059import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070060import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import com.android.server.am.BatteryStatsService;
62
Jack Yud19b6ae2017-04-05 14:12:09 -070063import java.io.FileDescriptor;
64import java.io.PrintWriter;
65import java.util.ArrayList;
66import java.util.Arrays;
67import java.util.List;
68
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069/**
Wink Savillee9b06d72009-05-18 21:47:50 -070070 * Since phone process can be restarted, this class provides a centralized place
71 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070072 *
73 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
74 * and 15973975 by saving the phoneId of the registrant and then using the
75 * phoneId when deciding to to make a callback. This is necessary because
76 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070077 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070078 * the dummy value conversion we properly do the callbacks.
79 *
80 * Eventually we may want to remove the notion of dummy value but for now this
81 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 */
83class TelephonyRegistry extends ITelephonyRegistry.Stub {
84 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070085 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070086 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070087 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088
89 private static class Record {
Svet Ganov16a16892015-04-16 10:32:04 -070090 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -080095 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -070096
Hall Liu5fb337f2017-11-22 17:38:15 -080097 int callerUid;
98 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -070099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700101
Wink Savilled09c4ca2014-11-22 10:08:16 -0800102 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700103
Wink Savilled09c4ca2014-11-22 10:08:16 -0800104 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800105
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700106 boolean canReadPhoneState;
107
Wink Savillea374c3d2014-11-11 11:48:04 -0800108 boolean matchPhoneStateListenerEvent(int events) {
109 return (callback != null) && ((events & this.events) != 0);
110 }
111
Wink Savilled09c4ca2014-11-22 10:08:16 -0800112 boolean matchOnSubscriptionsChangedListener() {
113 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800114 }
Wink Savillee380b982014-07-26 18:24:22 -0700115
Wink Savillea12a7b32012-09-20 10:09:45 -0700116 @Override
117 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700118 return "{callingPackage=" + callingPackage + " binder=" + binder
119 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800120 + " onSubscriptionsChangedListenererCallback="
121 + onSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800122 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700123 + " events=" + Integer.toHexString(events)
124 + " canReadPhoneState=" + canReadPhoneState + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700125 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 }
127
128 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700129
Joe Onorato163d8d92010-10-21 13:21:20 -0400130 // access should be inside synchronized (mRecords) for these two fields
131 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
132 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 private final IBatteryStats mBatteryStats;
135
Svet Ganov16a16892015-04-16 10:32:04 -0700136 private final AppOpsManager mAppOps;
137
Wink Savilled09c4ca2014-11-22 10:08:16 -0800138 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
139
Wink Savillefb40dd42014-06-12 17:02:31 -0700140 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700141
Wink Savillefb40dd42014-06-12 17:02:31 -0700142 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700143
Wink Savillefb40dd42014-06-12 17:02:31 -0700144 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700145
Wink Savillefb40dd42014-06-12 17:02:31 -0700146 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700147
fionaxu12312f62016-11-14 13:32:14 -0800148 private int[] mVoiceActivationState;
149
150 private int[] mDataActivationState;
151
zxuan35a47022018-01-04 11:24:04 -0800152 private boolean[] mUserMobileDataState;
153
Wink Savillefb40dd42014-06-12 17:02:31 -0700154 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700155
Wink Savillefb40dd42014-06-12 17:02:31 -0700156 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700157
Wink Savillefb40dd42014-06-12 17:02:31 -0700158 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700159
Wink Savillefb40dd42014-06-12 17:02:31 -0700160 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700161
Wink Savillefb40dd42014-06-12 17:02:31 -0700162 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700163
Yifan Bai57b39e32016-04-01 16:24:33 +0800164 private ArrayList<String>[] mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700165
Wink Savillefb40dd42014-06-12 17:02:31 -0700166 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700167
Wink Savillefb40dd42014-06-12 17:02:31 -0700168 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700169
Wink Savillefb40dd42014-06-12 17:02:31 -0700170 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171
Wink Savillefb40dd42014-06-12 17:02:31 -0700172 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700173
Nathan Harold016e9c62016-12-14 11:24:48 -0800174 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700175
Wink Savillefb40dd42014-06-12 17:02:31 -0700176 private ArrayList<List<CellInfo>> mCellInfo = null;
177
178 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
179
Wink Savilled09c4ca2014-11-22 10:08:16 -0800180 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700181
Wink Savilled09c4ca2014-11-22 10:08:16 -0800182 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700183
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200184 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
185
186 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
187
188 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
189
190 private PreciseCallState mPreciseCallState = new PreciseCallState();
191
Andrew Flynn1f452642015-04-14 22:16:04 -0400192 private boolean mCarrierNetworkChangeState = false;
193
Jack Yud19b6ae2017-04-05 14:12:09 -0700194 private final LocalLog mLocalLog = new LocalLog(100);
195
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200196 private PreciseDataConnectionState mPreciseDataConnectionState =
197 new PreciseDataConnectionState();
198
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700199 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700200 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700201 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
202 PhoneStateListener.LISTEN_VOLTE_STATE;
203
204 static final int CHECK_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700205 PhoneStateListener.LISTEN_CALL_STATE |
206 PhoneStateListener.LISTEN_DATA_ACTIVITY |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700207 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700208
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200209 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
210 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
211 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
212
Wink Savillea12a7b32012-09-20 10:09:45 -0700213 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700214 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700215
216 private final Handler mHandler = new Handler() {
217 @Override
218 public void handleMessage(Message msg) {
219 switch (msg.what) {
220 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700221 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700222 int numPhones = TelephonyManager.getDefault().getPhoneCount();
223 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700224 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700225 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700226 }
227 break;
228 }
xinhee9f16402014-09-25 16:39:28 -0700229 case MSG_UPDATE_DEFAULT_SUB: {
230 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700231 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700232 if (VDBG) {
233 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
234 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
235 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
236 }
237
238 //Due to possible risk condition,(notify call back using the new
239 //defaultSubId comes before new defaultSubId update) we need to recall all
240 //possible missed notify callback
241 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700242 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800243 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700244 checkPossibleMissNotify(r, newDefaultPhoneId);
245 }
246 }
247 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700248 }
249 mDefaultSubId = newDefaultSubId;
250 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700251 }
252 }
253 }
254 };
255
256 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
257 @Override
258 public void onReceive(Context context, Intent intent) {
259 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700260 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700261 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700262 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700263 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700264 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700265 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700266 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800267 PhoneConstants.SUBSCRIPTION_KEY,
268 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700269 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
270 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700271 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700272 log("onReceive:current mDefaultSubId=" + mDefaultSubId
273 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
274 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700275 }
xinhee9f16402014-09-25 16:39:28 -0700276
Junda Liu985f52c2015-02-23 16:06:51 -0800277 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700278 || (newDefaultPhoneId != mDefaultPhoneId))) {
279 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
280 newDefaultPhoneId, 0, newDefaultSubIdObj));
281 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700282 }
283 }
284 };
285
Wink Savillee9b06d72009-05-18 21:47:50 -0700286 // we keep a copy of all of the state so we can send it out when folks
287 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800288 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700289 // In these calls we call with the lock held. This is safe becasuse remote
290 // calls go through a oneway interface and local calls going through a
291 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292
293 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700294 CellLocation location = CellLocation.getEmpty();
295
Wink Savillefb40dd42014-06-12 17:02:31 -0700296 mContext = context;
297 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700298
Wink Savillefb40dd42014-06-12 17:02:31 -0700299 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700300 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700301 mNumPhones = numPhones;
Yifan Bai57b39e32016-04-01 16:24:33 +0800302 mConnectedApns = new ArrayList[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700303 mCallState = new int[numPhones];
304 mDataActivity = new int[numPhones];
305 mDataConnectionState = new int[numPhones];
306 mDataConnectionNetworkType = new int[numPhones];
307 mCallIncomingNumber = new String[numPhones];
308 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800309 mVoiceActivationState = new int[numPhones];
310 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800311 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700312 mSignalStrength = new SignalStrength[numPhones];
313 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700314 mCallForwarding = new boolean[numPhones];
315 mCellLocation = new Bundle[numPhones];
316 mDataConnectionLinkProperties = new LinkProperties[numPhones];
317 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
318 mCellInfo = new ArrayList<List<CellInfo>>();
319 for (int i = 0; i < numPhones; i++) {
320 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
321 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
322 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800323 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
324 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700325 mCallIncomingNumber[i] = "";
326 mServiceState[i] = new ServiceState();
327 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800328 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700329 mMessageWaiting[i] = false;
330 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700331 mCellLocation[i] = new Bundle();
332 mCellInfo.add(i, null);
Yifan Bai57b39e32016-04-01 16:24:33 +0800333 mConnectedApns[i] = new ArrayList<String>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700334 }
335
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700336 // Note that location can be null for non-phone builds like
337 // like the generic one.
338 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700339 for (int i = 0; i < numPhones; i++) {
340 location.fillInNotifierBundle(mCellLocation[i]);
341 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700342 }
Svet Ganov16a16892015-04-16 10:32:04 -0700343
344 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 }
346
Svetoslav Ganova0027152013-06-25 14:59:53 -0700347 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700348 // Watch for interesting updates
349 final IntentFilter filter = new IntentFilter();
350 filter.addAction(Intent.ACTION_USER_SWITCHED);
351 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700352 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700353 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700354 mContext.registerReceiver(mBroadcastReceiver, filter);
355 }
356
357 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700358 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800359 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700360 int callerUserId = UserHandle.getCallingUserId();
Hall Liu5fb337f2017-11-22 17:38:15 -0800361 mContext.getSystemService(AppOpsManager.class)
362 .checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800363 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700364 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
365 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800366 + " callback.asBinder=" + callback.asBinder());
367 }
368
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700369 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700370 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700371 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
372 "addOnSubscriptionsChangedListener");
Amit Mahajana9e72a72015-07-30 16:04:13 -0700373 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700374 } catch (SecurityException e) {
375 mContext.enforceCallingOrSelfPermission(
376 android.Manifest.permission.READ_PHONE_STATE,
377 "addOnSubscriptionsChangedListener");
Svet Ganov16a16892015-04-16 10:32:04 -0700378
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700379 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
380 callingPackage) != AppOpsManager.MODE_ALLOWED) {
381 return;
382 }
Svet Ganov16a16892015-04-16 10:32:04 -0700383 }
384
Fyodor Kupolovac038a92015-06-09 13:14:54 -0700385 Record r;
Wink Savillea374c3d2014-11-11 11:48:04 -0800386
Wink Savilled09c4ca2014-11-22 10:08:16 -0800387 synchronized (mRecords) {
388 // register
389 find_and_add: {
390 IBinder b = callback.asBinder();
391 final int N = mRecords.size();
392 for (int i = 0; i < N; i++) {
393 r = mRecords.get(i);
394 if (b == r.binder) {
395 break find_and_add;
Wink Savillea374c3d2014-11-11 11:48:04 -0800396 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800397 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800398 r = new Record();
399 r.binder = b;
400 mRecords.add(r);
401 if (DBG) log("listen oscl: add new record");
Wink Savillea374c3d2014-11-11 11:48:04 -0800402 }
403
Wink Savilled09c4ca2014-11-22 10:08:16 -0800404 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700405 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800406 r.callerUid = Binder.getCallingUid();
407 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800408 r.events = 0;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700409 r.canReadPhoneState = true; // permission has been enforced above
Wink Savilled09c4ca2014-11-22 10:08:16 -0800410 if (DBG) {
411 log("listen oscl: Register r=" + r);
412 }
413 // Always notify when registration occurs if there has been a notification.
414 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800415 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800416 if (VDBG) log("listen oscl: send to r=" + r);
417 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
418 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800419 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800420 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800421 remove(r.binder);
422 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800423 } else {
424 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800425 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800426 }
427 }
428
429 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800430 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800431 IOnSubscriptionsChangedListener callback) {
432 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800433 remove(callback.asBinder());
434 }
435
Wink Savillea374c3d2014-11-11 11:48:04 -0800436 @Override
437 public void notifySubscriptionInfoChanged() {
438 if (VDBG) log("notifySubscriptionInfoChanged:");
439 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800440 if (!hasNotifySubscriptionInfoChangedOccurred) {
441 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
442 + mRecords.size());
443 }
444 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800445 mRemoveList.clear();
446 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800447 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800448 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800449 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
450 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
451 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800452 } catch (RemoteException ex) {
453 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
454 mRemoveList.add(r.binder);
455 }
456 }
457 }
458 handleRemoveListLocked();
459 }
460 }
461
462 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
464 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800465 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
466 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700467 }
468
469 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700470 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700471 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700472 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700473 }
474
Svet Ganov16a16892015-04-16 10:32:04 -0700475 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700476 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700477 int callerUserId = UserHandle.getCallingUserId();
Hall Liu5fb337f2017-11-22 17:38:15 -0800478 mContext.getSystemService(AppOpsManager.class)
479 .checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700480 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700481 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700482 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
483 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700484 }
xinhe75c2c152014-10-16 11:49:45 -0700485
486 if (events != PhoneStateListener.LISTEN_NONE) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700487 /* Checks permission and throws Security exception */
488 checkListenerPermission(events);
Svet Ganov16a16892015-04-16 10:32:04 -0700489
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700490 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700491 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700492 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700493 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -0700494 // SKIP checking for run-time permission since caller or self has PRIVILEGED
495 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700496 } catch (SecurityException e) {
497 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
498 callingPackage) != AppOpsManager.MODE_ALLOWED) {
499 return;
500 }
Svet Ganov16a16892015-04-16 10:32:04 -0700501 }
502 }
503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 synchronized (mRecords) {
505 // register
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700506 Record r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 find_and_add: {
508 IBinder b = callback.asBinder();
509 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700510 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 r = mRecords.get(i);
512 if (b == r.binder) {
513 break find_and_add;
514 }
515 }
516 r = new Record();
517 r.binder = b;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 mRecords.add(r);
Wink Savillee380b982014-07-26 18:24:22 -0700519 if (DBG) log("listen: add new record");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 }
xinhe43c50292014-09-18 17:56:48 -0700521
xinhe75c2c152014-10-16 11:49:45 -0700522 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700523 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800524 r.callerUid = Binder.getCallingUid();
525 r.callerPid = Binder.getCallingPid();
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700526 boolean isPhoneStateEvent = (events & (CHECK_PHONE_STATE_PERMISSION_MASK
527 | ENFORCE_PHONE_STATE_PERMISSION_MASK)) != 0;
528 r.canReadPhoneState = isPhoneStateEvent && canReadPhoneState(callingPackage);
xinhe75c2c152014-10-16 11:49:45 -0700529 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
530 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800531 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800532 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700533 } else {//APP specify subID
534 r.subId = subId;
535 }
536 r.phoneId = SubscriptionManager.getPhoneId(r.subId);
537
xinhe43c50292014-09-18 17:56:48 -0700538 int phoneId = r.phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700540 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700541 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700542 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700543 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400545 try {
Wink Savillee380b982014-07-26 18:24:22 -0700546 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700547 r.callback.onServiceStateChanged(
548 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400549 } catch (RemoteException ex) {
550 remove(r.binder);
551 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 }
553 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
554 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700555 int gsmSignalStrength = mSignalStrength[phoneId]
556 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700557 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
558 : gsmSignalStrength));
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_MESSAGE_WAITING_INDICATOR) != 0) {
564 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700565 r.callback.onMessageWaitingIndicatorChanged(
566 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 } catch (RemoteException ex) {
568 remove(r.binder);
569 }
570 }
571 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
572 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700573 r.callback.onCallForwardingIndicatorChanged(
574 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 } catch (RemoteException ex) {
576 remove(r.binder);
577 }
578 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700579 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400580 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700581 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700582 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -0800583 if (checkLocationAccess(r)) {
584 r.callback.onCellLocationChanged(
585 new Bundle(mCellLocation[phoneId]));
586 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400587 } catch (RemoteException ex) {
588 remove(r.binder);
589 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 }
591 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
592 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700593 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700594 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 } catch (RemoteException ex) {
596 remove(r.binder);
597 }
598 }
599 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
600 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700601 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
602 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 } catch (RemoteException ex) {
604 remove(r.binder);
605 }
606 }
607 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
608 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700609 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 } catch (RemoteException ex) {
611 remove(r.binder);
612 }
613 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700614 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
615 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700616 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700617 } catch (RemoteException ex) {
618 remove(r.binder);
619 }
620 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700621 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
622 try {
623 r.callback.onOtaspChanged(mOtaspMode);
624 } catch (RemoteException ex) {
625 remove(r.binder);
626 }
627 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700628 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700629 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700630 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700631 + mCellInfo.get(phoneId));
Hall Liu5fb337f2017-11-22 17:38:15 -0800632 if (checkLocationAccess(r)) {
633 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
634 }
John Wang963db55d2012-03-30 16:04:06 -0700635 } catch (RemoteException ex) {
636 remove(r.binder);
637 }
638 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200639 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
640 try {
641 r.callback.onPreciseCallStateChanged(mPreciseCallState);
642 } catch (RemoteException ex) {
643 remove(r.binder);
644 }
645 }
646 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
647 try {
648 r.callback.onPreciseDataConnectionStateChanged(
649 mPreciseDataConnectionState);
650 } catch (RemoteException ex) {
651 remove(r.binder);
652 }
653 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400654 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
655 try {
656 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
657 } catch (RemoteException ex) {
658 remove(r.binder);
659 }
660 }
fionaxu12312f62016-11-14 13:32:14 -0800661 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
662 try {
663 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
664 } catch (RemoteException ex) {
665 remove(r.binder);
666 }
667 }
668 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
669 try {
670 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
671 } catch (RemoteException ex) {
672 remove(r.binder);
673 }
674 }
zxuan35a47022018-01-04 11:24:04 -0800675 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
676 try {
677 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
678 } catch (RemoteException ex) {
679 remove(r.binder);
680 }
681 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 }
683 }
684 } else {
xinhe75c2c152014-10-16 11:49:45 -0700685 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800686 remove(callback.asBinder());
687 }
688 }
689
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700690 private boolean canReadPhoneState(String callingPackage) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700691 if (mContext.checkCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700692 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) ==
693 PackageManager.PERMISSION_GRANTED) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700694 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700695 return true;
696 }
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700697 boolean canReadPhoneState = mContext.checkCallingOrSelfPermission(
698 android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
699 if (canReadPhoneState &&
700 mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
701 callingPackage) != AppOpsManager.MODE_ALLOWED) {
702 return false;
703 }
704 return canReadPhoneState;
705 }
706
707 private String getCallIncomingNumber(Record record, int phoneId) {
708 // Hide the number if record's process has no READ_PHONE_STATE permission
709 return record.canReadPhoneState ? mCallIncomingNumber[phoneId] : "";
710 }
711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800712 private void remove(IBinder binder) {
713 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700714 final int recordCount = mRecords.size();
715 for (int i = 0; i < recordCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800716 if (mRecords.get(i).binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800717 if (DBG) {
718 Record r = mRecords.get(i);
Svet Ganov16a16892015-04-16 10:32:04 -0700719 log("remove: binder=" + binder + "r.callingPackage" + r.callingPackage
xinheac11ae92014-12-18 10:02:14 -0800720 + "r.callback" + r.callback);
721 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 mRecords.remove(i);
723 return;
724 }
725 }
726 }
727 }
728
729 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700730 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700731 return;
732 }
xinhe43c50292014-09-18 17:56:48 -0700733
734 if (VDBG) {
735 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
736 }
737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700739 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800740 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800741 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700743 String incomingNumberOrEmpty = r.canReadPhoneState ? incomingNumber : "";
744 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400746 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 }
748 }
749 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400750 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700752
753 // Called only by Telecomm to communicate call state across different phone accounts. So
754 // there is no need to add a valid subId or slotId.
Wink Savilled09c4ca2014-11-22 10:08:16 -0800755 broadcastCallStateChanged(state, incomingNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700756 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700757 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800758 }
759
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700760 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
761 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700762 if (!checkNotifyPermission("notifyCallState()")) {
763 return;
764 }
Wink Savillee380b982014-07-26 18:24:22 -0700765 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700766 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700767 + " state=" + state + " incomingNumber=" + incomingNumber);
768 }
769 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700770 if (validatePhoneId(phoneId)) {
771 mCallState[phoneId] = state;
772 mCallIncomingNumber[phoneId] = incomingNumber;
773 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800774 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700775 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800776 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700777 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700778 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
779 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700780 } catch (RemoteException ex) {
781 mRemoveList.add(r.binder);
782 }
783 }
784 }
785 }
786 handleRemoveListLocked();
787 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700788 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700789 }
790
Wink Saville63f03dd2014-10-23 10:44:45 -0700791 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700792 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700793 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700794 }
xinhe43c50292014-09-18 17:56:48 -0700795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800796 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700797 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
798 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700799 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700800 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700801 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700802 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700803 if (validatePhoneId(phoneId)) {
804 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700805
Wink Savillefb40dd42014-06-12 17:02:31 -0700806 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700807 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700808 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700809 + " phoneId=" + phoneId + " state=" + state);
810 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800811 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800812 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700813 try {
Wink Savillee380b982014-07-26 18:24:22 -0700814 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700815 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700816 + " subId=" + subId + " phoneId=" + phoneId
817 + " state=" + state);
818 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700819 r.callback.onServiceStateChanged(new ServiceState(state));
820 } catch (RemoteException ex) {
821 mRemoveList.add(r.binder);
822 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400823 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700825 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700826 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400828 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700830 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 }
832
fionaxu12312f62016-11-14 13:32:14 -0800833 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
834 int activationType, int activationState) {
835 if (!checkNotifyPermission("notifySimActivationState()")){
836 return;
837 }
838 if (VDBG) {
839 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
840 + "type=" + activationType + " state=" + activationState);
841 }
842 synchronized (mRecords) {
843 if (validatePhoneId(phoneId)) {
844 switch (activationType) {
845 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
846 mVoiceActivationState[phoneId] = activationState;
847 break;
848 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
849 mDataActivationState[phoneId] = activationState;
850 break;
851 default:
852 return;
853 }
854 for (Record r : mRecords) {
855 if (VDBG) {
856 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
857 + " phoneId=" + phoneId + "type=" + activationType
858 + " state=" + activationState);
859 }
860 try {
861 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
862 r.matchPhoneStateListenerEvent(
863 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
864 idMatch(r.subId, subId, phoneId)) {
865 if (DBG) {
866 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
867 + " subId=" + subId + " phoneId=" + phoneId
868 + " state=" + activationState);
869 }
870 r.callback.onVoiceActivationStateChanged(activationState);
871 }
872 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
873 r.matchPhoneStateListenerEvent(
874 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
875 idMatch(r.subId, subId, phoneId)) {
876 if (DBG) {
877 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
878 + " subId=" + subId + " phoneId=" + phoneId
879 + " state=" + activationState);
880 }
881 r.callback.onDataActivationStateChanged(activationState);
882 }
883 } catch (RemoteException ex) {
884 mRemoveList.add(r.binder);
885 }
886 }
887 } else {
888 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
889 }
890 handleRemoveListLocked();
891 }
892 }
893
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700894 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
895 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700896 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700897 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700898 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000899 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700900 log("notifySignalStrengthForPhoneId: subId=" + subId
901 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000902 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700905 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700906 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700907 mSignalStrength[phoneId] = signalStrength;
908 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000909 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700910 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000911 + " phoneId=" + phoneId + " ss=" + signalStrength);
912 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800913 if (r.matchPhoneStateListenerEvent(
914 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800915 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700916 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000917 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700918 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000919 + " subId=" + subId + " phoneId=" + phoneId
920 + " ss=" + signalStrength);
921 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700922 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
923 } catch (RemoteException ex) {
924 mRemoveList.add(r.binder);
925 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400926 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800927 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800928 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700929 try {
930 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700931 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000932 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700933 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000934 + " subId=" + subId + " phoneId=" + phoneId
935 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
936 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700937 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700938 } catch (RemoteException ex) {
939 mRemoveList.add(r.binder);
940 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941 }
942 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700943 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700944 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800945 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400946 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700948 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800949 }
950
Andrew Flynn1f452642015-04-14 22:16:04 -0400951 @Override
952 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +0000953 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
954
Andrew Flynn1f452642015-04-14 22:16:04 -0400955 if (VDBG) {
956 log("notifyCarrierNetworkChange: active=" + active);
957 }
958
959 synchronized (mRecords) {
960 mCarrierNetworkChangeState = active;
961 for (Record r : mRecords) {
962 if (r.matchPhoneStateListenerEvent(
963 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
964 try {
965 r.callback.onCarrierNetworkChange(active);
966 } catch (RemoteException ex) {
967 mRemoveList.add(r.binder);
968 }
969 }
970 }
971 handleRemoveListLocked();
972 }
973 }
974
Wink Savilleb208a242012-07-25 14:08:09 -0700975 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800976 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700977 }
978
Wink Saville63f03dd2014-10-23 10:44:45 -0700979 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700980 if (!checkNotifyPermission("notifyCellInfo()")) {
981 return;
982 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700983 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700984 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700985 + " cellInfo=" + cellInfo);
986 }
John Wang963db55d2012-03-30 16:04:06 -0700987
988 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700989 int phoneId = SubscriptionManager.getPhoneId(subId);
990 if (validatePhoneId(phoneId)) {
991 mCellInfo.set(phoneId, cellInfo);
992 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -0700993 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -0800994 idMatch(r.subId, subId, phoneId) &&
995 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700996 try {
997 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700998 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -0700999 }
1000 r.callback.onCellInfoChanged(cellInfo);
1001 } catch (RemoteException ex) {
1002 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001003 }
John Wang963db55d2012-03-30 16:04:06 -07001004 }
1005 }
1006 }
1007 handleRemoveListLocked();
1008 }
1009 }
1010
xinhe43c50292014-09-18 17:56:48 -07001011 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001012 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001013 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001014 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001015 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001016 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001017 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001018 + " mwi=" + mwi);
1019 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001021 if (validatePhoneId(phoneId)) {
1022 mMessageWaiting[phoneId] = mwi;
1023 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001024 if (r.matchPhoneStateListenerEvent(
1025 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001026 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001027 try {
1028 r.callback.onMessageWaitingIndicatorChanged(mwi);
1029 } catch (RemoteException ex) {
1030 mRemoveList.add(r.binder);
1031 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 }
1033 }
1034 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001035 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 }
1037 }
1038
zxuan35a47022018-01-04 11:24:04 -08001039 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1040 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1041 return;
1042 }
1043 if (VDBG) {
1044 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1045 + " state=" + state);
1046 }
1047 synchronized (mRecords) {
1048 if (validatePhoneId(phoneId)) {
1049 mMessageWaiting[phoneId] = state;
1050 for (Record r : mRecords) {
1051 if (r.matchPhoneStateListenerEvent(
1052 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1053 idMatch(r.subId, subId, phoneId)) {
1054 try {
1055 r.callback.onUserMobileDataStateChanged(state);
1056 } catch (RemoteException ex) {
1057 mRemoveList.add(r.binder);
1058 }
1059 }
1060 }
1061 }
1062 handleRemoveListLocked();
1063 }
1064 }
1065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001067 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001068 }
1069
Wink Saville63f03dd2014-10-23 10:44:45 -07001070 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001071 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001072 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001073 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001074 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001075 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001076 + " cfi=" + cfi);
1077 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001079 int phoneId = SubscriptionManager.getPhoneId(subId);
1080 if (validatePhoneId(phoneId)) {
1081 mCallForwarding[phoneId] = cfi;
1082 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001083 if (r.matchPhoneStateListenerEvent(
1084 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001085 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001086 try {
1087 r.callback.onCallForwardingIndicatorChanged(cfi);
1088 } catch (RemoteException ex) {
1089 mRemoveList.add(r.binder);
1090 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 }
1092 }
1093 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001094 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 }
1096 }
1097
1098 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001099 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001100 }
1101
Wink Saville63f03dd2014-10-23 10:44:45 -07001102 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001103 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001104 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001105 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001107 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001108 if (validatePhoneId(phoneId)) {
1109 mDataActivity[phoneId] = state;
1110 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001111 // Notify by correct subId.
1112 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1113 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001114 try {
1115 r.callback.onDataActivity(state);
1116 } catch (RemoteException ex) {
1117 mRemoveList.add(r.binder);
1118 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 }
1120 }
1121 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001122 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001123 }
1124 }
1125
Jack Yubaeec622017-05-01 17:01:11 -07001126 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001127 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001128 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001129 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001130 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001131 networkCapabilities, networkType, roaming);
1132 }
1133
Wink Saville63f03dd2014-10-23 10:44:45 -07001134 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001135 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001136 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1137 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001138 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001139 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001140 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001141 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001142 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001143 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001144 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001145 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001146 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001149 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001150 if (validatePhoneId(phoneId)) {
1151 boolean modified = false;
1152 if (state == TelephonyManager.DATA_CONNECTED) {
Yifan Bai57b39e32016-04-01 16:24:33 +08001153 if (!mConnectedApns[phoneId].contains(apnType)) {
1154 mConnectedApns[phoneId].add(apnType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001155 if (mDataConnectionState[phoneId] != state) {
1156 mDataConnectionState[phoneId] = state;
1157 modified = true;
1158 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001160 } else {
Yifan Bai57b39e32016-04-01 16:24:33 +08001161 if (mConnectedApns[phoneId].remove(apnType)) {
1162 if (mConnectedApns[phoneId].isEmpty()) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001163 mDataConnectionState[phoneId] = state;
1164 modified = true;
1165 } else {
1166 // leave mDataConnectionState as is and
1167 // send out the new status for the APN in question.
Wink Savillebaf21da2014-11-19 16:03:09 -08001168 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001169 }
1170 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001171 mDataConnectionLinkProperties[phoneId] = linkProperties;
1172 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
1173 if (mDataConnectionNetworkType[phoneId] != networkType) {
1174 mDataConnectionNetworkType[phoneId] = networkType;
1175 // need to tell registered listeners about the new network type
1176 modified = true;
1177 }
1178 if (modified) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001179 String str = "onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
1180 + ", " + mDataConnectionNetworkType[phoneId] + ")";
1181 log(str);
1182 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001183 for (Record r : mRecords) {
1184 if (r.matchPhoneStateListenerEvent(
1185 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1186 idMatch(r.subId, subId, phoneId)) {
1187 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001188 if (DBG) {
1189 log("Notify data connection state changed on sub: " + subId);
1190 }
1191 r.callback.onDataConnectionStateChanged(
1192 mDataConnectionState[phoneId],
Wink Savilled09c4ca2014-11-22 10:08:16 -08001193 mDataConnectionNetworkType[phoneId]);
1194 } catch (RemoteException ex) {
1195 mRemoveList.add(r.binder);
1196 }
1197 }
1198 }
1199 handleRemoveListLocked();
1200 }
1201 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1202 apnType, apn, reason, linkProperties, "");
1203 for (Record r : mRecords) {
1204 if (r.matchPhoneStateListenerEvent(
1205 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1206 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001207 r.callback.onPreciseDataConnectionStateChanged(
1208 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001209 } catch (RemoteException ex) {
1210 mRemoveList.add(r.binder);
1211 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001212 }
1213 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001214 }
1215 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001216 }
Jack Yubaeec622017-05-01 17:01:11 -07001217 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001218 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001219 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1220 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 }
1222
Robert Greenwalt02648a42010-05-18 10:52:51 -07001223 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001224 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001225 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001226 }
1227
Wink Saville63f03dd2014-10-23 10:44:45 -07001228 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001229 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001230 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001231 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001232 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001233 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001234 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001235 + " reason=" + reason + " apnType=" + apnType);
1236 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001238 mPreciseDataConnectionState = new PreciseDataConnectionState(
1239 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1240 apnType, "", reason, null, "");
1241 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001242 if (r.matchPhoneStateListenerEvent(
1243 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001244 try {
1245 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1246 } catch (RemoteException ex) {
1247 mRemoveList.add(r.binder);
1248 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 }
1250 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001251 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001253 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001254 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1255 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 }
1257
1258 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001259 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001260 }
1261
Wink Saville63f03dd2014-10-23 10:44:45 -07001262 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001263 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001264 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001265 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001266 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001267 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001268 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001269 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001270 + " cellLocation=" + cellLocation);
1271 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001273 int phoneId = SubscriptionManager.getPhoneId(subId);
1274 if (validatePhoneId(phoneId)) {
1275 mCellLocation[phoneId] = cellLocation;
1276 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001277 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001278 idMatch(r.subId, subId, phoneId) &&
1279 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001280 try {
1281 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001282 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001283 + " r=" + r);
1284 }
1285 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1286 } catch (RemoteException ex) {
1287 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001288 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001289 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001290 }
1291 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001292 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001293 }
1294 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001295
Wink Savillefd2d0132010-10-28 14:22:26 -07001296 public void notifyOtaspChanged(int otaspMode) {
1297 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1298 return;
1299 }
1300 synchronized (mRecords) {
1301 mOtaspMode = otaspMode;
1302 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001303 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001304 try {
1305 r.callback.onOtaspChanged(otaspMode);
1306 } catch (RemoteException ex) {
1307 mRemoveList.add(r.binder);
1308 }
1309 }
1310 }
1311 handleRemoveListLocked();
1312 }
1313 }
1314
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001315 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1316 int backgroundCallState) {
1317 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1318 return;
1319 }
1320 synchronized (mRecords) {
1321 mRingingCallState = ringingCallState;
1322 mForegroundCallState = foregroundCallState;
1323 mBackgroundCallState = backgroundCallState;
1324 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1325 backgroundCallState,
1326 DisconnectCause.NOT_VALID,
1327 PreciseDisconnectCause.NOT_VALID);
1328 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001329 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001330 try {
1331 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1332 } catch (RemoteException ex) {
1333 mRemoveList.add(r.binder);
1334 }
1335 }
1336 }
1337 handleRemoveListLocked();
1338 }
1339 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1340 DisconnectCause.NOT_VALID,
1341 PreciseDisconnectCause.NOT_VALID);
1342 }
1343
1344 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1345 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1346 return;
1347 }
1348 synchronized (mRecords) {
1349 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1350 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1351 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001352 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001353 try {
1354 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1355 } catch (RemoteException ex) {
1356 mRemoveList.add(r.binder);
1357 }
1358 }
1359 }
1360 handleRemoveListLocked();
1361 }
1362 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1363 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1364 }
1365
1366 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1367 String apn, String failCause) {
1368 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1369 return;
1370 }
1371 synchronized (mRecords) {
1372 mPreciseDataConnectionState = new PreciseDataConnectionState(
1373 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1374 apnType, apn, reason, null, failCause);
1375 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001376 if (r.matchPhoneStateListenerEvent(
1377 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001378 try {
1379 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1380 } catch (RemoteException ex) {
1381 mRemoveList.add(r.binder);
1382 }
1383 }
1384 }
1385 handleRemoveListLocked();
1386 }
1387 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1388 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1389 }
1390
Wink Savillefb40dd42014-06-12 17:02:31 -07001391 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1392 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1393 return;
1394 }
1395 synchronized (mRecords) {
1396 mVoLteServiceState = lteState;
1397 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001398 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001399 try {
1400 r.callback.onVoLteServiceStateChanged(
1401 new VoLteServiceState(mVoLteServiceState));
1402 } catch (RemoteException ex) {
1403 mRemoveList.add(r.binder);
1404 }
1405 }
1406 }
1407 handleRemoveListLocked();
1408 }
1409 }
1410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001411 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001412 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1413 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1414
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001415 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001417 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001418 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001419 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001420 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301421 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001422 pw.println("Phone Id=" + i);
1423 pw.increaseIndent();
1424 pw.println("mCallState=" + mCallState[i]);
1425 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1426 pw.println("mServiceState=" + mServiceState[i]);
1427 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1428 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001429 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001430 pw.println("mSignalStrength=" + mSignalStrength[i]);
1431 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1432 pw.println("mCallForwarding=" + mCallForwarding[i]);
1433 pw.println("mDataActivity=" + mDataActivity[i]);
1434 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001435 pw.println("mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1436 pw.println("mDataConnectionNetworkCapabilities=" +
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301437 mDataConnectionNetworkCapabilities[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001438 pw.println("mCellLocation=" + mCellLocation[i]);
1439 pw.println("mCellInfo=" + mCellInfo.get(i));
1440 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301441 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001442 pw.println("mConnectedApns=" + Arrays.toString(mConnectedApns));
1443 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1444 pw.println("mPreciseCallState=" + mPreciseCallState);
1445 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1446 pw.println("mRingingCallState=" + mRingingCallState);
1447 pw.println("mForegroundCallState=" + mForegroundCallState);
1448 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1449 pw.println("mVoLteServiceState=" + mVoLteServiceState);
1450
1451 pw.decreaseIndent();
1452
1453 pw.println("local logs:");
1454 pw.increaseIndent();
1455 mLocalLog.dump(fd, pw, args);
1456 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001457 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001458 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001459 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001460 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001462 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 }
1464 }
1465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001466 //
1467 // the legacy intent broadcasting
1468 //
1469
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001470 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001471 long ident = Binder.clearCallingIdentity();
1472 try {
1473 mBatteryStats.notePhoneState(state.getState());
1474 } catch (RemoteException re) {
1475 // Can't do much
1476 } finally {
1477 Binder.restoreCallingIdentity(ident);
1478 }
1479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001481 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001482 Bundle data = new Bundle();
1483 state.fillInNotifierBundle(data);
1484 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001485 // Pass the subscription along with the intent.
1486 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001487 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001488 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001489 }
1490
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001491 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1492 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001493 long ident = Binder.clearCallingIdentity();
1494 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001495 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001496 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001497 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001498 } finally {
1499 Binder.restoreCallingIdentity(ident);
1500 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001502 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001503 Bundle data = new Bundle();
1504 signalStrength.fillInNotifierBundle(data);
1505 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001506 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001507 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001508 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 }
1510
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001511 /**
1512 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1513 * a valid subId, in which case this function fires a subId-specific intent, or it
1514 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1515 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1516 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001517 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1518 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001519 long ident = Binder.clearCallingIdentity();
1520 try {
1521 if (state == TelephonyManager.CALL_STATE_IDLE) {
1522 mBatteryStats.notePhoneOff();
1523 } else {
1524 mBatteryStats.notePhoneOn();
1525 }
1526 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001527 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 } finally {
1529 Binder.restoreCallingIdentity(ident);
1530 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001533 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001534 PhoneConstantConversions.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535 if (!TextUtils.isEmpty(incomingNumber)) {
1536 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1537 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001538
1539 // If a valid subId was specified, we should fire off a subId-specific state
1540 // change intent and include the subId.
1541 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1542 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1543 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1544 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001545 // If the phoneId is invalid, the broadcast is for overall call state.
1546 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1547 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1548 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001549
Brad Ebinger51de96a2017-04-21 17:05:18 -07001550 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1551 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1552
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001553 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1554 // that have the runtime one
1555 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1556 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001557 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001558 android.Manifest.permission.READ_PHONE_STATE,
1559 AppOpsManager.OP_READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560 }
1561
Robert Greenwalt42acef32009-08-12 16:08:25 -07001562 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001563 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001564 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001565 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001566 // Note: not reporting to the battery stats service here, because the
1567 // status bar takes care of that after taking into account all of the
1568 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001570 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001571 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001572 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001573 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 }
1575 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001576 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001577 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001578 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001579 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001580 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001581 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001582 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001583 }
1584 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001585 if (networkCapabilities != null) {
1586 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001587 }
Wink Savillea639b312012-07-10 12:37:54 -07001588 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001589
Wink Savillea639b312012-07-10 12:37:54 -07001590 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1591 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001592 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001593 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001594 }
1595
Wink Savillefb40dd42014-06-12 17:02:31 -07001596 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001597 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001598 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001599 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1600 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001601 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001602 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001604
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001605 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1606 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1607 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1608 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1609 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1610 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1611 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1612 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1613 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1614 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1615 }
1616
1617 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001618 String apnType, String apn, String reason, LinkProperties linkProperties,
1619 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001620 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1621 intent.putExtra(PhoneConstants.STATE_KEY, state);
1622 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1623 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1624 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1625 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001626 if (linkProperties != null) {
1627 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1628 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001629 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1630
1631 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1632 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1633 }
1634
Andrew Flynnceaed682015-06-09 12:36:58 +00001635 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
1636 if (checkNotifyPermission()) {
1637 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001638 }
1639
Andrew Flynnceaed682015-06-09 12:36:58 +00001640 enforceCarrierPrivilege();
Andrew Flynn1f452642015-04-14 22:16:04 -04001641 }
1642
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001643 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001644 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001645 return true;
1646 }
1647 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001648 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001649 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001650 return false;
1651 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001652
Andrew Flynn1f452642015-04-14 22:16:04 -04001653 private boolean checkNotifyPermission() {
1654 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1655 == PackageManager.PERMISSION_GRANTED;
1656 }
1657
Andrew Flynnceaed682015-06-09 12:36:58 +00001658 private void enforceCarrierPrivilege() {
Andrew Flynn1f452642015-04-14 22:16:04 -04001659 TelephonyManager tm = TelephonyManager.getDefault();
1660 String[] pkgs = mContext.getPackageManager().getPackagesForUid(Binder.getCallingUid());
1661 for (String pkg : pkgs) {
1662 if (tm.checkCarrierPrivilegesForPackage(pkg) ==
1663 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001664 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001665 }
1666 }
1667
Andrew Flynnceaed682015-06-09 12:36:58 +00001668 String msg = "Carrier Privilege Permission Denial: from pid=" + Binder.getCallingPid()
1669 + ", uid=" + Binder.getCallingUid();
1670 if (DBG) log(msg);
1671 throw new SecurityException(msg);
Andrew Flynn1f452642015-04-14 22:16:04 -04001672 }
1673
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001674 private void checkListenerPermission(int events) {
1675 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1676 mContext.enforceCallingOrSelfPermission(
1677 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1678
1679 }
1680
John Wang963db55d2012-03-30 16:04:06 -07001681 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1682 mContext.enforceCallingOrSelfPermission(
1683 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1684
1685 }
1686
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001687 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001688 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -07001689 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001690 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -07001691 // SKIP checking for run-time permission since caller or self has PRIVILEGED
1692 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001693 } catch (SecurityException e) {
1694 mContext.enforceCallingOrSelfPermission(
1695 android.Manifest.permission.READ_PHONE_STATE, null);
1696 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001697 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001698
1699 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1700 mContext.enforceCallingOrSelfPermission(
1701 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1702
1703 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001704 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001705
1706 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001707 int size = mRemoveList.size();
1708 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1709 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001710 for (IBinder b: mRemoveList) {
1711 remove(b);
1712 }
1713 mRemoveList.clear();
1714 }
1715 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001716
1717 private boolean validateEventsAndUserLocked(Record r, int events) {
1718 int foregroundUser;
1719 long callingIdentity = Binder.clearCallingIdentity();
1720 boolean valid = false;
1721 try {
1722 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08001723 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
1724 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001725 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001726 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08001727 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001728 + " r.events=" + r.events + " events=" + events);
1729 }
1730 } finally {
1731 Binder.restoreCallingIdentity(callingIdentity);
1732 }
1733 return valid;
1734 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001735
1736 private boolean validatePhoneId(int phoneId) {
1737 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001738 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001739 return valid;
1740 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001741
1742 private static void log(String s) {
1743 Rlog.d(TAG, s);
1744 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001745
xinhe8b79fb62014-11-05 14:55:03 -08001746 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001747
1748 if(subId < 0) {
1749 // Invalid case, we need compare phoneId with default one.
1750 return (mDefaultPhoneId == phoneId);
1751 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001752 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001753 return (subId == mDefaultSubId);
1754 } else {
1755 return (rSubId == subId);
1756 }
1757 }
1758
Hall Liu5fb337f2017-11-22 17:38:15 -08001759 private boolean checkLocationAccess(Record r) {
1760 long token = Binder.clearCallingIdentity();
1761 try {
1762 return LocationAccessPolicy.canAccessCellLocation(mContext,
1763 r.callingPackage, r.callerUid, r.callerPid);
1764 } finally {
1765 Binder.restoreCallingIdentity(token);
1766 }
1767 }
1768
xinhee9f16402014-09-25 16:39:28 -07001769 private void checkPossibleMissNotify(Record r, int phoneId) {
1770 int events = r.events;
1771
1772 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1773 try {
1774 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1775 mServiceState[phoneId]);
1776 r.callback.onServiceStateChanged(
1777 new ServiceState(mServiceState[phoneId]));
1778 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001779 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001780 }
1781 }
1782
1783 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1784 try {
1785 SignalStrength signalStrength = mSignalStrength[phoneId];
1786 if (DBG) {
1787 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1788 }
1789 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1790 } catch (RemoteException ex) {
1791 mRemoveList.add(r.binder);
1792 }
1793 }
1794
1795 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1796 try {
1797 int gsmSignalStrength = mSignalStrength[phoneId]
1798 .getGsmSignalStrength();
1799 if (DBG) {
1800 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1801 gsmSignalStrength);
1802 }
1803 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1804 : gsmSignalStrength));
1805 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001806 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001807 }
1808 }
1809
1810 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1811 try {
1812 if (DBG_LOC) {
1813 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1814 + mCellInfo.get(phoneId));
1815 }
Hall Liu5fb337f2017-11-22 17:38:15 -08001816 if (checkLocationAccess(r)) {
1817 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1818 }
xinhee9f16402014-09-25 16:39:28 -07001819 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001820 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001821 }
1822 }
1823
zxuan35a47022018-01-04 11:24:04 -08001824 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
1825 try {
1826 if (VDBG) {
1827 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
1828 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
1829 }
1830 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
1831 } catch (RemoteException ex) {
1832 mRemoveList.add(r.binder);
1833 }
1834 }
1835
xinhee9f16402014-09-25 16:39:28 -07001836 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1837 try {
1838 if (VDBG) {
1839 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1840 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1841 }
1842 r.callback.onMessageWaitingIndicatorChanged(
1843 mMessageWaiting[phoneId]);
1844 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001845 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001846 }
1847 }
1848
1849 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1850 try {
1851 if (VDBG) {
1852 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1853 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1854 }
1855 r.callback.onCallForwardingIndicatorChanged(
1856 mCallForwarding[phoneId]);
1857 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001858 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001859 }
1860 }
1861
1862 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1863 try {
1864 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1865 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -08001866 if (checkLocationAccess(r)) {
1867 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1868 }
xinhee9f16402014-09-25 16:39:28 -07001869 } catch (RemoteException ex) {
1870 mRemoveList.add(r.binder);
1871 }
1872 }
1873
1874 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1875 try {
1876 if (DBG) {
1877 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1878 + "=" + mDataConnectionState[phoneId]
1879 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1880 + ")");
1881 }
1882 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1883 mDataConnectionNetworkType[phoneId]);
1884 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001885 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001886 }
1887 }
1888 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001889}