blob: 4ee665770d4fec150efa0dd05ad1c80615a2800f [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 Saville070e0612014-04-15 22:04:10 -070036import android.telephony.DataConnectionRealTimeInfo;
Wink Savillef4cd25b2014-07-08 19:03:20 -070037import android.telephony.Rlog;
Wink Savillefb40dd42014-06-12 17:02:31 -070038import android.telephony.TelephonyManager;
39import android.telephony.SubscriptionManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.telephony.PhoneStateListener;
41import android.telephony.ServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -070042import android.telephony.SignalStrength;
John Wang963db55d2012-03-30 16:04:06 -070043import android.telephony.CellInfo;
Wink Savillefb40dd42014-06-12 17:02:31 -070044import android.telephony.VoLteServiceState;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020045import android.telephony.DisconnectCause;
46import android.telephony.PreciseCallState;
47import android.telephony.PreciseDataConnectionState;
48import android.telephony.PreciseDisconnectCause;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.text.TextUtils;
Wink Saville47d8d1b2014-07-10 13:01:52 -070050import android.text.format.Time;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
52import java.util.ArrayList;
Wink Savilleb208a242012-07-25 14:08:09 -070053import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import java.io.FileDescriptor;
55import java.io.PrintWriter;
56
57import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080058import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import com.android.internal.telephony.ITelephonyRegistry;
60import com.android.internal.telephony.IPhoneStateListener;
61import com.android.internal.telephony.DefaultPhoneNotifier;
Wink Savillea639b312012-07-10 12:37:54 -070062import com.android.internal.telephony.PhoneConstants;
Wink Savillec9330dd2011-01-12 13:37:38 -080063import com.android.internal.telephony.ServiceStateTracker;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import com.android.internal.telephony.TelephonyIntents;
65import com.android.server.am.BatteryStatsService;
66
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067/**
Wink Savillee9b06d72009-05-18 21:47:50 -070068 * Since phone process can be restarted, this class provides a centralized place
69 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070070 *
71 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
72 * and 15973975 by saving the phoneId of the registrant and then using the
73 * phoneId when deciding to to make a callback. This is necessary because
74 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070075 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070076 * the dummy value conversion we properly do the callbacks.
77 *
78 * Eventually we may want to remove the notion of dummy value but for now this
79 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 */
81class TelephonyRegistry extends ITelephonyRegistry.Stub {
82 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070083 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070084 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070085 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086
87 private static class Record {
Svet Ganov16a16892015-04-16 10:32:04 -070088 String callingPackage;
Wink Savillee9b06d72009-05-18 21:47:50 -070089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -080093 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -070094
Wink Savillea12a7b32012-09-20 10:09:45 -070095 int callerUid;
96
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -070098
Wink Savilled09c4ca2014-11-22 10:08:16 -080099 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -0700100
Wink Savilled09c4ca2014-11-22 10:08:16 -0800101 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800102
103 boolean matchPhoneStateListenerEvent(int events) {
104 return (callback != null) && ((events & this.events) != 0);
105 }
106
Wink Savilled09c4ca2014-11-22 10:08:16 -0800107 boolean matchOnSubscriptionsChangedListener() {
108 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800109 }
Wink Savillee380b982014-07-26 18:24:22 -0700110
Wink Savillea12a7b32012-09-20 10:09:45 -0700111 @Override
112 public String toString() {
Svet Ganov16a16892015-04-16 10:32:04 -0700113 return "{callingPackage=" + callingPackage + " binder=" + binder
114 + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800115 + " onSubscriptionsChangedListenererCallback="
116 + onSubscriptionsChangedListenerCallback
Wink Savillea374c3d2014-11-11 11:48:04 -0800117 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
118 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700119 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 }
121
122 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700123
Joe Onorato163d8d92010-10-21 13:21:20 -0400124 // access should be inside synchronized (mRecords) for these two fields
125 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
126 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 private final IBatteryStats mBatteryStats;
129
Svet Ganov16a16892015-04-16 10:32:04 -0700130 private final AppOpsManager mAppOps;
131
Wink Savilled09c4ca2014-11-22 10:08:16 -0800132 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
133
Wink Savillefb40dd42014-06-12 17:02:31 -0700134 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700135
Wink Savillefb40dd42014-06-12 17:02:31 -0700136 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700137
Wink Savillefb40dd42014-06-12 17:02:31 -0700138 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700139
Wink Savillefb40dd42014-06-12 17:02:31 -0700140 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700141
Wink Savillefb40dd42014-06-12 17:02:31 -0700142 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700143
Wink Savillefb40dd42014-06-12 17:02:31 -0700144 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700145
Wink Savillefb40dd42014-06-12 17:02:31 -0700146 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700147
Wink Savillefb40dd42014-06-12 17:02:31 -0700148 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700149
Wink Savillefb40dd42014-06-12 17:02:31 -0700150 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700151
Wink Savillefb40dd42014-06-12 17:02:31 -0700152 private boolean[] mDataConnectionPossible;
Wink Savillee9b06d72009-05-18 21:47:50 -0700153
Wink Savillefb40dd42014-06-12 17:02:31 -0700154 private String[] mDataConnectionReason;
155
156 private String[] mDataConnectionApn;
Wink Savillee9b06d72009-05-18 21:47:50 -0700157
Robert Greenwalt02648a42010-05-18 10:52:51 -0700158 private ArrayList<String> mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700159
Wink Savillefb40dd42014-06-12 17:02:31 -0700160 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700161
Wink Savillefb40dd42014-06-12 17:02:31 -0700162 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700163
Wink Savillefb40dd42014-06-12 17:02:31 -0700164 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165
Wink Savillefb40dd42014-06-12 17:02:31 -0700166 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700167
Wink Savillec9330dd2011-01-12 13:37:38 -0800168 private int mOtaspMode = ServiceStateTracker.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700169
Wink Savillefb40dd42014-06-12 17:02:31 -0700170 private ArrayList<List<CellInfo>> mCellInfo = null;
171
172 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
173
Wink Savilled09c4ca2014-11-22 10:08:16 -0800174 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700175
Wink Savilled09c4ca2014-11-22 10:08:16 -0800176 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700177
Wink Saville070e0612014-04-15 22:04:10 -0700178 private DataConnectionRealTimeInfo mDcRtInfo = new DataConnectionRealTimeInfo();
179
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200180 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
181
182 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
183
184 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
185
186 private PreciseCallState mPreciseCallState = new PreciseCallState();
187
Andrew Flynn1f452642015-04-14 22:16:04 -0400188 private boolean mCarrierNetworkChangeState = false;
189
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200190 private PreciseDataConnectionState mPreciseDataConnectionState =
191 new PreciseDataConnectionState();
192
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700193 static final int PHONE_STATE_PERMISSION_MASK =
194 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
195 PhoneStateListener.LISTEN_CALL_STATE |
196 PhoneStateListener.LISTEN_DATA_ACTIVITY |
197 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
Wink Savillefb40dd42014-06-12 17:02:31 -0700198 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
199 PhoneStateListener.LISTEN_VOLTE_STATE;;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700200
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200201 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
202 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
203 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
204
Wink Savillea12a7b32012-09-20 10:09:45 -0700205 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700206 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700207
208 private final Handler mHandler = new Handler() {
209 @Override
210 public void handleMessage(Message msg) {
211 switch (msg.what) {
212 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700213 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700214 int numPhones = TelephonyManager.getDefault().getPhoneCount();
215 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700216 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700217 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700218 }
219 break;
220 }
xinhee9f16402014-09-25 16:39:28 -0700221 case MSG_UPDATE_DEFAULT_SUB: {
222 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700223 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700224 if (VDBG) {
225 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
226 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
227 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
228 }
229
230 //Due to possible risk condition,(notify call back using the new
231 //defaultSubId comes before new defaultSubId update) we need to recall all
232 //possible missed notify callback
233 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700234 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800235 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700236 checkPossibleMissNotify(r, newDefaultPhoneId);
237 }
238 }
239 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700240 }
241 mDefaultSubId = newDefaultSubId;
242 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700243 }
244 }
245 }
246 };
247
248 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
249 @Override
250 public void onReceive(Context context, Intent intent) {
251 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700252 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700253 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700254 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700255 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700256 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700257 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700258 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
xinhee9f16402014-09-25 16:39:28 -0700259 PhoneConstants.SUBSCRIPTION_KEY, SubscriptionManager.getDefaultSubId()));
260 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
261 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700262 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700263 log("onReceive:current mDefaultSubId=" + mDefaultSubId
264 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
265 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700266 }
xinhee9f16402014-09-25 16:39:28 -0700267
Junda Liu985f52c2015-02-23 16:06:51 -0800268 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700269 || (newDefaultPhoneId != mDefaultPhoneId))) {
270 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
271 newDefaultPhoneId, 0, newDefaultSubIdObj));
272 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700273 }
274 }
275 };
276
Wink Savillee9b06d72009-05-18 21:47:50 -0700277 // we keep a copy of all of the state so we can send it out when folks
278 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700280 // In these calls we call with the lock held. This is safe becasuse remote
281 // calls go through a oneway interface and local calls going through a
282 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283
284 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700285 CellLocation location = CellLocation.getEmpty();
286
Wink Savillefb40dd42014-06-12 17:02:31 -0700287 mContext = context;
288 mBatteryStats = BatteryStatsService.getService();
289 mConnectedApns = new ArrayList<String>();
290
Wink Savillefb40dd42014-06-12 17:02:31 -0700291 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700292 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700293 mNumPhones = numPhones;
294 mCallState = new int[numPhones];
295 mDataActivity = new int[numPhones];
296 mDataConnectionState = new int[numPhones];
297 mDataConnectionNetworkType = new int[numPhones];
298 mCallIncomingNumber = new String[numPhones];
299 mServiceState = new ServiceState[numPhones];
300 mSignalStrength = new SignalStrength[numPhones];
301 mMessageWaiting = new boolean[numPhones];
302 mDataConnectionPossible = new boolean[numPhones];
303 mDataConnectionReason = new String[numPhones];
304 mDataConnectionApn = new String[numPhones];
305 mCallForwarding = new boolean[numPhones];
306 mCellLocation = new Bundle[numPhones];
307 mDataConnectionLinkProperties = new LinkProperties[numPhones];
308 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
309 mCellInfo = new ArrayList<List<CellInfo>>();
310 for (int i = 0; i < numPhones; i++) {
311 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
312 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
313 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
314 mCallIncomingNumber[i] = "";
315 mServiceState[i] = new ServiceState();
316 mSignalStrength[i] = new SignalStrength();
317 mMessageWaiting[i] = false;
318 mCallForwarding[i] = false;
319 mDataConnectionPossible[i] = false;
320 mDataConnectionReason[i] = "";
321 mDataConnectionApn[i] = "";
322 mCellLocation[i] = new Bundle();
323 mCellInfo.add(i, null);
324 }
325
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700326 // Note that location can be null for non-phone builds like
327 // like the generic one.
328 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700329 for (int i = 0; i < numPhones; i++) {
330 location.fillInNotifierBundle(mCellLocation[i]);
331 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700332 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700333 mConnectedApns = new ArrayList<String>();
Svet Ganov16a16892015-04-16 10:32:04 -0700334
335 mAppOps = mContext.getSystemService(AppOpsManager.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336 }
337
Svetoslav Ganova0027152013-06-25 14:59:53 -0700338 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700339 // Watch for interesting updates
340 final IntentFilter filter = new IntentFilter();
341 filter.addAction(Intent.ACTION_USER_SWITCHED);
342 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700343 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700344 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700345 mContext.registerReceiver(mBroadcastReceiver, filter);
346 }
347
348 @Override
Svet Ganov16a16892015-04-16 10:32:04 -0700349 public void addOnSubscriptionsChangedListener(String callingPackage,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800350 IOnSubscriptionsChangedListener callback) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800351 int callerUid = UserHandle.getCallingUserId();
352 int myUid = UserHandle.myUserId();
353 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700354 log("listen oscl: E pkg=" + callingPackage + " myUid=" + myUid
Wink Savilled09c4ca2014-11-22 10:08:16 -0800355 + " callerUid=" + callerUid + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800356 + " callback.asBinder=" + callback.asBinder());
357 }
358
Svet Ganov16a16892015-04-16 10:32:04 -0700359 mContext.enforceCallingOrSelfPermission(
360 android.Manifest.permission.READ_PHONE_STATE, null);
361
362 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
363 callingPackage) != AppOpsManager.MODE_ALLOWED) {
364 return;
365 }
366
Wink Savilled09c4ca2014-11-22 10:08:16 -0800367 Record r = null;
Wink Savillea374c3d2014-11-11 11:48:04 -0800368
Wink Savilled09c4ca2014-11-22 10:08:16 -0800369 synchronized (mRecords) {
370 // register
371 find_and_add: {
372 IBinder b = callback.asBinder();
373 final int N = mRecords.size();
374 for (int i = 0; i < N; i++) {
375 r = mRecords.get(i);
376 if (b == r.binder) {
377 break find_and_add;
Wink Savillea374c3d2014-11-11 11:48:04 -0800378 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800379 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800380 r = new Record();
381 r.binder = b;
382 mRecords.add(r);
383 if (DBG) log("listen oscl: add new record");
Wink Savillea374c3d2014-11-11 11:48:04 -0800384 }
385
Wink Savilled09c4ca2014-11-22 10:08:16 -0800386 r.onSubscriptionsChangedListenerCallback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700387 r.callingPackage = callingPackage;
Wink Savilled09c4ca2014-11-22 10:08:16 -0800388 r.callerUid = callerUid;
389 r.events = 0;
390 if (DBG) {
391 log("listen oscl: Register r=" + r);
392 }
393 // Always notify when registration occurs if there has been a notification.
394 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800395 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800396 if (VDBG) log("listen oscl: send to r=" + r);
397 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
398 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800399 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800400 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800401 remove(r.binder);
402 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800403 } else {
404 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800405 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800406 }
407 }
408
409 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800410 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800411 IOnSubscriptionsChangedListener callback) {
412 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800413 remove(callback.asBinder());
414 }
415
Wink Savillea374c3d2014-11-11 11:48:04 -0800416 @Override
417 public void notifySubscriptionInfoChanged() {
418 if (VDBG) log("notifySubscriptionInfoChanged:");
419 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800420 if (!hasNotifySubscriptionInfoChangedOccurred) {
421 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
422 + mRecords.size());
423 }
424 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800425 mRemoveList.clear();
426 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800427 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800428 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800429 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
430 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
431 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800432 } catch (RemoteException ex) {
433 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
434 mRemoveList.add(r.binder);
435 }
436 }
437 }
438 handleRemoveListLocked();
439 }
440 }
441
442 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
444 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800445 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
446 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700447 }
448
449 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700450 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700451 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700452 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700453 }
454
Svet Ganov16a16892015-04-16 10:32:04 -0700455 private void listen(String callingPackage, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700456 boolean notifyNow, int subId) {
Wink Savillea12a7b32012-09-20 10:09:45 -0700457 int callerUid = UserHandle.getCallingUserId();
458 int myUid = UserHandle.myUserId();
Wink Savillee380b982014-07-26 18:24:22 -0700459 if (VDBG) {
Svet Ganov16a16892015-04-16 10:32:04 -0700460 log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
xinhe43c50292014-09-18 17:56:48 -0700461 + " notifyNow=" + notifyNow + " subId=" + subId + " myUid=" + myUid
Wink Savillea12a7b32012-09-20 10:09:45 -0700462 + " callerUid=" + callerUid);
463 }
xinhe75c2c152014-10-16 11:49:45 -0700464
465 if (events != PhoneStateListener.LISTEN_NONE) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700466 /* Checks permission and throws Security exception */
467 checkListenerPermission(events);
Svet Ganov16a16892015-04-16 10:32:04 -0700468
469 if ((events & PHONE_STATE_PERMISSION_MASK) != 0) {
470 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
471 callingPackage) != AppOpsManager.MODE_ALLOWED) {
472 return;
473 }
474 }
475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 synchronized (mRecords) {
477 // register
478 Record r = null;
479 find_and_add: {
480 IBinder b = callback.asBinder();
481 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700482 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483 r = mRecords.get(i);
484 if (b == r.binder) {
485 break find_and_add;
486 }
487 }
488 r = new Record();
489 r.binder = b;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 mRecords.add(r);
Wink Savillee380b982014-07-26 18:24:22 -0700491 if (DBG) log("listen: add new record");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 }
xinhe43c50292014-09-18 17:56:48 -0700493
xinhe75c2c152014-10-16 11:49:45 -0700494 r.callback = callback;
Svet Ganov16a16892015-04-16 10:32:04 -0700495 r.callingPackage = callingPackage;
xinhe75c2c152014-10-16 11:49:45 -0700496 r.callerUid = callerUid;
497 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
498 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800499 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800500 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700501 } else {//APP specify subID
502 r.subId = subId;
503 }
504 r.phoneId = SubscriptionManager.getPhoneId(r.subId);
505
xinhe43c50292014-09-18 17:56:48 -0700506 int phoneId = r.phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700508 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700509 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700510 }
511 if (VDBG) toStringLogSSC("listen");
Wink Savillefb40dd42014-06-12 17:02:31 -0700512 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400514 try {
Wink Savillee380b982014-07-26 18:24:22 -0700515 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700516 r.callback.onServiceStateChanged(
517 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400518 } catch (RemoteException ex) {
519 remove(r.binder);
520 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800521 }
522 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
523 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700524 int gsmSignalStrength = mSignalStrength[phoneId]
525 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700526 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
527 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 } catch (RemoteException ex) {
529 remove(r.binder);
530 }
531 }
532 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
533 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700534 r.callback.onMessageWaitingIndicatorChanged(
535 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 } catch (RemoteException ex) {
537 remove(r.binder);
538 }
539 }
540 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
541 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700542 r.callback.onCallForwardingIndicatorChanged(
543 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 } catch (RemoteException ex) {
545 remove(r.binder);
546 }
547 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700548 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400549 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700550 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700551 + mCellLocation[phoneId]);
552 r.callback.onCellLocationChanged(
553 new Bundle(mCellLocation[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400554 } catch (RemoteException ex) {
555 remove(r.binder);
556 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 }
558 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
559 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700560 r.callback.onCallStateChanged(mCallState[phoneId],
561 mCallIncomingNumber[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 } catch (RemoteException ex) {
563 remove(r.binder);
564 }
565 }
566 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
567 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700568 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
569 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 } catch (RemoteException ex) {
571 remove(r.binder);
572 }
573 }
574 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
575 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700576 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 } catch (RemoteException ex) {
578 remove(r.binder);
579 }
580 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700581 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
582 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700583 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700584 } catch (RemoteException ex) {
585 remove(r.binder);
586 }
587 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700588 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
589 try {
590 r.callback.onOtaspChanged(mOtaspMode);
591 } catch (RemoteException ex) {
592 remove(r.binder);
593 }
594 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700595 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700596 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700597 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700598 + mCellInfo.get(phoneId));
599 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
John Wang963db55d2012-03-30 16:04:06 -0700600 } catch (RemoteException ex) {
601 remove(r.binder);
602 }
603 }
Wink Saville070e0612014-04-15 22:04:10 -0700604 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO) != 0) {
605 try {
606 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
607 } catch (RemoteException ex) {
608 remove(r.binder);
609 }
610 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200611 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
612 try {
613 r.callback.onPreciseCallStateChanged(mPreciseCallState);
614 } catch (RemoteException ex) {
615 remove(r.binder);
616 }
617 }
618 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
619 try {
620 r.callback.onPreciseDataConnectionStateChanged(
621 mPreciseDataConnectionState);
622 } catch (RemoteException ex) {
623 remove(r.binder);
624 }
625 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400626 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
627 try {
628 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
629 } catch (RemoteException ex) {
630 remove(r.binder);
631 }
632 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 }
634 }
635 } else {
xinhe75c2c152014-10-16 11:49:45 -0700636 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 remove(callback.asBinder());
638 }
639 }
640
641 private void remove(IBinder binder) {
642 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700643 final int recordCount = mRecords.size();
644 for (int i = 0; i < recordCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 if (mRecords.get(i).binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800646 if (DBG) {
647 Record r = mRecords.get(i);
Svet Ganov16a16892015-04-16 10:32:04 -0700648 log("remove: binder=" + binder + "r.callingPackage" + r.callingPackage
xinheac11ae92014-12-18 10:02:14 -0800649 + "r.callback" + r.callback);
650 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 mRecords.remove(i);
652 return;
653 }
654 }
655 }
656 }
657
658 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700659 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700660 return;
661 }
xinhe43c50292014-09-18 17:56:48 -0700662
663 if (VDBG) {
664 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
665 }
666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700668 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800669 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800670 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671 try {
672 r.callback.onCallStateChanged(state, incomingNumber);
673 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400674 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 }
676 }
677 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400678 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800680 broadcastCallStateChanged(state, incomingNumber,
681 SubscriptionManager.DEFAULT_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 }
683
Wink Saville63f03dd2014-10-23 10:44:45 -0700684 public void notifyCallStateForSubscriber(int subId, int state, String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700685 if (!checkNotifyPermission("notifyCallState()")) {
686 return;
687 }
Wink Savillee380b982014-07-26 18:24:22 -0700688 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700689 log("notifyCallStateForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700690 + " state=" + state + " incomingNumber=" + incomingNumber);
691 }
692 synchronized (mRecords) {
693 int phoneId = SubscriptionManager.getPhoneId(subId);
694 if (validatePhoneId(phoneId)) {
695 mCallState[phoneId] = state;
696 mCallIncomingNumber[phoneId] = incomingNumber;
697 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800698 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700699 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800700 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700701 try {
702 r.callback.onCallStateChanged(state, incomingNumber);
703 } catch (RemoteException ex) {
704 mRemoveList.add(r.binder);
705 }
706 }
707 }
708 }
709 handleRemoveListLocked();
710 }
711 broadcastCallStateChanged(state, incomingNumber, subId);
712 }
713
Wink Saville63f03dd2014-10-23 10:44:45 -0700714 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700715 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700716 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700717 }
xinhe43c50292014-09-18 17:56:48 -0700718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719 synchronized (mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700720 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700721 log("notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
Wink Saville47d8d1b2014-07-10 13:01:52 -0700722 + " state=" + state);
723 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700724 if (validatePhoneId(phoneId)) {
725 mServiceState[phoneId] = state;
Wink Savillebc027272014-09-08 14:50:58 -0700726 logServiceStateChanged("notifyServiceStateForSubscriber", subId, phoneId, state);
727 if (VDBG) toStringLogSSC("notifyServiceStateForSubscriber");
Wink Saville47d8d1b2014-07-10 13:01:52 -0700728
Wink Savillefb40dd42014-06-12 17:02:31 -0700729 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700730 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700731 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700732 + " phoneId=" + phoneId + " state=" + state);
733 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800734 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800735 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700736 try {
Wink Savillee380b982014-07-26 18:24:22 -0700737 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700738 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700739 + " subId=" + subId + " phoneId=" + phoneId
740 + " state=" + state);
741 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700742 r.callback.onServiceStateChanged(new ServiceState(state));
743 } catch (RemoteException ex) {
744 mRemoveList.add(r.binder);
745 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400746 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700748 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700749 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400751 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700753 broadcastServiceStateChanged(state, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 }
755
Wink Savillee9b06d72009-05-18 21:47:50 -0700756 public void notifySignalStrength(SignalStrength signalStrength) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800757 notifySignalStrengthForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
758 signalStrength);
Wink Savillefb40dd42014-06-12 17:02:31 -0700759 }
760
Wink Saville63f03dd2014-10-23 10:44:45 -0700761 public void notifySignalStrengthForSubscriber(int subId, SignalStrength signalStrength) {
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800762 log("notifySignalStrengthForSubscriber: subId=" + subId
763 + " signalStrength=" + signalStrength);
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700764 if (!checkNotifyPermission("notifySignalStrength()")) {
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800765 log("notifySignalStrengthForSubscriber: permission check failure");
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700766 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700767 }
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800768 toStringLogSSC("notifySignalStrengthForSubscriber");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700770 int phoneId = SubscriptionManager.getPhoneId(subId);
771 if (validatePhoneId(phoneId)) {
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800772 log("notifySignalStrengthForSubscriber: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700773 mSignalStrength[phoneId] = signalStrength;
774 for (Record r : mRecords) {
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800775 log("notifySignalStrengthForSubscriber: r=" + r + " subId=" + subId
776 + " phoneId=" + phoneId + " ss=" + signalStrength);
Wink Savillea374c3d2014-11-11 11:48:04 -0800777 if (r.matchPhoneStateListenerEvent(
778 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800779 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700780 try {
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800781 log("notifySignalStrengthForSubscriber: callback.onSsS r=" + r
782 + " subId=" + subId + " phoneId=" + phoneId
783 + " ss=" + signalStrength);
Wink Savillefb40dd42014-06-12 17:02:31 -0700784 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
785 } catch (RemoteException ex) {
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800786 log("notifySignalStrengthForSubscriber: Exception while calling callback!!");
Wink Savillefb40dd42014-06-12 17:02:31 -0700787 mRemoveList.add(r.binder);
788 }
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800789 } else {
790 log("notifySignalStrengthForSubscriber: no match for LISTEN_SIGNAL_STRENGTHS");
Joe Onorato163d8d92010-10-21 13:21:20 -0400791 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800792 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800793 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700794 try {
795 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700796 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800797 log("notifySignalStrengthForSubscriber: callback.onSS r=" + r
798 + " subId=" + subId + " phoneId=" + phoneId
799 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700800 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700801 } catch (RemoteException ex) {
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800802 log("notifySignalStrengthForSubscriber: Exception in deprecated LISTEN_SIGNAL_STRENGTH");
Wink Savillefb40dd42014-06-12 17:02:31 -0700803 mRemoveList.add(r.binder);
804 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 }
806 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700807 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700808 log("notifySignalStrengthForSubscriber: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800809 }
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800810 log("notifySignalStrengthForSubscriber: done with all records");
Joe Onorato163d8d92010-10-21 13:21:20 -0400811 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700813 broadcastSignalStrengthChanged(signalStrength, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 }
815
Andrew Flynn1f452642015-04-14 22:16:04 -0400816 @Override
817 public void notifyCarrierNetworkChange(boolean active) {
818 if (!checkNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()")) {
819 return;
820 }
821 if (VDBG) {
822 log("notifyCarrierNetworkChange: active=" + active);
823 }
824
825 synchronized (mRecords) {
826 mCarrierNetworkChangeState = active;
827 for (Record r : mRecords) {
828 if (r.matchPhoneStateListenerEvent(
829 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
830 try {
831 r.callback.onCarrierNetworkChange(active);
832 } catch (RemoteException ex) {
833 mRemoveList.add(r.binder);
834 }
835 }
836 }
837 handleRemoveListLocked();
838 }
839 }
840
Wink Savilleb208a242012-07-25 14:08:09 -0700841 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800842 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700843 }
844
Wink Saville63f03dd2014-10-23 10:44:45 -0700845 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700846 if (!checkNotifyPermission("notifyCellInfo()")) {
847 return;
848 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700849 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700850 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700851 + " cellInfo=" + cellInfo);
852 }
John Wang963db55d2012-03-30 16:04:06 -0700853
854 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700855 int phoneId = SubscriptionManager.getPhoneId(subId);
856 if (validatePhoneId(phoneId)) {
857 mCellInfo.set(phoneId, cellInfo);
858 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -0700859 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
xinhe8b79fb62014-11-05 14:55:03 -0800860 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700861 try {
862 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700863 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -0700864 }
865 r.callback.onCellInfoChanged(cellInfo);
866 } catch (RemoteException ex) {
867 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700868 }
John Wang963db55d2012-03-30 16:04:06 -0700869 }
870 }
871 }
872 handleRemoveListLocked();
873 }
874 }
875
Wink Saville070e0612014-04-15 22:04:10 -0700876 public void notifyDataConnectionRealTimeInfo(DataConnectionRealTimeInfo dcRtInfo) {
877 if (!checkNotifyPermission("notifyDataConnectionRealTimeInfo()")) {
878 return;
879 }
880
881 synchronized (mRecords) {
882 mDcRtInfo = dcRtInfo;
883 for (Record r : mRecords) {
884 if (validateEventsAndUserLocked(r,
885 PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO)) {
886 try {
887 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700888 log("notifyDataConnectionRealTimeInfo: mDcRtInfo="
Wink Saville070e0612014-04-15 22:04:10 -0700889 + mDcRtInfo + " r=" + r);
890 }
891 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
892 } catch (RemoteException ex) {
893 mRemoveList.add(r.binder);
894 }
895 }
896 }
897 handleRemoveListLocked();
898 }
899 }
900
xinhe43c50292014-09-18 17:56:48 -0700901 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700902 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700903 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700904 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700905 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700906 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -0700907 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -0700908 + " mwi=" + mwi);
909 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700911 if (validatePhoneId(phoneId)) {
912 mMessageWaiting[phoneId] = mwi;
913 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800914 if (r.matchPhoneStateListenerEvent(
915 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -0800916 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700917 try {
918 r.callback.onMessageWaitingIndicatorChanged(mwi);
919 } catch (RemoteException ex) {
920 mRemoveList.add(r.binder);
921 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922 }
923 }
924 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400925 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 }
927 }
928
929 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800930 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -0700931 }
932
Wink Saville63f03dd2014-10-23 10:44:45 -0700933 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700934 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700935 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700936 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700937 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700938 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700939 + " cfi=" + cfi);
940 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700942 int phoneId = SubscriptionManager.getPhoneId(subId);
943 if (validatePhoneId(phoneId)) {
944 mCallForwarding[phoneId] = cfi;
945 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800946 if (r.matchPhoneStateListenerEvent(
947 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -0800948 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700949 try {
950 r.callback.onCallForwardingIndicatorChanged(cfi);
951 } catch (RemoteException ex) {
952 mRemoveList.add(r.binder);
953 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 }
955 }
956 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400957 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 }
959 }
960
961 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800962 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -0700963 }
964
Wink Saville63f03dd2014-10-23 10:44:45 -0700965 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700966 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700967 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700968 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700970 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -0800971 if (validatePhoneId(phoneId)) {
972 mDataActivity[phoneId] = state;
973 for (Record r : mRecords) {
974 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY)) {
975 try {
976 r.callback.onDataActivity(state);
977 } catch (RemoteException ex) {
978 mRemoveList.add(r.binder);
979 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980 }
981 }
982 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400983 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 }
985 }
986
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700987 public void notifyDataConnection(int state, boolean isDataConnectivityPossible,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700988 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -0700989 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800990 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
xinhe43c50292014-09-18 17:56:48 -0700991 isDataConnectivityPossible,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -0700992 networkCapabilities, networkType, roaming);
993 }
994
Wink Saville63f03dd2014-10-23 10:44:45 -0700995 public void notifyDataConnectionForSubscriber(int subId, int state,
Wink Savillefb40dd42014-06-12 17:02:31 -0700996 boolean isDataConnectivityPossible, String reason, String apn, String apnType,
997 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
998 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700999 if (!checkNotifyPermission("notifyDataConnection()" )) {
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) {
Wink Savillebc027272014-09-08 14:50:58 -07001003 log("notifyDataConnectionForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001004 + " state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible
1005 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -07001006 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -08001007 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -07001008 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001010 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001011 if (validatePhoneId(phoneId)) {
1012 boolean modified = false;
1013 if (state == TelephonyManager.DATA_CONNECTED) {
1014 if (!mConnectedApns.contains(apnType)) {
1015 mConnectedApns.add(apnType);
1016 if (mDataConnectionState[phoneId] != state) {
1017 mDataConnectionState[phoneId] = state;
1018 modified = true;
1019 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001021 } else {
1022 if (mConnectedApns.remove(apnType)) {
1023 if (mConnectedApns.isEmpty()) {
1024 mDataConnectionState[phoneId] = state;
1025 modified = true;
1026 } else {
1027 // leave mDataConnectionState as is and
1028 // send out the new status for the APN in question.
Wink Savillebaf21da2014-11-19 16:03:09 -08001029 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001030 }
1031 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001032 mDataConnectionPossible[phoneId] = isDataConnectivityPossible;
1033 mDataConnectionReason[phoneId] = reason;
1034 mDataConnectionLinkProperties[phoneId] = linkProperties;
1035 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
1036 if (mDataConnectionNetworkType[phoneId] != networkType) {
1037 mDataConnectionNetworkType[phoneId] = networkType;
1038 // need to tell registered listeners about the new network type
1039 modified = true;
1040 }
1041 if (modified) {
1042 if (DBG) {
1043 log("onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
1044 + ", " + mDataConnectionNetworkType[phoneId] + ")");
1045 }
1046 for (Record r : mRecords) {
1047 if (r.matchPhoneStateListenerEvent(
1048 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1049 idMatch(r.subId, subId, phoneId)) {
1050 try {
1051 log("Notify data connection state changed on sub: " +
1052 subId);
1053 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1054 mDataConnectionNetworkType[phoneId]);
1055 } catch (RemoteException ex) {
1056 mRemoveList.add(r.binder);
1057 }
1058 }
1059 }
1060 handleRemoveListLocked();
1061 }
1062 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1063 apnType, apn, reason, linkProperties, "");
1064 for (Record r : mRecords) {
1065 if (r.matchPhoneStateListenerEvent(
1066 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1067 try {
1068 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1069 } catch (RemoteException ex) {
1070 mRemoveList.add(r.binder);
1071 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001072 }
1073 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001074 }
1075 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001077 broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001078 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001079 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1080 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 }
1082
Robert Greenwalt02648a42010-05-18 10:52:51 -07001083 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001084 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001085 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001086 }
1087
Wink Saville63f03dd2014-10-23 10:44:45 -07001088 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001089 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001090 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001091 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001092 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001093 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001094 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001095 + " reason=" + reason + " apnType=" + apnType);
1096 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001098 mPreciseDataConnectionState = new PreciseDataConnectionState(
1099 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1100 apnType, "", reason, null, "");
1101 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001102 if (r.matchPhoneStateListenerEvent(
1103 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001104 try {
1105 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1106 } catch (RemoteException ex) {
1107 mRemoveList.add(r.binder);
1108 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 }
1110 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001111 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001113 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001114 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1115 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 }
1117
1118 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001119 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001120 }
1121
Wink Saville63f03dd2014-10-23 10:44:45 -07001122 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001123 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001124 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001125 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001126 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001127 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001128 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001129 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001130 + " cellLocation=" + cellLocation);
1131 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001133 int phoneId = SubscriptionManager.getPhoneId(subId);
1134 if (validatePhoneId(phoneId)) {
1135 mCellLocation[phoneId] = cellLocation;
1136 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001137 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
xinhe8b79fb62014-11-05 14:55:03 -08001138 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001139 try {
1140 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001141 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001142 + " r=" + r);
1143 }
1144 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1145 } catch (RemoteException ex) {
1146 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001147 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001148 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 }
1150 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001151 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001152 }
1153 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154
Wink Savillefd2d0132010-10-28 14:22:26 -07001155 public void notifyOtaspChanged(int otaspMode) {
1156 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1157 return;
1158 }
1159 synchronized (mRecords) {
1160 mOtaspMode = otaspMode;
1161 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001162 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001163 try {
1164 r.callback.onOtaspChanged(otaspMode);
1165 } catch (RemoteException ex) {
1166 mRemoveList.add(r.binder);
1167 }
1168 }
1169 }
1170 handleRemoveListLocked();
1171 }
1172 }
1173
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001174 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1175 int backgroundCallState) {
1176 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1177 return;
1178 }
1179 synchronized (mRecords) {
1180 mRingingCallState = ringingCallState;
1181 mForegroundCallState = foregroundCallState;
1182 mBackgroundCallState = backgroundCallState;
1183 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1184 backgroundCallState,
1185 DisconnectCause.NOT_VALID,
1186 PreciseDisconnectCause.NOT_VALID);
1187 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001188 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001189 try {
1190 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1191 } catch (RemoteException ex) {
1192 mRemoveList.add(r.binder);
1193 }
1194 }
1195 }
1196 handleRemoveListLocked();
1197 }
1198 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1199 DisconnectCause.NOT_VALID,
1200 PreciseDisconnectCause.NOT_VALID);
1201 }
1202
1203 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1204 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1205 return;
1206 }
1207 synchronized (mRecords) {
1208 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1209 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1210 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001211 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001212 try {
1213 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1214 } catch (RemoteException ex) {
1215 mRemoveList.add(r.binder);
1216 }
1217 }
1218 }
1219 handleRemoveListLocked();
1220 }
1221 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1222 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1223 }
1224
1225 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1226 String apn, String failCause) {
1227 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1228 return;
1229 }
1230 synchronized (mRecords) {
1231 mPreciseDataConnectionState = new PreciseDataConnectionState(
1232 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1233 apnType, apn, reason, null, failCause);
1234 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001235 if (r.matchPhoneStateListenerEvent(
1236 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001237 try {
1238 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1239 } catch (RemoteException ex) {
1240 mRemoveList.add(r.binder);
1241 }
1242 }
1243 }
1244 handleRemoveListLocked();
1245 }
1246 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1247 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1248 }
1249
Wink Savillefb40dd42014-06-12 17:02:31 -07001250 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1251 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1252 return;
1253 }
1254 synchronized (mRecords) {
1255 mVoLteServiceState = lteState;
1256 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001257 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001258 try {
1259 r.callback.onVoLteServiceStateChanged(
1260 new VoLteServiceState(mVoLteServiceState));
1261 } catch (RemoteException ex) {
1262 mRemoveList.add(r.binder);
1263 }
1264 }
1265 }
1266 handleRemoveListLocked();
1267 }
1268 }
1269
Wink Saville63f03dd2014-10-23 10:44:45 -07001270 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001271 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1272 return;
1273 }
1274
1275 synchronized (mRecords) {
1276 for (Record r : mRecords) {
1277 if (VDBG) {
1278 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1279 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001280 if ((r.matchPhoneStateListenerEvent(
1281 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
New Author Steven Liu485f2092014-09-11 10:18:45 -05001282 ((r.subId == subId) ||
Wink Savilled09c4ca2014-11-22 10:08:16 -08001283 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001284 try {
1285 r.callback.onOemHookRawEvent(rawData);
1286 } catch (RemoteException ex) {
1287 mRemoveList.add(r.binder);
1288 }
1289 }
1290 }
1291 handleRemoveListLocked();
1292 }
1293 }
1294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001295 @Override
1296 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1297 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1298 != PackageManager.PERMISSION_GRANTED) {
1299 pw.println("Permission Denial: can't dump telephony.registry from from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001300 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301 return;
1302 }
1303 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001304 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001305 pw.println("last known state:");
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301306 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1307 pw.println(" Phone Id=" + i);
1308 pw.println(" mCallState=" + mCallState[i]);
1309 pw.println(" mCallIncomingNumber=" + mCallIncomingNumber[i]);
1310 pw.println(" mServiceState=" + mServiceState[i]);
1311 pw.println(" mSignalStrength=" + mSignalStrength[i]);
1312 pw.println(" mMessageWaiting=" + mMessageWaiting[i]);
1313 pw.println(" mCallForwarding=" + mCallForwarding[i]);
1314 pw.println(" mDataActivity=" + mDataActivity[i]);
1315 pw.println(" mDataConnectionState=" + mDataConnectionState[i]);
1316 pw.println(" mDataConnectionPossible=" + mDataConnectionPossible[i]);
1317 pw.println(" mDataConnectionReason=" + mDataConnectionReason[i]);
1318 pw.println(" mDataConnectionApn=" + mDataConnectionApn[i]);
1319 pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1320 pw.println(" mDataConnectionNetworkCapabilities=" +
1321 mDataConnectionNetworkCapabilities[i]);
1322 pw.println(" mCellLocation=" + mCellLocation[i]);
1323 pw.println(" mCellInfo=" + mCellInfo.get(i));
1324 }
Wink Saville070e0612014-04-15 22:04:10 -07001325 pw.println(" mDcRtInfo=" + mDcRtInfo);
Wink Savillee9b06d72009-05-18 21:47:50 -07001326 pw.println("registrations: count=" + recordCount);
Robert Greenwalt02648a42010-05-18 10:52:51 -07001327 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -07001328 pw.println(" " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 }
1330 }
1331 }
1332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001333 //
1334 // the legacy intent broadcasting
1335 //
1336
Wink Saville63f03dd2014-10-23 10:44:45 -07001337 private void broadcastServiceStateChanged(ServiceState state, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001338 long ident = Binder.clearCallingIdentity();
1339 try {
1340 mBatteryStats.notePhoneState(state.getState());
1341 } catch (RemoteException re) {
1342 // Can't do much
1343 } finally {
1344 Binder.restoreCallingIdentity(ident);
1345 }
1346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
1348 Bundle data = new Bundle();
1349 state.fillInNotifierBundle(data);
1350 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001351 // Pass the subscription along with the intent.
1352 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001353 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001354 }
1355
Wink Saville63f03dd2014-10-23 10:44:45 -07001356 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001357 long ident = Binder.clearCallingIdentity();
1358 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001359 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001360 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001361 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001362 } finally {
1363 Binder.restoreCallingIdentity(ident);
1364 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001366 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08001367 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
Wink Savillee9b06d72009-05-18 21:47:50 -07001368 Bundle data = new Bundle();
1369 signalStrength.fillInNotifierBundle(data);
1370 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001371 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001372 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001373 }
1374
Wink Saville63f03dd2014-10-23 10:44:45 -07001375 private void broadcastCallStateChanged(int state, String incomingNumber, int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001376 long ident = Binder.clearCallingIdentity();
1377 try {
1378 if (state == TelephonyManager.CALL_STATE_IDLE) {
1379 mBatteryStats.notePhoneOff();
1380 } else {
1381 mBatteryStats.notePhoneOn();
1382 }
1383 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001384 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001385 } finally {
1386 Binder.restoreCallingIdentity(ident);
1387 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001389 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001390 intent.putExtra(PhoneConstants.STATE_KEY,
1391 DefaultPhoneNotifier.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392 if (!TextUtils.isEmpty(incomingNumber)) {
1393 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1394 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001395 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001396 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
Svet Ganov16a16892015-04-16 10:32:04 -07001397 android.Manifest.permission.READ_PHONE_STATE,
1398 AppOpsManager.OP_READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399 }
1400
Robert Greenwalt42acef32009-08-12 16:08:25 -07001401 private void broadcastDataConnectionStateChanged(int state,
1402 boolean isDataConnectivityPossible,
Wink Savillef61101f2010-09-16 16:36:42 -07001403 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001404 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001405 // Note: not reporting to the battery stats service here, because the
1406 // status bar takes care of that after taking into account all of the
1407 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001408 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001409 intent.putExtra(PhoneConstants.STATE_KEY,
1410 DefaultPhoneNotifier.convertDataState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001411 if (!isDataConnectivityPossible) {
Wink Savillea639b312012-07-10 12:37:54 -07001412 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001413 }
1414 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001415 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001416 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001417 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001418 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001419 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001420 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001421 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001422 }
1423 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001424 if (networkCapabilities != null) {
1425 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001426 }
Wink Savillea639b312012-07-10 12:37:54 -07001427 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001428
Wink Savillea639b312012-07-10 12:37:54 -07001429 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1430 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001431 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001432 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001433 }
1434
Wink Savillefb40dd42014-06-12 17:02:31 -07001435 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001436 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001438 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1439 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001440 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001441 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001443
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001444 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1445 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1446 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1447 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1448 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1449 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1450 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1451 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1452 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1453 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1454 }
1455
1456 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001457 String apnType, String apn, String reason, LinkProperties linkProperties,
1458 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001459 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1460 intent.putExtra(PhoneConstants.STATE_KEY, state);
1461 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1462 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1463 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1464 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001465 if (linkProperties != null) {
1466 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1467 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001468 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1469
1470 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1471 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1472 }
1473
Andrew Flynn1f452642015-04-14 22:16:04 -04001474 private boolean checkNotifyPermissionOrCarrierPrivilege(String method) {
1475 if (checkNotifyPermission() || checkCarrierPrivilege()) {
1476 return true;
1477 }
1478
1479 String msg = "Modify Phone State or Carrier Privilege Permission Denial: " + method
1480 + " from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
1481 if (DBG) log(msg);
1482 return false;
1483 }
1484
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001485 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001486 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001487 return true;
1488 }
1489 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001490 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001491 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001492 return false;
1493 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001494
Andrew Flynn1f452642015-04-14 22:16:04 -04001495 private boolean checkNotifyPermission() {
1496 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1497 == PackageManager.PERMISSION_GRANTED;
1498 }
1499
1500 private boolean checkCarrierPrivilege() {
1501 TelephonyManager tm = TelephonyManager.getDefault();
1502 String[] pkgs = mContext.getPackageManager().getPackagesForUid(Binder.getCallingUid());
1503 for (String pkg : pkgs) {
1504 if (tm.checkCarrierPrivilegesForPackage(pkg) ==
1505 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
1506 return true;
1507 }
1508 }
1509
1510 return false;
1511 }
1512
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001513 private void checkListenerPermission(int events) {
1514 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1515 mContext.enforceCallingOrSelfPermission(
1516 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1517
1518 }
1519
John Wang963db55d2012-03-30 16:04:06 -07001520 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1521 mContext.enforceCallingOrSelfPermission(
1522 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1523
1524 }
1525
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001526 if ((events & PHONE_STATE_PERMISSION_MASK) != 0) {
1527 mContext.enforceCallingOrSelfPermission(
1528 android.Manifest.permission.READ_PHONE_STATE, null);
1529 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001530
1531 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1532 mContext.enforceCallingOrSelfPermission(
1533 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1534
1535 }
New Author Steven Liu485f2092014-09-11 10:18:45 -05001536
1537 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1538 mContext.enforceCallingOrSelfPermission(
1539 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1540 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001541 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001542
1543 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001544 int size = mRemoveList.size();
1545 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1546 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001547 for (IBinder b: mRemoveList) {
1548 remove(b);
1549 }
1550 mRemoveList.clear();
1551 }
1552 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001553
1554 private boolean validateEventsAndUserLocked(Record r, int events) {
1555 int foregroundUser;
1556 long callingIdentity = Binder.clearCallingIdentity();
1557 boolean valid = false;
1558 try {
1559 foregroundUser = ActivityManager.getCurrentUser();
Wink Savillea374c3d2014-11-11 11:48:04 -08001560 valid = r.callerUid == foregroundUser && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001561 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001562 log("validateEventsAndUserLocked: valid=" + valid
Wink Savillea12a7b32012-09-20 10:09:45 -07001563 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
1564 + " r.events=" + r.events + " events=" + events);
1565 }
1566 } finally {
1567 Binder.restoreCallingIdentity(callingIdentity);
1568 }
1569 return valid;
1570 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001571
1572 private boolean validatePhoneId(int phoneId) {
1573 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001574 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001575 return valid;
1576 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001577
1578 private static void log(String s) {
1579 Rlog.d(TAG, s);
1580 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001581
1582 private static class LogSSC {
1583 private Time mTime;
1584 private String mS;
Wink Saville63f03dd2014-10-23 10:44:45 -07001585 private int mSubId;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001586 private int mPhoneId;
1587 private ServiceState mState;
1588
Wink Saville63f03dd2014-10-23 10:44:45 -07001589 public void set(Time t, String s, int subId, int phoneId, ServiceState state) {
Wink Saville47d8d1b2014-07-10 13:01:52 -07001590 mTime = t; mS = s; mSubId = subId; mPhoneId = phoneId; mState = state;
1591 }
1592
1593 @Override
1594 public String toString() {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001595 return mS + " Time " + mTime.toString() + " mSubId " + mSubId + " mPhoneId "
1596 + mPhoneId + " mState " + mState;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001597 }
1598 }
1599
1600 private LogSSC logSSC [] = new LogSSC[10];
1601 private int next = 0;
1602
Wink Saville63f03dd2014-10-23 10:44:45 -07001603 private void logServiceStateChanged(String s, int subId, int phoneId, ServiceState state) {
Wink Saville47d8d1b2014-07-10 13:01:52 -07001604 if (logSSC == null || logSSC.length == 0) {
1605 return;
1606 }
1607 if (logSSC[next] == null) {
1608 logSSC[next] = new LogSSC();
1609 }
1610 Time t = new Time();
1611 t.setToNow();
1612 logSSC[next].set(t, s, subId, phoneId, state);
1613 if (++next >= logSSC.length) {
1614 next = 0;
1615 }
1616 }
1617
1618 private void toStringLogSSC(String prompt) {
1619 if (logSSC == null || logSSC.length == 0 || (next == 0 && logSSC[next] == null)) {
1620 log(prompt + ": logSSC is empty");
1621 } else {
1622 // There is at least one element
1623 log(prompt + ": logSSC.length=" + logSSC.length + " next=" + next);
1624 int i = next;
1625 if (logSSC[i] == null) {
1626 // logSSC is not full so back to the beginning
1627 i = 0;
1628 }
1629 do {
1630 log(logSSC[i].toString());
1631 if (++i >= logSSC.length) {
1632 i = 0;
1633 }
1634 } while (i != next);
Wink Savillee380b982014-07-26 18:24:22 -07001635 log(prompt + ": ----------------");
Wink Saville47d8d1b2014-07-10 13:01:52 -07001636 }
1637 }
xinhee9f16402014-09-25 16:39:28 -07001638
xinhe8b79fb62014-11-05 14:55:03 -08001639 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001640
1641 if(subId < 0) {
1642 // Invalid case, we need compare phoneId with default one.
1643 return (mDefaultPhoneId == phoneId);
1644 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001645 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001646 return (subId == mDefaultSubId);
1647 } else {
1648 return (rSubId == subId);
1649 }
1650 }
1651
1652 private void checkPossibleMissNotify(Record r, int phoneId) {
1653 int events = r.events;
1654
1655 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1656 try {
1657 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1658 mServiceState[phoneId]);
1659 r.callback.onServiceStateChanged(
1660 new ServiceState(mServiceState[phoneId]));
1661 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001662 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001663 }
1664 }
1665
1666 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1667 try {
1668 SignalStrength signalStrength = mSignalStrength[phoneId];
1669 if (DBG) {
1670 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1671 }
1672 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1673 } catch (RemoteException ex) {
1674 mRemoveList.add(r.binder);
1675 }
1676 }
1677
1678 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1679 try {
1680 int gsmSignalStrength = mSignalStrength[phoneId]
1681 .getGsmSignalStrength();
1682 if (DBG) {
1683 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1684 gsmSignalStrength);
1685 }
1686 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1687 : gsmSignalStrength));
1688 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001689 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001690 }
1691 }
1692
1693 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1694 try {
1695 if (DBG_LOC) {
1696 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1697 + mCellInfo.get(phoneId));
1698 }
1699 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1700 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001701 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001702 }
1703 }
1704
1705 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1706 try {
1707 if (VDBG) {
1708 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1709 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1710 }
1711 r.callback.onMessageWaitingIndicatorChanged(
1712 mMessageWaiting[phoneId]);
1713 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001714 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001715 }
1716 }
1717
1718 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1719 try {
1720 if (VDBG) {
1721 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1722 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1723 }
1724 r.callback.onCallForwardingIndicatorChanged(
1725 mCallForwarding[phoneId]);
1726 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001727 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001728 }
1729 }
1730
1731 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1732 try {
1733 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1734 + mCellLocation[phoneId]);
1735 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1736 } catch (RemoteException ex) {
1737 mRemoveList.add(r.binder);
1738 }
1739 }
1740
1741 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1742 try {
1743 if (DBG) {
1744 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1745 + "=" + mDataConnectionState[phoneId]
1746 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1747 + ")");
1748 }
1749 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1750 mDataConnectionNetworkType[phoneId]);
1751 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001752 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001753 }
1754 }
1755 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001756}