blob: b9467f1e9519e96152e898668d8c898fb232edcb [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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import android.telephony.TelephonyManager;
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +020045import android.telephony.DisconnectCause;
46import android.telephony.PreciseCallState;
47import android.telephony.PreciseDataConnectionState;
48import android.telephony.PreciseDisconnectCause;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.text.TextUtils;
50
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;
57import com.android.internal.telephony.ITelephonyRegistry;
58import com.android.internal.telephony.IPhoneStateListener;
59import com.android.internal.telephony.DefaultPhoneNotifier;
Wink Savillea639b312012-07-10 12:37:54 -070060import com.android.internal.telephony.PhoneConstants;
Wink Savillec9330dd2011-01-12 13:37:38 -080061import com.android.internal.telephony.ServiceStateTracker;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062import com.android.internal.telephony.TelephonyIntents;
63import com.android.server.am.BatteryStatsService;
64
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065/**
Wink Savillee9b06d72009-05-18 21:47:50 -070066 * Since phone process can be restarted, this class provides a centralized place
67 * that applications can register and be called back from.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 */
69class TelephonyRegistry extends ITelephonyRegistry.Stub {
70 private static final String TAG = "TelephonyRegistry";
Wink Savillefb40dd42014-06-12 17:02:31 -070071 private static final boolean DBG = false; // STOPSHIP if true
72 private static final boolean DBG_LOC = false; // STOPSHIP if true
73 private static final boolean VDBG = false; // STOPSHIP if true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074
75 private static class Record {
76 String pkgForDebug;
Wink Savillee9b06d72009-05-18 21:47:50 -070077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 IPhoneStateListener callback;
Wink Savillee9b06d72009-05-18 21:47:50 -070081
Wink Savillea12a7b32012-09-20 10:09:45 -070082 int callerUid;
83
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -070085
Wink Savillefb40dd42014-06-12 17:02:31 -070086 long subId;
87
88 boolean isLegacyApp;
89
Wink Savillea12a7b32012-09-20 10:09:45 -070090 @Override
91 public String toString() {
Wink Savilleeeacf932014-06-18 01:07:10 -070092 return "{pkgForDebug=" + pkgForDebug + " callerUid=" + callerUid + " subId=" + subId +
Wink Savillea12a7b32012-09-20 10:09:45 -070093 " events=" + Integer.toHexString(events) + "}";
94 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 }
96
97 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -070098
Joe Onorato163d8d92010-10-21 13:21:20 -040099 // access should be inside synchronized (mRecords) for these two fields
100 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
101 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -0700102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 private final IBatteryStats mBatteryStats;
104
Wink Savillefb40dd42014-06-12 17:02:31 -0700105 private int mNumPhones;
Wink Savillee9b06d72009-05-18 21:47:50 -0700106
Wink Savillefb40dd42014-06-12 17:02:31 -0700107 private int[] mCallState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700108
Wink Savillefb40dd42014-06-12 17:02:31 -0700109 private String[] mCallIncomingNumber;
Wink Savillee9b06d72009-05-18 21:47:50 -0700110
Wink Savillefb40dd42014-06-12 17:02:31 -0700111 private ServiceState[] mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700112
Wink Savillefb40dd42014-06-12 17:02:31 -0700113 private SignalStrength[] mSignalStrength;
Wink Savillee9b06d72009-05-18 21:47:50 -0700114
Wink Savillefb40dd42014-06-12 17:02:31 -0700115 private boolean[] mMessageWaiting;
Wink Savillee9b06d72009-05-18 21:47:50 -0700116
Wink Savillefb40dd42014-06-12 17:02:31 -0700117 private boolean[] mCallForwarding;
Wink Savillee9b06d72009-05-18 21:47:50 -0700118
Wink Savillefb40dd42014-06-12 17:02:31 -0700119 private int[] mDataActivity;
Wink Savillee9b06d72009-05-18 21:47:50 -0700120
Wink Savillefb40dd42014-06-12 17:02:31 -0700121 private int[] mDataConnectionState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700122
Wink Savillefb40dd42014-06-12 17:02:31 -0700123 private boolean[] mDataConnectionPossible;
Wink Savillee9b06d72009-05-18 21:47:50 -0700124
Wink Savillefb40dd42014-06-12 17:02:31 -0700125 private String[] mDataConnectionReason;
126
127 private String[] mDataConnectionApn;
Wink Savillee9b06d72009-05-18 21:47:50 -0700128
Robert Greenwalt02648a42010-05-18 10:52:51 -0700129 private ArrayList<String> mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700130
Wink Savillefb40dd42014-06-12 17:02:31 -0700131 private LinkProperties[] mDataConnectionLinkProperties;
Wink Savillef61101f2010-09-16 16:36:42 -0700132
Wink Savillefb40dd42014-06-12 17:02:31 -0700133 private NetworkCapabilities[] mDataConnectionNetworkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700134
Wink Savillefb40dd42014-06-12 17:02:31 -0700135 private Bundle[] mCellLocation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136
Wink Savillefb40dd42014-06-12 17:02:31 -0700137 private int[] mDataConnectionNetworkType;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700138
Wink Savillec9330dd2011-01-12 13:37:38 -0800139 private int mOtaspMode = ServiceStateTracker.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700140
Wink Savillefb40dd42014-06-12 17:02:31 -0700141 private ArrayList<List<CellInfo>> mCellInfo = null;
142
143 private VoLteServiceState mVoLteServiceState = new VoLteServiceState();
144
145 private long mDefaultSubId;
John Wang963db55d2012-03-30 16:04:06 -0700146
Wink Saville070e0612014-04-15 22:04:10 -0700147 private DataConnectionRealTimeInfo mDcRtInfo = new DataConnectionRealTimeInfo();
148
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200149 private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
150
151 private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
152
153 private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
154
155 private PreciseCallState mPreciseCallState = new PreciseCallState();
156
157 private PreciseDataConnectionState mPreciseDataConnectionState =
158 new PreciseDataConnectionState();
159
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700160 static final int PHONE_STATE_PERMISSION_MASK =
161 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
162 PhoneStateListener.LISTEN_CALL_STATE |
163 PhoneStateListener.LISTEN_DATA_ACTIVITY |
164 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
Wink Savillefb40dd42014-06-12 17:02:31 -0700165 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
166 PhoneStateListener.LISTEN_VOLTE_STATE;;
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700167
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200168 static final int PRECISE_PHONE_STATE_PERMISSION_MASK =
169 PhoneStateListener.LISTEN_PRECISE_CALL_STATE |
170 PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE;
171
Wink Savillea12a7b32012-09-20 10:09:45 -0700172 private static final int MSG_USER_SWITCHED = 1;
Wink Savillefb40dd42014-06-12 17:02:31 -0700173 private static final int MSG_UPDATE_DEFAULT_SUB = 2;
Wink Savillea12a7b32012-09-20 10:09:45 -0700174
175 private final Handler mHandler = new Handler() {
176 @Override
177 public void handleMessage(Message msg) {
178 switch (msg.what) {
179 case MSG_USER_SWITCHED: {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700180 log("MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillefb40dd42014-06-12 17:02:31 -0700181 int numPhones = TelephonyManager.getDefault().getPhoneCount();
182 for (int sub = 0; sub < numPhones; sub++) {
183 TelephonyRegistry.this.notifyCellLocationUsingSubId(sub, mCellLocation[sub]);
184 }
185 break;
186 }
187 case MSG_UPDATE_DEFAULT_SUB: {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700188 log("MSG_UPDATE_DEFAULT_SUB subid=" + mDefaultSubId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700189 // Default subscription id changed, update the changed default subscription
190 // id in all the legacy application listener records.
191 synchronized (mRecords) {
192 for (Record r : mRecords) {
193 // FIXME: Be sure we're using isLegacyApp correctly!
194 if (r.isLegacyApp == true) {
195 r.subId = mDefaultSubId;
196 }
197 }
198 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700199 break;
200 }
201 }
202 }
203 };
204
205 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
206 @Override
207 public void onReceive(Context context, Intent intent) {
208 String action = intent.getAction();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700209 log("mBroadcastReceiver: action=" + action);
Wink Savillea12a7b32012-09-20 10:09:45 -0700210 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Wink Savilleeeacf932014-06-18 01:07:10 -0700211 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700212 if (DBG) log("onReceive: userHandle=" + userHandle);
Wink Savilleeeacf932014-06-18 01:07:10 -0700213 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700214 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
215 mDefaultSubId = intent.getLongExtra(PhoneConstants.SUBSCRIPTION_KEY,
216 SubscriptionManager.getDefaultSubId());
Wink Savillef4cd25b2014-07-08 19:03:20 -0700217 if (DBG) log("onReceive: mDefaultSubId=" + mDefaultSubId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700218 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB, 0, 0));
Wink Savillea12a7b32012-09-20 10:09:45 -0700219 }
220 }
221 };
222
Wink Savillee9b06d72009-05-18 21:47:50 -0700223 // we keep a copy of all of the state so we can send it out when folks
224 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700226 // In these calls we call with the lock held. This is safe becasuse remote
227 // calls go through a oneway interface and local calls going through a
228 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229
230 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700231 CellLocation location = CellLocation.getEmpty();
232
Wink Savillefb40dd42014-06-12 17:02:31 -0700233 mContext = context;
234 mBatteryStats = BatteryStatsService.getService();
235 mConnectedApns = new ArrayList<String>();
236
237 // Initialize default subscription to be used for single standby.
238 mDefaultSubId = SubscriptionManager.getDefaultSubId();
239
240 int numPhones = TelephonyManager.getDefault().getPhoneCount();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700241 if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
Wink Savillefb40dd42014-06-12 17:02:31 -0700242 mNumPhones = numPhones;
243 mCallState = new int[numPhones];
244 mDataActivity = new int[numPhones];
245 mDataConnectionState = new int[numPhones];
246 mDataConnectionNetworkType = new int[numPhones];
247 mCallIncomingNumber = new String[numPhones];
248 mServiceState = new ServiceState[numPhones];
249 mSignalStrength = new SignalStrength[numPhones];
250 mMessageWaiting = new boolean[numPhones];
251 mDataConnectionPossible = new boolean[numPhones];
252 mDataConnectionReason = new String[numPhones];
253 mDataConnectionApn = new String[numPhones];
254 mCallForwarding = new boolean[numPhones];
255 mCellLocation = new Bundle[numPhones];
256 mDataConnectionLinkProperties = new LinkProperties[numPhones];
257 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
258 mCellInfo = new ArrayList<List<CellInfo>>();
259 for (int i = 0; i < numPhones; i++) {
260 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
261 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
262 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
263 mCallIncomingNumber[i] = "";
264 mServiceState[i] = new ServiceState();
265 mSignalStrength[i] = new SignalStrength();
266 mMessageWaiting[i] = false;
267 mCallForwarding[i] = false;
268 mDataConnectionPossible[i] = false;
269 mDataConnectionReason[i] = "";
270 mDataConnectionApn[i] = "";
271 mCellLocation[i] = new Bundle();
272 mCellInfo.add(i, null);
273 }
274
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700275 // Note that location can be null for non-phone builds like
276 // like the generic one.
277 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700278 for (int i = 0; i < numPhones; i++) {
279 location.fillInNotifierBundle(mCellLocation[i]);
280 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700281 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700282 mConnectedApns = new ArrayList<String>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 }
284
Svetoslav Ganova0027152013-06-25 14:59:53 -0700285 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700286 // Watch for interesting updates
287 final IntentFilter filter = new IntentFilter();
288 filter.addAction(Intent.ACTION_USER_SWITCHED);
289 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700290 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700291 log("systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700292 mContext.registerReceiver(mBroadcastReceiver, filter);
293 }
294
295 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
297 boolean notifyNow) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700298 listen(pkgForDebug, callback, events, notifyNow, mDefaultSubId, true);
299 }
300
301 @Override
302 public void listenUsingSubId(long subId, String pkgForDebug, IPhoneStateListener callback,
303 int events, boolean notifyNow) {
304 listen(pkgForDebug, callback, events, notifyNow, subId, false);
305 }
306
307 private void listen(String pkgForDebug, IPhoneStateListener callback, int events,
308 boolean notifyNow, long subId, boolean isLegacyApp) {
Wink Savillea12a7b32012-09-20 10:09:45 -0700309 int callerUid = UserHandle.getCallingUserId();
310 int myUid = UserHandle.myUserId();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700311 if (true /*VDBG*/) {
312 log("listen: E pkg=" + pkgForDebug + " events=0x" + Integer.toHexString(events)
Wink Savillefb40dd42014-06-12 17:02:31 -0700313 + " notifyNow=" + notifyNow + " subId=" + subId
314 + " isLegacyApp=" + isLegacyApp
Wink Savillea12a7b32012-09-20 10:09:45 -0700315 + " myUid=" + myUid
316 + " callerUid=" + callerUid);
317 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 if (events != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700319 /* Checks permission and throws Security exception */
320 checkListenerPermission(events);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321
322 synchronized (mRecords) {
323 // register
324 Record r = null;
325 find_and_add: {
326 IBinder b = callback.asBinder();
327 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700328 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 r = mRecords.get(i);
330 if (b == r.binder) {
331 break find_and_add;
332 }
333 }
334 r = new Record();
335 r.binder = b;
336 r.callback = callback;
337 r.pkgForDebug = pkgForDebug;
Wink Savillea12a7b32012-09-20 10:09:45 -0700338 r.callerUid = callerUid;
Wink Savillefb40dd42014-06-12 17:02:31 -0700339 r.subId = subId;
340 r.isLegacyApp = isLegacyApp;
341 // Legacy applications pass invalid subId(-1), based on
342 // the received subId value update the isLegacyApp field
343 if ((r.subId <= 0) || (r.subId == SubscriptionManager.INVALID_SUB_ID)) {
344 r.subId = mDefaultSubId;
Wink Savilleeeacf932014-06-18 01:07:10 -0700345 r.isLegacyApp = true; // r.subId is to be update when default changes.
Wink Savillefb40dd42014-06-12 17:02:31 -0700346 }
347 if (r.subId == SubscriptionManager.DEFAULT_SUB_ID) {
348 r.subId = mDefaultSubId;
Wink Savilleeeacf932014-06-18 01:07:10 -0700349 r.isLegacyApp = true; // r.subId is to be update when default changes.
Wink Savillef4cd25b2014-07-08 19:03:20 -0700350 if (true/*DBG*/) log("listen: DEFAULT_SUB_ID");
Wink Savillefb40dd42014-06-12 17:02:31 -0700351 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 mRecords.add(r);
Wink Savillef4cd25b2014-07-08 19:03:20 -0700353 if (true/*DBG*/) log("listen: add new record");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700355 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 r.events = events;
Wink Savillef4cd25b2014-07-08 19:03:20 -0700357 if (true/*DBG*/) log("listen: set events record=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -0700358 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400360 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700361 r.callback.onServiceStateChanged(
362 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400363 } catch (RemoteException ex) {
364 remove(r.binder);
365 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 }
367 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
368 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700369 int gsmSignalStrength = mSignalStrength[phoneId]
370 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700371 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
372 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 } catch (RemoteException ex) {
374 remove(r.binder);
375 }
376 }
377 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
378 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700379 r.callback.onMessageWaitingIndicatorChanged(
380 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 } catch (RemoteException ex) {
382 remove(r.binder);
383 }
384 }
385 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
386 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700387 r.callback.onCallForwardingIndicatorChanged(
388 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 } catch (RemoteException ex) {
390 remove(r.binder);
391 }
392 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700393 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400394 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700395 if (DBG_LOC) log("listen: mCellLocation = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700396 + mCellLocation[phoneId]);
397 r.callback.onCellLocationChanged(
398 new Bundle(mCellLocation[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400399 } catch (RemoteException ex) {
400 remove(r.binder);
401 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 }
403 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
404 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700405 r.callback.onCallStateChanged(mCallState[phoneId],
406 mCallIncomingNumber[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 } catch (RemoteException ex) {
408 remove(r.binder);
409 }
410 }
411 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
412 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700413 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
414 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 } catch (RemoteException ex) {
416 remove(r.binder);
417 }
418 }
419 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
420 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700421 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 } catch (RemoteException ex) {
423 remove(r.binder);
424 }
425 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700426 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
427 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700428 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700429 } catch (RemoteException ex) {
430 remove(r.binder);
431 }
432 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700433 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
434 try {
435 r.callback.onOtaspChanged(mOtaspMode);
436 } catch (RemoteException ex) {
437 remove(r.binder);
438 }
439 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700440 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700441 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700442 if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = "
Wink Savillefb40dd42014-06-12 17:02:31 -0700443 + mCellInfo.get(phoneId));
444 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
John Wang963db55d2012-03-30 16:04:06 -0700445 } catch (RemoteException ex) {
446 remove(r.binder);
447 }
448 }
Wink Saville070e0612014-04-15 22:04:10 -0700449 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO) != 0) {
450 try {
451 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
452 } catch (RemoteException ex) {
453 remove(r.binder);
454 }
455 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200456 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
457 try {
458 r.callback.onPreciseCallStateChanged(mPreciseCallState);
459 } catch (RemoteException ex) {
460 remove(r.binder);
461 }
462 }
463 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
464 try {
465 r.callback.onPreciseDataConnectionStateChanged(
466 mPreciseDataConnectionState);
467 } catch (RemoteException ex) {
468 remove(r.binder);
469 }
470 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 }
472 }
473 } else {
474 remove(callback.asBinder());
475 }
476 }
477
478 private void remove(IBinder binder) {
479 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700480 final int recordCount = mRecords.size();
481 for (int i = 0; i < recordCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 if (mRecords.get(i).binder == binder) {
483 mRecords.remove(i);
484 return;
485 }
486 }
487 }
488 }
489
490 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700491 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700492 return;
493 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700495 for (Record r : mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700496 if (((r.events & PhoneStateListener.LISTEN_CALL_STATE) != 0) &&
497 (r.isLegacyApp == true)) {
498 // FIXME: why does isLegacyApp need to be true?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499 try {
500 r.callback.onCallStateChanged(state, incomingNumber);
501 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400502 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 }
504 }
505 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400506 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700508 broadcastCallStateChanged(state, incomingNumber, mDefaultSubId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 }
510
Wink Savillefb40dd42014-06-12 17:02:31 -0700511 public void notifyCallStateUsingSubId(long subId, int state, String incomingNumber) {
512 if (!checkNotifyPermission("notifyCallState()")) {
513 return;
514 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700515 if (true /*VDBG*/) {
516 log("notifyCallStateUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700517 + " state=" + state + " incomingNumber=" + incomingNumber);
518 }
519 synchronized (mRecords) {
520 int phoneId = SubscriptionManager.getPhoneId(subId);
521 if (validatePhoneId(phoneId)) {
522 mCallState[phoneId] = state;
523 mCallIncomingNumber[phoneId] = incomingNumber;
524 for (Record r : mRecords) {
525 if (((r.events & PhoneStateListener.LISTEN_CALL_STATE) != 0) &&
526 (r.subId == subId) && (r.isLegacyApp == false)) {
527 // FIXME: why isLegacyApp false?
528 try {
529 r.callback.onCallStateChanged(state, incomingNumber);
530 } catch (RemoteException ex) {
531 mRemoveList.add(r.binder);
532 }
533 }
534 }
535 }
536 handleRemoveListLocked();
537 }
538 broadcastCallStateChanged(state, incomingNumber, subId);
539 }
540
541 public void notifyServiceState(ServiceState state) {
542 notifyServiceStateUsingSubId(mDefaultSubId, state);
543 }
544
545 public void notifyServiceStateUsingSubId(long subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700546 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700547 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700548 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700549 if (subId == SubscriptionManager.DEFAULT_SUB_ID) {
550 subId = mDefaultSubId;
Wink Savillef4cd25b2014-07-08 19:03:20 -0700551 log("notifyServiceStateUsingSubId: using mDefaultSubId=" + mDefaultSubId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700552 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700553 if (true/*VDBG*/) {
554 log("notifyServiceStateUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700555 + " state=" + state);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700556 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700558 int phoneId = SubscriptionManager.getPhoneId(subId);
559 if (validatePhoneId(phoneId)) {
560 mServiceState[phoneId] = state;
561 for (Record r : mRecords) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700562 // log("notifyServiceStateUsingSubId: r.events=0x" + Integer.toHexString(r.events) + " r.subId=" + r.subId + " subId=" + subId + " state=" + state);
Wink Savillefb40dd42014-06-12 17:02:31 -0700563 // FIXME: use DEFAULT_SUB_ID instead??
564 if (((r.events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) &&
565 (r.subId == subId)) {
566 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700567 log("notifyServiceStateUsingSubId: call onSSC subId=" + subId
568 + " state=" + state);
Wink Savillefb40dd42014-06-12 17:02:31 -0700569 r.callback.onServiceStateChanged(new ServiceState(state));
570 } catch (RemoteException ex) {
571 mRemoveList.add(r.binder);
572 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400573 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700575 } else {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700576 log("notifyServiceStateUsingSubId: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400578 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700580 broadcastServiceStateChanged(state, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 }
582
Wink Savillee9b06d72009-05-18 21:47:50 -0700583 public void notifySignalStrength(SignalStrength signalStrength) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700584 notifySignalStrengthUsingSubId(mDefaultSubId, signalStrength);
585 }
586
587 public void notifySignalStrengthUsingSubId(long subId, SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700588 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700589 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700590 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700591 if (true/*VDBG*/) {
592 log("notifySignalStrengthUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700593 + " signalStrength=" + signalStrength);
594 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700596 int phoneId = SubscriptionManager.getPhoneId(subId);
597 if (validatePhoneId(phoneId)) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700598 log("notifySignalStrengthUsingSubId: valid phoneId=" + phoneId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700599 mSignalStrength[phoneId] = signalStrength;
600 for (Record r : mRecords) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700601 //log("notifySignalStrengthUsingSubId: r.events=0x" + Integer.toHexString(r.events) + " r.subId=" + r.subId + " subId=" + subId);
Wink Savillefb40dd42014-06-12 17:02:31 -0700602 if (((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) &&
603 (r.subId == subId)){
604 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700605 log("notifySignalStrengthUsingSubId: callback.onSsS ss=" + signalStrength);
Wink Savillefb40dd42014-06-12 17:02:31 -0700606 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
607 } catch (RemoteException ex) {
608 mRemoveList.add(r.binder);
609 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400610 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700611 if (((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) &&
612 (r.subId == subId)) {
613 try {
614 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
Wink Savillef4cd25b2014-07-08 19:03:20 -0700615 int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength);
616 log("notifySignalStrengthUsingSubId: callback.onSS gsmSS=" + gsmSignalStrength + " ss=" + ss);
617 r.callback.onSignalStrengthChanged(ss);
Wink Savillefb40dd42014-06-12 17:02:31 -0700618 } catch (RemoteException ex) {
619 mRemoveList.add(r.binder);
620 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 }
622 }
Wink Savillef4cd25b2014-07-08 19:03:20 -0700623 } else {
624 log("notifySignalStrengthUsingSubId: invalid phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400626 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700628 broadcastSignalStrengthChanged(signalStrength, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 }
630
Wink Savilleb208a242012-07-25 14:08:09 -0700631 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700632 notifyCellInfoUsingSubId(mDefaultSubId, cellInfo);
633 }
634
635 public void notifyCellInfoUsingSubId(long subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700636 if (!checkNotifyPermission("notifyCellInfo()")) {
637 return;
638 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700639 if (VDBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700640 log("notifyCellInfoUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700641 + " cellInfo=" + cellInfo);
642 }
John Wang963db55d2012-03-30 16:04:06 -0700643
644 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700645 int phoneId = SubscriptionManager.getPhoneId(subId);
646 if (validatePhoneId(phoneId)) {
647 mCellInfo.set(phoneId, cellInfo);
648 for (Record r : mRecords) {
649 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)
650 && r.subId == subId) {
651 try {
652 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700653 log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
Wink Savillefb40dd42014-06-12 17:02:31 -0700654 }
655 r.callback.onCellInfoChanged(cellInfo);
656 } catch (RemoteException ex) {
657 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700658 }
John Wang963db55d2012-03-30 16:04:06 -0700659 }
660 }
661 }
662 handleRemoveListLocked();
663 }
664 }
665
Wink Saville070e0612014-04-15 22:04:10 -0700666 public void notifyDataConnectionRealTimeInfo(DataConnectionRealTimeInfo dcRtInfo) {
667 if (!checkNotifyPermission("notifyDataConnectionRealTimeInfo()")) {
668 return;
669 }
670
671 synchronized (mRecords) {
672 mDcRtInfo = dcRtInfo;
673 for (Record r : mRecords) {
674 if (validateEventsAndUserLocked(r,
675 PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO)) {
676 try {
677 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700678 log("notifyDataConnectionRealTimeInfo: mDcRtInfo="
Wink Saville070e0612014-04-15 22:04:10 -0700679 + mDcRtInfo + " r=" + r);
680 }
681 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
682 } catch (RemoteException ex) {
683 mRemoveList.add(r.binder);
684 }
685 }
686 }
687 handleRemoveListLocked();
688 }
689 }
690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 public void notifyMessageWaitingChanged(boolean mwi) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700692 notifyMessageWaitingChangedUsingSubId(mDefaultSubId, mwi);
693 }
694
695 public void notifyMessageWaitingChangedUsingSubId(long subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700696 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700697 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700698 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700699 if (VDBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700700 log("notifyMessageWaitingChangedUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700701 + " mwi=" + mwi);
702 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700704 int phoneId = SubscriptionManager.getPhoneId(subId);
705 if (validatePhoneId(phoneId)) {
706 mMessageWaiting[phoneId] = mwi;
707 for (Record r : mRecords) {
708 if (((r.events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) &&
709 (r.subId == subId)) {
710 try {
711 r.callback.onMessageWaitingIndicatorChanged(mwi);
712 } catch (RemoteException ex) {
713 mRemoveList.add(r.binder);
714 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800715 }
716 }
717 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400718 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719 }
720 }
721
722 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700723 notifyCallForwardingChangedUsingSubId(mDefaultSubId, cfi);
724 }
725
726 public void notifyCallForwardingChangedUsingSubId(long subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700727 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700728 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700729 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700730 if (VDBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700731 log("notifyCallForwardingChangedUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700732 + " cfi=" + cfi);
733 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800734 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700735 int phoneId = SubscriptionManager.getPhoneId(subId);
736 if (validatePhoneId(phoneId)) {
737 mCallForwarding[phoneId] = cfi;
738 for (Record r : mRecords) {
739 if (((r.events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) &&
740 (r.subId == subId)) {
741 try {
742 r.callback.onCallForwardingIndicatorChanged(cfi);
743 } catch (RemoteException ex) {
744 mRemoveList.add(r.binder);
745 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746 }
747 }
748 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400749 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 }
751 }
752
753 public void notifyDataActivity(int state) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700754 notifyDataActivityUsingSubId(mDefaultSubId, state);
755 }
756
757 public void notifyDataActivityUsingSubId(long subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700758 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700759 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700760 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700762 int phoneId = SubscriptionManager.getPhoneId(subId);
763 mDataActivity[phoneId] = state;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700764 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 if ((r.events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
766 try {
767 r.callback.onDataActivity(state);
768 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400769 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 }
771 }
772 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400773 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 }
775 }
776
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700777 public void notifyDataConnection(int state, boolean isDataConnectivityPossible,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700778 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -0700779 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700780 notifyDataConnectionUsingSubId(mDefaultSubId, state, isDataConnectivityPossible,
781 reason, apn, apnType, linkProperties,
782 networkCapabilities, networkType, roaming);
783 }
784
785 public void notifyDataConnectionUsingSubId(long subId, int state,
786 boolean isDataConnectivityPossible, String reason, String apn, String apnType,
787 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
788 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700789 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700790 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700791 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700792 if (VDBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700793 log("notifyDataConnectionUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700794 + " state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible
795 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -0700796 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
797 + " mRecords.size()=" + mRecords.size() + " mRecords=" + mRecords);
Wink Savillec9acde92011-09-21 11:05:43 -0700798 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700800 int phoneId = SubscriptionManager.getPhoneId(subId);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700801 boolean modified = false;
802 if (state == TelephonyManager.DATA_CONNECTED) {
803 if (!mConnectedApns.contains(apnType)) {
804 mConnectedApns.add(apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -0700805 if (mDataConnectionState[phoneId] != state) {
806 mDataConnectionState[phoneId] = state;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700807 modified = true;
808 }
809 }
810 } else {
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800811 if (mConnectedApns.remove(apnType)) {
812 if (mConnectedApns.isEmpty()) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700813 mDataConnectionState[phoneId] = state;
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800814 modified = true;
815 } else {
816 // leave mDataConnectionState as is and
817 // send out the new status for the APN in question.
818 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700819 }
820 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700821 mDataConnectionPossible[phoneId] = isDataConnectivityPossible;
822 mDataConnectionReason[phoneId] = reason;
823 mDataConnectionLinkProperties[phoneId] = linkProperties;
824 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
825 if (mDataConnectionNetworkType[phoneId] != networkType) {
826 mDataConnectionNetworkType[phoneId] = networkType;
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800827 // need to tell registered listeners about the new network type
Robert Greenwalt02648a42010-05-18 10:52:51 -0700828 modified = true;
829 }
830 if (modified) {
Wink Savillec9acde92011-09-21 11:05:43 -0700831 if (DBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700832 log("onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
Wink Savillefb40dd42014-06-12 17:02:31 -0700833 + ", " + mDataConnectionNetworkType[phoneId] + ")");
Wink Savillec9acde92011-09-21 11:05:43 -0700834 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700835 for (Record r : mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700836 if (((r.events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) &&
837 (r.subId == subId)) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700838 try {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700839 log("Notify data connection state changed on sub: " +
Wink Savillefb40dd42014-06-12 17:02:31 -0700840 subId);
841 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
842 mDataConnectionNetworkType[phoneId]);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700843 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400844 mRemoveList.add(r.binder);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700845 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846 }
847 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400848 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200850 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
851 apnType, apn, reason, linkProperties, "");
852 for (Record r : mRecords) {
853 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
854 try {
855 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
856 } catch (RemoteException ex) {
857 mRemoveList.add(r.binder);
858 }
859 }
860 }
861 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800862 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700863 broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -0700864 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200865 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
866 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800867 }
868
Robert Greenwalt02648a42010-05-18 10:52:51 -0700869 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700870 notifyDataConnectionFailedUsingSubId(mDefaultSubId, reason, apnType);
871 }
872
873 public void notifyDataConnectionFailedUsingSubId(long subId,
874 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700875 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700876 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700877 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700878 if (VDBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700879 log("notifyDataConnectionFailedUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700880 + " reason=" + reason + " apnType=" + apnType);
881 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800882 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200883 mPreciseDataConnectionState = new PreciseDataConnectionState(
884 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
885 apnType, "", reason, null, "");
886 for (Record r : mRecords) {
887 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
888 try {
889 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
890 } catch (RemoteException ex) {
891 mRemoveList.add(r.binder);
892 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893 }
894 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200895 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800896 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700897 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200898 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
899 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 }
901
902 public void notifyCellLocation(Bundle cellLocation) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700903 notifyCellLocationUsingSubId(mDefaultSubId, cellLocation);
904 }
905
906 public void notifyCellLocationUsingSubId(long subId, Bundle cellLocation) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700907 log("notifyCellLocationUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700908 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700909 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700910 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700911 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700912 if (VDBG) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700913 log("notifyCellLocationUsingSubId: subId=" + subId
Wink Savillefb40dd42014-06-12 17:02:31 -0700914 + " cellLocation=" + cellLocation);
915 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700917 int phoneId = SubscriptionManager.getPhoneId(subId);
918 if (validatePhoneId(phoneId)) {
919 mCellLocation[phoneId] = cellLocation;
920 for (Record r : mRecords) {
921 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)
922 && r.subId == subId) {
923 try {
924 if (DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -0700925 log("notifyCellLocation: cellLocation=" + cellLocation
Wink Savillefb40dd42014-06-12 17:02:31 -0700926 + " r=" + r);
927 }
928 r.callback.onCellLocationChanged(new Bundle(cellLocation));
929 } catch (RemoteException ex) {
930 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700931 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400932 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 }
934 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400935 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -0700936 }
937 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938
Wink Savillefd2d0132010-10-28 14:22:26 -0700939 public void notifyOtaspChanged(int otaspMode) {
940 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
941 return;
942 }
943 synchronized (mRecords) {
944 mOtaspMode = otaspMode;
945 for (Record r : mRecords) {
946 if ((r.events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
947 try {
948 r.callback.onOtaspChanged(otaspMode);
949 } catch (RemoteException ex) {
950 mRemoveList.add(r.binder);
951 }
952 }
953 }
954 handleRemoveListLocked();
955 }
956 }
957
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200958 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
959 int backgroundCallState) {
960 if (!checkNotifyPermission("notifyPreciseCallState()")) {
961 return;
962 }
963 synchronized (mRecords) {
964 mRingingCallState = ringingCallState;
965 mForegroundCallState = foregroundCallState;
966 mBackgroundCallState = backgroundCallState;
967 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
968 backgroundCallState,
969 DisconnectCause.NOT_VALID,
970 PreciseDisconnectCause.NOT_VALID);
971 for (Record r : mRecords) {
972 if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
973 try {
974 r.callback.onPreciseCallStateChanged(mPreciseCallState);
975 } catch (RemoteException ex) {
976 mRemoveList.add(r.binder);
977 }
978 }
979 }
980 handleRemoveListLocked();
981 }
982 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
983 DisconnectCause.NOT_VALID,
984 PreciseDisconnectCause.NOT_VALID);
985 }
986
987 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
988 if (!checkNotifyPermission("notifyDisconnectCause()")) {
989 return;
990 }
991 synchronized (mRecords) {
992 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
993 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
994 for (Record r : mRecords) {
995 if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
996 try {
997 r.callback.onPreciseCallStateChanged(mPreciseCallState);
998 } catch (RemoteException ex) {
999 mRemoveList.add(r.binder);
1000 }
1001 }
1002 }
1003 handleRemoveListLocked();
1004 }
1005 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
1006 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
1007 }
1008
1009 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1010 String apn, String failCause) {
1011 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1012 return;
1013 }
1014 synchronized (mRecords) {
1015 mPreciseDataConnectionState = new PreciseDataConnectionState(
1016 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1017 apnType, apn, reason, null, failCause);
1018 for (Record r : mRecords) {
1019 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
1020 try {
1021 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1022 } catch (RemoteException ex) {
1023 mRemoveList.add(r.binder);
1024 }
1025 }
1026 }
1027 handleRemoveListLocked();
1028 }
1029 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1030 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1031 }
1032
Wink Savillefb40dd42014-06-12 17:02:31 -07001033 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1034 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1035 return;
1036 }
1037 synchronized (mRecords) {
1038 mVoLteServiceState = lteState;
1039 for (Record r : mRecords) {
1040 if ((r.events & PhoneStateListener.LISTEN_VOLTE_STATE) != 0) {
1041 try {
1042 r.callback.onVoLteServiceStateChanged(
1043 new VoLteServiceState(mVoLteServiceState));
1044 } catch (RemoteException ex) {
1045 mRemoveList.add(r.binder);
1046 }
1047 }
1048 }
1049 handleRemoveListLocked();
1050 }
1051 }
1052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 @Override
1054 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1055 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1056 != PackageManager.PERMISSION_GRANTED) {
1057 pw.println("Permission Denial: can't dump telephony.registry from from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001058 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 return;
1060 }
1061 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001062 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 pw.println("last known state:");
1064 pw.println(" mCallState=" + mCallState);
1065 pw.println(" mCallIncomingNumber=" + mCallIncomingNumber);
1066 pw.println(" mServiceState=" + mServiceState);
1067 pw.println(" mSignalStrength=" + mSignalStrength);
1068 pw.println(" mMessageWaiting=" + mMessageWaiting);
1069 pw.println(" mCallForwarding=" + mCallForwarding);
1070 pw.println(" mDataActivity=" + mDataActivity);
1071 pw.println(" mDataConnectionState=" + mDataConnectionState);
1072 pw.println(" mDataConnectionPossible=" + mDataConnectionPossible);
1073 pw.println(" mDataConnectionReason=" + mDataConnectionReason);
1074 pw.println(" mDataConnectionApn=" + mDataConnectionApn);
Wink Savillef61101f2010-09-16 16:36:42 -07001075 pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties);
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001076 pw.println(" mDataConnectionNetworkCapabilities=" +
1077 mDataConnectionNetworkCapabilities);
Wink Savilleeeacf932014-06-18 01:07:10 -07001078 pw.println(" mDefaultSubId=" + mDefaultSubId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 pw.println(" mCellLocation=" + mCellLocation);
John Wang963db55d2012-03-30 16:04:06 -07001080 pw.println(" mCellInfo=" + mCellInfo);
Wink Saville070e0612014-04-15 22:04:10 -07001081 pw.println(" mDcRtInfo=" + mDcRtInfo);
Wink Savillee9b06d72009-05-18 21:47:50 -07001082 pw.println("registrations: count=" + recordCount);
Robert Greenwalt02648a42010-05-18 10:52:51 -07001083 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 pw.println(" " + r.pkgForDebug + " 0x" + Integer.toHexString(r.events));
1085 }
1086 }
1087 }
1088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 //
1090 // the legacy intent broadcasting
1091 //
1092
Wink Savillefb40dd42014-06-12 17:02:31 -07001093 private void broadcastServiceStateChanged(ServiceState state, long subId) {
1094 long ident = Binder.clearCallingIdentity();
1095 try {
1096 mBatteryStats.notePhoneState(state.getState());
1097 } catch (RemoteException re) {
1098 // Can't do much
1099 } finally {
1100 Binder.restoreCallingIdentity(ident);
1101 }
1102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
1104 Bundle data = new Bundle();
1105 state.fillInNotifierBundle(data);
1106 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001107 // Pass the subscription along with the intent.
1108 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001109 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 }
1111
Wink Savillefb40dd42014-06-12 17:02:31 -07001112 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, long subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001113 long ident = Binder.clearCallingIdentity();
1114 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001115 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001116 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001117 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001118 } finally {
1119 Binder.restoreCallingIdentity(ident);
1120 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08001123 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
Wink Savillee9b06d72009-05-18 21:47:50 -07001124 Bundle data = new Bundle();
1125 signalStrength.fillInNotifierBundle(data);
1126 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001127 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001128 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129 }
1130
Wink Savillefb40dd42014-06-12 17:02:31 -07001131 private void broadcastCallStateChanged(int state, String incomingNumber, long subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 long ident = Binder.clearCallingIdentity();
1133 try {
1134 if (state == TelephonyManager.CALL_STATE_IDLE) {
1135 mBatteryStats.notePhoneOff();
1136 } else {
1137 mBatteryStats.notePhoneOn();
1138 }
1139 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001140 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 } finally {
1142 Binder.restoreCallingIdentity(ident);
1143 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001146 intent.putExtra(PhoneConstants.STATE_KEY,
1147 DefaultPhoneNotifier.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 if (!TextUtils.isEmpty(incomingNumber)) {
1149 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1150 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001151 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001152 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1153 android.Manifest.permission.READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 }
1155
Robert Greenwalt42acef32009-08-12 16:08:25 -07001156 private void broadcastDataConnectionStateChanged(int state,
1157 boolean isDataConnectivityPossible,
Wink Savillef61101f2010-09-16 16:36:42 -07001158 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001159 NetworkCapabilities networkCapabilities, boolean roaming, long subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001160 // Note: not reporting to the battery stats service here, because the
1161 // status bar takes care of that after taking into account all of the
1162 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001164 intent.putExtra(PhoneConstants.STATE_KEY,
1165 DefaultPhoneNotifier.convertDataState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 if (!isDataConnectivityPossible) {
Wink Savillea639b312012-07-10 12:37:54 -07001167 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 }
1169 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001170 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001172 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001173 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001174 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001175 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001176 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001177 }
1178 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001179 if (networkCapabilities != null) {
1180 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001181 }
Wink Savillea639b312012-07-10 12:37:54 -07001182 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001183
Wink Savillea639b312012-07-10 12:37:54 -07001184 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1185 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001186 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001187 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 }
1189
Wink Savillefb40dd42014-06-12 17:02:31 -07001190 private void broadcastDataConnectionFailed(String reason, String apnType,
1191 long subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001193 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1194 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001195 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001196 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001198
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001199 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1200 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1201 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1202 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1203 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1204 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1205 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1206 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1207 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1208 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1209 }
1210
1211 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
1212 String apnType, String apn, String reason, LinkProperties linkProperties, String failCause) {
1213 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1214 intent.putExtra(PhoneConstants.STATE_KEY, state);
1215 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1216 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1217 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1218 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1219 if (linkProperties != null) intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
1220 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1221
1222 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1223 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1224 }
1225
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001226 private boolean checkNotifyPermission(String method) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001227 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1228 == PackageManager.PERMISSION_GRANTED) {
1229 return true;
1230 }
1231 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001232 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillef4cd25b2014-07-08 19:03:20 -07001233 if (DBG) log(msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001234 return false;
1235 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001236
1237 private void checkListenerPermission(int events) {
1238 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1239 mContext.enforceCallingOrSelfPermission(
1240 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1241
1242 }
1243
John Wang963db55d2012-03-30 16:04:06 -07001244 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1245 mContext.enforceCallingOrSelfPermission(
1246 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1247
1248 }
1249
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001250 if ((events & PHONE_STATE_PERMISSION_MASK) != 0) {
1251 mContext.enforceCallingOrSelfPermission(
1252 android.Manifest.permission.READ_PHONE_STATE, null);
1253 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001254
1255 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1256 mContext.enforceCallingOrSelfPermission(
1257 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1258
1259 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001260 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001261
1262 private void handleRemoveListLocked() {
1263 if (mRemoveList.size() > 0) {
1264 for (IBinder b: mRemoveList) {
1265 remove(b);
1266 }
1267 mRemoveList.clear();
1268 }
1269 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001270
1271 private boolean validateEventsAndUserLocked(Record r, int events) {
1272 int foregroundUser;
1273 long callingIdentity = Binder.clearCallingIdentity();
1274 boolean valid = false;
1275 try {
1276 foregroundUser = ActivityManager.getCurrentUser();
1277 valid = r.callerUid == foregroundUser && (r.events & events) != 0;
1278 if (DBG | DBG_LOC) {
Wink Savillef4cd25b2014-07-08 19:03:20 -07001279 log("validateEventsAndUserLocked: valid=" + valid
Wink Savillea12a7b32012-09-20 10:09:45 -07001280 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
1281 + " r.events=" + r.events + " events=" + events);
1282 }
1283 } finally {
1284 Binder.restoreCallingIdentity(callingIdentity);
1285 }
1286 return valid;
1287 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001288
1289 private boolean validatePhoneId(int phoneId) {
1290 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
Wink Savillef4cd25b2014-07-08 19:03:20 -07001291 if (VDBG) log("validatePhoneId: " + valid);
Wink Savillefb40dd42014-06-12 17:02:31 -07001292 return valid;
1293 }
Wink Savillef4cd25b2014-07-08 19:03:20 -07001294
1295 private static void log(String s) {
1296 Rlog.d(TAG, s);
1297 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001298}