The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server; |
| 18 | |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 19 | import android.app.ActivityManager; |
| 20 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 23 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.pm.PackageManager; |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 25 | import android.net.LinkProperties; |
Robert Greenwalt | f9cb86a | 2014-04-08 17:34:00 -0700 | [diff] [blame] | 26 | import android.net.NetworkCapabilities; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.os.Binder; |
| 28 | import android.os.Bundle; |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 29 | import android.os.Handler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.os.IBinder; |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 31 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.os.RemoteException; |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 33 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.telephony.CellLocation; |
Wink Saville | 070e061 | 2014-04-15 22:04:10 -0700 | [diff] [blame] | 35 | import android.telephony.DataConnectionRealTimeInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.telephony.PhoneStateListener; |
| 37 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 38 | import android.telephony.SignalStrength; |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 39 | import android.telephony.CellInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.telephony.TelephonyManager; |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 41 | import android.telephony.DisconnectCause; |
| 42 | import android.telephony.PreciseCallState; |
| 43 | import android.telephony.PreciseDataConnectionState; |
| 44 | import android.telephony.PreciseDisconnectCause; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.text.TextUtils; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 46 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | |
| 48 | import java.util.ArrayList; |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 49 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import java.io.FileDescriptor; |
| 51 | import java.io.PrintWriter; |
| 52 | |
| 53 | import com.android.internal.app.IBatteryStats; |
| 54 | import com.android.internal.telephony.ITelephonyRegistry; |
| 55 | import com.android.internal.telephony.IPhoneStateListener; |
| 56 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 57 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | c9330dd | 2011-01-12 13:37:38 -0800 | [diff] [blame] | 58 | import com.android.internal.telephony.ServiceStateTracker; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import com.android.internal.telephony.TelephonyIntents; |
| 60 | import com.android.server.am.BatteryStatsService; |
| 61 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | /** |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 63 | * Since phone process can be restarted, this class provides a centralized place |
| 64 | * that applications can register and be called back from. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | */ |
| 66 | class TelephonyRegistry extends ITelephonyRegistry.Stub { |
| 67 | private static final String TAG = "TelephonyRegistry"; |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 68 | private static final boolean DBG = false; |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 69 | private static final boolean DBG_LOC = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | |
| 71 | private static class Record { |
| 72 | String pkgForDebug; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 73 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | IBinder binder; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 75 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | IPhoneStateListener callback; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 77 | |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 78 | int callerUid; |
| 79 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | int events; |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 81 | |
| 82 | @Override |
| 83 | public String toString() { |
| 84 | return "{pkgForDebug=" + pkgForDebug + " callerUid=" + callerUid + |
| 85 | " events=" + Integer.toHexString(events) + "}"; |
| 86 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | private final Context mContext; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 90 | |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 91 | // access should be inside synchronized (mRecords) for these two fields |
| 92 | private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>(); |
| 93 | private final ArrayList<Record> mRecords = new ArrayList<Record>(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 94 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | private final IBatteryStats mBatteryStats; |
| 96 | |
| 97 | private int mCallState = TelephonyManager.CALL_STATE_IDLE; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 98 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | private String mCallIncomingNumber = ""; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 100 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | private ServiceState mServiceState = new ServiceState(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 102 | |
| 103 | private SignalStrength mSignalStrength = new SignalStrength(); |
| 104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | private boolean mMessageWaiting = false; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | private boolean mCallForwarding = false; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | private int mDataActivity = TelephonyManager.DATA_ACTIVITY_NONE; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 110 | |
Robert Greenwalt | 8e7e0a9 | 2010-11-09 10:24:40 -0800 | [diff] [blame] | 111 | private int mDataConnectionState = TelephonyManager.DATA_UNKNOWN; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 112 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | private boolean mDataConnectionPossible = false; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 114 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | private String mDataConnectionReason = ""; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | private String mDataConnectionApn = ""; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 118 | |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 119 | private ArrayList<String> mConnectedApns; |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 120 | |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 121 | private LinkProperties mDataConnectionLinkProperties; |
| 122 | |
Robert Greenwalt | f9cb86a | 2014-04-08 17:34:00 -0700 | [diff] [blame] | 123 | private NetworkCapabilities mDataConnectionNetworkCapabilities; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | private Bundle mCellLocation = new Bundle(); |
| 126 | |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame] | 127 | private int mDataConnectionNetworkType; |
| 128 | |
Wink Saville | c9330dd | 2011-01-12 13:37:38 -0800 | [diff] [blame] | 129 | private int mOtaspMode = ServiceStateTracker.OTASP_UNKNOWN; |
Wink Saville | fd2d013 | 2010-10-28 14:22:26 -0700 | [diff] [blame] | 130 | |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 131 | private List<CellInfo> mCellInfo = null; |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 132 | |
Wink Saville | 070e061 | 2014-04-15 22:04:10 -0700 | [diff] [blame] | 133 | private DataConnectionRealTimeInfo mDcRtInfo = new DataConnectionRealTimeInfo(); |
| 134 | |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 135 | private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE; |
| 136 | |
| 137 | private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE; |
| 138 | |
| 139 | private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE; |
| 140 | |
| 141 | private PreciseCallState mPreciseCallState = new PreciseCallState(); |
| 142 | |
| 143 | private PreciseDataConnectionState mPreciseDataConnectionState = |
| 144 | new PreciseDataConnectionState(); |
| 145 | |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 146 | static final int PHONE_STATE_PERMISSION_MASK = |
| 147 | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR | |
| 148 | PhoneStateListener.LISTEN_CALL_STATE | |
| 149 | PhoneStateListener.LISTEN_DATA_ACTIVITY | |
| 150 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE | |
| 151 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR; |
| 152 | |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 153 | static final int PRECISE_PHONE_STATE_PERMISSION_MASK = |
| 154 | PhoneStateListener.LISTEN_PRECISE_CALL_STATE | |
| 155 | PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE; |
| 156 | |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 157 | private static final int MSG_USER_SWITCHED = 1; |
| 158 | |
| 159 | private final Handler mHandler = new Handler() { |
| 160 | @Override |
| 161 | public void handleMessage(Message msg) { |
| 162 | switch (msg.what) { |
| 163 | case MSG_USER_SWITCHED: { |
Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 164 | if (DBG) Slog.d(TAG, "MSG_USER_SWITCHED userId=" + msg.arg1); |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 165 | TelephonyRegistry.this.notifyCellLocation(mCellLocation); |
| 166 | break; |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | }; |
| 171 | |
| 172 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 173 | @Override |
| 174 | public void onReceive(Context context, Intent intent) { |
| 175 | String action = intent.getAction(); |
| 176 | if (Intent.ACTION_USER_SWITCHED.equals(action)) { |
| 177 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, |
| 178 | intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0), 0)); |
| 179 | } |
| 180 | } |
| 181 | }; |
| 182 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 183 | // we keep a copy of all of the state so we can send it out when folks |
| 184 | // register for it |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | // |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 186 | // In these calls we call with the lock held. This is safe becasuse remote |
| 187 | // calls go through a oneway interface and local calls going through a |
| 188 | // handler before they get to app code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | |
| 190 | TelephonyRegistry(Context context) { |
David 'Digit' Turner | 4ef8ec3 | 2009-09-25 11:33:24 -0700 | [diff] [blame] | 191 | CellLocation location = CellLocation.getEmpty(); |
| 192 | |
| 193 | // Note that location can be null for non-phone builds like |
| 194 | // like the generic one. |
| 195 | if (location != null) { |
| 196 | location.fillInNotifierBundle(mCellLocation); |
| 197 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | mContext = context; |
| 199 | mBatteryStats = BatteryStatsService.getService(); |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 200 | mConnectedApns = new ArrayList<String>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 203 | public void systemRunning() { |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 204 | // Watch for interesting updates |
| 205 | final IntentFilter filter = new IntentFilter(); |
| 206 | filter.addAction(Intent.ACTION_USER_SWITCHED); |
| 207 | filter.addAction(Intent.ACTION_USER_REMOVED); |
| 208 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 209 | } |
| 210 | |
| 211 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | public void listen(String pkgForDebug, IPhoneStateListener callback, int events, |
| 213 | boolean notifyNow) { |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 214 | int callerUid = UserHandle.getCallingUserId(); |
| 215 | int myUid = UserHandle.myUserId(); |
| 216 | if (DBG) { |
| 217 | Slog.d(TAG, "listen: E pkg=" + pkgForDebug + " events=0x" + Integer.toHexString(events) |
| 218 | + " myUid=" + myUid |
| 219 | + " callerUid=" + callerUid); |
| 220 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | if (events != 0) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 222 | /* Checks permission and throws Security exception */ |
| 223 | checkListenerPermission(events); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | |
| 225 | synchronized (mRecords) { |
| 226 | // register |
| 227 | Record r = null; |
| 228 | find_and_add: { |
| 229 | IBinder b = callback.asBinder(); |
| 230 | final int N = mRecords.size(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 231 | for (int i = 0; i < N; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | r = mRecords.get(i); |
| 233 | if (b == r.binder) { |
| 234 | break find_and_add; |
| 235 | } |
| 236 | } |
| 237 | r = new Record(); |
| 238 | r.binder = b; |
| 239 | r.callback = callback; |
| 240 | r.pkgForDebug = pkgForDebug; |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 241 | r.callerUid = callerUid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 242 | mRecords.add(r); |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 243 | if (DBG) Slog.i(TAG, "listen: add new record=" + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | } |
| 245 | int send = events & (events ^ r.events); |
| 246 | r.events = events; |
| 247 | if (notifyNow) { |
| 248 | if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 249 | try { |
| 250 | r.callback.onServiceStateChanged(new ServiceState(mServiceState)); |
| 251 | } catch (RemoteException ex) { |
| 252 | remove(r.binder); |
| 253 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | } |
| 255 | if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) { |
| 256 | try { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 257 | int gsmSignalStrength = mSignalStrength.getGsmSignalStrength(); |
| 258 | r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1 |
| 259 | : gsmSignalStrength)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | } catch (RemoteException ex) { |
| 261 | remove(r.binder); |
| 262 | } |
| 263 | } |
| 264 | if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) { |
| 265 | try { |
| 266 | r.callback.onMessageWaitingIndicatorChanged(mMessageWaiting); |
| 267 | } catch (RemoteException ex) { |
| 268 | remove(r.binder); |
| 269 | } |
| 270 | } |
| 271 | if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) { |
| 272 | try { |
| 273 | r.callback.onCallForwardingIndicatorChanged(mCallForwarding); |
| 274 | } catch (RemoteException ex) { |
| 275 | remove(r.binder); |
| 276 | } |
| 277 | } |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 278 | if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 279 | try { |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 280 | if (DBG_LOC) Slog.d(TAG, "listen: mCellLocation=" + mCellLocation); |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 281 | r.callback.onCellLocationChanged(new Bundle(mCellLocation)); |
| 282 | } catch (RemoteException ex) { |
| 283 | remove(r.binder); |
| 284 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | } |
| 286 | if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) { |
| 287 | try { |
| 288 | r.callback.onCallStateChanged(mCallState, mCallIncomingNumber); |
| 289 | } catch (RemoteException ex) { |
| 290 | remove(r.binder); |
| 291 | } |
| 292 | } |
| 293 | if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) { |
| 294 | try { |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame] | 295 | r.callback.onDataConnectionStateChanged(mDataConnectionState, |
| 296 | mDataConnectionNetworkType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | } catch (RemoteException ex) { |
| 298 | remove(r.binder); |
| 299 | } |
| 300 | } |
| 301 | if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) { |
| 302 | try { |
| 303 | r.callback.onDataActivity(mDataActivity); |
| 304 | } catch (RemoteException ex) { |
| 305 | remove(r.binder); |
| 306 | } |
| 307 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 308 | if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) { |
| 309 | try { |
| 310 | r.callback.onSignalStrengthsChanged(mSignalStrength); |
| 311 | } catch (RemoteException ex) { |
| 312 | remove(r.binder); |
| 313 | } |
| 314 | } |
Wink Saville | fd2d013 | 2010-10-28 14:22:26 -0700 | [diff] [blame] | 315 | if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) { |
| 316 | try { |
| 317 | r.callback.onOtaspChanged(mOtaspMode); |
| 318 | } catch (RemoteException ex) { |
| 319 | remove(r.binder); |
| 320 | } |
| 321 | } |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 322 | if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) { |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 323 | try { |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 324 | if (DBG_LOC) Slog.d(TAG, "listen: mCellInfo=" + mCellInfo); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 325 | r.callback.onCellInfoChanged(mCellInfo); |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 326 | } catch (RemoteException ex) { |
| 327 | remove(r.binder); |
| 328 | } |
| 329 | } |
Wink Saville | 070e061 | 2014-04-15 22:04:10 -0700 | [diff] [blame] | 330 | if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO) != 0) { |
| 331 | try { |
| 332 | r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo); |
| 333 | } catch (RemoteException ex) { |
| 334 | remove(r.binder); |
| 335 | } |
| 336 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 337 | if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) { |
| 338 | try { |
| 339 | r.callback.onPreciseCallStateChanged(mPreciseCallState); |
| 340 | } catch (RemoteException ex) { |
| 341 | remove(r.binder); |
| 342 | } |
| 343 | } |
| 344 | if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) { |
| 345 | try { |
| 346 | r.callback.onPreciseDataConnectionStateChanged( |
| 347 | mPreciseDataConnectionState); |
| 348 | } catch (RemoteException ex) { |
| 349 | remove(r.binder); |
| 350 | } |
| 351 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | } else { |
| 355 | remove(callback.asBinder()); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | private void remove(IBinder binder) { |
| 360 | synchronized (mRecords) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 361 | final int recordCount = mRecords.size(); |
| 362 | for (int i = 0; i < recordCount; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | if (mRecords.get(i).binder == binder) { |
| 364 | mRecords.remove(i); |
| 365 | return; |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | public void notifyCallState(int state, String incomingNumber) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 372 | if (!checkNotifyPermission("notifyCallState()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 373 | return; |
| 374 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 375 | synchronized (mRecords) { |
| 376 | mCallState = state; |
| 377 | mCallIncomingNumber = incomingNumber; |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 378 | for (Record r : mRecords) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | if ((r.events & PhoneStateListener.LISTEN_CALL_STATE) != 0) { |
| 380 | try { |
| 381 | r.callback.onCallStateChanged(state, incomingNumber); |
| 382 | } catch (RemoteException ex) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 383 | mRemoveList.add(r.binder); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 387 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | } |
| 389 | broadcastCallStateChanged(state, incomingNumber); |
| 390 | } |
| 391 | |
| 392 | public void notifyServiceState(ServiceState state) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 393 | if (!checkNotifyPermission("notifyServiceState()")){ |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 394 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 395 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 396 | long ident = Binder.clearCallingIdentity(); |
| 397 | try { |
| 398 | mBatteryStats.notePhoneState(state.getState()); |
| 399 | } catch (RemoteException re) { |
| 400 | // Can't do much |
| 401 | } finally { |
| 402 | Binder.restoreCallingIdentity(ident); |
| 403 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | synchronized (mRecords) { |
| 405 | mServiceState = state; |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 406 | for (Record r : mRecords) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 407 | if ((r.events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 408 | try { |
| 409 | r.callback.onServiceStateChanged(new ServiceState(state)); |
| 410 | } catch (RemoteException ex) { |
| 411 | mRemoveList.add(r.binder); |
| 412 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | } |
| 414 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 415 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 | } |
| 417 | broadcastServiceStateChanged(state); |
| 418 | } |
| 419 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 420 | public void notifySignalStrength(SignalStrength signalStrength) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 421 | if (!checkNotifyPermission("notifySignalStrength()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 422 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 423 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | synchronized (mRecords) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 425 | mSignalStrength = signalStrength; |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 426 | for (Record r : mRecords) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 427 | if ((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 428 | try { |
| 429 | r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength)); |
| 430 | } catch (RemoteException ex) { |
| 431 | mRemoveList.add(r.binder); |
| 432 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 433 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | if ((r.events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) { |
| 435 | try { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 436 | int gsmSignalStrength = signalStrength.getGsmSignalStrength(); |
| 437 | r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1 |
| 438 | : gsmSignalStrength)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | } catch (RemoteException ex) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 440 | mRemoveList.add(r.binder); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 444 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 446 | broadcastSignalStrengthChanged(signalStrength); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | } |
| 448 | |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 449 | public void notifyCellInfo(List<CellInfo> cellInfo) { |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 450 | if (!checkNotifyPermission("notifyCellInfo()")) { |
| 451 | return; |
| 452 | } |
| 453 | |
| 454 | synchronized (mRecords) { |
| 455 | mCellInfo = cellInfo; |
| 456 | for (Record r : mRecords) { |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 457 | if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) { |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 458 | try { |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 459 | if (DBG_LOC) { |
| 460 | Slog.d(TAG, "notifyCellInfo: mCellInfo=" + mCellInfo + " r=" + r); |
| 461 | } |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 462 | r.callback.onCellInfoChanged(cellInfo); |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 463 | } catch (RemoteException ex) { |
| 464 | mRemoveList.add(r.binder); |
| 465 | } |
| 466 | } |
| 467 | } |
| 468 | handleRemoveListLocked(); |
| 469 | } |
| 470 | } |
| 471 | |
Wink Saville | 070e061 | 2014-04-15 22:04:10 -0700 | [diff] [blame] | 472 | public void notifyDataConnectionRealTimeInfo(DataConnectionRealTimeInfo dcRtInfo) { |
| 473 | if (!checkNotifyPermission("notifyDataConnectionRealTimeInfo()")) { |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | synchronized (mRecords) { |
| 478 | mDcRtInfo = dcRtInfo; |
| 479 | for (Record r : mRecords) { |
| 480 | if (validateEventsAndUserLocked(r, |
| 481 | PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO)) { |
| 482 | try { |
| 483 | if (DBG_LOC) { |
| 484 | Slog.d(TAG, "notifyDataConnectionRealTimeInfo: mDcRtInfo=" |
| 485 | + mDcRtInfo + " r=" + r); |
| 486 | } |
| 487 | r.callback.onDataConnectionRealTimeInfoChanged(mDcRtInfo); |
| 488 | } catch (RemoteException ex) { |
| 489 | mRemoveList.add(r.binder); |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | handleRemoveListLocked(); |
| 494 | } |
| 495 | } |
| 496 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 497 | public void notifyMessageWaitingChanged(boolean mwi) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 498 | if (!checkNotifyPermission("notifyMessageWaitingChanged()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 499 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 500 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | synchronized (mRecords) { |
| 502 | mMessageWaiting = mwi; |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 503 | for (Record r : mRecords) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | if ((r.events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) { |
| 505 | try { |
| 506 | r.callback.onMessageWaitingIndicatorChanged(mwi); |
| 507 | } catch (RemoteException ex) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 508 | mRemoveList.add(r.binder); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | } |
| 510 | } |
| 511 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 512 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | |
| 516 | public void notifyCallForwardingChanged(boolean cfi) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 517 | if (!checkNotifyPermission("notifyCallForwardingChanged()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 518 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 519 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | synchronized (mRecords) { |
| 521 | mCallForwarding = cfi; |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 522 | for (Record r : mRecords) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | if ((r.events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) { |
| 524 | try { |
| 525 | r.callback.onCallForwardingIndicatorChanged(cfi); |
| 526 | } catch (RemoteException ex) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 527 | mRemoveList.add(r.binder); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 531 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 532 | } |
| 533 | } |
| 534 | |
| 535 | public void notifyDataActivity(int state) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 536 | if (!checkNotifyPermission("notifyDataActivity()" )) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 537 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 538 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 539 | synchronized (mRecords) { |
| 540 | mDataActivity = state; |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 541 | for (Record r : mRecords) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 542 | if ((r.events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) { |
| 543 | try { |
| 544 | r.callback.onDataActivity(state); |
| 545 | } catch (RemoteException ex) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 546 | mRemoveList.add(r.binder); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 547 | } |
| 548 | } |
| 549 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 550 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 554 | public void notifyDataConnection(int state, boolean isDataConnectivityPossible, |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 555 | String reason, String apn, String apnType, LinkProperties linkProperties, |
Robert Greenwalt | f9cb86a | 2014-04-08 17:34:00 -0700 | [diff] [blame] | 556 | NetworkCapabilities networkCapabilities, int networkType, boolean roaming) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 557 | if (!checkNotifyPermission("notifyDataConnection()" )) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 558 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 559 | } |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 560 | if (DBG) { |
| 561 | Slog.i(TAG, "notifyDataConnection: state=" + state + " isDataConnectivityPossible=" |
Wink Saville | 26f5a38 | 2010-11-24 16:44:29 -0800 | [diff] [blame] | 562 | + isDataConnectivityPossible + " reason='" + reason |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 563 | + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType |
| 564 | + " mRecords.size()=" + mRecords.size() + " mRecords=" + mRecords); |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 565 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 566 | synchronized (mRecords) { |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 567 | boolean modified = false; |
| 568 | if (state == TelephonyManager.DATA_CONNECTED) { |
| 569 | if (!mConnectedApns.contains(apnType)) { |
| 570 | mConnectedApns.add(apnType); |
| 571 | if (mDataConnectionState != state) { |
| 572 | mDataConnectionState = state; |
| 573 | modified = true; |
| 574 | } |
| 575 | } |
| 576 | } else { |
Robert Greenwalt | 8e7e0a9 | 2010-11-09 10:24:40 -0800 | [diff] [blame] | 577 | if (mConnectedApns.remove(apnType)) { |
| 578 | if (mConnectedApns.isEmpty()) { |
| 579 | mDataConnectionState = state; |
| 580 | modified = true; |
| 581 | } else { |
| 582 | // leave mDataConnectionState as is and |
| 583 | // send out the new status for the APN in question. |
| 584 | } |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 585 | } |
| 586 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 587 | mDataConnectionPossible = isDataConnectivityPossible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | mDataConnectionReason = reason; |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 589 | mDataConnectionLinkProperties = linkProperties; |
Robert Greenwalt | f9cb86a | 2014-04-08 17:34:00 -0700 | [diff] [blame] | 590 | mDataConnectionNetworkCapabilities = networkCapabilities; |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 591 | if (mDataConnectionNetworkType != networkType) { |
| 592 | mDataConnectionNetworkType = networkType; |
Robert Greenwalt | 8e7e0a9 | 2010-11-09 10:24:40 -0800 | [diff] [blame] | 593 | // need to tell registered listeners about the new network type |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 594 | modified = true; |
| 595 | } |
| 596 | if (modified) { |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 597 | if (DBG) { |
| 598 | Slog.d(TAG, "onDataConnectionStateChanged(" + mDataConnectionState |
yoonsung.nam | e6fa120 | 2011-08-20 21:39:12 -0700 | [diff] [blame] | 599 | + ", " + mDataConnectionNetworkType + ")"); |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 600 | } |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 601 | for (Record r : mRecords) { |
| 602 | if ((r.events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) { |
| 603 | try { |
yoonsung.nam | e6fa120 | 2011-08-20 21:39:12 -0700 | [diff] [blame] | 604 | r.callback.onDataConnectionStateChanged(mDataConnectionState, |
| 605 | mDataConnectionNetworkType); |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 606 | } catch (RemoteException ex) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 607 | mRemoveList.add(r.binder); |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 608 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | } |
| 610 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 611 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 613 | mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType, |
| 614 | apnType, apn, reason, linkProperties, ""); |
| 615 | for (Record r : mRecords) { |
| 616 | if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) { |
| 617 | try { |
| 618 | r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState); |
| 619 | } catch (RemoteException ex) { |
| 620 | mRemoveList.add(r.binder); |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 626 | broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn, |
Robert Greenwalt | f9cb86a | 2014-04-08 17:34:00 -0700 | [diff] [blame] | 627 | apnType, linkProperties, networkCapabilities, roaming); |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 628 | broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason, |
| 629 | linkProperties, ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | } |
| 631 | |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 632 | public void notifyDataConnectionFailed(String reason, String apnType) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 633 | if (!checkNotifyPermission("notifyDataConnectionFailed()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 634 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 635 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 636 | synchronized (mRecords) { |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 637 | mPreciseDataConnectionState = new PreciseDataConnectionState( |
| 638 | TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN, |
| 639 | apnType, "", reason, null, ""); |
| 640 | for (Record r : mRecords) { |
| 641 | if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) { |
| 642 | try { |
| 643 | r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState); |
| 644 | } catch (RemoteException ex) { |
| 645 | mRemoveList.add(r.binder); |
| 646 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 647 | } |
| 648 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 649 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 650 | } |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 651 | broadcastDataConnectionFailed(reason, apnType); |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 652 | broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN, |
| 653 | TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | public void notifyCellLocation(Bundle cellLocation) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 657 | if (!checkNotifyPermission("notifyCellLocation()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 658 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 659 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 660 | synchronized (mRecords) { |
| 661 | mCellLocation = cellLocation; |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 662 | for (Record r : mRecords) { |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 663 | if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 664 | try { |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 665 | if (DBG_LOC) { |
| 666 | Slog.d(TAG, "notifyCellLocation: mCellLocation=" + mCellLocation |
| 667 | + " r=" + r); |
| 668 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 669 | r.callback.onCellLocationChanged(new Bundle(cellLocation)); |
| 670 | } catch (RemoteException ex) { |
| 671 | mRemoveList.add(r.binder); |
| 672 | } |
| 673 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | } |
| 675 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 676 | handleRemoveListLocked(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 677 | } |
| 678 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 679 | |
Wink Saville | fd2d013 | 2010-10-28 14:22:26 -0700 | [diff] [blame] | 680 | public void notifyOtaspChanged(int otaspMode) { |
| 681 | if (!checkNotifyPermission("notifyOtaspChanged()" )) { |
| 682 | return; |
| 683 | } |
| 684 | synchronized (mRecords) { |
| 685 | mOtaspMode = otaspMode; |
| 686 | for (Record r : mRecords) { |
| 687 | if ((r.events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) { |
| 688 | try { |
| 689 | r.callback.onOtaspChanged(otaspMode); |
| 690 | } catch (RemoteException ex) { |
| 691 | mRemoveList.add(r.binder); |
| 692 | } |
| 693 | } |
| 694 | } |
| 695 | handleRemoveListLocked(); |
| 696 | } |
| 697 | } |
| 698 | |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 699 | public void notifyPreciseCallState(int ringingCallState, int foregroundCallState, |
| 700 | int backgroundCallState) { |
| 701 | if (!checkNotifyPermission("notifyPreciseCallState()")) { |
| 702 | return; |
| 703 | } |
| 704 | synchronized (mRecords) { |
| 705 | mRingingCallState = ringingCallState; |
| 706 | mForegroundCallState = foregroundCallState; |
| 707 | mBackgroundCallState = backgroundCallState; |
| 708 | mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState, |
| 709 | backgroundCallState, |
| 710 | DisconnectCause.NOT_VALID, |
| 711 | PreciseDisconnectCause.NOT_VALID); |
| 712 | for (Record r : mRecords) { |
| 713 | if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) { |
| 714 | try { |
| 715 | r.callback.onPreciseCallStateChanged(mPreciseCallState); |
| 716 | } catch (RemoteException ex) { |
| 717 | mRemoveList.add(r.binder); |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | handleRemoveListLocked(); |
| 722 | } |
| 723 | broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState, |
| 724 | DisconnectCause.NOT_VALID, |
| 725 | PreciseDisconnectCause.NOT_VALID); |
| 726 | } |
| 727 | |
| 728 | public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) { |
| 729 | if (!checkNotifyPermission("notifyDisconnectCause()")) { |
| 730 | return; |
| 731 | } |
| 732 | synchronized (mRecords) { |
| 733 | mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState, |
| 734 | mBackgroundCallState, disconnectCause, preciseDisconnectCause); |
| 735 | for (Record r : mRecords) { |
| 736 | if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) { |
| 737 | try { |
| 738 | r.callback.onPreciseCallStateChanged(mPreciseCallState); |
| 739 | } catch (RemoteException ex) { |
| 740 | mRemoveList.add(r.binder); |
| 741 | } |
| 742 | } |
| 743 | } |
| 744 | handleRemoveListLocked(); |
| 745 | } |
| 746 | broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState, |
| 747 | mBackgroundCallState, disconnectCause, preciseDisconnectCause); |
| 748 | } |
| 749 | |
| 750 | public void notifyPreciseDataConnectionFailed(String reason, String apnType, |
| 751 | String apn, String failCause) { |
| 752 | if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) { |
| 753 | return; |
| 754 | } |
| 755 | synchronized (mRecords) { |
| 756 | mPreciseDataConnectionState = new PreciseDataConnectionState( |
| 757 | TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN, |
| 758 | apnType, apn, reason, null, failCause); |
| 759 | for (Record r : mRecords) { |
| 760 | if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) { |
| 761 | try { |
| 762 | r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState); |
| 763 | } catch (RemoteException ex) { |
| 764 | mRemoveList.add(r.binder); |
| 765 | } |
| 766 | } |
| 767 | } |
| 768 | handleRemoveListLocked(); |
| 769 | } |
| 770 | broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN, |
| 771 | TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause); |
| 772 | } |
| 773 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 774 | @Override |
| 775 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 776 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 777 | != PackageManager.PERMISSION_GRANTED) { |
| 778 | pw.println("Permission Denial: can't dump telephony.registry from from pid=" |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 779 | + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 780 | return; |
| 781 | } |
| 782 | synchronized (mRecords) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 783 | final int recordCount = mRecords.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | pw.println("last known state:"); |
| 785 | pw.println(" mCallState=" + mCallState); |
| 786 | pw.println(" mCallIncomingNumber=" + mCallIncomingNumber); |
| 787 | pw.println(" mServiceState=" + mServiceState); |
| 788 | pw.println(" mSignalStrength=" + mSignalStrength); |
| 789 | pw.println(" mMessageWaiting=" + mMessageWaiting); |
| 790 | pw.println(" mCallForwarding=" + mCallForwarding); |
| 791 | pw.println(" mDataActivity=" + mDataActivity); |
| 792 | pw.println(" mDataConnectionState=" + mDataConnectionState); |
| 793 | pw.println(" mDataConnectionPossible=" + mDataConnectionPossible); |
| 794 | pw.println(" mDataConnectionReason=" + mDataConnectionReason); |
| 795 | pw.println(" mDataConnectionApn=" + mDataConnectionApn); |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 796 | pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties); |
Robert Greenwalt | f9cb86a | 2014-04-08 17:34:00 -0700 | [diff] [blame] | 797 | pw.println(" mDataConnectionNetworkCapabilities=" + |
| 798 | mDataConnectionNetworkCapabilities); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | pw.println(" mCellLocation=" + mCellLocation); |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 800 | pw.println(" mCellInfo=" + mCellInfo); |
Wink Saville | 070e061 | 2014-04-15 22:04:10 -0700 | [diff] [blame] | 801 | pw.println(" mDcRtInfo=" + mDcRtInfo); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 802 | pw.println("registrations: count=" + recordCount); |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 803 | for (Record r : mRecords) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 804 | pw.println(" " + r.pkgForDebug + " 0x" + Integer.toHexString(r.events)); |
| 805 | } |
| 806 | } |
| 807 | } |
| 808 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | // |
| 810 | // the legacy intent broadcasting |
| 811 | // |
| 812 | |
| 813 | private void broadcastServiceStateChanged(ServiceState state) { |
| 814 | Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); |
| 815 | Bundle data = new Bundle(); |
| 816 | state.fillInNotifierBundle(data); |
| 817 | intent.putExtras(data); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 818 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | } |
| 820 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 821 | private void broadcastSignalStrengthChanged(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 822 | long ident = Binder.clearCallingIdentity(); |
| 823 | try { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 824 | mBatteryStats.notePhoneSignalStrength(signalStrength); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 825 | } catch (RemoteException e) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 826 | /* The remote entity disappeared, we can safely ignore the exception. */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 827 | } finally { |
| 828 | Binder.restoreCallingIdentity(ident); |
| 829 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 830 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED); |
Dianne Hackborn | 1c633fc | 2009-12-08 19:45:14 -0800 | [diff] [blame] | 832 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 833 | Bundle data = new Bundle(); |
| 834 | signalStrength.fillInNotifierBundle(data); |
| 835 | intent.putExtras(data); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 836 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | private void broadcastCallStateChanged(int state, String incomingNumber) { |
| 840 | long ident = Binder.clearCallingIdentity(); |
| 841 | try { |
| 842 | if (state == TelephonyManager.CALL_STATE_IDLE) { |
| 843 | mBatteryStats.notePhoneOff(); |
| 844 | } else { |
| 845 | mBatteryStats.notePhoneOn(); |
| 846 | } |
| 847 | } catch (RemoteException e) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 848 | /* The remote entity disappeared, we can safely ignore the exception. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | } finally { |
| 850 | Binder.restoreCallingIdentity(ident); |
| 851 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 852 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 853 | Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 854 | intent.putExtra(PhoneConstants.STATE_KEY, |
| 855 | DefaultPhoneNotifier.convertCallState(state).toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 856 | if (!TextUtils.isEmpty(incomingNumber)) { |
| 857 | intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber); |
| 858 | } |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 859 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL, |
| 860 | android.Manifest.permission.READ_PHONE_STATE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | } |
| 862 | |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 863 | private void broadcastDataConnectionStateChanged(int state, |
| 864 | boolean isDataConnectivityPossible, |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 865 | String reason, String apn, String apnType, LinkProperties linkProperties, |
Robert Greenwalt | f9cb86a | 2014-04-08 17:34:00 -0700 | [diff] [blame] | 866 | NetworkCapabilities networkCapabilities, boolean roaming) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 867 | // Note: not reporting to the battery stats service here, because the |
| 868 | // status bar takes care of that after taking into account all of the |
| 869 | // required info. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 870 | Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 871 | intent.putExtra(PhoneConstants.STATE_KEY, |
| 872 | DefaultPhoneNotifier.convertDataState(state).toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 873 | if (!isDataConnectivityPossible) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 874 | intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 875 | } |
| 876 | if (reason != null) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 877 | intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 878 | } |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 879 | if (linkProperties != null) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 880 | intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties); |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 881 | String iface = linkProperties.getInterfaceName(); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 882 | if (iface != null) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 883 | intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 884 | } |
| 885 | } |
Robert Greenwalt | f9cb86a | 2014-04-08 17:34:00 -0700 | [diff] [blame] | 886 | if (networkCapabilities != null) { |
| 887 | intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities); |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 888 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 889 | if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true); |
Robert Greenwalt | a6d4248 | 2011-09-02 15:19:31 -0700 | [diff] [blame] | 890 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 891 | intent.putExtra(PhoneConstants.DATA_APN_KEY, apn); |
| 892 | intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 893 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 894 | } |
| 895 | |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 896 | private void broadcastDataConnectionFailed(String reason, String apnType) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 897 | Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 898 | intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason); |
| 899 | intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 900 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 902 | |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 903 | private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState, |
| 904 | int backgroundCallState, int disconnectCause, int preciseDisconnectCause) { |
| 905 | Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED); |
| 906 | intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState); |
| 907 | intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState); |
| 908 | intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState); |
| 909 | intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause); |
| 910 | intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause); |
| 911 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL, |
| 912 | android.Manifest.permission.READ_PRECISE_PHONE_STATE); |
| 913 | } |
| 914 | |
| 915 | private void broadcastPreciseDataConnectionStateChanged(int state, int networkType, |
| 916 | String apnType, String apn, String reason, LinkProperties linkProperties, String failCause) { |
| 917 | Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED); |
| 918 | intent.putExtra(PhoneConstants.STATE_KEY, state); |
| 919 | intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType); |
| 920 | if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason); |
| 921 | if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType); |
| 922 | if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn); |
| 923 | if (linkProperties != null) intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties); |
| 924 | if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause); |
| 925 | |
| 926 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL, |
| 927 | android.Manifest.permission.READ_PRECISE_PHONE_STATE); |
| 928 | } |
| 929 | |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 930 | private boolean checkNotifyPermission(String method) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 931 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 932 | == PackageManager.PERMISSION_GRANTED) { |
| 933 | return true; |
| 934 | } |
| 935 | String msg = "Modify Phone State Permission Denial: " + method + " from pid=" |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 936 | + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid(); |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 937 | if (DBG) Slog.w(TAG, msg); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 938 | return false; |
| 939 | } |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 940 | |
| 941 | private void checkListenerPermission(int events) { |
| 942 | if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) { |
| 943 | mContext.enforceCallingOrSelfPermission( |
| 944 | android.Manifest.permission.ACCESS_COARSE_LOCATION, null); |
| 945 | |
| 946 | } |
| 947 | |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 948 | if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) { |
| 949 | mContext.enforceCallingOrSelfPermission( |
| 950 | android.Manifest.permission.ACCESS_COARSE_LOCATION, null); |
| 951 | |
| 952 | } |
| 953 | |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 954 | if ((events & PHONE_STATE_PERMISSION_MASK) != 0) { |
| 955 | mContext.enforceCallingOrSelfPermission( |
| 956 | android.Manifest.permission.READ_PHONE_STATE, null); |
| 957 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 958 | |
| 959 | if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) { |
| 960 | mContext.enforceCallingOrSelfPermission( |
| 961 | android.Manifest.permission.READ_PRECISE_PHONE_STATE, null); |
| 962 | |
| 963 | } |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 964 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 965 | |
| 966 | private void handleRemoveListLocked() { |
| 967 | if (mRemoveList.size() > 0) { |
| 968 | for (IBinder b: mRemoveList) { |
| 969 | remove(b); |
| 970 | } |
| 971 | mRemoveList.clear(); |
| 972 | } |
| 973 | } |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 974 | |
| 975 | private boolean validateEventsAndUserLocked(Record r, int events) { |
| 976 | int foregroundUser; |
| 977 | long callingIdentity = Binder.clearCallingIdentity(); |
| 978 | boolean valid = false; |
| 979 | try { |
| 980 | foregroundUser = ActivityManager.getCurrentUser(); |
| 981 | valid = r.callerUid == foregroundUser && (r.events & events) != 0; |
| 982 | if (DBG | DBG_LOC) { |
| 983 | Slog.d(TAG, "validateEventsAndUserLocked: valid=" + valid |
| 984 | + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser |
| 985 | + " r.events=" + r.events + " events=" + events); |
| 986 | } |
| 987 | } finally { |
| 988 | Binder.restoreCallingIdentity(callingIdentity); |
| 989 | } |
| 990 | return valid; |
| 991 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 992 | } |