blob: 37d8592670ee109add438d238e3d249c6a3f2008 [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;
Wink Savillec9330dd2011-01-12 13:37:38 -080062import com.android.internal.telephony.ServiceStateTracker;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import com.android.internal.telephony.TelephonyIntents;
64import com.android.server.am.BatteryStatsService;
65
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066/**
Wink Savillee9b06d72009-05-18 21:47:50 -070067 * Since phone process can be restarted, this class provides a centralized place
68 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070069 *
70 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
71 * and 15973975 by saving the phoneId of the registrant and then using the
72 * phoneId when deciding to to make a callback. This is necessary because
73 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070074 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070075 * the dummy value conversion we properly do the callbacks.
76 *
77 * Eventually we may want to remove the notion of dummy value but for now this
78 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 */
80class TelephonyRegistry extends ITelephonyRegistry.Stub {
81 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070082 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070083 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070084 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085
86 private static class Record {
Svet Ganov16a16892015-04-16 10:32:04 -070087 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -080092 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -070093
Fyodor Kupolov309b2f632015-06-03 16:29:01 -070094 int callerUserId;
Wink Savillea12a7b32012-09-20 10:09:45 -070095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -070097
Wink Savilled09c4ca2014-11-22 10:08:16 -080098 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -070099
Wink Savilled09c4ca2014-11-22 10:08:16 -0800100 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800101
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700102 boolean canReadPhoneState;
103
Wink Savillea374c3d2014-11-11 11:48:04 -0800104 boolean matchPhoneStateListenerEvent(int events) {
105 return (callback != null) && ((events & this.events) != 0);
106 }
107
Wink Savilled09c4ca2014-11-22 10:08:16 -0800108 boolean matchOnSubscriptionsChangedListener() {
109 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800110 }
Wink Savillee380b982014-07-26 18:24:22 -0700111
Wink Savillea12a7b32012-09-20 10:09:45 -0700112 @Override
113 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700114 return "{callingPackage=" + callingPackage + " binder=" + binder
115 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800116 + " onSubscriptionsChangedListenererCallback="
117 + onSubscriptionsChangedListenerCallback
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700118 + " callerUserId=" + callerUserId + " subId=" + subId + " phoneId=" + phoneId
119 + " events=" + Integer.toHexString(events)
120 + " canReadPhoneState=" + canReadPhoneState + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700121 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 }
123
124 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700125
Joe Onorato163d8d92010-10-21 13:21:20 -0400126 // access should be inside synchronized (mRecords) for these two fields
127 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
128 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 private final IBatteryStats mBatteryStats;
131
Svet Ganov16a16892015-04-16 10:32:04 -0700132 private final AppOpsManager mAppOps;
133
Wink Savilled09c4ca2014-11-22 10:08:16 -0800134 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
135
Wink Savillefb40dd42014-06-12 17:02:31 -0700136 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700137
Wink Savillefb40dd42014-06-12 17:02:31 -0700138 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700139
Wink Savillefb40dd42014-06-12 17:02:31 -0700140 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700141
Wink Savillefb40dd42014-06-12 17:02:31 -0700142 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700143
fionaxu12312f62016-11-14 13:32:14 -0800144 private int[] mVoiceActivationState;
145
146 private int[] mDataActivationState;
147
Wink Savillefb40dd42014-06-12 17:02:31 -0700148 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700149
Wink Savillefb40dd42014-06-12 17:02:31 -0700150 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700151
Wink Savillefb40dd42014-06-12 17:02:31 -0700152 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700153
Wink Savillefb40dd42014-06-12 17:02:31 -0700154 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700155
Wink Savillefb40dd42014-06-12 17:02:31 -0700156 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700157
Wink Savillefb40dd42014-06-12 17:02:31 -0700158 private boolean[] mDataConnectionPossible;
Wink Savillee9b06d72009-05-18 21:47:50 -0700159
Wink Savillefb40dd42014-06-12 17:02:31 -0700160 private String[] mDataConnectionReason;
161
162 private String[] mDataConnectionApn;
Wink Savillee9b06d72009-05-18 21:47:50 -0700163
Yifan Bai57b39e32016-04-01 16:24:33 +0800164 private ArrayList<String>[] mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700165
Wink Savillefb40dd42014-06-12 17:02:31 -0700166 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700167
Wink Savillefb40dd42014-06-12 17:02:31 -0700168 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700169
Wink Savillefb40dd42014-06-12 17:02:31 -0700170 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171
Wink Savillefb40dd42014-06-12 17:02:31 -0700172 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700173
Wink Savillec9330dd2011-01-12 13:37:38 -0800174 private int mOtaspMode = ServiceStateTracker.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700175
Wink Savillefb40dd42014-06-12 17:02:31 -0700176 private ArrayList<List<CellInfo>> mCellInfo = null;
177
178 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
179
Wink Savilled09c4ca2014-11-22 10:08:16 -0800180 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700181
Wink Savilled09c4ca2014-11-22 10:08:16 -0800182 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700183
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200184 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
185
186 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
187
188 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
189
190 private PreciseCallState mPreciseCallState = new PreciseCallState();
191
Andrew Flynn1f452642015-04-14 22:16:04 -0400192 private boolean mCarrierNetworkChangeState = false;
193
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200194 private PreciseDataConnectionState mPreciseDataConnectionState =
195 new PreciseDataConnectionState();
196
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700197 static final int ENFORCE_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700198 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700199 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
200 PhoneStateListener.LISTEN_VOLTE_STATE;
201
202 static final int CHECK_PHONE_STATE_PERMISSION_MASK =
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700203 PhoneStateListener.LISTEN_CALL_STATE |
204 PhoneStateListener.LISTEN_DATA_ACTIVITY |
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700205 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700206
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200207 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
208 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
209 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
210
Wink Savillea12a7b32012-09-20 10:09:45 -0700211 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700212 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700213
214 private final Handler mHandler = new Handler() {
215 @Override
216 public void handleMessage(Message msg) {
217 switch (msg.what) {
218 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700219 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700220 int numPhones = TelephonyManager.getDefault().getPhoneCount();
221 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700222 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700223 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700224 }
225 break;
226 }
xinhee9f16402014-09-25 16:39:28 -0700227 case MSG_UPDATE_DEFAULT_SUB: {
228 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700229 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700230 if (VDBG) {
231 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
232 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
233 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
234 }
235
236 //Due to possible risk condition,(notify call back using the new
237 //defaultSubId comes before new defaultSubId update) we need to recall all
238 //possible missed notify callback
239 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700240 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800241 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700242 checkPossibleMissNotify(r, newDefaultPhoneId);
243 }
244 }
245 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700246 }
247 mDefaultSubId = newDefaultSubId;
248 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700249 }
250 }
251 }
252 };
253
254 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
255 @Override
256 public void onReceive(Context context, Intent intent) {
257 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700258 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700259 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700260 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700261 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700262 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700263 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700264 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
Shishir Agrawal7ea3e8b2016-01-25 13:03:07 -0800265 PhoneConstants.SUBSCRIPTION_KEY,
266 SubscriptionManager.getDefaultSubscriptionId()));
xinhee9f16402014-09-25 16:39:28 -0700267 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
268 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700269 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700270 log("onReceive:current mDefaultSubId=" + mDefaultSubId
271 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
272 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700273 }
xinhee9f16402014-09-25 16:39:28 -0700274
Junda Liu985f52c2015-02-23 16:06:51 -0800275 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700276 || (newDefaultPhoneId != mDefaultPhoneId))) {
277 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
278 newDefaultPhoneId, 0, newDefaultSubIdObj));
279 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700280 }
281 }
282 };
283
Wink Savillee9b06d72009-05-18 21:47:50 -0700284 // we keep a copy of all of the state so we can send it out when folks
285 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700287 // In these calls we call with the lock held. This is safe becasuse remote
288 // calls go through a oneway interface and local calls going through a
289 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290
291 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700292 CellLocation location = CellLocation.getEmpty();
293
Wink Savillefb40dd42014-06-12 17:02:31 -0700294 mContext = context;
295 mBatteryStats = BatteryStatsService.getService();
Wink Savillefb40dd42014-06-12 17:02:31 -0700296
Wink Savillefb40dd42014-06-12 17:02:31 -0700297 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700298 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700299 mNumPhones = numPhones;
Yifan Bai57b39e32016-04-01 16:24:33 +0800300 mConnectedApns = new ArrayList[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700301 mCallState = new int[numPhones];
302 mDataActivity = new int[numPhones];
303 mDataConnectionState = new int[numPhones];
304 mDataConnectionNetworkType = new int[numPhones];
305 mCallIncomingNumber = new String[numPhones];
306 mServiceState = new ServiceState[numPhones];
fionaxu12312f62016-11-14 13:32:14 -0800307 mVoiceActivationState = new int[numPhones];
308 mDataActivationState = new int[numPhones];
Wink Savillefb40dd42014-06-12 17:02:31 -0700309 mSignalStrength = new SignalStrength[numPhones];
310 mMessageWaiting = new boolean[numPhones];
311 mDataConnectionPossible = new boolean[numPhones];
312 mDataConnectionReason = new String[numPhones];
313 mDataConnectionApn = new String[numPhones];
314 mCallForwarding = new boolean[numPhones];
315 mCellLocation = new Bundle[numPhones];
316 mDataConnectionLinkProperties = new LinkProperties[numPhones];
317 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
318 mCellInfo = new ArrayList<List<CellInfo>>();
319 for (int i = 0; i < numPhones; i++) {
320 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
321 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
322 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
fionaxu12312f62016-11-14 13:32:14 -0800323 mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
324 mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
Wink Savillefb40dd42014-06-12 17:02:31 -0700325 mCallIncomingNumber[i] = "";
326 mServiceState[i] = new ServiceState();
327 mSignalStrength[i] = new SignalStrength();
328 mMessageWaiting[i] = false;
329 mCallForwarding[i] = false;
330 mDataConnectionPossible[i] = false;
331 mDataConnectionReason[i] = "";
332 mDataConnectionApn[i] = "";
333 mCellLocation[i] = new Bundle();
334 mCellInfo.add(i, null);
Yifan Bai57b39e32016-04-01 16:24:33 +0800335 mConnectedApns[i] = new ArrayList<String>();
Wink Savillefb40dd42014-06-12 17:02:31 -0700336 }
337
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700338 // Note that location can be null for non-phone builds like
339 // like the generic one.
340 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700341 for (int i = 0; i < numPhones; i++) {
342 location.fillInNotifierBundle(mCellLocation[i]);
343 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700344 }
Svet Ganov16a16892015-04-16 10:32:04 -0700345
346 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 }
348
Svetoslav Ganova0027152013-06-25 14:59:53 -0700349 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700350 // Watch for interesting updates
351 final IntentFilter filter = new IntentFilter();
352 filter.addAction(Intent.ACTION_USER_SWITCHED);
353 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700354 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700355 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700356 mContext.registerReceiver(mBroadcastReceiver, filter);
357 }
358
359 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700360 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800361 IOnSubscriptionsChangedListener callback) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700362 int callerUserId = UserHandle.getCallingUserId();
Wink Savillea374c3d2014-11-11 11:48:04 -0800363 if (VDBG) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700364 log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId()
365 + " callerUserId=" + callerUserId + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800366 + " callback.asBinder=" + callback.asBinder());
367 }
368
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700369 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700370 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700371 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
372 "addOnSubscriptionsChangedListener");
Amit Mahajana9e72a72015-07-30 16:04:13 -0700373 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700374 } catch (SecurityException e) {
375 mContext.enforceCallingOrSelfPermission(
376 android.Manifest.permission.READ_PHONE_STATE,
377 "addOnSubscriptionsChangedListener");
Svet Ganov16a16892015-04-16 10:32:04 -0700378
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700379 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
380 callingPackage) != AppOpsManager.MODE_ALLOWED) {
381 return;
382 }
Svet Ganov16a16892015-04-16 10:32:04 -0700383 }
384
Fyodor Kupolovac038a92015-06-09 13:14:54 -0700385 Record r;
Wink Savillea374c3d2014-11-11 11:48:04 -0800386
Wink Savilled09c4ca2014-11-22 10:08:16 -0800387 synchronized (mRecords) {
388 // register
389 find_and_add: {
390 IBinder b = callback.asBinder();
391 final int N = mRecords.size();
392 for (int i = 0; i < N; i++) {
393 r = mRecords.get(i);
394 if (b == r.binder) {
395 break find_and_add;
Wink Savillea374c3d2014-11-11 11:48:04 -0800396 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800397 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800398 r = new Record();
399 r.binder = b;
400 mRecords.add(r);
401 if (DBG) log("listen oscl: add new record");
Wink Savillea374c3d2014-11-11 11:48:04 -0800402 }
403
Wink Savilled09c4ca2014-11-22 10:08:16 -0800404 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700405 r.callingPackage = callingPackage;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700406 r.callerUserId = callerUserId;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800407 r.events = 0;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700408 r.canReadPhoneState = true; // permission has been enforced above
Wink Savilled09c4ca2014-11-22 10:08:16 -0800409 if (DBG) {
410 log("listen oscl: Register r=" + r);
411 }
412 // Always notify when registration occurs if there has been a notification.
413 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800414 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800415 if (VDBG) log("listen oscl: send to r=" + r);
416 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
417 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800418 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800419 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800420 remove(r.binder);
421 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800422 } else {
423 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800424 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800425 }
426 }
427
428 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800429 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800430 IOnSubscriptionsChangedListener callback) {
431 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800432 remove(callback.asBinder());
433 }
434
Wink Savillea374c3d2014-11-11 11:48:04 -0800435 @Override
436 public void notifySubscriptionInfoChanged() {
437 if (VDBG) log("notifySubscriptionInfoChanged:");
438 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800439 if (!hasNotifySubscriptionInfoChangedOccurred) {
440 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
441 + mRecords.size());
442 }
443 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800444 mRemoveList.clear();
445 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800446 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800447 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800448 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
449 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
450 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800451 } catch (RemoteException ex) {
452 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
453 mRemoveList.add(r.binder);
454 }
455 }
456 }
457 handleRemoveListLocked();
458 }
459 }
460
461 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
463 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800464 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
465 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700466 }
467
468 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700469 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700470 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700471 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700472 }
473
Svet Ganov16a16892015-04-16 10:32:04 -0700474 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700475 boolean notifyNow, int subId) {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700476 int callerUserId = UserHandle.getCallingUserId();
Wink Savillee380b982014-07-26 18:24:22 -0700477 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700478 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700479 + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId="
480 + UserHandle.myUserId() + " callerUserId=" + callerUserId);
Wink Savillea12a7b32012-09-20 10:09:45 -0700481 }
xinhe75c2c152014-10-16 11:49:45 -0700482
483 if (events != PhoneStateListener.LISTEN_NONE) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700484 /* Checks permission and throws Security exception */
485 checkListenerPermission(events);
Svet Ganov16a16892015-04-16 10:32:04 -0700486
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700487 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700488 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700489 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700490 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -0700491 // SKIP checking for run-time permission since caller or self has PRIVILEGED
492 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700493 } catch (SecurityException e) {
494 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
495 callingPackage) != AppOpsManager.MODE_ALLOWED) {
496 return;
497 }
Svet Ganov16a16892015-04-16 10:32:04 -0700498 }
499 }
500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 synchronized (mRecords) {
502 // register
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700503 Record r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 find_and_add: {
505 IBinder b = callback.asBinder();
506 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700507 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 r = mRecords.get(i);
509 if (b == r.binder) {
510 break find_and_add;
511 }
512 }
513 r = new Record();
514 r.binder = b;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 mRecords.add(r);
Wink Savillee380b982014-07-26 18:24:22 -0700516 if (DBG) log("listen: add new record");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 }
xinhe43c50292014-09-18 17:56:48 -0700518
xinhe75c2c152014-10-16 11:49:45 -0700519 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700520 r.callingPackage = callingPackage;
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700521 r.callerUserId = callerUserId;
522 boolean isPhoneStateEvent = (events & (CHECK_PHONE_STATE_PERMISSION_MASK
523 | ENFORCE_PHONE_STATE_PERMISSION_MASK)) != 0;
524 r.canReadPhoneState = isPhoneStateEvent && canReadPhoneState(callingPackage);
xinhe75c2c152014-10-16 11:49:45 -0700525 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
526 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800527 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800528 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700529 } else {//APP specify subID
530 r.subId = subId;
531 }
532 r.phoneId = SubscriptionManager.getPhoneId(r.subId);
533
xinhe43c50292014-09-18 17:56:48 -0700534 int phoneId = r.phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700536 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700537 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700538 }
539 if (VDBG) toStringLogSSC("listen");
Wink Savillefb40dd42014-06-12 17:02:31 -0700540 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400542 try {
Wink Savillee380b982014-07-26 18:24:22 -0700543 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700544 r.callback.onServiceStateChanged(
545 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400546 } catch (RemoteException ex) {
547 remove(r.binder);
548 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 }
550 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
551 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700552 int gsmSignalStrength = mSignalStrength[phoneId]
553 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700554 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
555 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 } catch (RemoteException ex) {
557 remove(r.binder);
558 }
559 }
560 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
561 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700562 r.callback.onMessageWaitingIndicatorChanged(
563 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 } catch (RemoteException ex) {
565 remove(r.binder);
566 }
567 }
568 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
569 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700570 r.callback.onCallForwardingIndicatorChanged(
571 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 } catch (RemoteException ex) {
573 remove(r.binder);
574 }
575 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700576 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400577 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700578 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700579 + mCellLocation[phoneId]);
580 r.callback.onCellLocationChanged(
581 new Bundle(mCellLocation[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400582 } catch (RemoteException ex) {
583 remove(r.binder);
584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 }
586 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
587 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700588 r.callback.onCallStateChanged(mCallState[phoneId],
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700589 getCallIncomingNumber(r, phoneId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 } catch (RemoteException ex) {
591 remove(r.binder);
592 }
593 }
594 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
595 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700596 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
597 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 } catch (RemoteException ex) {
599 remove(r.binder);
600 }
601 }
602 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
603 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700604 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 } catch (RemoteException ex) {
606 remove(r.binder);
607 }
608 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700609 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
610 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700611 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700612 } catch (RemoteException ex) {
613 remove(r.binder);
614 }
615 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700616 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
617 try {
618 r.callback.onOtaspChanged(mOtaspMode);
619 } catch (RemoteException ex) {
620 remove(r.binder);
621 }
622 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700623 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700624 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700625 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700626 + mCellInfo.get(phoneId));
627 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
John Wang963db55d2012-03-30 16:04:06 -0700628 } catch (RemoteException ex) {
629 remove(r.binder);
630 }
631 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200632 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
633 try {
634 r.callback.onPreciseCallStateChanged(mPreciseCallState);
635 } catch (RemoteException ex) {
636 remove(r.binder);
637 }
638 }
639 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
640 try {
641 r.callback.onPreciseDataConnectionStateChanged(
642 mPreciseDataConnectionState);
643 } catch (RemoteException ex) {
644 remove(r.binder);
645 }
646 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400647 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
648 try {
649 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
650 } catch (RemoteException ex) {
651 remove(r.binder);
652 }
653 }
fionaxu12312f62016-11-14 13:32:14 -0800654 if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) {
655 try {
656 r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]);
657 } catch (RemoteException ex) {
658 remove(r.binder);
659 }
660 }
661 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) {
662 try {
663 r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]);
664 } catch (RemoteException ex) {
665 remove(r.binder);
666 }
667 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 }
669 }
670 } else {
xinhe75c2c152014-10-16 11:49:45 -0700671 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 remove(callback.asBinder());
673 }
674 }
675
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700676 private boolean canReadPhoneState(String callingPackage) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700677 if (mContext.checkCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700678 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) ==
679 PackageManager.PERMISSION_GRANTED) {
Amit Mahajana9e72a72015-07-30 16:04:13 -0700680 // SKIP checking for run-time permission since caller or self has PRIVILEGED permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -0700681 return true;
682 }
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700683 boolean canReadPhoneState = mContext.checkCallingOrSelfPermission(
684 android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
685 if (canReadPhoneState &&
686 mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
687 callingPackage) != AppOpsManager.MODE_ALLOWED) {
688 return false;
689 }
690 return canReadPhoneState;
691 }
692
693 private String getCallIncomingNumber(Record record, int phoneId) {
694 // Hide the number if record's process has no READ_PHONE_STATE permission
695 return record.canReadPhoneState ? mCallIncomingNumber[phoneId] : "";
696 }
697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 private void remove(IBinder binder) {
699 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700700 final int recordCount = mRecords.size();
701 for (int i = 0; i < recordCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800702 if (mRecords.get(i).binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800703 if (DBG) {
704 Record r = mRecords.get(i);
Svet Ganov16a16892015-04-16 10:32:04 -0700705 log("remove: binder=" + binder + "r.callingPackage" + r.callingPackage
xinheac11ae92014-12-18 10:02:14 -0800706 + "r.callback" + r.callback);
707 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800708 mRecords.remove(i);
709 return;
710 }
711 }
712 }
713 }
714
715 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700716 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700717 return;
718 }
xinhe43c50292014-09-18 17:56:48 -0700719
720 if (VDBG) {
721 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
722 }
723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800724 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700725 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800726 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800727 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800728 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700729 String incomingNumberOrEmpty = r.canReadPhoneState ? incomingNumber : "";
730 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400732 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 }
734 }
735 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400736 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700738
739 // Called only by Telecomm to communicate call state across different phone accounts. So
740 // there is no need to add a valid subId or slotId.
Wink Savilled09c4ca2014-11-22 10:08:16 -0800741 broadcastCallStateChanged(state, incomingNumber,
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700742 SubscriptionManager.INVALID_PHONE_INDEX,
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -0700743 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 }
745
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700746 public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
747 String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700748 if (!checkNotifyPermission("notifyCallState()")) {
749 return;
750 }
Wink Savillee380b982014-07-26 18:24:22 -0700751 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700752 log("notifyCallStateForPhoneId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700753 + " state=" + state + " incomingNumber=" + incomingNumber);
754 }
755 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700756 if (validatePhoneId(phoneId)) {
757 mCallState[phoneId] = state;
758 mCallIncomingNumber[phoneId] = incomingNumber;
759 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800760 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700761 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800762 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700763 try {
Fyodor Kupolov309b2f632015-06-03 16:29:01 -0700764 String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
765 r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
Wink Savillefb40dd42014-06-12 17:02:31 -0700766 } catch (RemoteException ex) {
767 mRemoveList.add(r.binder);
768 }
769 }
770 }
771 }
772 handleRemoveListLocked();
773 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700774 broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700775 }
776
Wink Saville63f03dd2014-10-23 10:44:45 -0700777 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700778 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700779 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700780 }
xinhe43c50292014-09-18 17:56:48 -0700781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800782 synchronized (mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700783 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700784 log("notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
Wink Saville47d8d1b2014-07-10 13:01:52 -0700785 + " state=" + state);
786 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700787 if (validatePhoneId(phoneId)) {
788 mServiceState[phoneId] = state;
Wink Savillebc027272014-09-08 14:50:58 -0700789 logServiceStateChanged("notifyServiceStateForSubscriber", subId, phoneId, state);
790 if (VDBG) toStringLogSSC("notifyServiceStateForSubscriber");
Wink Saville47d8d1b2014-07-10 13:01:52 -0700791
Wink Savillefb40dd42014-06-12 17:02:31 -0700792 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700793 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700794 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700795 + " phoneId=" + phoneId + " state=" + state);
796 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800797 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800798 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700799 try {
Wink Savillee380b982014-07-26 18:24:22 -0700800 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700801 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700802 + " subId=" + subId + " phoneId=" + phoneId
803 + " state=" + state);
804 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700805 r.callback.onServiceStateChanged(new ServiceState(state));
806 } catch (RemoteException ex) {
807 mRemoveList.add(r.binder);
808 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400809 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800810 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700811 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700812 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400814 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800815 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700816 broadcastServiceStateChanged(state, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800817 }
818
fionaxu12312f62016-11-14 13:32:14 -0800819 public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
820 int activationType, int activationState) {
821 if (!checkNotifyPermission("notifySimActivationState()")){
822 return;
823 }
824 if (VDBG) {
825 log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId
826 + "type=" + activationType + " state=" + activationState);
827 }
828 synchronized (mRecords) {
829 if (validatePhoneId(phoneId)) {
830 switch (activationType) {
831 case PhoneConstants.SIM_ACTIVATION_TYPE_VOICE:
832 mVoiceActivationState[phoneId] = activationState;
833 break;
834 case PhoneConstants.SIM_ACTIVATION_TYPE_DATA:
835 mDataActivationState[phoneId] = activationState;
836 break;
837 default:
838 return;
839 }
840 for (Record r : mRecords) {
841 if (VDBG) {
842 log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId
843 + " phoneId=" + phoneId + "type=" + activationType
844 + " state=" + activationState);
845 }
846 try {
847 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_VOICE) &&
848 r.matchPhoneStateListenerEvent(
849 PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) &&
850 idMatch(r.subId, subId, phoneId)) {
851 if (DBG) {
852 log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r
853 + " subId=" + subId + " phoneId=" + phoneId
854 + " state=" + activationState);
855 }
856 r.callback.onVoiceActivationStateChanged(activationState);
857 }
858 if ((activationType == PhoneConstants.SIM_ACTIVATION_TYPE_DATA) &&
859 r.matchPhoneStateListenerEvent(
860 PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) &&
861 idMatch(r.subId, subId, phoneId)) {
862 if (DBG) {
863 log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r
864 + " subId=" + subId + " phoneId=" + phoneId
865 + " state=" + activationState);
866 }
867 r.callback.onDataActivationStateChanged(activationState);
868 }
869 } catch (RemoteException ex) {
870 mRemoveList.add(r.binder);
871 }
872 }
873 } else {
874 log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId);
875 }
876 handleRemoveListLocked();
877 }
878 }
879
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700880 public void notifySignalStrengthForPhoneId(int phoneId, int subId,
881 SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700882 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700883 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700884 }
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000885 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700886 log("notifySignalStrengthForPhoneId: subId=" + subId
887 +" phoneId=" + phoneId + " signalStrength=" + signalStrength);
888 toStringLogSSC("notifySignalStrengthForPhoneId");
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000889 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700892 if (validatePhoneId(phoneId)) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700893 if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700894 mSignalStrength[phoneId] = signalStrength;
895 for (Record r : mRecords) {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000896 if (VDBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700897 log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000898 + " phoneId=" + phoneId + " ss=" + signalStrength);
899 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800900 if (r.matchPhoneStateListenerEvent(
901 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800902 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700903 try {
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000904 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700905 log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000906 + " subId=" + subId + " phoneId=" + phoneId
907 + " ss=" + signalStrength);
908 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700909 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
910 } catch (RemoteException ex) {
911 mRemoveList.add(r.binder);
912 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400913 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800914 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800915 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700916 try {
917 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700918 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000919 if (DBG) {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700920 log("notifySignalStrengthForPhoneId: callback.onSS r=" + r
Amit Mahajan1466a9c2015-04-27 22:58:29 +0000921 + " subId=" + subId + " phoneId=" + phoneId
922 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
923 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700924 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700925 } catch (RemoteException ex) {
926 mRemoveList.add(r.binder);
927 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 }
929 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700930 } else {
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700931 log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400933 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -0700935 broadcastSignalStrengthChanged(signalStrength, phoneId, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 }
937
Andrew Flynn1f452642015-04-14 22:16:04 -0400938 @Override
939 public void notifyCarrierNetworkChange(boolean active) {
Andrew Flynnceaed682015-06-09 12:36:58 +0000940 enforceNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()");
941
Andrew Flynn1f452642015-04-14 22:16:04 -0400942 if (VDBG) {
943 log("notifyCarrierNetworkChange: active=" + active);
944 }
945
946 synchronized (mRecords) {
947 mCarrierNetworkChangeState = active;
948 for (Record r : mRecords) {
949 if (r.matchPhoneStateListenerEvent(
950 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
951 try {
952 r.callback.onCarrierNetworkChange(active);
953 } catch (RemoteException ex) {
954 mRemoveList.add(r.binder);
955 }
956 }
957 }
958 handleRemoveListLocked();
959 }
960 }
961
Wink Savilleb208a242012-07-25 14:08:09 -0700962 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800963 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700964 }
965
Wink Saville63f03dd2014-10-23 10:44:45 -0700966 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700967 if (!checkNotifyPermission("notifyCellInfo()")) {
968 return;
969 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700970 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700971 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700972 + " cellInfo=" + cellInfo);
973 }
John Wang963db55d2012-03-30 16:04:06 -0700974
975 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700976 int phoneId = SubscriptionManager.getPhoneId(subId);
977 if (validatePhoneId(phoneId)) {
978 mCellInfo.set(phoneId, cellInfo);
979 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -0700980 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
xinhe8b79fb62014-11-05 14:55:03 -0800981 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700982 try {
983 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700984 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -0700985 }
986 r.callback.onCellInfoChanged(cellInfo);
987 } catch (RemoteException ex) {
988 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700989 }
John Wang963db55d2012-03-30 16:04:06 -0700990 }
991 }
992 }
993 handleRemoveListLocked();
994 }
995 }
996
xinhe43c50292014-09-18 17:56:48 -0700997 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700998 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700999 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001000 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001001 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001002 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -07001003 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -07001004 + " mwi=" + mwi);
1005 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001007 if (validatePhoneId(phoneId)) {
1008 mMessageWaiting[phoneId] = mwi;
1009 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001010 if (r.matchPhoneStateListenerEvent(
1011 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001012 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001013 try {
1014 r.callback.onMessageWaitingIndicatorChanged(mwi);
1015 } catch (RemoteException ex) {
1016 mRemoveList.add(r.binder);
1017 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001018 }
1019 }
1020 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001021 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001022 }
1023 }
1024
1025 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001026 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -07001027 }
1028
Wink Saville63f03dd2014-10-23 10:44:45 -07001029 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001030 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001031 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001032 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001033 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001034 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001035 + " cfi=" + cfi);
1036 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001037 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001038 int phoneId = SubscriptionManager.getPhoneId(subId);
1039 if (validatePhoneId(phoneId)) {
1040 mCallForwarding[phoneId] = cfi;
1041 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001042 if (r.matchPhoneStateListenerEvent(
1043 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -08001044 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001045 try {
1046 r.callback.onCallForwardingIndicatorChanged(cfi);
1047 } catch (RemoteException ex) {
1048 mRemoveList.add(r.binder);
1049 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 }
1051 }
1052 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001053 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 }
1055 }
1056
1057 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001058 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -07001059 }
1060
Wink Saville63f03dd2014-10-23 10:44:45 -07001061 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001062 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001063 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001064 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001066 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001067 if (validatePhoneId(phoneId)) {
1068 mDataActivity[phoneId] = state;
1069 for (Record r : mRecords) {
xu.peng9071ced2016-03-22 18:21:28 +08001070 // Notify by correct subId.
1071 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
1072 idMatch(r.subId, subId, phoneId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001073 try {
1074 r.callback.onDataActivity(state);
1075 } catch (RemoteException ex) {
1076 mRemoveList.add(r.binder);
1077 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 }
1079 }
1080 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001081 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 }
1083 }
1084
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001085 public void notifyDataConnection(int state, boolean isDataConnectivityPossible,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001086 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001087 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001088 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
xinhe43c50292014-09-18 17:56:48 -07001089 isDataConnectivityPossible,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001090 networkCapabilities, networkType, roaming);
1091 }
1092
Wink Saville63f03dd2014-10-23 10:44:45 -07001093 public void notifyDataConnectionForSubscriber(int subId, int state,
Wink Savillefb40dd42014-06-12 17:02:31 -07001094 boolean isDataConnectivityPossible, String reason, String apn, String apnType,
1095 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
1096 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001097 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001098 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001099 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001100 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001101 log("notifyDataConnectionForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001102 + " state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible
1103 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001104 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001105 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001106 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001108 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001109 if (validatePhoneId(phoneId)) {
1110 boolean modified = false;
1111 if (state == TelephonyManager.DATA_CONNECTED) {
Yifan Bai57b39e32016-04-01 16:24:33 +08001112 if (!mConnectedApns[phoneId].contains(apnType)) {
1113 mConnectedApns[phoneId].add(apnType);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001114 if (mDataConnectionState[phoneId] != state) {
1115 mDataConnectionState[phoneId] = state;
1116 modified = true;
1117 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001119 } else {
Yifan Bai57b39e32016-04-01 16:24:33 +08001120 if (mConnectedApns[phoneId].remove(apnType)) {
1121 if (mConnectedApns[phoneId].isEmpty()) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001122 mDataConnectionState[phoneId] = state;
1123 modified = true;
1124 } else {
1125 // leave mDataConnectionState as is and
1126 // send out the new status for the APN in question.
Wink Savillebaf21da2014-11-19 16:03:09 -08001127 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001128 }
1129 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001130 mDataConnectionPossible[phoneId] = isDataConnectivityPossible;
1131 mDataConnectionReason[phoneId] = reason;
1132 mDataConnectionLinkProperties[phoneId] = linkProperties;
1133 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
1134 if (mDataConnectionNetworkType[phoneId] != networkType) {
1135 mDataConnectionNetworkType[phoneId] = networkType;
1136 // need to tell registered listeners about the new network type
1137 modified = true;
1138 }
1139 if (modified) {
1140 if (DBG) {
1141 log("onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
1142 + ", " + mDataConnectionNetworkType[phoneId] + ")");
1143 }
1144 for (Record r : mRecords) {
1145 if (r.matchPhoneStateListenerEvent(
1146 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1147 idMatch(r.subId, subId, phoneId)) {
1148 try {
1149 log("Notify data connection state changed on sub: " +
1150 subId);
1151 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1152 mDataConnectionNetworkType[phoneId]);
1153 } catch (RemoteException ex) {
1154 mRemoveList.add(r.binder);
1155 }
1156 }
1157 }
1158 handleRemoveListLocked();
1159 }
1160 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1161 apnType, apn, reason, linkProperties, "");
1162 for (Record r : mRecords) {
1163 if (r.matchPhoneStateListenerEvent(
1164 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1165 try {
1166 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1167 } catch (RemoteException ex) {
1168 mRemoveList.add(r.binder);
1169 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001170 }
1171 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001172 }
1173 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001174 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001175 broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001176 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001177 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1178 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 }
1180
Robert Greenwalt02648a42010-05-18 10:52:51 -07001181 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001182 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001183 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001184 }
1185
Wink Saville63f03dd2014-10-23 10:44:45 -07001186 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001187 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001188 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001189 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001190 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001191 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001192 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001193 + " reason=" + reason + " apnType=" + apnType);
1194 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001195 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001196 mPreciseDataConnectionState = new PreciseDataConnectionState(
1197 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1198 apnType, "", reason, null, "");
1199 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001200 if (r.matchPhoneStateListenerEvent(
1201 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001202 try {
1203 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1204 } catch (RemoteException ex) {
1205 mRemoveList.add(r.binder);
1206 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 }
1208 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001209 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001210 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001211 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001212 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1213 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001214 }
1215
1216 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001217 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001218 }
1219
Wink Saville63f03dd2014-10-23 10:44:45 -07001220 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001221 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001222 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001223 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001224 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001225 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001226 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001227 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001228 + " cellLocation=" + cellLocation);
1229 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001231 int phoneId = SubscriptionManager.getPhoneId(subId);
1232 if (validatePhoneId(phoneId)) {
1233 mCellLocation[phoneId] = cellLocation;
1234 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001235 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
xinhe8b79fb62014-11-05 14:55:03 -08001236 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001237 try {
1238 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001239 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001240 + " r=" + r);
1241 }
1242 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1243 } catch (RemoteException ex) {
1244 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001245 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001246 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 }
1248 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001249 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001250 }
1251 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252
Wink Savillefd2d0132010-10-28 14:22:26 -07001253 public void notifyOtaspChanged(int otaspMode) {
1254 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1255 return;
1256 }
1257 synchronized (mRecords) {
1258 mOtaspMode = otaspMode;
1259 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001260 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001261 try {
1262 r.callback.onOtaspChanged(otaspMode);
1263 } catch (RemoteException ex) {
1264 mRemoveList.add(r.binder);
1265 }
1266 }
1267 }
1268 handleRemoveListLocked();
1269 }
1270 }
1271
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001272 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1273 int backgroundCallState) {
1274 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1275 return;
1276 }
1277 synchronized (mRecords) {
1278 mRingingCallState = ringingCallState;
1279 mForegroundCallState = foregroundCallState;
1280 mBackgroundCallState = backgroundCallState;
1281 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1282 backgroundCallState,
1283 DisconnectCause.NOT_VALID,
1284 PreciseDisconnectCause.NOT_VALID);
1285 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001286 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001287 try {
1288 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1289 } catch (RemoteException ex) {
1290 mRemoveList.add(r.binder);
1291 }
1292 }
1293 }
1294 handleRemoveListLocked();
1295 }
1296 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1297 DisconnectCause.NOT_VALID,
1298 PreciseDisconnectCause.NOT_VALID);
1299 }
1300
1301 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1302 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1303 return;
1304 }
1305 synchronized (mRecords) {
1306 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1307 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1308 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001309 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001310 try {
1311 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1312 } catch (RemoteException ex) {
1313 mRemoveList.add(r.binder);
1314 }
1315 }
1316 }
1317 handleRemoveListLocked();
1318 }
1319 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1320 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1321 }
1322
1323 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1324 String apn, String failCause) {
1325 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1326 return;
1327 }
1328 synchronized (mRecords) {
1329 mPreciseDataConnectionState = new PreciseDataConnectionState(
1330 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1331 apnType, apn, reason, null, failCause);
1332 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001333 if (r.matchPhoneStateListenerEvent(
1334 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001335 try {
1336 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1337 } catch (RemoteException ex) {
1338 mRemoveList.add(r.binder);
1339 }
1340 }
1341 }
1342 handleRemoveListLocked();
1343 }
1344 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1345 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1346 }
1347
Wink Savillefb40dd42014-06-12 17:02:31 -07001348 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1349 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1350 return;
1351 }
1352 synchronized (mRecords) {
1353 mVoLteServiceState = lteState;
1354 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001355 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001356 try {
1357 r.callback.onVoLteServiceStateChanged(
1358 new VoLteServiceState(mVoLteServiceState));
1359 } catch (RemoteException ex) {
1360 mRemoveList.add(r.binder);
1361 }
1362 }
1363 }
1364 handleRemoveListLocked();
1365 }
1366 }
1367
Wink Saville63f03dd2014-10-23 10:44:45 -07001368 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001369 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1370 return;
1371 }
1372
1373 synchronized (mRecords) {
1374 for (Record r : mRecords) {
1375 if (VDBG) {
1376 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1377 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001378 if ((r.matchPhoneStateListenerEvent(
1379 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
New Author Steven Liu485f2092014-09-11 10:18:45 -05001380 ((r.subId == subId) ||
Wink Savilled09c4ca2014-11-22 10:08:16 -08001381 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001382 try {
1383 r.callback.onOemHookRawEvent(rawData);
1384 } catch (RemoteException ex) {
1385 mRemoveList.add(r.binder);
1386 }
1387 }
1388 }
1389 handleRemoveListLocked();
1390 }
1391 }
1392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001393 @Override
1394 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1395 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1396 != PackageManager.PERMISSION_GRANTED) {
1397 pw.println("Permission Denial: can't dump telephony.registry from from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001398 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399 return;
1400 }
1401 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001402 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001403 pw.println("last known state:");
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301404 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1405 pw.println(" Phone Id=" + i);
1406 pw.println(" mCallState=" + mCallState[i]);
1407 pw.println(" mCallIncomingNumber=" + mCallIncomingNumber[i]);
1408 pw.println(" mServiceState=" + mServiceState[i]);
fionaxu12312f62016-11-14 13:32:14 -08001409 pw.println(" mVoiceActivationState= " + mVoiceActivationState[i]);
1410 pw.println(" mDataActivationState= " + mDataActivationState[i]);
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301411 pw.println(" mSignalStrength=" + mSignalStrength[i]);
1412 pw.println(" mMessageWaiting=" + mMessageWaiting[i]);
1413 pw.println(" mCallForwarding=" + mCallForwarding[i]);
1414 pw.println(" mDataActivity=" + mDataActivity[i]);
1415 pw.println(" mDataConnectionState=" + mDataConnectionState[i]);
1416 pw.println(" mDataConnectionPossible=" + mDataConnectionPossible[i]);
1417 pw.println(" mDataConnectionReason=" + mDataConnectionReason[i]);
1418 pw.println(" mDataConnectionApn=" + mDataConnectionApn[i]);
1419 pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1420 pw.println(" mDataConnectionNetworkCapabilities=" +
1421 mDataConnectionNetworkCapabilities[i]);
1422 pw.println(" mCellLocation=" + mCellLocation[i]);
1423 pw.println(" mCellInfo=" + mCellInfo.get(i));
1424 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001425 pw.println("registrations: count=" + recordCount);
Robert Greenwalt02648a42010-05-18 10:52:51 -07001426 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -07001427 pw.println(" " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001428 }
1429 }
1430 }
1431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 //
1433 // the legacy intent broadcasting
1434 //
1435
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001436 private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001437 long ident = Binder.clearCallingIdentity();
1438 try {
1439 mBatteryStats.notePhoneState(state.getState());
1440 } catch (RemoteException re) {
1441 // Can't do much
1442 } finally {
1443 Binder.restoreCallingIdentity(ident);
1444 }
1445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
Christopher Tate42a386b2016-11-07 12:21:21 -08001447 intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 Bundle data = new Bundle();
1449 state.fillInNotifierBundle(data);
1450 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001451 // Pass the subscription along with the intent.
1452 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001453 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001454 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001455 }
1456
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001457 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId,
1458 int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001459 long ident = Binder.clearCallingIdentity();
1460 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001461 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001462 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001463 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001464 } finally {
1465 Binder.restoreCallingIdentity(ident);
1466 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001468 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Wink Savillee9b06d72009-05-18 21:47:50 -07001469 Bundle data = new Bundle();
1470 signalStrength.fillInNotifierBundle(data);
1471 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001472 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001473 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001474 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 }
1476
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001477 /**
1478 * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be
1479 * a valid subId, in which case this function fires a subId-specific intent, or it
1480 * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send
1481 * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}).
1482 */
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001483 private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId,
1484 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001485 long ident = Binder.clearCallingIdentity();
1486 try {
1487 if (state == TelephonyManager.CALL_STATE_IDLE) {
1488 mBatteryStats.notePhoneOff();
1489 } else {
1490 mBatteryStats.notePhoneOn();
1491 }
1492 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001493 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 } finally {
1495 Binder.restoreCallingIdentity(ident);
1496 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001499 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001500 PhoneConstantConversions.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501 if (!TextUtils.isEmpty(incomingNumber)) {
1502 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1503 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001504
1505 // If a valid subId was specified, we should fire off a subId-specific state
1506 // change intent and include the subId.
1507 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
1508 intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED);
1509 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
1510 }
Shishir Agrawalf7e59c12016-04-13 09:55:55 -07001511 // If the phoneId is invalid, the broadcast is for overall call state.
1512 if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) {
1513 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
1514 }
Sharvil Nanavati61a3ab02015-04-23 13:57:24 -07001515
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001516 // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those
1517 // that have the runtime one
1518 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1519 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001520 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001521 android.Manifest.permission.READ_PHONE_STATE,
1522 AppOpsManager.OP_READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 }
1524
Robert Greenwalt42acef32009-08-12 16:08:25 -07001525 private void broadcastDataConnectionStateChanged(int state,
1526 boolean isDataConnectivityPossible,
Wink Savillef61101f2010-09-16 16:36:42 -07001527 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001528 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001529 // Note: not reporting to the battery stats service here, because the
1530 // status bar takes care of that after taking into account all of the
1531 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001533 intent.putExtra(PhoneConstants.STATE_KEY,
Nathan Harold5a0618e2016-12-14 10:48:00 -08001534 PhoneConstantConversions.convertDataState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535 if (!isDataConnectivityPossible) {
Wink Savillea639b312012-07-10 12:37:54 -07001536 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001537 }
1538 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001539 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001541 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001542 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001543 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001544 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001545 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001546 }
1547 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001548 if (networkCapabilities != null) {
1549 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001550 }
Wink Savillea639b312012-07-10 12:37:54 -07001551 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001552
Wink Savillea639b312012-07-10 12:37:54 -07001553 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1554 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001555 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001556 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 }
1558
Wink Savillefb40dd42014-06-12 17:02:31 -07001559 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001560 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001562 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1563 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001564 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001565 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001566 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001567
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001568 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1569 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1570 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1571 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1572 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1573 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1574 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1575 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1576 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1577 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1578 }
1579
1580 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001581 String apnType, String apn, String reason, LinkProperties linkProperties,
1582 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001583 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1584 intent.putExtra(PhoneConstants.STATE_KEY, state);
1585 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1586 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1587 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1588 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001589 if (linkProperties != null) {
1590 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1591 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001592 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1593
1594 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1595 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1596 }
1597
Andrew Flynnceaed682015-06-09 12:36:58 +00001598 private void enforceNotifyPermissionOrCarrierPrivilege(String method) {
1599 if (checkNotifyPermission()) {
1600 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001601 }
1602
Andrew Flynnceaed682015-06-09 12:36:58 +00001603 enforceCarrierPrivilege();
Andrew Flynn1f452642015-04-14 22:16:04 -04001604 }
1605
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001606 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001607 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001608 return true;
1609 }
1610 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001611 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001612 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001613 return false;
1614 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001615
Andrew Flynn1f452642015-04-14 22:16:04 -04001616 private boolean checkNotifyPermission() {
1617 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1618 == PackageManager.PERMISSION_GRANTED;
1619 }
1620
Andrew Flynnceaed682015-06-09 12:36:58 +00001621 private void enforceCarrierPrivilege() {
Andrew Flynn1f452642015-04-14 22:16:04 -04001622 TelephonyManager tm = TelephonyManager.getDefault();
1623 String[] pkgs = mContext.getPackageManager().getPackagesForUid(Binder.getCallingUid());
1624 for (String pkg : pkgs) {
1625 if (tm.checkCarrierPrivilegesForPackage(pkg) ==
1626 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Andrew Flynnceaed682015-06-09 12:36:58 +00001627 return;
Andrew Flynn1f452642015-04-14 22:16:04 -04001628 }
1629 }
1630
Andrew Flynnceaed682015-06-09 12:36:58 +00001631 String msg = "Carrier Privilege Permission Denial: from pid=" + Binder.getCallingPid()
1632 + ", uid=" + Binder.getCallingUid();
1633 if (DBG) log(msg);
1634 throw new SecurityException(msg);
Andrew Flynn1f452642015-04-14 22:16:04 -04001635 }
1636
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001637 private void checkListenerPermission(int events) {
1638 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1639 mContext.enforceCallingOrSelfPermission(
1640 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1641
1642 }
1643
John Wang963db55d2012-03-30 16:04:06 -07001644 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1645 mContext.enforceCallingOrSelfPermission(
1646 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1647
1648 }
1649
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001650 if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001651 try {
Amit Mahajana9e72a72015-07-30 16:04:13 -07001652 mContext.enforceCallingOrSelfPermission(
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001653 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
Amit Mahajana9e72a72015-07-30 16:04:13 -07001654 // SKIP checking for run-time permission since caller or self has PRIVILEGED
1655 // permission
Amit Mahajan1cfd4572015-07-09 11:12:19 -07001656 } catch (SecurityException e) {
1657 mContext.enforceCallingOrSelfPermission(
1658 android.Manifest.permission.READ_PHONE_STATE, null);
1659 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001660 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001661
1662 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1663 mContext.enforceCallingOrSelfPermission(
1664 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1665
1666 }
New Author Steven Liu485f2092014-09-11 10:18:45 -05001667
1668 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1669 mContext.enforceCallingOrSelfPermission(
1670 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1671 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001672 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001673
1674 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001675 int size = mRemoveList.size();
1676 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1677 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001678 for (IBinder b: mRemoveList) {
1679 remove(b);
1680 }
1681 mRemoveList.clear();
1682 }
1683 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001684
1685 private boolean validateEventsAndUserLocked(Record r, int events) {
1686 int foregroundUser;
1687 long callingIdentity = Binder.clearCallingIdentity();
1688 boolean valid = false;
1689 try {
1690 foregroundUser = ActivityManager.getCurrentUser();
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001691 valid = r.callerUserId == foregroundUser && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001692 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001693 log("validateEventsAndUserLocked: valid=" + valid
Fyodor Kupolov309b2f632015-06-03 16:29:01 -07001694 + " r.callerUserId=" + r.callerUserId + " foregroundUser=" + foregroundUser
Wink Savillea12a7b32012-09-20 10:09:45 -07001695 + " r.events=" + r.events + " events=" + events);
1696 }
1697 } finally {
1698 Binder.restoreCallingIdentity(callingIdentity);
1699 }
1700 return valid;
1701 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001702
1703 private boolean validatePhoneId(int phoneId) {
1704 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001705 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001706 return valid;
1707 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001708
1709 private static void log(String s) {
1710 Rlog.d(TAG, s);
1711 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001712
1713 private static class LogSSC {
1714 private Time mTime;
1715 private String mS;
Wink Saville63f03dd2014-10-23 10:44:45 -07001716 private int mSubId;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001717 private int mPhoneId;
1718 private ServiceState mState;
1719
Wink Saville63f03dd2014-10-23 10:44:45 -07001720 public void set(Time t, String s, int subId, int phoneId, ServiceState state) {
Wink Saville47d8d1b2014-07-10 13:01:52 -07001721 mTime = t; mS = s; mSubId = subId; mPhoneId = phoneId; mState = state;
1722 }
1723
1724 @Override
1725 public String toString() {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001726 return mS + " Time " + mTime.toString() + " mSubId " + mSubId + " mPhoneId "
1727 + mPhoneId + " mState " + mState;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001728 }
1729 }
1730
1731 private LogSSC logSSC [] = new LogSSC[10];
1732 private int next = 0;
1733
Wink Saville63f03dd2014-10-23 10:44:45 -07001734 private void logServiceStateChanged(String s, int subId, int phoneId, ServiceState state) {
Wink Saville47d8d1b2014-07-10 13:01:52 -07001735 if (logSSC == null || logSSC.length == 0) {
1736 return;
1737 }
1738 if (logSSC[next] == null) {
1739 logSSC[next] = new LogSSC();
1740 }
1741 Time t = new Time();
1742 t.setToNow();
1743 logSSC[next].set(t, s, subId, phoneId, state);
1744 if (++next >= logSSC.length) {
1745 next = 0;
1746 }
1747 }
1748
1749 private void toStringLogSSC(String prompt) {
1750 if (logSSC == null || logSSC.length == 0 || (next == 0 && logSSC[next] == null)) {
1751 log(prompt + ": logSSC is empty");
1752 } else {
1753 // There is at least one element
1754 log(prompt + ": logSSC.length=" + logSSC.length + " next=" + next);
1755 int i = next;
1756 if (logSSC[i] == null) {
1757 // logSSC is not full so back to the beginning
1758 i = 0;
1759 }
1760 do {
1761 log(logSSC[i].toString());
1762 if (++i >= logSSC.length) {
1763 i = 0;
1764 }
1765 } while (i != next);
Wink Savillee380b982014-07-26 18:24:22 -07001766 log(prompt + ": ----------------");
Wink Saville47d8d1b2014-07-10 13:01:52 -07001767 }
1768 }
xinhee9f16402014-09-25 16:39:28 -07001769
xinhe8b79fb62014-11-05 14:55:03 -08001770 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001771
1772 if(subId < 0) {
1773 // Invalid case, we need compare phoneId with default one.
1774 return (mDefaultPhoneId == phoneId);
1775 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001776 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001777 return (subId == mDefaultSubId);
1778 } else {
1779 return (rSubId == subId);
1780 }
1781 }
1782
1783 private void checkPossibleMissNotify(Record r, int phoneId) {
1784 int events = r.events;
1785
1786 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1787 try {
1788 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1789 mServiceState[phoneId]);
1790 r.callback.onServiceStateChanged(
1791 new ServiceState(mServiceState[phoneId]));
1792 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001793 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001794 }
1795 }
1796
1797 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1798 try {
1799 SignalStrength signalStrength = mSignalStrength[phoneId];
1800 if (DBG) {
1801 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1802 }
1803 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1804 } catch (RemoteException ex) {
1805 mRemoveList.add(r.binder);
1806 }
1807 }
1808
1809 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1810 try {
1811 int gsmSignalStrength = mSignalStrength[phoneId]
1812 .getGsmSignalStrength();
1813 if (DBG) {
1814 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1815 gsmSignalStrength);
1816 }
1817 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1818 : gsmSignalStrength));
1819 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001820 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001821 }
1822 }
1823
1824 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1825 try {
1826 if (DBG_LOC) {
1827 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1828 + mCellInfo.get(phoneId));
1829 }
1830 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1831 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001832 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001833 }
1834 }
1835
1836 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1837 try {
1838 if (VDBG) {
1839 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1840 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1841 }
1842 r.callback.onMessageWaitingIndicatorChanged(
1843 mMessageWaiting[phoneId]);
1844 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001845 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001846 }
1847 }
1848
1849 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1850 try {
1851 if (VDBG) {
1852 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1853 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1854 }
1855 r.callback.onCallForwardingIndicatorChanged(
1856 mCallForwarding[phoneId]);
1857 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001858 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001859 }
1860 }
1861
1862 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1863 try {
1864 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1865 + mCellLocation[phoneId]);
1866 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1867 } catch (RemoteException ex) {
1868 mRemoveList.add(r.binder);
1869 }
1870 }
1871
1872 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1873 try {
1874 if (DBG) {
1875 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1876 + "=" + mDataConnectionState[phoneId]
1877 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1878 + ")");
1879 }
1880 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1881 mDataConnectionNetworkType[phoneId]);
1882 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001883 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001884 }
1885 }
1886 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001887}