blob: 908ee22c75ecb52e314242cd6226e85fde4f94e8 [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;
20import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.Context;
22import android.content.Intent;
Wink Savillea12a7b32012-09-20 10:09:45 -070023import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.content.pm.PackageManager;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070025import android.net.LinkProperties;
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -070026import android.net.NetworkCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.os.Binder;
28import android.os.Bundle;
Wink Savillea12a7b32012-09-20 10:09:45 -070029import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.os.IBinder;
Wink Savillea12a7b32012-09-20 10:09:45 -070031import android.os.Message;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.os.RemoteException;
Dianne Hackborn5ac72a22012-08-29 18:32:08 -070033import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.telephony.CellLocation;
Wink Saville070e0612014-04-15 22:04:10 -070035import android.telephony.DataConnectionRealTimeInfo;
Wink Savillef4cd25b2014-07-08 19:03:20 -070036import android.telephony.Rlog;
Wink Savillefb40dd42014-06-12 17:02:31 -070037import android.telephony.TelephonyManager;
38import android.telephony.SubscriptionManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.telephony.PhoneStateListener;
40import android.telephony.ServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -070041import android.telephony.SignalStrength;
John Wang963db55d2012-03-30 16:04:06 -070042import android.telephony.CellInfo;
Wink Savillefb40dd42014-06-12 17:02:31 -070043import android.telephony.VoLteServiceState;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020044import android.telephony.DisconnectCause;
45import android.telephony.PreciseCallState;
46import android.telephony.PreciseDataConnectionState;
47import android.telephony.PreciseDisconnectCause;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import android.text.TextUtils;
Wink Saville47d8d1b2014-07-10 13:01:52 -070049import android.text.format.Time;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050
51import java.util.ArrayList;
Wink Savilleb208a242012-07-25 14:08:09 -070052import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import java.io.FileDescriptor;
54import java.io.PrintWriter;
55
56import com.android.internal.app.IBatteryStats;
Wink Savilled09c4ca2014-11-22 10:08:16 -080057import com.android.internal.telephony.IOnSubscriptionsChangedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import com.android.internal.telephony.ITelephonyRegistry;
59import com.android.internal.telephony.IPhoneStateListener;
60import com.android.internal.telephony.DefaultPhoneNotifier;
Wink Savillea639b312012-07-10 12:37:54 -070061import com.android.internal.telephony.PhoneConstants;
Wink Savillec9330dd2011-01-12 13:37:38 -080062import com.android.internal.telephony.ServiceStateTracker;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import com.android.internal.telephony.TelephonyIntents;
64import com.android.server.am.BatteryStatsService;
65
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066/**
Wink Savillee9b06d72009-05-18 21:47:50 -070067 * Since phone process can be restarted, this class provides a centralized place
68 * that applications can register and be called back from.
Wink Savillee380b982014-07-26 18:24:22 -070069 *
70 * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026
71 * and 15973975 by saving the phoneId of the registrant and then using the
72 * phoneId when deciding to to make a callback. This is necessary because
73 * a subId changes from to a dummy value when a SIM is removed and thus won't
Wink Saville63f03dd2014-10-23 10:44:45 -070074 * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles
Wink Savillee380b982014-07-26 18:24:22 -070075 * the dummy value conversion we properly do the callbacks.
76 *
77 * Eventually we may want to remove the notion of dummy value but for now this
78 * looks like the best approach.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 */
80class TelephonyRegistry extends ITelephonyRegistry.Stub {
81 private static final String TAG = "TelephonyRegistry";
Wink Saville6d13bc82014-08-01 11:13:40 -070082 private static final boolean DBG = false; // STOPSHIP if true
Wink Savillefb40dd42014-06-12 17:02:31 -070083 private static final boolean DBG_LOC = false; // STOPSHIP if true
Wink Saville6d13bc82014-08-01 11:13:40 -070084 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085
86 private static class Record {
87 String pkgForDebug;
Wink Savillee9b06d72009-05-18 21:47:50 -070088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 IPhoneStateListener callback;
Wink Savilled09c4ca2014-11-22 10:08:16 -080092 IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
Wink Savillee9b06d72009-05-18 21:47:50 -070093
Wink Savillea12a7b32012-09-20 10:09:45 -070094 int callerUid;
95
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -070097
Wink Savilled09c4ca2014-11-22 10:08:16 -080098 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Wink Savillefb40dd42014-06-12 17:02:31 -070099
Wink Savilled09c4ca2014-11-22 10:08:16 -0800100 int phoneId = SubscriptionManager.INVALID_PHONE_INDEX;
Wink Savillea374c3d2014-11-11 11:48:04 -0800101
102 boolean matchPhoneStateListenerEvent(int events) {
103 return (callback != null) && ((events & this.events) != 0);
104 }
105
Wink Savilled09c4ca2014-11-22 10:08:16 -0800106 boolean matchOnSubscriptionsChangedListener() {
107 return (onSubscriptionsChangedListenerCallback != null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800108 }
Wink Savillee380b982014-07-26 18:24:22 -0700109
Wink Savillea12a7b32012-09-20 10:09:45 -0700110 @Override
111 public String toString() {
Wink Savillea374c3d2014-11-11 11:48:04 -0800112 return "{pkgForDebug=" + pkgForDebug + " binder=" + binder + " callback=" + callback
Wink Savilled09c4ca2014-11-22 10:08:16 -0800113 + " onSubscriptionsChangedListenererCallback="
114 + onSubscriptionsChangedListenerCallback
Wink Savillea374c3d2014-11-11 11:48:04 -0800115 + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId
116 + " events=" + Integer.toHexString(events) + "}";
Wink Savillea12a7b32012-09-20 10:09:45 -0700117 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 }
119
120 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -0700121
Joe Onorato163d8d92010-10-21 13:21:20 -0400122 // access should be inside synchronized (mRecords) for these two fields
123 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
124 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 private final IBatteryStats mBatteryStats;
127
Wink Savilled09c4ca2014-11-22 10:08:16 -0800128 private boolean hasNotifySubscriptionInfoChangedOccurred = false;
129
Wink Savillefb40dd42014-06-12 17:02:31 -0700130 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700131
Wink Savillefb40dd42014-06-12 17:02:31 -0700132 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700133
Wink Savillefb40dd42014-06-12 17:02:31 -0700134 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700135
Wink Savillefb40dd42014-06-12 17:02:31 -0700136 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700137
Wink Savillefb40dd42014-06-12 17:02:31 -0700138 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700139
Wink Savillefb40dd42014-06-12 17:02:31 -0700140 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700141
Wink Savillefb40dd42014-06-12 17:02:31 -0700142 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700143
Wink Savillefb40dd42014-06-12 17:02:31 -0700144 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700145
Wink Savillefb40dd42014-06-12 17:02:31 -0700146 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700147
Wink Savillefb40dd42014-06-12 17:02:31 -0700148 private boolean[] mDataConnectionPossible;
Wink Savillee9b06d72009-05-18 21:47:50 -0700149
Wink Savillefb40dd42014-06-12 17:02:31 -0700150 private String[] mDataConnectionReason;
151
152 private String[] mDataConnectionApn;
Wink Savillee9b06d72009-05-18 21:47:50 -0700153
Robert Greenwalt02648a42010-05-18 10:52:51 -0700154 private ArrayList<String> mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700155
Wink Savillefb40dd42014-06-12 17:02:31 -0700156 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700157
Wink Savillefb40dd42014-06-12 17:02:31 -0700158 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700159
Wink Savillefb40dd42014-06-12 17:02:31 -0700160 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161
Wink Savillefb40dd42014-06-12 17:02:31 -0700162 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700163
Wink Savillec9330dd2011-01-12 13:37:38 -0800164 private int mOtaspMode = ServiceStateTracker.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700165
Wink Savillefb40dd42014-06-12 17:02:31 -0700166 private ArrayList<List<CellInfo>> mCellInfo = null;
167
168 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
169
Wink Savilled09c4ca2014-11-22 10:08:16 -0800170 private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
xinhee9f16402014-09-25 16:39:28 -0700171
Wink Savilled09c4ca2014-11-22 10:08:16 -0800172 private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
xinhee9f16402014-09-25 16:39:28 -0700173
Wink Saville070e0612014-04-15 22:04:10 -0700174 private DataConnectionRealTimeInfo mDcRtInfo = new DataConnectionRealTimeInfo();
175
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200176 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
177
178 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
179
180 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
181
182 private PreciseCallState mPreciseCallState = new PreciseCallState();
183
Andrew Flynn1f452642015-04-14 22:16:04 -0400184 private boolean mCarrierNetworkChangeState = false;
185
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200186 private PreciseDataConnectionState mPreciseDataConnectionState =
187 new PreciseDataConnectionState();
188
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700189 static final int PHONE_STATE_PERMISSION_MASK =
190 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
191 PhoneStateListener.LISTEN_CALL_STATE |
192 PhoneStateListener.LISTEN_DATA_ACTIVITY |
193 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
Wink Savillefb40dd42014-06-12 17:02:31 -0700194 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
195 PhoneStateListener.LISTEN_VOLTE_STATE;;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700196
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200197 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
198 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
199 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
200
Wink Savillea12a7b32012-09-20 10:09:45 -0700201 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700202 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700203
204 private final Handler mHandler = new Handler() {
205 @Override
206 public void handleMessage(Message msg) {
207 switch (msg.what) {
208 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700209 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700210 int numPhones = TelephonyManager.getDefault().getPhoneCount();
211 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700212 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700213 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700214 }
215 break;
216 }
xinhee9f16402014-09-25 16:39:28 -0700217 case MSG_UPDATE_DEFAULT_SUB: {
218 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700219 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700220 if (VDBG) {
221 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
222 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
223 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
224 }
225
226 //Due to possible risk condition,(notify call back using the new
227 //defaultSubId comes before new defaultSubId update) we need to recall all
228 //possible missed notify callback
229 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700230 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800231 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700232 checkPossibleMissNotify(r, newDefaultPhoneId);
233 }
234 }
235 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700236 }
237 mDefaultSubId = newDefaultSubId;
238 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700239 }
240 }
241 }
242 };
243
244 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
245 @Override
246 public void onReceive(Context context, Intent intent) {
247 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700248 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700249 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700250 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700251 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700252 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700253 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700254 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
xinhee9f16402014-09-25 16:39:28 -0700255 PhoneConstants.SUBSCRIPTION_KEY, SubscriptionManager.getDefaultSubId()));
256 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
257 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700258 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700259 log("onReceive:current mDefaultSubId=" + mDefaultSubId
260 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
261 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700262 }
xinhee9f16402014-09-25 16:39:28 -0700263
Junda Liu985f52c2015-02-23 16:06:51 -0800264 if(validatePhoneId(newDefaultPhoneId) && (!newDefaultSubIdObj.equals(mDefaultSubId)
xinhee9f16402014-09-25 16:39:28 -0700265 || (newDefaultPhoneId != mDefaultPhoneId))) {
266 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
267 newDefaultPhoneId, 0, newDefaultSubIdObj));
268 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700269 }
270 }
271 };
272
Wink Savillee9b06d72009-05-18 21:47:50 -0700273 // we keep a copy of all of the state so we can send it out when folks
274 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700276 // In these calls we call with the lock held. This is safe becasuse remote
277 // calls go through a oneway interface and local calls going through a
278 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279
280 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700281 CellLocation location = CellLocation.getEmpty();
282
Wink Savillefb40dd42014-06-12 17:02:31 -0700283 mContext = context;
284 mBatteryStats = BatteryStatsService.getService();
285 mConnectedApns = new ArrayList<String>();
286
Wink Savillefb40dd42014-06-12 17:02:31 -0700287 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700288 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700289 mNumPhones = numPhones;
290 mCallState = new int[numPhones];
291 mDataActivity = new int[numPhones];
292 mDataConnectionState = new int[numPhones];
293 mDataConnectionNetworkType = new int[numPhones];
294 mCallIncomingNumber = new String[numPhones];
295 mServiceState = new ServiceState[numPhones];
296 mSignalStrength = new SignalStrength[numPhones];
297 mMessageWaiting = new boolean[numPhones];
298 mDataConnectionPossible = new boolean[numPhones];
299 mDataConnectionReason = new String[numPhones];
300 mDataConnectionApn = new String[numPhones];
301 mCallForwarding = new boolean[numPhones];
302 mCellLocation = new Bundle[numPhones];
303 mDataConnectionLinkProperties = new LinkProperties[numPhones];
304 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
305 mCellInfo = new ArrayList<List<CellInfo>>();
306 for (int i = 0; i < numPhones; i++) {
307 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
308 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
309 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
310 mCallIncomingNumber[i] = "";
311 mServiceState[i] = new ServiceState();
312 mSignalStrength[i] = new SignalStrength();
313 mMessageWaiting[i] = false;
314 mCallForwarding[i] = false;
315 mDataConnectionPossible[i] = false;
316 mDataConnectionReason[i] = "";
317 mDataConnectionApn[i] = "";
318 mCellLocation[i] = new Bundle();
319 mCellInfo.add(i, null);
320 }
321
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700322 // Note that location can be null for non-phone builds like
323 // like the generic one.
324 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700325 for (int i = 0; i < numPhones; i++) {
326 location.fillInNotifierBundle(mCellLocation[i]);
327 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700328 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700329 mConnectedApns = new ArrayList<String>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330 }
331
Svetoslav Ganova0027152013-06-25 14:59:53 -0700332 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700333 // Watch for interesting updates
334 final IntentFilter filter = new IntentFilter();
335 filter.addAction(Intent.ACTION_USER_SWITCHED);
336 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700337 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700338 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700339 mContext.registerReceiver(mBroadcastReceiver, filter);
340 }
341
342 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800343 public void addOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800344 IOnSubscriptionsChangedListener callback) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800345 int callerUid = UserHandle.getCallingUserId();
346 int myUid = UserHandle.myUserId();
347 if (VDBG) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800348 log("listen oscl: E pkg=" + pkgForDebug + " myUid=" + myUid
349 + " callerUid=" + callerUid + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800350 + " callback.asBinder=" + callback.asBinder());
351 }
352
Wink Savilled09c4ca2014-11-22 10:08:16 -0800353 /* Checks permission and throws Security exception */
354 checkOnSubscriptionsChangedListenerPermission();
355 Record r = null;
Wink Savillea374c3d2014-11-11 11:48:04 -0800356
Wink Savilled09c4ca2014-11-22 10:08:16 -0800357 synchronized (mRecords) {
358 // register
359 find_and_add: {
360 IBinder b = callback.asBinder();
361 final int N = mRecords.size();
362 for (int i = 0; i < N; i++) {
363 r = mRecords.get(i);
364 if (b == r.binder) {
365 break find_and_add;
Wink Savillea374c3d2014-11-11 11:48:04 -0800366 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800367 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800368 r = new Record();
369 r.binder = b;
370 mRecords.add(r);
371 if (DBG) log("listen oscl: add new record");
Wink Savillea374c3d2014-11-11 11:48:04 -0800372 }
373
Wink Savilled09c4ca2014-11-22 10:08:16 -0800374 r.onSubscriptionsChangedListenerCallback = callback;
375 r.pkgForDebug = pkgForDebug;
376 r.callerUid = callerUid;
377 r.events = 0;
378 if (DBG) {
379 log("listen oscl: Register r=" + r);
380 }
381 // Always notify when registration occurs if there has been a notification.
382 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800383 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800384 if (VDBG) log("listen oscl: send to r=" + r);
385 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
386 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800387 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800388 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800389 remove(r.binder);
390 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800391 } else {
392 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800393 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800394 }
395 }
396
397 @Override
Wink Saville071743f2015-01-12 17:11:04 -0800398 public void removeOnSubscriptionsChangedListener(String pkgForDebug,
Wink Savilled09c4ca2014-11-22 10:08:16 -0800399 IOnSubscriptionsChangedListener callback) {
400 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800401 remove(callback.asBinder());
402 }
403
Wink Savilled09c4ca2014-11-22 10:08:16 -0800404 private void checkOnSubscriptionsChangedListenerPermission() {
405 mContext.enforceCallingOrSelfPermission(
406 SubscriptionManager.OnSubscriptionsChangedListener
407 .PERMISSION_ON_SUBSCRIPTIONS_CHANGED, null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800408 }
409
410 @Override
411 public void notifySubscriptionInfoChanged() {
412 if (VDBG) log("notifySubscriptionInfoChanged:");
413 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800414 if (!hasNotifySubscriptionInfoChangedOccurred) {
415 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
416 + mRecords.size());
417 }
418 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800419 mRemoveList.clear();
420 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800421 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800422 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800423 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
424 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
425 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800426 } catch (RemoteException ex) {
427 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
428 mRemoveList.add(r.binder);
429 }
430 }
431 }
432 handleRemoveListLocked();
433 }
434 }
435
436 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
438 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800439 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
440 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700441 }
442
443 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700444 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700445 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700446 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700447 }
448
449 private void listen(String pkgForDebug, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700450 boolean notifyNow, int subId) {
Wink Savillea12a7b32012-09-20 10:09:45 -0700451 int callerUid = UserHandle.getCallingUserId();
452 int myUid = UserHandle.myUserId();
Wink Savillee380b982014-07-26 18:24:22 -0700453 if (VDBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700454 log("listen: E pkg=" + pkgForDebug + " events=0x" + Integer.toHexString(events)
xinhe43c50292014-09-18 17:56:48 -0700455 + " notifyNow=" + notifyNow + " subId=" + subId + " myUid=" + myUid
Wink Savillea12a7b32012-09-20 10:09:45 -0700456 + " callerUid=" + callerUid);
457 }
xinhe75c2c152014-10-16 11:49:45 -0700458
459 if (events != PhoneStateListener.LISTEN_NONE) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700460 /* Checks permission and throws Security exception */
461 checkListenerPermission(events);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 synchronized (mRecords) {
463 // register
464 Record r = null;
465 find_and_add: {
466 IBinder b = callback.asBinder();
467 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700468 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 r = mRecords.get(i);
470 if (b == r.binder) {
471 break find_and_add;
472 }
473 }
474 r = new Record();
475 r.binder = b;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 mRecords.add(r);
Wink Savillee380b982014-07-26 18:24:22 -0700477 if (DBG) log("listen: add new record");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478 }
xinhe43c50292014-09-18 17:56:48 -0700479
xinhe75c2c152014-10-16 11:49:45 -0700480 r.callback = callback;
481 r.pkgForDebug = pkgForDebug;
482 r.callerUid = callerUid;
483 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
484 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800485 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800486 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700487 } else {//APP specify subID
488 r.subId = subId;
489 }
490 r.phoneId = SubscriptionManager.getPhoneId(r.subId);
491
xinhe43c50292014-09-18 17:56:48 -0700492 int phoneId = r.phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700494 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700495 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700496 }
497 if (VDBG) toStringLogSSC("listen");
Wink Savillefb40dd42014-06-12 17:02:31 -0700498 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400500 try {
Wink Savillee380b982014-07-26 18:24:22 -0700501 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700502 r.callback.onServiceStateChanged(
503 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400504 } catch (RemoteException ex) {
505 remove(r.binder);
506 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 }
508 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
509 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700510 int gsmSignalStrength = mSignalStrength[phoneId]
511 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700512 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
513 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 } catch (RemoteException ex) {
515 remove(r.binder);
516 }
517 }
518 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
519 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700520 r.callback.onMessageWaitingIndicatorChanged(
521 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800522 } catch (RemoteException ex) {
523 remove(r.binder);
524 }
525 }
526 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
527 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700528 r.callback.onCallForwardingIndicatorChanged(
529 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 } catch (RemoteException ex) {
531 remove(r.binder);
532 }
533 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700534 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400535 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700536 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700537 + mCellLocation[phoneId]);
538 r.callback.onCellLocationChanged(
539 new Bundle(mCellLocation[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400540 } catch (RemoteException ex) {
541 remove(r.binder);
542 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 }
544 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
545 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700546 r.callback.onCallStateChanged(mCallState[phoneId],
547 mCallIncomingNumber[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 } catch (RemoteException ex) {
549 remove(r.binder);
550 }
551 }
552 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
553 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700554 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
555 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 } catch (RemoteException ex) {
557 remove(r.binder);
558 }
559 }
560 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
561 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700562 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 } catch (RemoteException ex) {
564 remove(r.binder);
565 }
566 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700567 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
568 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700569 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700570 } catch (RemoteException ex) {
571 remove(r.binder);
572 }
573 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700574 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
575 try {
576 r.callback.onOtaspChanged(mOtaspMode);
577 } catch (RemoteException ex) {
578 remove(r.binder);
579 }
580 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700581 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700582 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700583 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700584 + mCellInfo.get(phoneId));
585 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
John Wang963db55d2012-03-30 16:04:06 -0700586 } catch (RemoteException ex) {
587 remove(r.binder);
588 }
589 }
Wink Saville070e0612014-04-15 22:04:10 -0700590 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO) != 0) {
591 try {
592 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
593 } catch (RemoteException ex) {
594 remove(r.binder);
595 }
596 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200597 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
598 try {
599 r.callback.onPreciseCallStateChanged(mPreciseCallState);
600 } catch (RemoteException ex) {
601 remove(r.binder);
602 }
603 }
604 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
605 try {
606 r.callback.onPreciseDataConnectionStateChanged(
607 mPreciseDataConnectionState);
608 } catch (RemoteException ex) {
609 remove(r.binder);
610 }
611 }
Andrew Flynn1f452642015-04-14 22:16:04 -0400612 if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
613 try {
614 r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
615 } catch (RemoteException ex) {
616 remove(r.binder);
617 }
618 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 }
620 }
621 } else {
xinhe75c2c152014-10-16 11:49:45 -0700622 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 remove(callback.asBinder());
624 }
625 }
626
627 private void remove(IBinder binder) {
628 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700629 final int recordCount = mRecords.size();
630 for (int i = 0; i < recordCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 if (mRecords.get(i).binder == binder) {
xinheac11ae92014-12-18 10:02:14 -0800632 if (DBG) {
633 Record r = mRecords.get(i);
634 log("remove: binder=" + binder + "r.pkgForDebug" + r.pkgForDebug
635 + "r.callback" + r.callback);
636 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 mRecords.remove(i);
638 return;
639 }
640 }
641 }
642 }
643
644 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700645 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700646 return;
647 }
xinhe43c50292014-09-18 17:56:48 -0700648
649 if (VDBG) {
650 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
651 }
652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700654 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800655 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800656 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657 try {
658 r.callback.onCallStateChanged(state, incomingNumber);
659 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400660 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661 }
662 }
663 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400664 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800666 broadcastCallStateChanged(state, incomingNumber,
667 SubscriptionManager.DEFAULT_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 }
669
Wink Saville63f03dd2014-10-23 10:44:45 -0700670 public void notifyCallStateForSubscriber(int subId, int state, String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700671 if (!checkNotifyPermission("notifyCallState()")) {
672 return;
673 }
Wink Savillee380b982014-07-26 18:24:22 -0700674 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700675 log("notifyCallStateForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700676 + " state=" + state + " incomingNumber=" + incomingNumber);
677 }
678 synchronized (mRecords) {
679 int phoneId = SubscriptionManager.getPhoneId(subId);
680 if (validatePhoneId(phoneId)) {
681 mCallState[phoneId] = state;
682 mCallIncomingNumber[phoneId] = incomingNumber;
683 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800684 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700685 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800686 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700687 try {
688 r.callback.onCallStateChanged(state, incomingNumber);
689 } catch (RemoteException ex) {
690 mRemoveList.add(r.binder);
691 }
692 }
693 }
694 }
695 handleRemoveListLocked();
696 }
697 broadcastCallStateChanged(state, incomingNumber, subId);
698 }
699
Wink Saville63f03dd2014-10-23 10:44:45 -0700700 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700701 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700702 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700703 }
xinhe43c50292014-09-18 17:56:48 -0700704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705 synchronized (mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700706 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700707 log("notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
Wink Saville47d8d1b2014-07-10 13:01:52 -0700708 + " state=" + state);
709 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700710 if (validatePhoneId(phoneId)) {
711 mServiceState[phoneId] = state;
Wink Savillebc027272014-09-08 14:50:58 -0700712 logServiceStateChanged("notifyServiceStateForSubscriber", subId, phoneId, state);
713 if (VDBG) toStringLogSSC("notifyServiceStateForSubscriber");
Wink Saville47d8d1b2014-07-10 13:01:52 -0700714
Wink Savillefb40dd42014-06-12 17:02:31 -0700715 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700716 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700717 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700718 + " phoneId=" + phoneId + " state=" + state);
719 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800720 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800721 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700722 try {
Wink Savillee380b982014-07-26 18:24:22 -0700723 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700724 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700725 + " subId=" + subId + " phoneId=" + phoneId
726 + " state=" + state);
727 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700728 r.callback.onServiceStateChanged(new ServiceState(state));
729 } catch (RemoteException ex) {
730 mRemoveList.add(r.binder);
731 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400732 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700734 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700735 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400737 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700739 broadcastServiceStateChanged(state, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800740 }
741
Wink Savillee9b06d72009-05-18 21:47:50 -0700742 public void notifySignalStrength(SignalStrength signalStrength) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800743 notifySignalStrengthForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
744 signalStrength);
Wink Savillefb40dd42014-06-12 17:02:31 -0700745 }
746
Wink Saville63f03dd2014-10-23 10:44:45 -0700747 public void notifySignalStrengthForSubscriber(int subId, SignalStrength signalStrength) {
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800748 log("notifySignalStrengthForSubscriber: subId=" + subId
749 + " signalStrength=" + signalStrength);
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700750 if (!checkNotifyPermission("notifySignalStrength()")) {
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800751 log("notifySignalStrengthForSubscriber: permission check failure");
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700752 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700753 }
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800754 toStringLogSSC("notifySignalStrengthForSubscriber");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700756 int phoneId = SubscriptionManager.getPhoneId(subId);
757 if (validatePhoneId(phoneId)) {
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800758 log("notifySignalStrengthForSubscriber: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700759 mSignalStrength[phoneId] = signalStrength;
760 for (Record r : mRecords) {
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800761 log("notifySignalStrengthForSubscriber: r=" + r + " subId=" + subId
762 + " phoneId=" + phoneId + " ss=" + signalStrength);
Wink Savillea374c3d2014-11-11 11:48:04 -0800763 if (r.matchPhoneStateListenerEvent(
764 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800765 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700766 try {
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800767 log("notifySignalStrengthForSubscriber: callback.onSsS r=" + r
768 + " subId=" + subId + " phoneId=" + phoneId
769 + " ss=" + signalStrength);
Wink Savillefb40dd42014-06-12 17:02:31 -0700770 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
771 } catch (RemoteException ex) {
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800772 log("notifySignalStrengthForSubscriber: Exception while calling callback!!");
Wink Savillefb40dd42014-06-12 17:02:31 -0700773 mRemoveList.add(r.binder);
774 }
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800775 } else {
776 log("notifySignalStrengthForSubscriber: no match for LISTEN_SIGNAL_STRENGTHS");
Joe Onorato163d8d92010-10-21 13:21:20 -0400777 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800778 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800779 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700780 try {
781 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700782 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800783 log("notifySignalStrengthForSubscriber: callback.onSS r=" + r
784 + " subId=" + subId + " phoneId=" + phoneId
785 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700786 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700787 } catch (RemoteException ex) {
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800788 log("notifySignalStrengthForSubscriber: Exception in deprecated LISTEN_SIGNAL_STRENGTH");
Wink Savillefb40dd42014-06-12 17:02:31 -0700789 mRemoveList.add(r.binder);
790 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 }
792 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700793 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700794 log("notifySignalStrengthForSubscriber: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800795 }
Amit Mahajan6ba726f82015-02-26 10:48:02 -0800796 log("notifySignalStrengthForSubscriber: done with all records");
Joe Onorato163d8d92010-10-21 13:21:20 -0400797 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700799 broadcastSignalStrengthChanged(signalStrength, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 }
801
Andrew Flynn1f452642015-04-14 22:16:04 -0400802 @Override
803 public void notifyCarrierNetworkChange(boolean active) {
804 if (!checkNotifyPermissionOrCarrierPrivilege("notifyCarrierNetworkChange()")) {
805 return;
806 }
807 if (VDBG) {
808 log("notifyCarrierNetworkChange: active=" + active);
809 }
810
811 synchronized (mRecords) {
812 mCarrierNetworkChangeState = active;
813 for (Record r : mRecords) {
814 if (r.matchPhoneStateListenerEvent(
815 PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE)) {
816 try {
817 r.callback.onCarrierNetworkChange(active);
818 } catch (RemoteException ex) {
819 mRemoveList.add(r.binder);
820 }
821 }
822 }
823 handleRemoveListLocked();
824 }
825 }
826
Wink Savilleb208a242012-07-25 14:08:09 -0700827 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800828 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700829 }
830
Wink Saville63f03dd2014-10-23 10:44:45 -0700831 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700832 if (!checkNotifyPermission("notifyCellInfo()")) {
833 return;
834 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700835 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700836 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700837 + " cellInfo=" + cellInfo);
838 }
John Wang963db55d2012-03-30 16:04:06 -0700839
840 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700841 int phoneId = SubscriptionManager.getPhoneId(subId);
842 if (validatePhoneId(phoneId)) {
843 mCellInfo.set(phoneId, cellInfo);
844 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -0700845 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
xinhe8b79fb62014-11-05 14:55:03 -0800846 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700847 try {
848 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700849 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -0700850 }
851 r.callback.onCellInfoChanged(cellInfo);
852 } catch (RemoteException ex) {
853 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700854 }
John Wang963db55d2012-03-30 16:04:06 -0700855 }
856 }
857 }
858 handleRemoveListLocked();
859 }
860 }
861
Wink Saville070e0612014-04-15 22:04:10 -0700862 public void notifyDataConnectionRealTimeInfo(DataConnectionRealTimeInfo dcRtInfo) {
863 if (!checkNotifyPermission("notifyDataConnectionRealTimeInfo()")) {
864 return;
865 }
866
867 synchronized (mRecords) {
868 mDcRtInfo = dcRtInfo;
869 for (Record r : mRecords) {
870 if (validateEventsAndUserLocked(r,
871 PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO)) {
872 try {
873 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700874 log("notifyDataConnectionRealTimeInfo: mDcRtInfo="
Wink Saville070e0612014-04-15 22:04:10 -0700875 + mDcRtInfo + " r=" + r);
876 }
877 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
878 } catch (RemoteException ex) {
879 mRemoveList.add(r.binder);
880 }
881 }
882 }
883 handleRemoveListLocked();
884 }
885 }
886
xinhe43c50292014-09-18 17:56:48 -0700887 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700888 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700889 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700890 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700891 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700892 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -0700893 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -0700894 + " mwi=" + mwi);
895 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800896 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700897 if (validatePhoneId(phoneId)) {
898 mMessageWaiting[phoneId] = mwi;
899 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800900 if (r.matchPhoneStateListenerEvent(
901 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -0800902 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700903 try {
904 r.callback.onMessageWaitingIndicatorChanged(mwi);
905 } catch (RemoteException ex) {
906 mRemoveList.add(r.binder);
907 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908 }
909 }
910 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400911 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 }
913 }
914
915 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800916 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -0700917 }
918
Wink Saville63f03dd2014-10-23 10:44:45 -0700919 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700920 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700921 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700922 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700923 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700924 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700925 + " cfi=" + cfi);
926 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700928 int phoneId = SubscriptionManager.getPhoneId(subId);
929 if (validatePhoneId(phoneId)) {
930 mCallForwarding[phoneId] = cfi;
931 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800932 if (r.matchPhoneStateListenerEvent(
933 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -0800934 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700935 try {
936 r.callback.onCallForwardingIndicatorChanged(cfi);
937 } catch (RemoteException ex) {
938 mRemoveList.add(r.binder);
939 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 }
941 }
942 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400943 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 }
945 }
946
947 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800948 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -0700949 }
950
Wink Saville63f03dd2014-10-23 10:44:45 -0700951 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700952 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700953 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700954 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700956 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -0800957 if (validatePhoneId(phoneId)) {
958 mDataActivity[phoneId] = state;
959 for (Record r : mRecords) {
960 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY)) {
961 try {
962 r.callback.onDataActivity(state);
963 } catch (RemoteException ex) {
964 mRemoveList.add(r.binder);
965 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 }
967 }
968 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400969 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 }
971 }
972
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700973 public void notifyDataConnection(int state, boolean isDataConnectivityPossible,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700974 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -0700975 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800976 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
xinhe43c50292014-09-18 17:56:48 -0700977 isDataConnectivityPossible,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -0700978 networkCapabilities, networkType, roaming);
979 }
980
Wink Saville63f03dd2014-10-23 10:44:45 -0700981 public void notifyDataConnectionForSubscriber(int subId, int state,
Wink Savillefb40dd42014-06-12 17:02:31 -0700982 boolean isDataConnectivityPossible, String reason, String apn, String apnType,
983 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
984 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700985 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700986 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700987 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700988 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700989 log("notifyDataConnectionForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700990 + " state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible
991 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -0700992 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
xinheac11ae92014-12-18 10:02:14 -0800993 + " mRecords.size()=" + mRecords.size());
Wink Savillec9acde92011-09-21 11:05:43 -0700994 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700996 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -0800997 if (validatePhoneId(phoneId)) {
998 boolean modified = false;
999 if (state == TelephonyManager.DATA_CONNECTED) {
1000 if (!mConnectedApns.contains(apnType)) {
1001 mConnectedApns.add(apnType);
1002 if (mDataConnectionState[phoneId] != state) {
1003 mDataConnectionState[phoneId] = state;
1004 modified = true;
1005 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001007 } else {
1008 if (mConnectedApns.remove(apnType)) {
1009 if (mConnectedApns.isEmpty()) {
1010 mDataConnectionState[phoneId] = state;
1011 modified = true;
1012 } else {
1013 // leave mDataConnectionState as is and
1014 // send out the new status for the APN in question.
Wink Savillebaf21da2014-11-19 16:03:09 -08001015 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001016 }
1017 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001018 mDataConnectionPossible[phoneId] = isDataConnectivityPossible;
1019 mDataConnectionReason[phoneId] = reason;
1020 mDataConnectionLinkProperties[phoneId] = linkProperties;
1021 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
1022 if (mDataConnectionNetworkType[phoneId] != networkType) {
1023 mDataConnectionNetworkType[phoneId] = networkType;
1024 // need to tell registered listeners about the new network type
1025 modified = true;
1026 }
1027 if (modified) {
1028 if (DBG) {
1029 log("onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
1030 + ", " + mDataConnectionNetworkType[phoneId] + ")");
1031 }
1032 for (Record r : mRecords) {
1033 if (r.matchPhoneStateListenerEvent(
1034 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
1035 idMatch(r.subId, subId, phoneId)) {
1036 try {
1037 log("Notify data connection state changed on sub: " +
1038 subId);
1039 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1040 mDataConnectionNetworkType[phoneId]);
1041 } catch (RemoteException ex) {
1042 mRemoveList.add(r.binder);
1043 }
1044 }
1045 }
1046 handleRemoveListLocked();
1047 }
1048 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1049 apnType, apn, reason, linkProperties, "");
1050 for (Record r : mRecords) {
1051 if (r.matchPhoneStateListenerEvent(
1052 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1053 try {
1054 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1055 } catch (RemoteException ex) {
1056 mRemoveList.add(r.binder);
1057 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001058 }
1059 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001060 }
1061 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001063 broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001064 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001065 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1066 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 }
1068
Robert Greenwalt02648a42010-05-18 10:52:51 -07001069 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001070 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001071 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001072 }
1073
Wink Saville63f03dd2014-10-23 10:44:45 -07001074 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001075 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001076 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001077 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001078 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001079 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001080 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001081 + " reason=" + reason + " apnType=" + apnType);
1082 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001084 mPreciseDataConnectionState = new PreciseDataConnectionState(
1085 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1086 apnType, "", reason, null, "");
1087 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001088 if (r.matchPhoneStateListenerEvent(
1089 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001090 try {
1091 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1092 } catch (RemoteException ex) {
1093 mRemoveList.add(r.binder);
1094 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 }
1096 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001097 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001099 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001100 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1101 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 }
1103
1104 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001105 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001106 }
1107
Wink Saville63f03dd2014-10-23 10:44:45 -07001108 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001109 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001110 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001111 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001112 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001113 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001114 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001115 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001116 + " cellLocation=" + cellLocation);
1117 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001119 int phoneId = SubscriptionManager.getPhoneId(subId);
1120 if (validatePhoneId(phoneId)) {
1121 mCellLocation[phoneId] = cellLocation;
1122 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001123 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
xinhe8b79fb62014-11-05 14:55:03 -08001124 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001125 try {
1126 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001127 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001128 + " r=" + r);
1129 }
1130 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1131 } catch (RemoteException ex) {
1132 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001133 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001134 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 }
1136 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001137 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001138 }
1139 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001140
Wink Savillefd2d0132010-10-28 14:22:26 -07001141 public void notifyOtaspChanged(int otaspMode) {
1142 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1143 return;
1144 }
1145 synchronized (mRecords) {
1146 mOtaspMode = otaspMode;
1147 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001148 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001149 try {
1150 r.callback.onOtaspChanged(otaspMode);
1151 } catch (RemoteException ex) {
1152 mRemoveList.add(r.binder);
1153 }
1154 }
1155 }
1156 handleRemoveListLocked();
1157 }
1158 }
1159
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001160 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1161 int backgroundCallState) {
1162 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1163 return;
1164 }
1165 synchronized (mRecords) {
1166 mRingingCallState = ringingCallState;
1167 mForegroundCallState = foregroundCallState;
1168 mBackgroundCallState = backgroundCallState;
1169 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1170 backgroundCallState,
1171 DisconnectCause.NOT_VALID,
1172 PreciseDisconnectCause.NOT_VALID);
1173 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001174 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001175 try {
1176 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1177 } catch (RemoteException ex) {
1178 mRemoveList.add(r.binder);
1179 }
1180 }
1181 }
1182 handleRemoveListLocked();
1183 }
1184 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1185 DisconnectCause.NOT_VALID,
1186 PreciseDisconnectCause.NOT_VALID);
1187 }
1188
1189 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1190 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1191 return;
1192 }
1193 synchronized (mRecords) {
1194 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1195 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1196 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001197 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001198 try {
1199 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1200 } catch (RemoteException ex) {
1201 mRemoveList.add(r.binder);
1202 }
1203 }
1204 }
1205 handleRemoveListLocked();
1206 }
1207 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1208 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1209 }
1210
1211 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1212 String apn, String failCause) {
1213 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1214 return;
1215 }
1216 synchronized (mRecords) {
1217 mPreciseDataConnectionState = new PreciseDataConnectionState(
1218 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1219 apnType, apn, reason, null, failCause);
1220 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001221 if (r.matchPhoneStateListenerEvent(
1222 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001223 try {
1224 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1225 } catch (RemoteException ex) {
1226 mRemoveList.add(r.binder);
1227 }
1228 }
1229 }
1230 handleRemoveListLocked();
1231 }
1232 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1233 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1234 }
1235
Wink Savillefb40dd42014-06-12 17:02:31 -07001236 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1237 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1238 return;
1239 }
1240 synchronized (mRecords) {
1241 mVoLteServiceState = lteState;
1242 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001243 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001244 try {
1245 r.callback.onVoLteServiceStateChanged(
1246 new VoLteServiceState(mVoLteServiceState));
1247 } catch (RemoteException ex) {
1248 mRemoveList.add(r.binder);
1249 }
1250 }
1251 }
1252 handleRemoveListLocked();
1253 }
1254 }
1255
Wink Saville63f03dd2014-10-23 10:44:45 -07001256 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001257 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1258 return;
1259 }
1260
1261 synchronized (mRecords) {
1262 for (Record r : mRecords) {
1263 if (VDBG) {
1264 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1265 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001266 if ((r.matchPhoneStateListenerEvent(
1267 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
New Author Steven Liu485f2092014-09-11 10:18:45 -05001268 ((r.subId == subId) ||
Wink Savilled09c4ca2014-11-22 10:08:16 -08001269 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001270 try {
1271 r.callback.onOemHookRawEvent(rawData);
1272 } catch (RemoteException ex) {
1273 mRemoveList.add(r.binder);
1274 }
1275 }
1276 }
1277 handleRemoveListLocked();
1278 }
1279 }
1280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001281 @Override
1282 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1283 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1284 != PackageManager.PERMISSION_GRANTED) {
1285 pw.println("Permission Denial: can't dump telephony.registry from from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001286 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 return;
1288 }
1289 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001290 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001291 pw.println("last known state:");
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301292 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1293 pw.println(" Phone Id=" + i);
1294 pw.println(" mCallState=" + mCallState[i]);
1295 pw.println(" mCallIncomingNumber=" + mCallIncomingNumber[i]);
1296 pw.println(" mServiceState=" + mServiceState[i]);
1297 pw.println(" mSignalStrength=" + mSignalStrength[i]);
1298 pw.println(" mMessageWaiting=" + mMessageWaiting[i]);
1299 pw.println(" mCallForwarding=" + mCallForwarding[i]);
1300 pw.println(" mDataActivity=" + mDataActivity[i]);
1301 pw.println(" mDataConnectionState=" + mDataConnectionState[i]);
1302 pw.println(" mDataConnectionPossible=" + mDataConnectionPossible[i]);
1303 pw.println(" mDataConnectionReason=" + mDataConnectionReason[i]);
1304 pw.println(" mDataConnectionApn=" + mDataConnectionApn[i]);
1305 pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1306 pw.println(" mDataConnectionNetworkCapabilities=" +
1307 mDataConnectionNetworkCapabilities[i]);
1308 pw.println(" mCellLocation=" + mCellLocation[i]);
1309 pw.println(" mCellInfo=" + mCellInfo.get(i));
1310 }
Wink Saville070e0612014-04-15 22:04:10 -07001311 pw.println(" mDcRtInfo=" + mDcRtInfo);
Wink Savillee9b06d72009-05-18 21:47:50 -07001312 pw.println("registrations: count=" + recordCount);
Robert Greenwalt02648a42010-05-18 10:52:51 -07001313 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -07001314 pw.println(" " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 }
1316 }
1317 }
1318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001319 //
1320 // the legacy intent broadcasting
1321 //
1322
Wink Saville63f03dd2014-10-23 10:44:45 -07001323 private void broadcastServiceStateChanged(ServiceState state, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001324 long ident = Binder.clearCallingIdentity();
1325 try {
1326 mBatteryStats.notePhoneState(state.getState());
1327 } catch (RemoteException re) {
1328 // Can't do much
1329 } finally {
1330 Binder.restoreCallingIdentity(ident);
1331 }
1332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001333 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
1334 Bundle data = new Bundle();
1335 state.fillInNotifierBundle(data);
1336 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001337 // Pass the subscription along with the intent.
1338 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001339 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001340 }
1341
Wink Saville63f03dd2014-10-23 10:44:45 -07001342 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001343 long ident = Binder.clearCallingIdentity();
1344 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001345 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001346 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001347 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001348 } finally {
1349 Binder.restoreCallingIdentity(ident);
1350 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08001353 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
Wink Savillee9b06d72009-05-18 21:47:50 -07001354 Bundle data = new Bundle();
1355 signalStrength.fillInNotifierBundle(data);
1356 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001357 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001358 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001359 }
1360
Wink Saville63f03dd2014-10-23 10:44:45 -07001361 private void broadcastCallStateChanged(int state, String incomingNumber, int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001362 long ident = Binder.clearCallingIdentity();
1363 try {
1364 if (state == TelephonyManager.CALL_STATE_IDLE) {
1365 mBatteryStats.notePhoneOff();
1366 } else {
1367 mBatteryStats.notePhoneOn();
1368 }
1369 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001370 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001371 } finally {
1372 Binder.restoreCallingIdentity(ident);
1373 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001375 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001376 intent.putExtra(PhoneConstants.STATE_KEY,
1377 DefaultPhoneNotifier.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001378 if (!TextUtils.isEmpty(incomingNumber)) {
1379 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1380 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001381 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001382 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1383 android.Manifest.permission.READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001384 }
1385
Robert Greenwalt42acef32009-08-12 16:08:25 -07001386 private void broadcastDataConnectionStateChanged(int state,
1387 boolean isDataConnectivityPossible,
Wink Savillef61101f2010-09-16 16:36:42 -07001388 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001389 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001390 // Note: not reporting to the battery stats service here, because the
1391 // status bar takes care of that after taking into account all of the
1392 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001393 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001394 intent.putExtra(PhoneConstants.STATE_KEY,
1395 DefaultPhoneNotifier.convertDataState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001396 if (!isDataConnectivityPossible) {
Wink Savillea639b312012-07-10 12:37:54 -07001397 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001398 }
1399 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001400 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001401 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001402 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001403 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001404 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001405 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001406 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001407 }
1408 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001409 if (networkCapabilities != null) {
1410 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001411 }
Wink Savillea639b312012-07-10 12:37:54 -07001412 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001413
Wink Savillea639b312012-07-10 12:37:54 -07001414 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1415 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001416 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001417 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001418 }
1419
Wink Savillefb40dd42014-06-12 17:02:31 -07001420 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001421 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001423 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1424 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001425 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001426 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001428
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001429 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1430 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1431 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1432 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1433 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1434 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1435 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1436 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1437 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1438 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1439 }
1440
1441 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001442 String apnType, String apn, String reason, LinkProperties linkProperties,
1443 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001444 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1445 intent.putExtra(PhoneConstants.STATE_KEY, state);
1446 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1447 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1448 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1449 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001450 if (linkProperties != null) {
1451 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1452 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001453 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1454
1455 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1456 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1457 }
1458
Andrew Flynn1f452642015-04-14 22:16:04 -04001459 private boolean checkNotifyPermissionOrCarrierPrivilege(String method) {
1460 if (checkNotifyPermission() || checkCarrierPrivilege()) {
1461 return true;
1462 }
1463
1464 String msg = "Modify Phone State or Carrier Privilege Permission Denial: " + method
1465 + " from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
1466 if (DBG) log(msg);
1467 return false;
1468 }
1469
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001470 private boolean checkNotifyPermission(String method) {
Andrew Flynn1f452642015-04-14 22:16:04 -04001471 if (checkNotifyPermission()) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001472 return true;
1473 }
1474 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001475 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001476 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001477 return false;
1478 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001479
Andrew Flynn1f452642015-04-14 22:16:04 -04001480 private boolean checkNotifyPermission() {
1481 return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1482 == PackageManager.PERMISSION_GRANTED;
1483 }
1484
1485 private boolean checkCarrierPrivilege() {
1486 TelephonyManager tm = TelephonyManager.getDefault();
1487 String[] pkgs = mContext.getPackageManager().getPackagesForUid(Binder.getCallingUid());
1488 for (String pkg : pkgs) {
1489 if (tm.checkCarrierPrivilegesForPackage(pkg) ==
1490 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
1491 return true;
1492 }
1493 }
1494
1495 return false;
1496 }
1497
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001498 private void checkListenerPermission(int events) {
1499 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1500 mContext.enforceCallingOrSelfPermission(
1501 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1502
1503 }
1504
John Wang963db55d2012-03-30 16:04:06 -07001505 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1506 mContext.enforceCallingOrSelfPermission(
1507 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1508
1509 }
1510
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001511 if ((events & PHONE_STATE_PERMISSION_MASK) != 0) {
1512 mContext.enforceCallingOrSelfPermission(
1513 android.Manifest.permission.READ_PHONE_STATE, null);
1514 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001515
1516 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1517 mContext.enforceCallingOrSelfPermission(
1518 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1519
1520 }
New Author Steven Liu485f2092014-09-11 10:18:45 -05001521
1522 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1523 mContext.enforceCallingOrSelfPermission(
1524 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1525 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001526 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001527
1528 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001529 int size = mRemoveList.size();
1530 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1531 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001532 for (IBinder b: mRemoveList) {
1533 remove(b);
1534 }
1535 mRemoveList.clear();
1536 }
1537 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001538
1539 private boolean validateEventsAndUserLocked(Record r, int events) {
1540 int foregroundUser;
1541 long callingIdentity = Binder.clearCallingIdentity();
1542 boolean valid = false;
1543 try {
1544 foregroundUser = ActivityManager.getCurrentUser();
Wink Savillea374c3d2014-11-11 11:48:04 -08001545 valid = r.callerUid == foregroundUser && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001546 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001547 log("validateEventsAndUserLocked: valid=" + valid
Wink Savillea12a7b32012-09-20 10:09:45 -07001548 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
1549 + " r.events=" + r.events + " events=" + events);
1550 }
1551 } finally {
1552 Binder.restoreCallingIdentity(callingIdentity);
1553 }
1554 return valid;
1555 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001556
1557 private boolean validatePhoneId(int phoneId) {
1558 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001559 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001560 return valid;
1561 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001562
1563 private static void log(String s) {
1564 Rlog.d(TAG, s);
1565 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001566
1567 private static class LogSSC {
1568 private Time mTime;
1569 private String mS;
Wink Saville63f03dd2014-10-23 10:44:45 -07001570 private int mSubId;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001571 private int mPhoneId;
1572 private ServiceState mState;
1573
Wink Saville63f03dd2014-10-23 10:44:45 -07001574 public void set(Time t, String s, int subId, int phoneId, ServiceState state) {
Wink Saville47d8d1b2014-07-10 13:01:52 -07001575 mTime = t; mS = s; mSubId = subId; mPhoneId = phoneId; mState = state;
1576 }
1577
1578 @Override
1579 public String toString() {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001580 return mS + " Time " + mTime.toString() + " mSubId " + mSubId + " mPhoneId "
1581 + mPhoneId + " mState " + mState;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001582 }
1583 }
1584
1585 private LogSSC logSSC [] = new LogSSC[10];
1586 private int next = 0;
1587
Wink Saville63f03dd2014-10-23 10:44:45 -07001588 private void logServiceStateChanged(String s, int subId, int phoneId, ServiceState state) {
Wink Saville47d8d1b2014-07-10 13:01:52 -07001589 if (logSSC == null || logSSC.length == 0) {
1590 return;
1591 }
1592 if (logSSC[next] == null) {
1593 logSSC[next] = new LogSSC();
1594 }
1595 Time t = new Time();
1596 t.setToNow();
1597 logSSC[next].set(t, s, subId, phoneId, state);
1598 if (++next >= logSSC.length) {
1599 next = 0;
1600 }
1601 }
1602
1603 private void toStringLogSSC(String prompt) {
1604 if (logSSC == null || logSSC.length == 0 || (next == 0 && logSSC[next] == null)) {
1605 log(prompt + ": logSSC is empty");
1606 } else {
1607 // There is at least one element
1608 log(prompt + ": logSSC.length=" + logSSC.length + " next=" + next);
1609 int i = next;
1610 if (logSSC[i] == null) {
1611 // logSSC is not full so back to the beginning
1612 i = 0;
1613 }
1614 do {
1615 log(logSSC[i].toString());
1616 if (++i >= logSSC.length) {
1617 i = 0;
1618 }
1619 } while (i != next);
Wink Savillee380b982014-07-26 18:24:22 -07001620 log(prompt + ": ----------------");
Wink Saville47d8d1b2014-07-10 13:01:52 -07001621 }
1622 }
xinhee9f16402014-09-25 16:39:28 -07001623
xinhe8b79fb62014-11-05 14:55:03 -08001624 boolean idMatch(int rSubId, int subId, int phoneId) {
xinheac11ae92014-12-18 10:02:14 -08001625
1626 if(subId < 0) {
1627 // Invalid case, we need compare phoneId with default one.
1628 return (mDefaultPhoneId == phoneId);
1629 }
Wink Savilled09c4ca2014-11-22 10:08:16 -08001630 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhee9f16402014-09-25 16:39:28 -07001631 return (subId == mDefaultSubId);
1632 } else {
1633 return (rSubId == subId);
1634 }
1635 }
1636
1637 private void checkPossibleMissNotify(Record r, int phoneId) {
1638 int events = r.events;
1639
1640 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1641 try {
1642 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1643 mServiceState[phoneId]);
1644 r.callback.onServiceStateChanged(
1645 new ServiceState(mServiceState[phoneId]));
1646 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001647 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001648 }
1649 }
1650
1651 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1652 try {
1653 SignalStrength signalStrength = mSignalStrength[phoneId];
1654 if (DBG) {
1655 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1656 }
1657 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1658 } catch (RemoteException ex) {
1659 mRemoveList.add(r.binder);
1660 }
1661 }
1662
1663 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1664 try {
1665 int gsmSignalStrength = mSignalStrength[phoneId]
1666 .getGsmSignalStrength();
1667 if (DBG) {
1668 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1669 gsmSignalStrength);
1670 }
1671 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1672 : gsmSignalStrength));
1673 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001674 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001675 }
1676 }
1677
1678 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1679 try {
1680 if (DBG_LOC) {
1681 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1682 + mCellInfo.get(phoneId));
1683 }
1684 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1685 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001686 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001687 }
1688 }
1689
1690 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1691 try {
1692 if (VDBG) {
1693 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1694 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1695 }
1696 r.callback.onMessageWaitingIndicatorChanged(
1697 mMessageWaiting[phoneId]);
1698 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001699 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001700 }
1701 }
1702
1703 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1704 try {
1705 if (VDBG) {
1706 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1707 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1708 }
1709 r.callback.onCallForwardingIndicatorChanged(
1710 mCallForwarding[phoneId]);
1711 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001712 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001713 }
1714 }
1715
1716 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1717 try {
1718 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1719 + mCellLocation[phoneId]);
1720 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1721 } catch (RemoteException ex) {
1722 mRemoveList.add(r.binder);
1723 }
1724 }
1725
1726 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1727 try {
1728 if (DBG) {
1729 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1730 + "=" + mDataConnectionState[phoneId]
1731 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1732 + ")");
1733 }
1734 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1735 mDataConnectionNetworkType[phoneId]);
1736 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001737 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001738 }
1739 }
1740 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001741}