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