blob: 9d92421a6bc4e900027cef8ad328db024c87e683 [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() {
92 return "{pkgForDebug=" + pkgForDebug + " callerUid=" + callerUid +
93 " 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)) {
211 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED,
212 intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0), 0));
Wink Savillefb40dd42014-06-12 17:02:31 -0700213 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) {
214 mDefaultSubId = intent.getLongExtra(PhoneConstants.SUBSCRIPTION_KEY,
215 SubscriptionManager.getDefaultSubId());
216 mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB, 0, 0));
Wink Savillea12a7b32012-09-20 10:09:45 -0700217 }
218 }
219 };
220
Wink Savillee9b06d72009-05-18 21:47:50 -0700221 // we keep a copy of all of the state so we can send it out when folks
222 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700224 // In these calls we call with the lock held. This is safe becasuse remote
225 // calls go through a oneway interface and local calls going through a
226 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227
228 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700229 CellLocation location = CellLocation.getEmpty();
230
Wink Savillefb40dd42014-06-12 17:02:31 -0700231 mContext = context;
232 mBatteryStats = BatteryStatsService.getService();
233 mConnectedApns = new ArrayList<String>();
234
235 // Initialize default subscription to be used for single standby.
236 mDefaultSubId = SubscriptionManager.getDefaultSubId();
237
238 int numPhones = TelephonyManager.getDefault().getPhoneCount();
239 if (DBG) Slog.d(TAG, "TelephonyRegistor: ctor numPhones=" + numPhones);
240 mNumPhones = numPhones;
241 mCallState = new int[numPhones];
242 mDataActivity = new int[numPhones];
243 mDataConnectionState = new int[numPhones];
244 mDataConnectionNetworkType = new int[numPhones];
245 mCallIncomingNumber = new String[numPhones];
246 mServiceState = new ServiceState[numPhones];
247 mSignalStrength = new SignalStrength[numPhones];
248 mMessageWaiting = new boolean[numPhones];
249 mDataConnectionPossible = new boolean[numPhones];
250 mDataConnectionReason = new String[numPhones];
251 mDataConnectionApn = new String[numPhones];
252 mCallForwarding = new boolean[numPhones];
253 mCellLocation = new Bundle[numPhones];
254 mDataConnectionLinkProperties = new LinkProperties[numPhones];
255 mDataConnectionNetworkCapabilities = new NetworkCapabilities[numPhones];
256 mCellInfo = new ArrayList<List<CellInfo>>();
257 for (int i = 0; i < numPhones; i++) {
258 mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
259 mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
260 mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
261 mCallIncomingNumber[i] = "";
262 mServiceState[i] = new ServiceState();
263 mSignalStrength[i] = new SignalStrength();
264 mMessageWaiting[i] = false;
265 mCallForwarding[i] = false;
266 mDataConnectionPossible[i] = false;
267 mDataConnectionReason[i] = "";
268 mDataConnectionApn[i] = "";
269 mCellLocation[i] = new Bundle();
270 mCellInfo.add(i, null);
271 }
272
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700273 // Note that location can be null for non-phone builds like
274 // like the generic one.
275 if (location != null) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700276 for (int i = 0; i < numPhones; i++) {
277 location.fillInNotifierBundle(mCellLocation[i]);
278 }
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700279 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700280 mConnectedApns = new ArrayList<String>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 }
282
Svetoslav Ganova0027152013-06-25 14:59:53 -0700283 public void systemRunning() {
Wink Savillea12a7b32012-09-20 10:09:45 -0700284 // Watch for interesting updates
285 final IntentFilter filter = new IntentFilter();
286 filter.addAction(Intent.ACTION_USER_SWITCHED);
287 filter.addAction(Intent.ACTION_USER_REMOVED);
Wink Savillefb40dd42014-06-12 17:02:31 -0700288 filter.addAction(TelephonyIntents.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
289 Slog.d(TAG, "systemRunning register for intents");
Wink Savillea12a7b32012-09-20 10:09:45 -0700290 mContext.registerReceiver(mBroadcastReceiver, filter);
291 }
292
293 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
295 boolean notifyNow) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700296 listen(pkgForDebug, callback, events, notifyNow, mDefaultSubId, true);
297 }
298
299 @Override
300 public void listenUsingSubId(long subId, String pkgForDebug, IPhoneStateListener callback,
301 int events, boolean notifyNow) {
302 listen(pkgForDebug, callback, events, notifyNow, subId, false);
303 }
304
305 private void listen(String pkgForDebug, IPhoneStateListener callback, int events,
306 boolean notifyNow, long subId, boolean isLegacyApp) {
Wink Savillea12a7b32012-09-20 10:09:45 -0700307 int callerUid = UserHandle.getCallingUserId();
308 int myUid = UserHandle.myUserId();
Wink Savillefb40dd42014-06-12 17:02:31 -0700309 if (VDBG) {
Wink Savillea12a7b32012-09-20 10:09:45 -0700310 Slog.d(TAG, "listen: E pkg=" + pkgForDebug + " events=0x" + Integer.toHexString(events)
Wink Savillefb40dd42014-06-12 17:02:31 -0700311 + " notifyNow=" + notifyNow + " subId=" + subId
312 + " isLegacyApp=" + isLegacyApp
Wink Savillea12a7b32012-09-20 10:09:45 -0700313 + " myUid=" + myUid
314 + " callerUid=" + callerUid);
315 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 if (events != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700317 /* Checks permission and throws Security exception */
318 checkListenerPermission(events);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319
320 synchronized (mRecords) {
321 // register
322 Record r = null;
323 find_and_add: {
324 IBinder b = callback.asBinder();
325 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700326 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 r = mRecords.get(i);
328 if (b == r.binder) {
329 break find_and_add;
330 }
331 }
332 r = new Record();
333 r.binder = b;
334 r.callback = callback;
335 r.pkgForDebug = pkgForDebug;
Wink Savillea12a7b32012-09-20 10:09:45 -0700336 r.callerUid = callerUid;
Wink Savillefb40dd42014-06-12 17:02:31 -0700337 r.subId = subId;
338 r.isLegacyApp = isLegacyApp;
339 // Legacy applications pass invalid subId(-1), based on
340 // the received subId value update the isLegacyApp field
341 if ((r.subId <= 0) || (r.subId == SubscriptionManager.INVALID_SUB_ID)) {
342 r.subId = mDefaultSubId;
343 r.isLegacyApp = true; // FIXME: is this needed ??
344 }
345 if (r.subId == SubscriptionManager.DEFAULT_SUB_ID) {
346 r.subId = mDefaultSubId;
347 if (DBG) Slog.i(TAG, "listen: DEFAULT_SUB_ID");
348 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 mRecords.add(r);
Wink Savillea12a7b32012-09-20 10:09:45 -0700350 if (DBG) Slog.i(TAG, "listen: add new record=" + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700352 int phoneId = SubscriptionManager.getPhoneId(subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 int send = events & (events ^ r.events);
354 r.events = events;
Wink Savillefb40dd42014-06-12 17:02:31 -0700355 if (notifyNow && validatePhoneId(phoneId)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400357 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700358 r.callback.onServiceStateChanged(
359 new ServiceState(mServiceState[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400360 } catch (RemoteException ex) {
361 remove(r.binder);
362 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 }
364 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
365 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700366 int gsmSignalStrength = mSignalStrength[phoneId]
367 .getGsmSignalStrength();
Wink Savillee9b06d72009-05-18 21:47:50 -0700368 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
369 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 } catch (RemoteException ex) {
371 remove(r.binder);
372 }
373 }
374 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
375 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700376 r.callback.onMessageWaitingIndicatorChanged(
377 mMessageWaiting[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 } catch (RemoteException ex) {
379 remove(r.binder);
380 }
381 }
382 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
383 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700384 r.callback.onCallForwardingIndicatorChanged(
385 mCallForwarding[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 } catch (RemoteException ex) {
387 remove(r.binder);
388 }
389 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700390 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400391 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700392 if (DBG_LOC) Slog.d(TAG, "listen: mCellLocation = "
393 + mCellLocation[phoneId]);
394 r.callback.onCellLocationChanged(
395 new Bundle(mCellLocation[phoneId]));
Joe Onorato163d8d92010-10-21 13:21:20 -0400396 } catch (RemoteException ex) {
397 remove(r.binder);
398 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 }
400 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
401 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700402 r.callback.onCallStateChanged(mCallState[phoneId],
403 mCallIncomingNumber[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 } catch (RemoteException ex) {
405 remove(r.binder);
406 }
407 }
408 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
409 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700410 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
411 mDataConnectionNetworkType[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 } catch (RemoteException ex) {
413 remove(r.binder);
414 }
415 }
416 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
417 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700418 r.callback.onDataActivity(mDataActivity[phoneId]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 } catch (RemoteException ex) {
420 remove(r.binder);
421 }
422 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700423 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
424 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700425 r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
Wink Savillee9b06d72009-05-18 21:47:50 -0700426 } catch (RemoteException ex) {
427 remove(r.binder);
428 }
429 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700430 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
431 try {
432 r.callback.onOtaspChanged(mOtaspMode);
433 } catch (RemoteException ex) {
434 remove(r.binder);
435 }
436 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700437 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700438 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700439 if (DBG_LOC) Slog.d(TAG, "listen: mCellInfo[" + phoneId + "] = "
440 + mCellInfo.get(phoneId));
441 r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
John Wang963db55d2012-03-30 16:04:06 -0700442 } catch (RemoteException ex) {
443 remove(r.binder);
444 }
445 }
Wink Saville070e0612014-04-15 22:04:10 -0700446 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO) != 0) {
447 try {
448 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
449 } catch (RemoteException ex) {
450 remove(r.binder);
451 }
452 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200453 if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
454 try {
455 r.callback.onPreciseCallStateChanged(mPreciseCallState);
456 } catch (RemoteException ex) {
457 remove(r.binder);
458 }
459 }
460 if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
461 try {
462 r.callback.onPreciseDataConnectionStateChanged(
463 mPreciseDataConnectionState);
464 } catch (RemoteException ex) {
465 remove(r.binder);
466 }
467 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 }
469 }
470 } else {
471 remove(callback.asBinder());
472 }
473 }
474
475 private void remove(IBinder binder) {
476 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700477 final int recordCount = mRecords.size();
478 for (int i = 0; i < recordCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 if (mRecords.get(i).binder == binder) {
480 mRecords.remove(i);
481 return;
482 }
483 }
484 }
485 }
486
487 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700488 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700489 return;
490 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700492 for (Record r : mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700493 if (((r.events & PhoneStateListener.LISTEN_CALL_STATE) != 0) &&
494 (r.isLegacyApp == true)) {
495 // FIXME: why does isLegacyApp need to be true?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 try {
497 r.callback.onCallStateChanged(state, incomingNumber);
498 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400499 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 }
501 }
502 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400503 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700505 broadcastCallStateChanged(state, incomingNumber, mDefaultSubId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 }
507
Wink Savillefb40dd42014-06-12 17:02:31 -0700508 public void notifyCallStateUsingSubId(long subId, int state, String incomingNumber) {
509 if (!checkNotifyPermission("notifyCallState()")) {
510 return;
511 }
512 if (VDBG) {
513 Slog.d(TAG, "notifyCallStateUsingSubId: subId=" + subId
514 + " state=" + state + " incomingNumber=" + incomingNumber);
515 }
516 synchronized (mRecords) {
517 int phoneId = SubscriptionManager.getPhoneId(subId);
518 if (validatePhoneId(phoneId)) {
519 mCallState[phoneId] = state;
520 mCallIncomingNumber[phoneId] = incomingNumber;
521 for (Record r : mRecords) {
522 if (((r.events & PhoneStateListener.LISTEN_CALL_STATE) != 0) &&
523 (r.subId == subId) && (r.isLegacyApp == false)) {
524 // FIXME: why isLegacyApp false?
525 try {
526 r.callback.onCallStateChanged(state, incomingNumber);
527 } catch (RemoteException ex) {
528 mRemoveList.add(r.binder);
529 }
530 }
531 }
532 }
533 handleRemoveListLocked();
534 }
535 broadcastCallStateChanged(state, incomingNumber, subId);
536 }
537
538 public void notifyServiceState(ServiceState state) {
539 notifyServiceStateUsingSubId(mDefaultSubId, state);
540 }
541
542 public void notifyServiceStateUsingSubId(long subId, ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700543 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700544 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700545 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700546 if (subId == SubscriptionManager.DEFAULT_SUB_ID) {
547 subId = mDefaultSubId;
548 Slog.d(TAG, "notifyServiceStateUsingSubId: using mDefaultSubId=" + mDefaultSubId);
549 }
550 if (VDBG) {
551 Slog.d(TAG, "notifyServiceStateUsingSubId: subId=" + subId
552 + " state=" + state);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700553 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700555 int phoneId = SubscriptionManager.getPhoneId(subId);
556 if (validatePhoneId(phoneId)) {
557 mServiceState[phoneId] = state;
558 for (Record r : mRecords) {
559 // FIXME: use DEFAULT_SUB_ID instead??
560 if (((r.events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) &&
561 (r.subId == subId)) {
562 try {
563 r.callback.onServiceStateChanged(new ServiceState(state));
564 } catch (RemoteException ex) {
565 mRemoveList.add(r.binder);
566 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400567 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700569 } else {
570 Slog.d(TAG, "notifyServiceStateUsingSubId: INVALID phoneId=" + phoneId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400572 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700574 broadcastServiceStateChanged(state, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 }
576
Wink Savillee9b06d72009-05-18 21:47:50 -0700577 public void notifySignalStrength(SignalStrength signalStrength) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700578 notifySignalStrengthUsingSubId(mDefaultSubId, signalStrength);
579 }
580
581 public void notifySignalStrengthUsingSubId(long subId, SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700582 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700583 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700584 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700585 if (VDBG) {
586 Slog.d(TAG, "notifySignalStrengthUsingSubId: subId=" + subId
587 + " signalStrength=" + signalStrength);
588 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700590 int phoneId = SubscriptionManager.getPhoneId(subId);
591 if (validatePhoneId(phoneId)) {
592 mSignalStrength[phoneId] = signalStrength;
593 for (Record r : mRecords) {
594 if (((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) &&
595 (r.subId == subId)){
596 try {
597 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
598 } catch (RemoteException ex) {
599 mRemoveList.add(r.binder);
600 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400601 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700602 if (((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) &&
603 (r.subId == subId)) {
604 try {
605 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
606 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
607 : gsmSignalStrength));
608 } catch (RemoteException ex) {
609 mRemoveList.add(r.binder);
610 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800611 }
612 }
613 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400614 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700616 broadcastSignalStrengthChanged(signalStrength, subId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617 }
618
Wink Savilleb208a242012-07-25 14:08:09 -0700619 public void notifyCellInfo(List<CellInfo> cellInfo) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700620 notifyCellInfoUsingSubId(mDefaultSubId, cellInfo);
621 }
622
623 public void notifyCellInfoUsingSubId(long subId, List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700624 if (!checkNotifyPermission("notifyCellInfo()")) {
625 return;
626 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700627 if (VDBG) {
628 Slog.d(TAG, "notifyCellInfoUsingSubId: subId=" + subId
629 + " cellInfo=" + cellInfo);
630 }
John Wang963db55d2012-03-30 16:04:06 -0700631
632 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700633 int phoneId = SubscriptionManager.getPhoneId(subId);
634 if (validatePhoneId(phoneId)) {
635 mCellInfo.set(phoneId, cellInfo);
636 for (Record r : mRecords) {
637 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)
638 && r.subId == subId) {
639 try {
640 if (DBG_LOC) {
641 Slog.d(TAG, "notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
642 }
643 r.callback.onCellInfoChanged(cellInfo);
644 } catch (RemoteException ex) {
645 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700646 }
John Wang963db55d2012-03-30 16:04:06 -0700647 }
648 }
649 }
650 handleRemoveListLocked();
651 }
652 }
653
Wink Saville070e0612014-04-15 22:04:10 -0700654 public void notifyDataConnectionRealTimeInfo(DataConnectionRealTimeInfo dcRtInfo) {
655 if (!checkNotifyPermission("notifyDataConnectionRealTimeInfo()")) {
656 return;
657 }
658
659 synchronized (mRecords) {
660 mDcRtInfo = dcRtInfo;
661 for (Record r : mRecords) {
662 if (validateEventsAndUserLocked(r,
663 PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO)) {
664 try {
665 if (DBG_LOC) {
666 Slog.d(TAG, "notifyDataConnectionRealTimeInfo: mDcRtInfo="
667 + mDcRtInfo + " r=" + r);
668 }
669 r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo);
670 } catch (RemoteException ex) {
671 mRemoveList.add(r.binder);
672 }
673 }
674 }
675 handleRemoveListLocked();
676 }
677 }
678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 public void notifyMessageWaitingChanged(boolean mwi) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700680 notifyMessageWaitingChangedUsingSubId(mDefaultSubId, mwi);
681 }
682
683 public void notifyMessageWaitingChangedUsingSubId(long subId, boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700684 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700685 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700686 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700687 if (VDBG) {
688 Slog.d(TAG, "notifyMessageWaitingChangedUsingSubId: subId=" + subId
689 + " mwi=" + mwi);
690 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700692 int phoneId = SubscriptionManager.getPhoneId(subId);
693 if (validatePhoneId(phoneId)) {
694 mMessageWaiting[phoneId] = mwi;
695 for (Record r : mRecords) {
696 if (((r.events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) &&
697 (r.subId == subId)) {
698 try {
699 r.callback.onMessageWaitingIndicatorChanged(mwi);
700 } catch (RemoteException ex) {
701 mRemoveList.add(r.binder);
702 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 }
704 }
705 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400706 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 }
708 }
709
710 public void notifyCallForwardingChanged(boolean cfi) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700711 notifyCallForwardingChangedUsingSubId(mDefaultSubId, cfi);
712 }
713
714 public void notifyCallForwardingChangedUsingSubId(long subId, boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700715 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700716 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700717 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700718 if (VDBG) {
719 Slog.d(TAG, "notifyCallForwardingChangedUsingSubId: subId=" + subId
720 + " cfi=" + cfi);
721 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700723 int phoneId = SubscriptionManager.getPhoneId(subId);
724 if (validatePhoneId(phoneId)) {
725 mCallForwarding[phoneId] = cfi;
726 for (Record r : mRecords) {
727 if (((r.events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) &&
728 (r.subId == subId)) {
729 try {
730 r.callback.onCallForwardingIndicatorChanged(cfi);
731 } catch (RemoteException ex) {
732 mRemoveList.add(r.binder);
733 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800734 }
735 }
736 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400737 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 }
739 }
740
741 public void notifyDataActivity(int state) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700742 notifyDataActivityUsingSubId(mDefaultSubId, state);
743 }
744
745 public void notifyDataActivityUsingSubId(long subId, int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700746 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700747 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700748 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800749 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700750 int phoneId = SubscriptionManager.getPhoneId(subId);
751 mDataActivity[phoneId] = state;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700752 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 if ((r.events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
754 try {
755 r.callback.onDataActivity(state);
756 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400757 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800758 }
759 }
760 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400761 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 }
763 }
764
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700765 public void notifyDataConnection(int state, boolean isDataConnectivityPossible,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700766 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -0700767 NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700768 notifyDataConnectionUsingSubId(mDefaultSubId, state, isDataConnectivityPossible,
769 reason, apn, apnType, linkProperties,
770 networkCapabilities, networkType, roaming);
771 }
772
773 public void notifyDataConnectionUsingSubId(long subId, int state,
774 boolean isDataConnectivityPossible, String reason, String apn, String apnType,
775 LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
776 int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700777 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700778 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700779 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700780 if (VDBG) {
781 Slog.i(TAG, "notifyDataConnectionUsingSubId: subId=" + subId
782 + " state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible
783 + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -0700784 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
785 + " mRecords.size()=" + mRecords.size() + " mRecords=" + mRecords);
Wink Savillec9acde92011-09-21 11:05:43 -0700786 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700788 int phoneId = SubscriptionManager.getPhoneId(subId);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700789 boolean modified = false;
790 if (state == TelephonyManager.DATA_CONNECTED) {
791 if (!mConnectedApns.contains(apnType)) {
792 mConnectedApns.add(apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -0700793 if (mDataConnectionState[phoneId] != state) {
794 mDataConnectionState[phoneId] = state;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700795 modified = true;
796 }
797 }
798 } else {
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800799 if (mConnectedApns.remove(apnType)) {
800 if (mConnectedApns.isEmpty()) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700801 mDataConnectionState[phoneId] = state;
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800802 modified = true;
803 } else {
804 // leave mDataConnectionState as is and
805 // send out the new status for the APN in question.
806 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700807 }
808 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700809 mDataConnectionPossible[phoneId] = isDataConnectivityPossible;
810 mDataConnectionReason[phoneId] = reason;
811 mDataConnectionLinkProperties[phoneId] = linkProperties;
812 mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
813 if (mDataConnectionNetworkType[phoneId] != networkType) {
814 mDataConnectionNetworkType[phoneId] = networkType;
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800815 // need to tell registered listeners about the new network type
Robert Greenwalt02648a42010-05-18 10:52:51 -0700816 modified = true;
817 }
818 if (modified) {
Wink Savillec9acde92011-09-21 11:05:43 -0700819 if (DBG) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700820 Slog.d(TAG, "onDataConnectionStateChanged(" + mDataConnectionState[phoneId]
821 + ", " + mDataConnectionNetworkType[phoneId] + ")");
Wink Savillec9acde92011-09-21 11:05:43 -0700822 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700823 for (Record r : mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700824 if (((r.events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) &&
825 (r.subId == subId)) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700826 try {
Wink Savillefb40dd42014-06-12 17:02:31 -0700827 Slog.d(TAG,"Notify data connection state changed on sub: " +
828 subId);
829 r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId],
830 mDataConnectionNetworkType[phoneId]);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700831 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400832 mRemoveList.add(r.binder);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700833 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800834 }
835 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400836 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200838 mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType,
839 apnType, apn, reason, linkProperties, "");
840 for (Record r : mRecords) {
841 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
842 try {
843 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
844 } catch (RemoteException ex) {
845 mRemoveList.add(r.binder);
846 }
847 }
848 }
849 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700851 broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn,
Wink Savillefb40dd42014-06-12 17:02:31 -0700852 apnType, linkProperties, networkCapabilities, roaming, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200853 broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason,
854 linkProperties, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 }
856
Robert Greenwalt02648a42010-05-18 10:52:51 -0700857 public void notifyDataConnectionFailed(String reason, String apnType) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700858 notifyDataConnectionFailedUsingSubId(mDefaultSubId, reason, apnType);
859 }
860
861 public void notifyDataConnectionFailedUsingSubId(long subId,
862 String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700863 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700864 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700865 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700866 if (VDBG) {
867 Slog.d(TAG, "notifyDataConnectionFailedUsingSubId: subId=" + subId
868 + " reason=" + reason + " apnType=" + apnType);
869 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870 synchronized (mRecords) {
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200871 mPreciseDataConnectionState = new PreciseDataConnectionState(
872 TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN,
873 apnType, "", reason, null, "");
874 for (Record r : mRecords) {
875 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
876 try {
877 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
878 } catch (RemoteException ex) {
879 mRemoveList.add(r.binder);
880 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800881 }
882 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200883 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800884 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700885 broadcastDataConnectionFailed(reason, apnType, subId);
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200886 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
887 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800888 }
889
890 public void notifyCellLocation(Bundle cellLocation) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700891 notifyCellLocationUsingSubId(mDefaultSubId, cellLocation);
892 }
893
894 public void notifyCellLocationUsingSubId(long subId, Bundle cellLocation) {
895 Slog.d(TAG, "notifyCellLocationUsingSubId: subId=" + subId
896 + " cellLocation=" + cellLocation);
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700897 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700898 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700899 }
Wink Savillefb40dd42014-06-12 17:02:31 -0700900 if (VDBG) {
901 Slog.d(TAG, "notifyCellLocationUsingSubId: subId=" + subId
902 + " cellLocation=" + cellLocation);
903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904 synchronized (mRecords) {
Wink Savillefb40dd42014-06-12 17:02:31 -0700905 int phoneId = SubscriptionManager.getPhoneId(subId);
906 if (validatePhoneId(phoneId)) {
907 mCellLocation[phoneId] = cellLocation;
908 for (Record r : mRecords) {
909 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)
910 && r.subId == subId) {
911 try {
912 if (DBG_LOC) {
913 Slog.d(TAG, "notifyCellLocation: cellLocation=" + cellLocation
914 + " r=" + r);
915 }
916 r.callback.onCellLocationChanged(new Bundle(cellLocation));
917 } catch (RemoteException ex) {
918 mRemoveList.add(r.binder);
Wink Savillea12a7b32012-09-20 10:09:45 -0700919 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400920 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 }
922 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400923 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -0700924 }
925 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926
Wink Savillefd2d0132010-10-28 14:22:26 -0700927 public void notifyOtaspChanged(int otaspMode) {
928 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
929 return;
930 }
931 synchronized (mRecords) {
932 mOtaspMode = otaspMode;
933 for (Record r : mRecords) {
934 if ((r.events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
935 try {
936 r.callback.onOtaspChanged(otaspMode);
937 } catch (RemoteException ex) {
938 mRemoveList.add(r.binder);
939 }
940 }
941 }
942 handleRemoveListLocked();
943 }
944 }
945
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +0200946 public void notifyPreciseCallState(int ringingCallState, int foregroundCallState,
947 int backgroundCallState) {
948 if (!checkNotifyPermission("notifyPreciseCallState()")) {
949 return;
950 }
951 synchronized (mRecords) {
952 mRingingCallState = ringingCallState;
953 mForegroundCallState = foregroundCallState;
954 mBackgroundCallState = backgroundCallState;
955 mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState,
956 backgroundCallState,
957 DisconnectCause.NOT_VALID,
958 PreciseDisconnectCause.NOT_VALID);
959 for (Record r : mRecords) {
960 if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
961 try {
962 r.callback.onPreciseCallStateChanged(mPreciseCallState);
963 } catch (RemoteException ex) {
964 mRemoveList.add(r.binder);
965 }
966 }
967 }
968 handleRemoveListLocked();
969 }
970 broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState,
971 DisconnectCause.NOT_VALID,
972 PreciseDisconnectCause.NOT_VALID);
973 }
974
975 public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) {
976 if (!checkNotifyPermission("notifyDisconnectCause()")) {
977 return;
978 }
979 synchronized (mRecords) {
980 mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState,
981 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
982 for (Record r : mRecords) {
983 if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
984 try {
985 r.callback.onPreciseCallStateChanged(mPreciseCallState);
986 } catch (RemoteException ex) {
987 mRemoveList.add(r.binder);
988 }
989 }
990 }
991 handleRemoveListLocked();
992 }
993 broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState,
994 mBackgroundCallState, disconnectCause, preciseDisconnectCause);
995 }
996
997 public void notifyPreciseDataConnectionFailed(String reason, String apnType,
998 String apn, String failCause) {
999 if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
1000 return;
1001 }
1002 synchronized (mRecords) {
1003 mPreciseDataConnectionState = new PreciseDataConnectionState(
1004 TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
1005 apnType, apn, reason, null, failCause);
1006 for (Record r : mRecords) {
1007 if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
1008 try {
1009 r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
1010 } catch (RemoteException ex) {
1011 mRemoveList.add(r.binder);
1012 }
1013 }
1014 }
1015 handleRemoveListLocked();
1016 }
1017 broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
1018 TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
1019 }
1020
Wink Savillefb40dd42014-06-12 17:02:31 -07001021 public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
1022 if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
1023 return;
1024 }
1025 synchronized (mRecords) {
1026 mVoLteServiceState = lteState;
1027 for (Record r : mRecords) {
1028 if ((r.events & PhoneStateListener.LISTEN_VOLTE_STATE) != 0) {
1029 try {
1030 r.callback.onVoLteServiceStateChanged(
1031 new VoLteServiceState(mVoLteServiceState));
1032 } catch (RemoteException ex) {
1033 mRemoveList.add(r.binder);
1034 }
1035 }
1036 }
1037 handleRemoveListLocked();
1038 }
1039 }
1040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 @Override
1042 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1043 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1044 != PackageManager.PERMISSION_GRANTED) {
1045 pw.println("Permission Denial: can't dump telephony.registry from from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001046 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 return;
1048 }
1049 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001050 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 pw.println("last known state:");
1052 pw.println(" mCallState=" + mCallState);
1053 pw.println(" mCallIncomingNumber=" + mCallIncomingNumber);
1054 pw.println(" mServiceState=" + mServiceState);
1055 pw.println(" mSignalStrength=" + mSignalStrength);
1056 pw.println(" mMessageWaiting=" + mMessageWaiting);
1057 pw.println(" mCallForwarding=" + mCallForwarding);
1058 pw.println(" mDataActivity=" + mDataActivity);
1059 pw.println(" mDataConnectionState=" + mDataConnectionState);
1060 pw.println(" mDataConnectionPossible=" + mDataConnectionPossible);
1061 pw.println(" mDataConnectionReason=" + mDataConnectionReason);
1062 pw.println(" mDataConnectionApn=" + mDataConnectionApn);
Wink Savillef61101f2010-09-16 16:36:42 -07001063 pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties);
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001064 pw.println(" mDataConnectionNetworkCapabilities=" +
1065 mDataConnectionNetworkCapabilities);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 pw.println(" mCellLocation=" + mCellLocation);
John Wang963db55d2012-03-30 16:04:06 -07001067 pw.println(" mCellInfo=" + mCellInfo);
Wink Saville070e0612014-04-15 22:04:10 -07001068 pw.println(" mDcRtInfo=" + mDcRtInfo);
Wink Savillee9b06d72009-05-18 21:47:50 -07001069 pw.println("registrations: count=" + recordCount);
Robert Greenwalt02648a42010-05-18 10:52:51 -07001070 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 pw.println(" " + r.pkgForDebug + " 0x" + Integer.toHexString(r.events));
1072 }
1073 }
1074 }
1075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 //
1077 // the legacy intent broadcasting
1078 //
1079
Wink Savillefb40dd42014-06-12 17:02:31 -07001080 private void broadcastServiceStateChanged(ServiceState state, long subId) {
1081 long ident = Binder.clearCallingIdentity();
1082 try {
1083 mBatteryStats.notePhoneState(state.getState());
1084 } catch (RemoteException re) {
1085 // Can't do much
1086 } finally {
1087 Binder.restoreCallingIdentity(ident);
1088 }
1089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
1091 Bundle data = new Bundle();
1092 state.fillInNotifierBundle(data);
1093 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001094 // Pass the subscription along with the intent.
1095 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001096 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 }
1098
Wink Savillefb40dd42014-06-12 17:02:31 -07001099 private void broadcastSignalStrengthChanged(SignalStrength signalStrength, long subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001100 long ident = Binder.clearCallingIdentity();
1101 try {
Wink Savillee9b06d72009-05-18 21:47:50 -07001102 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001103 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001104 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -07001105 } finally {
1106 Binder.restoreCallingIdentity(ident);
1107 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08001110 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
Wink Savillee9b06d72009-05-18 21:47:50 -07001111 Bundle data = new Bundle();
1112 signalStrength.fillInNotifierBundle(data);
1113 intent.putExtras(data);
Wink Savillefb40dd42014-06-12 17:02:31 -07001114 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001115 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 }
1117
Wink Savillefb40dd42014-06-12 17:02:31 -07001118 private void broadcastCallStateChanged(int state, String incomingNumber, long subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 long ident = Binder.clearCallingIdentity();
1120 try {
1121 if (state == TelephonyManager.CALL_STATE_IDLE) {
1122 mBatteryStats.notePhoneOff();
1123 } else {
1124 mBatteryStats.notePhoneOn();
1125 }
1126 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001127 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 } finally {
1129 Binder.restoreCallingIdentity(ident);
1130 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001133 intent.putExtra(PhoneConstants.STATE_KEY,
1134 DefaultPhoneNotifier.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 if (!TextUtils.isEmpty(incomingNumber)) {
1136 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
1137 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001138 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001139 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1140 android.Manifest.permission.READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 }
1142
Robert Greenwalt42acef32009-08-12 16:08:25 -07001143 private void broadcastDataConnectionStateChanged(int state,
1144 boolean isDataConnectivityPossible,
Wink Savillef61101f2010-09-16 16:36:42 -07001145 String reason, String apn, String apnType, LinkProperties linkProperties,
Wink Savillefb40dd42014-06-12 17:02:31 -07001146 NetworkCapabilities networkCapabilities, boolean roaming, long subId) {
Dianne Hackborn627bba72009-03-24 22:32:56 -07001147 // Note: not reporting to the battery stats service here, because the
1148 // status bar takes care of that after taking into account all of the
1149 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -07001151 intent.putExtra(PhoneConstants.STATE_KEY,
1152 DefaultPhoneNotifier.convertDataState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001153 if (!isDataConnectivityPossible) {
Wink Savillea639b312012-07-10 12:37:54 -07001154 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 }
1156 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001157 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001158 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -07001159 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001160 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -07001161 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001162 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -07001163 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001164 }
1165 }
Robert Greenwaltf9cb86a2014-04-08 17:34:00 -07001166 if (networkCapabilities != null) {
1167 intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -07001168 }
Wink Savillea639b312012-07-10 12:37:54 -07001169 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -07001170
Wink Savillea639b312012-07-10 12:37:54 -07001171 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1172 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001173 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001174 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 }
1176
Wink Savillefb40dd42014-06-12 17:02:31 -07001177 private void broadcastDataConnectionFailed(String reason, String apnType,
1178 long subId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -07001180 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
1181 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Wink Savillefb40dd42014-06-12 17:02:31 -07001182 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001183 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001185
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001186 private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState,
1187 int backgroundCallState, int disconnectCause, int preciseDisconnectCause) {
1188 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED);
1189 intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState);
1190 intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState);
1191 intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState);
1192 intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause);
1193 intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause);
1194 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1195 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1196 }
1197
1198 private void broadcastPreciseDataConnectionStateChanged(int state, int networkType,
1199 String apnType, String apn, String reason, LinkProperties linkProperties, String failCause) {
1200 Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED);
1201 intent.putExtra(PhoneConstants.STATE_KEY, state);
1202 intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType);
1203 if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
1204 if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
1205 if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
1206 if (linkProperties != null) intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
1207 if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause);
1208
1209 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
1210 android.Manifest.permission.READ_PRECISE_PHONE_STATE);
1211 }
1212
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001213 private boolean checkNotifyPermission(String method) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001214 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
1215 == PackageManager.PERMISSION_GRANTED) {
1216 return true;
1217 }
1218 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -07001219 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillec9acde92011-09-21 11:05:43 -07001220 if (DBG) Slog.w(TAG, msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001221 return false;
1222 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001223
1224 private void checkListenerPermission(int events) {
1225 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
1226 mContext.enforceCallingOrSelfPermission(
1227 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1228
1229 }
1230
John Wang963db55d2012-03-30 16:04:06 -07001231 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
1232 mContext.enforceCallingOrSelfPermission(
1233 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1234
1235 }
1236
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001237 if ((events & PHONE_STATE_PERMISSION_MASK) != 0) {
1238 mContext.enforceCallingOrSelfPermission(
1239 android.Manifest.permission.READ_PHONE_STATE, null);
1240 }
Antonio Marín Cerezuelac5ac15a2013-05-27 11:36:36 +02001241
1242 if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
1243 mContext.enforceCallingOrSelfPermission(
1244 android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
1245
1246 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -07001247 }
Joe Onorato163d8d92010-10-21 13:21:20 -04001248
1249 private void handleRemoveListLocked() {
1250 if (mRemoveList.size() > 0) {
1251 for (IBinder b: mRemoveList) {
1252 remove(b);
1253 }
1254 mRemoveList.clear();
1255 }
1256 }
Wink Savillea12a7b32012-09-20 10:09:45 -07001257
1258 private boolean validateEventsAndUserLocked(Record r, int events) {
1259 int foregroundUser;
1260 long callingIdentity = Binder.clearCallingIdentity();
1261 boolean valid = false;
1262 try {
1263 foregroundUser = ActivityManager.getCurrentUser();
1264 valid = r.callerUid == foregroundUser && (r.events & events) != 0;
1265 if (DBG | DBG_LOC) {
1266 Slog.d(TAG, "validateEventsAndUserLocked: valid=" + valid
1267 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
1268 + " r.events=" + r.events + " events=" + events);
1269 }
1270 } finally {
1271 Binder.restoreCallingIdentity(callingIdentity);
1272 }
1273 return valid;
1274 }
Wink Savillefb40dd42014-06-12 17:02:31 -07001275
1276 private boolean validatePhoneId(int phoneId) {
1277 boolean valid = (phoneId >= 0) && (phoneId < mNumPhones);
1278 if (VDBG) Slog.d(TAG, "validatePhoneId: " + valid);
1279 return valid;
1280 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001281}