blob: 776f8362a5ebf89685f456cc3c5118f5cf8b3f64 [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
184 private PreciseDataConnectionState mPreciseDataConnectionState =
185 new PreciseDataConnectionState();
186
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700187 static final int PHONE_STATE_PERMISSION_MASK =
188 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
189 PhoneStateListener.LISTEN_CALL_STATE |
190 PhoneStateListener.LISTEN_DATA_ACTIVITY |
191 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
Wink Savillefb40dd42014-06-12 17:02:31 -0700192 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
193 PhoneStateListener.LISTEN_VOLTE_STATE;;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700194
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200195 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
196 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
197 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
198
Wink Savillea12a7b32012-09-20 10:09:45 -0700199 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700200 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700201
202 private final Handler mHandler = new Handler() {
203 @Override
204 public void handleMessage(Message msg) {
205 switch (msg.what) {
206 case MSG_USER_SWITCHED: {
Wink Savillee380b982014-07-26 18:24:22 -0700207 if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700208 int numPhones = TelephonyManager.getDefault().getPhoneCount();
209 for (int sub = 0; sub < numPhones; sub++) {
Wink Savillebc027272014-09-08 14:50:58 -0700210 TelephonyRegistry.this.notifyCellLocationForSubscriber(sub,
Wink Savillee380b982014-07-26 18:24:22 -0700211 mCellLocation[sub]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700212 }
213 break;
214 }
xinhee9f16402014-09-25 16:39:28 -0700215 case MSG_UPDATE_DEFAULT_SUB: {
216 int newDefaultPhoneId = msg.arg1;
Wink Saville63f03dd2014-10-23 10:44:45 -0700217 int newDefaultSubId = (Integer)(msg.obj);
xinhee9f16402014-09-25 16:39:28 -0700218 if (VDBG) {
219 log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId
220 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
221 + newDefaultSubId + " newDefaultPhoneId=" + newDefaultPhoneId);
222 }
223
224 //Due to possible risk condition,(notify call back using the new
225 //defaultSubId comes before new defaultSubId update) we need to recall all
226 //possible missed notify callback
227 synchronized (mRecords) {
Etan Cohena33cf072014-09-30 10:35:24 -0700228 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800229 if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
Etan Cohena33cf072014-09-30 10:35:24 -0700230 checkPossibleMissNotify(r, newDefaultPhoneId);
231 }
232 }
233 handleRemoveListLocked();
xinhee9f16402014-09-25 16:39:28 -0700234 }
235 mDefaultSubId = newDefaultSubId;
236 mDefaultPhoneId = newDefaultPhoneId;
Wink Savillea12a7b32012-09-20 10:09:45 -0700237 }
238 }
239 }
240 };
241
242 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
243 @Override
244 public void onReceive(Context context, Intent intent) {
245 String action = intent.getAction();
Wink Savillee380b982014-07-26 18:24:22 -0700246 if (VDBG) log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700247 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700248 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700249 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700250 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700251 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
Wink Saville63f03dd2014-10-23 10:44:45 -0700252 Integer newDefaultSubIdObj = new Integer(intent.getIntExtra(
xinhee9f16402014-09-25 16:39:28 -0700253 PhoneConstants.SUBSCRIPTION_KEY, SubscriptionManager.getDefaultSubId()));
254 int newDefaultPhoneId = intent.getIntExtra(PhoneConstants.SLOT_KEY,
255 SubscriptionManager.getPhoneId(mDefaultSubId));
Wink Savillee380b982014-07-26 18:24:22 -0700256 if (DBG) {
xinhee9f16402014-09-25 16:39:28 -0700257 log("onReceive:current mDefaultSubId=" + mDefaultSubId
258 + " current mDefaultPhoneId=" + mDefaultPhoneId + " newDefaultSubId= "
259 + newDefaultSubIdObj + " newDefaultPhoneId=" + newDefaultPhoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700260 }
xinhee9f16402014-09-25 16:39:28 -0700261
262 if(validatePhoneId(newDefaultPhoneId) && (newDefaultSubIdObj.equals(mDefaultSubId)
263 || (newDefaultPhoneId != mDefaultPhoneId))) {
264 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB,
265 newDefaultPhoneId, 0, newDefaultSubIdObj));
266 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700267 }
268 }
269 };
270
Wink Savillee9b06d72009-05-18 21:47:50 -0700271 // we keep a copy of all of the state so we can send it out when folks
272 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700274 // In these calls we call with the lock held. This is safe becasuse remote
275 // calls go through a oneway interface and local calls going through a
276 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277
278 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700279 CellLocation location = CellLocation.getEmpty();
280
Wink Savillefb40dd42014-06-12 17:02:31 -0700281 mContext = context;
282 mBatteryStats = BatteryStatsService.getService();
283 mConnectedApns = new ArrayList<String>();
284
Wink Savillefb40dd42014-06-12 17:02:31 -0700285 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700286 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700287 mNumPhones = numPhones;
288 mCallState = new int[numPhones];
289 mDataActivity = new int[numPhones];
290 mDataConnectionState = new int[numPhones];
291 mDataConnectionNetworkType = new int[numPhones];
292 mCallIncomingNumber = new String[numPhones];
293 mServiceState = new ServiceState[numPhones];
294 mSignalStrength = new SignalStrength[numPhones];
295 mMessageWaiting = new boolean[numPhones];
296 mDataConnectionPossible = new boolean[numPhones];
297 mDataConnectionReason = new String[numPhones];
298 mDataConnectionApn = new String[numPhones];
299 mCallForwarding = new boolean[numPhones];
300 mCellLocation = new Bundle[numPhones];
301 mDataConnectionLinkProperties = new LinkProperties[numPhones];
302 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
303 mCellInfo = new ArrayList<List<CellInfo>>();
304 for (int i = 0; i < numPhones; i++) {
305 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
306 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
307 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
308 mCallIncomingNumber[i] = "";
309 mServiceState[i] = new ServiceState();
310 mSignalStrength[i] = new SignalStrength();
311 mMessageWaiting[i] = false;
312 mCallForwarding[i] = false;
313 mDataConnectionPossible[i] = false;
314 mDataConnectionReason[i] = "";
315 mDataConnectionApn[i] = "";
316 mCellLocation[i] = new Bundle();
317 mCellInfo.add(i, null);
318 }
319
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700320 // Note that location can be null for non-phone builds like
321 // like the generic one.
322 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700323 for (int i = 0; i < numPhones; i++) {
324 location.fillInNotifierBundle(mCellLocation[i]);
325 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700326 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700327 mConnectedApns = new ArrayList<String>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800328 }
329
Svetoslav Ganova0027152013-06-25 14:59:53 -0700330 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700331 // Watch for interesting updates
332 final IntentFilter filter = new IntentFilter();
333 filter.addAction(Intent.ACTION_USER_SWITCHED);
334 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700335 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700336 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700337 mContext.registerReceiver(mBroadcastReceiver, filter);
338 }
339
340 @Override
Wink Savilled09c4ca2014-11-22 10:08:16 -0800341 public void registerOnSubscriptionsChangedListener(String pkgForDebug,
342 IOnSubscriptionsChangedListener callback) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800343 int callerUid = UserHandle.getCallingUserId();
344 int myUid = UserHandle.myUserId();
345 if (VDBG) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800346 log("listen oscl: E pkg=" + pkgForDebug + " myUid=" + myUid
347 + " callerUid=" + callerUid + " callback=" + callback
Wink Savillea374c3d2014-11-11 11:48:04 -0800348 + " callback.asBinder=" + callback.asBinder());
349 }
350
Wink Savilled09c4ca2014-11-22 10:08:16 -0800351 /* Checks permission and throws Security exception */
352 checkOnSubscriptionsChangedListenerPermission();
353 Record r = null;
Wink Savillea374c3d2014-11-11 11:48:04 -0800354
Wink Savilled09c4ca2014-11-22 10:08:16 -0800355 synchronized (mRecords) {
356 // register
357 find_and_add: {
358 IBinder b = callback.asBinder();
359 final int N = mRecords.size();
360 for (int i = 0; i < N; i++) {
361 r = mRecords.get(i);
362 if (b == r.binder) {
363 break find_and_add;
Wink Savillea374c3d2014-11-11 11:48:04 -0800364 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800365 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800366 r = new Record();
367 r.binder = b;
368 mRecords.add(r);
369 if (DBG) log("listen oscl: add new record");
Wink Savillea374c3d2014-11-11 11:48:04 -0800370 }
371
Wink Savilled09c4ca2014-11-22 10:08:16 -0800372 r.onSubscriptionsChangedListenerCallback = callback;
373 r.pkgForDebug = pkgForDebug;
374 r.callerUid = callerUid;
375 r.events = 0;
376 if (DBG) {
377 log("listen oscl: Register r=" + r);
378 }
379 // Always notify when registration occurs if there has been a notification.
380 if (hasNotifySubscriptionInfoChangedOccurred) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800381 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800382 if (VDBG) log("listen oscl: send to r=" + r);
383 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
384 if (VDBG) log("listen oscl: sent to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800385 } catch (RemoteException e) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800386 if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e);
Wink Savillea374c3d2014-11-11 11:48:04 -0800387 remove(r.binder);
388 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800389 } else {
390 log("listen oscl: hasNotifySubscriptionInfoChangedOccurred==false no callback");
Wink Savillea374c3d2014-11-11 11:48:04 -0800391 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800392 }
393 }
394
395 @Override
Wink Savilled09c4ca2014-11-22 10:08:16 -0800396 public void unregisterOnSubscriptionsChangedListener(String pkgForDebug,
397 IOnSubscriptionsChangedListener callback) {
398 if (DBG) log("listen oscl: Unregister");
Wink Savillea374c3d2014-11-11 11:48:04 -0800399 remove(callback.asBinder());
400 }
401
Wink Savilled09c4ca2014-11-22 10:08:16 -0800402 private void checkOnSubscriptionsChangedListenerPermission() {
403 mContext.enforceCallingOrSelfPermission(
404 SubscriptionManager.OnSubscriptionsChangedListener
405 .PERMISSION_ON_SUBSCRIPTIONS_CHANGED, null);
Wink Savillea374c3d2014-11-11 11:48:04 -0800406 }
407
408 @Override
409 public void notifySubscriptionInfoChanged() {
410 if (VDBG) log("notifySubscriptionInfoChanged:");
411 synchronized (mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800412 if (!hasNotifySubscriptionInfoChangedOccurred) {
413 log("notifySubscriptionInfoChanged: first invocation mRecords.size="
414 + mRecords.size());
415 }
416 hasNotifySubscriptionInfoChangedOccurred = true;
Wink Savillea374c3d2014-11-11 11:48:04 -0800417 mRemoveList.clear();
418 for (Record r : mRecords) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800419 if (r.matchOnSubscriptionsChangedListener()) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800420 try {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800421 if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r);
422 r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged();
423 if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r);
Wink Savillea374c3d2014-11-11 11:48:04 -0800424 } catch (RemoteException ex) {
425 if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r);
426 mRemoveList.add(r.binder);
427 }
428 }
429 }
430 handleRemoveListLocked();
431 }
432 }
433
434 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
436 boolean notifyNow) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800437 listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
438 events, notifyNow);
Wink Savillefb40dd42014-06-12 17:02:31 -0700439 }
440
441 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700442 public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
Wink Savillefb40dd42014-06-12 17:02:31 -0700443 int events, boolean notifyNow) {
xinhe43c50292014-09-18 17:56:48 -0700444 listen(pkgForDebug, callback, events, notifyNow, subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700445 }
446
447 private void listen(String pkgForDebug, IPhoneStateListener callback, int events,
Wink Saville63f03dd2014-10-23 10:44:45 -0700448 boolean notifyNow, int subId) {
Wink Savillea12a7b32012-09-20 10:09:45 -0700449 int callerUid = UserHandle.getCallingUserId();
450 int myUid = UserHandle.myUserId();
Wink Savillee380b982014-07-26 18:24:22 -0700451 if (VDBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700452 log("listen: E pkg=" + pkgForDebug + " events=0x" + Integer.toHexString(events)
xinhe43c50292014-09-18 17:56:48 -0700453 + " notifyNow=" + notifyNow + " subId=" + subId + " myUid=" + myUid
Wink Savillea12a7b32012-09-20 10:09:45 -0700454 + " callerUid=" + callerUid);
455 }
xinhe75c2c152014-10-16 11:49:45 -0700456
457 if (events != PhoneStateListener.LISTEN_NONE) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700458 /* Checks permission and throws Security exception */
459 checkListenerPermission(events);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460 synchronized (mRecords) {
461 // register
462 Record r = null;
463 find_and_add: {
464 IBinder b = callback.asBinder();
465 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700466 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 r = mRecords.get(i);
468 if (b == r.binder) {
469 break find_and_add;
470 }
471 }
472 r = new Record();
473 r.binder = b;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800474 mRecords.add(r);
Wink Savillee380b982014-07-26 18:24:22 -0700475 if (DBG) log("listen: add new record");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 }
xinhe43c50292014-09-18 17:56:48 -0700477
xinhe75c2c152014-10-16 11:49:45 -0700478 r.callback = callback;
479 r.pkgForDebug = pkgForDebug;
480 r.callerUid = callerUid;
481 // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
482 // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
Wink Savillea54bf652014-12-11 13:37:50 -0800483 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800484 r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
xinhe75c2c152014-10-16 11:49:45 -0700485 } else {//APP specify subID
486 r.subId = subId;
487 }
488 r.phoneId = SubscriptionManager.getPhoneId(r.subId);
489
xinhe43c50292014-09-18 17:56:48 -0700490 int phoneId = r.phoneId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 r.events = events;
Wink Savillee380b982014-07-26 18:24:22 -0700492 if (DBG) {
xinhe75c2c152014-10-16 11:49:45 -0700493 log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
Wink Savillee380b982014-07-26 18:24:22 -0700494 }
495 if (VDBG) toStringLogSSC("listen");
Wink Savillefb40dd42014-06-12 17:02:31 -0700496 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400498 try {
Wink Savillee380b982014-07-26 18:24:22 -0700499 if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]);
Wink Savillefb40dd42014-06-12 17:02:31 -0700500 r.callback.onServiceStateChanged(
501 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400502 } catch (RemoteException ex) {
503 remove(r.binder);
504 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 }
506 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
507 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700508 int gsmSignalStrength = mSignalStrength[phoneId]
509 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700510 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
511 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 } catch (RemoteException ex) {
513 remove(r.binder);
514 }
515 }
516 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
517 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700518 r.callback.onMessageWaitingIndicatorChanged(
519 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 } catch (RemoteException ex) {
521 remove(r.binder);
522 }
523 }
524 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
525 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700526 r.callback.onCallForwardingIndicatorChanged(
527 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 } catch (RemoteException ex) {
529 remove(r.binder);
530 }
531 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700532 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400533 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700534 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700535 + mCellLocation[phoneId]);
536 r.callback.onCellLocationChanged(
537 new Bundle(mCellLocation[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400538 } catch (RemoteException ex) {
539 remove(r.binder);
540 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 }
542 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
543 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700544 r.callback.onCallStateChanged(mCallState[phoneId],
545 mCallIncomingNumber[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 } catch (RemoteException ex) {
547 remove(r.binder);
548 }
549 }
550 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
551 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700552 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
553 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 } catch (RemoteException ex) {
555 remove(r.binder);
556 }
557 }
558 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
559 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700560 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 } catch (RemoteException ex) {
562 remove(r.binder);
563 }
564 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700565 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
566 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700567 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700568 } catch (RemoteException ex) {
569 remove(r.binder);
570 }
571 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700572 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
573 try {
574 r.callback.onOtaspChanged(mOtaspMode);
575 } catch (RemoteException ex) {
576 remove(r.binder);
577 }
578 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700579 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700580 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700581 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700582 + mCellInfo.get(phoneId));
583 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
John Wang963db55d2012-03-30 16:04:06 -0700584 } catch (RemoteException ex) {
585 remove(r.binder);
586 }
587 }
Wink Saville070e0612014-04-15 22:04:10 -0700588 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO) != 0) {
589 try {
590 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
591 } catch (RemoteException ex) {
592 remove(r.binder);
593 }
594 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200595 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
596 try {
597 r.callback.onPreciseCallStateChanged(mPreciseCallState);
598 } catch (RemoteException ex) {
599 remove(r.binder);
600 }
601 }
602 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
603 try {
604 r.callback.onPreciseDataConnectionStateChanged(
605 mPreciseDataConnectionState);
606 } catch (RemoteException ex) {
607 remove(r.binder);
608 }
609 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 }
611 }
612 } else {
xinhe75c2c152014-10-16 11:49:45 -0700613 if(DBG) log("listen: Unregister");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 remove(callback.asBinder());
615 }
616 }
617
618 private void remove(IBinder binder) {
619 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700620 final int recordCount = mRecords.size();
621 for (int i = 0; i < recordCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 if (mRecords.get(i).binder == binder) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800623 if (VDBG) log("remove: binder=" + binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 mRecords.remove(i);
625 return;
626 }
627 }
628 }
629 }
630
631 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700632 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700633 return;
634 }
xinhe43c50292014-09-18 17:56:48 -0700635
636 if (VDBG) {
637 log("notifyCallState: state=" + state + " incomingNumber=" + incomingNumber);
638 }
639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700641 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800642 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800643 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 try {
645 r.callback.onCallStateChanged(state, incomingNumber);
646 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400647 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800648 }
649 }
650 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400651 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800653 broadcastCallStateChanged(state, incomingNumber,
654 SubscriptionManager.DEFAULT_SUBSCRIPTION_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655 }
656
Wink Saville63f03dd2014-10-23 10:44:45 -0700657 public void notifyCallStateForSubscriber(int subId, int state, String incomingNumber) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700658 if (!checkNotifyPermission("notifyCallState()")) {
659 return;
660 }
Wink Savillee380b982014-07-26 18:24:22 -0700661 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700662 log("notifyCallStateForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700663 + " state=" + state + " incomingNumber=" + incomingNumber);
664 }
665 synchronized (mRecords) {
666 int phoneId = SubscriptionManager.getPhoneId(subId);
667 if (validatePhoneId(phoneId)) {
668 mCallState[phoneId] = state;
669 mCallIncomingNumber[phoneId] = incomingNumber;
670 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800671 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
xinhe43c50292014-09-18 17:56:48 -0700672 (r.subId == subId) &&
Wink Savilled09c4ca2014-11-22 10:08:16 -0800673 (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700674 try {
675 r.callback.onCallStateChanged(state, incomingNumber);
676 } catch (RemoteException ex) {
677 mRemoveList.add(r.binder);
678 }
679 }
680 }
681 }
682 handleRemoveListLocked();
683 }
684 broadcastCallStateChanged(state, incomingNumber, subId);
685 }
686
Wink Saville63f03dd2014-10-23 10:44:45 -0700687 public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700688 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700689 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700690 }
xinhe43c50292014-09-18 17:56:48 -0700691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 synchronized (mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700693 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700694 log("notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
Wink Saville47d8d1b2014-07-10 13:01:52 -0700695 + " state=" + state);
696 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700697 if (validatePhoneId(phoneId)) {
698 mServiceState[phoneId] = state;
Wink Savillebc027272014-09-08 14:50:58 -0700699 logServiceStateChanged("notifyServiceStateForSubscriber", subId, phoneId, state);
700 if (VDBG) toStringLogSSC("notifyServiceStateForSubscriber");
Wink Saville47d8d1b2014-07-10 13:01:52 -0700701
Wink Savillefb40dd42014-06-12 17:02:31 -0700702 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700703 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700704 log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700705 + " phoneId=" + phoneId + " state=" + state);
706 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800707 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
xinhe8b79fb62014-11-05 14:55:03 -0800708 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700709 try {
Wink Savillee380b982014-07-26 18:24:22 -0700710 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700711 log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700712 + " subId=" + subId + " phoneId=" + phoneId
713 + " state=" + state);
714 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700715 r.callback.onServiceStateChanged(new ServiceState(state));
716 } catch (RemoteException ex) {
717 mRemoveList.add(r.binder);
718 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400719 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700721 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700722 log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400724 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700726 broadcastServiceStateChanged(state, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 }
728
Wink Savillee9b06d72009-05-18 21:47:50 -0700729 public void notifySignalStrength(SignalStrength signalStrength) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800730 notifySignalStrengthForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
731 signalStrength);
Wink Savillefb40dd42014-06-12 17:02:31 -0700732 }
733
Wink Saville63f03dd2014-10-23 10:44:45 -0700734 public void notifySignalStrengthForSubscriber(int subId, SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700735 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700736 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700737 }
Wink Savillee380b982014-07-26 18:24:22 -0700738 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700739 log("notifySignalStrengthForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700740 + " signalStrength=" + signalStrength);
Wink Savillebc027272014-09-08 14:50:58 -0700741 toStringLogSSC("notifySignalStrengthForSubscriber");
Wink Savillefb40dd42014-06-12 17:02:31 -0700742 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700744 int phoneId = SubscriptionManager.getPhoneId(subId);
745 if (validatePhoneId(phoneId)) {
Wink Savillebc027272014-09-08 14:50:58 -0700746 if (VDBG) log("notifySignalStrengthForSubscriber: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700747 mSignalStrength[phoneId] = signalStrength;
748 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -0700749 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700750 log("notifySignalStrengthForSubscriber: r=" + r + " subId=" + subId
Wink Savillee380b982014-07-26 18:24:22 -0700751 + " phoneId=" + phoneId + " ss=" + signalStrength);
752 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800753 if (r.matchPhoneStateListenerEvent(
754 PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) &&
xinhe8b79fb62014-11-05 14:55:03 -0800755 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700756 try {
Wink Savillee380b982014-07-26 18:24:22 -0700757 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700758 log("notifySignalStrengthForSubscriber: callback.onSsS r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700759 + " subId=" + subId + " phoneId=" + phoneId
760 + " ss=" + signalStrength);
761 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700762 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
763 } catch (RemoteException ex) {
764 mRemoveList.add(r.binder);
765 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400766 }
Wink Savillea374c3d2014-11-11 11:48:04 -0800767 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) &&
xinhe8b79fb62014-11-05 14:55:03 -0800768 idMatch(r.subId, subId, phoneId)){
Wink Savillefb40dd42014-06-12 17:02:31 -0700769 try {
770 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700771 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
Wink Savillee380b982014-07-26 18:24:22 -0700772 if (DBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700773 log("notifySignalStrengthForSubscriber: callback.onSS r=" + r
Wink Savillee380b982014-07-26 18:24:22 -0700774 + " subId=" + subId + " phoneId=" + phoneId
775 + " gsmSS=" + gsmSignalStrength + " ss=" + ss);
776 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700777 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700778 } catch (RemoteException ex) {
779 mRemoveList.add(r.binder);
780 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800781 }
782 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700783 } else {
Wink Savillebc027272014-09-08 14:50:58 -0700784 log("notifySignalStrengthForSubscriber: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800785 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400786 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700788 broadcastSignalStrengthChanged(signalStrength, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789 }
790
Wink Savilleb208a242012-07-25 14:08:09 -0700791 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800792 notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo);
Wink Savillefb40dd42014-06-12 17:02:31 -0700793 }
794
Wink Saville63f03dd2014-10-23 10:44:45 -0700795 public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700796 if (!checkNotifyPermission("notifyCellInfo()")) {
797 return;
798 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700799 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700800 log("notifyCellInfoForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700801 + " cellInfo=" + cellInfo);
802 }
John Wang963db55d2012-03-30 16:04:06 -0700803
804 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700805 int phoneId = SubscriptionManager.getPhoneId(subId);
806 if (validatePhoneId(phoneId)) {
807 mCellInfo.set(phoneId, cellInfo);
808 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -0700809 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
xinhe8b79fb62014-11-05 14:55:03 -0800810 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700811 try {
812 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700813 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -0700814 }
815 r.callback.onCellInfoChanged(cellInfo);
816 } catch (RemoteException ex) {
817 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700818 }
John Wang963db55d2012-03-30 16:04:06 -0700819 }
820 }
821 }
822 handleRemoveListLocked();
823 }
824 }
825
Wink Saville070e0612014-04-15 22:04:10 -0700826 public void notifyDataConnectionRealTimeInfo(DataConnectionRealTimeInfo dcRtInfo) {
827 if (!checkNotifyPermission("notifyDataConnectionRealTimeInfo()")) {
828 return;
829 }
830
831 synchronized (mRecords) {
832 mDcRtInfo = dcRtInfo;
833 for (Record r : mRecords) {
834 if (validateEventsAndUserLocked(r,
835 PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO)) {
836 try {
837 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700838 log("notifyDataConnectionRealTimeInfo: mDcRtInfo="
Wink Saville070e0612014-04-15 22:04:10 -0700839 + mDcRtInfo + " r=" + r);
840 }
841 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
842 } catch (RemoteException ex) {
843 mRemoveList.add(r.binder);
844 }
845 }
846 }
847 handleRemoveListLocked();
848 }
849 }
850
xinhe43c50292014-09-18 17:56:48 -0700851 @Override
Wink Saville63f03dd2014-10-23 10:44:45 -0700852 public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700853 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700854 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700855 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700856 if (VDBG) {
xinhe43c50292014-09-18 17:56:48 -0700857 log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId
Wink Savillefb40dd42014-06-12 17:02:31 -0700858 + " mwi=" + mwi);
859 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800860 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700861 if (validatePhoneId(phoneId)) {
862 mMessageWaiting[phoneId] = mwi;
863 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800864 if (r.matchPhoneStateListenerEvent(
865 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -0800866 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700867 try {
868 r.callback.onMessageWaitingIndicatorChanged(mwi);
869 } catch (RemoteException ex) {
870 mRemoveList.add(r.binder);
871 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800872 }
873 }
874 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400875 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800876 }
877 }
878
879 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800880 notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi);
Wink Savillefb40dd42014-06-12 17:02:31 -0700881 }
882
Wink Saville63f03dd2014-10-23 10:44:45 -0700883 public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700884 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700885 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700886 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700887 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700888 log("notifyCallForwardingChangedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700889 + " cfi=" + cfi);
890 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700892 int phoneId = SubscriptionManager.getPhoneId(subId);
893 if (validatePhoneId(phoneId)) {
894 mCallForwarding[phoneId] = cfi;
895 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -0800896 if (r.matchPhoneStateListenerEvent(
897 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) &&
xinhe8b79fb62014-11-05 14:55:03 -0800898 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700899 try {
900 r.callback.onCallForwardingIndicatorChanged(cfi);
901 } catch (RemoteException ex) {
902 mRemoveList.add(r.binder);
903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904 }
905 }
906 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400907 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908 }
909 }
910
911 public void notifyDataActivity(int state) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800912 notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state);
Wink Savillefb40dd42014-06-12 17:02:31 -0700913 }
914
Wink Saville63f03dd2014-10-23 10:44:45 -0700915 public void notifyDataActivityForSubscriber(int subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700916 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700917 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700918 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700920 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -0800921 if (validatePhoneId(phoneId)) {
922 mDataActivity[phoneId] = state;
923 for (Record r : mRecords) {
924 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY)) {
925 try {
926 r.callback.onDataActivity(state);
927 } catch (RemoteException ex) {
928 mRemoveList.add(r.binder);
929 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 }
931 }
932 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400933 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 }
935 }
936
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700937 public void notifyDataConnection(int state, boolean isDataConnectivityPossible,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700938 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -0700939 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savilled09c4ca2014-11-22 10:08:16 -0800940 notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
xinhe43c50292014-09-18 17:56:48 -0700941 isDataConnectivityPossible,reason, apn, apnType, linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -0700942 networkCapabilities, networkType, roaming);
943 }
944
Wink Saville63f03dd2014-10-23 10:44:45 -0700945 public void notifyDataConnectionForSubscriber(int subId, int state,
Wink Savillefb40dd42014-06-12 17:02:31 -0700946 boolean isDataConnectivityPossible, String reason, String apn, String apnType,
947 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
948 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700949 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700950 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700951 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700952 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -0700953 log("notifyDataConnectionForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700954 + " state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible
955 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -0700956 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
957 + " mRecords.size()=" + mRecords.size() + " mRecords=" + mRecords);
Wink Savillec9acde92011-09-21 11:05:43 -0700958 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700960 int phoneId = SubscriptionManager.getPhoneId(subId);
Wink Savilled09c4ca2014-11-22 10:08:16 -0800961 if (validatePhoneId(phoneId)) {
962 boolean modified = false;
963 if (state == TelephonyManager.DATA_CONNECTED) {
964 if (!mConnectedApns.contains(apnType)) {
965 mConnectedApns.add(apnType);
966 if (mDataConnectionState[phoneId] != state) {
967 mDataConnectionState[phoneId] = state;
968 modified = true;
969 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800971 } else {
972 if (mConnectedApns.remove(apnType)) {
973 if (mConnectedApns.isEmpty()) {
974 mDataConnectionState[phoneId] = state;
975 modified = true;
976 } else {
977 // leave mDataConnectionState as is and
978 // send out the new status for the APN in question.
Wink Savillebaf21da2014-11-19 16:03:09 -0800979 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200980 }
981 }
Wink Savilled09c4ca2014-11-22 10:08:16 -0800982 mDataConnectionPossible[phoneId] = isDataConnectivityPossible;
983 mDataConnectionReason[phoneId] = reason;
984 mDataConnectionLinkProperties[phoneId] = linkProperties;
985 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
986 if (mDataConnectionNetworkType[phoneId] != networkType) {
987 mDataConnectionNetworkType[phoneId] = networkType;
988 // need to tell registered listeners about the new network type
989 modified = true;
990 }
991 if (modified) {
992 if (DBG) {
993 log("onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
994 + ", " + mDataConnectionNetworkType[phoneId] + ")");
995 }
996 for (Record r : mRecords) {
997 if (r.matchPhoneStateListenerEvent(
998 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) &&
999 idMatch(r.subId, subId, phoneId)) {
1000 try {
1001 log("Notify data connection state changed on sub: " +
1002 subId);
1003 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1004 mDataConnectionNetworkType[phoneId]);
1005 } catch (RemoteException ex) {
1006 mRemoveList.add(r.binder);
1007 }
1008 }
1009 }
1010 handleRemoveListLocked();
1011 }
1012 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
1013 apnType, apn, reason, linkProperties, "");
1014 for (Record r : mRecords) {
1015 if (r.matchPhoneStateListenerEvent(
1016 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
1017 try {
1018 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1019 } catch (RemoteException ex) {
1020 mRemoveList.add(r.binder);
1021 }
Wink Saville2d1ee982014-11-20 20:29:51 +00001022 }
1023 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001024 }
1025 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001026 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001027 broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -07001028 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001029 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
1030 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001031 }
1032
Robert Greenwalt02648a42010-05-18 10:52:51 -07001033 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001034 notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
xinhe43c50292014-09-18 17:56:48 -07001035 reason, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001036 }
1037
Wink Saville63f03dd2014-10-23 10:44:45 -07001038 public void notifyDataConnectionFailedForSubscriber(int subId,
Wink Savillefb40dd42014-06-12 17:02:31 -07001039 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001040 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001041 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001042 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001043 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001044 log("notifyDataConnectionFailedForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001045 + " reason=" + reason + " apnType=" + apnType);
1046 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001048 mPreciseDataConnectionState = new PreciseDataConnectionState(
1049 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
1050 apnType, "", reason, null, "");
1051 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001052 if (r.matchPhoneStateListenerEvent(
1053 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001054 try {
1055 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1056 } catch (RemoteException ex) {
1057 mRemoveList.add(r.binder);
1058 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 }
1060 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001061 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001063 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001064 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1065 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 }
1067
1068 public void notifyCellLocation(Bundle cellLocation) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001069 notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation);
Wink Savillefb40dd42014-06-12 17:02:31 -07001070 }
1071
Wink Saville63f03dd2014-10-23 10:44:45 -07001072 public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
Wink Savillebc027272014-09-08 14:50:58 -07001073 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001074 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001075 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001076 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001077 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001078 if (VDBG) {
Wink Savillebc027272014-09-08 14:50:58 -07001079 log("notifyCellLocationForSubscriber: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -07001080 + " cellLocation=" + cellLocation);
1081 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001083 int phoneId = SubscriptionManager.getPhoneId(subId);
1084 if (validatePhoneId(phoneId)) {
1085 mCellLocation[phoneId] = cellLocation;
1086 for (Record r : mRecords) {
xinhe43c50292014-09-18 17:56:48 -07001087 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
xinhe8b79fb62014-11-05 14:55:03 -08001088 idMatch(r.subId, subId, phoneId)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001089 try {
1090 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001091 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -07001092 + " r=" + r);
1093 }
1094 r.callback.onCellLocationChanged(new Bundle(cellLocation));
1095 } catch (RemoteException ex) {
1096 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -07001097 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001098 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 }
1100 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001101 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -07001102 }
1103 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104
Wink Savillefd2d0132010-10-28 14:22:26 -07001105 public void notifyOtaspChanged(int otaspMode) {
1106 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
1107 return;
1108 }
1109 synchronized (mRecords) {
1110 mOtaspMode = otaspMode;
1111 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001112 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) {
Wink Savillefd2d0132010-10-28 14:22:26 -07001113 try {
1114 r.callback.onOtaspChanged(otaspMode);
1115 } catch (RemoteException ex) {
1116 mRemoveList.add(r.binder);
1117 }
1118 }
1119 }
1120 handleRemoveListLocked();
1121 }
1122 }
1123
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001124 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
1125 int backgroundCallState) {
1126 if (!checkNotifyPermission("notifyPreciseCallState()")) {
1127 return;
1128 }
1129 synchronized (mRecords) {
1130 mRingingCallState = ringingCallState;
1131 mForegroundCallState = foregroundCallState;
1132 mBackgroundCallState = backgroundCallState;
1133 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
1134 backgroundCallState,
1135 DisconnectCause.NOT_VALID,
1136 PreciseDisconnectCause.NOT_VALID);
1137 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001138 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001139 try {
1140 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1141 } catch (RemoteException ex) {
1142 mRemoveList.add(r.binder);
1143 }
1144 }
1145 }
1146 handleRemoveListLocked();
1147 }
1148 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
1149 DisconnectCause.NOT_VALID,
1150 PreciseDisconnectCause.NOT_VALID);
1151 }
1152
1153 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
1154 if (!checkNotifyPermission("notifyDisconnectCause()")) {
1155 return;
1156 }
1157 synchronized (mRecords) {
1158 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
1159 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1160 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001161 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001162 try {
1163 r.callback.onPreciseCallStateChanged(mPreciseCallState);
1164 } catch (RemoteException ex) {
1165 mRemoveList.add(r.binder);
1166 }
1167 }
1168 }
1169 handleRemoveListLocked();
1170 }
1171 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1172 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1173 }
1174
1175 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1176 String apn, String failCause) {
1177 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1178 return;
1179 }
1180 synchronized (mRecords) {
1181 mPreciseDataConnectionState = new PreciseDataConnectionState(
1182 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1183 apnType, apn, reason, null, failCause);
1184 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001185 if (r.matchPhoneStateListenerEvent(
1186 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001187 try {
1188 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1189 } catch (RemoteException ex) {
1190 mRemoveList.add(r.binder);
1191 }
1192 }
1193 }
1194 handleRemoveListLocked();
1195 }
1196 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1197 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1198 }
1199
Wink Savillefb40dd42014-06-12 17:02:31 -07001200 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1201 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1202 return;
1203 }
1204 synchronized (mRecords) {
1205 mVoLteServiceState = lteState;
1206 for (Record r : mRecords) {
Wink Savillea374c3d2014-11-11 11:48:04 -08001207 if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001208 try {
1209 r.callback.onVoLteServiceStateChanged(
1210 new VoLteServiceState(mVoLteServiceState));
1211 } catch (RemoteException ex) {
1212 mRemoveList.add(r.binder);
1213 }
1214 }
1215 }
1216 handleRemoveListLocked();
1217 }
1218 }
1219
Wink Saville63f03dd2014-10-23 10:44:45 -07001220 public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001221 if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
1222 return;
1223 }
1224
1225 synchronized (mRecords) {
1226 for (Record r : mRecords) {
1227 if (VDBG) {
1228 log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId);
1229 }
Wink Savillea374c3d2014-11-11 11:48:04 -08001230 if ((r.matchPhoneStateListenerEvent(
1231 PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
New Author Steven Liu485f2092014-09-11 10:18:45 -05001232 ((r.subId == subId) ||
Wink Savilled09c4ca2014-11-22 10:08:16 -08001233 (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
New Author Steven Liu485f2092014-09-11 10:18:45 -05001234 try {
1235 r.callback.onOemHookRawEvent(rawData);
1236 } catch (RemoteException ex) {
1237 mRemoveList.add(r.binder);
1238 }
1239 }
1240 }
1241 handleRemoveListLocked();
1242 }
1243 }
1244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001245 @Override
1246 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1247 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1248 != PackageManager.PERMISSION_GRANTED) {
1249 pw.println("Permission Denial: can't dump telephony.registry from from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001250 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 return;
1252 }
1253 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001254 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001255 pw.println("last known state:");
Sandeep Gutta2f32ac22014-07-16 03:14:03 +05301256 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1257 pw.println(" Phone Id=" + i);
1258 pw.println(" mCallState=" + mCallState[i]);
1259 pw.println(" mCallIncomingNumber=" + mCallIncomingNumber[i]);
1260 pw.println(" mServiceState=" + mServiceState[i]);
1261 pw.println(" mSignalStrength=" + mSignalStrength[i]);
1262 pw.println(" mMessageWaiting=" + mMessageWaiting[i]);
1263 pw.println(" mCallForwarding=" + mCallForwarding[i]);
1264 pw.println(" mDataActivity=" + mDataActivity[i]);
1265 pw.println(" mDataConnectionState=" + mDataConnectionState[i]);
1266 pw.println(" mDataConnectionPossible=" + mDataConnectionPossible[i]);
1267 pw.println(" mDataConnectionReason=" + mDataConnectionReason[i]);
1268 pw.println(" mDataConnectionApn=" + mDataConnectionApn[i]);
1269 pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]);
1270 pw.println(" mDataConnectionNetworkCapabilities=" +
1271 mDataConnectionNetworkCapabilities[i]);
1272 pw.println(" mCellLocation=" + mCellLocation[i]);
1273 pw.println(" mCellInfo=" + mCellInfo.get(i));
1274 }
Wink Saville070e0612014-04-15 22:04:10 -07001275 pw.println(" mDcRtInfo=" + mDcRtInfo);
Wink Savillee9b06d72009-05-18 21:47:50 -07001276 pw.println("registrations: count=" + recordCount);
Robert Greenwalt02648a42010-05-18 10:52:51 -07001277 for (Record r : mRecords) {
Wink Savillee380b982014-07-26 18:24:22 -07001278 pw.println(" " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001279 }
1280 }
1281 }
1282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 //
1284 // the legacy intent broadcasting
1285 //
1286
Wink Saville63f03dd2014-10-23 10:44:45 -07001287 private void broadcastServiceStateChanged(ServiceState state, int subId) {
Wink Savillefb40dd42014-06-12 17:02:31 -07001288 long ident = Binder.clearCallingIdentity();
1289 try {
1290 mBatteryStats.notePhoneState(state.getState());
1291 } catch (RemoteException re) {
1292 // Can't do much
1293 } finally {
1294 Binder.restoreCallingIdentity(ident);
1295 }
1296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001297 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
1298 Bundle data = new Bundle();
1299 state.fillInNotifierBundle(data);
1300 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001301 // Pass the subscription along with the intent.
1302 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001303 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001304 }
1305
Wink Saville63f03dd2014-10-23 10:44:45 -07001306 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001307 long ident = Binder.clearCallingIdentity();
1308 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001309 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001310 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001311 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001312 } finally {
1313 Binder.restoreCallingIdentity(ident);
1314 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08001317 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
Wink Savillee9b06d72009-05-18 21:47:50 -07001318 Bundle data = new Bundle();
1319 signalStrength.fillInNotifierBundle(data);
1320 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001321 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001322 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001323 }
1324
Wink Saville63f03dd2014-10-23 10:44:45 -07001325 private void broadcastCallStateChanged(int state, String incomingNumber, int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001326 long ident = Binder.clearCallingIdentity();
1327 try {
1328 if (state == TelephonyManager.CALL_STATE_IDLE) {
1329 mBatteryStats.notePhoneOff();
1330 } else {
1331 mBatteryStats.notePhoneOn();
1332 }
1333 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001334 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335 } finally {
1336 Binder.restoreCallingIdentity(ident);
1337 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001339 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001340 intent.putExtra(PhoneConstants.STATE_KEY,
1341 DefaultPhoneNotifier.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001342 if (!TextUtils.isEmpty(incomingNumber)) {
1343 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1344 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001345 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001346 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1347 android.Manifest.permission.READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348 }
1349
Robert Greenwalt42acef32009-08-12 16:08:25 -07001350 private void broadcastDataConnectionStateChanged(int state,
1351 boolean isDataConnectivityPossible,
Wink Savillef61101f2010-09-16 16:36:42 -07001352 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Saville63f03dd2014-10-23 10:44:45 -07001353 NetworkCapabilities networkCapabilities, boolean roaming, int subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001354 // Note: not reporting to the battery stats service here, because the
1355 // status bar takes care of that after taking into account all of the
1356 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001357 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001358 intent.putExtra(PhoneConstants.STATE_KEY,
1359 DefaultPhoneNotifier.convertDataState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001360 if (!isDataConnectivityPossible) {
Wink Savillea639b312012-07-10 12:37:54 -07001361 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001362 }
1363 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001364 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001366 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001367 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001368 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001369 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001370 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001371 }
1372 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001373 if (networkCapabilities != null) {
1374 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001375 }
Wink Savillea639b312012-07-10 12:37:54 -07001376 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001377
Wink Savillea639b312012-07-10 12:37:54 -07001378 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1379 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001380 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001381 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 }
1383
Wink Savillefb40dd42014-06-12 17:02:31 -07001384 private void broadcastDataConnectionFailed(String reason, String apnType,
Wink Saville63f03dd2014-10-23 10:44:45 -07001385 int subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001386 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001387 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1388 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001389 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001390 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001391 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001392
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001393 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1394 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1395 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1396 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1397 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1398 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1399 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1400 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1401 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1402 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1403 }
1404
1405 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
Wink Savilled09c4ca2014-11-22 10:08:16 -08001406 String apnType, String apn, String reason, LinkProperties linkProperties,
1407 String failCause) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001408 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1409 intent.putExtra(PhoneConstants.STATE_KEY, state);
1410 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1411 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1412 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1413 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
Wink Savilled09c4ca2014-11-22 10:08:16 -08001414 if (linkProperties != null) {
1415 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties);
1416 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001417 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1418
1419 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1420 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1421 }
1422
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001423 private boolean checkNotifyPermission(String method) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001424 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1425 == PackageManager.PERMISSION_GRANTED) {
1426 return true;
1427 }
1428 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001429 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001430 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001431 return false;
1432 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001433
1434 private void checkListenerPermission(int events) {
1435 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1436 mContext.enforceCallingOrSelfPermission(
1437 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1438
1439 }
1440
John Wang963db55d2012-03-30 16:04:06 -07001441 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1442 mContext.enforceCallingOrSelfPermission(
1443 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1444
1445 }
1446
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001447 if ((events & PHONE_STATE_PERMISSION_MASK) != 0) {
1448 mContext.enforceCallingOrSelfPermission(
1449 android.Manifest.permission.READ_PHONE_STATE, null);
1450 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001451
1452 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1453 mContext.enforceCallingOrSelfPermission(
1454 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1455
1456 }
New Author Steven Liu485f2092014-09-11 10:18:45 -05001457
1458 if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
1459 mContext.enforceCallingOrSelfPermission(
1460 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
1461 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001462 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001463
1464 private void handleRemoveListLocked() {
Wink Savillea374c3d2014-11-11 11:48:04 -08001465 int size = mRemoveList.size();
1466 if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size);
1467 if (size > 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -04001468 for (IBinder b: mRemoveList) {
1469 remove(b);
1470 }
1471 mRemoveList.clear();
1472 }
1473 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001474
1475 private boolean validateEventsAndUserLocked(Record r, int events) {
1476 int foregroundUser;
1477 long callingIdentity = Binder.clearCallingIdentity();
1478 boolean valid = false;
1479 try {
1480 foregroundUser = ActivityManager.getCurrentUser();
Wink Savillea374c3d2014-11-11 11:48:04 -08001481 valid = r.callerUid == foregroundUser && r.matchPhoneStateListenerEvent(events);
Wink Savillea12a7b32012-09-20 10:09:45 -07001482 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001483 log("validateEventsAndUserLocked: valid=" + valid
Wink Savillea12a7b32012-09-20 10:09:45 -07001484 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
1485 + " r.events=" + r.events + " events=" + events);
1486 }
1487 } finally {
1488 Binder.restoreCallingIdentity(callingIdentity);
1489 }
1490 return valid;
1491 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001492
1493 private boolean validatePhoneId(int phoneId) {
1494 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001495 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001496 return valid;
1497 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001498
1499 private static void log(String s) {
1500 Rlog.d(TAG, s);
1501 }
Wink Saville47d8d1b2014-07-10 13:01:52 -07001502
1503 private static class LogSSC {
1504 private Time mTime;
1505 private String mS;
Wink Saville63f03dd2014-10-23 10:44:45 -07001506 private int mSubId;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001507 private int mPhoneId;
1508 private ServiceState mState;
1509
Wink Saville63f03dd2014-10-23 10:44:45 -07001510 public void set(Time t, String s, int subId, int phoneId, ServiceState state) {
Wink Saville47d8d1b2014-07-10 13:01:52 -07001511 mTime = t; mS = s; mSubId = subId; mPhoneId = phoneId; mState = state;
1512 }
1513
1514 @Override
1515 public String toString() {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001516 return mS + " Time " + mTime.toString() + " mSubId " + mSubId + " mPhoneId "
1517 + mPhoneId + " mState " + mState;
Wink Saville47d8d1b2014-07-10 13:01:52 -07001518 }
1519 }
1520
1521 private LogSSC logSSC [] = new LogSSC[10];
1522 private int next = 0;
1523
Wink Saville63f03dd2014-10-23 10:44:45 -07001524 private void logServiceStateChanged(String s, int subId, int phoneId, ServiceState state) {
Wink Saville47d8d1b2014-07-10 13:01:52 -07001525 if (logSSC == null || logSSC.length == 0) {
1526 return;
1527 }
1528 if (logSSC[next] == null) {
1529 logSSC[next] = new LogSSC();
1530 }
1531 Time t = new Time();
1532 t.setToNow();
1533 logSSC[next].set(t, s, subId, phoneId, state);
1534 if (++next >= logSSC.length) {
1535 next = 0;
1536 }
1537 }
1538
1539 private void toStringLogSSC(String prompt) {
1540 if (logSSC == null || logSSC.length == 0 || (next == 0 && logSSC[next] == null)) {
1541 log(prompt + ": logSSC is empty");
1542 } else {
1543 // There is at least one element
1544 log(prompt + ": logSSC.length=" + logSSC.length + " next=" + next);
1545 int i = next;
1546 if (logSSC[i] == null) {
1547 // logSSC is not full so back to the beginning
1548 i = 0;
1549 }
1550 do {
1551 log(logSSC[i].toString());
1552 if (++i >= logSSC.length) {
1553 i = 0;
1554 }
1555 } while (i != next);
Wink Savillee380b982014-07-26 18:24:22 -07001556 log(prompt + ": ----------------");
Wink Saville47d8d1b2014-07-10 13:01:52 -07001557 }
1558 }
xinhee9f16402014-09-25 16:39:28 -07001559
xinhe8b79fb62014-11-05 14:55:03 -08001560 boolean idMatch(int rSubId, int subId, int phoneId) {
Wink Savilled09c4ca2014-11-22 10:08:16 -08001561 if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
xinhe8b79fb62014-11-05 14:55:03 -08001562 if(subId < 0) {
1563 // Invalid case, we need compare phoneId with default one.
1564 return (mDefaultPhoneId == phoneId);
1565 }
xinhee9f16402014-09-25 16:39:28 -07001566 return (subId == mDefaultSubId);
1567 } else {
1568 return (rSubId == subId);
1569 }
1570 }
1571
1572 private void checkPossibleMissNotify(Record r, int phoneId) {
1573 int events = r.events;
1574
1575 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
1576 try {
1577 if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" +
1578 mServiceState[phoneId]);
1579 r.callback.onServiceStateChanged(
1580 new ServiceState(mServiceState[phoneId]));
1581 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001582 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001583 }
1584 }
1585
1586 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
1587 try {
1588 SignalStrength signalStrength = mSignalStrength[phoneId];
1589 if (DBG) {
1590 log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength);
1591 }
1592 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
1593 } catch (RemoteException ex) {
1594 mRemoveList.add(r.binder);
1595 }
1596 }
1597
1598 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
1599 try {
1600 int gsmSignalStrength = mSignalStrength[phoneId]
1601 .getGsmSignalStrength();
1602 if (DBG) {
1603 log("checkPossibleMissNotify: onSignalStrengthChanged SS=" +
1604 gsmSignalStrength);
1605 }
1606 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
1607 : gsmSignalStrength));
1608 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001609 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001610 }
1611 }
1612
1613 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
1614 try {
1615 if (DBG_LOC) {
1616 log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = "
1617 + mCellInfo.get(phoneId));
1618 }
1619 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
1620 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001621 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001622 }
1623 }
1624
1625 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
1626 try {
1627 if (VDBG) {
1628 log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId="
1629 + phoneId + " mwi=" + mMessageWaiting[phoneId]);
1630 }
1631 r.callback.onMessageWaitingIndicatorChanged(
1632 mMessageWaiting[phoneId]);
1633 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001634 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001635 }
1636 }
1637
1638 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
1639 try {
1640 if (VDBG) {
1641 log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId="
1642 + phoneId + " cfi=" + mCallForwarding[phoneId]);
1643 }
1644 r.callback.onCallForwardingIndicatorChanged(
1645 mCallForwarding[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 (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
1652 try {
1653 if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = "
1654 + mCellLocation[phoneId]);
1655 r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
1656 } catch (RemoteException ex) {
1657 mRemoveList.add(r.binder);
1658 }
1659 }
1660
1661 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
1662 try {
1663 if (DBG) {
1664 log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState"
1665 + "=" + mDataConnectionState[phoneId]
1666 + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId]
1667 + ")");
1668 }
1669 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
1670 mDataConnectionNetworkType[phoneId]);
1671 } catch (RemoteException ex) {
Etan Cohena33cf072014-09-30 10:35:24 -07001672 mRemoveList.add(r.binder);
xinhee9f16402014-09-25 16:39:28 -07001673 }
1674 }
1675 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001676}