blob: 65f3c035b0313300c03c8b0522db6209d0b2b453 [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;
Yangster4ccebea2018-10-09 17:09:02 -070052import android.util.StatsLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053
Malcolm Chen3ceeedd2018-08-27 20:38:29 -070054import com.android.internal.annotations.VisibleForTesting;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080056import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070058import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080059import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070060import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import com.android.internal.telephony.TelephonyIntents;
Jeff Davidsond7bf38a2018-02-13 18:11:37 -080062import com.android.internal.telephony.TelephonyPermissions;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060063import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070064import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import com.android.server.am.BatteryStatsService;
66
Jack Yud19b6ae2017-04-05 14:12:09 -070067import java.io.FileDescriptor;
68import java.io.PrintWriter;
69import java.util.ArrayList;
Jack Yud19b6ae2017-04-05 14:12:09 -070070import java.util.List;
Malcolm Chenabbfac22018-02-12 19:15:59 -080071import java.util.NoSuchElementException;
Jack Yud19b6ae2017-04-05 14:12:09 -070072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073/**
Wink Savillee9b06d72009-05-18 21:47:50 -070074 * Since phone process can be restarted, this class provides a centralized place
75 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070076 *
77 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
78 * and 15973975 by saving the phoneId of the registrant and then using the
79 * phoneId when deciding to to make a callback. This is necessary because
80 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070081 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070082 * the dummy value conversion we properly do the callbacks.
83 *
84 * Eventually we may want to remove the notion of dummy value but for now this
85 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 */
Malcolm Chen3ceeedd2018-08-27 20:38:29 -070087@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
88public class TelephonyRegistry extends ITelephonyRegistry.Stub {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070090 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070091 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070092 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093
94 private static class Record {
Jeff Davidson29da89f2018-02-28 17:50:16 -080095 Context context;
96
Svet Ganov16a16892015-04-16 10:32:04 -070097 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -0700100
Malcolm Chenabbfac22018-02-12 19:15:59 -0800101 TelephonyRegistryDeathRecipient deathRecipient;
102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800104 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Malcolm Chen13f31af2018-09-04 22:12:31 -0700105 IOnSubscriptionsChangedListener onOpportunisticSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -0700106
Hall Liu5fb337f2017-11-22 17:38:15 -0800107 int callerUid;
108 int callerPid;
Wink Savillea12a7b32012-09-20 10:09:45 -0700109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -0700111
Wink Savilled09c4ca2014-11-22 10:08:16 -0800112 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700113
Wink Savilled09c4ca2014-11-22 10:08:16 -0800114 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800115
116 boolean matchPhoneStateListenerEvent(int events) {
117 return (callback != null) && ((events & this.events) != 0);
118 }
119
Wink Savilled09c4ca2014-11-22 10:08:16 -0800120 boolean matchOnSubscriptionsChangedListener() {
121 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800122 }
Wink Savillee380b982014-07-26 18:24:22 -0700123
Malcolm Chen13f31af2018-09-04 22:12:31 -0700124 boolean matchOnOpportunisticSubscriptionsChangedListener() {
125 return (onOpportunisticSubscriptionsChangedListenerCallback != null);
126 }
127
Tyler Gunnf955e562018-04-26 14:43:31 -0700128 boolean canReadCallLog() {
Jeff Davidson29da89f2018-02-28 17:50:16 -0800129 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700130 return TelephonyPermissions.checkReadCallLog(
131 context, subId, callerPid, callerUid, callingPackage);
Jeff Davidson29da89f2018-02-28 17:50:16 -0800132 } catch (SecurityException e) {
133 return false;
134 }
135 }
136
Wink Savillea12a7b32012-09-20 10:09:45 -0700137 @Override
138 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700139 return "{callingPackage=" + callingPackage + " binder=" + binder
140 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800141 + " onSubscriptionsChangedListenererCallback="
Malcolm Chen13f31af2018-09-04 22:12:31 -0700142 + onSubscriptionsChangedListenerCallback
143 + " onOpportunisticSubscriptionsChangedListenererCallback="
144 + onOpportunisticSubscriptionsChangedListenerCallback
Hall Liu5fb337f2017-11-22 17:38:15 -0800145 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
Jeff Davidson29da89f2018-02-28 17:50:16 -0800146 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 }
149
150 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700151
Joe Onorato163d8d92010-10-21 13:21:20 -0400152 // access should be inside synchronized (mRecords) for these two fields
153 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
154 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 private final IBatteryStats mBatteryStats;
157
Svet Ganov16a16892015-04-16 10:32:04 -0700158 private final AppOpsManager mAppOps;
159
Malcolm Chen13f31af2018-09-04 22:12:31 -0700160 private boolean mHasNotifySubscriptionInfoChangedOccurred = false;
161
162 private boolean mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = false;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800163
Wink Savillefb40dd42014-06-12 17:02:31 -0700164 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700165
Wink Savillefb40dd42014-06-12 17:02:31 -0700166 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700167
Wink Savillefb40dd42014-06-12 17:02:31 -0700168 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700169
Wink Savillefb40dd42014-06-12 17:02:31 -0700170 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700171
fionaxu12312f62016-11-14 13:32:14 -0800172 private int[] mVoiceActivationState;
173
174 private int[] mDataActivationState;
175
zxuan35a47022018-01-04 11:24:04 -0800176 private boolean[] mUserMobileDataState;
177
Wink Savillefb40dd42014-06-12 17:02:31 -0700178 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700179
Wink Savillefb40dd42014-06-12 17:02:31 -0700180 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700181
Wink Savillefb40dd42014-06-12 17:02:31 -0700182 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700183
Wink Savillefb40dd42014-06-12 17:02:31 -0700184 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700185
Jack Yub1bac542018-03-14 16:23:38 -0700186 // Connection state of default APN type data (i.e. internet) of phones
Wink Savillefb40dd42014-06-12 17:02:31 -0700187 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700188
Wink Savillefb40dd42014-06-12 17:02:31 -0700189 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190
Wink Savillefb40dd42014-06-12 17:02:31 -0700191 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700192
Nathan Harold016e9c62016-12-14 11:24:48 -0800193 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700194
Wink Savillefb40dd42014-06-12 17:02:31 -0700195 private ArrayList<List<CellInfo>> mCellInfo = null;
196
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800197 private ArrayList<List<PhysicalChannelConfig>> mPhysicalChannelConfigs;
198
Wink Savillefb40dd42014-06-12 17:02:31 -0700199 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
200
Wink Savilled09c4ca2014-11-22 10:08:16 -0800201 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700202
Wink Savilled09c4ca2014-11-22 10:08:16 -0800203 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700204
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200205 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
206
207 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
208
209 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
210
211 private PreciseCallState mPreciseCallState = new PreciseCallState();
212
Andrew Flynn1f452642015-04-14 22:16:04 -0400213 private boolean mCarrierNetworkChangeState = false;
214
Malcolm Chene1623652018-08-08 20:27:45 -0700215 private PhoneCapability mPhoneCapability = null;
216
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700217 private int mPreferredDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
218
Chen Xu7395c632018-10-17 17:53:47 +0000219 @TelephonyManager.RadioPowerState
220 private int mRadioPowerState = TelephonyManager.RADIO_POWER_UNAVAILABLE;
221
Jack Yud19b6ae2017-04-05 14:12:09 -0700222 private final LocalLog mLocalLog = new LocalLog(100);
223
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200224 private PreciseDataConnectionState mPreciseDataConnectionState =
225 new PreciseDataConnectionState();
226
Hall Liu70bbc162018-03-02 17:44:46 -0800227 static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK =
228 PhoneStateListener.LISTEN_CELL_LOCATION
229 | PhoneStateListener.LISTEN_CELL_INFO;
230
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700231 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700232 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700233 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
234 PhoneStateListener.LISTEN_VOLTE_STATE;
235
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200236 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
237 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
238 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
239
Wink Savillea12a7b32012-09-20 10:09:45 -0700240 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700241 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700242
243 private final Handler mHandler = new Handler() {
244 @Override
245 public void handleMessage(Message msg) {
246 switch (msg.what) {
247 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700248 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700249 int numPhones = TelephonyManager.getDefault().getPhoneCount();
250 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700251 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700252 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700253 }
254 break;
255 }
xinhee9f16402014-09-25 16:39:28 -0700256 case MSG_UPDATE_DEFAULT_SUB: {
257 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700258 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700259 if (VDBG) {
260 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
261 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
262 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
263 }
264
265 //Due to possible risk condition,(notify call back using the new
266 //defaultSubId comes before new defaultSubId update) we need to recall all
267 //possible missed notify callback
268 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700269 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800270 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700271 checkPossibleMissNotify(r, newDefaultPhoneId);
272 }
273 }
274 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700275 }
276 mDefaultSubId = newDefaultSubId;
277 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700278 }
279 }
280 }
281 };
282
Malcolm Chenabbfac22018-02-12 19:15:59 -0800283 private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient {
284
285 private final IBinder binder;
286
287 TelephonyRegistryDeathRecipient(IBinder binder) {
288 this.binder = binder;
289 }
290
291 @Override
292 public void binderDied() {
293 if (DBG) log("binderDied " + binder);
294 remove(binder);
295 }
296 }
297
Wink Savillea12a7b32012-09-20 10:09:45 -0700298 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
299 @Override
300 public void onReceive(Context context, Intent intent) {
301 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700302 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700303 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700304 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700305 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700306 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700307 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700308 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800309 PhoneConstants.SUBSCRIPTION_KEY,
310 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700311 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
312 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700313 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700314 log("onReceive:current mDefaultSubId=" + mDefaultSubId
315 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
316 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700317 }
xinhee9f16402014-09-25 16:39:28 -0700318
Junda Liu985f52c2015-02-23 16:06:51 -0800319 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700320 || (newDefaultPhoneId != mDefaultPhoneId))) {
321 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
322 newDefaultPhoneId, 0, newDefaultSubIdObj));
323 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700324 }
325 }
326 };
327
Wink Savillee9b06d72009-05-18 21:47:50 -0700328 // we keep a copy of all of the state so we can send it out when folks
329 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700331 // In these calls we call with the lock held. This is safe becasuse remote
332 // calls go through a oneway interface and local calls going through a
333 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334
Malcolm Chen3ceeedd2018-08-27 20:38:29 -0700335 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
336 public TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700337 CellLocation location = CellLocation.getEmpty();
338
Wink Savillefb40dd42014-06-12 17:02:31 -0700339 mContext = context;
340 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700341
Wink Savillefb40dd42014-06-12 17:02:31 -0700342 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Jack Yub1bac542018-03-14 16:23:38 -0700343 if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700344 mNumPhones = numPhones;
345 mCallState = new int[numPhones];
346 mDataActivity = new int[numPhones];
347 mDataConnectionState = new int[numPhones];
348 mDataConnectionNetworkType = new int[numPhones];
349 mCallIncomingNumber = new String[numPhones];
350 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800351 mVoiceActivationState = new int[numPhones];
352 mDataActivationState = new int[numPhones];
zxuan35a47022018-01-04 11:24:04 -0800353 mUserMobileDataState = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700354 mSignalStrength = new SignalStrength[numPhones];
355 mMessageWaiting = new boolean[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700356 mCallForwarding = new boolean[numPhones];
357 mCellLocation = new Bundle[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700358 mCellInfo = new ArrayList<List<CellInfo>>();
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800359 mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700360 for (int i = 0; i < numPhones; i++) {
361 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
362 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
363 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800364 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
365 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700366 mCallIncomingNumber[i] = "";
367 mServiceState[i] = new ServiceState();
368 mSignalStrength[i] = new SignalStrength();
zxuan35a47022018-01-04 11:24:04 -0800369 mUserMobileDataState[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700370 mMessageWaiting[i] = false;
371 mCallForwarding[i] = false;
Wink Savillefb40dd42014-06-12 17:02:31 -0700372 mCellLocation[i] = new Bundle();
373 mCellInfo.add(i, null);
Nathan Haroldc9bad6e2018-04-25 12:53:04 -0700374 mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>());
Wink Savillefb40dd42014-06-12 17:02:31 -0700375 }
376
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700377 // Note that location can be null for non-phone builds like
378 // like the generic one.
379 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700380 for (int i = 0; i < numPhones; i++) {
381 location.fillInNotifierBundle(mCellLocation[i]);
382 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700383 }
Svet Ganov16a16892015-04-16 10:32:04 -0700384
385 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 }
387
Svetoslav Ganova0027152013-06-25 14:59:53 -0700388 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700389 // Watch for interesting updates
390 final IntentFilter filter = new IntentFilter();
391 filter.addAction(Intent.ACTION_USER_SWITCHED);
392 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700393 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700394 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700395 mContext.registerReceiver(mBroadcastReceiver, filter);
396 }
397
398 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700399 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800400 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700401 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800402 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillea374c3d2014-11-11 11:48:04 -0800403 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700404 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
405 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800406 + " callback.asBinder=" + callback.asBinder());
407 }
408
Wink Savilled09c4ca2014-11-22 10:08:16 -0800409 synchronized (mRecords) {
410 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800411 IBinder b = callback.asBinder();
412 Record r = add(b);
413
414 if (r == null) {
415 return;
Wink Savillea374c3d2014-11-11 11:48:04 -0800416 }
417
Jeff Davidson29da89f2018-02-28 17:50:16 -0800418 r.context = mContext;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800419 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700420 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800421 r.callerUid = Binder.getCallingUid();
422 r.callerPid = Binder.getCallingPid();
Wink Savilled09c4ca2014-11-22 10:08:16 -0800423 r.events = 0;
424 if (DBG) {
425 log("listen oscl: Register r=" + r);
426 }
427 // Always notify when registration occurs if there has been a notification.
Malcolm Chen13f31af2018-09-04 22:12:31 -0700428 if (mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800429 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800430 if (VDBG) log("listen oscl: send to r=" + r);
431 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
432 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800433 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800434 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800435 remove(r.binder);
436 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800437 } else {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700438 log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800439 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800440 }
441 }
442
443 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800444 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800445 IOnSubscriptionsChangedListener callback) {
446 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800447 remove(callback.asBinder());
448 }
449
Malcolm Chen13f31af2018-09-04 22:12:31 -0700450
451 @Override
452 public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage,
453 IOnSubscriptionsChangedListener callback) {
454 int callerUserId = UserHandle.getCallingUserId();
455 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
456 if (VDBG) {
457 log("listen ooscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
458 + " callerUserId=" + callerUserId + " callback=" + callback
459 + " callback.asBinder=" + callback.asBinder());
460 }
461
462 synchronized (mRecords) {
463 // register
464 IBinder b = callback.asBinder();
465 Record r = add(b);
466
467 if (r == null) {
468 return;
469 }
470
471 r.context = mContext;
472 r.onOpportunisticSubscriptionsChangedListenerCallback = callback;
473 r.callingPackage = callingPackage;
474 r.callerUid = Binder.getCallingUid();
475 r.callerPid = Binder.getCallingPid();
476 r.events = 0;
477 if (DBG) {
478 log("listen ooscl: Register r=" + r);
479 }
480 // Always notify when registration occurs if there has been a notification.
481 if (mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
482 try {
483 if (VDBG) log("listen ooscl: send to r=" + r);
484 r.onOpportunisticSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
485 if (VDBG) log("listen ooscl: sent to r=" + r);
486 } catch (RemoteException e) {
487 if (VDBG) log("listen ooscl: remote exception sending to r=" + r + " e=" + e);
488 remove(r.binder);
489 }
490 } else {
491 log("listen ooscl: hasNotifyOpptSubInfoChangedOccurred==false no callback");
492 }
493 }
494 }
495
Wink Savillea374c3d2014-11-11 11:48:04 -0800496 @Override
497 public void notifySubscriptionInfoChanged() {
498 if (VDBG) log("notifySubscriptionInfoChanged:");
499 synchronized (mRecords) {
Malcolm Chen13f31af2018-09-04 22:12:31 -0700500 if (!mHasNotifySubscriptionInfoChangedOccurred) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800501 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
502 + mRecords.size());
503 }
Malcolm Chen13f31af2018-09-04 22:12:31 -0700504 mHasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800505 mRemoveList.clear();
506 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800507 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800508 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800509 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
510 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
511 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800512 } catch (RemoteException ex) {
513 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
514 mRemoveList.add(r.binder);
515 }
516 }
517 }
518 handleRemoveListLocked();
519 }
520 }
521
522 @Override
Malcolm Chen13f31af2018-09-04 22:12:31 -0700523 public void notifyOpportunisticSubscriptionInfoChanged() {
524 if (VDBG) log("notifyOpptSubscriptionInfoChanged:");
525 synchronized (mRecords) {
526 if (!mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) {
527 log("notifyOpptSubscriptionInfoChanged: first invocation mRecords.size="
528 + mRecords.size());
529 }
530 mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = true;
531 mRemoveList.clear();
532 for (Record r : mRecords) {
533 if (r.matchOnOpportunisticSubscriptionsChangedListener()) {
534 try {
535 if (VDBG) log("notifyOpptSubChanged: call oosc to r=" + r);
536 r.onOpportunisticSubscriptionsChangedListenerCallback
537 .onSubscriptionsChanged();
538 if (VDBG) log("notifyOpptSubChanged: done oosc to r=" + r);
539 } catch (RemoteException ex) {
540 if (VDBG) log("notifyOpptSubChanged: RemoteException r=" + r);
541 mRemoveList.add(r.binder);
542 }
543 }
544 }
545 handleRemoveListLocked();
546 }
547 }
548
549 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
551 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800552 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
553 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700554 }
555
556 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700557 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700558 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700559 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700560 }
561
Svet Ganov16a16892015-04-16 10:32:04 -0700562 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700563 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700564 int callerUserId = UserHandle.getCallingUserId();
Jeff Davidson29da89f2018-02-28 17:50:16 -0800565 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Wink Savillee380b982014-07-26 18:24:22 -0700566 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700567 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700568 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
569 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700570 }
xinhe75c2c152014-10-16 11:49:45 -0700571
572 if (events != PhoneStateListener.LISTEN_NONE) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800573 // Checks permission and throws SecurityException for disallowed operations. For pre-M
574 // apps whose runtime permission has been revoked, we return immediately to skip sending
575 // events to the app without crashing it.
Jeff Davidson29da89f2018-02-28 17:50:16 -0800576 if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -0800577 return;
Svet Ganov16a16892015-04-16 10:32:04 -0700578 }
579
yifan.baie620ce72017-12-22 14:59:57 +0800580 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 synchronized (mRecords) {
582 // register
Malcolm Chenabbfac22018-02-12 19:15:59 -0800583 IBinder b = callback.asBinder();
584 Record r = add(b);
585
586 if (r == null) {
587 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 }
xinhe43c50292014-09-18 17:56:48 -0700589
Jeff Davidson29da89f2018-02-28 17:50:16 -0800590 r.context = mContext;
xinhe75c2c152014-10-16 11:49:45 -0700591 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700592 r.callingPackage = callingPackage;
Hall Liu5fb337f2017-11-22 17:38:15 -0800593 r.callerUid = Binder.getCallingUid();
594 r.callerPid = Binder.getCallingPid();
xinhe75c2c152014-10-16 11:49:45 -0700595 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
596 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800597 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800598 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700599 } else {//APP specify subID
600 r.subId = subId;
601 }
yifan.baie620ce72017-12-22 14:59:57 +0800602 r.phoneId = phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700604 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700605 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700606 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700607 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400609 try {
Wink Savillee380b982014-07-26 18:24:22 -0700610 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700611 r.callback.onServiceStateChanged(
612 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400613 } catch (RemoteException ex) {
614 remove(r.binder);
615 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800616 }
617 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
618 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700619 int gsmSignalStrength = mSignalStrength[phoneId]
620 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700621 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
622 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 } catch (RemoteException ex) {
624 remove(r.binder);
625 }
626 }
627 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
628 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700629 r.callback.onMessageWaitingIndicatorChanged(
630 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 } catch (RemoteException ex) {
632 remove(r.binder);
633 }
634 }
635 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
636 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700637 r.callback.onCallForwardingIndicatorChanged(
638 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 } catch (RemoteException ex) {
640 remove(r.binder);
641 }
642 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700643 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400644 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700645 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700646 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -0800647 if (checkLocationAccess(r)) {
648 r.callback.onCellLocationChanged(
649 new Bundle(mCellLocation[phoneId]));
650 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400651 } catch (RemoteException ex) {
652 remove(r.binder);
653 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 }
655 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
656 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700657 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700658 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 } catch (RemoteException ex) {
660 remove(r.binder);
661 }
662 }
663 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
664 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700665 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
666 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 } catch (RemoteException ex) {
668 remove(r.binder);
669 }
670 }
671 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
672 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700673 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 } catch (RemoteException ex) {
675 remove(r.binder);
676 }
677 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700678 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
679 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700680 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700681 } catch (RemoteException ex) {
682 remove(r.binder);
683 }
684 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700685 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
686 try {
687 r.callback.onOtaspChanged(mOtaspMode);
688 } catch (RemoteException ex) {
689 remove(r.binder);
690 }
691 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700692 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700693 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700694 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700695 + mCellInfo.get(phoneId));
Hall Liu5fb337f2017-11-22 17:38:15 -0800696 if (checkLocationAccess(r)) {
697 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
698 }
John Wang963db55d2012-03-30 16:04:06 -0700699 } catch (RemoteException ex) {
700 remove(r.binder);
701 }
702 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200703 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
704 try {
705 r.callback.onPreciseCallStateChanged(mPreciseCallState);
706 } catch (RemoteException ex) {
707 remove(r.binder);
708 }
709 }
710 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
711 try {
712 r.callback.onPreciseDataConnectionStateChanged(
713 mPreciseDataConnectionState);
714 } catch (RemoteException ex) {
715 remove(r.binder);
716 }
717 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400718 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
719 try {
720 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
721 } catch (RemoteException ex) {
722 remove(r.binder);
723 }
724 }
fionaxu12312f62016-11-14 13:32:14 -0800725 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
726 try {
727 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
728 } catch (RemoteException ex) {
729 remove(r.binder);
730 }
731 }
732 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
733 try {
734 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
735 } catch (RemoteException ex) {
736 remove(r.binder);
737 }
738 }
zxuan35a47022018-01-04 11:24:04 -0800739 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
740 try {
741 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
742 } catch (RemoteException ex) {
743 remove(r.binder);
744 }
745 }
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -0800746 if ((events & PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION) != 0) {
747 try {
748 r.callback.onPhysicalChannelConfigurationChanged(
749 mPhysicalChannelConfigs.get(phoneId));
750 } catch (RemoteException ex) {
751 remove(r.binder);
752 }
753 }
Malcolm Chene1623652018-08-08 20:27:45 -0700754 if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
755 try {
756 r.callback.onPhoneCapabilityChanged(mPhoneCapability);
757 } catch (RemoteException ex) {
758 remove(r.binder);
759 }
760 }
Malcolm Chen8b53afe2018-09-24 20:01:32 -0700761 if ((events & PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE) != 0) {
762 try {
763 r.callback.onPreferredDataSubIdChanged(mPreferredDataSubId);
764 } catch (RemoteException ex) {
765 remove(r.binder);
766 }
767 }
Chen Xu7395c632018-10-17 17:53:47 +0000768 if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
769 try {
770 r.callback.onRadioPowerStateChanged(mRadioPowerState);
771 } catch (RemoteException ex) {
772 remove(r.binder);
773 }
774 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 }
776 }
777 } else {
xinhe75c2c152014-10-16 11:49:45 -0700778 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 remove(callback.asBinder());
780 }
781 }
782
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700783 private String getCallIncomingNumber(Record record, int phoneId) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700784 // Only reveal the incoming number if the record has read call log permission.
785 return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : "";
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700786 }
787
Malcolm Chenabbfac22018-02-12 19:15:59 -0800788 private Record add(IBinder binder) {
789 Record r;
790
791 synchronized (mRecords) {
792 final int N = mRecords.size();
793 for (int i = 0; i < N; i++) {
794 r = mRecords.get(i);
795 if (binder == r.binder) {
796 // Already existed.
797 return r;
798 }
799 }
800 r = new Record();
801 r.binder = binder;
802 r.deathRecipient = new TelephonyRegistryDeathRecipient(binder);
803
804 try {
805 binder.linkToDeath(r.deathRecipient, 0);
806 } catch (RemoteException e) {
807 if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e);
808 // Binder already died. Return null.
809 return null;
810 }
811
812 mRecords.add(r);
813 if (DBG) log("add new record");
814 }
815
816 return r;
817 }
818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 private void remove(IBinder binder) {
820 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700821 final int recordCount = mRecords.size();
822 for (int i = 0; i < recordCount; i++) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800823 Record r = mRecords.get(i);
824 if (r.binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800825 if (DBG) {
Malcolm Chenabbfac22018-02-12 19:15:59 -0800826 log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
827 + " r.callback " + r.callback);
xinheac11ae92014-12-18 10:02:14 -0800828 }
Malcolm Chenabbfac22018-02-12 19:15:59 -0800829
830 if (r.deathRecipient != null) {
831 try {
832 binder.unlinkToDeath(r.deathRecipient, 0);
833 } catch (NoSuchElementException e) {
834 if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
835 + r + " e=" + e);
836 }
837 }
838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 mRecords.remove(i);
840 return;
841 }
842 }
843 }
844 }
845
Tyler Gunnf955e562018-04-26 14:43:31 -0700846 public void notifyCallState(int state, String phoneNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700847 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700848 return;
849 }
xinhe43c50292014-09-18 17:56:48 -0700850
851 if (VDBG) {
Tyler Gunnf955e562018-04-26 14:43:31 -0700852 log("notifyCallState: state=" + state + " phoneNumber=" + phoneNumber);
xinhe43c50292014-09-18 17:56:48 -0700853 }
854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700856 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800857 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800858 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800859 try {
Tyler Gunnf955e562018-04-26 14:43:31 -0700860 // Ensure the listener has read call log permission; if they do not return
861 // an empty phone number.
862 String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
863 r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800864 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400865 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800866 }
867 }
868 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400869 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700871
872 // Called only by Telecomm to communicate call state across different phone accounts. So
873 // there is no need to add a valid subId or slotId.
Tyler Gunnf955e562018-04-26 14:43:31 -0700874 broadcastCallStateChanged(state, phoneNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700875 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700876 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 }
878
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700879 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
880 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700881 if (!checkNotifyPermission("notifyCallState()")) {
882 return;
883 }
Wink Savillee380b982014-07-26 18:24:22 -0700884 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700885 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700886 + " state=" + state + " incomingNumber=" + incomingNumber);
887 }
888 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700889 if (validatePhoneId(phoneId)) {
890 mCallState[phoneId] = state;
891 mCallIncomingNumber[phoneId] = incomingNumber;
892 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800893 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700894 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800895 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700896 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700897 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
898 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700899 } catch (RemoteException ex) {
900 mRemoveList.add(r.binder);
901 }
902 }
903 }
904 }
905 handleRemoveListLocked();
906 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700907 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700908 }
909
Wink Saville63f03dd2014-10-23 10:44:45 -0700910 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700911 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700912 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700913 }
xinhe43c50292014-09-18 17:56:48 -0700914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700916 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
917 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700918 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700919 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700920 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700921 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700922 if (validatePhoneId(phoneId)) {
923 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700924
Wink Savillefb40dd42014-06-12 17:02:31 -0700925 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700926 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700927 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700928 + " phoneId=" + phoneId + " state=" + state);
929 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800930 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800931 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700932 try {
Wink Savillee380b982014-07-26 18:24:22 -0700933 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700934 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700935 + " subId=" + subId + " phoneId=" + phoneId
936 + " state=" + state);
937 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700938 r.callback.onServiceStateChanged(new ServiceState(state));
939 } catch (RemoteException ex) {
940 mRemoveList.add(r.binder);
941 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400942 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700944 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700945 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400947 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700949 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 }
951
fionaxu12312f62016-11-14 13:32:14 -0800952 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
953 int activationType, int activationState) {
954 if (!checkNotifyPermission("notifySimActivationState()")){
955 return;
956 }
957 if (VDBG) {
958 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
959 + "type=" + activationType + " state=" + activationState);
960 }
961 synchronized (mRecords) {
962 if (validatePhoneId(phoneId)) {
963 switch (activationType) {
964 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
965 mVoiceActivationState[phoneId] = activationState;
966 break;
967 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
968 mDataActivationState[phoneId] = activationState;
969 break;
970 default:
971 return;
972 }
973 for (Record r : mRecords) {
974 if (VDBG) {
975 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
976 + " phoneId=" + phoneId + "type=" + activationType
977 + " state=" + activationState);
978 }
979 try {
980 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
981 r.matchPhoneStateListenerEvent(
982 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
983 idMatch(r.subId, subId, phoneId)) {
984 if (DBG) {
985 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
986 + " subId=" + subId + " phoneId=" + phoneId
987 + " state=" + activationState);
988 }
989 r.callback.onVoiceActivationStateChanged(activationState);
990 }
991 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
992 r.matchPhoneStateListenerEvent(
993 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
994 idMatch(r.subId, subId, phoneId)) {
995 if (DBG) {
996 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
997 + " subId=" + subId + " phoneId=" + phoneId
998 + " state=" + activationState);
999 }
1000 r.callback.onDataActivationStateChanged(activationState);
1001 }
1002 } catch (RemoteException ex) {
1003 mRemoveList.add(r.binder);
1004 }
1005 }
1006 } else {
1007 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
1008 }
1009 handleRemoveListLocked();
1010 }
1011 }
1012
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001013 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
1014 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001015 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001016 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001017 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001018 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001019 log("notifySignalStrengthForPhoneId: subId=" + subId
1020 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001021 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001023 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001024 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001025 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -07001026 mSignalStrength[phoneId] = signalStrength;
1027 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001028 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001029 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001030 + " phoneId=" + phoneId + " ss=" + signalStrength);
1031 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001032 if (r.matchPhoneStateListenerEvent(
1033 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -08001034 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001035 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001036 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001037 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001038 + " subId=" + subId + " phoneId=" + phoneId
1039 + " ss=" + signalStrength);
1040 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001041 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1042 } catch (RemoteException ex) {
1043 mRemoveList.add(r.binder);
1044 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001045 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001046 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -08001047 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -07001048 try {
1049 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001050 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001051 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001052 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +00001053 + " subId=" + subId + " phoneId=" + phoneId
1054 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
1055 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001056 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -07001057 } catch (RemoteException ex) {
1058 mRemoveList.add(r.binder);
1059 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 }
1061 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001062 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001063 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001064 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001065 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001067 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 }
1069
Andrew Flynn1f452642015-04-14 22:16:04 -04001070 @Override
1071 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001072 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
1073
Andrew Flynn1f452642015-04-14 22:16:04 -04001074 if (VDBG) {
1075 log("notifyCarrierNetworkChange: active=" + active);
1076 }
1077
1078 synchronized (mRecords) {
1079 mCarrierNetworkChangeState = active;
1080 for (Record r : mRecords) {
1081 if (r.matchPhoneStateListenerEvent(
1082 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
1083 try {
1084 r.callback.onCarrierNetworkChange(active);
1085 } catch (RemoteException ex) {
1086 mRemoveList.add(r.binder);
1087 }
1088 }
1089 }
1090 handleRemoveListLocked();
1091 }
1092 }
1093
Wink Savilleb208a242012-07-25 14:08:09 -07001094 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001095 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -07001096 }
1097
Wink Saville63f03dd2014-10-23 10:44:45 -07001098 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -07001099 if (!checkNotifyPermission("notifyCellInfo()")) {
1100 return;
1101 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001102 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001103 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001104 + " cellInfo=" + cellInfo);
1105 }
yifan.baie620ce72017-12-22 14:59:57 +08001106 int phoneId = SubscriptionManager.getPhoneId(subId);
John Wang963db55d2012-03-30 16:04:06 -07001107 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001108 if (validatePhoneId(phoneId)) {
1109 mCellInfo.set(phoneId, cellInfo);
1110 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001111 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001112 idMatch(r.subId, subId, phoneId) &&
1113 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001114 try {
1115 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001116 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -07001117 }
1118 r.callback.onCellInfoChanged(cellInfo);
1119 } catch (RemoteException ex) {
1120 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001121 }
John Wang963db55d2012-03-30 16:04:06 -07001122 }
1123 }
1124 }
1125 handleRemoveListLocked();
1126 }
1127 }
1128
Eric Schwarzenbach4ce04dd2018-01-24 13:21:27 -08001129 public void notifyPhysicalChannelConfiguration(List<PhysicalChannelConfig> configs) {
1130 notifyPhysicalChannelConfigurationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
1131 configs);
1132 }
1133
1134 public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
1135 List<PhysicalChannelConfig> configs) {
1136 if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
1137 return;
1138 }
1139
1140 if (VDBG) {
1141 log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
1142 }
1143
1144 synchronized (mRecords) {
1145 int phoneId = SubscriptionManager.getPhoneId(subId);
1146 if (validatePhoneId(phoneId)) {
1147 mPhysicalChannelConfigs.set(phoneId, configs);
1148 for (Record r : mRecords) {
1149 if (r.matchPhoneStateListenerEvent(
1150 PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
1151 && idMatch(r.subId, subId, phoneId)) {
1152 try {
1153 if (DBG_LOC) {
1154 log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
1155 + configs + " r=" + r);
1156 }
1157 r.callback.onPhysicalChannelConfigurationChanged(configs);
1158 } catch (RemoteException ex) {
1159 mRemoveList.add(r.binder);
1160 }
1161 }
1162 }
1163 }
1164 handleRemoveListLocked();
1165 }
1166 }
1167
xinhe43c50292014-09-18 17:56:48 -07001168 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -07001169 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001170 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001171 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001172 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001173 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001174 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001175 + " mwi=" + mwi);
1176 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001177 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001178 if (validatePhoneId(phoneId)) {
1179 mMessageWaiting[phoneId] = mwi;
1180 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001181 if (r.matchPhoneStateListenerEvent(
1182 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001183 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001184 try {
1185 r.callback.onMessageWaitingIndicatorChanged(mwi);
1186 } catch (RemoteException ex) {
1187 mRemoveList.add(r.binder);
1188 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 }
1190 }
1191 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001192 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193 }
1194 }
1195
zxuan35a47022018-01-04 11:24:04 -08001196 public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
1197 if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
1198 return;
1199 }
1200 if (VDBG) {
1201 log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
1202 + " state=" + state);
1203 }
1204 synchronized (mRecords) {
1205 if (validatePhoneId(phoneId)) {
1206 mMessageWaiting[phoneId] = state;
1207 for (Record r : mRecords) {
1208 if (r.matchPhoneStateListenerEvent(
1209 PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
1210 idMatch(r.subId, subId, phoneId)) {
1211 try {
1212 r.callback.onUserMobileDataStateChanged(state);
1213 } catch (RemoteException ex) {
1214 mRemoveList.add(r.binder);
1215 }
1216 }
1217 }
1218 }
1219 handleRemoveListLocked();
1220 }
1221 }
1222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001224 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001225 }
1226
Wink Saville63f03dd2014-10-23 10:44:45 -07001227 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001228 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001229 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001230 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001231 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001232 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001233 + " cfi=" + cfi);
1234 }
yifan.baie620ce72017-12-22 14:59:57 +08001235 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001236 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001237 if (validatePhoneId(phoneId)) {
1238 mCallForwarding[phoneId] = cfi;
1239 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001240 if (r.matchPhoneStateListenerEvent(
1241 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001242 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001243 try {
1244 r.callback.onCallForwardingIndicatorChanged(cfi);
1245 } catch (RemoteException ex) {
1246 mRemoveList.add(r.binder);
1247 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 }
1249 }
1250 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001251 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 }
1253 }
1254
1255 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001256 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001257 }
1258
Wink Saville63f03dd2014-10-23 10:44:45 -07001259 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001260 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001261 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001262 }
yifan.baie620ce72017-12-22 14:59:57 +08001263 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001264 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001265 if (validatePhoneId(phoneId)) {
1266 mDataActivity[phoneId] = state;
1267 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001268 // Notify by correct subId.
1269 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1270 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001271 try {
1272 r.callback.onDataActivity(state);
1273 } catch (RemoteException ex) {
1274 mRemoveList.add(r.binder);
1275 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276 }
1277 }
1278 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001279 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001280 }
1281 }
1282
Jack Yubaeec622017-05-01 17:01:11 -07001283 public void notifyDataConnection(int state, boolean isDataAllowed,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001284 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001285 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001286 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
Jack Yubaeec622017-05-01 17:01:11 -07001287 isDataAllowed,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001288 networkCapabilities, networkType, roaming);
1289 }
1290
Wink Saville63f03dd2014-10-23 10:44:45 -07001291 public void notifyDataConnectionForSubscriber(int subId, int state,
Jack Yubaeec622017-05-01 17:01:11 -07001292 boolean isDataAllowed, String reason, String apn, String apnType,
Wink Savillefb40dd42014-06-12 17:02:31 -07001293 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1294 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001295 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001296 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001297 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001298 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001299 log("notifyDataConnectionForSubscriber: subId=" + subId
Jack Yubaeec622017-05-01 17:01:11 -07001300 + " state=" + state + " isDataAllowed=" + isDataAllowed
Wink Savillefb40dd42014-06-12 17:02:31 -07001301 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001302 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001303 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001304 }
yifan.baie620ce72017-12-22 14:59:57 +08001305 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001306 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001307 if (validatePhoneId(phoneId)) {
Jack Yub1bac542018-03-14 16:23:38 -07001308 // We only call the callback when the change is for default APN type.
1309 if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)
1310 && (mDataConnectionState[phoneId] != state
1311 || mDataConnectionNetworkType[phoneId] != networkType)) {
1312 String str = "onDataConnectionStateChanged(" + state
1313 + ", " + networkType + ")";
Jack Yud19b6ae2017-04-05 14:12:09 -07001314 log(str);
1315 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001316 for (Record r : mRecords) {
1317 if (r.matchPhoneStateListenerEvent(
1318 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1319 idMatch(r.subId, subId, phoneId)) {
1320 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001321 if (DBG) {
1322 log("Notify data connection state changed on sub: " + subId);
1323 }
Jack Yub1bac542018-03-14 16:23:38 -07001324 r.callback.onDataConnectionStateChanged(state, networkType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001325 } catch (RemoteException ex) {
1326 mRemoveList.add(r.binder);
1327 }
1328 }
1329 }
1330 handleRemoveListLocked();
Jack Yub1bac542018-03-14 16:23:38 -07001331
1332 mDataConnectionState[phoneId] = state;
1333 mDataConnectionNetworkType[phoneId] = networkType;
Wink Savilled09c4ca2014-11-22 10:08:16 -08001334 }
1335 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1336 apnType, apn, reason, linkProperties, "");
1337 for (Record r : mRecords) {
1338 if (r.matchPhoneStateListenerEvent(
1339 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1340 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001341 r.callback.onPreciseDataConnectionStateChanged(
1342 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001343 } catch (RemoteException ex) {
1344 mRemoveList.add(r.binder);
1345 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001346 }
1347 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001348 }
1349 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001350 }
Jack Yubaeec622017-05-01 17:01:11 -07001351 broadcastDataConnectionStateChanged(state, isDataAllowed, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001352 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001353 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1354 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001355 }
1356
Robert Greenwalt02648a42010-05-18 10:52:51 -07001357 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001358 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001359 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001360 }
1361
Wink Saville63f03dd2014-10-23 10:44:45 -07001362 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001363 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001364 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001365 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001366 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001367 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001368 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001369 + " reason=" + reason + " apnType=" + apnType);
1370 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001371 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001372 mPreciseDataConnectionState = new PreciseDataConnectionState(
1373 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1374 apnType, "", reason, null, "");
1375 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001376 if (r.matchPhoneStateListenerEvent(
1377 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001378 try {
1379 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1380 } catch (RemoteException ex) {
1381 mRemoveList.add(r.binder);
1382 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001383 }
1384 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001385 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001386 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001387 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001388 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1389 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 }
1391
1392 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001393 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001394 }
1395
Wink Saville63f03dd2014-10-23 10:44:45 -07001396 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001397 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001398 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001399 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001400 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001401 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001402 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001403 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001404 + " cellLocation=" + cellLocation);
1405 }
yifan.baie620ce72017-12-22 14:59:57 +08001406 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001408 if (validatePhoneId(phoneId)) {
1409 mCellLocation[phoneId] = cellLocation;
1410 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001411 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
Hall Liu5fb337f2017-11-22 17:38:15 -08001412 idMatch(r.subId, subId, phoneId) &&
1413 checkLocationAccess(r)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001414 try {
1415 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001416 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001417 + " r=" + r);
1418 }
1419 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1420 } catch (RemoteException ex) {
1421 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001422 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001423 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001424 }
1425 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001426 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001427 }
1428 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001429
Wink Savillefd2d0132010-10-28 14:22:26 -07001430 public void notifyOtaspChanged(int otaspMode) {
1431 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1432 return;
1433 }
1434 synchronized (mRecords) {
1435 mOtaspMode = otaspMode;
1436 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001437 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001438 try {
1439 r.callback.onOtaspChanged(otaspMode);
1440 } catch (RemoteException ex) {
1441 mRemoveList.add(r.binder);
1442 }
1443 }
1444 }
1445 handleRemoveListLocked();
1446 }
1447 }
1448
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001449 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1450 int backgroundCallState) {
1451 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1452 return;
1453 }
1454 synchronized (mRecords) {
1455 mRingingCallState = ringingCallState;
1456 mForegroundCallState = foregroundCallState;
1457 mBackgroundCallState = backgroundCallState;
1458 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1459 backgroundCallState,
1460 DisconnectCause.NOT_VALID,
1461 PreciseDisconnectCause.NOT_VALID);
1462 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001463 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001464 try {
1465 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1466 } catch (RemoteException ex) {
1467 mRemoveList.add(r.binder);
1468 }
1469 }
1470 }
1471 handleRemoveListLocked();
1472 }
1473 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1474 DisconnectCause.NOT_VALID,
1475 PreciseDisconnectCause.NOT_VALID);
1476 }
1477
1478 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1479 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1480 return;
1481 }
1482 synchronized (mRecords) {
1483 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1484 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1485 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001486 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001487 try {
1488 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1489 } catch (RemoteException ex) {
1490 mRemoveList.add(r.binder);
1491 }
1492 }
1493 }
1494 handleRemoveListLocked();
1495 }
1496 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1497 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1498 }
1499
1500 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1501 String apn, String failCause) {
1502 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1503 return;
1504 }
1505 synchronized (mRecords) {
1506 mPreciseDataConnectionState = new PreciseDataConnectionState(
1507 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1508 apnType, apn, reason, null, failCause);
1509 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001510 if (r.matchPhoneStateListenerEvent(
1511 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001512 try {
1513 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1514 } catch (RemoteException ex) {
1515 mRemoveList.add(r.binder);
1516 }
1517 }
1518 }
1519 handleRemoveListLocked();
1520 }
1521 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1522 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1523 }
1524
Wink Savillefb40dd42014-06-12 17:02:31 -07001525 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1526 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1527 return;
1528 }
1529 synchronized (mRecords) {
1530 mVoLteServiceState = lteState;
1531 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001532 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001533 try {
1534 r.callback.onVoLteServiceStateChanged(
1535 new VoLteServiceState(mVoLteServiceState));
1536 } catch (RemoteException ex) {
1537 mRemoveList.add(r.binder);
1538 }
1539 }
1540 }
1541 handleRemoveListLocked();
1542 }
1543 }
1544
Shuo Qian066e8652018-04-25 21:02:35 +00001545 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
1546 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1547 return;
1548 }
1549
1550 synchronized (mRecords) {
1551 for (Record r : mRecords) {
1552 if (VDBG) {
1553 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1554 }
1555 if ((r.matchPhoneStateListenerEvent(
1556 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
1557 ((r.subId == subId) ||
1558 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
1559 try {
1560 r.callback.onOemHookRawEvent(rawData);
1561 } catch (RemoteException ex) {
1562 mRemoveList.add(r.binder);
1563 }
1564 }
1565 }
1566 handleRemoveListLocked();
1567 }
1568 }
1569
Malcolm Chene1623652018-08-08 20:27:45 -07001570 public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
1571 if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) {
1572 return;
1573 }
1574
1575 if (VDBG) {
1576 log("notifyPhoneCapabilityChanged: capability=" + capability);
1577 }
1578
1579 synchronized (mRecords) {
1580 mPhoneCapability = capability;
1581
1582 for (Record r : mRecords) {
1583 if (r.matchPhoneStateListenerEvent(
1584 PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) {
1585 try {
1586 r.callback.onPhoneCapabilityChanged(capability);
1587 } catch (RemoteException ex) {
1588 mRemoveList.add(r.binder);
1589 }
1590 }
1591 }
1592 handleRemoveListLocked();
1593 }
1594 }
1595
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001596 public void notifyPreferredDataSubIdChanged(int preferredSubId) {
1597 if (!checkNotifyPermission("notifyPreferredDataSubIdChanged()")) {
1598 return;
1599 }
1600
1601 if (VDBG) {
1602 log("notifyPreferredDataSubIdChanged: preferredSubId=" + preferredSubId);
1603 }
1604
1605 synchronized (mRecords) {
1606 mPreferredDataSubId = preferredSubId;
1607
1608 for (Record r : mRecords) {
1609 if (r.matchPhoneStateListenerEvent(
1610 PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE)) {
1611 try {
1612 r.callback.onPreferredDataSubIdChanged(preferredSubId);
1613 } catch (RemoteException ex) {
1614 mRemoveList.add(r.binder);
1615 }
1616 }
1617 }
1618 handleRemoveListLocked();
1619 }
1620 }
Malcolm Chene1623652018-08-08 20:27:45 -07001621
Chen Xu7395c632018-10-17 17:53:47 +00001622 public void notifyRadioPowerStateChanged(@TelephonyManager.RadioPowerState int state) {
1623 if (!checkNotifyPermission("notifyRadioPowerStateChanged()")) {
1624 return;
1625 }
1626
1627 if (VDBG) {
1628 log("notifyRadioPowerStateChanged: state= " + state);
1629 }
1630
1631 synchronized (mRecords) {
1632 mRadioPowerState = state;
1633
1634 for (Record r : mRecords) {
1635 if (r.matchPhoneStateListenerEvent(
1636 PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED)) {
1637 try {
1638 r.callback.onRadioPowerStateChanged(state);
1639 } catch (RemoteException ex) {
1640 mRemoveList.add(r.binder);
1641 }
1642 }
1643 }
1644 handleRemoveListLocked();
1645 }
1646 }
1647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001648 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001649 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1650 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1651
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001652 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001655 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001656 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001657 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301658 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001659 pw.println("Phone Id=" + i);
1660 pw.increaseIndent();
1661 pw.println("mCallState=" + mCallState[i]);
1662 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1663 pw.println("mServiceState=" + mServiceState[i]);
1664 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1665 pw.println("mDataActivationState= " + mDataActivationState[i]);
zxuan35a47022018-01-04 11:24:04 -08001666 pw.println("mUserMobileDataState= " + mUserMobileDataState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001667 pw.println("mSignalStrength=" + mSignalStrength[i]);
1668 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1669 pw.println("mCallForwarding=" + mCallForwarding[i]);
1670 pw.println("mDataActivity=" + mDataActivity[i]);
1671 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001672 pw.println("mCellLocation=" + mCellLocation[i]);
1673 pw.println("mCellInfo=" + mCellInfo.get(i));
1674 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301675 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001676 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1677 pw.println("mPreciseCallState=" + mPreciseCallState);
1678 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1679 pw.println("mRingingCallState=" + mRingingCallState);
1680 pw.println("mForegroundCallState=" + mForegroundCallState);
1681 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1682 pw.println("mVoLteServiceState=" + mVoLteServiceState);
Malcolm Chene1623652018-08-08 20:27:45 -07001683 pw.println("mPhoneCapability=" + mPhoneCapability);
Malcolm Chen8b53afe2018-09-24 20:01:32 -07001684 pw.println("mPreferredDataSubId=" + mPreferredDataSubId);
Chen Xu7395c632018-10-17 17:53:47 +00001685 pw.println("mRadioPowerState=" + mRadioPowerState);
Jack Yud19b6ae2017-04-05 14:12:09 -07001686
1687 pw.decreaseIndent();
1688
1689 pw.println("local logs:");
1690 pw.increaseIndent();
1691 mLocalLog.dump(fd, pw, args);
1692 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001693 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001694 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001695 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001696 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001698 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001699 }
1700 }
1701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001702 //
1703 // the legacy intent broadcasting
1704 //
1705
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001706 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001707 long ident = Binder.clearCallingIdentity();
1708 try {
1709 mBatteryStats.notePhoneState(state.getState());
1710 } catch (RemoteException re) {
1711 // Can't do much
1712 } finally {
1713 Binder.restoreCallingIdentity(ident);
1714 }
1715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001716 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001717 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001718 Bundle data = new Bundle();
1719 state.fillInNotifierBundle(data);
1720 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001721 // Pass the subscription along with the intent.
1722 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001723 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001724 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001725 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001726 }
1727
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001728 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1729 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001730 long ident = Binder.clearCallingIdentity();
1731 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001732 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001733 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001734 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001735 } finally {
1736 Binder.restoreCallingIdentity(ident);
1737 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001739 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001740 Bundle data = new Bundle();
1741 signalStrength.fillInNotifierBundle(data);
1742 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001743 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001744 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001745 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001746 }
1747
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001748 /**
1749 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1750 * a valid subId, in which case this function fires a subId-specific intent, or it
1751 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1752 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1753 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001754 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1755 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001756 long ident = Binder.clearCallingIdentity();
1757 try {
1758 if (state == TelephonyManager.CALL_STATE_IDLE) {
1759 mBatteryStats.notePhoneOff();
Yangster4ccebea2018-10-09 17:09:02 -07001760 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1761 StatsLog.PHONE_STATE_CHANGED__STATE__OFF);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001762 } else {
1763 mBatteryStats.notePhoneOn();
Yangster4ccebea2018-10-09 17:09:02 -07001764 StatsLog.write(StatsLog.PHONE_STATE_CHANGED,
1765 StatsLog.PHONE_STATE_CHANGED__STATE__ON);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001766 }
1767 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001768 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001769 } finally {
1770 Binder.restoreCallingIdentity(ident);
1771 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001773 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001774 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001775 PhoneConstantConversions.convertCallState(state).toString());
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001776
1777 // If a valid subId was specified, we should fire off a subId-specific state
1778 // change intent and include the subId.
1779 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1780 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1781 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
chen xu379e5312018-09-28 15:53:43 -07001782 intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001783 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001784 // If the phoneId is invalid, the broadcast is for overall call state.
1785 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1786 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1787 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001788
Brad Ebinger51de96a2017-04-21 17:05:18 -07001789 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1790 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1791
Tyler Gunn1c27bb72018-06-19 09:55:43 -07001792 // Create a version of the intent with the number always populated.
Tyler Gunnf955e562018-04-26 14:43:31 -07001793 Intent intentWithPhoneNumber = new Intent(intent);
Tyler Gunn1c27bb72018-06-19 09:55:43 -07001794 intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1795
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001796 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1797 // that have the runtime one
Tyler Gunnf955e562018-04-26 14:43:31 -07001798 mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL,
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001799 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001800 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001801 android.Manifest.permission.READ_PHONE_STATE,
1802 AppOpsManager.OP_READ_PHONE_STATE);
Tyler Gunnf955e562018-04-26 14:43:31 -07001803 mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL,
1804 new String[] { android.Manifest.permission.READ_PHONE_STATE,
1805 android.Manifest.permission.READ_CALL_LOG});
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001806 }
1807
Robert Greenwalt42acef32009-08-12 16:08:25 -07001808 private void broadcastDataConnectionStateChanged(int state,
Jack Yubaeec622017-05-01 17:01:11 -07001809 boolean isDataAllowed,
Wink Savillef61101f2010-09-16 16:36:42 -07001810 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001811 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001812 // Note: not reporting to the battery stats service here, because the
1813 // status bar takes care of that after taking into account all of the
1814 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001816 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001817 PhoneConstantConversions.convertDataState(state).toString());
Jack Yubaeec622017-05-01 17:01:11 -07001818 if (!isDataAllowed) {
Wink Savillea639b312012-07-10 12:37:54 -07001819 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001820 }
1821 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001822 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001823 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001824 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001825 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001826 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001827 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001828 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001829 }
1830 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001831 if (networkCapabilities != null) {
1832 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001833 }
Wink Savillea639b312012-07-10 12:37:54 -07001834 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001835
Wink Savillea639b312012-07-10 12:37:54 -07001836 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1837 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001838 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001839 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001840 }
1841
Wink Savillefb40dd42014-06-12 17:02:31 -07001842 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001843 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001844 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001845 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1846 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001847 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001848 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001849 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001850
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001851 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1852 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1853 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1854 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1855 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1856 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1857 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1858 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1859 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1860 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1861 }
1862
1863 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001864 String apnType, String apn, String reason, LinkProperties linkProperties,
1865 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001866 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1867 intent.putExtra(PhoneConstants.STATE_KEY, state);
1868 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1869 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1870 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1871 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001872 if (linkProperties != null) {
1873 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1874 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001875 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1876
1877 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1878 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1879 }
1880
Andrew Flynnceaed682015-06-09 12:36:58 +00001881 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001882 if (checkNotifyPermission()) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001883 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001884 }
1885
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001886 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
1887 SubscriptionManager.getDefaultSubscriptionId(), method);
Andrew Flynn1f452642015-04-14 22:16:04 -04001888 }
1889
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001890 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001891 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001892 return true;
1893 }
1894 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001895 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001896 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001897 return false;
1898 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001899
Andrew Flynn1f452642015-04-14 22:16:04 -04001900 private boolean checkNotifyPermission() {
1901 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1902 == PackageManager.PERMISSION_GRANTED;
1903 }
1904
Jeff Davidson29da89f2018-02-28 17:50:16 -08001905 private boolean checkListenerPermission(
1906 int events, int subId, String callingPackage, String message) {
Hall Liu70bbc162018-03-02 17:44:46 -08001907 if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001908 mContext.enforceCallingOrSelfPermission(
1909 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
Hall Liu70bbc162018-03-02 17:44:46 -08001910 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1911 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1912 return false;
1913 }
John Wang963db55d2012-03-30 16:04:06 -07001914 }
1915
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001916 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Jeff Davidson29da89f2018-02-28 17:50:16 -08001917 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1918 mContext, subId, callingPackage, message)) {
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001919 return false;
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001920 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001921 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001922
1923 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1924 mContext.enforceCallingOrSelfPermission(
1925 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001926 }
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001927
Shuo Qian066e8652018-04-25 21:02:35 +00001928 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1929 mContext.enforceCallingOrSelfPermission(
1930 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1931 }
1932
Jeff Davidsond7bf38a2018-02-13 18:11:37 -08001933 return true;
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001934 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001935
1936 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001937 int size = mRemoveList.size();
1938 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1939 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001940 for (IBinder b: mRemoveList) {
1941 remove(b);
1942 }
1943 mRemoveList.clear();
1944 }
1945 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001946
1947 private boolean validateEventsAndUserLocked(Record r, int events) {
1948 int foregroundUser;
1949 long callingIdentity = Binder.clearCallingIdentity();
1950 boolean valid = false;
1951 try {
1952 foregroundUser = ActivityManager.getCurrentUser();
Hall Liu5fb337f2017-11-22 17:38:15 -08001953 valid = UserHandle.getUserId(r.callerUid) == foregroundUser
1954 && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001955 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001956 log("validateEventsAndUserLocked: valid=" + valid
Hall Liu5fb337f2017-11-22 17:38:15 -08001957 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001958 + " r.events=" + r.events + " events=" + events);
1959 }
1960 } finally {
1961 Binder.restoreCallingIdentity(callingIdentity);
1962 }
1963 return valid;
1964 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001965
1966 private boolean validatePhoneId(int phoneId) {
1967 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001968 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001969 return valid;
1970 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001971
1972 private static void log(String s) {
1973 Rlog.d(TAG, s);
1974 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001975
xinhe8b79fb62014-11-05 14:55:03 -08001976 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001977
1978 if(subId < 0) {
1979 // Invalid case, we need compare phoneId with default one.
1980 return (mDefaultPhoneId == phoneId);
1981 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001982 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001983 return (subId == mDefaultSubId);
1984 } else {
1985 return (rSubId == subId);
1986 }
1987 }
1988
Hall Liu5fb337f2017-11-22 17:38:15 -08001989 private boolean checkLocationAccess(Record r) {
1990 long token = Binder.clearCallingIdentity();
1991 try {
1992 return LocationAccessPolicy.canAccessCellLocation(mContext,
Svet Ganov33b15092018-03-07 19:53:43 -08001993 r.callingPackage, r.callerUid, r.callerPid,
1994 /*throwOnDeniedPermission*/ false);
Hall Liu5fb337f2017-11-22 17:38:15 -08001995 } finally {
1996 Binder.restoreCallingIdentity(token);
1997 }
1998 }
1999
xinhee9f16402014-09-25 16:39:28 -07002000 private void checkPossibleMissNotify(Record r, int phoneId) {
2001 int events = r.events;
2002
2003 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
2004 try {
2005 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
2006 mServiceState[phoneId]);
2007 r.callback.onServiceStateChanged(
2008 new ServiceState(mServiceState[phoneId]));
2009 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002010 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002011 }
2012 }
2013
2014 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
2015 try {
2016 SignalStrength signalStrength = mSignalStrength[phoneId];
2017 if (DBG) {
2018 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
2019 }
2020 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
2021 } catch (RemoteException ex) {
2022 mRemoveList.add(r.binder);
2023 }
2024 }
2025
2026 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
2027 try {
2028 int gsmSignalStrength = mSignalStrength[phoneId]
2029 .getGsmSignalStrength();
2030 if (DBG) {
2031 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
2032 gsmSignalStrength);
2033 }
2034 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
2035 : gsmSignalStrength));
2036 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002037 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002038 }
2039 }
2040
2041 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
2042 try {
2043 if (DBG_LOC) {
2044 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
2045 + mCellInfo.get(phoneId));
2046 }
Hall Liu5fb337f2017-11-22 17:38:15 -08002047 if (checkLocationAccess(r)) {
2048 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
2049 }
xinhee9f16402014-09-25 16:39:28 -07002050 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002051 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002052 }
2053 }
2054
zxuan35a47022018-01-04 11:24:04 -08002055 if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
2056 try {
2057 if (VDBG) {
2058 log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId="
2059 + phoneId + " umds=" + mUserMobileDataState[phoneId]);
2060 }
2061 r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]);
2062 } catch (RemoteException ex) {
2063 mRemoveList.add(r.binder);
2064 }
2065 }
2066
xinhee9f16402014-09-25 16:39:28 -07002067 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
2068 try {
2069 if (VDBG) {
2070 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
2071 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
2072 }
2073 r.callback.onMessageWaitingIndicatorChanged(
2074 mMessageWaiting[phoneId]);
2075 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002076 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002077 }
2078 }
2079
2080 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
2081 try {
2082 if (VDBG) {
2083 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
2084 + phoneId + " cfi=" + mCallForwarding[phoneId]);
2085 }
2086 r.callback.onCallForwardingIndicatorChanged(
2087 mCallForwarding[phoneId]);
2088 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002089 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002090 }
2091 }
2092
2093 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
2094 try {
2095 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
2096 + mCellLocation[phoneId]);
Hall Liu5fb337f2017-11-22 17:38:15 -08002097 if (checkLocationAccess(r)) {
2098 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
2099 }
xinhee9f16402014-09-25 16:39:28 -07002100 } catch (RemoteException ex) {
2101 mRemoveList.add(r.binder);
2102 }
2103 }
2104
2105 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
2106 try {
2107 if (DBG) {
2108 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
2109 + "=" + mDataConnectionState[phoneId]
2110 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
2111 + ")");
2112 }
2113 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
2114 mDataConnectionNetworkType[phoneId]);
2115 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07002116 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07002117 }
2118 }
2119 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120}