blob: 4ce76f4b96fe0cf412cdba6efc0c05317aa3d3ac [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
Wink Savillea12a7b32012-09-20 10:09:45 -070019import android.app.ActivityManager;
Svet Ganov16a16892015-04-16 10:32:04 -070020import android.app.AppOpsManager;
Wink Savillea12a7b32012-09-20 10:09:45 -070021import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
23import android.content.Intent;
Wink Savillea12a7b32012-09-20 10:09:45 -070024import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.pm.PackageManager;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070026import android.net.LinkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -070027import android.net.NetworkCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Binder;
29import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070030import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070032import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070034import android.os.UserHandle;
John Wang963db55d2012-03-30 16:04:06 -070035import android.telephony.CellInfo;
Jack Yud19b6ae2017-04-05 14:12:09 -070036import android.telephony.CellLocation;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020037import android.telephony.DisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070038import android.telephony.PhoneStateListener;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020039import android.telephony.PreciseCallState;
40import android.telephony.PreciseDataConnectionState;
41import android.telephony.PreciseDisconnectCause;
Jack Yud19b6ae2017-04-05 14:12:09 -070042import android.telephony.Rlog;
43import android.telephony.ServiceState;
44import android.telephony.SignalStrength;
45import android.telephony.SubscriptionManager;
46import android.telephony.TelephonyManager;
47import android.telephony.VoLteServiceState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import android.text.TextUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070049import android.util.LocalLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050
51import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080052import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import com.android.internal.telephony.IPhoneStateListener;
Jack Yud19b6ae2017-04-05 14:12:09 -070054import com.android.internal.telephony.ITelephonyRegistry;
Nathan Harold5a0618e2016-12-14 10:48:00 -080055import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070056import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import com.android.internal.telephony.TelephonyIntents;
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -060058import com.android.internal.util.DumpUtils;
Jack Yud19b6ae2017-04-05 14:12:09 -070059import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import com.android.server.am.BatteryStatsService;
61
Jack Yud19b6ae2017-04-05 14:12:09 -070062import java.io.FileDescriptor;
63import java.io.PrintWriter;
64import java.util.ArrayList;
65import java.util.Arrays;
66import java.util.List;
67
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068/**
Wink Savillee9b06d72009-05-18 21:47:50 -070069 * Since phone process can be restarted, this class provides a centralized place
70 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070071 *
72 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
73 * and 15973975 by saving the phoneId of the registrant and then using the
74 * phoneId when deciding to to make a callback. This is necessary because
75 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070076 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070077 * the dummy value conversion we properly do the callbacks.
78 *
79 * Eventually we may want to remove the notion of dummy value but for now this
80 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 */
82class TelephonyRegistry extends ITelephonyRegistry.Stub {
83 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070084 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070085 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070086 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087
88 private static class Record {
Svet Ganov16a16892015-04-16 10:32:04 -070089 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -080094 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -070095
Fyodor Kupolov309b2f632015-06-03 16:29:01 -070096 int callerUserId;
Wink Savillea12a7b32012-09-20 10:09:45 -070097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -070099
Wink Savilled09c4ca2014-11-22 10:08:16 -0800100 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700101
Wink Savilled09c4ca2014-11-22 10:08:16 -0800102 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800103
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700104 boolean canReadPhoneState;
105
Wink Savillea374c3d2014-11-11 11:48:04 -0800106 boolean matchPhoneStateListenerEvent(int events) {
107 return (callback != null) && ((events & this.events) != 0);
108 }
109
Wink Savilled09c4ca2014-11-22 10:08:16 -0800110 boolean matchOnSubscriptionsChangedListener() {
111 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800112 }
Wink Savillee380b982014-07-26 18:24:22 -0700113
Wink Savillea12a7b32012-09-20 10:09:45 -0700114 @Override
115 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700116 return "{callingPackage=" + callingPackage + " binder=" + binder
117 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800118 + " onSubscriptionsChangedListenererCallback="
119 + onSubscriptionsChangedListenerCallback
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700120 + " callerUserId=" + callerUserId + " subId=" + subId + " phoneId=" + phoneId
121 + " events=" + Integer.toHexString(events)
122 + " canReadPhoneState=" + canReadPhoneState + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700123 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 }
125
126 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700127
Joe Onorato163d8d92010-10-21 13:21:20 -0400128 // access should be inside synchronized (mRecords) for these two fields
129 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
130 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 private final IBatteryStats mBatteryStats;
133
Svet Ganov16a16892015-04-16 10:32:04 -0700134 private final AppOpsManager mAppOps;
135
Wink Savilled09c4ca2014-11-22 10:08:16 -0800136 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
137
Wink Savillefb40dd42014-06-12 17:02:31 -0700138 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700139
Wink Savillefb40dd42014-06-12 17:02:31 -0700140 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700141
Wink Savillefb40dd42014-06-12 17:02:31 -0700142 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700143
Wink Savillefb40dd42014-06-12 17:02:31 -0700144 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700145
fionaxu12312f62016-11-14 13:32:14 -0800146 private int[] mVoiceActivationState;
147
148 private int[] mDataActivationState;
149
Wink Savillefb40dd42014-06-12 17:02:31 -0700150 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700151
Wink Savillefb40dd42014-06-12 17:02:31 -0700152 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700153
Wink Savillefb40dd42014-06-12 17:02:31 -0700154 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700155
Wink Savillefb40dd42014-06-12 17:02:31 -0700156 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700157
Wink Savillefb40dd42014-06-12 17:02:31 -0700158 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700159
Wink Savillefb40dd42014-06-12 17:02:31 -0700160 private boolean[] mDataConnectionPossible;
Wink Savillee9b06d72009-05-18 21:47:50 -0700161
Wink Savillefb40dd42014-06-12 17:02:31 -0700162 private String[] mDataConnectionReason;
163
Yifan Bai57b39e32016-04-01 16:24:33 +0800164 private ArrayList<String>[] mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700165
Wink Savillefb40dd42014-06-12 17:02:31 -0700166 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700167
Wink Savillefb40dd42014-06-12 17:02:31 -0700168 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700169
Wink Savillefb40dd42014-06-12 17:02:31 -0700170 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171
Wink Savillefb40dd42014-06-12 17:02:31 -0700172 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700173
Nathan Harold016e9c62016-12-14 11:24:48 -0800174 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700175
Wink Savillefb40dd42014-06-12 17:02:31 -0700176 private ArrayList<List<CellInfo>> mCellInfo = null;
177
178 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
179
Wink Savilled09c4ca2014-11-22 10:08:16 -0800180 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700181
Wink Savilled09c4ca2014-11-22 10:08:16 -0800182 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700183
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200184 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
185
186 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
187
188 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
189
190 private PreciseCallState mPreciseCallState = new PreciseCallState();
191
Andrew Flynn1f452642015-04-14 22:16:04 -0400192 private boolean mCarrierNetworkChangeState = false;
193
Jack Yud19b6ae2017-04-05 14:12:09 -0700194 private final LocalLog mLocalLog = new LocalLog(100);
195
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200196 private PreciseDataConnectionState mPreciseDataConnectionState =
197 new PreciseDataConnectionState();
198
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700199 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700200 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700201 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
202 PhoneStateListener.LISTEN_VOLTE_STATE;
203
204 static final int CHECK_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700205 PhoneStateListener.LISTEN_CALL_STATE |
206 PhoneStateListener.LISTEN_DATA_ACTIVITY |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700207 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700208
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200209 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
210 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
211 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
212
Wink Savillea12a7b32012-09-20 10:09:45 -0700213 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700214 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700215
216 private final Handler mHandler = new Handler() {
217 @Override
218 public void handleMessage(Message msg) {
219 switch (msg.what) {
220 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700221 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700222 int numPhones = TelephonyManager.getDefault().getPhoneCount();
223 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700224 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700225 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700226 }
227 break;
228 }
xinhee9f16402014-09-25 16:39:28 -0700229 case MSG_UPDATE_DEFAULT_SUB: {
230 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700231 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700232 if (VDBG) {
233 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
234 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
235 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
236 }
237
238 //Due to possible risk condition,(notify call back using the new
239 //defaultSubId comes before new defaultSubId update) we need to recall all
240 //possible missed notify callback
241 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700242 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800243 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700244 checkPossibleMissNotify(r, newDefaultPhoneId);
245 }
246 }
247 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700248 }
249 mDefaultSubId = newDefaultSubId;
250 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700251 }
252 }
253 }
254 };
255
256 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
257 @Override
258 public void onReceive(Context context, Intent intent) {
259 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700260 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700261 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700262 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700263 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700264 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700265 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700266 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800267 PhoneConstants.SUBSCRIPTION_KEY,
268 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700269 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
270 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700271 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700272 log("onReceive:current mDefaultSubId=" + mDefaultSubId
273 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
274 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700275 }
xinhee9f16402014-09-25 16:39:28 -0700276
Junda Liu985f52c2015-02-23 16:06:51 -0800277 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700278 || (newDefaultPhoneId != mDefaultPhoneId))) {
279 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
280 newDefaultPhoneId, 0, newDefaultSubIdObj));
281 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700282 }
283 }
284 };
285
Wink Savillee9b06d72009-05-18 21:47:50 -0700286 // we keep a copy of all of the state so we can send it out when folks
287 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800288 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700289 // In these calls we call with the lock held. This is safe becasuse remote
290 // calls go through a oneway interface and local calls going through a
291 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292
293 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700294 CellLocation location = CellLocation.getEmpty();
295
Wink Savillefb40dd42014-06-12 17:02:31 -0700296 mContext = context;
297 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700298
Wink Savillefb40dd42014-06-12 17:02:31 -0700299 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700300 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700301 mNumPhones = numPhones;
Yifan Bai57b39e32016-04-01 16:24:33 +0800302 mConnectedApns = new ArrayList[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700303 mCallState = new int[numPhones];
304 mDataActivity = new int[numPhones];
305 mDataConnectionState = new int[numPhones];
306 mDataConnectionNetworkType = new int[numPhones];
307 mCallIncomingNumber = new String[numPhones];
308 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800309 mVoiceActivationState = new int[numPhones];
310 mDataActivationState = new int[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700311 mSignalStrength = new SignalStrength[numPhones];
312 mMessageWaiting = new boolean[numPhones];
313 mDataConnectionPossible = new boolean[numPhones];
314 mDataConnectionReason = new String[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700315 mCallForwarding = new boolean[numPhones];
316 mCellLocation = new Bundle[numPhones];
317 mDataConnectionLinkProperties = new LinkProperties[numPhones];
318 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
319 mCellInfo = new ArrayList<List<CellInfo>>();
320 for (int i = 0; i < numPhones; i++) {
321 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
322 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
323 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800324 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
325 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700326 mCallIncomingNumber[i] = "";
327 mServiceState[i] = new ServiceState();
328 mSignalStrength[i] = new SignalStrength();
329 mMessageWaiting[i] = false;
330 mCallForwarding[i] = false;
331 mDataConnectionPossible[i] = false;
332 mDataConnectionReason[i] = "";
Wink Savillefb40dd42014-06-12 17:02:31 -0700333 mCellLocation[i] = new Bundle();
334 mCellInfo.add(i, null);
Yifan Bai57b39e32016-04-01 16:24:33 +0800335 mConnectedApns[i] = new ArrayList<String>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700336 }
337
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700338 // Note that location can be null for non-phone builds like
339 // like the generic one.
340 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700341 for (int i = 0; i < numPhones; i++) {
342 location.fillInNotifierBundle(mCellLocation[i]);
343 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700344 }
Svet Ganov16a16892015-04-16 10:32:04 -0700345
346 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 }
348
Svetoslav Ganova0027152013-06-25 14:59:53 -0700349 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700350 // Watch for interesting updates
351 final IntentFilter filter = new IntentFilter();
352 filter.addAction(Intent.ACTION_USER_SWITCHED);
353 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700354 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700355 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700356 mContext.registerReceiver(mBroadcastReceiver, filter);
357 }
358
359 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700360 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800361 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700362 int callerUserId = UserHandle.getCallingUserId();
Wink Savillea374c3d2014-11-11 11:48:04 -0800363 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700364 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
365 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800366 + " callback.asBinder=" + callback.asBinder());
367 }
368
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700369 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700370 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700371 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
372 "addOnSubscriptionsChangedListener");
Amit Mahajana9e72a72015-07-30 16:04:13 -0700373 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700374 } catch (SecurityException e) {
375 mContext.enforceCallingOrSelfPermission(
376 android.Manifest.permission.READ_PHONE_STATE,
377 "addOnSubscriptionsChangedListener");
Svet Ganov16a16892015-04-16 10:32:04 -0700378
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700379 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
380 callingPackage) != AppOpsManager.MODE_ALLOWED) {
381 return;
382 }
Svet Ganov16a16892015-04-16 10:32:04 -0700383 }
384
Fyodor Kupolovac038a92015-06-09 13:14:54 -0700385 Record r;
Wink Savillea374c3d2014-11-11 11:48:04 -0800386
Wink Savilled09c4ca2014-11-22 10:08:16 -0800387 synchronized (mRecords) {
388 // register
389 find_and_add: {
390 IBinder b = callback.asBinder();
391 final int N = mRecords.size();
392 for (int i = 0; i < N; i++) {
393 r = mRecords.get(i);
394 if (b == r.binder) {
395 break find_and_add;
Wink Savillea374c3d2014-11-11 11:48:04 -0800396 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800397 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800398 r = new Record();
399 r.binder = b;
400 mRecords.add(r);
401 if (DBG) log("listen oscl: add new record");
Wink Savillea374c3d2014-11-11 11:48:04 -0800402 }
403
Wink Savilled09c4ca2014-11-22 10:08:16 -0800404 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700405 r.callingPackage = callingPackage;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700406 r.callerUserId = callerUserId;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800407 r.events = 0;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700408 r.canReadPhoneState = true; // permission has been enforced above
Wink Savilled09c4ca2014-11-22 10:08:16 -0800409 if (DBG) {
410 log("listen oscl: Register r=" + r);
411 }
412 // Always notify when registration occurs if there has been a notification.
413 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800414 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800415 if (VDBG) log("listen oscl: send to r=" + r);
416 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
417 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800418 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800419 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800420 remove(r.binder);
421 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800422 } else {
423 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800424 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800425 }
426 }
427
428 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800429 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800430 IOnSubscriptionsChangedListener callback) {
431 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800432 remove(callback.asBinder());
433 }
434
Wink Savillea374c3d2014-11-11 11:48:04 -0800435 @Override
436 public void notifySubscriptionInfoChanged() {
437 if (VDBG) log("notifySubscriptionInfoChanged:");
438 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800439 if (!hasNotifySubscriptionInfoChangedOccurred) {
440 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
441 + mRecords.size());
442 }
443 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800444 mRemoveList.clear();
445 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800446 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800447 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800448 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
449 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
450 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800451 } catch (RemoteException ex) {
452 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
453 mRemoveList.add(r.binder);
454 }
455 }
456 }
457 handleRemoveListLocked();
458 }
459 }
460
461 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
463 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800464 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
465 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700466 }
467
468 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700469 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700470 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700471 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700472 }
473
Svet Ganov16a16892015-04-16 10:32:04 -0700474 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700475 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700476 int callerUserId = UserHandle.getCallingUserId();
Wink Savillee380b982014-07-26 18:24:22 -0700477 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700478 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700479 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
480 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700481 }
xinhe75c2c152014-10-16 11:49:45 -0700482
483 if (events != PhoneStateListener.LISTEN_NONE) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700484 /* Checks permission and throws Security exception */
485 checkListenerPermission(events);
Svet Ganov16a16892015-04-16 10:32:04 -0700486
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700487 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700488 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700489 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700490 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -0700491 // SKIP checking for run-time permission since caller or self has PRIVILEGED
492 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700493 } catch (SecurityException e) {
494 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
495 callingPackage) != AppOpsManager.MODE_ALLOWED) {
496 return;
497 }
Svet Ganov16a16892015-04-16 10:32:04 -0700498 }
499 }
500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 synchronized (mRecords) {
502 // register
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700503 Record r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 find_and_add: {
505 IBinder b = callback.asBinder();
506 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700507 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 r = mRecords.get(i);
509 if (b == r.binder) {
510 break find_and_add;
511 }
512 }
513 r = new Record();
514 r.binder = b;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 mRecords.add(r);
Wink Savillee380b982014-07-26 18:24:22 -0700516 if (DBG) log("listen: add new record");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 }
xinhe43c50292014-09-18 17:56:48 -0700518
xinhe75c2c152014-10-16 11:49:45 -0700519 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700520 r.callingPackage = callingPackage;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700521 r.callerUserId = callerUserId;
522 boolean isPhoneStateEvent = (events & (CHECK_PHONE_STATE_PERMISSION_MASK
523 | ENFORCE_PHONE_STATE_PERMISSION_MASK)) != 0;
524 r.canReadPhoneState = isPhoneStateEvent && canReadPhoneState(callingPackage);
xinhe75c2c152014-10-16 11:49:45 -0700525 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
526 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800527 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800528 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700529 } else {//APP specify subID
530 r.subId = subId;
531 }
532 r.phoneId = SubscriptionManager.getPhoneId(r.subId);
533
xinhe43c50292014-09-18 17:56:48 -0700534 int phoneId = r.phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700536 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700537 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700538 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700539 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400541 try {
Wink Savillee380b982014-07-26 18:24:22 -0700542 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700543 r.callback.onServiceStateChanged(
544 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400545 } catch (RemoteException ex) {
546 remove(r.binder);
547 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 }
549 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
550 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700551 int gsmSignalStrength = mSignalStrength[phoneId]
552 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700553 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
554 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 } catch (RemoteException ex) {
556 remove(r.binder);
557 }
558 }
559 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
560 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700561 r.callback.onMessageWaitingIndicatorChanged(
562 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 } catch (RemoteException ex) {
564 remove(r.binder);
565 }
566 }
567 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
568 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700569 r.callback.onCallForwardingIndicatorChanged(
570 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 } catch (RemoteException ex) {
572 remove(r.binder);
573 }
574 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700575 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400576 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700577 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700578 + mCellLocation[phoneId]);
579 r.callback.onCellLocationChanged(
580 new Bundle(mCellLocation[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400581 } catch (RemoteException ex) {
582 remove(r.binder);
583 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 }
585 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
586 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700587 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700588 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 } catch (RemoteException ex) {
590 remove(r.binder);
591 }
592 }
593 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
594 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700595 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
596 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800597 } catch (RemoteException ex) {
598 remove(r.binder);
599 }
600 }
601 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
602 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700603 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 } catch (RemoteException ex) {
605 remove(r.binder);
606 }
607 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700608 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
609 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700610 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700611 } catch (RemoteException ex) {
612 remove(r.binder);
613 }
614 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700615 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
616 try {
617 r.callback.onOtaspChanged(mOtaspMode);
618 } catch (RemoteException ex) {
619 remove(r.binder);
620 }
621 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700622 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700623 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700624 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700625 + mCellInfo.get(phoneId));
626 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
John Wang963db55d2012-03-30 16:04:06 -0700627 } catch (RemoteException ex) {
628 remove(r.binder);
629 }
630 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200631 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
632 try {
633 r.callback.onPreciseCallStateChanged(mPreciseCallState);
634 } catch (RemoteException ex) {
635 remove(r.binder);
636 }
637 }
638 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
639 try {
640 r.callback.onPreciseDataConnectionStateChanged(
641 mPreciseDataConnectionState);
642 } catch (RemoteException ex) {
643 remove(r.binder);
644 }
645 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400646 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
647 try {
648 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
649 } catch (RemoteException ex) {
650 remove(r.binder);
651 }
652 }
fionaxu12312f62016-11-14 13:32:14 -0800653 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
654 try {
655 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
656 } catch (RemoteException ex) {
657 remove(r.binder);
658 }
659 }
660 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
661 try {
662 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
663 } catch (RemoteException ex) {
664 remove(r.binder);
665 }
666 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 }
668 }
669 } else {
xinhe75c2c152014-10-16 11:49:45 -0700670 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671 remove(callback.asBinder());
672 }
673 }
674
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700675 private boolean canReadPhoneState(String callingPackage) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700676 if (mContext.checkCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700677 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) ==
678 PackageManager.PERMISSION_GRANTED) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700679 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700680 return true;
681 }
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700682 boolean canReadPhoneState = mContext.checkCallingOrSelfPermission(
683 android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
684 if (canReadPhoneState &&
685 mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
686 callingPackage) != AppOpsManager.MODE_ALLOWED) {
687 return false;
688 }
689 return canReadPhoneState;
690 }
691
692 private String getCallIncomingNumber(Record record, int phoneId) {
693 // Hide the number if record's process has no READ_PHONE_STATE permission
694 return record.canReadPhoneState ? mCallIncomingNumber[phoneId] : "";
695 }
696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800697 private void remove(IBinder binder) {
698 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700699 final int recordCount = mRecords.size();
700 for (int i = 0; i < recordCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 if (mRecords.get(i).binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800702 if (DBG) {
703 Record r = mRecords.get(i);
Svet Ganov16a16892015-04-16 10:32:04 -0700704 log("remove: binder=" + binder + "r.callingPackage" + r.callingPackage
xinheac11ae92014-12-18 10:02:14 -0800705 + "r.callback" + r.callback);
706 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 mRecords.remove(i);
708 return;
709 }
710 }
711 }
712 }
713
714 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700715 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700716 return;
717 }
xinhe43c50292014-09-18 17:56:48 -0700718
719 if (VDBG) {
720 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
721 }
722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700724 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800725 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800726 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700728 String incomingNumberOrEmpty = r.canReadPhoneState ? incomingNumber : "";
729 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400731 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 }
733 }
734 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400735 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700737
738 // Called only by Telecomm to communicate call state across different phone accounts. So
739 // there is no need to add a valid subId or slotId.
Wink Savilled09c4ca2014-11-22 10:08:16 -0800740 broadcastCallStateChanged(state, incomingNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700741 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700742 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 }
744
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700745 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
746 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700747 if (!checkNotifyPermission("notifyCallState()")) {
748 return;
749 }
Wink Savillee380b982014-07-26 18:24:22 -0700750 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700751 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700752 + " state=" + state + " incomingNumber=" + incomingNumber);
753 }
754 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700755 if (validatePhoneId(phoneId)) {
756 mCallState[phoneId] = state;
757 mCallIncomingNumber[phoneId] = incomingNumber;
758 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800759 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700760 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800761 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700762 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700763 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
764 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700765 } catch (RemoteException ex) {
766 mRemoveList.add(r.binder);
767 }
768 }
769 }
770 }
771 handleRemoveListLocked();
772 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700773 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700774 }
775
Wink Saville63f03dd2014-10-23 10:44:45 -0700776 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700777 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700778 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700779 }
xinhe43c50292014-09-18 17:56:48 -0700780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800781 synchronized (mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700782 String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
783 + " state=" + state;
Wink Savillee380b982014-07-26 18:24:22 -0700784 if (VDBG) {
Jack Yud19b6ae2017-04-05 14:12:09 -0700785 log(str);
Wink Saville47d8d1b2014-07-10 13:01:52 -0700786 }
Jack Yud19b6ae2017-04-05 14:12:09 -0700787 mLocalLog.log(str);
Wink Savillefb40dd42014-06-12 17:02:31 -0700788 if (validatePhoneId(phoneId)) {
789 mServiceState[phoneId] = state;
Wink Saville47d8d1b2014-07-10 13:01:52 -0700790
Wink Savillefb40dd42014-06-12 17:02:31 -0700791 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700792 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700793 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700794 + " phoneId=" + phoneId + " state=" + state);
795 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800796 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800797 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700798 try {
Wink Savillee380b982014-07-26 18:24:22 -0700799 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700800 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700801 + " subId=" + subId + " phoneId=" + phoneId
802 + " state=" + state);
803 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700804 r.callback.onServiceStateChanged(new ServiceState(state));
805 } catch (RemoteException ex) {
806 mRemoveList.add(r.binder);
807 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400808 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800809 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700810 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700811 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400813 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700815 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800816 }
817
fionaxu12312f62016-11-14 13:32:14 -0800818 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
819 int activationType, int activationState) {
820 if (!checkNotifyPermission("notifySimActivationState()")){
821 return;
822 }
823 if (VDBG) {
824 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
825 + "type=" + activationType + " state=" + activationState);
826 }
827 synchronized (mRecords) {
828 if (validatePhoneId(phoneId)) {
829 switch (activationType) {
830 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
831 mVoiceActivationState[phoneId] = activationState;
832 break;
833 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
834 mDataActivationState[phoneId] = activationState;
835 break;
836 default:
837 return;
838 }
839 for (Record r : mRecords) {
840 if (VDBG) {
841 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
842 + " phoneId=" + phoneId + "type=" + activationType
843 + " state=" + activationState);
844 }
845 try {
846 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
847 r.matchPhoneStateListenerEvent(
848 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
849 idMatch(r.subId, subId, phoneId)) {
850 if (DBG) {
851 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
852 + " subId=" + subId + " phoneId=" + phoneId
853 + " state=" + activationState);
854 }
855 r.callback.onVoiceActivationStateChanged(activationState);
856 }
857 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
858 r.matchPhoneStateListenerEvent(
859 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
860 idMatch(r.subId, subId, phoneId)) {
861 if (DBG) {
862 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
863 + " subId=" + subId + " phoneId=" + phoneId
864 + " state=" + activationState);
865 }
866 r.callback.onDataActivationStateChanged(activationState);
867 }
868 } catch (RemoteException ex) {
869 mRemoveList.add(r.binder);
870 }
871 }
872 } else {
873 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
874 }
875 handleRemoveListLocked();
876 }
877 }
878
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700879 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
880 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700881 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700882 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700883 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000884 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700885 log("notifySignalStrengthForPhoneId: subId=" + subId
886 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000887 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800889 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700890 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700891 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700892 mSignalStrength[phoneId] = signalStrength;
893 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000894 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700895 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000896 + " phoneId=" + phoneId + " ss=" + signalStrength);
897 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800898 if (r.matchPhoneStateListenerEvent(
899 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800900 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700901 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000902 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700903 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000904 + " subId=" + subId + " phoneId=" + phoneId
905 + " ss=" + signalStrength);
906 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700907 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
908 } catch (RemoteException ex) {
909 mRemoveList.add(r.binder);
910 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400911 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800912 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800913 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700914 try {
915 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700916 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000917 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700918 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000919 + " subId=" + subId + " phoneId=" + phoneId
920 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
921 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700922 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700923 } catch (RemoteException ex) {
924 mRemoveList.add(r.binder);
925 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 }
927 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700928 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700929 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400931 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700933 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 }
935
Andrew Flynn1f452642015-04-14 22:16:04 -0400936 @Override
937 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +0000938 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
939
Andrew Flynn1f452642015-04-14 22:16:04 -0400940 if (VDBG) {
941 log("notifyCarrierNetworkChange: active=" + active);
942 }
943
944 synchronized (mRecords) {
945 mCarrierNetworkChangeState = active;
946 for (Record r : mRecords) {
947 if (r.matchPhoneStateListenerEvent(
948 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
949 try {
950 r.callback.onCarrierNetworkChange(active);
951 } catch (RemoteException ex) {
952 mRemoveList.add(r.binder);
953 }
954 }
955 }
956 handleRemoveListLocked();
957 }
958 }
959
Wink Savilleb208a242012-07-25 14:08:09 -0700960 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800961 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700962 }
963
Wink Saville63f03dd2014-10-23 10:44:45 -0700964 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700965 if (!checkNotifyPermission("notifyCellInfo()")) {
966 return;
967 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700968 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700969 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700970 + " cellInfo=" + cellInfo);
971 }
John Wang963db55d2012-03-30 16:04:06 -0700972
973 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700974 int phoneId = SubscriptionManager.getPhoneId(subId);
975 if (validatePhoneId(phoneId)) {
976 mCellInfo.set(phoneId, cellInfo);
977 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -0700978 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
xinhe8b79fb62014-11-05 14:55:03 -0800979 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700980 try {
981 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700982 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -0700983 }
984 r.callback.onCellInfoChanged(cellInfo);
985 } catch (RemoteException ex) {
986 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700987 }
John Wang963db55d2012-03-30 16:04:06 -0700988 }
989 }
990 }
991 handleRemoveListLocked();
992 }
993 }
994
xinhe43c50292014-09-18 17:56:48 -0700995 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700996 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700997 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700998 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700999 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001000 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001001 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001002 + " mwi=" + mwi);
1003 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001005 if (validatePhoneId(phoneId)) {
1006 mMessageWaiting[phoneId] = mwi;
1007 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001008 if (r.matchPhoneStateListenerEvent(
1009 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001010 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001011 try {
1012 r.callback.onMessageWaitingIndicatorChanged(mwi);
1013 } catch (RemoteException ex) {
1014 mRemoveList.add(r.binder);
1015 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001016 }
1017 }
1018 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001019 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 }
1021 }
1022
1023 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001024 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001025 }
1026
Wink Saville63f03dd2014-10-23 10:44:45 -07001027 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001028 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001029 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001030 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001031 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001032 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001033 + " cfi=" + cfi);
1034 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001036 int phoneId = SubscriptionManager.getPhoneId(subId);
1037 if (validatePhoneId(phoneId)) {
1038 mCallForwarding[phoneId] = cfi;
1039 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001040 if (r.matchPhoneStateListenerEvent(
1041 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001042 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001043 try {
1044 r.callback.onCallForwardingIndicatorChanged(cfi);
1045 } catch (RemoteException ex) {
1046 mRemoveList.add(r.binder);
1047 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 }
1049 }
1050 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001051 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 }
1053 }
1054
1055 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001056 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001057 }
1058
Wink Saville63f03dd2014-10-23 10:44:45 -07001059 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001060 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001061 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001062 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001064 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001065 if (validatePhoneId(phoneId)) {
1066 mDataActivity[phoneId] = state;
1067 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001068 // Notify by correct subId.
1069 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1070 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001071 try {
1072 r.callback.onDataActivity(state);
1073 } catch (RemoteException ex) {
1074 mRemoveList.add(r.binder);
1075 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 }
1077 }
1078 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001079 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 }
1081 }
1082
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001083 public void notifyDataConnection(int state, boolean isDataConnectivityPossible,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001084 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001085 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001086 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
xinhe43c50292014-09-18 17:56:48 -07001087 isDataConnectivityPossible,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001088 networkCapabilities, networkType, roaming);
1089 }
1090
Wink Saville63f03dd2014-10-23 10:44:45 -07001091 public void notifyDataConnectionForSubscriber(int subId, int state,
Wink Savillefb40dd42014-06-12 17:02:31 -07001092 boolean isDataConnectivityPossible, String reason, String apn, String apnType,
1093 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1094 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001095 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001096 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001097 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001098 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001099 log("notifyDataConnectionForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001100 + " state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible
1101 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001102 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001103 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001104 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001106 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001107 if (validatePhoneId(phoneId)) {
1108 boolean modified = false;
1109 if (state == TelephonyManager.DATA_CONNECTED) {
Yifan Bai57b39e32016-04-01 16:24:33 +08001110 if (!mConnectedApns[phoneId].contains(apnType)) {
1111 mConnectedApns[phoneId].add(apnType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001112 if (mDataConnectionState[phoneId] != state) {
1113 mDataConnectionState[phoneId] = state;
1114 modified = true;
1115 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001117 } else {
Yifan Bai57b39e32016-04-01 16:24:33 +08001118 if (mConnectedApns[phoneId].remove(apnType)) {
1119 if (mConnectedApns[phoneId].isEmpty()) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001120 mDataConnectionState[phoneId] = state;
1121 modified = true;
1122 } else {
1123 // leave mDataConnectionState as is and
1124 // send out the new status for the APN in question.
Wink Savillebaf21da2014-11-19 16:03:09 -08001125 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001126 }
1127 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001128 mDataConnectionPossible[phoneId] = isDataConnectivityPossible;
1129 mDataConnectionReason[phoneId] = reason;
1130 mDataConnectionLinkProperties[phoneId] = linkProperties;
1131 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
1132 if (mDataConnectionNetworkType[phoneId] != networkType) {
1133 mDataConnectionNetworkType[phoneId] = networkType;
1134 // need to tell registered listeners about the new network type
1135 modified = true;
1136 }
1137 if (modified) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001138 String str = "onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
1139 + ", " + mDataConnectionNetworkType[phoneId] + ")";
1140 log(str);
1141 mLocalLog.log(str);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001142 for (Record r : mRecords) {
1143 if (r.matchPhoneStateListenerEvent(
1144 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1145 idMatch(r.subId, subId, phoneId)) {
1146 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001147 if (DBG) {
1148 log("Notify data connection state changed on sub: " + subId);
1149 }
1150 r.callback.onDataConnectionStateChanged(
1151 mDataConnectionState[phoneId],
Wink Savilled09c4ca2014-11-22 10:08:16 -08001152 mDataConnectionNetworkType[phoneId]);
1153 } catch (RemoteException ex) {
1154 mRemoveList.add(r.binder);
1155 }
1156 }
1157 }
1158 handleRemoveListLocked();
1159 }
1160 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1161 apnType, apn, reason, linkProperties, "");
1162 for (Record r : mRecords) {
1163 if (r.matchPhoneStateListenerEvent(
1164 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1165 try {
Jack Yud19b6ae2017-04-05 14:12:09 -07001166 r.callback.onPreciseDataConnectionStateChanged(
1167 mPreciseDataConnectionState);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001168 } catch (RemoteException ex) {
1169 mRemoveList.add(r.binder);
1170 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001171 }
1172 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001173 }
1174 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001176 broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001177 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001178 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1179 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180 }
1181
Robert Greenwalt02648a42010-05-18 10:52:51 -07001182 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001183 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001184 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001185 }
1186
Wink Saville63f03dd2014-10-23 10:44:45 -07001187 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001188 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001189 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001190 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001191 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001192 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001193 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001194 + " reason=" + reason + " apnType=" + apnType);
1195 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001196 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001197 mPreciseDataConnectionState = new PreciseDataConnectionState(
1198 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1199 apnType, "", reason, null, "");
1200 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001201 if (r.matchPhoneStateListenerEvent(
1202 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001203 try {
1204 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1205 } catch (RemoteException ex) {
1206 mRemoveList.add(r.binder);
1207 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 }
1209 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001210 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001212 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001213 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1214 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001215 }
1216
1217 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001218 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001219 }
1220
Wink Saville63f03dd2014-10-23 10:44:45 -07001221 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001222 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001223 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001224 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001225 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001226 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001227 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001228 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001229 + " cellLocation=" + cellLocation);
1230 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001231 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001232 int phoneId = SubscriptionManager.getPhoneId(subId);
1233 if (validatePhoneId(phoneId)) {
1234 mCellLocation[phoneId] = cellLocation;
1235 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001236 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
xinhe8b79fb62014-11-05 14:55:03 -08001237 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001238 try {
1239 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001240 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001241 + " r=" + r);
1242 }
1243 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1244 } catch (RemoteException ex) {
1245 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001246 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001247 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 }
1249 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001250 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001251 }
1252 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253
Wink Savillefd2d0132010-10-28 14:22:26 -07001254 public void notifyOtaspChanged(int otaspMode) {
1255 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1256 return;
1257 }
1258 synchronized (mRecords) {
1259 mOtaspMode = otaspMode;
1260 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001261 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001262 try {
1263 r.callback.onOtaspChanged(otaspMode);
1264 } catch (RemoteException ex) {
1265 mRemoveList.add(r.binder);
1266 }
1267 }
1268 }
1269 handleRemoveListLocked();
1270 }
1271 }
1272
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001273 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1274 int backgroundCallState) {
1275 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1276 return;
1277 }
1278 synchronized (mRecords) {
1279 mRingingCallState = ringingCallState;
1280 mForegroundCallState = foregroundCallState;
1281 mBackgroundCallState = backgroundCallState;
1282 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1283 backgroundCallState,
1284 DisconnectCause.NOT_VALID,
1285 PreciseDisconnectCause.NOT_VALID);
1286 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001287 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001288 try {
1289 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1290 } catch (RemoteException ex) {
1291 mRemoveList.add(r.binder);
1292 }
1293 }
1294 }
1295 handleRemoveListLocked();
1296 }
1297 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1298 DisconnectCause.NOT_VALID,
1299 PreciseDisconnectCause.NOT_VALID);
1300 }
1301
1302 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1303 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1304 return;
1305 }
1306 synchronized (mRecords) {
1307 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1308 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1309 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001310 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001311 try {
1312 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1313 } catch (RemoteException ex) {
1314 mRemoveList.add(r.binder);
1315 }
1316 }
1317 }
1318 handleRemoveListLocked();
1319 }
1320 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1321 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1322 }
1323
1324 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1325 String apn, String failCause) {
1326 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1327 return;
1328 }
1329 synchronized (mRecords) {
1330 mPreciseDataConnectionState = new PreciseDataConnectionState(
1331 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1332 apnType, apn, reason, null, failCause);
1333 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001334 if (r.matchPhoneStateListenerEvent(
1335 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001336 try {
1337 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1338 } catch (RemoteException ex) {
1339 mRemoveList.add(r.binder);
1340 }
1341 }
1342 }
1343 handleRemoveListLocked();
1344 }
1345 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1346 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1347 }
1348
Wink Savillefb40dd42014-06-12 17:02:31 -07001349 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1350 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1351 return;
1352 }
1353 synchronized (mRecords) {
1354 mVoLteServiceState = lteState;
1355 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001356 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001357 try {
1358 r.callback.onVoLteServiceStateChanged(
1359 new VoLteServiceState(mVoLteServiceState));
1360 } catch (RemoteException ex) {
1361 mRemoveList.add(r.binder);
1362 }
1363 }
1364 }
1365 handleRemoveListLocked();
1366 }
1367 }
1368
Wink Saville63f03dd2014-10-23 10:44:45 -07001369 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001370 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1371 return;
1372 }
1373
1374 synchronized (mRecords) {
1375 for (Record r : mRecords) {
1376 if (VDBG) {
1377 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1378 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001379 if ((r.matchPhoneStateListenerEvent(
1380 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
New Author Steven Liu485f2092014-09-11 10:18:45 -05001381 ((r.subId == subId) ||
Wink Savilled09c4ca2014-11-22 10:08:16 -08001382 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001383 try {
1384 r.callback.onOemHookRawEvent(rawData);
1385 } catch (RemoteException ex) {
1386 mRemoveList.add(r.binder);
1387 }
1388 }
1389 }
1390 handleRemoveListLocked();
1391 }
1392 }
1393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001394 @Override
Jack Yud19b6ae2017-04-05 14:12:09 -07001395 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1396 final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
1397
Jeff Sharkeyfe9a53b2017-03-31 14:08:23 -06001398 if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
Jack Yud19b6ae2017-04-05 14:12:09 -07001399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001400 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001401 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001402 pw.println("last known state:");
Jack Yud19b6ae2017-04-05 14:12:09 -07001403 pw.increaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301404 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001405 pw.println("Phone Id=" + i);
1406 pw.increaseIndent();
1407 pw.println("mCallState=" + mCallState[i]);
1408 pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]);
1409 pw.println("mServiceState=" + mServiceState[i]);
1410 pw.println("mVoiceActivationState= " + mVoiceActivationState[i]);
1411 pw.println("mDataActivationState= " + mDataActivationState[i]);
1412 pw.println("mSignalStrength=" + mSignalStrength[i]);
1413 pw.println("mMessageWaiting=" + mMessageWaiting[i]);
1414 pw.println("mCallForwarding=" + mCallForwarding[i]);
1415 pw.println("mDataActivity=" + mDataActivity[i]);
1416 pw.println("mDataConnectionState=" + mDataConnectionState[i]);
1417 pw.println("mDataConnectionPossible=" + mDataConnectionPossible[i]);
1418 pw.println("mDataConnectionReason=" + mDataConnectionReason[i]);
1419 pw.println("mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1420 pw.println("mDataConnectionNetworkCapabilities=" +
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301421 mDataConnectionNetworkCapabilities[i]);
Jack Yud19b6ae2017-04-05 14:12:09 -07001422 pw.println("mCellLocation=" + mCellLocation[i]);
1423 pw.println("mCellInfo=" + mCellInfo.get(i));
1424 pw.decreaseIndent();
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301425 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001426 pw.println("mConnectedApns=" + Arrays.toString(mConnectedApns));
1427 pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState);
1428 pw.println("mPreciseCallState=" + mPreciseCallState);
1429 pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);
1430 pw.println("mRingingCallState=" + mRingingCallState);
1431 pw.println("mForegroundCallState=" + mForegroundCallState);
1432 pw.println("mBackgroundCallState=" + mBackgroundCallState);
1433 pw.println("mVoLteServiceState=" + mVoLteServiceState);
1434
1435 pw.decreaseIndent();
1436
1437 pw.println("local logs:");
1438 pw.increaseIndent();
1439 mLocalLog.dump(fd, pw, args);
1440 pw.decreaseIndent();
Wink Savillee9b06d72009-05-18 21:47:50 -07001441 pw.println("registrations: count=" + recordCount);
Jack Yud19b6ae2017-04-05 14:12:09 -07001442 pw.increaseIndent();
Robert Greenwalt02648a42010-05-18 10:52:51 -07001443 for (Record r : mRecords) {
Jack Yud19b6ae2017-04-05 14:12:09 -07001444 pw.println(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001445 }
Jack Yud19b6ae2017-04-05 14:12:09 -07001446 pw.decreaseIndent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001447 }
1448 }
1449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001450 //
1451 // the legacy intent broadcasting
1452 //
1453
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001454 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001455 long ident = Binder.clearCallingIdentity();
1456 try {
1457 mBatteryStats.notePhoneState(state.getState());
1458 } catch (RemoteException re) {
1459 // Can't do much
1460 } finally {
1461 Binder.restoreCallingIdentity(ident);
1462 }
1463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001465 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001466 Bundle data = new Bundle();
1467 state.fillInNotifierBundle(data);
1468 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001469 // Pass the subscription along with the intent.
1470 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001471 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001472 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 }
1474
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001475 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1476 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001477 long ident = Binder.clearCallingIdentity();
1478 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001479 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001480 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001481 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001482 } finally {
1483 Binder.restoreCallingIdentity(ident);
1484 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001487 Bundle data = new Bundle();
1488 signalStrength.fillInNotifierBundle(data);
1489 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001490 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001491 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001492 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 }
1494
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001495 /**
1496 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1497 * a valid subId, in which case this function fires a subId-specific intent, or it
1498 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1499 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1500 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001501 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1502 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001503 long ident = Binder.clearCallingIdentity();
1504 try {
1505 if (state == TelephonyManager.CALL_STATE_IDLE) {
1506 mBatteryStats.notePhoneOff();
1507 } else {
1508 mBatteryStats.notePhoneOn();
1509 }
1510 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001511 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001512 } finally {
1513 Binder.restoreCallingIdentity(ident);
1514 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001517 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001518 PhoneConstantConversions.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001519 if (!TextUtils.isEmpty(incomingNumber)) {
1520 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1521 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001522
1523 // If a valid subId was specified, we should fire off a subId-specific state
1524 // change intent and include the subId.
1525 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1526 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1527 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1528 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001529 // If the phoneId is invalid, the broadcast is for overall call state.
1530 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1531 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1532 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001533
Brad Ebinger51de96a2017-04-21 17:05:18 -07001534 // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast.
1535 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
1536
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001537 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1538 // that have the runtime one
1539 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1540 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001541 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001542 android.Manifest.permission.READ_PHONE_STATE,
1543 AppOpsManager.OP_READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 }
1545
Robert Greenwalt42acef32009-08-12 16:08:25 -07001546 private void broadcastDataConnectionStateChanged(int state,
1547 boolean isDataConnectivityPossible,
Wink Savillef61101f2010-09-16 16:36:42 -07001548 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001549 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001550 // Note: not reporting to the battery stats service here, because the
1551 // status bar takes care of that after taking into account all of the
1552 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001553 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001554 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001555 PhoneConstantConversions.convertDataState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001556 if (!isDataConnectivityPossible) {
Wink Savillea639b312012-07-10 12:37:54 -07001557 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001558 }
1559 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001560 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001562 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001563 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001564 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001565 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001566 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001567 }
1568 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001569 if (networkCapabilities != null) {
1570 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001571 }
Wink Savillea639b312012-07-10 12:37:54 -07001572 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001573
Wink Savillea639b312012-07-10 12:37:54 -07001574 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1575 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001576 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001577 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 }
1579
Wink Savillefb40dd42014-06-12 17:02:31 -07001580 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001581 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001582 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001583 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1584 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001585 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001586 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001588
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001589 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1590 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1591 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1592 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1593 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1594 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1595 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1596 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1597 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1598 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1599 }
1600
1601 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001602 String apnType, String apn, String reason, LinkProperties linkProperties,
1603 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001604 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1605 intent.putExtra(PhoneConstants.STATE_KEY, state);
1606 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1607 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1608 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1609 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001610 if (linkProperties != null) {
1611 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1612 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001613 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1614
1615 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1616 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1617 }
1618
Andrew Flynnceaed682015-06-09 12:36:58 +00001619 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
1620 if (checkNotifyPermission()) {
1621 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001622 }
1623
Andrew Flynnceaed682015-06-09 12:36:58 +00001624 enforceCarrierPrivilege();
Andrew Flynn1f452642015-04-14 22:16:04 -04001625 }
1626
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001627 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001628 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001629 return true;
1630 }
1631 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001632 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001633 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001634 return false;
1635 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001636
Andrew Flynn1f452642015-04-14 22:16:04 -04001637 private boolean checkNotifyPermission() {
1638 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1639 == PackageManager.PERMISSION_GRANTED;
1640 }
1641
Andrew Flynnceaed682015-06-09 12:36:58 +00001642 private void enforceCarrierPrivilege() {
Andrew Flynn1f452642015-04-14 22:16:04 -04001643 TelephonyManager tm = TelephonyManager.getDefault();
1644 String[] pkgs = mContext.getPackageManager().getPackagesForUid(Binder.getCallingUid());
1645 for (String pkg : pkgs) {
1646 if (tm.checkCarrierPrivilegesForPackage(pkg) ==
1647 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001648 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001649 }
1650 }
1651
Andrew Flynnceaed682015-06-09 12:36:58 +00001652 String msg = "Carrier Privilege Permission Denial: from pid=" + Binder.getCallingPid()
1653 + ", uid=" + Binder.getCallingUid();
1654 if (DBG) log(msg);
1655 throw new SecurityException(msg);
Andrew Flynn1f452642015-04-14 22:16:04 -04001656 }
1657
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001658 private void checkListenerPermission(int events) {
1659 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1660 mContext.enforceCallingOrSelfPermission(
1661 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1662
1663 }
1664
John Wang963db55d2012-03-30 16:04:06 -07001665 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1666 mContext.enforceCallingOrSelfPermission(
1667 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1668
1669 }
1670
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001671 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001672 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -07001673 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001674 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -07001675 // SKIP checking for run-time permission since caller or self has PRIVILEGED
1676 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001677 } catch (SecurityException e) {
1678 mContext.enforceCallingOrSelfPermission(
1679 android.Manifest.permission.READ_PHONE_STATE, null);
1680 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001681 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001682
1683 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1684 mContext.enforceCallingOrSelfPermission(
1685 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1686
1687 }
New Author Steven Liu485f2092014-09-11 10:18:45 -05001688
1689 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1690 mContext.enforceCallingOrSelfPermission(
1691 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1692 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001693 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001694
1695 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001696 int size = mRemoveList.size();
1697 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1698 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001699 for (IBinder b: mRemoveList) {
1700 remove(b);
1701 }
1702 mRemoveList.clear();
1703 }
1704 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001705
1706 private boolean validateEventsAndUserLocked(Record r, int events) {
1707 int foregroundUser;
1708 long callingIdentity = Binder.clearCallingIdentity();
1709 boolean valid = false;
1710 try {
1711 foregroundUser = ActivityManager.getCurrentUser();
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001712 valid = r.callerUserId == foregroundUser && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001713 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001714 log("validateEventsAndUserLocked: valid=" + valid
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001715 + " r.callerUserId=" + r.callerUserId + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001716 + " r.events=" + r.events + " events=" + events);
1717 }
1718 } finally {
1719 Binder.restoreCallingIdentity(callingIdentity);
1720 }
1721 return valid;
1722 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001723
1724 private boolean validatePhoneId(int phoneId) {
1725 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001726 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001727 return valid;
1728 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001729
1730 private static void log(String s) {
1731 Rlog.d(TAG, s);
1732 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001733
xinhe8b79fb62014-11-05 14:55:03 -08001734 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001735
1736 if(subId < 0) {
1737 // Invalid case, we need compare phoneId with default one.
1738 return (mDefaultPhoneId == phoneId);
1739 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001740 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001741 return (subId == mDefaultSubId);
1742 } else {
1743 return (rSubId == subId);
1744 }
1745 }
1746
1747 private void checkPossibleMissNotify(Record r, int phoneId) {
1748 int events = r.events;
1749
1750 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1751 try {
1752 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1753 mServiceState[phoneId]);
1754 r.callback.onServiceStateChanged(
1755 new ServiceState(mServiceState[phoneId]));
1756 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001757 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001758 }
1759 }
1760
1761 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1762 try {
1763 SignalStrength signalStrength = mSignalStrength[phoneId];
1764 if (DBG) {
1765 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1766 }
1767 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1768 } catch (RemoteException ex) {
1769 mRemoveList.add(r.binder);
1770 }
1771 }
1772
1773 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1774 try {
1775 int gsmSignalStrength = mSignalStrength[phoneId]
1776 .getGsmSignalStrength();
1777 if (DBG) {
1778 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1779 gsmSignalStrength);
1780 }
1781 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1782 : gsmSignalStrength));
1783 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001784 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001785 }
1786 }
1787
1788 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1789 try {
1790 if (DBG_LOC) {
1791 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1792 + mCellInfo.get(phoneId));
1793 }
1794 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1795 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001796 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001797 }
1798 }
1799
1800 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1801 try {
1802 if (VDBG) {
1803 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1804 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1805 }
1806 r.callback.onMessageWaitingIndicatorChanged(
1807 mMessageWaiting[phoneId]);
1808 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001809 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001810 }
1811 }
1812
1813 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1814 try {
1815 if (VDBG) {
1816 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1817 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1818 }
1819 r.callback.onCallForwardingIndicatorChanged(
1820 mCallForwarding[phoneId]);
1821 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001822 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001823 }
1824 }
1825
1826 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1827 try {
1828 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1829 + mCellLocation[phoneId]);
1830 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1831 } catch (RemoteException ex) {
1832 mRemoveList.add(r.binder);
1833 }
1834 }
1835
1836 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1837 try {
1838 if (DBG) {
1839 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1840 + "=" + mDataConnectionState[phoneId]
1841 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1842 + ")");
1843 }
1844 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1845 mDataConnectionNetworkType[phoneId]);
1846 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001847 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001848 }
1849 }
1850 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001851}