blob: 531df81b7126d5af3c7a117e51bf525b239015b3 [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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.telephony.CellLocation;
Wink Savillef4cd25b2014-07-08 19:03:20 -070036import android.telephony.Rlog;
Wink Savillefb40dd42014-06-12 17:02:31 -070037import android.telephony.TelephonyManager;
38import android.telephony.SubscriptionManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.telephony.PhoneStateListener;
40import android.telephony.ServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -070041import android.telephony.SignalStrength;
John Wang963db55d2012-03-30 16:04:06 -070042import android.telephony.CellInfo;
Wink Savillefb40dd42014-06-12 17:02:31 -070043import android.telephony.VoLteServiceState;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020044import android.telephony.DisconnectCause;
45import android.telephony.PreciseCallState;
46import android.telephony.PreciseDataConnectionState;
47import android.telephony.PreciseDisconnectCause;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import android.text.TextUtils;
Wink Saville47d8d1b2014-07-10 13:01:52 -070049import android.text.format.Time;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050
51import java.util.ArrayList;
Wink Savilleb208a242012-07-25 14:08:09 -070052import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import java.io.FileDescriptor;
54import java.io.PrintWriter;
55
56import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080057import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import com.android.internal.telephony.ITelephonyRegistry;
59import com.android.internal.telephony.IPhoneStateListener;
Nathan Harold5a0618e2016-12-14 10:48:00 -080060import com.android.internal.telephony.PhoneConstantConversions;
Wink Savillea639b312012-07-10 12:37:54 -070061import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062import com.android.internal.telephony.TelephonyIntents;
63import com.android.server.am.BatteryStatsService;
64
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065/**
Wink Savillee9b06d72009-05-18 21:47:50 -070066 * Since phone process can be restarted, this class provides a centralized place
67 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070068 *
69 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
70 * and 15973975 by saving the phoneId of the registrant and then using the
71 * phoneId when deciding to to make a callback. This is necessary because
72 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070073 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070074 * the dummy value conversion we properly do the callbacks.
75 *
76 * Eventually we may want to remove the notion of dummy value but for now this
77 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 */
79class TelephonyRegistry extends ITelephonyRegistry.Stub {
80 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070081 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070082 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070083 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084
85 private static class Record {
Svet Ganov16a16892015-04-16 10:32:04 -070086 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070087
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -080091 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -070092
Fyodor Kupolov309b2f632015-06-03 16:29:01 -070093 int callerUserId;
Wink Savillea12a7b32012-09-20 10:09:45 -070094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -070096
Wink Savilled09c4ca2014-11-22 10:08:16 -080097 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -070098
Wink Savilled09c4ca2014-11-22 10:08:16 -080099 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800100
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700101 boolean canReadPhoneState;
102
Wink Savillea374c3d2014-11-11 11:48:04 -0800103 boolean matchPhoneStateListenerEvent(int events) {
104 return (callback != null) && ((events & this.events) != 0);
105 }
106
Wink Savilled09c4ca2014-11-22 10:08:16 -0800107 boolean matchOnSubscriptionsChangedListener() {
108 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800109 }
Wink Savillee380b982014-07-26 18:24:22 -0700110
Wink Savillea12a7b32012-09-20 10:09:45 -0700111 @Override
112 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700113 return "{callingPackage=" + callingPackage + " binder=" + binder
114 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800115 + " onSubscriptionsChangedListenererCallback="
116 + onSubscriptionsChangedListenerCallback
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700117 + " callerUserId=" + callerUserId + " subId=" + subId + " phoneId=" + phoneId
118 + " events=" + Integer.toHexString(events)
119 + " canReadPhoneState=" + canReadPhoneState + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700120 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 }
122
123 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700124
Joe Onorato163d8d92010-10-21 13:21:20 -0400125 // access should be inside synchronized (mRecords) for these two fields
126 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
127 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 private final IBatteryStats mBatteryStats;
130
Svet Ganov16a16892015-04-16 10:32:04 -0700131 private final AppOpsManager mAppOps;
132
Wink Savilled09c4ca2014-11-22 10:08:16 -0800133 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
134
Wink Savillefb40dd42014-06-12 17:02:31 -0700135 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700136
Wink Savillefb40dd42014-06-12 17:02:31 -0700137 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700138
Wink Savillefb40dd42014-06-12 17:02:31 -0700139 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700140
Wink Savillefb40dd42014-06-12 17:02:31 -0700141 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700142
fionaxu12312f62016-11-14 13:32:14 -0800143 private int[] mVoiceActivationState;
144
145 private int[] mDataActivationState;
146
Wink Savillefb40dd42014-06-12 17:02:31 -0700147 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700148
Wink Savillefb40dd42014-06-12 17:02:31 -0700149 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700150
Wink Savillefb40dd42014-06-12 17:02:31 -0700151 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700152
Wink Savillefb40dd42014-06-12 17:02:31 -0700153 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700154
Wink Savillefb40dd42014-06-12 17:02:31 -0700155 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700156
Wink Savillefb40dd42014-06-12 17:02:31 -0700157 private boolean[] mDataConnectionPossible;
Wink Savillee9b06d72009-05-18 21:47:50 -0700158
Wink Savillefb40dd42014-06-12 17:02:31 -0700159 private String[] mDataConnectionReason;
160
161 private String[] mDataConnectionApn;
Wink Savillee9b06d72009-05-18 21:47:50 -0700162
Yifan Bai57b39e32016-04-01 16:24:33 +0800163 private ArrayList<String>[] mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700164
Wink Savillefb40dd42014-06-12 17:02:31 -0700165 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700166
Wink Savillefb40dd42014-06-12 17:02:31 -0700167 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700168
Wink Savillefb40dd42014-06-12 17:02:31 -0700169 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170
Wink Savillefb40dd42014-06-12 17:02:31 -0700171 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700172
Nathan Harold016e9c62016-12-14 11:24:48 -0800173 private int mOtaspMode = TelephonyManager.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700174
Wink Savillefb40dd42014-06-12 17:02:31 -0700175 private ArrayList<List<CellInfo>> mCellInfo = null;
176
177 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
178
Wink Savilled09c4ca2014-11-22 10:08:16 -0800179 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700180
Wink Savilled09c4ca2014-11-22 10:08:16 -0800181 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700182
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200183 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
184
185 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
186
187 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
188
189 private PreciseCallState mPreciseCallState = new PreciseCallState();
190
Andrew Flynn1f452642015-04-14 22:16:04 -0400191 private boolean mCarrierNetworkChangeState = false;
192
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200193 private PreciseDataConnectionState mPreciseDataConnectionState =
194 new PreciseDataConnectionState();
195
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700196 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700197 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700198 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
199 PhoneStateListener.LISTEN_VOLTE_STATE;
200
201 static final int CHECK_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700202 PhoneStateListener.LISTEN_CALL_STATE |
203 PhoneStateListener.LISTEN_DATA_ACTIVITY |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700204 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700205
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200206 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
207 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
208 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
209
Wink Savillea12a7b32012-09-20 10:09:45 -0700210 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700211 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700212
213 private final Handler mHandler = new Handler() {
214 @Override
215 public void handleMessage(Message msg) {
216 switch (msg.what) {
217 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700218 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700219 int numPhones = TelephonyManager.getDefault().getPhoneCount();
220 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700221 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700222 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700223 }
224 break;
225 }
xinhee9f16402014-09-25 16:39:28 -0700226 case MSG_UPDATE_DEFAULT_SUB: {
227 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700228 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700229 if (VDBG) {
230 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
231 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
232 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
233 }
234
235 //Due to possible risk condition,(notify call back using the new
236 //defaultSubId comes before new defaultSubId update) we need to recall all
237 //possible missed notify callback
238 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700239 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800240 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700241 checkPossibleMissNotify(r, newDefaultPhoneId);
242 }
243 }
244 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700245 }
246 mDefaultSubId = newDefaultSubId;
247 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700248 }
249 }
250 }
251 };
252
253 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
254 @Override
255 public void onReceive(Context context, Intent intent) {
256 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700257 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700258 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700259 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700260 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700261 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700262 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700263 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800264 PhoneConstants.SUBSCRIPTION_KEY,
265 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700266 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
267 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700268 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700269 log("onReceive:current mDefaultSubId=" + mDefaultSubId
270 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
271 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700272 }
xinhee9f16402014-09-25 16:39:28 -0700273
Junda Liu985f52c2015-02-23 16:06:51 -0800274 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700275 || (newDefaultPhoneId != mDefaultPhoneId))) {
276 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
277 newDefaultPhoneId, 0, newDefaultSubIdObj));
278 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700279 }
280 }
281 };
282
Wink Savillee9b06d72009-05-18 21:47:50 -0700283 // we keep a copy of all of the state so we can send it out when folks
284 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700286 // In these calls we call with the lock held. This is safe becasuse remote
287 // calls go through a oneway interface and local calls going through a
288 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289
290 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700291 CellLocation location = CellLocation.getEmpty();
292
Wink Savillefb40dd42014-06-12 17:02:31 -0700293 mContext = context;
294 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700295
Wink Savillefb40dd42014-06-12 17:02:31 -0700296 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700297 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700298 mNumPhones = numPhones;
Yifan Bai57b39e32016-04-01 16:24:33 +0800299 mConnectedApns = new ArrayList[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700300 mCallState = new int[numPhones];
301 mDataActivity = new int[numPhones];
302 mDataConnectionState = new int[numPhones];
303 mDataConnectionNetworkType = new int[numPhones];
304 mCallIncomingNumber = new String[numPhones];
305 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800306 mVoiceActivationState = new int[numPhones];
307 mDataActivationState = new int[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700308 mSignalStrength = new SignalStrength[numPhones];
309 mMessageWaiting = new boolean[numPhones];
310 mDataConnectionPossible = new boolean[numPhones];
311 mDataConnectionReason = new String[numPhones];
312 mDataConnectionApn = new String[numPhones];
313 mCallForwarding = new boolean[numPhones];
314 mCellLocation = new Bundle[numPhones];
315 mDataConnectionLinkProperties = new LinkProperties[numPhones];
316 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
317 mCellInfo = new ArrayList<List<CellInfo>>();
318 for (int i = 0; i < numPhones; i++) {
319 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
320 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
321 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800322 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
323 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700324 mCallIncomingNumber[i] = "";
325 mServiceState[i] = new ServiceState();
326 mSignalStrength[i] = new SignalStrength();
327 mMessageWaiting[i] = false;
328 mCallForwarding[i] = false;
329 mDataConnectionPossible[i] = false;
330 mDataConnectionReason[i] = "";
331 mDataConnectionApn[i] = "";
332 mCellLocation[i] = new Bundle();
333 mCellInfo.add(i, null);
Yifan Bai57b39e32016-04-01 16:24:33 +0800334 mConnectedApns[i] = new ArrayList<String>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700335 }
336
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700337 // Note that location can be null for non-phone builds like
338 // like the generic one.
339 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700340 for (int i = 0; i < numPhones; i++) {
341 location.fillInNotifierBundle(mCellLocation[i]);
342 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700343 }
Svet Ganov16a16892015-04-16 10:32:04 -0700344
345 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 }
347
Svetoslav Ganova0027152013-06-25 14:59:53 -0700348 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700349 // Watch for interesting updates
350 final IntentFilter filter = new IntentFilter();
351 filter.addAction(Intent.ACTION_USER_SWITCHED);
352 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700353 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700354 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700355 mContext.registerReceiver(mBroadcastReceiver, filter);
356 }
357
358 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700359 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800360 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700361 int callerUserId = UserHandle.getCallingUserId();
Wink Savillea374c3d2014-11-11 11:48:04 -0800362 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700363 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
364 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800365 + " callback.asBinder=" + callback.asBinder());
366 }
367
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700368 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700369 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700370 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
371 "addOnSubscriptionsChangedListener");
Amit Mahajana9e72a72015-07-30 16:04:13 -0700372 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700373 } catch (SecurityException e) {
374 mContext.enforceCallingOrSelfPermission(
375 android.Manifest.permission.READ_PHONE_STATE,
376 "addOnSubscriptionsChangedListener");
Svet Ganov16a16892015-04-16 10:32:04 -0700377
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700378 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
379 callingPackage) != AppOpsManager.MODE_ALLOWED) {
380 return;
381 }
Svet Ganov16a16892015-04-16 10:32:04 -0700382 }
383
Fyodor Kupolovac038a92015-06-09 13:14:54 -0700384 Record r;
Wink Savillea374c3d2014-11-11 11:48:04 -0800385
Wink Savilled09c4ca2014-11-22 10:08:16 -0800386 synchronized (mRecords) {
387 // register
388 find_and_add: {
389 IBinder b = callback.asBinder();
390 final int N = mRecords.size();
391 for (int i = 0; i < N; i++) {
392 r = mRecords.get(i);
393 if (b == r.binder) {
394 break find_and_add;
Wink Savillea374c3d2014-11-11 11:48:04 -0800395 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800396 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800397 r = new Record();
398 r.binder = b;
399 mRecords.add(r);
400 if (DBG) log("listen oscl: add new record");
Wink Savillea374c3d2014-11-11 11:48:04 -0800401 }
402
Wink Savilled09c4ca2014-11-22 10:08:16 -0800403 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700404 r.callingPackage = callingPackage;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700405 r.callerUserId = callerUserId;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800406 r.events = 0;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700407 r.canReadPhoneState = true; // permission has been enforced above
Wink Savilled09c4ca2014-11-22 10:08:16 -0800408 if (DBG) {
409 log("listen oscl: Register r=" + r);
410 }
411 // Always notify when registration occurs if there has been a notification.
412 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800413 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800414 if (VDBG) log("listen oscl: send to r=" + r);
415 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
416 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800417 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800418 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800419 remove(r.binder);
420 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800421 } else {
422 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800423 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800424 }
425 }
426
427 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800428 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800429 IOnSubscriptionsChangedListener callback) {
430 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800431 remove(callback.asBinder());
432 }
433
Wink Savillea374c3d2014-11-11 11:48:04 -0800434 @Override
435 public void notifySubscriptionInfoChanged() {
436 if (VDBG) log("notifySubscriptionInfoChanged:");
437 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800438 if (!hasNotifySubscriptionInfoChangedOccurred) {
439 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
440 + mRecords.size());
441 }
442 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800443 mRemoveList.clear();
444 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800445 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800446 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800447 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
448 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
449 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800450 } catch (RemoteException ex) {
451 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
452 mRemoveList.add(r.binder);
453 }
454 }
455 }
456 handleRemoveListLocked();
457 }
458 }
459
460 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
462 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800463 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
464 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700465 }
466
467 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700468 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700469 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700470 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700471 }
472
Svet Ganov16a16892015-04-16 10:32:04 -0700473 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700474 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700475 int callerUserId = UserHandle.getCallingUserId();
Wink Savillee380b982014-07-26 18:24:22 -0700476 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700477 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700478 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
479 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700480 }
xinhe75c2c152014-10-16 11:49:45 -0700481
482 if (events != PhoneStateListener.LISTEN_NONE) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700483 /* Checks permission and throws Security exception */
484 checkListenerPermission(events);
Svet Ganov16a16892015-04-16 10:32:04 -0700485
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700486 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700487 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700488 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700489 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -0700490 // SKIP checking for run-time permission since caller or self has PRIVILEGED
491 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700492 } catch (SecurityException e) {
493 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
494 callingPackage) != AppOpsManager.MODE_ALLOWED) {
495 return;
496 }
Svet Ganov16a16892015-04-16 10:32:04 -0700497 }
498 }
499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 synchronized (mRecords) {
501 // register
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700502 Record r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 find_and_add: {
504 IBinder b = callback.asBinder();
505 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700506 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 r = mRecords.get(i);
508 if (b == r.binder) {
509 break find_and_add;
510 }
511 }
512 r = new Record();
513 r.binder = b;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 mRecords.add(r);
Wink Savillee380b982014-07-26 18:24:22 -0700515 if (DBG) log("listen: add new record");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 }
xinhe43c50292014-09-18 17:56:48 -0700517
xinhe75c2c152014-10-16 11:49:45 -0700518 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700519 r.callingPackage = callingPackage;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700520 r.callerUserId = callerUserId;
521 boolean isPhoneStateEvent = (events & (CHECK_PHONE_STATE_PERMISSION_MASK
522 | ENFORCE_PHONE_STATE_PERMISSION_MASK)) != 0;
523 r.canReadPhoneState = isPhoneStateEvent && canReadPhoneState(callingPackage);
xinhe75c2c152014-10-16 11:49:45 -0700524 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
525 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800526 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800527 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700528 } else {//APP specify subID
529 r.subId = subId;
530 }
531 r.phoneId = SubscriptionManager.getPhoneId(r.subId);
532
xinhe43c50292014-09-18 17:56:48 -0700533 int phoneId = r.phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700535 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700536 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700537 }
538 if (VDBG) toStringLogSSC("listen");
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) {
Wink Savillee380b982014-07-26 18:24:22 -0700782 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700783 log("notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
Wink Saville47d8d1b2014-07-10 13:01:52 -0700784 + " state=" + state);
785 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700786 if (validatePhoneId(phoneId)) {
787 mServiceState[phoneId] = state;
Wink Savillebc027272014-09-08 14:50:58 -0700788 logServiceStateChanged("notifyServiceStateForSubscriber", subId, phoneId, state);
789 if (VDBG) toStringLogSSC("notifyServiceStateForSubscriber");
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);
887 toStringLogSSC("notifySignalStrengthForPhoneId");
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000888 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800890 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700891 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700892 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700893 mSignalStrength[phoneId] = signalStrength;
894 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000895 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700896 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000897 + " phoneId=" + phoneId + " ss=" + signalStrength);
898 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800899 if (r.matchPhoneStateListenerEvent(
900 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800901 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700902 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000903 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700904 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000905 + " subId=" + subId + " phoneId=" + phoneId
906 + " ss=" + signalStrength);
907 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700908 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
909 } catch (RemoteException ex) {
910 mRemoveList.add(r.binder);
911 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400912 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800913 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800914 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700915 try {
916 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700917 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000918 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700919 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000920 + " subId=" + subId + " phoneId=" + phoneId
921 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
922 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700923 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700924 } catch (RemoteException ex) {
925 mRemoveList.add(r.binder);
926 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 }
928 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700929 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700930 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400932 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700934 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 }
936
Andrew Flynn1f452642015-04-14 22:16:04 -0400937 @Override
938 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +0000939 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
940
Andrew Flynn1f452642015-04-14 22:16:04 -0400941 if (VDBG) {
942 log("notifyCarrierNetworkChange: active=" + active);
943 }
944
945 synchronized (mRecords) {
946 mCarrierNetworkChangeState = active;
947 for (Record r : mRecords) {
948 if (r.matchPhoneStateListenerEvent(
949 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
950 try {
951 r.callback.onCarrierNetworkChange(active);
952 } catch (RemoteException ex) {
953 mRemoveList.add(r.binder);
954 }
955 }
956 }
957 handleRemoveListLocked();
958 }
959 }
960
Wink Savilleb208a242012-07-25 14:08:09 -0700961 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800962 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700963 }
964
Wink Saville63f03dd2014-10-23 10:44:45 -0700965 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700966 if (!checkNotifyPermission("notifyCellInfo()")) {
967 return;
968 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700969 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700970 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700971 + " cellInfo=" + cellInfo);
972 }
John Wang963db55d2012-03-30 16:04:06 -0700973
974 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700975 int phoneId = SubscriptionManager.getPhoneId(subId);
976 if (validatePhoneId(phoneId)) {
977 mCellInfo.set(phoneId, cellInfo);
978 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -0700979 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
xinhe8b79fb62014-11-05 14:55:03 -0800980 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700981 try {
982 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700983 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -0700984 }
985 r.callback.onCellInfoChanged(cellInfo);
986 } catch (RemoteException ex) {
987 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700988 }
John Wang963db55d2012-03-30 16:04:06 -0700989 }
990 }
991 }
992 handleRemoveListLocked();
993 }
994 }
995
xinhe43c50292014-09-18 17:56:48 -0700996 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700997 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700998 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700999 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001000 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001001 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001002 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001003 + " mwi=" + mwi);
1004 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001006 if (validatePhoneId(phoneId)) {
1007 mMessageWaiting[phoneId] = mwi;
1008 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001009 if (r.matchPhoneStateListenerEvent(
1010 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001011 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001012 try {
1013 r.callback.onMessageWaitingIndicatorChanged(mwi);
1014 } catch (RemoteException ex) {
1015 mRemoveList.add(r.binder);
1016 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 }
1018 }
1019 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001020 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001021 }
1022 }
1023
1024 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001025 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001026 }
1027
Wink Saville63f03dd2014-10-23 10:44:45 -07001028 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001029 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001030 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001031 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001032 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001033 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001034 + " cfi=" + cfi);
1035 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001037 int phoneId = SubscriptionManager.getPhoneId(subId);
1038 if (validatePhoneId(phoneId)) {
1039 mCallForwarding[phoneId] = cfi;
1040 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001041 if (r.matchPhoneStateListenerEvent(
1042 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001043 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001044 try {
1045 r.callback.onCallForwardingIndicatorChanged(cfi);
1046 } catch (RemoteException ex) {
1047 mRemoveList.add(r.binder);
1048 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 }
1050 }
1051 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001052 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 }
1054 }
1055
1056 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001057 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001058 }
1059
Wink Saville63f03dd2014-10-23 10:44:45 -07001060 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001061 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001062 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001063 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001064 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001065 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001066 if (validatePhoneId(phoneId)) {
1067 mDataActivity[phoneId] = state;
1068 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001069 // Notify by correct subId.
1070 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1071 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001072 try {
1073 r.callback.onDataActivity(state);
1074 } catch (RemoteException ex) {
1075 mRemoveList.add(r.binder);
1076 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 }
1078 }
1079 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001080 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 }
1082 }
1083
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001084 public void notifyDataConnection(int state, boolean isDataConnectivityPossible,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001085 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001086 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001087 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
xinhe43c50292014-09-18 17:56:48 -07001088 isDataConnectivityPossible,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001089 networkCapabilities, networkType, roaming);
1090 }
1091
Wink Saville63f03dd2014-10-23 10:44:45 -07001092 public void notifyDataConnectionForSubscriber(int subId, int state,
Wink Savillefb40dd42014-06-12 17:02:31 -07001093 boolean isDataConnectivityPossible, String reason, String apn, String apnType,
1094 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1095 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001096 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001097 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001098 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001099 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001100 log("notifyDataConnectionForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001101 + " state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible
1102 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001103 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001104 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001105 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001107 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001108 if (validatePhoneId(phoneId)) {
1109 boolean modified = false;
1110 if (state == TelephonyManager.DATA_CONNECTED) {
Yifan Bai57b39e32016-04-01 16:24:33 +08001111 if (!mConnectedApns[phoneId].contains(apnType)) {
1112 mConnectedApns[phoneId].add(apnType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001113 if (mDataConnectionState[phoneId] != state) {
1114 mDataConnectionState[phoneId] = state;
1115 modified = true;
1116 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001118 } else {
Yifan Bai57b39e32016-04-01 16:24:33 +08001119 if (mConnectedApns[phoneId].remove(apnType)) {
1120 if (mConnectedApns[phoneId].isEmpty()) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001121 mDataConnectionState[phoneId] = state;
1122 modified = true;
1123 } else {
1124 // leave mDataConnectionState as is and
1125 // send out the new status for the APN in question.
Wink Savillebaf21da2014-11-19 16:03:09 -08001126 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001127 }
1128 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001129 mDataConnectionPossible[phoneId] = isDataConnectivityPossible;
1130 mDataConnectionReason[phoneId] = reason;
1131 mDataConnectionLinkProperties[phoneId] = linkProperties;
1132 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
1133 if (mDataConnectionNetworkType[phoneId] != networkType) {
1134 mDataConnectionNetworkType[phoneId] = networkType;
1135 // need to tell registered listeners about the new network type
1136 modified = true;
1137 }
1138 if (modified) {
1139 if (DBG) {
1140 log("onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
1141 + ", " + mDataConnectionNetworkType[phoneId] + ")");
1142 }
1143 for (Record r : mRecords) {
1144 if (r.matchPhoneStateListenerEvent(
1145 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1146 idMatch(r.subId, subId, phoneId)) {
1147 try {
1148 log("Notify data connection state changed on sub: " +
1149 subId);
1150 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1151 mDataConnectionNetworkType[phoneId]);
1152 } catch (RemoteException ex) {
1153 mRemoveList.add(r.binder);
1154 }
1155 }
1156 }
1157 handleRemoveListLocked();
1158 }
1159 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1160 apnType, apn, reason, linkProperties, "");
1161 for (Record r : mRecords) {
1162 if (r.matchPhoneStateListenerEvent(
1163 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1164 try {
1165 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1166 } catch (RemoteException ex) {
1167 mRemoveList.add(r.binder);
1168 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001169 }
1170 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001171 }
1172 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001174 broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001175 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001176 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1177 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 }
1179
Robert Greenwalt02648a42010-05-18 10:52:51 -07001180 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001181 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001182 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001183 }
1184
Wink Saville63f03dd2014-10-23 10:44:45 -07001185 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001186 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001187 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001188 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001189 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001190 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001191 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001192 + " reason=" + reason + " apnType=" + apnType);
1193 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001195 mPreciseDataConnectionState = new PreciseDataConnectionState(
1196 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1197 apnType, "", reason, null, "");
1198 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001199 if (r.matchPhoneStateListenerEvent(
1200 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001201 try {
1202 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1203 } catch (RemoteException ex) {
1204 mRemoveList.add(r.binder);
1205 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001206 }
1207 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001208 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001209 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001210 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001211 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1212 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001213 }
1214
1215 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001216 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001217 }
1218
Wink Saville63f03dd2014-10-23 10:44:45 -07001219 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001220 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001221 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001222 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001223 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001224 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001225 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001226 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001227 + " cellLocation=" + cellLocation);
1228 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001230 int phoneId = SubscriptionManager.getPhoneId(subId);
1231 if (validatePhoneId(phoneId)) {
1232 mCellLocation[phoneId] = cellLocation;
1233 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001234 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
xinhe8b79fb62014-11-05 14:55:03 -08001235 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001236 try {
1237 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001238 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001239 + " r=" + r);
1240 }
1241 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1242 } catch (RemoteException ex) {
1243 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001244 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001246 }
1247 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001248 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001249 }
1250 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251
Wink Savillefd2d0132010-10-28 14:22:26 -07001252 public void notifyOtaspChanged(int otaspMode) {
1253 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1254 return;
1255 }
1256 synchronized (mRecords) {
1257 mOtaspMode = otaspMode;
1258 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001259 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001260 try {
1261 r.callback.onOtaspChanged(otaspMode);
1262 } catch (RemoteException ex) {
1263 mRemoveList.add(r.binder);
1264 }
1265 }
1266 }
1267 handleRemoveListLocked();
1268 }
1269 }
1270
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001271 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1272 int backgroundCallState) {
1273 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1274 return;
1275 }
1276 synchronized (mRecords) {
1277 mRingingCallState = ringingCallState;
1278 mForegroundCallState = foregroundCallState;
1279 mBackgroundCallState = backgroundCallState;
1280 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1281 backgroundCallState,
1282 DisconnectCause.NOT_VALID,
1283 PreciseDisconnectCause.NOT_VALID);
1284 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001285 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001286 try {
1287 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1288 } catch (RemoteException ex) {
1289 mRemoveList.add(r.binder);
1290 }
1291 }
1292 }
1293 handleRemoveListLocked();
1294 }
1295 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1296 DisconnectCause.NOT_VALID,
1297 PreciseDisconnectCause.NOT_VALID);
1298 }
1299
1300 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1301 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1302 return;
1303 }
1304 synchronized (mRecords) {
1305 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1306 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1307 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001308 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001309 try {
1310 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1311 } catch (RemoteException ex) {
1312 mRemoveList.add(r.binder);
1313 }
1314 }
1315 }
1316 handleRemoveListLocked();
1317 }
1318 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1319 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1320 }
1321
1322 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1323 String apn, String failCause) {
1324 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1325 return;
1326 }
1327 synchronized (mRecords) {
1328 mPreciseDataConnectionState = new PreciseDataConnectionState(
1329 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1330 apnType, apn, reason, null, failCause);
1331 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001332 if (r.matchPhoneStateListenerEvent(
1333 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001334 try {
1335 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1336 } catch (RemoteException ex) {
1337 mRemoveList.add(r.binder);
1338 }
1339 }
1340 }
1341 handleRemoveListLocked();
1342 }
1343 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1344 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1345 }
1346
Wink Savillefb40dd42014-06-12 17:02:31 -07001347 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1348 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1349 return;
1350 }
1351 synchronized (mRecords) {
1352 mVoLteServiceState = lteState;
1353 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001354 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001355 try {
1356 r.callback.onVoLteServiceStateChanged(
1357 new VoLteServiceState(mVoLteServiceState));
1358 } catch (RemoteException ex) {
1359 mRemoveList.add(r.binder);
1360 }
1361 }
1362 }
1363 handleRemoveListLocked();
1364 }
1365 }
1366
Wink Saville63f03dd2014-10-23 10:44:45 -07001367 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001368 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1369 return;
1370 }
1371
1372 synchronized (mRecords) {
1373 for (Record r : mRecords) {
1374 if (VDBG) {
1375 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1376 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001377 if ((r.matchPhoneStateListenerEvent(
1378 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
New Author Steven Liu485f2092014-09-11 10:18:45 -05001379 ((r.subId == subId) ||
Wink Savilled09c4ca2014-11-22 10:08:16 -08001380 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001381 try {
1382 r.callback.onOemHookRawEvent(rawData);
1383 } catch (RemoteException ex) {
1384 mRemoveList.add(r.binder);
1385 }
1386 }
1387 }
1388 handleRemoveListLocked();
1389 }
1390 }
1391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392 @Override
1393 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1394 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1395 != PackageManager.PERMISSION_GRANTED) {
1396 pw.println("Permission Denial: can't dump telephony.registry from from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001397 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001398 return;
1399 }
1400 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:");
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301403 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1404 pw.println(" Phone Id=" + i);
1405 pw.println(" mCallState=" + mCallState[i]);
1406 pw.println(" mCallIncomingNumber=" + mCallIncomingNumber[i]);
1407 pw.println(" mServiceState=" + mServiceState[i]);
fionaxu12312f62016-11-14 13:32:14 -08001408 pw.println(" mVoiceActivationState= " + mVoiceActivationState[i]);
1409 pw.println(" mDataActivationState= " + mDataActivationState[i]);
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301410 pw.println(" mSignalStrength=" + mSignalStrength[i]);
1411 pw.println(" mMessageWaiting=" + mMessageWaiting[i]);
1412 pw.println(" mCallForwarding=" + mCallForwarding[i]);
1413 pw.println(" mDataActivity=" + mDataActivity[i]);
1414 pw.println(" mDataConnectionState=" + mDataConnectionState[i]);
1415 pw.println(" mDataConnectionPossible=" + mDataConnectionPossible[i]);
1416 pw.println(" mDataConnectionReason=" + mDataConnectionReason[i]);
1417 pw.println(" mDataConnectionApn=" + mDataConnectionApn[i]);
1418 pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1419 pw.println(" mDataConnectionNetworkCapabilities=" +
1420 mDataConnectionNetworkCapabilities[i]);
1421 pw.println(" mCellLocation=" + mCellLocation[i]);
1422 pw.println(" mCellInfo=" + mCellInfo.get(i));
1423 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001424 pw.println("registrations: count=" + recordCount);
Robert Greenwalt02648a42010-05-18 10:52:51 -07001425 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -07001426 pw.println(" " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 }
1428 }
1429 }
1430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001431 //
1432 // the legacy intent broadcasting
1433 //
1434
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001435 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001436 long ident = Binder.clearCallingIdentity();
1437 try {
1438 mBatteryStats.notePhoneState(state.getState());
1439 } catch (RemoteException re) {
1440 // Can't do much
1441 } finally {
1442 Binder.restoreCallingIdentity(ident);
1443 }
1444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001445 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001446 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001447 Bundle data = new Bundle();
1448 state.fillInNotifierBundle(data);
1449 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001450 // Pass the subscription along with the intent.
1451 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001452 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001453 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001454 }
1455
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001456 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1457 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001458 long ident = Binder.clearCallingIdentity();
1459 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001460 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001461 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001462 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001463 } finally {
1464 Binder.restoreCallingIdentity(ident);
1465 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001467 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001468 Bundle data = new Bundle();
1469 signalStrength.fillInNotifierBundle(data);
1470 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001471 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001472 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001473 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001474 }
1475
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001476 /**
1477 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1478 * a valid subId, in which case this function fires a subId-specific intent, or it
1479 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1480 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1481 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001482 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1483 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001484 long ident = Binder.clearCallingIdentity();
1485 try {
1486 if (state == TelephonyManager.CALL_STATE_IDLE) {
1487 mBatteryStats.notePhoneOff();
1488 } else {
1489 mBatteryStats.notePhoneOn();
1490 }
1491 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001492 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 } finally {
1494 Binder.restoreCallingIdentity(ident);
1495 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001498 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001499 PhoneConstantConversions.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001500 if (!TextUtils.isEmpty(incomingNumber)) {
1501 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1502 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001503
1504 // If a valid subId was specified, we should fire off a subId-specific state
1505 // change intent and include the subId.
1506 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1507 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1508 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1509 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001510 // If the phoneId is invalid, the broadcast is for overall call state.
1511 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1512 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1513 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001514
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001515 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1516 // that have the runtime one
1517 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1518 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001519 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001520 android.Manifest.permission.READ_PHONE_STATE,
1521 AppOpsManager.OP_READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522 }
1523
Robert Greenwalt42acef32009-08-12 16:08:25 -07001524 private void broadcastDataConnectionStateChanged(int state,
1525 boolean isDataConnectivityPossible,
Wink Savillef61101f2010-09-16 16:36:42 -07001526 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001527 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001528 // Note: not reporting to the battery stats service here, because the
1529 // status bar takes care of that after taking into account all of the
1530 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001532 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001533 PhoneConstantConversions.convertDataState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 if (!isDataConnectivityPossible) {
Wink Savillea639b312012-07-10 12:37:54 -07001535 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001536 }
1537 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001538 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001540 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001541 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001542 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001543 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001544 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001545 }
1546 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001547 if (networkCapabilities != null) {
1548 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001549 }
Wink Savillea639b312012-07-10 12:37:54 -07001550 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001551
Wink Savillea639b312012-07-10 12:37:54 -07001552 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1553 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001554 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001555 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001556 }
1557
Wink Savillefb40dd42014-06-12 17:02:31 -07001558 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001559 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001561 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1562 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001563 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001564 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001565 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001566
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001567 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1568 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1569 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1570 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1571 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1572 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1573 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1574 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1575 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1576 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1577 }
1578
1579 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001580 String apnType, String apn, String reason, LinkProperties linkProperties,
1581 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001582 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1583 intent.putExtra(PhoneConstants.STATE_KEY, state);
1584 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1585 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1586 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1587 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001588 if (linkProperties != null) {
1589 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1590 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001591 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1592
1593 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1594 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1595 }
1596
Andrew Flynnceaed682015-06-09 12:36:58 +00001597 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
1598 if (checkNotifyPermission()) {
1599 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001600 }
1601
Andrew Flynnceaed682015-06-09 12:36:58 +00001602 enforceCarrierPrivilege();
Andrew Flynn1f452642015-04-14 22:16:04 -04001603 }
1604
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001605 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001606 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001607 return true;
1608 }
1609 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001610 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001611 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001612 return false;
1613 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001614
Andrew Flynn1f452642015-04-14 22:16:04 -04001615 private boolean checkNotifyPermission() {
1616 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1617 == PackageManager.PERMISSION_GRANTED;
1618 }
1619
Andrew Flynnceaed682015-06-09 12:36:58 +00001620 private void enforceCarrierPrivilege() {
Andrew Flynn1f452642015-04-14 22:16:04 -04001621 TelephonyManager tm = TelephonyManager.getDefault();
1622 String[] pkgs = mContext.getPackageManager().getPackagesForUid(Binder.getCallingUid());
1623 for (String pkg : pkgs) {
1624 if (tm.checkCarrierPrivilegesForPackage(pkg) ==
1625 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001626 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001627 }
1628 }
1629
Andrew Flynnceaed682015-06-09 12:36:58 +00001630 String msg = "Carrier Privilege Permission Denial: from pid=" + Binder.getCallingPid()
1631 + ", uid=" + Binder.getCallingUid();
1632 if (DBG) log(msg);
1633 throw new SecurityException(msg);
Andrew Flynn1f452642015-04-14 22:16:04 -04001634 }
1635
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001636 private void checkListenerPermission(int events) {
1637 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1638 mContext.enforceCallingOrSelfPermission(
1639 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1640
1641 }
1642
John Wang963db55d2012-03-30 16:04:06 -07001643 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1644 mContext.enforceCallingOrSelfPermission(
1645 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1646
1647 }
1648
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001649 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001650 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -07001651 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001652 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -07001653 // SKIP checking for run-time permission since caller or self has PRIVILEGED
1654 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001655 } catch (SecurityException e) {
1656 mContext.enforceCallingOrSelfPermission(
1657 android.Manifest.permission.READ_PHONE_STATE, null);
1658 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001659 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001660
1661 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1662 mContext.enforceCallingOrSelfPermission(
1663 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1664
1665 }
New Author Steven Liu485f2092014-09-11 10:18:45 -05001666
1667 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1668 mContext.enforceCallingOrSelfPermission(
1669 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1670 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001671 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001672
1673 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001674 int size = mRemoveList.size();
1675 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1676 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001677 for (IBinder b: mRemoveList) {
1678 remove(b);
1679 }
1680 mRemoveList.clear();
1681 }
1682 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001683
1684 private boolean validateEventsAndUserLocked(Record r, int events) {
1685 int foregroundUser;
1686 long callingIdentity = Binder.clearCallingIdentity();
1687 boolean valid = false;
1688 try {
1689 foregroundUser = ActivityManager.getCurrentUser();
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001690 valid = r.callerUserId == foregroundUser && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001691 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001692 log("validateEventsAndUserLocked: valid=" + valid
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001693 + " r.callerUserId=" + r.callerUserId + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001694 + " r.events=" + r.events + " events=" + events);
1695 }
1696 } finally {
1697 Binder.restoreCallingIdentity(callingIdentity);
1698 }
1699 return valid;
1700 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001701
1702 private boolean validatePhoneId(int phoneId) {
1703 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001704 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001705 return valid;
1706 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001707
1708 private static void log(String s) {
1709 Rlog.d(TAG, s);
1710 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001711
1712 private static class LogSSC {
1713 private Time mTime;
1714 private String mS;
Wink Saville63f03dd2014-10-23 10:44:45 -07001715 private int mSubId;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001716 private int mPhoneId;
1717 private ServiceState mState;
1718
Wink Saville63f03dd2014-10-23 10:44:45 -07001719 public void set(Time t, String s, int subId, int phoneId, ServiceState state) {
Wink Saville47d8d1b2014-07-10 13:01:52 -07001720 mTime = t; mS = s; mSubId = subId; mPhoneId = phoneId; mState = state;
1721 }
1722
1723 @Override
1724 public String toString() {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001725 return mS + " Time " + mTime.toString() + " mSubId " + mSubId + " mPhoneId "
1726 + mPhoneId + " mState " + mState;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001727 }
1728 }
1729
1730 private LogSSC logSSC [] = new LogSSC[10];
1731 private int next = 0;
1732
Wink Saville63f03dd2014-10-23 10:44:45 -07001733 private void logServiceStateChanged(String s, int subId, int phoneId, ServiceState state) {
Wink Saville47d8d1b2014-07-10 13:01:52 -07001734 if (logSSC == null || logSSC.length == 0) {
1735 return;
1736 }
1737 if (logSSC[next] == null) {
1738 logSSC[next] = new LogSSC();
1739 }
1740 Time t = new Time();
1741 t.setToNow();
1742 logSSC[next].set(t, s, subId, phoneId, state);
1743 if (++next >= logSSC.length) {
1744 next = 0;
1745 }
1746 }
1747
1748 private void toStringLogSSC(String prompt) {
1749 if (logSSC == null || logSSC.length == 0 || (next == 0 && logSSC[next] == null)) {
1750 log(prompt + ": logSSC is empty");
1751 } else {
1752 // There is at least one element
1753 log(prompt + ": logSSC.length=" + logSSC.length + " next=" + next);
1754 int i = next;
1755 if (logSSC[i] == null) {
1756 // logSSC is not full so back to the beginning
1757 i = 0;
1758 }
1759 do {
1760 log(logSSC[i].toString());
1761 if (++i >= logSSC.length) {
1762 i = 0;
1763 }
1764 } while (i != next);
Wink Savillee380b982014-07-26 18:24:22 -07001765 log(prompt + ": ----------------");
Wink Saville47d8d1b2014-07-10 13:01:52 -07001766 }
1767 }
xinhee9f16402014-09-25 16:39:28 -07001768
xinhe8b79fb62014-11-05 14:55:03 -08001769 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001770
1771 if(subId < 0) {
1772 // Invalid case, we need compare phoneId with default one.
1773 return (mDefaultPhoneId == phoneId);
1774 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001775 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001776 return (subId == mDefaultSubId);
1777 } else {
1778 return (rSubId == subId);
1779 }
1780 }
1781
1782 private void checkPossibleMissNotify(Record r, int phoneId) {
1783 int events = r.events;
1784
1785 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1786 try {
1787 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1788 mServiceState[phoneId]);
1789 r.callback.onServiceStateChanged(
1790 new ServiceState(mServiceState[phoneId]));
1791 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001792 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001793 }
1794 }
1795
1796 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1797 try {
1798 SignalStrength signalStrength = mSignalStrength[phoneId];
1799 if (DBG) {
1800 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1801 }
1802 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1803 } catch (RemoteException ex) {
1804 mRemoveList.add(r.binder);
1805 }
1806 }
1807
1808 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1809 try {
1810 int gsmSignalStrength = mSignalStrength[phoneId]
1811 .getGsmSignalStrength();
1812 if (DBG) {
1813 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1814 gsmSignalStrength);
1815 }
1816 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1817 : gsmSignalStrength));
1818 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001819 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001820 }
1821 }
1822
1823 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1824 try {
1825 if (DBG_LOC) {
1826 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1827 + mCellInfo.get(phoneId));
1828 }
1829 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1830 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001831 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001832 }
1833 }
1834
1835 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1836 try {
1837 if (VDBG) {
1838 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1839 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1840 }
1841 r.callback.onMessageWaitingIndicatorChanged(
1842 mMessageWaiting[phoneId]);
1843 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001844 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001845 }
1846 }
1847
1848 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1849 try {
1850 if (VDBG) {
1851 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1852 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1853 }
1854 r.callback.onCallForwardingIndicatorChanged(
1855 mCallForwarding[phoneId]);
1856 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001857 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001858 }
1859 }
1860
1861 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1862 try {
1863 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1864 + mCellLocation[phoneId]);
1865 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1866 } catch (RemoteException ex) {
1867 mRemoveList.add(r.binder);
1868 }
1869 }
1870
1871 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1872 try {
1873 if (DBG) {
1874 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1875 + "=" + mDataConnectionState[phoneId]
1876 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1877 + ")");
1878 }
1879 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1880 mDataConnectionNetworkType[phoneId]);
1881 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001882 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001883 }
1884 }
1885 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001886}