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