blob: 17260d505fdb49624a7a0328c9b28566fff60a7a [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;
Wink Savillef61101f2010-09-16 16:36:42 -070025import android.net.LinkCapabilities;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070026import android.net.LinkProperties;
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;
35import android.telephony.PhoneStateListener;
36import android.telephony.ServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -070037import android.telephony.SignalStrength;
John Wang963db55d2012-03-30 16:04:06 -070038import android.telephony.CellInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.telephony.TelephonyManager;
40import android.text.TextUtils;
Joe Onorato8a9b2202010-02-26 18:56:32 -080041import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
43import java.util.ArrayList;
Wink Savilleb208a242012-07-25 14:08:09 -070044import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import java.io.FileDescriptor;
46import java.io.PrintWriter;
47
48import com.android.internal.app.IBatteryStats;
49import com.android.internal.telephony.ITelephonyRegistry;
50import com.android.internal.telephony.IPhoneStateListener;
51import com.android.internal.telephony.DefaultPhoneNotifier;
Wink Savillea639b312012-07-10 12:37:54 -070052import com.android.internal.telephony.PhoneConstants;
Wink Savillec9330dd2011-01-12 13:37:38 -080053import com.android.internal.telephony.ServiceStateTracker;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import com.android.internal.telephony.TelephonyIntents;
55import com.android.server.am.BatteryStatsService;
56
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057/**
Wink Savillee9b06d72009-05-18 21:47:50 -070058 * Since phone process can be restarted, this class provides a centralized place
59 * that applications can register and be called back from.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 */
61class TelephonyRegistry extends ITelephonyRegistry.Stub {
62 private static final String TAG = "TelephonyRegistry";
Wink Savillec9acde92011-09-21 11:05:43 -070063 private static final boolean DBG = false;
Wink Savillea12a7b32012-09-20 10:09:45 -070064 private static final boolean DBG_LOC = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065
66 private static class Record {
67 String pkgForDebug;
Wink Savillee9b06d72009-05-18 21:47:50 -070068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 IBinder binder;
Wink Savillee9b06d72009-05-18 21:47:50 -070070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 IPhoneStateListener callback;
Wink Savillee9b06d72009-05-18 21:47:50 -070072
Wink Savillea12a7b32012-09-20 10:09:45 -070073 int callerUid;
74
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 int events;
Wink Savillea12a7b32012-09-20 10:09:45 -070076
77 @Override
78 public String toString() {
79 return "{pkgForDebug=" + pkgForDebug + " callerUid=" + callerUid +
80 " events=" + Integer.toHexString(events) + "}";
81 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 }
83
84 private final Context mContext;
Wink Savillee9b06d72009-05-18 21:47:50 -070085
Joe Onorato163d8d92010-10-21 13:21:20 -040086 // access should be inside synchronized (mRecords) for these two fields
87 private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>();
88 private final ArrayList<Record> mRecords = new ArrayList<Record>();
Wink Savillee9b06d72009-05-18 21:47:50 -070089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 private final IBatteryStats mBatteryStats;
91
92 private int mCallState = TelephonyManager.CALL_STATE_IDLE;
Wink Savillee9b06d72009-05-18 21:47:50 -070093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 private String mCallIncomingNumber = "";
Wink Savillee9b06d72009-05-18 21:47:50 -070095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 private ServiceState mServiceState = new ServiceState();
Wink Savillee9b06d72009-05-18 21:47:50 -070097
98 private SignalStrength mSignalStrength = new SignalStrength();
99
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 private boolean mMessageWaiting = false;
Wink Savillee9b06d72009-05-18 21:47:50 -0700101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 private boolean mCallForwarding = false;
Wink Savillee9b06d72009-05-18 21:47:50 -0700103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 private int mDataActivity = TelephonyManager.DATA_ACTIVITY_NONE;
Wink Savillee9b06d72009-05-18 21:47:50 -0700105
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800106 private int mDataConnectionState = TelephonyManager.DATA_UNKNOWN;
Wink Savillee9b06d72009-05-18 21:47:50 -0700107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 private boolean mDataConnectionPossible = false;
Wink Savillee9b06d72009-05-18 21:47:50 -0700109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 private String mDataConnectionReason = "";
Wink Savillee9b06d72009-05-18 21:47:50 -0700111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 private String mDataConnectionApn = "";
Wink Savillee9b06d72009-05-18 21:47:50 -0700113
Robert Greenwalt02648a42010-05-18 10:52:51 -0700114 private ArrayList<String> mConnectedApns;
Robert Greenwalt42acef32009-08-12 16:08:25 -0700115
Wink Savillef61101f2010-09-16 16:36:42 -0700116 private LinkProperties mDataConnectionLinkProperties;
117
118 private LinkCapabilities mDataConnectionLinkCapabilities;
Wink Savillee9b06d72009-05-18 21:47:50 -0700119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 private Bundle mCellLocation = new Bundle();
121
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700122 private int mDataConnectionNetworkType;
123
Wink Savillec9330dd2011-01-12 13:37:38 -0800124 private int mOtaspMode = ServiceStateTracker.OTASP_UNKNOWN;
Wink Savillefd2d0132010-10-28 14:22:26 -0700125
Wink Savilleb208a242012-07-25 14:08:09 -0700126 private List<CellInfo> mCellInfo = null;
John Wang963db55d2012-03-30 16:04:06 -0700127
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700128 static final int PHONE_STATE_PERMISSION_MASK =
129 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
130 PhoneStateListener.LISTEN_CALL_STATE |
131 PhoneStateListener.LISTEN_DATA_ACTIVITY |
132 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
133 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR;
134
Wink Savillea12a7b32012-09-20 10:09:45 -0700135 private static final int MSG_USER_SWITCHED = 1;
136
137 private final Handler mHandler = new Handler() {
138 @Override
139 public void handleMessage(Message msg) {
140 switch (msg.what) {
141 case MSG_USER_SWITCHED: {
Dianne Hackborn40e9f292012-11-27 19:12:23 -0800142 if (DBG) Slog.d(TAG, "MSG_USER_SWITCHED userId=" + msg.arg1);
Wink Savillea12a7b32012-09-20 10:09:45 -0700143 TelephonyRegistry.this.notifyCellLocation(mCellLocation);
144 break;
145 }
146 }
147 }
148 };
149
150 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
151 @Override
152 public void onReceive(Context context, Intent intent) {
153 String action = intent.getAction();
154 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
155 mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED,
156 intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0), 0));
157 }
158 }
159 };
160
Wink Savillee9b06d72009-05-18 21:47:50 -0700161 // we keep a copy of all of the state so we can send it out when folks
162 // register for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 //
Wink Savillee9b06d72009-05-18 21:47:50 -0700164 // In these calls we call with the lock held. This is safe becasuse remote
165 // calls go through a oneway interface and local calls going through a
166 // handler before they get to app code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167
168 TelephonyRegistry(Context context) {
David 'Digit' Turner4ef8ec32009-09-25 11:33:24 -0700169 CellLocation location = CellLocation.getEmpty();
170
171 // Note that location can be null for non-phone builds like
172 // like the generic one.
173 if (location != null) {
174 location.fillInNotifierBundle(mCellLocation);
175 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 mContext = context;
177 mBatteryStats = BatteryStatsService.getService();
Robert Greenwalt02648a42010-05-18 10:52:51 -0700178 mConnectedApns = new ArrayList<String>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 }
180
Wink Savillea12a7b32012-09-20 10:09:45 -0700181 public void systemReady() {
182 // Watch for interesting updates
183 final IntentFilter filter = new IntentFilter();
184 filter.addAction(Intent.ACTION_USER_SWITCHED);
185 filter.addAction(Intent.ACTION_USER_REMOVED);
186 mContext.registerReceiver(mBroadcastReceiver, filter);
187 }
188
189 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
191 boolean notifyNow) {
Wink Savillea12a7b32012-09-20 10:09:45 -0700192 int callerUid = UserHandle.getCallingUserId();
193 int myUid = UserHandle.myUserId();
194 if (DBG) {
195 Slog.d(TAG, "listen: E pkg=" + pkgForDebug + " events=0x" + Integer.toHexString(events)
196 + " myUid=" + myUid
197 + " callerUid=" + callerUid);
198 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 if (events != 0) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700200 /* Checks permission and throws Security exception */
201 checkListenerPermission(events);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202
203 synchronized (mRecords) {
204 // register
205 Record r = null;
206 find_and_add: {
207 IBinder b = callback.asBinder();
208 final int N = mRecords.size();
Wink Savillee9b06d72009-05-18 21:47:50 -0700209 for (int i = 0; i < N; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 r = mRecords.get(i);
211 if (b == r.binder) {
212 break find_and_add;
213 }
214 }
215 r = new Record();
216 r.binder = b;
217 r.callback = callback;
218 r.pkgForDebug = pkgForDebug;
Wink Savillea12a7b32012-09-20 10:09:45 -0700219 r.callerUid = callerUid;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 mRecords.add(r);
Wink Savillea12a7b32012-09-20 10:09:45 -0700221 if (DBG) Slog.i(TAG, "listen: add new record=" + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 }
223 int send = events & (events ^ r.events);
224 r.events = events;
225 if (notifyNow) {
226 if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400227 try {
228 r.callback.onServiceStateChanged(new ServiceState(mServiceState));
229 } catch (RemoteException ex) {
230 remove(r.binder);
231 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 }
233 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
234 try {
Wink Savillee9b06d72009-05-18 21:47:50 -0700235 int gsmSignalStrength = mSignalStrength.getGsmSignalStrength();
236 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
237 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 } catch (RemoteException ex) {
239 remove(r.binder);
240 }
241 }
242 if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
243 try {
244 r.callback.onMessageWaitingIndicatorChanged(mMessageWaiting);
245 } catch (RemoteException ex) {
246 remove(r.binder);
247 }
248 }
249 if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
250 try {
251 r.callback.onCallForwardingIndicatorChanged(mCallForwarding);
252 } catch (RemoteException ex) {
253 remove(r.binder);
254 }
255 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700256 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400257 try {
Wink Savillea12a7b32012-09-20 10:09:45 -0700258 if (DBG_LOC) Slog.d(TAG, "listen: mCellLocation=" + mCellLocation);
Joe Onorato163d8d92010-10-21 13:21:20 -0400259 r.callback.onCellLocationChanged(new Bundle(mCellLocation));
260 } catch (RemoteException ex) {
261 remove(r.binder);
262 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 }
264 if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
265 try {
266 r.callback.onCallStateChanged(mCallState, mCallIncomingNumber);
267 } catch (RemoteException ex) {
268 remove(r.binder);
269 }
270 }
271 if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
272 try {
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700273 r.callback.onDataConnectionStateChanged(mDataConnectionState,
274 mDataConnectionNetworkType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 } catch (RemoteException ex) {
276 remove(r.binder);
277 }
278 }
279 if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
280 try {
281 r.callback.onDataActivity(mDataActivity);
282 } catch (RemoteException ex) {
283 remove(r.binder);
284 }
285 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700286 if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
287 try {
288 r.callback.onSignalStrengthsChanged(mSignalStrength);
289 } catch (RemoteException ex) {
290 remove(r.binder);
291 }
292 }
Wink Savillefd2d0132010-10-28 14:22:26 -0700293 if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
294 try {
295 r.callback.onOtaspChanged(mOtaspMode);
296 } catch (RemoteException ex) {
297 remove(r.binder);
298 }
299 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700300 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700301 try {
Wink Savillea12a7b32012-09-20 10:09:45 -0700302 if (DBG_LOC) Slog.d(TAG, "listen: mCellInfo=" + mCellInfo);
Wink Savilleb208a242012-07-25 14:08:09 -0700303 r.callback.onCellInfoChanged(mCellInfo);
John Wang963db55d2012-03-30 16:04:06 -0700304 } catch (RemoteException ex) {
305 remove(r.binder);
306 }
307 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 }
309 }
310 } else {
311 remove(callback.asBinder());
312 }
313 }
314
315 private void remove(IBinder binder) {
316 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700317 final int recordCount = mRecords.size();
318 for (int i = 0; i < recordCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 if (mRecords.get(i).binder == binder) {
320 mRecords.remove(i);
321 return;
322 }
323 }
324 }
325 }
326
327 public void notifyCallState(int state, String incomingNumber) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700328 if (!checkNotifyPermission("notifyCallState()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700329 return;
330 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 synchronized (mRecords) {
332 mCallState = state;
333 mCallIncomingNumber = incomingNumber;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700334 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 if ((r.events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
336 try {
337 r.callback.onCallStateChanged(state, incomingNumber);
338 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400339 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 }
341 }
342 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400343 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 }
345 broadcastCallStateChanged(state, incomingNumber);
346 }
347
348 public void notifyServiceState(ServiceState state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700349 if (!checkNotifyPermission("notifyServiceState()")){
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700350 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700351 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 synchronized (mRecords) {
353 mServiceState = state;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700354 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 if ((r.events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400356 try {
357 r.callback.onServiceStateChanged(new ServiceState(state));
358 } catch (RemoteException ex) {
359 mRemoveList.add(r.binder);
360 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 }
362 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400363 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800364 }
365 broadcastServiceStateChanged(state);
366 }
367
Wink Savillee9b06d72009-05-18 21:47:50 -0700368 public void notifySignalStrength(SignalStrength signalStrength) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700369 if (!checkNotifyPermission("notifySignalStrength()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700370 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700371 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700373 mSignalStrength = signalStrength;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700374 for (Record r : mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700375 if ((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400376 try {
377 r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength));
378 } catch (RemoteException ex) {
379 mRemoveList.add(r.binder);
380 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700381 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 if ((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
383 try {
Wink Savillee9b06d72009-05-18 21:47:50 -0700384 int gsmSignalStrength = signalStrength.getGsmSignalStrength();
385 r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
386 : gsmSignalStrength));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400388 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 }
390 }
391 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400392 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700394 broadcastSignalStrengthChanged(signalStrength);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 }
396
Wink Savilleb208a242012-07-25 14:08:09 -0700397 public void notifyCellInfo(List<CellInfo> cellInfo) {
John Wang963db55d2012-03-30 16:04:06 -0700398 if (!checkNotifyPermission("notifyCellInfo()")) {
399 return;
400 }
401
402 synchronized (mRecords) {
403 mCellInfo = cellInfo;
404 for (Record r : mRecords) {
Wink Savillea12a7b32012-09-20 10:09:45 -0700405 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
John Wang963db55d2012-03-30 16:04:06 -0700406 try {
Wink Savillea12a7b32012-09-20 10:09:45 -0700407 if (DBG_LOC) {
408 Slog.d(TAG, "notifyCellInfo: mCellInfo=" + mCellInfo + " r=" + r);
409 }
Wink Savilleb208a242012-07-25 14:08:09 -0700410 r.callback.onCellInfoChanged(cellInfo);
John Wang963db55d2012-03-30 16:04:06 -0700411 } catch (RemoteException ex) {
412 mRemoveList.add(r.binder);
413 }
414 }
415 }
416 handleRemoveListLocked();
417 }
418 }
419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 public void notifyMessageWaitingChanged(boolean mwi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700421 if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700422 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700423 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800424 synchronized (mRecords) {
425 mMessageWaiting = mwi;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700426 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 if ((r.events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
428 try {
429 r.callback.onMessageWaitingIndicatorChanged(mwi);
430 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400431 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 }
433 }
434 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400435 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 }
437 }
438
439 public void notifyCallForwardingChanged(boolean cfi) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700440 if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700441 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700442 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 synchronized (mRecords) {
444 mCallForwarding = cfi;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700445 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 if ((r.events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
447 try {
448 r.callback.onCallForwardingIndicatorChanged(cfi);
449 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400450 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 }
452 }
453 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400454 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 }
456 }
457
458 public void notifyDataActivity(int state) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700459 if (!checkNotifyPermission("notifyDataActivity()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700460 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700461 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 synchronized (mRecords) {
463 mDataActivity = state;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700464 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800465 if ((r.events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
466 try {
467 r.callback.onDataActivity(state);
468 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400469 mRemoveList.add(r.binder);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 }
471 }
472 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400473 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800474 }
475 }
476
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700477 public void notifyDataConnection(int state, boolean isDataConnectivityPossible,
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700478 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwalta6d42482011-09-02 15:19:31 -0700479 LinkCapabilities linkCapabilities, int networkType, boolean roaming) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700480 if (!checkNotifyPermission("notifyDataConnection()" )) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700481 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700482 }
Wink Savillec9acde92011-09-21 11:05:43 -0700483 if (DBG) {
484 Slog.i(TAG, "notifyDataConnection: state=" + state + " isDataConnectivityPossible="
Wink Saville26f5a382010-11-24 16:44:29 -0800485 + isDataConnectivityPossible + " reason='" + reason
Wink Savillea12a7b32012-09-20 10:09:45 -0700486 + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
487 + " mRecords.size()=" + mRecords.size() + " mRecords=" + mRecords);
Wink Savillec9acde92011-09-21 11:05:43 -0700488 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 synchronized (mRecords) {
Robert Greenwalt02648a42010-05-18 10:52:51 -0700490 boolean modified = false;
491 if (state == TelephonyManager.DATA_CONNECTED) {
492 if (!mConnectedApns.contains(apnType)) {
493 mConnectedApns.add(apnType);
494 if (mDataConnectionState != state) {
495 mDataConnectionState = state;
496 modified = true;
497 }
498 }
499 } else {
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800500 if (mConnectedApns.remove(apnType)) {
501 if (mConnectedApns.isEmpty()) {
502 mDataConnectionState = state;
503 modified = true;
504 } else {
505 // leave mDataConnectionState as is and
506 // send out the new status for the APN in question.
507 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700508 }
509 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700510 mDataConnectionPossible = isDataConnectivityPossible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 mDataConnectionReason = reason;
Wink Savillef61101f2010-09-16 16:36:42 -0700512 mDataConnectionLinkProperties = linkProperties;
513 mDataConnectionLinkCapabilities = linkCapabilities;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700514 if (mDataConnectionNetworkType != networkType) {
515 mDataConnectionNetworkType = networkType;
Robert Greenwalt8e7e0a92010-11-09 10:24:40 -0800516 // need to tell registered listeners about the new network type
Robert Greenwalt02648a42010-05-18 10:52:51 -0700517 modified = true;
518 }
519 if (modified) {
Wink Savillec9acde92011-09-21 11:05:43 -0700520 if (DBG) {
521 Slog.d(TAG, "onDataConnectionStateChanged(" + mDataConnectionState
yoonsung.name6fa1202011-08-20 21:39:12 -0700522 + ", " + mDataConnectionNetworkType + ")");
Wink Savillec9acde92011-09-21 11:05:43 -0700523 }
Robert Greenwalt02648a42010-05-18 10:52:51 -0700524 for (Record r : mRecords) {
525 if ((r.events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
526 try {
yoonsung.name6fa1202011-08-20 21:39:12 -0700527 r.callback.onDataConnectionStateChanged(mDataConnectionState,
528 mDataConnectionNetworkType);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700529 } catch (RemoteException ex) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400530 mRemoveList.add(r.binder);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700531 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 }
533 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400534 handleRemoveListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 }
536 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700537 broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn,
Robert Greenwalta6d42482011-09-02 15:19:31 -0700538 apnType, linkProperties, linkCapabilities, roaming);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 }
540
Robert Greenwalt02648a42010-05-18 10:52:51 -0700541 public void notifyDataConnectionFailed(String reason, String apnType) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700542 if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700543 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700544 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545 /*
Robert Greenwalt02648a42010-05-18 10:52:51 -0700546 * This is commented out because there is no onDataConnectionFailed callback
547 * in PhoneStateListener. There should be.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 synchronized (mRecords) {
549 mDataConnectionFailedReason = reason;
550 final int N = mRecords.size();
551 for (int i=N-1; i>=0; i--) {
552 Record r = mRecords.get(i);
553 if ((r.events & PhoneStateListener.LISTEN_DATA_CONNECTION_FAILED) != 0) {
554 // XXX
555 }
556 }
557 }
558 */
Robert Greenwalt02648a42010-05-18 10:52:51 -0700559 broadcastDataConnectionFailed(reason, apnType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 }
561
562 public void notifyCellLocation(Bundle cellLocation) {
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700563 if (!checkNotifyPermission("notifyCellLocation()")) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700564 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700565 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 synchronized (mRecords) {
567 mCellLocation = cellLocation;
Robert Greenwalt02648a42010-05-18 10:52:51 -0700568 for (Record r : mRecords) {
Wink Savillea12a7b32012-09-20 10:09:45 -0700569 if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
Joe Onorato163d8d92010-10-21 13:21:20 -0400570 try {
Wink Savillea12a7b32012-09-20 10:09:45 -0700571 if (DBG_LOC) {
572 Slog.d(TAG, "notifyCellLocation: mCellLocation=" + mCellLocation
573 + " r=" + r);
574 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400575 r.callback.onCellLocationChanged(new Bundle(cellLocation));
576 } catch (RemoteException ex) {
577 mRemoveList.add(r.binder);
578 }
579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 }
581 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400582 handleRemoveListLocked();
Wink Savillee9b06d72009-05-18 21:47:50 -0700583 }
584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585
Wink Savillefd2d0132010-10-28 14:22:26 -0700586 public void notifyOtaspChanged(int otaspMode) {
587 if (!checkNotifyPermission("notifyOtaspChanged()" )) {
588 return;
589 }
590 synchronized (mRecords) {
591 mOtaspMode = otaspMode;
592 for (Record r : mRecords) {
593 if ((r.events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
594 try {
595 r.callback.onOtaspChanged(otaspMode);
596 } catch (RemoteException ex) {
597 mRemoveList.add(r.binder);
598 }
599 }
600 }
601 handleRemoveListLocked();
602 }
603 }
604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 @Override
606 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
607 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
608 != PackageManager.PERMISSION_GRANTED) {
609 pw.println("Permission Denial: can't dump telephony.registry from from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -0700610 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800611 return;
612 }
613 synchronized (mRecords) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700614 final int recordCount = mRecords.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615 pw.println("last known state:");
616 pw.println(" mCallState=" + mCallState);
617 pw.println(" mCallIncomingNumber=" + mCallIncomingNumber);
618 pw.println(" mServiceState=" + mServiceState);
619 pw.println(" mSignalStrength=" + mSignalStrength);
620 pw.println(" mMessageWaiting=" + mMessageWaiting);
621 pw.println(" mCallForwarding=" + mCallForwarding);
622 pw.println(" mDataActivity=" + mDataActivity);
623 pw.println(" mDataConnectionState=" + mDataConnectionState);
624 pw.println(" mDataConnectionPossible=" + mDataConnectionPossible);
625 pw.println(" mDataConnectionReason=" + mDataConnectionReason);
626 pw.println(" mDataConnectionApn=" + mDataConnectionApn);
Wink Savillef61101f2010-09-16 16:36:42 -0700627 pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties);
628 pw.println(" mDataConnectionLinkCapabilities=" + mDataConnectionLinkCapabilities);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 pw.println(" mCellLocation=" + mCellLocation);
John Wang963db55d2012-03-30 16:04:06 -0700630 pw.println(" mCellInfo=" + mCellInfo);
Wink Savillee9b06d72009-05-18 21:47:50 -0700631 pw.println("registrations: count=" + recordCount);
Robert Greenwalt02648a42010-05-18 10:52:51 -0700632 for (Record r : mRecords) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 pw.println(" " + r.pkgForDebug + " 0x" + Integer.toHexString(r.events));
634 }
635 }
636 }
637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 //
639 // the legacy intent broadcasting
640 //
641
642 private void broadcastServiceStateChanged(ServiceState state) {
Amith Yamasani32dbefd2009-06-19 09:21:17 -0700643 long ident = Binder.clearCallingIdentity();
644 try {
Amith Yamasanif37447b2009-10-08 18:28:01 -0700645 mBatteryStats.notePhoneState(state.getState());
Amith Yamasani32dbefd2009-06-19 09:21:17 -0700646 } catch (RemoteException re) {
647 // Can't do much
648 } finally {
649 Binder.restoreCallingIdentity(ident);
650 }
651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
653 Bundle data = new Bundle();
654 state.fillInNotifierBundle(data);
655 intent.putExtras(data);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700656 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657 }
658
Wink Savillee9b06d72009-05-18 21:47:50 -0700659 private void broadcastSignalStrengthChanged(SignalStrength signalStrength) {
Dianne Hackborn627bba72009-03-24 22:32:56 -0700660 long ident = Binder.clearCallingIdentity();
661 try {
Wink Savillee9b06d72009-05-18 21:47:50 -0700662 mBatteryStats.notePhoneSignalStrength(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -0700663 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700664 /* The remote entity disappeared, we can safely ignore the exception. */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700665 } finally {
666 Binder.restoreCallingIdentity(ident);
667 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED);
Dianne Hackborn1c633fc2009-12-08 19:45:14 -0800670 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
Wink Savillee9b06d72009-05-18 21:47:50 -0700671 Bundle data = new Bundle();
672 signalStrength.fillInNotifierBundle(data);
673 intent.putExtras(data);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700674 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 }
676
677 private void broadcastCallStateChanged(int state, String incomingNumber) {
678 long ident = Binder.clearCallingIdentity();
679 try {
680 if (state == TelephonyManager.CALL_STATE_IDLE) {
681 mBatteryStats.notePhoneOff();
682 } else {
683 mBatteryStats.notePhoneOn();
684 }
685 } catch (RemoteException e) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700686 /* The remote entity disappeared, we can safely ignore the exception. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 } finally {
688 Binder.restoreCallingIdentity(ident);
689 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -0700692 intent.putExtra(PhoneConstants.STATE_KEY,
693 DefaultPhoneNotifier.convertCallState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 if (!TextUtils.isEmpty(incomingNumber)) {
695 intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
696 }
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700697 mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
698 android.Manifest.permission.READ_PHONE_STATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699 }
700
Robert Greenwalt42acef32009-08-12 16:08:25 -0700701 private void broadcastDataConnectionStateChanged(int state,
702 boolean isDataConnectivityPossible,
Wink Savillef61101f2010-09-16 16:36:42 -0700703 String reason, String apn, String apnType, LinkProperties linkProperties,
Robert Greenwalta6d42482011-09-02 15:19:31 -0700704 LinkCapabilities linkCapabilities, boolean roaming) {
Dianne Hackborn627bba72009-03-24 22:32:56 -0700705 // Note: not reporting to the battery stats service here, because the
706 // status bar takes care of that after taking into account all of the
707 // required info.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800708 Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Wink Savillea639b312012-07-10 12:37:54 -0700709 intent.putExtra(PhoneConstants.STATE_KEY,
710 DefaultPhoneNotifier.convertDataState(state).toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800711 if (!isDataConnectivityPossible) {
Wink Savillea639b312012-07-10 12:37:54 -0700712 intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800713 }
714 if (reason != null) {
Wink Savillea639b312012-07-10 12:37:54 -0700715 intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800716 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700717 if (linkProperties != null) {
Wink Savillea639b312012-07-10 12:37:54 -0700718 intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -0700719 String iface = linkProperties.getInterfaceName();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700720 if (iface != null) {
Wink Savillea639b312012-07-10 12:37:54 -0700721 intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700722 }
723 }
Wink Savillef61101f2010-09-16 16:36:42 -0700724 if (linkCapabilities != null) {
Wink Savillea639b312012-07-10 12:37:54 -0700725 intent.putExtra(PhoneConstants.DATA_LINK_CAPABILITIES_KEY, linkCapabilities);
Wink Savillef61101f2010-09-16 16:36:42 -0700726 }
Wink Savillea639b312012-07-10 12:37:54 -0700727 if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true);
Robert Greenwalta6d42482011-09-02 15:19:31 -0700728
Wink Savillea639b312012-07-10 12:37:54 -0700729 intent.putExtra(PhoneConstants.DATA_APN_KEY, apn);
730 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700731 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 }
733
Robert Greenwalt02648a42010-05-18 10:52:51 -0700734 private void broadcastDataConnectionFailed(String reason, String apnType) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
Wink Savillea639b312012-07-10 12:37:54 -0700736 intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason);
737 intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700738 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700740
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700741 private boolean checkNotifyPermission(String method) {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700742 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
743 == PackageManager.PERMISSION_GRANTED) {
744 return true;
745 }
746 String msg = "Modify Phone State Permission Denial: " + method + " from pid="
Wink Savillee9b06d72009-05-18 21:47:50 -0700747 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Wink Savillec9acde92011-09-21 11:05:43 -0700748 if (DBG) Slog.w(TAG, msg);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700749 return false;
750 }
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700751
752 private void checkListenerPermission(int events) {
753 if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
754 mContext.enforceCallingOrSelfPermission(
755 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
756
757 }
758
John Wang963db55d2012-03-30 16:04:06 -0700759 if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
760 mContext.enforceCallingOrSelfPermission(
761 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
762
763 }
764
Jaikumar Ganesh45515652009-04-23 15:20:21 -0700765 if ((events & PHONE_STATE_PERMISSION_MASK) != 0) {
766 mContext.enforceCallingOrSelfPermission(
767 android.Manifest.permission.READ_PHONE_STATE, null);
768 }
769 }
Joe Onorato163d8d92010-10-21 13:21:20 -0400770
771 private void handleRemoveListLocked() {
772 if (mRemoveList.size() > 0) {
773 for (IBinder b: mRemoveList) {
774 remove(b);
775 }
776 mRemoveList.clear();
777 }
778 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700779
780 private boolean validateEventsAndUserLocked(Record r, int events) {
781 int foregroundUser;
782 long callingIdentity = Binder.clearCallingIdentity();
783 boolean valid = false;
784 try {
785 foregroundUser = ActivityManager.getCurrentUser();
786 valid = r.callerUid == foregroundUser && (r.events & events) != 0;
787 if (DBG | DBG_LOC) {
788 Slog.d(TAG, "validateEventsAndUserLocked: valid=" + valid
789 + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
790 + " r.events=" + r.events + " events=" + events);
791 }
792 } finally {
793 Binder.restoreCallingIdentity(callingIdentity);
794 }
795 return valid;
796 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797}