blob: 566ce4f48e2564392ec7b01d4e807a582f42569d [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;
Malcolm Chene1623652018-08-08 20:27:45 -070039import android.telephony.PhoneCapability;
Jack Yud19b6ae2017-04-05 14:12:09 -070040import android.telephony.PhoneStateListener;
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -080041import android.telephony.PhysicalChannelConfig;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020042import android.telephony.PreciseCallState;
43import android.telephony.PreciseDataConnectionState;
44import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070045import android.telephony.Rlog;
46import android.telephony.ServiceState;
47import android.telephony.SignalStrength;
48import android.telephony.SubscriptionManager;
49import android.telephony.TelephonyManager;
50import android.telephony.VoLteServiceState;
Jack Yud19b6ae2017-04-05 14:12:09 -070051import android.util.LocalLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052
53import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080054import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070056import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080057import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070058import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080060import com.android.internal.telephony.TelephonyPermissions;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060061import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070062import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import com.android.server.am.BatteryStatsService;
64
Jack Yud19b6ae2017-04-05 14:12:09 -070065import java.io.FileDescriptor;
66import java.io.PrintWriter;
67import java.util.ArrayList;
Jack Yud19b6ae2017-04-05 14:12:09 -070068import java.util.List;
Malcolm Chenabbfac22018-02-12 19:15:59 -080069import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071/**
Wink Savillee9b06d72009-05-18 21:47:50 -070072 * Since phone process can be restarted, this class provides a centralized place
73 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070074 *
75 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
76 * and 15973975 by saving the phoneId of the registrant and then using the
77 * phoneId when deciding to to make a callback. This is necessary because
78 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070079 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070080 * the dummy value conversion we properly do the callbacks.
81 *
82 * Eventually we may want to remove the notion of dummy value but for now this
83 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 */
85class TelephonyRegistry extends ITelephonyRegistry.Stub {
86 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070087 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070088 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070089 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090
91 private static class Record {
Jeff Davidson29da89f2018-02-28 17:50:16 -080092 Context context;
93
Svet Ganov16a16892015-04-16 10:32:04 -070094 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070097
Malcolm Chenabbfac22018-02-12 19:15:59 -080098 TelephonyRegistryDeathRecipient deathRecipient;
99
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800101 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700102
Hall Liu5fb337f2017-11-22 17:38:15 -0800103 int callerUid;
104 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700107
Wink Savilled09c4ca2014-11-22 10:08:16 -0800108 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700109
Wink Savilled09c4ca2014-11-22 10:08:16 -0800110 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800111
112 boolean matchPhoneStateListenerEvent(int events) {
113 return (callback != null) && ((events & this.events) != 0);
114 }
115
Wink Savilled09c4ca2014-11-22 10:08:16 -0800116 boolean matchOnSubscriptionsChangedListener() {
117 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800118 }
Wink Savillee380b982014-07-26 18:24:22 -0700119
Tyler Gunnf955e562018-04-26 14:43:31 -0700120 boolean canReadCallLog() {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800121 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700122 return TelephonyPermissions.checkReadCallLog(
123 context, subId, callerPid, callerUid, callingPackage);
Jeff Davidson29da89f2018-02-28 17:50:16 -0800124 } catch (SecurityException e) {
125 return false;
126 }
127 }
128
Wink Savillea12a7b32012-09-20 10:09:45 -0700129 @Override
130 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700131 return "{callingPackage=" + callingPackage + " binder=" + binder
132 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800133 + " onSubscriptionsChangedListenererCallback="
134 + onSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800135 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800136 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700137 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 }
139
140 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700141
Joe Onorato163d8d92010-10-21 13:21:20 -0400142 // access should be inside synchronized (mRecords) for these two fields
143 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
144 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 private final IBatteryStats mBatteryStats;
147
Svet Ganov16a16892015-04-16 10:32:04 -0700148 private final AppOpsManager mAppOps;
149
Wink Savilled09c4ca2014-11-22 10:08:16 -0800150 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
151
Wink Savillefb40dd42014-06-12 17:02:31 -0700152 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700153
Wink Savillefb40dd42014-06-12 17:02:31 -0700154 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700155
Wink Savillefb40dd42014-06-12 17:02:31 -0700156 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700157
Wink Savillefb40dd42014-06-12 17:02:31 -0700158 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700159
fionaxu12312f62016-11-14 13:32:14 -0800160 private int[] mVoiceActivationState;
161
162 private int[] mDataActivationState;
163
zxuan35a47022018-01-04 11:24:04 -0800164 private boolean[] mUserMobileDataState;
165
Wink Savillefb40dd42014-06-12 17:02:31 -0700166 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700167
Wink Savillefb40dd42014-06-12 17:02:31 -0700168 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700169
Wink Savillefb40dd42014-06-12 17:02:31 -0700170 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700171
Wink Savillefb40dd42014-06-12 17:02:31 -0700172 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700173
Jack Yub1bac542018-03-14 16:23:38 -0700174 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700175 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700176
Wink Savillefb40dd42014-06-12 17:02:31 -0700177 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178
Wink Savillefb40dd42014-06-12 17:02:31 -0700179 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700180
Nathan Harold016e9c62016-12-14 11:24:48 -0800181 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700182
Wink Savillefb40dd42014-06-12 17:02:31 -0700183 private ArrayList<List<CellInfo>> mCellInfo = null;
184
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800185 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
186
Wink Savillefb40dd42014-06-12 17:02:31 -0700187 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
188
Wink Savilled09c4ca2014-11-22 10:08:16 -0800189 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700190
Wink Savilled09c4ca2014-11-22 10:08:16 -0800191 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700192
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200193 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
194
195 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
196
197 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
198
199 private PreciseCallState mPreciseCallState = new PreciseCallState();
200
Andrew Flynn1f452642015-04-14 22:16:04 -0400201 private boolean mCarrierNetworkChangeState = false;
202
Malcolm Chene1623652018-08-08 20:27:45 -0700203 private PhoneCapability mPhoneCapability = null;
204
Jack Yud19b6ae2017-04-05 14:12:09 -0700205 private final LocalLog mLocalLog = new LocalLog(100);
206
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200207 private PreciseDataConnectionState mPreciseDataConnectionState =
208 new PreciseDataConnectionState();
209
Hall Liu70bbc162018-03-02 17:44:46 -0800210 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK =
211 PhoneStateListener.LISTEN_CELL_LOCATION
212 | PhoneStateListener.LISTEN_CELL_INFO;
213
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700214 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700215 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700216 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
217 PhoneStateListener.LISTEN_VOLTE_STATE;
218
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200219 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
220 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
221 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
222
Wink Savillea12a7b32012-09-20 10:09:45 -0700223 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700224 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700225
226 private final Handler mHandler = new Handler() {
227 @Override
228 public void handleMessage(Message msg) {
229 switch (msg.what) {
230 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700231 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700232 int numPhones = TelephonyManager.getDefault().getPhoneCount();
233 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700234 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700235 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700236 }
237 break;
238 }
xinhee9f16402014-09-25 16:39:28 -0700239 case MSG_UPDATE_DEFAULT_SUB: {
240 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700241 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700242 if (VDBG) {
243 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
244 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
245 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
246 }
247
248 //Due to possible risk condition,(notify call back using the new
249 //defaultSubId comes before new defaultSubId update) we need to recall all
250 //possible missed notify callback
251 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700252 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800253 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700254 checkPossibleMissNotify(r, newDefaultPhoneId);
255 }
256 }
257 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700258 }
259 mDefaultSubId = newDefaultSubId;
260 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700261 }
262 }
263 }
264 };
265
Malcolm Chenabbfac22018-02-12 19:15:59 -0800266 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
267
268 private final IBinder binder;
269
270 TelephonyRegistryDeathRecipient(IBinder binder) {
271 this.binder = binder;
272 }
273
274 @Override
275 public void binderDied() {
276 if (DBG) log("binderDied " + binder);
277 remove(binder);
278 }
279 }
280
Wink Savillea12a7b32012-09-20 10:09:45 -0700281 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
282 @Override
283 public void onReceive(Context context, Intent intent) {
284 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700285 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700286 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700287 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700288 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700289 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700290 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700291 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800292 PhoneConstants.SUBSCRIPTION_KEY,
293 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700294 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
295 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700296 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700297 log("onReceive:current mDefaultSubId=" + mDefaultSubId
298 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
299 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700300 }
xinhee9f16402014-09-25 16:39:28 -0700301
Junda Liu985f52c2015-02-23 16:06:51 -0800302 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700303 || (newDefaultPhoneId != mDefaultPhoneId))) {
304 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
305 newDefaultPhoneId, 0, newDefaultSubIdObj));
306 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700307 }
308 }
309 };
310
Wink Savillee9b06d72009-05-18 21:47:50 -0700311 // we keep a copy of all of the state so we can send it out when folks
312 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700314 // In these calls we call with the lock held. This is safe becasuse remote
315 // calls go through a oneway interface and local calls going through a
316 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317
318 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700319 CellLocation location = CellLocation.getEmpty();
320
Wink Savillefb40dd42014-06-12 17:02:31 -0700321 mContext = context;
322 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700323
Wink Savillefb40dd42014-06-12 17:02:31 -0700324 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700325 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700326 mNumPhones = numPhones;
327 mCallState = new int[numPhones];
328 mDataActivity = new int[numPhones];
329 mDataConnectionState = new int[numPhones];
330 mDataConnectionNetworkType = new int[numPhones];
331 mCallIncomingNumber = new String[numPhones];
332 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800333 mVoiceActivationState = new int[numPhones];
334 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800335 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700336 mSignalStrength = new SignalStrength[numPhones];
337 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700338 mCallForwarding = new boolean[numPhones];
339 mCellLocation = new Bundle[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700340 mCellInfo = new ArrayList<List<CellInfo>>();
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800341 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700342 for (int i = 0; i < numPhones; i++) {
343 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
344 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
345 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800346 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
347 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700348 mCallIncomingNumber[i] = "";
349 mServiceState[i] = new ServiceState();
350 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800351 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700352 mMessageWaiting[i] = false;
353 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700354 mCellLocation[i] = new Bundle();
355 mCellInfo.add(i, null);
Nathan Haroldc9bad6e2018-04-25 12:53:04 -0700356 mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>());
Wink Savillefb40dd42014-06-12 17:02:31 -0700357 }
358
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700359 // Note that location can be null for non-phone builds like
360 // like the generic one.
361 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700362 for (int i = 0; i < numPhones; i++) {
363 location.fillInNotifierBundle(mCellLocation[i]);
364 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700365 }
Svet Ganov16a16892015-04-16 10:32:04 -0700366
367 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 }
369
Svetoslav Ganova0027152013-06-25 14:59:53 -0700370 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700371 // Watch for interesting updates
372 final IntentFilter filter = new IntentFilter();
373 filter.addAction(Intent.ACTION_USER_SWITCHED);
374 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700375 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700376 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700377 mContext.registerReceiver(mBroadcastReceiver, filter);
378 }
379
380 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700381 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800382 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700383 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800384 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800385 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700386 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
387 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800388 + " callback.asBinder=" + callback.asBinder());
389 }
390
Wink Savilled09c4ca2014-11-22 10:08:16 -0800391 synchronized (mRecords) {
392 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800393 IBinder b = callback.asBinder();
394 Record r = add(b);
395
396 if (r == null) {
397 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800398 }
399
Jeff Davidson29da89f2018-02-28 17:50:16 -0800400 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800401 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700402 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800403 r.callerUid = Binder.getCallingUid();
404 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800405 r.events = 0;
406 if (DBG) {
407 log("listen oscl: Register r=" + r);
408 }
409 // Always notify when registration occurs if there has been a notification.
410 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800411 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800412 if (VDBG) log("listen oscl: send to r=" + r);
413 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
414 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800415 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800416 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800417 remove(r.binder);
418 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800419 } else {
420 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800421 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800422 }
423 }
424
425 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800426 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800427 IOnSubscriptionsChangedListener callback) {
428 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800429 remove(callback.asBinder());
430 }
431
Wink Savillea374c3d2014-11-11 11:48:04 -0800432 @Override
433 public void notifySubscriptionInfoChanged() {
434 if (VDBG) log("notifySubscriptionInfoChanged:");
435 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800436 if (!hasNotifySubscriptionInfoChangedOccurred) {
437 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
438 + mRecords.size());
439 }
440 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800441 mRemoveList.clear();
442 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800443 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800444 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800445 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
446 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
447 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800448 } catch (RemoteException ex) {
449 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
450 mRemoveList.add(r.binder);
451 }
452 }
453 }
454 handleRemoveListLocked();
455 }
456 }
457
458 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
460 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800461 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
462 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700463 }
464
465 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700466 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700467 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700468 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700469 }
470
Svet Ganov16a16892015-04-16 10:32:04 -0700471 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700472 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700473 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800474 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700475 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700476 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700477 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
478 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700479 }
xinhe75c2c152014-10-16 11:49:45 -0700480
481 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800482 // Checks permission and throws SecurityException for disallowed operations. For pre-M
483 // apps whose runtime permission has been revoked, we return immediately to skip sending
484 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800485 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800486 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700487 }
488
yifan.baie620ce72017-12-22 14:59:57 +0800489 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 synchronized (mRecords) {
491 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800492 IBinder b = callback.asBinder();
493 Record r = add(b);
494
495 if (r == null) {
496 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 }
xinhe43c50292014-09-18 17:56:48 -0700498
Jeff Davidson29da89f2018-02-28 17:50:16 -0800499 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700500 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700501 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800502 r.callerUid = Binder.getCallingUid();
503 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700504 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
505 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800506 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800507 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700508 } else {//APP specify subID
509 r.subId = subId;
510 }
yifan.baie620ce72017-12-22 14:59:57 +0800511 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700513 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700514 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700515 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700516 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400518 try {
Wink Savillee380b982014-07-26 18:24:22 -0700519 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700520 r.callback.onServiceStateChanged(
521 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400522 } catch (RemoteException ex) {
523 remove(r.binder);
524 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 }
526 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
527 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700528 int gsmSignalStrength = mSignalStrength[phoneId]
529 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700530 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
531 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 } catch (RemoteException ex) {
533 remove(r.binder);
534 }
535 }
536 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
537 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700538 r.callback.onMessageWaitingIndicatorChanged(
539 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 } catch (RemoteException ex) {
541 remove(r.binder);
542 }
543 }
544 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
545 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700546 r.callback.onCallForwardingIndicatorChanged(
547 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 } catch (RemoteException ex) {
549 remove(r.binder);
550 }
551 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700552 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400553 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700554 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700555 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -0800556 if (checkLocationAccess(r)) {
557 r.callback.onCellLocationChanged(
558 new Bundle(mCellLocation[phoneId]));
559 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400560 } catch (RemoteException ex) {
561 remove(r.binder);
562 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 }
564 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
565 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700566 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700567 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 } catch (RemoteException ex) {
569 remove(r.binder);
570 }
571 }
572 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
573 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700574 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
575 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 } catch (RemoteException ex) {
577 remove(r.binder);
578 }
579 }
580 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
581 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700582 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 } catch (RemoteException ex) {
584 remove(r.binder);
585 }
586 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700587 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
588 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700589 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700590 } catch (RemoteException ex) {
591 remove(r.binder);
592 }
593 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700594 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
595 try {
596 r.callback.onOtaspChanged(mOtaspMode);
597 } catch (RemoteException ex) {
598 remove(r.binder);
599 }
600 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700601 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700602 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700603 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700604 + mCellInfo.get(phoneId));
Hall Liu5fb337f2017-11-22 17:38:15 -0800605 if (checkLocationAccess(r)) {
606 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
607 }
John Wang963db55d2012-03-30 16:04:06 -0700608 } catch (RemoteException ex) {
609 remove(r.binder);
610 }
611 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200612 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
613 try {
614 r.callback.onPreciseCallStateChanged(mPreciseCallState);
615 } catch (RemoteException ex) {
616 remove(r.binder);
617 }
618 }
619 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
620 try {
621 r.callback.onPreciseDataConnectionStateChanged(
622 mPreciseDataConnectionState);
623 } catch (RemoteException ex) {
624 remove(r.binder);
625 }
626 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400627 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
628 try {
629 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
630 } catch (RemoteException ex) {
631 remove(r.binder);
632 }
633 }
fionaxu12312f62016-11-14 13:32:14 -0800634 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
635 try {
636 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
637 } catch (RemoteException ex) {
638 remove(r.binder);
639 }
640 }
641 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
642 try {
643 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
644 } catch (RemoteException ex) {
645 remove(r.binder);
646 }
647 }
zxuan35a47022018-01-04 11:24:04 -0800648 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
649 try {
650 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
651 } catch (RemoteException ex) {
652 remove(r.binder);
653 }
654 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800655 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
656 try {
657 r.callback.onPhysicalChannelConfigurationChanged(
658 mPhysicalChannelConfigs.get(phoneId));
659 } catch (RemoteException ex) {
660 remove(r.binder);
661 }
662 }
Malcolm Chene1623652018-08-08 20:27:45 -0700663 if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
664 try {
665 r.callback.onPhoneCapabilityChanged(mPhoneCapability);
666 } catch (RemoteException ex) {
667 remove(r.binder);
668 }
669 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 }
671 }
672 } else {
xinhe75c2c152014-10-16 11:49:45 -0700673 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 remove(callback.asBinder());
675 }
676 }
677
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700678 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700679 // Only reveal the incoming number if the record has read call log permission.
680 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700681 }
682
Malcolm Chenabbfac22018-02-12 19:15:59 -0800683 private Record add(IBinder binder) {
684 Record r;
685
686 synchronized (mRecords) {
687 final int N = mRecords.size();
688 for (int i = 0; i < N; i++) {
689 r = mRecords.get(i);
690 if (binder == r.binder) {
691 // Already existed.
692 return r;
693 }
694 }
695 r = new Record();
696 r.binder = binder;
697 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
698
699 try {
700 binder.linkToDeath(r.deathRecipient, 0);
701 } catch (RemoteException e) {
702 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
703 // Binder already died. Return null.
704 return null;
705 }
706
707 mRecords.add(r);
708 if (DBG) log("add new record");
709 }
710
711 return r;
712 }
713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714 private void remove(IBinder binder) {
715 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700716 final int recordCount = mRecords.size();
717 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800718 Record r = mRecords.get(i);
719 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800720 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800721 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
722 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800723 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800724
725 if (r.deathRecipient != null) {
726 try {
727 binder.unlinkToDeath(r.deathRecipient, 0);
728 } catch (NoSuchElementException e) {
729 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
730 + r + " e=" + e);
731 }
732 }
733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800734 mRecords.remove(i);
735 return;
736 }
737 }
738 }
739 }
740
Tyler Gunnf955e562018-04-26 14:43:31 -0700741 public void notifyCallState(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700742 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700743 return;
744 }
xinhe43c50292014-09-18 17:56:48 -0700745
746 if (VDBG) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700747 log("notifyCallState: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -0700748 }
749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700751 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800752 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800753 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700755 // Ensure the listener has read call log permission; if they do not return
756 // an empty phone number.
757 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
758 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400760 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 }
762 }
763 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400764 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700766
767 // Called only by Telecomm to communicate call state across different phone accounts. So
768 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -0700769 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700770 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700771 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 }
773
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700774 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
775 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700776 if (!checkNotifyPermission("notifyCallState()")) {
777 return;
778 }
Wink Savillee380b982014-07-26 18:24:22 -0700779 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700780 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700781 + " state=" + state + " incomingNumber=" + incomingNumber);
782 }
783 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700784 if (validatePhoneId(phoneId)) {
785 mCallState[phoneId] = state;
786 mCallIncomingNumber[phoneId] = incomingNumber;
787 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800788 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700789 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800790 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700791 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700792 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
793 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700794 } catch (RemoteException ex) {
795 mRemoveList.add(r.binder);
796 }
797 }
798 }
799 }
800 handleRemoveListLocked();
801 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700802 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700803 }
804
Wink Saville63f03dd2014-10-23 10:44:45 -0700805 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700806 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700807 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700808 }
xinhe43c50292014-09-18 17:56:48 -0700809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800810 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700811 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
812 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700813 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700814 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700815 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700816 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700817 if (validatePhoneId(phoneId)) {
818 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700819
Wink Savillefb40dd42014-06-12 17:02:31 -0700820 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700821 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700822 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700823 + " phoneId=" + phoneId + " state=" + state);
824 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800825 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800826 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700827 try {
Wink Savillee380b982014-07-26 18:24:22 -0700828 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700829 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700830 + " subId=" + subId + " phoneId=" + phoneId
831 + " state=" + state);
832 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700833 r.callback.onServiceStateChanged(new ServiceState(state));
834 } catch (RemoteException ex) {
835 mRemoveList.add(r.binder);
836 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400837 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700839 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700840 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400842 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700844 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800845 }
846
fionaxu12312f62016-11-14 13:32:14 -0800847 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
848 int activationType, int activationState) {
849 if (!checkNotifyPermission("notifySimActivationState()")){
850 return;
851 }
852 if (VDBG) {
853 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
854 + "type=" + activationType + " state=" + activationState);
855 }
856 synchronized (mRecords) {
857 if (validatePhoneId(phoneId)) {
858 switch (activationType) {
859 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
860 mVoiceActivationState[phoneId] = activationState;
861 break;
862 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
863 mDataActivationState[phoneId] = activationState;
864 break;
865 default:
866 return;
867 }
868 for (Record r : mRecords) {
869 if (VDBG) {
870 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
871 + " phoneId=" + phoneId + "type=" + activationType
872 + " state=" + activationState);
873 }
874 try {
875 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
876 r.matchPhoneStateListenerEvent(
877 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
878 idMatch(r.subId, subId, phoneId)) {
879 if (DBG) {
880 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
881 + " subId=" + subId + " phoneId=" + phoneId
882 + " state=" + activationState);
883 }
884 r.callback.onVoiceActivationStateChanged(activationState);
885 }
886 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
887 r.matchPhoneStateListenerEvent(
888 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
889 idMatch(r.subId, subId, phoneId)) {
890 if (DBG) {
891 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
892 + " subId=" + subId + " phoneId=" + phoneId
893 + " state=" + activationState);
894 }
895 r.callback.onDataActivationStateChanged(activationState);
896 }
897 } catch (RemoteException ex) {
898 mRemoveList.add(r.binder);
899 }
900 }
901 } else {
902 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
903 }
904 handleRemoveListLocked();
905 }
906 }
907
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700908 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
909 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700910 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700911 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700912 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000913 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700914 log("notifySignalStrengthForPhoneId: subId=" + subId
915 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000916 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800918 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700919 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700920 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700921 mSignalStrength[phoneId] = signalStrength;
922 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000923 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700924 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000925 + " phoneId=" + phoneId + " ss=" + signalStrength);
926 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800927 if (r.matchPhoneStateListenerEvent(
928 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800929 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700930 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000931 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700932 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000933 + " subId=" + subId + " phoneId=" + phoneId
934 + " ss=" + signalStrength);
935 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700936 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
937 } catch (RemoteException ex) {
938 mRemoveList.add(r.binder);
939 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400940 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800941 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800942 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700943 try {
944 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700945 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000946 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700947 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000948 + " subId=" + subId + " phoneId=" + phoneId
949 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
950 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700951 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700952 } catch (RemoteException ex) {
953 mRemoveList.add(r.binder);
954 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 }
956 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700957 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700958 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400960 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700962 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 }
964
Andrew Flynn1f452642015-04-14 22:16:04 -0400965 @Override
966 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +0000967 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
968
Andrew Flynn1f452642015-04-14 22:16:04 -0400969 if (VDBG) {
970 log("notifyCarrierNetworkChange: active=" + active);
971 }
972
973 synchronized (mRecords) {
974 mCarrierNetworkChangeState = active;
975 for (Record r : mRecords) {
976 if (r.matchPhoneStateListenerEvent(
977 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
978 try {
979 r.callback.onCarrierNetworkChange(active);
980 } catch (RemoteException ex) {
981 mRemoveList.add(r.binder);
982 }
983 }
984 }
985 handleRemoveListLocked();
986 }
987 }
988
Wink Savilleb208a242012-07-25 14:08:09 -0700989 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800990 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700991 }
992
Wink Saville63f03dd2014-10-23 10:44:45 -0700993 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700994 if (!checkNotifyPermission("notifyCellInfo()")) {
995 return;
996 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700997 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700998 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700999 + " cellInfo=" + cellInfo);
1000 }
yifan.baie620ce72017-12-22 14:59:57 +08001001 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001002 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001003 if (validatePhoneId(phoneId)) {
1004 mCellInfo.set(phoneId, cellInfo);
1005 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001006 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001007 idMatch(r.subId, subId, phoneId) &&
1008 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001009 try {
1010 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001011 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001012 }
1013 r.callback.onCellInfoChanged(cellInfo);
1014 } catch (RemoteException ex) {
1015 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001016 }
John Wang963db55d2012-03-30 16:04:06 -07001017 }
1018 }
1019 }
1020 handleRemoveListLocked();
1021 }
1022 }
1023
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001024 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1025 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1026 configs);
1027 }
1028
1029 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1030 List<PhysicalChannelConfig> configs) {
1031 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1032 return;
1033 }
1034
1035 if (VDBG) {
1036 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1037 }
1038
1039 synchronized (mRecords) {
1040 int phoneId = SubscriptionManager.getPhoneId(subId);
1041 if (validatePhoneId(phoneId)) {
1042 mPhysicalChannelConfigs.set(phoneId, configs);
1043 for (Record r : mRecords) {
1044 if (r.matchPhoneStateListenerEvent(
1045 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1046 && idMatch(r.subId, subId, phoneId)) {
1047 try {
1048 if (DBG_LOC) {
1049 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1050 + configs + " r=" + r);
1051 }
1052 r.callback.onPhysicalChannelConfigurationChanged(configs);
1053 } catch (RemoteException ex) {
1054 mRemoveList.add(r.binder);
1055 }
1056 }
1057 }
1058 }
1059 handleRemoveListLocked();
1060 }
1061 }
1062
xinhe43c50292014-09-18 17:56:48 -07001063 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001064 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001065 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001066 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001067 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001068 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001069 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001070 + " mwi=" + mwi);
1071 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001073 if (validatePhoneId(phoneId)) {
1074 mMessageWaiting[phoneId] = mwi;
1075 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001076 if (r.matchPhoneStateListenerEvent(
1077 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001078 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001079 try {
1080 r.callback.onMessageWaitingIndicatorChanged(mwi);
1081 } catch (RemoteException ex) {
1082 mRemoveList.add(r.binder);
1083 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 }
1085 }
1086 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001087 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 }
1089 }
1090
zxuan35a47022018-01-04 11:24:04 -08001091 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1092 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1093 return;
1094 }
1095 if (VDBG) {
1096 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1097 + " state=" + state);
1098 }
1099 synchronized (mRecords) {
1100 if (validatePhoneId(phoneId)) {
1101 mMessageWaiting[phoneId] = state;
1102 for (Record r : mRecords) {
1103 if (r.matchPhoneStateListenerEvent(
1104 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1105 idMatch(r.subId, subId, phoneId)) {
1106 try {
1107 r.callback.onUserMobileDataStateChanged(state);
1108 } catch (RemoteException ex) {
1109 mRemoveList.add(r.binder);
1110 }
1111 }
1112 }
1113 }
1114 handleRemoveListLocked();
1115 }
1116 }
1117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001119 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001120 }
1121
Wink Saville63f03dd2014-10-23 10:44:45 -07001122 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001123 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001124 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001125 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001126 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001127 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001128 + " cfi=" + cfi);
1129 }
yifan.baie620ce72017-12-22 14:59:57 +08001130 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001132 if (validatePhoneId(phoneId)) {
1133 mCallForwarding[phoneId] = cfi;
1134 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001135 if (r.matchPhoneStateListenerEvent(
1136 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001137 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001138 try {
1139 r.callback.onCallForwardingIndicatorChanged(cfi);
1140 } catch (RemoteException ex) {
1141 mRemoveList.add(r.binder);
1142 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 }
1144 }
1145 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001146 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 }
1148 }
1149
1150 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001151 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001152 }
1153
Wink Saville63f03dd2014-10-23 10:44:45 -07001154 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001155 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001156 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001157 }
yifan.baie620ce72017-12-22 14:59:57 +08001158 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001160 if (validatePhoneId(phoneId)) {
1161 mDataActivity[phoneId] = state;
1162 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001163 // Notify by correct subId.
1164 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1165 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001166 try {
1167 r.callback.onDataActivity(state);
1168 } catch (RemoteException ex) {
1169 mRemoveList.add(r.binder);
1170 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 }
1172 }
1173 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001174 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 }
1176 }
1177
Jack Yubaeec622017-05-01 17:01:11 -07001178 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001179 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001180 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001181 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001182 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001183 networkCapabilities, networkType, roaming);
1184 }
1185
Wink Saville63f03dd2014-10-23 10:44:45 -07001186 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001187 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001188 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1189 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001190 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001191 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001192 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001193 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001194 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001195 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001196 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001197 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001198 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001199 }
yifan.baie620ce72017-12-22 14:59:57 +08001200 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001201 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001202 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001203 // We only call the callback when the change is for default APN type.
1204 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1205 && (mDataConnectionState[phoneId] != state
1206 || mDataConnectionNetworkType[phoneId] != networkType)) {
1207 String str = "onDataConnectionStateChanged(" + state
1208 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001209 log(str);
1210 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001211 for (Record r : mRecords) {
1212 if (r.matchPhoneStateListenerEvent(
1213 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1214 idMatch(r.subId, subId, phoneId)) {
1215 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001216 if (DBG) {
1217 log("Notify data connection state changed on sub: " + subId);
1218 }
Jack Yub1bac542018-03-14 16:23:38 -07001219 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001220 } catch (RemoteException ex) {
1221 mRemoveList.add(r.binder);
1222 }
1223 }
1224 }
1225 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001226
1227 mDataConnectionState[phoneId] = state;
1228 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001229 }
1230 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1231 apnType, apn, reason, linkProperties, "");
1232 for (Record r : mRecords) {
1233 if (r.matchPhoneStateListenerEvent(
1234 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1235 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001236 r.callback.onPreciseDataConnectionStateChanged(
1237 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001238 } catch (RemoteException ex) {
1239 mRemoveList.add(r.binder);
1240 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001241 }
1242 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001243 }
1244 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001245 }
Jack Yubaeec622017-05-01 17:01:11 -07001246 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001247 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001248 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1249 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 }
1251
Robert Greenwalt02648a42010-05-18 10:52:51 -07001252 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001253 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001254 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001255 }
1256
Wink Saville63f03dd2014-10-23 10:44:45 -07001257 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001258 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001259 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001260 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001261 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001262 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001263 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001264 + " reason=" + reason + " apnType=" + apnType);
1265 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001266 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001267 mPreciseDataConnectionState = new PreciseDataConnectionState(
1268 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1269 apnType, "", reason, null, "");
1270 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001271 if (r.matchPhoneStateListenerEvent(
1272 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001273 try {
1274 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1275 } catch (RemoteException ex) {
1276 mRemoveList.add(r.binder);
1277 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 }
1279 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001280 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001281 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001282 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001283 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1284 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285 }
1286
1287 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001288 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001289 }
1290
Wink Saville63f03dd2014-10-23 10:44:45 -07001291 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001292 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001293 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001294 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001295 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001296 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001297 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001298 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001299 + " cellLocation=" + cellLocation);
1300 }
yifan.baie620ce72017-12-22 14:59:57 +08001301 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001302 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001303 if (validatePhoneId(phoneId)) {
1304 mCellLocation[phoneId] = cellLocation;
1305 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001306 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001307 idMatch(r.subId, subId, phoneId) &&
1308 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001309 try {
1310 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001311 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001312 + " r=" + r);
1313 }
1314 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1315 } catch (RemoteException ex) {
1316 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001317 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001318 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001319 }
1320 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001321 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001322 }
1323 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001324
Wink Savillefd2d0132010-10-28 14:22:26 -07001325 public void notifyOtaspChanged(int otaspMode) {
1326 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1327 return;
1328 }
1329 synchronized (mRecords) {
1330 mOtaspMode = otaspMode;
1331 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001332 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001333 try {
1334 r.callback.onOtaspChanged(otaspMode);
1335 } catch (RemoteException ex) {
1336 mRemoveList.add(r.binder);
1337 }
1338 }
1339 }
1340 handleRemoveListLocked();
1341 }
1342 }
1343
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001344 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1345 int backgroundCallState) {
1346 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1347 return;
1348 }
1349 synchronized (mRecords) {
1350 mRingingCallState = ringingCallState;
1351 mForegroundCallState = foregroundCallState;
1352 mBackgroundCallState = backgroundCallState;
1353 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1354 backgroundCallState,
1355 DisconnectCause.NOT_VALID,
1356 PreciseDisconnectCause.NOT_VALID);
1357 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001358 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001359 try {
1360 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1361 } catch (RemoteException ex) {
1362 mRemoveList.add(r.binder);
1363 }
1364 }
1365 }
1366 handleRemoveListLocked();
1367 }
1368 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1369 DisconnectCause.NOT_VALID,
1370 PreciseDisconnectCause.NOT_VALID);
1371 }
1372
1373 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1374 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1375 return;
1376 }
1377 synchronized (mRecords) {
1378 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1379 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1380 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001381 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001382 try {
1383 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1384 } catch (RemoteException ex) {
1385 mRemoveList.add(r.binder);
1386 }
1387 }
1388 }
1389 handleRemoveListLocked();
1390 }
1391 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1392 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1393 }
1394
1395 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1396 String apn, String failCause) {
1397 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1398 return;
1399 }
1400 synchronized (mRecords) {
1401 mPreciseDataConnectionState = new PreciseDataConnectionState(
1402 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1403 apnType, apn, reason, null, failCause);
1404 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001405 if (r.matchPhoneStateListenerEvent(
1406 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001407 try {
1408 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1409 } catch (RemoteException ex) {
1410 mRemoveList.add(r.binder);
1411 }
1412 }
1413 }
1414 handleRemoveListLocked();
1415 }
1416 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1417 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1418 }
1419
Wink Savillefb40dd42014-06-12 17:02:31 -07001420 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1421 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1422 return;
1423 }
1424 synchronized (mRecords) {
1425 mVoLteServiceState = lteState;
1426 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001427 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001428 try {
1429 r.callback.onVoLteServiceStateChanged(
1430 new VoLteServiceState(mVoLteServiceState));
1431 } catch (RemoteException ex) {
1432 mRemoveList.add(r.binder);
1433 }
1434 }
1435 }
1436 handleRemoveListLocked();
1437 }
1438 }
1439
Shuo Qian066e8652018-04-25 21:02:35 +00001440 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
1441 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1442 return;
1443 }
1444
1445 synchronized (mRecords) {
1446 for (Record r : mRecords) {
1447 if (VDBG) {
1448 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1449 }
1450 if ((r.matchPhoneStateListenerEvent(
1451 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
1452 ((r.subId == subId) ||
1453 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
1454 try {
1455 r.callback.onOemHookRawEvent(rawData);
1456 } catch (RemoteException ex) {
1457 mRemoveList.add(r.binder);
1458 }
1459 }
1460 }
1461 handleRemoveListLocked();
1462 }
1463 }
1464
Malcolm Chene1623652018-08-08 20:27:45 -07001465 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1466 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1467 return;
1468 }
1469
1470 if (VDBG) {
1471 log("notifyPhoneCapabilityChanged: capability=" + capability);
1472 }
1473
1474 synchronized (mRecords) {
1475 mPhoneCapability = capability;
1476
1477 for (Record r : mRecords) {
1478 if (r.matchPhoneStateListenerEvent(
1479 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1480 try {
1481 r.callback.onPhoneCapabilityChanged(capability);
1482 } catch (RemoteException ex) {
1483 mRemoveList.add(r.binder);
1484 }
1485 }
1486 }
1487 handleRemoveListLocked();
1488 }
1489 }
1490
1491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001492 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001493 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1494 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1495
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001496 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001499 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001500 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001501 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301502 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001503 pw.println("Phone Id=" + i);
1504 pw.increaseIndent();
1505 pw.println("mCallState=" + mCallState[i]);
1506 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1507 pw.println("mServiceState=" + mServiceState[i]);
1508 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1509 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001510 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001511 pw.println("mSignalStrength=" + mSignalStrength[i]);
1512 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1513 pw.println("mCallForwarding=" + mCallForwarding[i]);
1514 pw.println("mDataActivity=" + mDataActivity[i]);
1515 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001516 pw.println("mCellLocation=" + mCellLocation[i]);
1517 pw.println("mCellInfo=" + mCellInfo.get(i));
1518 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301519 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001520 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1521 pw.println("mPreciseCallState=" + mPreciseCallState);
1522 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1523 pw.println("mRingingCallState=" + mRingingCallState);
1524 pw.println("mForegroundCallState=" + mForegroundCallState);
1525 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1526 pw.println("mVoLteServiceState=" + mVoLteServiceState);
Malcolm Chene1623652018-08-08 20:27:45 -07001527 pw.println("mPhoneCapability=" + mPhoneCapability);
Jack Yud19b6ae2017-04-05 14:12:09 -07001528
1529 pw.decreaseIndent();
1530
1531 pw.println("local logs:");
1532 pw.increaseIndent();
1533 mLocalLog.dump(fd, pw, args);
1534 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001535 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001536 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001537 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001538 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001540 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001541 }
1542 }
1543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 //
1545 // the legacy intent broadcasting
1546 //
1547
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001548 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001549 long ident = Binder.clearCallingIdentity();
1550 try {
1551 mBatteryStats.notePhoneState(state.getState());
1552 } catch (RemoteException re) {
1553 // Can't do much
1554 } finally {
1555 Binder.restoreCallingIdentity(ident);
1556 }
1557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001558 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001559 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560 Bundle data = new Bundle();
1561 state.fillInNotifierBundle(data);
1562 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001563 // Pass the subscription along with the intent.
1564 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001565 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001566 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 }
1568
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001569 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1570 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001571 long ident = Binder.clearCallingIdentity();
1572 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001573 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001574 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001575 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001576 } finally {
1577 Binder.restoreCallingIdentity(ident);
1578 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001581 Bundle data = new Bundle();
1582 signalStrength.fillInNotifierBundle(data);
1583 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001584 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001585 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001586 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 }
1588
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001589 /**
1590 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1591 * a valid subId, in which case this function fires a subId-specific intent, or it
1592 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1593 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1594 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001595 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1596 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001597 long ident = Binder.clearCallingIdentity();
1598 try {
1599 if (state == TelephonyManager.CALL_STATE_IDLE) {
1600 mBatteryStats.notePhoneOff();
1601 } else {
1602 mBatteryStats.notePhoneOn();
1603 }
1604 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001605 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001606 } finally {
1607 Binder.restoreCallingIdentity(ident);
1608 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001611 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001612 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001613
1614 // If a valid subId was specified, we should fire off a subId-specific state
1615 // change intent and include the subId.
1616 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1617 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1618 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1619 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001620 // If the phoneId is invalid, the broadcast is for overall call state.
1621 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1622 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1623 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001624
Brad Ebinger51de96a2017-04-21 17:05:18 -07001625 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1626 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1627
Tyler Gunn1c27bb72018-06-19 09:55:43 -07001628 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07001629 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunn1c27bb72018-06-19 09:55:43 -07001630 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1631
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001632 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1633 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07001634 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001635 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001636 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001637 android.Manifest.permission.READ_PHONE_STATE,
1638 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07001639 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
1640 new String[] { android.Manifest.permission.READ_PHONE_STATE,
1641 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001642 }
1643
Robert Greenwalt42acef32009-08-12 16:08:25 -07001644 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001645 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001646 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001647 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001648 // Note: not reporting to the battery stats service here, because the
1649 // status bar takes care of that after taking into account all of the
1650 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001652 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001653 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001654 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001655 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001656 }
1657 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001658 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001660 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001661 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001662 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001663 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001664 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001665 }
1666 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001667 if (networkCapabilities != null) {
1668 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001669 }
Wink Savillea639b312012-07-10 12:37:54 -07001670 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001671
Wink Savillea639b312012-07-10 12:37:54 -07001672 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1673 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001674 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001675 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001676 }
1677
Wink Savillefb40dd42014-06-12 17:02:31 -07001678 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001679 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001680 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001681 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1682 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001683 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001684 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001685 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001686
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001687 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1688 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1689 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1690 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1691 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1692 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1693 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1694 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1695 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1696 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1697 }
1698
1699 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001700 String apnType, String apn, String reason, LinkProperties linkProperties,
1701 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001702 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1703 intent.putExtra(PhoneConstants.STATE_KEY, state);
1704 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1705 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1706 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1707 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001708 if (linkProperties != null) {
1709 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1710 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001711 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1712
1713 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1714 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1715 }
1716
Andrew Flynnceaed682015-06-09 12:36:58 +00001717 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001718 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001719 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001720 }
1721
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001722 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
1723 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04001724 }
1725
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001726 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001727 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001728 return true;
1729 }
1730 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001731 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001732 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001733 return false;
1734 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001735
Andrew Flynn1f452642015-04-14 22:16:04 -04001736 private boolean checkNotifyPermission() {
1737 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1738 == PackageManager.PERMISSION_GRANTED;
1739 }
1740
Jeff Davidson29da89f2018-02-28 17:50:16 -08001741 private boolean checkListenerPermission(
1742 int events, int subId, String callingPackage, String message) {
Hall Liu70bbc162018-03-02 17:44:46 -08001743 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001744 mContext.enforceCallingOrSelfPermission(
1745 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
Hall Liu70bbc162018-03-02 17:44:46 -08001746 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1747 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1748 return false;
1749 }
John Wang963db55d2012-03-30 16:04:06 -07001750 }
1751
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001752 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08001753 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1754 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001755 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001756 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001757 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001758
1759 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1760 mContext.enforceCallingOrSelfPermission(
1761 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001762 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001763
Shuo Qian066e8652018-04-25 21:02:35 +00001764 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1765 mContext.enforceCallingOrSelfPermission(
1766 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1767 }
1768
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001769 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001770 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001771
1772 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001773 int size = mRemoveList.size();
1774 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1775 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001776 for (IBinder b: mRemoveList) {
1777 remove(b);
1778 }
1779 mRemoveList.clear();
1780 }
1781 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001782
1783 private boolean validateEventsAndUserLocked(Record r, int events) {
1784 int foregroundUser;
1785 long callingIdentity = Binder.clearCallingIdentity();
1786 boolean valid = false;
1787 try {
1788 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08001789 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
1790 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001791 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001792 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08001793 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001794 + " r.events=" + r.events + " events=" + events);
1795 }
1796 } finally {
1797 Binder.restoreCallingIdentity(callingIdentity);
1798 }
1799 return valid;
1800 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001801
1802 private boolean validatePhoneId(int phoneId) {
1803 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001804 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001805 return valid;
1806 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001807
1808 private static void log(String s) {
1809 Rlog.d(TAG, s);
1810 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001811
xinhe8b79fb62014-11-05 14:55:03 -08001812 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001813
1814 if(subId < 0) {
1815 // Invalid case, we need compare phoneId with default one.
1816 return (mDefaultPhoneId == phoneId);
1817 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001818 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001819 return (subId == mDefaultSubId);
1820 } else {
1821 return (rSubId == subId);
1822 }
1823 }
1824
Hall Liu5fb337f2017-11-22 17:38:15 -08001825 private boolean checkLocationAccess(Record r) {
1826 long token = Binder.clearCallingIdentity();
1827 try {
1828 return LocationAccessPolicy.canAccessCellLocation(mContext,
Svet Ganov33b15092018-03-07 19:53:43 -08001829 r.callingPackage, r.callerUid, r.callerPid,
1830 /*throwOnDeniedPermission*/ false);
Hall Liu5fb337f2017-11-22 17:38:15 -08001831 } finally {
1832 Binder.restoreCallingIdentity(token);
1833 }
1834 }
1835
xinhee9f16402014-09-25 16:39:28 -07001836 private void checkPossibleMissNotify(Record r, int phoneId) {
1837 int events = r.events;
1838
1839 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1840 try {
1841 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1842 mServiceState[phoneId]);
1843 r.callback.onServiceStateChanged(
1844 new ServiceState(mServiceState[phoneId]));
1845 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001846 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001847 }
1848 }
1849
1850 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1851 try {
1852 SignalStrength signalStrength = mSignalStrength[phoneId];
1853 if (DBG) {
1854 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1855 }
1856 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1857 } catch (RemoteException ex) {
1858 mRemoveList.add(r.binder);
1859 }
1860 }
1861
1862 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1863 try {
1864 int gsmSignalStrength = mSignalStrength[phoneId]
1865 .getGsmSignalStrength();
1866 if (DBG) {
1867 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1868 gsmSignalStrength);
1869 }
1870 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1871 : gsmSignalStrength));
1872 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001873 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001874 }
1875 }
1876
1877 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1878 try {
1879 if (DBG_LOC) {
1880 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1881 + mCellInfo.get(phoneId));
1882 }
Hall Liu5fb337f2017-11-22 17:38:15 -08001883 if (checkLocationAccess(r)) {
1884 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1885 }
xinhee9f16402014-09-25 16:39:28 -07001886 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001887 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001888 }
1889 }
1890
zxuan35a47022018-01-04 11:24:04 -08001891 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
1892 try {
1893 if (VDBG) {
1894 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
1895 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
1896 }
1897 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
1898 } catch (RemoteException ex) {
1899 mRemoveList.add(r.binder);
1900 }
1901 }
1902
xinhee9f16402014-09-25 16:39:28 -07001903 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1904 try {
1905 if (VDBG) {
1906 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1907 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1908 }
1909 r.callback.onMessageWaitingIndicatorChanged(
1910 mMessageWaiting[phoneId]);
1911 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001912 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001913 }
1914 }
1915
1916 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1917 try {
1918 if (VDBG) {
1919 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1920 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1921 }
1922 r.callback.onCallForwardingIndicatorChanged(
1923 mCallForwarding[phoneId]);
1924 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001925 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001926 }
1927 }
1928
1929 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1930 try {
1931 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1932 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -08001933 if (checkLocationAccess(r)) {
1934 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1935 }
xinhee9f16402014-09-25 16:39:28 -07001936 } catch (RemoteException ex) {
1937 mRemoveList.add(r.binder);
1938 }
1939 }
1940
1941 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1942 try {
1943 if (DBG) {
1944 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1945 + "=" + mDataConnectionState[phoneId]
1946 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1947 + ")");
1948 }
1949 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1950 mDataConnectionNetworkType[phoneId]);
1951 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001952 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001953 }
1954 }
1955 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001956}