blob: 1bd837b03b7b4b93ed57e4919bfa6ed16a5a708c [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 Savillefb40dd42014-06-12 17:02:31 -070036import android.telephony.TelephonyManager;
37import android.telephony.SubscriptionManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.telephony.PhoneStateListener;
39import android.telephony.ServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -070040import android.telephony.SignalStrength;
John Wang963db55d2012-03-30 16:04:06 -070041import android.telephony.CellInfo;
Wink Savillefb40dd42014-06-12 17:02:31 -070042import android.telephony.VoLteServiceState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import android.telephony.TelephonyManager;
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;
Joe Onorato8a9b2202010-02-26 18:56:32 -080049import android.util.Slog;
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;
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 Savillefb40dd42014-06-12 17:02:31 -0700180 Slog.d(TAG, "MSG_USER_SWITCHED userId=" + msg.arg1);
181 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: {
188 Slog.d(TAG, "MSG_UPDATE_DEFAULT_SUB subid=" + mDefaultSubId);
189 // 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 Savillefb40dd42014-06-12 17:02:31 -0700209 Slog.d(TAG, "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);
212 if (DBG) Slog.d(TAG, "onReceive: userHandle=" + userHandle);
213 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 Savilleeeacf932014-06-18 01:07:10 -0700217 if (DBG) Slog.d(TAG, "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();
241 if (DBG) Slog.d(TAG, "TelephonyRegistor: ctor numPhones=" + numPhones);
242 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);
291 Slog.d(TAG, "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 Savillefb40dd42014-06-12 17:02:31 -0700311 if (VDBG) {
Wink Savillea12a7b32012-09-20 10:09:45 -0700312 Slog.d(TAG, "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 Savillefb40dd42014-06-12 17:02:31 -0700350 if (DBG) Slog.i(TAG, "listen: DEFAULT_SUB_ID");
351 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 mRecords.add(r);
Wink Savilleeeacf932014-06-18 01:07:10 -0700353 if (DBG) Slog.i(TAG, "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 Savilleeeacf932014-06-18 01:07:10 -0700357 if (DBG) Slog.i(TAG, "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 Savillefb40dd42014-06-12 17:02:31 -0700395 if (DBG_LOC) Slog.d(TAG, "listen: mCellLocation = "
396 + 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 Savillefb40dd42014-06-12 17:02:31 -0700442 if (DBG_LOC) Slog.d(TAG, "listen: mCellInfo[" + phoneId + "] = "
443 + 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 }
515 if (VDBG) {
516 Slog.d(TAG, "notifyCallStateUsingSubId: subId=" + subId
517 + " 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;
551 Slog.d(TAG, "notifyServiceStateUsingSubId: using mDefaultSubId=" + mDefaultSubId);
552 }
553 if (VDBG) {
554 Slog.d(TAG, "notifyServiceStateUsingSubId: subId=" + subId
555 + " 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) {
562 // FIXME: use DEFAULT_SUB_ID instead??
563 if (((r.events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) &&
564 (r.subId == subId)) {
565 try {
566 r.callback.onServiceStateChanged(new ServiceState(state));
567 } catch (RemoteException ex) {
568 mRemoveList.add(r.binder);
569 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400570 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700572 } else {
573 Slog.d(TAG, "notifyServiceStateUsingSubId: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400575 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700577 broadcastServiceStateChanged(state, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 }
579
Wink Savillee9b06d72009-05-18 21:47:50 -0700580 public void notifySignalStrength(SignalStrength signalStrength) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700581 notifySignalStrengthUsingSubId(mDefaultSubId, signalStrength);
582 }
583
584 public void notifySignalStrengthUsingSubId(long subId, SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700585 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700586 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700587 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700588 if (VDBG) {
589 Slog.d(TAG, "notifySignalStrengthUsingSubId: subId=" + subId
590 + " signalStrength=" + signalStrength);
591 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700593 int phoneId = SubscriptionManager.getPhoneId(subId);
594 if (validatePhoneId(phoneId)) {
595 mSignalStrength[phoneId] = signalStrength;
596 for (Record r : mRecords) {
597 if (((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) &&
598 (r.subId == subId)){
599 try {
600 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
601 } catch (RemoteException ex) {
602 mRemoveList.add(r.binder);
603 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400604 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700605 if (((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) &&
606 (r.subId == subId)) {
607 try {
608 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
609 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
610 : gsmSignalStrength));
611 } catch (RemoteException ex) {
612 mRemoveList.add(r.binder);
613 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 }
615 }
616 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400617 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700619 broadcastSignalStrengthChanged(signalStrength, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 }
621
Wink Savilleb208a242012-07-25 14:08:09 -0700622 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700623 notifyCellInfoUsingSubId(mDefaultSubId, cellInfo);
624 }
625
626 public void notifyCellInfoUsingSubId(long subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700627 if (!checkNotifyPermission("notifyCellInfo()")) {
628 return;
629 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700630 if (VDBG) {
631 Slog.d(TAG, "notifyCellInfoUsingSubId: subId=" + subId
632 + " cellInfo=" + cellInfo);
633 }
John Wang963db55d2012-03-30 16:04:06 -0700634
635 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700636 int phoneId = SubscriptionManager.getPhoneId(subId);
637 if (validatePhoneId(phoneId)) {
638 mCellInfo.set(phoneId, cellInfo);
639 for (Record r : mRecords) {
640 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)
641 && r.subId == subId) {
642 try {
643 if (DBG_LOC) {
644 Slog.d(TAG, "notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
645 }
646 r.callback.onCellInfoChanged(cellInfo);
647 } catch (RemoteException ex) {
648 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700649 }
John Wang963db55d2012-03-30 16:04:06 -0700650 }
651 }
652 }
653 handleRemoveListLocked();
654 }
655 }
656
Wink Saville070e0612014-04-15 22:04:10 -0700657 public void notifyDataConnectionRealTimeInfo(DataConnectionRealTimeInfo dcRtInfo) {
658 if (!checkNotifyPermission("notifyDataConnectionRealTimeInfo()")) {
659 return;
660 }
661
662 synchronized (mRecords) {
663 mDcRtInfo = dcRtInfo;
664 for (Record r : mRecords) {
665 if (validateEventsAndUserLocked(r,
666 PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO)) {
667 try {
668 if (DBG_LOC) {
669 Slog.d(TAG, "notifyDataConnectionRealTimeInfo: mDcRtInfo="
670 + mDcRtInfo + " r=" + r);
671 }
672 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
673 } catch (RemoteException ex) {
674 mRemoveList.add(r.binder);
675 }
676 }
677 }
678 handleRemoveListLocked();
679 }
680 }
681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 public void notifyMessageWaitingChanged(boolean mwi) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700683 notifyMessageWaitingChangedUsingSubId(mDefaultSubId, mwi);
684 }
685
686 public void notifyMessageWaitingChangedUsingSubId(long subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700687 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700688 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700689 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700690 if (VDBG) {
691 Slog.d(TAG, "notifyMessageWaitingChangedUsingSubId: subId=" + subId
692 + " mwi=" + mwi);
693 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700695 int phoneId = SubscriptionManager.getPhoneId(subId);
696 if (validatePhoneId(phoneId)) {
697 mMessageWaiting[phoneId] = mwi;
698 for (Record r : mRecords) {
699 if (((r.events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) &&
700 (r.subId == subId)) {
701 try {
702 r.callback.onMessageWaitingIndicatorChanged(mwi);
703 } catch (RemoteException ex) {
704 mRemoveList.add(r.binder);
705 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800706 }
707 }
708 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400709 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 }
711 }
712
713 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700714 notifyCallForwardingChangedUsingSubId(mDefaultSubId, cfi);
715 }
716
717 public void notifyCallForwardingChangedUsingSubId(long subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700718 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700719 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700720 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700721 if (VDBG) {
722 Slog.d(TAG, "notifyCallForwardingChangedUsingSubId: subId=" + subId
723 + " cfi=" + cfi);
724 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700726 int phoneId = SubscriptionManager.getPhoneId(subId);
727 if (validatePhoneId(phoneId)) {
728 mCallForwarding[phoneId] = cfi;
729 for (Record r : mRecords) {
730 if (((r.events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) &&
731 (r.subId == subId)) {
732 try {
733 r.callback.onCallForwardingIndicatorChanged(cfi);
734 } catch (RemoteException ex) {
735 mRemoveList.add(r.binder);
736 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 }
738 }
739 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400740 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 }
742 }
743
744 public void notifyDataActivity(int state) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700745 notifyDataActivityUsingSubId(mDefaultSubId, state);
746 }
747
748 public void notifyDataActivityUsingSubId(long subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700749 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700750 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700751 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700753 int phoneId = SubscriptionManager.getPhoneId(subId);
754 mDataActivity[phoneId] = state;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700755 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 if ((r.events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
757 try {
758 r.callback.onDataActivity(state);
759 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400760 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 }
762 }
763 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400764 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 }
766 }
767
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700768 public void notifyDataConnection(int state, boolean isDataConnectivityPossible,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700769 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -0700770 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700771 notifyDataConnectionUsingSubId(mDefaultSubId, state, isDataConnectivityPossible,
772 reason, apn, apnType, linkProperties,
773 networkCapabilities, networkType, roaming);
774 }
775
776 public void notifyDataConnectionUsingSubId(long subId, int state,
777 boolean isDataConnectivityPossible, String reason, String apn, String apnType,
778 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
779 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700780 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700781 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700782 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700783 if (VDBG) {
784 Slog.i(TAG, "notifyDataConnectionUsingSubId: subId=" + subId
785 + " state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible
786 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -0700787 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
788 + " mRecords.size()=" + mRecords.size() + " mRecords=" + mRecords);
Wink Savillec9acde92011-09-21 11:05:43 -0700789 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800790 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700791 int phoneId = SubscriptionManager.getPhoneId(subId);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700792 boolean modified = false;
793 if (state == TelephonyManager.DATA_CONNECTED) {
794 if (!mConnectedApns.contains(apnType)) {
795 mConnectedApns.add(apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -0700796 if (mDataConnectionState[phoneId] != state) {
797 mDataConnectionState[phoneId] = state;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700798 modified = true;
799 }
800 }
801 } else {
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800802 if (mConnectedApns.remove(apnType)) {
803 if (mConnectedApns.isEmpty()) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700804 mDataConnectionState[phoneId] = state;
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800805 modified = true;
806 } else {
807 // leave mDataConnectionState as is and
808 // send out the new status for the APN in question.
809 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700810 }
811 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700812 mDataConnectionPossible[phoneId] = isDataConnectivityPossible;
813 mDataConnectionReason[phoneId] = reason;
814 mDataConnectionLinkProperties[phoneId] = linkProperties;
815 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
816 if (mDataConnectionNetworkType[phoneId] != networkType) {
817 mDataConnectionNetworkType[phoneId] = networkType;
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800818 // need to tell registered listeners about the new network type
Robert Greenwalt02648a42010-05-18 10:52:51 -0700819 modified = true;
820 }
821 if (modified) {
Wink Savillec9acde92011-09-21 11:05:43 -0700822 if (DBG) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700823 Slog.d(TAG, "onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
824 + ", " + mDataConnectionNetworkType[phoneId] + ")");
Wink Savillec9acde92011-09-21 11:05:43 -0700825 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700826 for (Record r : mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700827 if (((r.events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) &&
828 (r.subId == subId)) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700829 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700830 Slog.d(TAG,"Notify data connection state changed on sub: " +
831 subId);
832 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
833 mDataConnectionNetworkType[phoneId]);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700834 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400835 mRemoveList.add(r.binder);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700836 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 }
838 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400839 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200841 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
842 apnType, apn, reason, linkProperties, "");
843 for (Record r : mRecords) {
844 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
845 try {
846 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
847 } catch (RemoteException ex) {
848 mRemoveList.add(r.binder);
849 }
850 }
851 }
852 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800853 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700854 broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -0700855 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200856 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
857 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800858 }
859
Robert Greenwalt02648a42010-05-18 10:52:51 -0700860 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700861 notifyDataConnectionFailedUsingSubId(mDefaultSubId, reason, apnType);
862 }
863
864 public void notifyDataConnectionFailedUsingSubId(long subId,
865 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700866 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700867 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700868 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700869 if (VDBG) {
870 Slog.d(TAG, "notifyDataConnectionFailedUsingSubId: subId=" + subId
871 + " reason=" + reason + " apnType=" + apnType);
872 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800873 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200874 mPreciseDataConnectionState = new PreciseDataConnectionState(
875 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
876 apnType, "", reason, null, "");
877 for (Record r : mRecords) {
878 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
879 try {
880 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
881 } catch (RemoteException ex) {
882 mRemoveList.add(r.binder);
883 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800884 }
885 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200886 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800887 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700888 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200889 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
890 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 }
892
893 public void notifyCellLocation(Bundle cellLocation) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700894 notifyCellLocationUsingSubId(mDefaultSubId, cellLocation);
895 }
896
897 public void notifyCellLocationUsingSubId(long subId, Bundle cellLocation) {
898 Slog.d(TAG, "notifyCellLocationUsingSubId: subId=" + subId
899 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700900 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700901 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700902 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700903 if (VDBG) {
904 Slog.d(TAG, "notifyCellLocationUsingSubId: subId=" + subId
905 + " cellLocation=" + cellLocation);
906 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800907 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700908 int phoneId = SubscriptionManager.getPhoneId(subId);
909 if (validatePhoneId(phoneId)) {
910 mCellLocation[phoneId] = cellLocation;
911 for (Record r : mRecords) {
912 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)
913 && r.subId == subId) {
914 try {
915 if (DBG_LOC) {
916 Slog.d(TAG, "notifyCellLocation: cellLocation=" + cellLocation
917 + " r=" + r);
918 }
919 r.callback.onCellLocationChanged(new Bundle(cellLocation));
920 } catch (RemoteException ex) {
921 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700922 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400923 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 }
925 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400926 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -0700927 }
928 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929
Wink Savillefd2d0132010-10-28 14:22:26 -0700930 public void notifyOtaspChanged(int otaspMode) {
931 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
932 return;
933 }
934 synchronized (mRecords) {
935 mOtaspMode = otaspMode;
936 for (Record r : mRecords) {
937 if ((r.events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
938 try {
939 r.callback.onOtaspChanged(otaspMode);
940 } catch (RemoteException ex) {
941 mRemoveList.add(r.binder);
942 }
943 }
944 }
945 handleRemoveListLocked();
946 }
947 }
948
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200949 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
950 int backgroundCallState) {
951 if (!checkNotifyPermission("notifyPreciseCallState()")) {
952 return;
953 }
954 synchronized (mRecords) {
955 mRingingCallState = ringingCallState;
956 mForegroundCallState = foregroundCallState;
957 mBackgroundCallState = backgroundCallState;
958 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
959 backgroundCallState,
960 DisconnectCause.NOT_VALID,
961 PreciseDisconnectCause.NOT_VALID);
962 for (Record r : mRecords) {
963 if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
964 try {
965 r.callback.onPreciseCallStateChanged(mPreciseCallState);
966 } catch (RemoteException ex) {
967 mRemoveList.add(r.binder);
968 }
969 }
970 }
971 handleRemoveListLocked();
972 }
973 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
974 DisconnectCause.NOT_VALID,
975 PreciseDisconnectCause.NOT_VALID);
976 }
977
978 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
979 if (!checkNotifyPermission("notifyDisconnectCause()")) {
980 return;
981 }
982 synchronized (mRecords) {
983 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
984 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
985 for (Record r : mRecords) {
986 if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
987 try {
988 r.callback.onPreciseCallStateChanged(mPreciseCallState);
989 } catch (RemoteException ex) {
990 mRemoveList.add(r.binder);
991 }
992 }
993 }
994 handleRemoveListLocked();
995 }
996 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
997 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
998 }
999
1000 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
1001 String apn, String failCause) {
1002 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1003 return;
1004 }
1005 synchronized (mRecords) {
1006 mPreciseDataConnectionState = new PreciseDataConnectionState(
1007 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1008 apnType, apn, reason, null, failCause);
1009 for (Record r : mRecords) {
1010 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
1011 try {
1012 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1013 } catch (RemoteException ex) {
1014 mRemoveList.add(r.binder);
1015 }
1016 }
1017 }
1018 handleRemoveListLocked();
1019 }
1020 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1021 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1022 }
1023
Wink Savillefb40dd42014-06-12 17:02:31 -07001024 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1025 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1026 return;
1027 }
1028 synchronized (mRecords) {
1029 mVoLteServiceState = lteState;
1030 for (Record r : mRecords) {
1031 if ((r.events & PhoneStateListener.LISTEN_VOLTE_STATE) != 0) {
1032 try {
1033 r.callback.onVoLteServiceStateChanged(
1034 new VoLteServiceState(mVoLteServiceState));
1035 } catch (RemoteException ex) {
1036 mRemoveList.add(r.binder);
1037 }
1038 }
1039 }
1040 handleRemoveListLocked();
1041 }
1042 }
1043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 @Override
1045 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1046 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1047 != PackageManager.PERMISSION_GRANTED) {
1048 pw.println("Permission Denial: can't dump telephony.registry from from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001049 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 return;
1051 }
1052 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001053 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 pw.println("last known state:");
1055 pw.println(" mCallState=" + mCallState);
1056 pw.println(" mCallIncomingNumber=" + mCallIncomingNumber);
1057 pw.println(" mServiceState=" + mServiceState);
1058 pw.println(" mSignalStrength=" + mSignalStrength);
1059 pw.println(" mMessageWaiting=" + mMessageWaiting);
1060 pw.println(" mCallForwarding=" + mCallForwarding);
1061 pw.println(" mDataActivity=" + mDataActivity);
1062 pw.println(" mDataConnectionState=" + mDataConnectionState);
1063 pw.println(" mDataConnectionPossible=" + mDataConnectionPossible);
1064 pw.println(" mDataConnectionReason=" + mDataConnectionReason);
1065 pw.println(" mDataConnectionApn=" + mDataConnectionApn);
Wink Savillef61101f2010-09-16 16:36:42 -07001066 pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties);
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001067 pw.println(" mDataConnectionNetworkCapabilities=" +
1068 mDataConnectionNetworkCapabilities);
Wink Savilleeeacf932014-06-18 01:07:10 -07001069 pw.println(" mDefaultSubId=" + mDefaultSubId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070 pw.println(" mCellLocation=" + mCellLocation);
John Wang963db55d2012-03-30 16:04:06 -07001071 pw.println(" mCellInfo=" + mCellInfo);
Wink Saville070e0612014-04-15 22:04:10 -07001072 pw.println(" mDcRtInfo=" + mDcRtInfo);
Wink Savillee9b06d72009-05-18 21:47:50 -07001073 pw.println("registrations: count=" + recordCount);
Robert Greenwalt02648a42010-05-18 10:52:51 -07001074 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001075 pw.println(" " + r.pkgForDebug + " 0x" + Integer.toHexString(r.events));
1076 }
1077 }
1078 }
1079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 //
1081 // the legacy intent broadcasting
1082 //
1083
Wink Savillefb40dd42014-06-12 17:02:31 -07001084 private void broadcastServiceStateChanged(ServiceState state, long subId) {
1085 long ident = Binder.clearCallingIdentity();
1086 try {
1087 mBatteryStats.notePhoneState(state.getState());
1088 } catch (RemoteException re) {
1089 // Can't do much
1090 } finally {
1091 Binder.restoreCallingIdentity(ident);
1092 }
1093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
1095 Bundle data = new Bundle();
1096 state.fillInNotifierBundle(data);
1097 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001098 // Pass the subscription along with the intent.
1099 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001100 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 }
1102
Wink Savillefb40dd42014-06-12 17:02:31 -07001103 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, long subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001104 long ident = Binder.clearCallingIdentity();
1105 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001106 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001107 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001108 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001109 } finally {
1110 Binder.restoreCallingIdentity(ident);
1111 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08001114 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
Wink Savillee9b06d72009-05-18 21:47:50 -07001115 Bundle data = new Bundle();
1116 signalStrength.fillInNotifierBundle(data);
1117 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001118 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001119 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 }
1121
Wink Savillefb40dd42014-06-12 17:02:31 -07001122 private void broadcastCallStateChanged(int state, String incomingNumber, long subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001123 long ident = Binder.clearCallingIdentity();
1124 try {
1125 if (state == TelephonyManager.CALL_STATE_IDLE) {
1126 mBatteryStats.notePhoneOff();
1127 } else {
1128 mBatteryStats.notePhoneOn();
1129 }
1130 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001131 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 } finally {
1133 Binder.restoreCallingIdentity(ident);
1134 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001137 intent.putExtra(PhoneConstants.STATE_KEY,
1138 DefaultPhoneNotifier.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 if (!TextUtils.isEmpty(incomingNumber)) {
1140 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1141 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001142 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001143 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1144 android.Manifest.permission.READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 }
1146
Robert Greenwalt42acef32009-08-12 16:08:25 -07001147 private void broadcastDataConnectionStateChanged(int state,
1148 boolean isDataConnectivityPossible,
Wink Savillef61101f2010-09-16 16:36:42 -07001149 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001150 NetworkCapabilities networkCapabilities, boolean roaming, long subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001151 // Note: not reporting to the battery stats service here, because the
1152 // status bar takes care of that after taking into account all of the
1153 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001155 intent.putExtra(PhoneConstants.STATE_KEY,
1156 DefaultPhoneNotifier.convertDataState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001157 if (!isDataConnectivityPossible) {
Wink Savillea639b312012-07-10 12:37:54 -07001158 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 }
1160 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001161 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001162 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001163 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001164 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001165 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001166 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001167 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001168 }
1169 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001170 if (networkCapabilities != null) {
1171 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001172 }
Wink Savillea639b312012-07-10 12:37:54 -07001173 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001174
Wink Savillea639b312012-07-10 12:37:54 -07001175 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1176 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001177 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001178 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 }
1180
Wink Savillefb40dd42014-06-12 17:02:31 -07001181 private void broadcastDataConnectionFailed(String reason, String apnType,
1182 long subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001184 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
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 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001189
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001190 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1191 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1192 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1193 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1194 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1195 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1196 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1197 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1198 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1199 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1200 }
1201
1202 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
1203 String apnType, String apn, String reason, LinkProperties linkProperties, String failCause) {
1204 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1205 intent.putExtra(PhoneConstants.STATE_KEY, state);
1206 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1207 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1208 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1209 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1210 if (linkProperties != null) intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
1211 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1212
1213 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1214 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1215 }
1216
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001217 private boolean checkNotifyPermission(String method) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001218 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1219 == PackageManager.PERMISSION_GRANTED) {
1220 return true;
1221 }
1222 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001223 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillec9acde92011-09-21 11:05:43 -07001224 if (DBG) Slog.w(TAG, msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001225 return false;
1226 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001227
1228 private void checkListenerPermission(int events) {
1229 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1230 mContext.enforceCallingOrSelfPermission(
1231 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1232
1233 }
1234
John Wang963db55d2012-03-30 16:04:06 -07001235 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1236 mContext.enforceCallingOrSelfPermission(
1237 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1238
1239 }
1240
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001241 if ((events & PHONE_STATE_PERMISSION_MASK) != 0) {
1242 mContext.enforceCallingOrSelfPermission(
1243 android.Manifest.permission.READ_PHONE_STATE, null);
1244 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001245
1246 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1247 mContext.enforceCallingOrSelfPermission(
1248 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1249
1250 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001251 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001252
1253 private void handleRemoveListLocked() {
1254 if (mRemoveList.size() > 0) {
1255 for (IBinder b: mRemoveList) {
1256 remove(b);
1257 }
1258 mRemoveList.clear();
1259 }
1260 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001261
1262 private boolean validateEventsAndUserLocked(Record r, int events) {
1263 int foregroundUser;
1264 long callingIdentity = Binder.clearCallingIdentity();
1265 boolean valid = false;
1266 try {
1267 foregroundUser = ActivityManager.getCurrentUser();
1268 valid = r.callerUid == foregroundUser && (r.events & events) != 0;
1269 if (DBG | DBG_LOC) {
1270 Slog.d(TAG, "validateEventsAndUserLocked: valid=" + valid
1271 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
1272 + " r.events=" + r.events + " events=" + events);
1273 }
1274 } finally {
1275 Binder.restoreCallingIdentity(callingIdentity);
1276 }
1277 return valid;
1278 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001279
1280 private boolean validatePhoneId(int phoneId) {
1281 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
1282 if (VDBG) Slog.d(TAG, "validatePhoneId: " + valid);
1283 return valid;
1284 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285}