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 | |
Malcolm Chen | 5d35461 | 2019-11-06 15:03:23 -0800 | [diff] [blame] | 19 | import static android.telephony.TelephonyManager.ACTION_MULTI_SIM_CONFIG_CHANGED; |
Meng Wang | 62d2ff8 | 2019-12-04 18:02:55 -0800 | [diff] [blame] | 20 | import static android.telephony.TelephonyRegistryManager.SIM_ACTIVATION_TYPE_DATA; |
| 21 | import static android.telephony.TelephonyRegistryManager.SIM_ACTIVATION_TYPE_VOICE; |
Malcolm Chen | 5d35461 | 2019-11-06 15:03:23 -0800 | [diff] [blame] | 22 | |
| 23 | import static java.util.Arrays.copyOf; |
| 24 | |
Philip P. Moltmann | 33692f7 | 2019-10-03 11:56:11 -0700 | [diff] [blame] | 25 | import android.annotation.Nullable; |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 26 | import android.app.ActivityManager; |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 28 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 31 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.content.pm.PackageManager; |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 33 | import android.net.LinkProperties; |
Robert Greenwalt | f9cb86a | 2014-04-08 17:34:00 -0700 | [diff] [blame] | 34 | import android.net.NetworkCapabilities; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.os.Binder; |
Hall Liu | ee31373 | 2018-11-27 14:36:51 -0800 | [diff] [blame] | 36 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.os.Bundle; |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 38 | import android.os.Handler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.os.IBinder; |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 40 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.os.RemoteException; |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 42 | import android.os.UserHandle; |
zoey chen | c722b45 | 2019-12-03 17:23:22 +0800 | [diff] [blame] | 43 | import android.telephony.Annotation; |
Chen Xu | c9d4ee1 | 2019-09-26 16:11:59 -0700 | [diff] [blame] | 44 | import android.telephony.Annotation.DataFailureCause; |
| 45 | import android.telephony.Annotation.RadioPowerState; |
| 46 | import android.telephony.Annotation.SrvccState; |
Jordan Liu | 8218ddd | 2018-11-28 11:22:39 -0800 | [diff] [blame] | 47 | import android.telephony.CallAttributes; |
| 48 | import android.telephony.CallQuality; |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 49 | import android.telephony.CellInfo; |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 50 | import android.telephony.CellLocation; |
chen xu | 16e24cd | 2018-12-11 18:09:41 -0800 | [diff] [blame] | 51 | import android.telephony.DataFailCause; |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 52 | import android.telephony.DisconnectCause; |
Hall Liu | 5fb337f | 2017-11-22 17:38:15 -0800 | [diff] [blame] | 53 | import android.telephony.LocationAccessPolicy; |
Malcolm Chen | e162365 | 2018-08-08 20:27:45 -0700 | [diff] [blame] | 54 | import android.telephony.PhoneCapability; |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 55 | import android.telephony.PhoneStateListener; |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 56 | import android.telephony.PreciseCallState; |
| 57 | import android.telephony.PreciseDataConnectionState; |
| 58 | import android.telephony.PreciseDisconnectCause; |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 59 | import android.telephony.Rlog; |
| 60 | import android.telephony.ServiceState; |
| 61 | import android.telephony.SignalStrength; |
| 62 | import android.telephony.SubscriptionManager; |
| 63 | import android.telephony.TelephonyManager; |
chen xu | 16e24cd | 2018-12-11 18:09:41 -0800 | [diff] [blame] | 64 | import android.telephony.data.ApnSetting; |
sqian | bdc5a73 | 2018-10-26 13:27:51 -0700 | [diff] [blame] | 65 | import android.telephony.emergency.EmergencyNumber; |
chen xu | 6ac5fc1 | 2019-01-24 14:14:13 -0800 | [diff] [blame] | 66 | import android.telephony.ims.ImsReasonInfo; |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 67 | import android.util.LocalLog; |
Yangster | 4ccebea | 2018-10-09 17:09:02 -0700 | [diff] [blame] | 68 | import android.util.StatsLog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | |
Malcolm Chen | 3ceeedd | 2018-08-27 20:38:29 -0700 | [diff] [blame] | 70 | import com.android.internal.annotations.VisibleForTesting; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import com.android.internal.app.IBatteryStats; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 72 | import com.android.internal.telephony.IOnSubscriptionsChangedListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | import com.android.internal.telephony.IPhoneStateListener; |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 74 | import com.android.internal.telephony.ITelephonyRegistry; |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 75 | import com.android.internal.telephony.PhoneConstants; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | d7bf38a | 2018-02-13 18:11:37 -0800 | [diff] [blame] | 77 | import com.android.internal.telephony.TelephonyPermissions; |
chen xu | badf2b0 | 2019-04-26 17:45:26 -0700 | [diff] [blame] | 78 | import com.android.internal.util.ArrayUtils; |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 79 | import com.android.internal.util.DumpUtils; |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 80 | import com.android.internal.util.IndentingPrintWriter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | import com.android.server.am.BatteryStatsService; |
| 82 | |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 83 | import java.io.FileDescriptor; |
| 84 | import java.io.PrintWriter; |
| 85 | import java.util.ArrayList; |
chen xu | 5b98d40 | 2019-03-22 16:56:34 -0700 | [diff] [blame] | 86 | import java.util.Arrays; |
sqian | 9f93a12 | 2018-12-03 22:40:41 -0800 | [diff] [blame] | 87 | import java.util.HashMap; |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 88 | import java.util.List; |
sqian | 9f93a12 | 2018-12-03 22:40:41 -0800 | [diff] [blame] | 89 | import java.util.Map; |
Malcolm Chen | abbfac2 | 2018-02-12 19:15:59 -0800 | [diff] [blame] | 90 | import java.util.NoSuchElementException; |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 91 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | /** |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 93 | * Since phone process can be restarted, this class provides a centralized place |
| 94 | * that applications can register and be called back from. |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 95 | * |
| 96 | * Change-Id: I450c968bda93767554b5188ee63e10c9f43c5aa4 fixes bugs 16148026 |
| 97 | * and 15973975 by saving the phoneId of the registrant and then using the |
| 98 | * phoneId when deciding to to make a callback. This is necessary because |
| 99 | * a subId changes from to a dummy value when a SIM is removed and thus won't |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 100 | * compare properly. Because SubscriptionManager.getPhoneId(int subId) handles |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 101 | * the dummy value conversion we properly do the callbacks. |
| 102 | * |
| 103 | * Eventually we may want to remove the notion of dummy value but for now this |
| 104 | * looks like the best approach. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | */ |
Malcolm Chen | 3ceeedd | 2018-08-27 20:38:29 -0700 | [diff] [blame] | 106 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 107 | public class TelephonyRegistry extends ITelephonyRegistry.Stub { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | private static final String TAG = "TelephonyRegistry"; |
Wink Saville | 6d13bc8 | 2014-08-01 11:13:40 -0700 | [diff] [blame] | 109 | private static final boolean DBG = false; // STOPSHIP if true |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 110 | private static final boolean DBG_LOC = false; // STOPSHIP if true |
Wink Saville | 6d13bc8 | 2014-08-01 11:13:40 -0700 | [diff] [blame] | 111 | private static final boolean VDBG = false; // STOPSHIP if true |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | |
| 113 | private static class Record { |
Jeff Davidson | 29da89f | 2018-02-28 17:50:16 -0800 | [diff] [blame] | 114 | Context context; |
| 115 | |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 116 | String callingPackage; |
Philip P. Moltmann | 33692f7 | 2019-10-03 11:56:11 -0700 | [diff] [blame] | 117 | String callingFeatureId; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | IBinder binder; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 120 | |
Malcolm Chen | abbfac2 | 2018-02-12 19:15:59 -0800 | [diff] [blame] | 121 | TelephonyRegistryDeathRecipient deathRecipient; |
| 122 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | IPhoneStateListener callback; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 124 | IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback; |
Malcolm Chen | 13f31af | 2018-09-04 22:12:31 -0700 | [diff] [blame] | 125 | IOnSubscriptionsChangedListener onOpportunisticSubscriptionsChangedListenerCallback; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 126 | |
Hall Liu | 5fb337f | 2017-11-22 17:38:15 -0800 | [diff] [blame] | 127 | int callerUid; |
| 128 | int callerPid; |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 129 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | int events; |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 131 | |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 132 | int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 133 | |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 134 | int phoneId = SubscriptionManager.INVALID_PHONE_INDEX; |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 135 | |
| 136 | boolean matchPhoneStateListenerEvent(int events) { |
| 137 | return (callback != null) && ((events & this.events) != 0); |
| 138 | } |
| 139 | |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 140 | boolean matchOnSubscriptionsChangedListener() { |
| 141 | return (onSubscriptionsChangedListenerCallback != null); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 142 | } |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 143 | |
Malcolm Chen | 13f31af | 2018-09-04 22:12:31 -0700 | [diff] [blame] | 144 | boolean matchOnOpportunisticSubscriptionsChangedListener() { |
| 145 | return (onOpportunisticSubscriptionsChangedListenerCallback != null); |
| 146 | } |
| 147 | |
Tyler Gunn | f955e56 | 2018-04-26 14:43:31 -0700 | [diff] [blame] | 148 | boolean canReadCallLog() { |
Jeff Davidson | 29da89f | 2018-02-28 17:50:16 -0800 | [diff] [blame] | 149 | try { |
Tyler Gunn | f955e56 | 2018-04-26 14:43:31 -0700 | [diff] [blame] | 150 | return TelephonyPermissions.checkReadCallLog( |
Philip P. Moltmann | 33692f7 | 2019-10-03 11:56:11 -0700 | [diff] [blame] | 151 | context, subId, callerPid, callerUid, callingPackage, callingFeatureId); |
Jeff Davidson | 29da89f | 2018-02-28 17:50:16 -0800 | [diff] [blame] | 152 | } catch (SecurityException e) { |
| 153 | return false; |
| 154 | } |
| 155 | } |
| 156 | |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 157 | @Override |
| 158 | public String toString() { |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 159 | return "{callingPackage=" + callingPackage + " binder=" + binder |
| 160 | + " callback=" + callback |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 161 | + " onSubscriptionsChangedListenererCallback=" |
Malcolm Chen | 13f31af | 2018-09-04 22:12:31 -0700 | [diff] [blame] | 162 | + onSubscriptionsChangedListenerCallback |
| 163 | + " onOpportunisticSubscriptionsChangedListenererCallback=" |
| 164 | + onOpportunisticSubscriptionsChangedListenerCallback |
Hall Liu | 5fb337f | 2017-11-22 17:38:15 -0800 | [diff] [blame] | 165 | + " callerUid=" + callerUid + " subId=" + subId + " phoneId=" + phoneId |
Jeff Davidson | 29da89f | 2018-02-28 17:50:16 -0800 | [diff] [blame] | 166 | + " events=" + Integer.toHexString(events) + "}"; |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 167 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | private final Context mContext; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 171 | |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 172 | // access should be inside synchronized (mRecords) for these two fields |
| 173 | private final ArrayList<IBinder> mRemoveList = new ArrayList<IBinder>(); |
| 174 | private final ArrayList<Record> mRecords = new ArrayList<Record>(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 175 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | private final IBatteryStats mBatteryStats; |
| 177 | |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 178 | private final AppOpsManager mAppOps; |
| 179 | |
Malcolm Chen | 13f31af | 2018-09-04 22:12:31 -0700 | [diff] [blame] | 180 | private boolean mHasNotifySubscriptionInfoChangedOccurred = false; |
| 181 | |
| 182 | private boolean mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = false; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 183 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 184 | private int mNumPhones; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 185 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 186 | private int[] mCallState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 187 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 188 | private String[] mCallIncomingNumber; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 189 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 190 | private ServiceState[] mServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 191 | |
fionaxu | 12312f6 | 2016-11-14 13:32:14 -0800 | [diff] [blame] | 192 | private int[] mVoiceActivationState; |
| 193 | |
| 194 | private int[] mDataActivationState; |
| 195 | |
zxuan | 35a4702 | 2018-01-04 11:24:04 -0800 | [diff] [blame] | 196 | private boolean[] mUserMobileDataState; |
| 197 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 198 | private SignalStrength[] mSignalStrength; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 199 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 200 | private boolean[] mMessageWaiting; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 201 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 202 | private boolean[] mCallForwarding; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 203 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 204 | private int[] mDataActivity; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 205 | |
Jack Yu | b1bac54 | 2018-03-14 16:23:38 -0700 | [diff] [blame] | 206 | // Connection state of default APN type data (i.e. internet) of phones |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 207 | private int[] mDataConnectionState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 208 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 209 | private Bundle[] mCellLocation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 211 | private int[] mDataConnectionNetworkType; |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame] | 212 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 213 | private int[] mOtaspMode; |
Wink Saville | fd2d013 | 2010-10-28 14:22:26 -0700 | [diff] [blame] | 214 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 215 | private ArrayList<List<CellInfo>> mCellInfo = null; |
| 216 | |
sqian | 9f93a12 | 2018-12-03 22:40:41 -0800 | [diff] [blame] | 217 | private Map<Integer, List<EmergencyNumber>> mEmergencyNumberList; |
| 218 | |
Shuo Qian | 134334b | 2019-09-12 17:00:31 -0700 | [diff] [blame] | 219 | private EmergencyNumber[] mOutgoingSmsEmergencyNumber; |
| 220 | |
| 221 | private EmergencyNumber[] mOutgoingCallEmergencyNumber; |
| 222 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 223 | private CallQuality[] mCallQuality; |
Jordan Liu | 8218ddd | 2018-11-28 11:22:39 -0800 | [diff] [blame] | 224 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 225 | private CallAttributes[] mCallAttributes; |
Jordan Liu | 8218ddd | 2018-11-28 11:22:39 -0800 | [diff] [blame] | 226 | |
Jordan Liu | 65ed9d9 | 2019-02-19 14:42:07 -0800 | [diff] [blame] | 227 | // network type of the call associated with the mCallAttributes and mCallQuality |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 228 | private int[] mCallNetworkType; |
Jordan Liu | 65ed9d9 | 2019-02-19 14:42:07 -0800 | [diff] [blame] | 229 | |
Brad Ebinger | efed982 | 2018-10-26 10:25:57 -0700 | [diff] [blame] | 230 | private int[] mSrvccState; |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 231 | |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 232 | private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 233 | |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 234 | private int mDefaultPhoneId = SubscriptionManager.INVALID_PHONE_INDEX; |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 235 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 236 | private int[] mRingingCallState; |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 237 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 238 | private int[] mForegroundCallState; |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 239 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 240 | private int[] mBackgroundCallState; |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 241 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 242 | private PreciseCallState[] mPreciseCallState; |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 243 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 244 | private int[] mCallDisconnectCause; |
chen xu | 6a942d48 | 2018-12-12 19:59:30 -0800 | [diff] [blame] | 245 | |
chen xu | 6ac5fc1 | 2019-01-24 14:14:13 -0800 | [diff] [blame] | 246 | private List<ImsReasonInfo> mImsReasonInfo = null; |
| 247 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 248 | private int[] mCallPreciseDisconnectCause; |
chen xu | 6a942d48 | 2018-12-12 19:59:30 -0800 | [diff] [blame] | 249 | |
Andrew Flynn | 1f45264 | 2015-04-14 22:16:04 -0400 | [diff] [blame] | 250 | private boolean mCarrierNetworkChangeState = false; |
| 251 | |
Malcolm Chen | e162365 | 2018-08-08 20:27:45 -0700 | [diff] [blame] | 252 | private PhoneCapability mPhoneCapability = null; |
| 253 | |
Malcolm Chen | 026451d | 2019-02-14 19:50:19 -0800 | [diff] [blame] | 254 | private int mActiveDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Malcolm Chen | 8b53afe | 2018-09-24 20:01:32 -0700 | [diff] [blame] | 255 | |
Chen Xu | c9d4ee1 | 2019-09-26 16:11:59 -0700 | [diff] [blame] | 256 | @RadioPowerState |
Chen Xu | 7395c63 | 2018-10-17 17:53:47 +0000 | [diff] [blame] | 257 | private int mRadioPowerState = TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 258 | |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 259 | private final LocalLog mLocalLog = new LocalLog(100); |
| 260 | |
Jack Yu | 0c92c23 | 2019-04-04 15:10:17 -0700 | [diff] [blame] | 261 | private final LocalLog mListenLog = new LocalLog(100); |
| 262 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 263 | private PreciseDataConnectionState[] mPreciseDataConnectionState; |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 264 | |
Hall Liu | ee31373 | 2018-11-27 14:36:51 -0800 | [diff] [blame] | 265 | // Nothing here yet, but putting it here in case we want to add more in the future. |
| 266 | static final int ENFORCE_COARSE_LOCATION_PERMISSION_MASK = 0; |
| 267 | |
| 268 | static final int ENFORCE_FINE_LOCATION_PERMISSION_MASK = |
Hall Liu | 70bbc16 | 2018-03-02 17:44:46 -0800 | [diff] [blame] | 269 | PhoneStateListener.LISTEN_CELL_LOCATION |
| 270 | | PhoneStateListener.LISTEN_CELL_INFO; |
| 271 | |
Fyodor Kupolov | 309b2f63 | 2015-06-03 16:29:01 -0700 | [diff] [blame] | 272 | static final int ENFORCE_PHONE_STATE_PERMISSION_MASK = |
sqian | 9f93a12 | 2018-12-03 22:40:41 -0800 | [diff] [blame] | 273 | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
| 274 | | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
sqian | 9e9ed18 | 2019-03-20 16:17:09 -0700 | [diff] [blame] | 275 | | PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST; |
Fyodor Kupolov | 309b2f63 | 2015-06-03 16:29:01 -0700 | [diff] [blame] | 276 | |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 277 | static final int PRECISE_PHONE_STATE_PERMISSION_MASK = |
| 278 | PhoneStateListener.LISTEN_PRECISE_CALL_STATE | |
| 279 | PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE; |
| 280 | |
Shuo Qian | 134334b | 2019-09-12 17:00:31 -0700 | [diff] [blame] | 281 | static final int READ_ACTIVE_EMERGENCY_SESSION_PERMISSION_MASK = |
Shuo Qian | d966376 | 2019-10-04 13:20:45 -0700 | [diff] [blame] | 282 | PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_CALL |
| 283 | | PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_SMS; |
Shuo Qian | 134334b | 2019-09-12 17:00:31 -0700 | [diff] [blame] | 284 | |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 285 | private static final int MSG_USER_SWITCHED = 1; |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 286 | private static final int MSG_UPDATE_DEFAULT_SUB = 2; |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 287 | |
| 288 | private final Handler mHandler = new Handler() { |
| 289 | @Override |
| 290 | public void handleMessage(Message msg) { |
| 291 | switch (msg.what) { |
| 292 | case MSG_USER_SWITCHED: { |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 293 | if (VDBG) log("MSG_USER_SWITCHED userId=" + msg.arg1); |
Malcolm Chen | 5d35461 | 2019-11-06 15:03:23 -0800 | [diff] [blame] | 294 | int numPhones = getTelephonyManager().getPhoneCount(); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 295 | for (int sub = 0; sub < numPhones; sub++) { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 296 | TelephonyRegistry.this.notifyCellLocationForSubscriber(sub, |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 297 | mCellLocation[sub]); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 298 | } |
| 299 | break; |
| 300 | } |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 301 | case MSG_UPDATE_DEFAULT_SUB: { |
| 302 | int newDefaultPhoneId = msg.arg1; |
Taesu Lee | c955cd9 | 2019-09-23 08:06:31 +0900 | [diff] [blame] | 303 | int newDefaultSubId = msg.arg2; |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 304 | if (VDBG) { |
| 305 | log("MSG_UPDATE_DEFAULT_SUB:current mDefaultSubId=" + mDefaultSubId |
Taesu Lee | c955cd9 | 2019-09-23 08:06:31 +0900 | [diff] [blame] | 306 | + " current mDefaultPhoneId=" + mDefaultPhoneId |
| 307 | + " newDefaultSubId=" + newDefaultSubId |
| 308 | + " newDefaultPhoneId=" + newDefaultPhoneId); |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | //Due to possible risk condition,(notify call back using the new |
| 312 | //defaultSubId comes before new defaultSubId update) we need to recall all |
| 313 | //possible missed notify callback |
| 314 | synchronized (mRecords) { |
Etan Cohen | a33cf07 | 2014-09-30 10:35:24 -0700 | [diff] [blame] | 315 | for (Record r : mRecords) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 316 | if(r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
Etan Cohen | a33cf07 | 2014-09-30 10:35:24 -0700 | [diff] [blame] | 317 | checkPossibleMissNotify(r, newDefaultPhoneId); |
| 318 | } |
| 319 | } |
| 320 | handleRemoveListLocked(); |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 321 | } |
| 322 | mDefaultSubId = newDefaultSubId; |
| 323 | mDefaultPhoneId = newDefaultPhoneId; |
Jack Yu | 0c92c23 | 2019-04-04 15:10:17 -0700 | [diff] [blame] | 324 | mLocalLog.log("Default subscription updated: mDefaultPhoneId=" |
Taesu Lee | c955cd9 | 2019-09-23 08:06:31 +0900 | [diff] [blame] | 325 | + mDefaultPhoneId + ", mDefaultSubId=" + mDefaultSubId); |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | } |
| 329 | }; |
| 330 | |
Malcolm Chen | abbfac2 | 2018-02-12 19:15:59 -0800 | [diff] [blame] | 331 | private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient { |
| 332 | |
| 333 | private final IBinder binder; |
| 334 | |
| 335 | TelephonyRegistryDeathRecipient(IBinder binder) { |
| 336 | this.binder = binder; |
| 337 | } |
| 338 | |
| 339 | @Override |
| 340 | public void binderDied() { |
| 341 | if (DBG) log("binderDied " + binder); |
| 342 | remove(binder); |
| 343 | } |
| 344 | } |
| 345 | |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 346 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 347 | @Override |
| 348 | public void onReceive(Context context, Intent intent) { |
| 349 | String action = intent.getAction(); |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 350 | if (VDBG) log("mBroadcastReceiver: action=" + action); |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 351 | if (Intent.ACTION_USER_SWITCHED.equals(action)) { |
Wink Saville | eeacf93 | 2014-06-18 01:07:10 -0700 | [diff] [blame] | 352 | int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0); |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 353 | if (DBG) log("onReceive: userHandle=" + userHandle); |
Wink Saville | eeacf93 | 2014-06-18 01:07:10 -0700 | [diff] [blame] | 354 | mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED, userHandle, 0)); |
Taesu Lee | c955cd9 | 2019-09-23 08:06:31 +0900 | [diff] [blame] | 355 | } else if (action.equals(SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)) { |
| 356 | int newDefaultSubId = intent.getIntExtra( |
| 357 | SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, |
| 358 | SubscriptionManager.getDefaultSubscriptionId()); |
| 359 | int newDefaultPhoneId = intent.getIntExtra( |
Meng Wang | 92bc49b | 2019-12-09 16:06:51 -0800 | [diff] [blame] | 360 | SubscriptionManager.EXTRA_SLOT_INDEX, |
Taesu Lee | c955cd9 | 2019-09-23 08:06:31 +0900 | [diff] [blame] | 361 | SubscriptionManager.getPhoneId(newDefaultSubId)); |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 362 | if (DBG) { |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 363 | log("onReceive:current mDefaultSubId=" + mDefaultSubId |
Taesu Lee | c955cd9 | 2019-09-23 08:06:31 +0900 | [diff] [blame] | 364 | + " current mDefaultPhoneId=" + mDefaultPhoneId |
| 365 | + " newDefaultSubId=" + newDefaultSubId |
| 366 | + " newDefaultPhoneId=" + newDefaultPhoneId); |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 367 | } |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 368 | |
Taesu Lee | c955cd9 | 2019-09-23 08:06:31 +0900 | [diff] [blame] | 369 | if (validatePhoneId(newDefaultPhoneId) |
| 370 | && (newDefaultSubId != mDefaultSubId |
| 371 | || newDefaultPhoneId != mDefaultPhoneId)) { |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 372 | mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_DEFAULT_SUB, |
Taesu Lee | c955cd9 | 2019-09-23 08:06:31 +0900 | [diff] [blame] | 373 | newDefaultPhoneId, newDefaultSubId)); |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 374 | } |
Malcolm Chen | 5d35461 | 2019-11-06 15:03:23 -0800 | [diff] [blame] | 375 | } else if (action.equals(ACTION_MULTI_SIM_CONFIG_CHANGED)) { |
| 376 | onMultiSimConfigChanged(); |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | }; |
| 380 | |
Malcolm Chen | 5d35461 | 2019-11-06 15:03:23 -0800 | [diff] [blame] | 381 | private TelephonyManager getTelephonyManager() { |
| 382 | return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); |
| 383 | } |
| 384 | |
| 385 | private void onMultiSimConfigChanged() { |
| 386 | int oldNumPhones = mNumPhones; |
| 387 | mNumPhones = getTelephonyManager().getActiveModemCount(); |
| 388 | if (oldNumPhones == mNumPhones) return; |
| 389 | |
| 390 | if (DBG) { |
| 391 | log("TelephonyRegistry: activeModemCount changed from " + oldNumPhones |
| 392 | + " to " + mNumPhones); |
| 393 | } |
| 394 | mCallState = copyOf(mCallState, mNumPhones); |
| 395 | mDataActivity = copyOf(mCallState, mNumPhones); |
| 396 | mDataConnectionState = copyOf(mCallState, mNumPhones); |
| 397 | mDataConnectionNetworkType = copyOf(mCallState, mNumPhones); |
| 398 | mCallIncomingNumber = copyOf(mCallIncomingNumber, mNumPhones); |
| 399 | mServiceState = copyOf(mServiceState, mNumPhones); |
| 400 | mVoiceActivationState = copyOf(mVoiceActivationState, mNumPhones); |
| 401 | mDataActivationState = copyOf(mDataActivationState, mNumPhones); |
| 402 | mUserMobileDataState = copyOf(mUserMobileDataState, mNumPhones); |
| 403 | mSignalStrength = copyOf(mSignalStrength, mNumPhones); |
| 404 | mMessageWaiting = copyOf(mMessageWaiting, mNumPhones); |
| 405 | mCallForwarding = copyOf(mCallForwarding, mNumPhones); |
| 406 | mCellLocation = copyOf(mCellLocation, mNumPhones); |
| 407 | mSrvccState = copyOf(mSrvccState, mNumPhones); |
| 408 | mOtaspMode = copyOf(mOtaspMode, mNumPhones); |
| 409 | mPreciseCallState = copyOf(mPreciseCallState, mNumPhones); |
| 410 | mForegroundCallState = copyOf(mForegroundCallState, mNumPhones); |
| 411 | mBackgroundCallState = copyOf(mBackgroundCallState, mNumPhones); |
| 412 | mRingingCallState = copyOf(mRingingCallState, mNumPhones); |
| 413 | mCallDisconnectCause = copyOf(mCallDisconnectCause, mNumPhones); |
| 414 | mCallPreciseDisconnectCause = copyOf(mCallPreciseDisconnectCause, mNumPhones); |
| 415 | mCallQuality = copyOf(mCallQuality, mNumPhones); |
| 416 | mCallNetworkType = copyOf(mCallNetworkType, mNumPhones); |
| 417 | mCallAttributes = copyOf(mCallAttributes, mNumPhones); |
| 418 | mPreciseDataConnectionState = copyOf(mPreciseDataConnectionState, mNumPhones); |
| 419 | mOutgoingCallEmergencyNumber = copyOf(mOutgoingCallEmergencyNumber, mNumPhones); |
| 420 | mOutgoingSmsEmergencyNumber = copyOf(mOutgoingSmsEmergencyNumber, mNumPhones); |
| 421 | |
| 422 | // ds -> ss switch. |
| 423 | if (mNumPhones < oldNumPhones) { |
| 424 | cutListToSize(mCellInfo, mNumPhones); |
| 425 | cutListToSize(mImsReasonInfo, mNumPhones); |
Malcolm Chen | 5d35461 | 2019-11-06 15:03:23 -0800 | [diff] [blame] | 426 | return; |
| 427 | } |
| 428 | |
| 429 | // mNumPhones > oldNumPhones: ss -> ds switch |
| 430 | for (int i = oldNumPhones; i < mNumPhones; i++) { |
| 431 | mCallState[i] = TelephonyManager.CALL_STATE_IDLE; |
| 432 | mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE; |
| 433 | mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN; |
| 434 | mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 435 | mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 436 | mCallIncomingNumber[i] = ""; |
| 437 | mServiceState[i] = new ServiceState(); |
| 438 | mSignalStrength[i] = new SignalStrength(); |
| 439 | mUserMobileDataState[i] = false; |
| 440 | mMessageWaiting[i] = false; |
| 441 | mCallForwarding[i] = false; |
| 442 | mCellLocation[i] = new Bundle(); |
| 443 | mCellInfo.add(i, null); |
| 444 | mImsReasonInfo.add(i, null); |
| 445 | mSrvccState[i] = TelephonyManager.SRVCC_STATE_HANDOVER_NONE; |
Malcolm Chen | 5d35461 | 2019-11-06 15:03:23 -0800 | [diff] [blame] | 446 | mOtaspMode[i] = TelephonyManager.OTASP_UNKNOWN; |
| 447 | mCallDisconnectCause[i] = DisconnectCause.NOT_VALID; |
| 448 | mCallPreciseDisconnectCause[i] = PreciseDisconnectCause.NOT_VALID; |
Meng Wang | be15dba | 2019-12-10 10:54:50 -0800 | [diff] [blame] | 449 | mCallQuality[i] = createCallQuality(); |
Malcolm Chen | 5d35461 | 2019-11-06 15:03:23 -0800 | [diff] [blame] | 450 | mCallAttributes[i] = new CallAttributes(new PreciseCallState(), |
Meng Wang | be15dba | 2019-12-10 10:54:50 -0800 | [diff] [blame] | 451 | TelephonyManager.NETWORK_TYPE_UNKNOWN, createCallQuality()); |
Malcolm Chen | 5d35461 | 2019-11-06 15:03:23 -0800 | [diff] [blame] | 452 | mCallNetworkType[i] = TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 453 | mPreciseCallState[i] = new PreciseCallState(); |
| 454 | mRingingCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE; |
| 455 | mForegroundCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE; |
| 456 | mBackgroundCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE; |
| 457 | mPreciseDataConnectionState[i] = new PreciseDataConnectionState(); |
| 458 | } |
| 459 | |
| 460 | // Note that location can be null for non-phone builds like |
| 461 | // like the generic one. |
| 462 | CellLocation location = CellLocation.getEmpty(); |
| 463 | if (location != null) { |
| 464 | for (int i = oldNumPhones; i < mNumPhones; i++) { |
| 465 | location.fillInNotifierBundle(mCellLocation[i]); |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | private void cutListToSize(List list, int size) { |
| 471 | if (list == null) return; |
| 472 | |
| 473 | while (list.size() > size) { |
| 474 | list.remove(list.size() - 1); |
| 475 | } |
| 476 | } |
| 477 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 478 | // we keep a copy of all of the state so we can send it out when folks |
| 479 | // register for it |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | // |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 481 | // In these calls we call with the lock held. This is safe becasuse remote |
| 482 | // calls go through a oneway interface and local calls going through a |
| 483 | // handler before they get to app code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | |
Malcolm Chen | 3ceeedd | 2018-08-27 20:38:29 -0700 | [diff] [blame] | 485 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 486 | public TelephonyRegistry(Context context) { |
David 'Digit' Turner | 4ef8ec3 | 2009-09-25 11:33:24 -0700 | [diff] [blame] | 487 | CellLocation location = CellLocation.getEmpty(); |
| 488 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 489 | mContext = context; |
| 490 | mBatteryStats = BatteryStatsService.getService(); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 491 | |
Malcolm Chen | 5d35461 | 2019-11-06 15:03:23 -0800 | [diff] [blame] | 492 | int numPhones = getTelephonyManager().getActiveModemCount(); |
Jack Yu | b1bac54 | 2018-03-14 16:23:38 -0700 | [diff] [blame] | 493 | if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 494 | mNumPhones = numPhones; |
| 495 | mCallState = new int[numPhones]; |
| 496 | mDataActivity = new int[numPhones]; |
| 497 | mDataConnectionState = new int[numPhones]; |
| 498 | mDataConnectionNetworkType = new int[numPhones]; |
| 499 | mCallIncomingNumber = new String[numPhones]; |
| 500 | mServiceState = new ServiceState[numPhones]; |
fionaxu | 12312f6 | 2016-11-14 13:32:14 -0800 | [diff] [blame] | 501 | mVoiceActivationState = new int[numPhones]; |
| 502 | mDataActivationState = new int[numPhones]; |
zxuan | 35a4702 | 2018-01-04 11:24:04 -0800 | [diff] [blame] | 503 | mUserMobileDataState = new boolean[numPhones]; |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 504 | mSignalStrength = new SignalStrength[numPhones]; |
| 505 | mMessageWaiting = new boolean[numPhones]; |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 506 | mCallForwarding = new boolean[numPhones]; |
| 507 | mCellLocation = new Bundle[numPhones]; |
Brad Ebinger | efed982 | 2018-10-26 10:25:57 -0700 | [diff] [blame] | 508 | mSrvccState = new int[numPhones]; |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 509 | mOtaspMode = new int[numPhones]; |
| 510 | mPreciseCallState = new PreciseCallState[numPhones]; |
| 511 | mForegroundCallState = new int[numPhones]; |
| 512 | mBackgroundCallState = new int[numPhones]; |
| 513 | mRingingCallState = new int[numPhones]; |
| 514 | mCallDisconnectCause = new int[numPhones]; |
| 515 | mCallPreciseDisconnectCause = new int[numPhones]; |
| 516 | mCallQuality = new CallQuality[numPhones]; |
| 517 | mCallNetworkType = new int[numPhones]; |
| 518 | mCallAttributes = new CallAttributes[numPhones]; |
| 519 | mPreciseDataConnectionState = new PreciseDataConnectionState[numPhones]; |
| 520 | mCellInfo = new ArrayList<>(); |
| 521 | mImsReasonInfo = new ArrayList<>(); |
sqian | 9f93a12 | 2018-12-03 22:40:41 -0800 | [diff] [blame] | 522 | mEmergencyNumberList = new HashMap<>(); |
Shuo Qian | 134334b | 2019-09-12 17:00:31 -0700 | [diff] [blame] | 523 | mOutgoingCallEmergencyNumber = new EmergencyNumber[numPhones]; |
| 524 | mOutgoingSmsEmergencyNumber = new EmergencyNumber[numPhones]; |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 525 | for (int i = 0; i < numPhones; i++) { |
| 526 | mCallState[i] = TelephonyManager.CALL_STATE_IDLE; |
| 527 | mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE; |
| 528 | mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN; |
fionaxu | 12312f6 | 2016-11-14 13:32:14 -0800 | [diff] [blame] | 529 | mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 530 | mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 531 | mCallIncomingNumber[i] = ""; |
| 532 | mServiceState[i] = new ServiceState(); |
| 533 | mSignalStrength[i] = new SignalStrength(); |
zxuan | 35a4702 | 2018-01-04 11:24:04 -0800 | [diff] [blame] | 534 | mUserMobileDataState[i] = false; |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 535 | mMessageWaiting[i] = false; |
| 536 | mCallForwarding[i] = false; |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 537 | mCellLocation[i] = new Bundle(); |
| 538 | mCellInfo.add(i, null); |
chen xu | 6ac5fc1 | 2019-01-24 14:14:13 -0800 | [diff] [blame] | 539 | mImsReasonInfo.add(i, null); |
Brad Ebinger | efed982 | 2018-10-26 10:25:57 -0700 | [diff] [blame] | 540 | mSrvccState[i] = TelephonyManager.SRVCC_STATE_HANDOVER_NONE; |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 541 | mOtaspMode[i] = TelephonyManager.OTASP_UNKNOWN; |
| 542 | mCallDisconnectCause[i] = DisconnectCause.NOT_VALID; |
| 543 | mCallPreciseDisconnectCause[i] = PreciseDisconnectCause.NOT_VALID; |
Meng Wang | be15dba | 2019-12-10 10:54:50 -0800 | [diff] [blame] | 544 | mCallQuality[i] = createCallQuality(); |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 545 | mCallAttributes[i] = new CallAttributes(new PreciseCallState(), |
Meng Wang | be15dba | 2019-12-10 10:54:50 -0800 | [diff] [blame] | 546 | TelephonyManager.NETWORK_TYPE_UNKNOWN, createCallQuality()); |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 547 | mCallNetworkType[i] = TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 548 | mPreciseCallState[i] = new PreciseCallState(); |
| 549 | mRingingCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE; |
| 550 | mForegroundCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE; |
| 551 | mBackgroundCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE; |
| 552 | mPreciseDataConnectionState[i] = new PreciseDataConnectionState(); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 553 | } |
| 554 | |
David 'Digit' Turner | 4ef8ec3 | 2009-09-25 11:33:24 -0700 | [diff] [blame] | 555 | // Note that location can be null for non-phone builds like |
| 556 | // like the generic one. |
| 557 | if (location != null) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 558 | for (int i = 0; i < numPhones; i++) { |
| 559 | location.fillInNotifierBundle(mCellLocation[i]); |
| 560 | } |
David 'Digit' Turner | 4ef8ec3 | 2009-09-25 11:33:24 -0700 | [diff] [blame] | 561 | } |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 562 | |
| 563 | mAppOps = mContext.getSystemService(AppOpsManager.class); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | } |
| 565 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 566 | public void systemRunning() { |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 567 | // Watch for interesting updates |
| 568 | final IntentFilter filter = new IntentFilter(); |
| 569 | filter.addAction(Intent.ACTION_USER_SWITCHED); |
| 570 | filter.addAction(Intent.ACTION_USER_REMOVED); |
Taesu Lee | c955cd9 | 2019-09-23 08:06:31 +0900 | [diff] [blame] | 571 | filter.addAction(SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED); |
Malcolm Chen | 5d35461 | 2019-11-06 15:03:23 -0800 | [diff] [blame] | 572 | filter.addAction(ACTION_MULTI_SIM_CONFIG_CHANGED); |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 573 | log("systemRunning register for intents"); |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 574 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 575 | } |
| 576 | |
| 577 | @Override |
Philip P. Moltmann | 33692f7 | 2019-10-03 11:56:11 -0700 | [diff] [blame] | 578 | public void addOnSubscriptionsChangedListener(String callingPackage, String callingFeatureId, |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 579 | IOnSubscriptionsChangedListener callback) { |
Fyodor Kupolov | 309b2f63 | 2015-06-03 16:29:01 -0700 | [diff] [blame] | 580 | int callerUserId = UserHandle.getCallingUserId(); |
Jeff Davidson | 29da89f | 2018-02-28 17:50:16 -0800 | [diff] [blame] | 581 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 582 | if (VDBG) { |
Fyodor Kupolov | 309b2f63 | 2015-06-03 16:29:01 -0700 | [diff] [blame] | 583 | log("listen oscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId() |
| 584 | + " callerUserId=" + callerUserId + " callback=" + callback |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 585 | + " callback.asBinder=" + callback.asBinder()); |
| 586 | } |
| 587 | |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 588 | synchronized (mRecords) { |
| 589 | // register |
Malcolm Chen | abbfac2 | 2018-02-12 19:15:59 -0800 | [diff] [blame] | 590 | IBinder b = callback.asBinder(); |
| 591 | Record r = add(b); |
| 592 | |
| 593 | if (r == null) { |
| 594 | return; |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 595 | } |
| 596 | |
Jeff Davidson | 29da89f | 2018-02-28 17:50:16 -0800 | [diff] [blame] | 597 | r.context = mContext; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 598 | r.onSubscriptionsChangedListenerCallback = callback; |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 599 | r.callingPackage = callingPackage; |
Philip P. Moltmann | 33692f7 | 2019-10-03 11:56:11 -0700 | [diff] [blame] | 600 | r.callingFeatureId = callingFeatureId; |
Hall Liu | 5fb337f | 2017-11-22 17:38:15 -0800 | [diff] [blame] | 601 | r.callerUid = Binder.getCallingUid(); |
| 602 | r.callerPid = Binder.getCallingPid(); |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 603 | r.events = 0; |
| 604 | if (DBG) { |
| 605 | log("listen oscl: Register r=" + r); |
| 606 | } |
| 607 | // Always notify when registration occurs if there has been a notification. |
Malcolm Chen | 13f31af | 2018-09-04 22:12:31 -0700 | [diff] [blame] | 608 | if (mHasNotifySubscriptionInfoChangedOccurred) { |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 609 | try { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 610 | if (VDBG) log("listen oscl: send to r=" + r); |
| 611 | r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged(); |
| 612 | if (VDBG) log("listen oscl: sent to r=" + r); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 613 | } catch (RemoteException e) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 614 | if (VDBG) log("listen oscl: remote exception sending to r=" + r + " e=" + e); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 615 | remove(r.binder); |
| 616 | } |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 617 | } else { |
Malcolm Chen | 13f31af | 2018-09-04 22:12:31 -0700 | [diff] [blame] | 618 | log("listen oscl: mHasNotifySubscriptionInfoChangedOccurred==false no callback"); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 619 | } |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | |
| 623 | @Override |
Wink Saville | 071743f | 2015-01-12 17:11:04 -0800 | [diff] [blame] | 624 | public void removeOnSubscriptionsChangedListener(String pkgForDebug, |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 625 | IOnSubscriptionsChangedListener callback) { |
| 626 | if (DBG) log("listen oscl: Unregister"); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 627 | remove(callback.asBinder()); |
| 628 | } |
| 629 | |
Malcolm Chen | 13f31af | 2018-09-04 22:12:31 -0700 | [diff] [blame] | 630 | |
| 631 | @Override |
| 632 | public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage, |
Philip P. Moltmann | 33692f7 | 2019-10-03 11:56:11 -0700 | [diff] [blame] | 633 | String callingFeatureId, IOnSubscriptionsChangedListener callback) { |
Malcolm Chen | 13f31af | 2018-09-04 22:12:31 -0700 | [diff] [blame] | 634 | int callerUserId = UserHandle.getCallingUserId(); |
| 635 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 636 | if (VDBG) { |
| 637 | log("listen ooscl: E pkg=" + callingPackage + " myUserId=" + UserHandle.myUserId() |
| 638 | + " callerUserId=" + callerUserId + " callback=" + callback |
| 639 | + " callback.asBinder=" + callback.asBinder()); |
| 640 | } |
| 641 | |
| 642 | synchronized (mRecords) { |
| 643 | // register |
| 644 | IBinder b = callback.asBinder(); |
| 645 | Record r = add(b); |
| 646 | |
| 647 | if (r == null) { |
| 648 | return; |
| 649 | } |
| 650 | |
| 651 | r.context = mContext; |
| 652 | r.onOpportunisticSubscriptionsChangedListenerCallback = callback; |
| 653 | r.callingPackage = callingPackage; |
Philip P. Moltmann | 33692f7 | 2019-10-03 11:56:11 -0700 | [diff] [blame] | 654 | r.callingFeatureId = callingFeatureId; |
Malcolm Chen | 13f31af | 2018-09-04 22:12:31 -0700 | [diff] [blame] | 655 | r.callerUid = Binder.getCallingUid(); |
| 656 | r.callerPid = Binder.getCallingPid(); |
| 657 | r.events = 0; |
| 658 | if (DBG) { |
| 659 | log("listen ooscl: Register r=" + r); |
| 660 | } |
| 661 | // Always notify when registration occurs if there has been a notification. |
| 662 | if (mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) { |
| 663 | try { |
| 664 | if (VDBG) log("listen ooscl: send to r=" + r); |
| 665 | r.onOpportunisticSubscriptionsChangedListenerCallback.onSubscriptionsChanged(); |
| 666 | if (VDBG) log("listen ooscl: sent to r=" + r); |
| 667 | } catch (RemoteException e) { |
| 668 | if (VDBG) log("listen ooscl: remote exception sending to r=" + r + " e=" + e); |
| 669 | remove(r.binder); |
| 670 | } |
| 671 | } else { |
| 672 | log("listen ooscl: hasNotifyOpptSubInfoChangedOccurred==false no callback"); |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 677 | @Override |
| 678 | public void notifySubscriptionInfoChanged() { |
| 679 | if (VDBG) log("notifySubscriptionInfoChanged:"); |
| 680 | synchronized (mRecords) { |
Malcolm Chen | 13f31af | 2018-09-04 22:12:31 -0700 | [diff] [blame] | 681 | if (!mHasNotifySubscriptionInfoChangedOccurred) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 682 | log("notifySubscriptionInfoChanged: first invocation mRecords.size=" |
| 683 | + mRecords.size()); |
| 684 | } |
Malcolm Chen | 13f31af | 2018-09-04 22:12:31 -0700 | [diff] [blame] | 685 | mHasNotifySubscriptionInfoChangedOccurred = true; |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 686 | mRemoveList.clear(); |
| 687 | for (Record r : mRecords) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 688 | if (r.matchOnSubscriptionsChangedListener()) { |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 689 | try { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 690 | if (VDBG) log("notifySubscriptionInfoChanged: call osc to r=" + r); |
| 691 | r.onSubscriptionsChangedListenerCallback.onSubscriptionsChanged(); |
| 692 | if (VDBG) log("notifySubscriptionInfoChanged: done osc to r=" + r); |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 693 | } catch (RemoteException ex) { |
| 694 | if (VDBG) log("notifySubscriptionInfoChanged: RemoteException r=" + r); |
| 695 | mRemoveList.add(r.binder); |
| 696 | } |
| 697 | } |
| 698 | } |
| 699 | handleRemoveListLocked(); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | @Override |
Malcolm Chen | 13f31af | 2018-09-04 22:12:31 -0700 | [diff] [blame] | 704 | public void notifyOpportunisticSubscriptionInfoChanged() { |
| 705 | if (VDBG) log("notifyOpptSubscriptionInfoChanged:"); |
| 706 | synchronized (mRecords) { |
| 707 | if (!mHasNotifyOpportunisticSubscriptionInfoChangedOccurred) { |
| 708 | log("notifyOpptSubscriptionInfoChanged: first invocation mRecords.size=" |
| 709 | + mRecords.size()); |
| 710 | } |
| 711 | mHasNotifyOpportunisticSubscriptionInfoChangedOccurred = true; |
| 712 | mRemoveList.clear(); |
| 713 | for (Record r : mRecords) { |
| 714 | if (r.matchOnOpportunisticSubscriptionsChangedListener()) { |
| 715 | try { |
| 716 | if (VDBG) log("notifyOpptSubChanged: call oosc to r=" + r); |
| 717 | r.onOpportunisticSubscriptionsChangedListenerCallback |
| 718 | .onSubscriptionsChanged(); |
| 719 | if (VDBG) log("notifyOpptSubChanged: done oosc to r=" + r); |
| 720 | } catch (RemoteException ex) { |
| 721 | if (VDBG) log("notifyOpptSubChanged: RemoteException r=" + r); |
| 722 | mRemoveList.add(r.binder); |
| 723 | } |
| 724 | } |
| 725 | } |
| 726 | handleRemoveListLocked(); |
| 727 | } |
| 728 | } |
| 729 | |
Philip P. Moltmann | 33692f7 | 2019-10-03 11:56:11 -0700 | [diff] [blame] | 730 | @Deprecated |
Malcolm Chen | 13f31af | 2018-09-04 22:12:31 -0700 | [diff] [blame] | 731 | @Override |
Philip P. Moltmann | 33692f7 | 2019-10-03 11:56:11 -0700 | [diff] [blame] | 732 | public void listen(String callingPackage, IPhoneStateListener callback, int events, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 733 | boolean notifyNow) { |
Philip P. Moltmann | 33692f7 | 2019-10-03 11:56:11 -0700 | [diff] [blame] | 734 | listenWithFeature(callingPackage, null, callback, events, notifyNow); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | @Override |
Philip P. Moltmann | 33692f7 | 2019-10-03 11:56:11 -0700 | [diff] [blame] | 738 | public void listenWithFeature(String callingPackage, String callingFeatureId, |
| 739 | IPhoneStateListener callback, int events, boolean notifyNow) { |
| 740 | listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, callingPackage, |
| 741 | callingFeatureId, callback, events, notifyNow); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Philip P. Moltmann | 33692f7 | 2019-10-03 11:56:11 -0700 | [diff] [blame] | 744 | @Override |
| 745 | public void listenForSubscriber(int subId, String callingPackage, String callingFeatureId, |
| 746 | IPhoneStateListener callback, int events, boolean notifyNow) { |
| 747 | listen(callingPackage, callingFeatureId, callback, events, notifyNow, subId); |
| 748 | } |
| 749 | |
| 750 | private void listen(String callingPackage, @Nullable String callingFeatureId, |
| 751 | IPhoneStateListener callback, int events, boolean notifyNow, int subId) { |
Fyodor Kupolov | 309b2f63 | 2015-06-03 16:29:01 -0700 | [diff] [blame] | 752 | int callerUserId = UserHandle.getCallingUserId(); |
Jeff Davidson | 29da89f | 2018-02-28 17:50:16 -0800 | [diff] [blame] | 753 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jack Yu | 0c92c23 | 2019-04-04 15:10:17 -0700 | [diff] [blame] | 754 | String str = "listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events) |
Fyodor Kupolov | 309b2f63 | 2015-06-03 16:29:01 -0700 | [diff] [blame] | 755 | + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId=" |
Jack Yu | 0c92c23 | 2019-04-04 15:10:17 -0700 | [diff] [blame] | 756 | + UserHandle.myUserId() + " callerUserId=" + callerUserId; |
| 757 | mListenLog.log(str); |
| 758 | if (VDBG) { |
| 759 | log(str); |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 760 | } |
xinhe | 75c2c15 | 2014-10-16 11:49:45 -0700 | [diff] [blame] | 761 | |
| 762 | if (events != PhoneStateListener.LISTEN_NONE) { |
Jeff Davidson | d7bf38a | 2018-02-13 18:11:37 -0800 | [diff] [blame] | 763 | // Checks permission and throws SecurityException for disallowed operations. For pre-M |
| 764 | // apps whose runtime permission has been revoked, we return immediately to skip sending |
| 765 | // events to the app without crashing it. |
Philip P. Moltmann | 33692f7 | 2019-10-03 11:56:11 -0700 | [diff] [blame] | 766 | if (!checkListenerPermission(events, subId, callingPackage, callingFeatureId, |
| 767 | "listen")) { |
Jeff Davidson | d7bf38a | 2018-02-13 18:11:37 -0800 | [diff] [blame] | 768 | return; |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 769 | } |
| 770 | |
yifan.bai | e620ce7 | 2017-12-22 14:59:57 +0800 | [diff] [blame] | 771 | int phoneId = SubscriptionManager.getPhoneId(subId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | synchronized (mRecords) { |
| 773 | // register |
Malcolm Chen | abbfac2 | 2018-02-12 19:15:59 -0800 | [diff] [blame] | 774 | IBinder b = callback.asBinder(); |
| 775 | Record r = add(b); |
| 776 | |
| 777 | if (r == null) { |
| 778 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 779 | } |
xinhe | 43c5029 | 2014-09-18 17:56:48 -0700 | [diff] [blame] | 780 | |
Jeff Davidson | 29da89f | 2018-02-28 17:50:16 -0800 | [diff] [blame] | 781 | r.context = mContext; |
xinhe | 75c2c15 | 2014-10-16 11:49:45 -0700 | [diff] [blame] | 782 | r.callback = callback; |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 783 | r.callingPackage = callingPackage; |
Philip P. Moltmann | 33692f7 | 2019-10-03 11:56:11 -0700 | [diff] [blame] | 784 | r.callingFeatureId = callingFeatureId; |
Hall Liu | 5fb337f | 2017-11-22 17:38:15 -0800 | [diff] [blame] | 785 | r.callerUid = Binder.getCallingUid(); |
| 786 | r.callerPid = Binder.getCallingPid(); |
xinhe | 75c2c15 | 2014-10-16 11:49:45 -0700 | [diff] [blame] | 787 | // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID, |
| 788 | // force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID |
Wink Saville | a54bf65 | 2014-12-11 13:37:50 -0800 | [diff] [blame] | 789 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 790 | r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID; |
xinhe | 75c2c15 | 2014-10-16 11:49:45 -0700 | [diff] [blame] | 791 | } else {//APP specify subID |
| 792 | r.subId = subId; |
| 793 | } |
yifan.bai | e620ce7 | 2017-12-22 14:59:57 +0800 | [diff] [blame] | 794 | r.phoneId = phoneId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 795 | r.events = events; |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 796 | if (DBG) { |
xinhe | 75c2c15 | 2014-10-16 11:49:45 -0700 | [diff] [blame] | 797 | log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId); |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 798 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 799 | if (notifyNow && validatePhoneId(phoneId)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 801 | try { |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 802 | if (VDBG) log("listen: call onSSC state=" + mServiceState[phoneId]); |
Hall Liu | ee31373 | 2018-11-27 14:36:51 -0800 | [diff] [blame] | 803 | ServiceState rawSs = new ServiceState(mServiceState[phoneId]); |
| 804 | if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) { |
| 805 | r.callback.onServiceStateChanged(rawSs); |
| 806 | } else if (checkCoarseLocationAccess(r, Build.VERSION_CODES.Q)) { |
| 807 | r.callback.onServiceStateChanged(rawSs.sanitizeLocationInfo(false)); |
| 808 | } else { |
| 809 | r.callback.onServiceStateChanged(rawSs.sanitizeLocationInfo(true)); |
| 810 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 811 | } catch (RemoteException ex) { |
| 812 | remove(r.binder); |
| 813 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 814 | } |
| 815 | if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) { |
| 816 | try { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 817 | int gsmSignalStrength = mSignalStrength[phoneId] |
| 818 | .getGsmSignalStrength(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 819 | r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1 |
| 820 | : gsmSignalStrength)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 821 | } catch (RemoteException ex) { |
| 822 | remove(r.binder); |
| 823 | } |
| 824 | } |
| 825 | if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) { |
| 826 | try { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 827 | r.callback.onMessageWaitingIndicatorChanged( |
| 828 | mMessageWaiting[phoneId]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 829 | } catch (RemoteException ex) { |
| 830 | remove(r.binder); |
| 831 | } |
| 832 | } |
| 833 | if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) { |
| 834 | try { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 835 | r.callback.onCallForwardingIndicatorChanged( |
| 836 | mCallForwarding[phoneId]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | } catch (RemoteException ex) { |
| 838 | remove(r.binder); |
| 839 | } |
| 840 | } |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 841 | if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 842 | try { |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 843 | if (DBG_LOC) log("listen: mCellLocation = " |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 844 | + mCellLocation[phoneId]); |
Hall Liu | ee31373 | 2018-11-27 14:36:51 -0800 | [diff] [blame] | 845 | if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) { |
Hall Liu | 5fb337f | 2017-11-22 17:38:15 -0800 | [diff] [blame] | 846 | r.callback.onCellLocationChanged( |
| 847 | new Bundle(mCellLocation[phoneId])); |
| 848 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 849 | } catch (RemoteException ex) { |
| 850 | remove(r.binder); |
| 851 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | } |
| 853 | if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) { |
| 854 | try { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 855 | r.callback.onCallStateChanged(mCallState[phoneId], |
Fyodor Kupolov | 309b2f63 | 2015-06-03 16:29:01 -0700 | [diff] [blame] | 856 | getCallIncomingNumber(r, phoneId)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 857 | } catch (RemoteException ex) { |
| 858 | remove(r.binder); |
| 859 | } |
| 860 | } |
| 861 | if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) { |
| 862 | try { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 863 | r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId], |
| 864 | mDataConnectionNetworkType[phoneId]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 865 | } catch (RemoteException ex) { |
| 866 | remove(r.binder); |
| 867 | } |
| 868 | } |
| 869 | if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) { |
| 870 | try { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 871 | r.callback.onDataActivity(mDataActivity[phoneId]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 872 | } catch (RemoteException ex) { |
| 873 | remove(r.binder); |
| 874 | } |
| 875 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 876 | if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) { |
| 877 | try { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 878 | r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 879 | } catch (RemoteException ex) { |
| 880 | remove(r.binder); |
| 881 | } |
| 882 | } |
Wink Saville | fd2d013 | 2010-10-28 14:22:26 -0700 | [diff] [blame] | 883 | if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) { |
| 884 | try { |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 885 | r.callback.onOtaspChanged(mOtaspMode[phoneId]); |
Wink Saville | fd2d013 | 2010-10-28 14:22:26 -0700 | [diff] [blame] | 886 | } catch (RemoteException ex) { |
| 887 | remove(r.binder); |
| 888 | } |
| 889 | } |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 890 | if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) { |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 891 | try { |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 892 | if (DBG_LOC) log("listen: mCellInfo[" + phoneId + "] = " |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 893 | + mCellInfo.get(phoneId)); |
Hall Liu | ee31373 | 2018-11-27 14:36:51 -0800 | [diff] [blame] | 894 | if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) { |
Hall Liu | 5fb337f | 2017-11-22 17:38:15 -0800 | [diff] [blame] | 895 | r.callback.onCellInfoChanged(mCellInfo.get(phoneId)); |
| 896 | } |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 897 | } catch (RemoteException ex) { |
| 898 | remove(r.binder); |
| 899 | } |
| 900 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 901 | if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) { |
| 902 | try { |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 903 | r.callback.onPreciseCallStateChanged(mPreciseCallState[phoneId]); |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 904 | } catch (RemoteException ex) { |
| 905 | remove(r.binder); |
| 906 | } |
| 907 | } |
chen xu | 6a942d48 | 2018-12-12 19:59:30 -0800 | [diff] [blame] | 908 | if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) { |
| 909 | try { |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 910 | r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause[phoneId], |
| 911 | mCallPreciseDisconnectCause[phoneId]); |
chen xu | 6a942d48 | 2018-12-12 19:59:30 -0800 | [diff] [blame] | 912 | } catch (RemoteException ex) { |
| 913 | remove(r.binder); |
| 914 | } |
| 915 | } |
chen xu | 6ac5fc1 | 2019-01-24 14:14:13 -0800 | [diff] [blame] | 916 | if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) { |
| 917 | try { |
| 918 | r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId)); |
| 919 | } catch (RemoteException ex) { |
| 920 | remove(r.binder); |
| 921 | } |
| 922 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 923 | if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) { |
| 924 | try { |
| 925 | r.callback.onPreciseDataConnectionStateChanged( |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 926 | mPreciseDataConnectionState[phoneId]); |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 927 | } catch (RemoteException ex) { |
| 928 | remove(r.binder); |
| 929 | } |
| 930 | } |
Andrew Flynn | 1f45264 | 2015-04-14 22:16:04 -0400 | [diff] [blame] | 931 | if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) { |
| 932 | try { |
| 933 | r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState); |
| 934 | } catch (RemoteException ex) { |
| 935 | remove(r.binder); |
| 936 | } |
| 937 | } |
fionaxu | 12312f6 | 2016-11-14 13:32:14 -0800 | [diff] [blame] | 938 | if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) !=0) { |
| 939 | try { |
| 940 | r.callback.onVoiceActivationStateChanged(mVoiceActivationState[phoneId]); |
| 941 | } catch (RemoteException ex) { |
| 942 | remove(r.binder); |
| 943 | } |
| 944 | } |
| 945 | if ((events & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) !=0) { |
| 946 | try { |
| 947 | r.callback.onDataActivationStateChanged(mDataActivationState[phoneId]); |
| 948 | } catch (RemoteException ex) { |
| 949 | remove(r.binder); |
| 950 | } |
| 951 | } |
zxuan | 35a4702 | 2018-01-04 11:24:04 -0800 | [diff] [blame] | 952 | if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) { |
| 953 | try { |
| 954 | r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]); |
| 955 | } catch (RemoteException ex) { |
| 956 | remove(r.binder); |
| 957 | } |
| 958 | } |
sqian | 9f93a12 | 2018-12-03 22:40:41 -0800 | [diff] [blame] | 959 | if ((events & PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST) != 0) { |
| 960 | try { |
| 961 | r.callback.onEmergencyNumberListChanged(mEmergencyNumberList); |
| 962 | } catch (RemoteException ex) { |
| 963 | remove(r.binder); |
| 964 | } |
| 965 | } |
Malcolm Chen | e162365 | 2018-08-08 20:27:45 -0700 | [diff] [blame] | 966 | if ((events & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) { |
| 967 | try { |
| 968 | r.callback.onPhoneCapabilityChanged(mPhoneCapability); |
| 969 | } catch (RemoteException ex) { |
| 970 | remove(r.binder); |
| 971 | } |
| 972 | } |
Nazanin Bakhshi | 026c42d | 2019-03-01 10:10:22 -0800 | [diff] [blame] | 973 | if ((events & PhoneStateListener |
Malcolm Chen | f028c3b | 2019-09-04 16:10:34 -0700 | [diff] [blame] | 974 | .LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE) != 0) { |
Malcolm Chen | 8b53afe | 2018-09-24 20:01:32 -0700 | [diff] [blame] | 975 | try { |
Malcolm Chen | 026451d | 2019-02-14 19:50:19 -0800 | [diff] [blame] | 976 | r.callback.onActiveDataSubIdChanged(mActiveDataSubId); |
Malcolm Chen | 8b53afe | 2018-09-24 20:01:32 -0700 | [diff] [blame] | 977 | } catch (RemoteException ex) { |
| 978 | remove(r.binder); |
| 979 | } |
| 980 | } |
Chen Xu | 7395c63 | 2018-10-17 17:53:47 +0000 | [diff] [blame] | 981 | if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) { |
| 982 | try { |
| 983 | r.callback.onRadioPowerStateChanged(mRadioPowerState); |
| 984 | } catch (RemoteException ex) { |
| 985 | remove(r.binder); |
| 986 | } |
| 987 | } |
Brad Ebinger | efed982 | 2018-10-26 10:25:57 -0700 | [diff] [blame] | 988 | if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) { |
| 989 | try { |
| 990 | r.callback.onSrvccStateChanged(mSrvccState[phoneId]); |
| 991 | } catch (RemoteException ex) { |
| 992 | remove(r.binder); |
| 993 | } |
| 994 | } |
Jordan Liu | 8218ddd | 2018-11-28 11:22:39 -0800 | [diff] [blame] | 995 | if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) { |
| 996 | try { |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 997 | r.callback.onCallAttributesChanged(mCallAttributes[phoneId]); |
Jordan Liu | 8218ddd | 2018-11-28 11:22:39 -0800 | [diff] [blame] | 998 | } catch (RemoteException ex) { |
| 999 | remove(r.binder); |
| 1000 | } |
| 1001 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1002 | } |
| 1003 | } |
| 1004 | } else { |
xinhe | 75c2c15 | 2014-10-16 11:49:45 -0700 | [diff] [blame] | 1005 | if(DBG) log("listen: Unregister"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1006 | remove(callback.asBinder()); |
| 1007 | } |
| 1008 | } |
| 1009 | |
Fyodor Kupolov | 309b2f63 | 2015-06-03 16:29:01 -0700 | [diff] [blame] | 1010 | private String getCallIncomingNumber(Record record, int phoneId) { |
Tyler Gunn | f955e56 | 2018-04-26 14:43:31 -0700 | [diff] [blame] | 1011 | // Only reveal the incoming number if the record has read call log permission. |
| 1012 | return record.canReadCallLog() ? mCallIncomingNumber[phoneId] : ""; |
Fyodor Kupolov | 309b2f63 | 2015-06-03 16:29:01 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
Malcolm Chen | abbfac2 | 2018-02-12 19:15:59 -0800 | [diff] [blame] | 1015 | private Record add(IBinder binder) { |
| 1016 | Record r; |
| 1017 | |
| 1018 | synchronized (mRecords) { |
| 1019 | final int N = mRecords.size(); |
| 1020 | for (int i = 0; i < N; i++) { |
| 1021 | r = mRecords.get(i); |
| 1022 | if (binder == r.binder) { |
| 1023 | // Already existed. |
| 1024 | return r; |
| 1025 | } |
| 1026 | } |
| 1027 | r = new Record(); |
| 1028 | r.binder = binder; |
| 1029 | r.deathRecipient = new TelephonyRegistryDeathRecipient(binder); |
| 1030 | |
| 1031 | try { |
| 1032 | binder.linkToDeath(r.deathRecipient, 0); |
| 1033 | } catch (RemoteException e) { |
| 1034 | if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e); |
| 1035 | // Binder already died. Return null. |
| 1036 | return null; |
| 1037 | } |
| 1038 | |
| 1039 | mRecords.add(r); |
| 1040 | if (DBG) log("add new record"); |
| 1041 | } |
| 1042 | |
| 1043 | return r; |
| 1044 | } |
| 1045 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | private void remove(IBinder binder) { |
| 1047 | synchronized (mRecords) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1048 | final int recordCount = mRecords.size(); |
| 1049 | for (int i = 0; i < recordCount; i++) { |
Malcolm Chen | abbfac2 | 2018-02-12 19:15:59 -0800 | [diff] [blame] | 1050 | Record r = mRecords.get(i); |
| 1051 | if (r.binder == binder) { |
xinhe | ac11ae9 | 2014-12-18 10:02:14 -0800 | [diff] [blame] | 1052 | if (DBG) { |
Malcolm Chen | abbfac2 | 2018-02-12 19:15:59 -0800 | [diff] [blame] | 1053 | log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage |
| 1054 | + " r.callback " + r.callback); |
xinhe | ac11ae9 | 2014-12-18 10:02:14 -0800 | [diff] [blame] | 1055 | } |
Malcolm Chen | abbfac2 | 2018-02-12 19:15:59 -0800 | [diff] [blame] | 1056 | |
| 1057 | if (r.deathRecipient != null) { |
| 1058 | try { |
| 1059 | binder.unlinkToDeath(r.deathRecipient, 0); |
| 1060 | } catch (NoSuchElementException e) { |
| 1061 | if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r=" |
| 1062 | + r + " e=" + e); |
| 1063 | } |
| 1064 | } |
| 1065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1066 | mRecords.remove(i); |
| 1067 | return; |
| 1068 | } |
| 1069 | } |
| 1070 | } |
| 1071 | } |
| 1072 | |
Chen Xu | 288b71c | 2019-09-15 18:28:21 -0700 | [diff] [blame] | 1073 | public void notifyCallStateForAllSubs(int state, String phoneNumber) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1074 | if (!checkNotifyPermission("notifyCallState()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 1075 | return; |
| 1076 | } |
xinhe | 43c5029 | 2014-09-18 17:56:48 -0700 | [diff] [blame] | 1077 | |
| 1078 | if (VDBG) { |
Chen Xu | 288b71c | 2019-09-15 18:28:21 -0700 | [diff] [blame] | 1079 | log("notifyCallStateForAllSubs: state=" + state + " phoneNumber=" + phoneNumber); |
xinhe | 43c5029 | 2014-09-18 17:56:48 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1082 | synchronized (mRecords) { |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 1083 | for (Record r : mRecords) { |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 1084 | if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) && |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1085 | (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1086 | try { |
Tyler Gunn | f955e56 | 2018-04-26 14:43:31 -0700 | [diff] [blame] | 1087 | // Ensure the listener has read call log permission; if they do not return |
| 1088 | // an empty phone number. |
| 1089 | String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : ""; |
| 1090 | r.callback.onCallStateChanged(state, phoneNumberOrEmpty); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1091 | } catch (RemoteException ex) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 1092 | mRemoveList.add(r.binder); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1093 | } |
| 1094 | } |
| 1095 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 1096 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1097 | } |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 1098 | |
| 1099 | // Called only by Telecomm to communicate call state across different phone accounts. So |
| 1100 | // there is no need to add a valid subId or slotId. |
Tyler Gunn | f955e56 | 2018-04-26 14:43:31 -0700 | [diff] [blame] | 1101 | broadcastCallStateChanged(state, phoneNumber, |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 1102 | SubscriptionManager.INVALID_PHONE_INDEX, |
Sharvil Nanavati | 61a3ab0 | 2015-04-23 13:57:24 -0700 | [diff] [blame] | 1103 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1104 | } |
| 1105 | |
Chen Xu | 288b71c | 2019-09-15 18:28:21 -0700 | [diff] [blame] | 1106 | public void notifyCallState(int phoneId, int subId, int state, String incomingNumber) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1107 | if (!checkNotifyPermission("notifyCallState()")) { |
| 1108 | return; |
| 1109 | } |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 1110 | if (VDBG) { |
Chen Xu | 288b71c | 2019-09-15 18:28:21 -0700 | [diff] [blame] | 1111 | log("notifyCallState: subId=" + subId |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1112 | + " state=" + state + " incomingNumber=" + incomingNumber); |
| 1113 | } |
| 1114 | synchronized (mRecords) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1115 | if (validatePhoneId(phoneId)) { |
| 1116 | mCallState[phoneId] = state; |
| 1117 | mCallIncomingNumber[phoneId] = incomingNumber; |
| 1118 | for (Record r : mRecords) { |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 1119 | if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) && |
xinhe | 43c5029 | 2014-09-18 17:56:48 -0700 | [diff] [blame] | 1120 | (r.subId == subId) && |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1121 | (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1122 | try { |
Fyodor Kupolov | 309b2f63 | 2015-06-03 16:29:01 -0700 | [diff] [blame] | 1123 | String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId); |
| 1124 | r.callback.onCallStateChanged(state, incomingNumberOrEmpty); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1125 | } catch (RemoteException ex) { |
| 1126 | mRemoveList.add(r.binder); |
| 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | } |
| 1131 | handleRemoveListLocked(); |
| 1132 | } |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 1133 | broadcastCallStateChanged(state, incomingNumber, phoneId, subId); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1136 | public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1137 | if (!checkNotifyPermission("notifyServiceState()")){ |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 1138 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1139 | } |
xinhe | 43c5029 | 2014-09-18 17:56:48 -0700 | [diff] [blame] | 1140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1141 | synchronized (mRecords) { |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 1142 | String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId |
| 1143 | + " state=" + state; |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 1144 | if (VDBG) { |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 1145 | log(str); |
Wink Saville | 47d8d1b | 2014-07-10 13:01:52 -0700 | [diff] [blame] | 1146 | } |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 1147 | mLocalLog.log(str); |
Jordan Liu | 55b2bc46 | 2019-06-24 11:27:34 -0700 | [diff] [blame] | 1148 | // for service state updates, don't notify clients when subId is invalid. This prevents |
| 1149 | // us from sending incorrect notifications like b/133140128 |
| 1150 | // In the future, we can remove this logic for every notification here and add a |
| 1151 | // callback so listeners know when their PhoneStateListener's subId becomes invalid, but |
| 1152 | // for now we use the simplest fix. |
| 1153 | if (validatePhoneId(phoneId) && SubscriptionManager.isValidSubscriptionId(subId)) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1154 | mServiceState[phoneId] = state; |
Wink Saville | 47d8d1b | 2014-07-10 13:01:52 -0700 | [diff] [blame] | 1155 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1156 | for (Record r : mRecords) { |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 1157 | if (VDBG) { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 1158 | log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 1159 | + " phoneId=" + phoneId + " state=" + state); |
| 1160 | } |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 1161 | if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) && |
xinhe | 8b79fb6 | 2014-11-05 14:55:03 -0800 | [diff] [blame] | 1162 | idMatch(r.subId, subId, phoneId)) { |
Hall Liu | ee31373 | 2018-11-27 14:36:51 -0800 | [diff] [blame] | 1163 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1164 | try { |
Hall Liu | ee31373 | 2018-11-27 14:36:51 -0800 | [diff] [blame] | 1165 | ServiceState stateToSend; |
| 1166 | if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) { |
| 1167 | stateToSend = new ServiceState(state); |
| 1168 | } else if (checkCoarseLocationAccess(r, Build.VERSION_CODES.Q)) { |
| 1169 | stateToSend = state.sanitizeLocationInfo(false); |
| 1170 | } else { |
| 1171 | stateToSend = state.sanitizeLocationInfo(true); |
| 1172 | } |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 1173 | if (DBG) { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 1174 | log("notifyServiceStateForSubscriber: callback.onSSC r=" + r |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 1175 | + " subId=" + subId + " phoneId=" + phoneId |
| 1176 | + " state=" + state); |
| 1177 | } |
Hall Liu | ee31373 | 2018-11-27 14:36:51 -0800 | [diff] [blame] | 1178 | r.callback.onServiceStateChanged(stateToSend); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1179 | } catch (RemoteException ex) { |
| 1180 | mRemoveList.add(r.binder); |
| 1181 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 1182 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1183 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1184 | } else { |
Jordan Liu | 55b2bc46 | 2019-06-24 11:27:34 -0700 | [diff] [blame] | 1185 | log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId |
| 1186 | + " or subId=" + subId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1187 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 1188 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1189 | } |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 1190 | broadcastServiceStateChanged(state, phoneId, subId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1191 | } |
| 1192 | |
fionaxu | 12312f6 | 2016-11-14 13:32:14 -0800 | [diff] [blame] | 1193 | public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId, |
| 1194 | int activationType, int activationState) { |
| 1195 | if (!checkNotifyPermission("notifySimActivationState()")){ |
| 1196 | return; |
| 1197 | } |
| 1198 | if (VDBG) { |
| 1199 | log("notifySimActivationStateForPhoneId: subId=" + subId + " phoneId=" + phoneId |
| 1200 | + "type=" + activationType + " state=" + activationState); |
| 1201 | } |
| 1202 | synchronized (mRecords) { |
| 1203 | if (validatePhoneId(phoneId)) { |
| 1204 | switch (activationType) { |
Meng Wang | 62d2ff8 | 2019-12-04 18:02:55 -0800 | [diff] [blame] | 1205 | case SIM_ACTIVATION_TYPE_VOICE: |
fionaxu | 12312f6 | 2016-11-14 13:32:14 -0800 | [diff] [blame] | 1206 | mVoiceActivationState[phoneId] = activationState; |
| 1207 | break; |
Meng Wang | 62d2ff8 | 2019-12-04 18:02:55 -0800 | [diff] [blame] | 1208 | case SIM_ACTIVATION_TYPE_DATA: |
fionaxu | 12312f6 | 2016-11-14 13:32:14 -0800 | [diff] [blame] | 1209 | mDataActivationState[phoneId] = activationState; |
| 1210 | break; |
| 1211 | default: |
| 1212 | return; |
| 1213 | } |
| 1214 | for (Record r : mRecords) { |
| 1215 | if (VDBG) { |
| 1216 | log("notifySimActivationStateForPhoneId: r=" + r + " subId=" + subId |
| 1217 | + " phoneId=" + phoneId + "type=" + activationType |
| 1218 | + " state=" + activationState); |
| 1219 | } |
| 1220 | try { |
Meng Wang | 62d2ff8 | 2019-12-04 18:02:55 -0800 | [diff] [blame] | 1221 | if ((activationType == SIM_ACTIVATION_TYPE_VOICE) |
| 1222 | && r.matchPhoneStateListenerEvent( |
| 1223 | PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) |
| 1224 | && idMatch(r.subId, subId, phoneId)) { |
fionaxu | 12312f6 | 2016-11-14 13:32:14 -0800 | [diff] [blame] | 1225 | if (DBG) { |
| 1226 | log("notifyVoiceActivationStateForPhoneId: callback.onVASC r=" + r |
| 1227 | + " subId=" + subId + " phoneId=" + phoneId |
| 1228 | + " state=" + activationState); |
| 1229 | } |
| 1230 | r.callback.onVoiceActivationStateChanged(activationState); |
| 1231 | } |
Meng Wang | 62d2ff8 | 2019-12-04 18:02:55 -0800 | [diff] [blame] | 1232 | if ((activationType == SIM_ACTIVATION_TYPE_DATA) |
| 1233 | && r.matchPhoneStateListenerEvent( |
| 1234 | PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) |
| 1235 | && idMatch(r.subId, subId, phoneId)) { |
fionaxu | 12312f6 | 2016-11-14 13:32:14 -0800 | [diff] [blame] | 1236 | if (DBG) { |
| 1237 | log("notifyDataActivationStateForPhoneId: callback.onDASC r=" + r |
| 1238 | + " subId=" + subId + " phoneId=" + phoneId |
| 1239 | + " state=" + activationState); |
| 1240 | } |
| 1241 | r.callback.onDataActivationStateChanged(activationState); |
| 1242 | } |
| 1243 | } catch (RemoteException ex) { |
| 1244 | mRemoveList.add(r.binder); |
| 1245 | } |
| 1246 | } |
| 1247 | } else { |
| 1248 | log("notifySimActivationStateForPhoneId: INVALID phoneId=" + phoneId); |
| 1249 | } |
| 1250 | handleRemoveListLocked(); |
| 1251 | } |
| 1252 | } |
| 1253 | |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 1254 | public void notifySignalStrengthForPhoneId(int phoneId, int subId, |
| 1255 | SignalStrength signalStrength) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1256 | if (!checkNotifyPermission("notifySignalStrength()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 1257 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1258 | } |
Amit Mahajan | 1466a9c | 2015-04-27 22:58:29 +0000 | [diff] [blame] | 1259 | if (VDBG) { |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 1260 | log("notifySignalStrengthForPhoneId: subId=" + subId |
| 1261 | +" phoneId=" + phoneId + " signalStrength=" + signalStrength); |
Amit Mahajan | 1466a9c | 2015-04-27 22:58:29 +0000 | [diff] [blame] | 1262 | } |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 1263 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1264 | synchronized (mRecords) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1265 | if (validatePhoneId(phoneId)) { |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 1266 | if (VDBG) log("notifySignalStrengthForPhoneId: valid phoneId=" + phoneId); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1267 | mSignalStrength[phoneId] = signalStrength; |
| 1268 | for (Record r : mRecords) { |
Amit Mahajan | 1466a9c | 2015-04-27 22:58:29 +0000 | [diff] [blame] | 1269 | if (VDBG) { |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 1270 | log("notifySignalStrengthForPhoneId: r=" + r + " subId=" + subId |
Amit Mahajan | 1466a9c | 2015-04-27 22:58:29 +0000 | [diff] [blame] | 1271 | + " phoneId=" + phoneId + " ss=" + signalStrength); |
| 1272 | } |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 1273 | if (r.matchPhoneStateListenerEvent( |
| 1274 | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) && |
xinhe | 8b79fb6 | 2014-11-05 14:55:03 -0800 | [diff] [blame] | 1275 | idMatch(r.subId, subId, phoneId)) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1276 | try { |
Amit Mahajan | 1466a9c | 2015-04-27 22:58:29 +0000 | [diff] [blame] | 1277 | if (DBG) { |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 1278 | log("notifySignalStrengthForPhoneId: callback.onSsS r=" + r |
Amit Mahajan | 1466a9c | 2015-04-27 22:58:29 +0000 | [diff] [blame] | 1279 | + " subId=" + subId + " phoneId=" + phoneId |
| 1280 | + " ss=" + signalStrength); |
| 1281 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1282 | r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength)); |
| 1283 | } catch (RemoteException ex) { |
| 1284 | mRemoveList.add(r.binder); |
| 1285 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 1286 | } |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 1287 | if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SIGNAL_STRENGTH) && |
xinhe | 8b79fb6 | 2014-11-05 14:55:03 -0800 | [diff] [blame] | 1288 | idMatch(r.subId, subId, phoneId)){ |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1289 | try { |
| 1290 | int gsmSignalStrength = signalStrength.getGsmSignalStrength(); |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 1291 | int ss = (gsmSignalStrength == 99 ? -1 : gsmSignalStrength); |
Amit Mahajan | 1466a9c | 2015-04-27 22:58:29 +0000 | [diff] [blame] | 1292 | if (DBG) { |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 1293 | log("notifySignalStrengthForPhoneId: callback.onSS r=" + r |
Amit Mahajan | 1466a9c | 2015-04-27 22:58:29 +0000 | [diff] [blame] | 1294 | + " subId=" + subId + " phoneId=" + phoneId |
| 1295 | + " gsmSS=" + gsmSignalStrength + " ss=" + ss); |
| 1296 | } |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 1297 | r.callback.onSignalStrengthChanged(ss); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1298 | } catch (RemoteException ex) { |
| 1299 | mRemoveList.add(r.binder); |
| 1300 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1301 | } |
| 1302 | } |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 1303 | } else { |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 1304 | log("notifySignalStrengthForPhoneId: invalid phoneId=" + phoneId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1305 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 1306 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1307 | } |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 1308 | broadcastSignalStrengthChanged(signalStrength, phoneId, subId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1309 | } |
| 1310 | |
Andrew Flynn | 1f45264 | 2015-04-14 22:16:04 -0400 | [diff] [blame] | 1311 | @Override |
| 1312 | public void notifyCarrierNetworkChange(boolean active) { |
chen xu | badf2b0 | 2019-04-26 17:45:26 -0700 | [diff] [blame] | 1313 | // only CarrierService with carrier privilege rule should have the permission |
| 1314 | int[] subIds = Arrays.stream(SubscriptionManager.from(mContext) |
Malcolm Chen | 2c95aa9 | 2019-09-25 14:02:14 -0700 | [diff] [blame] | 1315 | .getActiveSubscriptionIdList(false)) |
chen xu | badf2b0 | 2019-04-26 17:45:26 -0700 | [diff] [blame] | 1316 | .filter(i -> TelephonyPermissions.checkCarrierPrivilegeForSubId(i)).toArray(); |
| 1317 | if (ArrayUtils.isEmpty(subIds)) { |
chen xu | 627d1b2 | 2019-04-11 02:16:19 -0700 | [diff] [blame] | 1318 | loge("notifyCarrierNetworkChange without carrier privilege"); |
chen xu | badf2b0 | 2019-04-26 17:45:26 -0700 | [diff] [blame] | 1319 | // the active subId does not have carrier privilege. |
chen xu | 627d1b2 | 2019-04-11 02:16:19 -0700 | [diff] [blame] | 1320 | throw new SecurityException("notifyCarrierNetworkChange without carrier privilege"); |
chen xu | 5b98d40 | 2019-03-22 16:56:34 -0700 | [diff] [blame] | 1321 | } |
Andrew Flynn | 1f45264 | 2015-04-14 22:16:04 -0400 | [diff] [blame] | 1322 | |
| 1323 | synchronized (mRecords) { |
| 1324 | mCarrierNetworkChangeState = active; |
chen xu | badf2b0 | 2019-04-26 17:45:26 -0700 | [diff] [blame] | 1325 | for (int subId : subIds) { |
| 1326 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 1327 | |
| 1328 | if (VDBG) { |
| 1329 | log("notifyCarrierNetworkChange: active=" + active + "subId: " + subId); |
| 1330 | } |
| 1331 | for (Record r : mRecords) { |
| 1332 | if (r.matchPhoneStateListenerEvent( |
| 1333 | PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) && |
| 1334 | idMatch(r.subId, subId, phoneId)) { |
| 1335 | try { |
| 1336 | r.callback.onCarrierNetworkChange(active); |
| 1337 | } catch (RemoteException ex) { |
| 1338 | mRemoveList.add(r.binder); |
| 1339 | } |
Andrew Flynn | 1f45264 | 2015-04-14 22:16:04 -0400 | [diff] [blame] | 1340 | } |
| 1341 | } |
| 1342 | } |
| 1343 | handleRemoveListLocked(); |
| 1344 | } |
| 1345 | } |
| 1346 | |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 1347 | public void notifyCellInfo(List<CellInfo> cellInfo) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1348 | notifyCellInfoForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellInfo); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1349 | } |
| 1350 | |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1351 | public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) { |
Chen Xu | 288b71c | 2019-09-15 18:28:21 -0700 | [diff] [blame] | 1352 | if (!checkNotifyPermission("notifyCellInfoForSubscriber()")) { |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 1353 | return; |
| 1354 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1355 | if (VDBG) { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 1356 | log("notifyCellInfoForSubscriber: subId=" + subId |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1357 | + " cellInfo=" + cellInfo); |
| 1358 | } |
yifan.bai | e620ce7 | 2017-12-22 14:59:57 +0800 | [diff] [blame] | 1359 | int phoneId = SubscriptionManager.getPhoneId(subId); |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 1360 | synchronized (mRecords) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1361 | if (validatePhoneId(phoneId)) { |
| 1362 | mCellInfo.set(phoneId, cellInfo); |
| 1363 | for (Record r : mRecords) { |
xinhe | 43c5029 | 2014-09-18 17:56:48 -0700 | [diff] [blame] | 1364 | if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) && |
Hall Liu | 5fb337f | 2017-11-22 17:38:15 -0800 | [diff] [blame] | 1365 | idMatch(r.subId, subId, phoneId) && |
Hall Liu | ee31373 | 2018-11-27 14:36:51 -0800 | [diff] [blame] | 1366 | checkFineLocationAccess(r, Build.VERSION_CODES.Q)) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1367 | try { |
| 1368 | if (DBG_LOC) { |
Chen Xu | 288b71c | 2019-09-15 18:28:21 -0700 | [diff] [blame] | 1369 | log("notifyCellInfoForSubscriber: mCellInfo=" + cellInfo |
| 1370 | + " r=" + r); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1371 | } |
| 1372 | r.callback.onCellInfoChanged(cellInfo); |
| 1373 | } catch (RemoteException ex) { |
| 1374 | mRemoveList.add(r.binder); |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 1375 | } |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 1376 | } |
| 1377 | } |
| 1378 | } |
| 1379 | handleRemoveListLocked(); |
| 1380 | } |
| 1381 | } |
| 1382 | |
xinhe | 43c5029 | 2014-09-18 17:56:48 -0700 | [diff] [blame] | 1383 | @Override |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1384 | public void notifyMessageWaitingChangedForPhoneId(int phoneId, int subId, boolean mwi) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1385 | if (!checkNotifyPermission("notifyMessageWaitingChanged()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 1386 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1387 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1388 | if (VDBG) { |
xinhe | 43c5029 | 2014-09-18 17:56:48 -0700 | [diff] [blame] | 1389 | log("notifyMessageWaitingChangedForSubscriberPhoneID: subId=" + phoneId |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1390 | + " mwi=" + mwi); |
| 1391 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1392 | synchronized (mRecords) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1393 | if (validatePhoneId(phoneId)) { |
| 1394 | mMessageWaiting[phoneId] = mwi; |
| 1395 | for (Record r : mRecords) { |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 1396 | if (r.matchPhoneStateListenerEvent( |
| 1397 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) && |
xinhe | 8b79fb6 | 2014-11-05 14:55:03 -0800 | [diff] [blame] | 1398 | idMatch(r.subId, subId, phoneId)) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1399 | try { |
| 1400 | r.callback.onMessageWaitingIndicatorChanged(mwi); |
| 1401 | } catch (RemoteException ex) { |
| 1402 | mRemoveList.add(r.binder); |
| 1403 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1404 | } |
| 1405 | } |
| 1406 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 1407 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1408 | } |
| 1409 | } |
| 1410 | |
zxuan | 35a4702 | 2018-01-04 11:24:04 -0800 | [diff] [blame] | 1411 | public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) { |
| 1412 | if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) { |
| 1413 | return; |
| 1414 | } |
| 1415 | if (VDBG) { |
SongFerngWang | 0b109f5f | 2019-04-09 17:29:29 +0800 | [diff] [blame] | 1416 | log("notifyUserMobileDataStateChangedForSubscriberPhoneID: PhoneId=" + phoneId |
| 1417 | + " subId=" + subId + " state=" + state); |
zxuan | 35a4702 | 2018-01-04 11:24:04 -0800 | [diff] [blame] | 1418 | } |
| 1419 | synchronized (mRecords) { |
| 1420 | if (validatePhoneId(phoneId)) { |
SongFerngWang | 0b109f5f | 2019-04-09 17:29:29 +0800 | [diff] [blame] | 1421 | mUserMobileDataState[phoneId] = state; |
zxuan | 35a4702 | 2018-01-04 11:24:04 -0800 | [diff] [blame] | 1422 | for (Record r : mRecords) { |
| 1423 | if (r.matchPhoneStateListenerEvent( |
| 1424 | PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) && |
| 1425 | idMatch(r.subId, subId, phoneId)) { |
| 1426 | try { |
| 1427 | r.callback.onUserMobileDataStateChanged(state); |
| 1428 | } catch (RemoteException ex) { |
| 1429 | mRemoveList.add(r.binder); |
| 1430 | } |
| 1431 | } |
| 1432 | } |
| 1433 | } |
| 1434 | handleRemoveListLocked(); |
| 1435 | } |
| 1436 | } |
| 1437 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1438 | public void notifyCallForwardingChanged(boolean cfi) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1439 | notifyCallForwardingChangedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cfi); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1442 | public void notifyCallForwardingChangedForSubscriber(int subId, boolean cfi) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1443 | if (!checkNotifyPermission("notifyCallForwardingChanged()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 1444 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1445 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1446 | if (VDBG) { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 1447 | log("notifyCallForwardingChangedForSubscriber: subId=" + subId |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1448 | + " cfi=" + cfi); |
| 1449 | } |
yifan.bai | e620ce7 | 2017-12-22 14:59:57 +0800 | [diff] [blame] | 1450 | int phoneId = SubscriptionManager.getPhoneId(subId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1451 | synchronized (mRecords) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1452 | if (validatePhoneId(phoneId)) { |
| 1453 | mCallForwarding[phoneId] = cfi; |
| 1454 | for (Record r : mRecords) { |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 1455 | if (r.matchPhoneStateListenerEvent( |
| 1456 | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) && |
xinhe | 8b79fb6 | 2014-11-05 14:55:03 -0800 | [diff] [blame] | 1457 | idMatch(r.subId, subId, phoneId)) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1458 | try { |
| 1459 | r.callback.onCallForwardingIndicatorChanged(cfi); |
| 1460 | } catch (RemoteException ex) { |
| 1461 | mRemoveList.add(r.binder); |
| 1462 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1463 | } |
| 1464 | } |
| 1465 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 1466 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | public void notifyDataActivity(int state) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1471 | notifyDataActivityForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1474 | public void notifyDataActivityForSubscriber(int subId, int state) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1475 | if (!checkNotifyPermission("notifyDataActivity()" )) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 1476 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1477 | } |
yifan.bai | e620ce7 | 2017-12-22 14:59:57 +0800 | [diff] [blame] | 1478 | int phoneId = SubscriptionManager.getPhoneId(subId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1479 | synchronized (mRecords) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1480 | if (validatePhoneId(phoneId)) { |
| 1481 | mDataActivity[phoneId] = state; |
| 1482 | for (Record r : mRecords) { |
xu.peng | 9071ced | 2016-03-22 18:21:28 +0800 | [diff] [blame] | 1483 | // Notify by correct subId. |
| 1484 | if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) && |
| 1485 | idMatch(r.subId, subId, phoneId)) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1486 | try { |
| 1487 | r.callback.onDataActivity(state); |
| 1488 | } catch (RemoteException ex) { |
| 1489 | mRemoveList.add(r.binder); |
| 1490 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1491 | } |
| 1492 | } |
| 1493 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 1494 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | } |
| 1496 | } |
| 1497 | |
Jack Yu | 4d1c945 | 2019-01-02 16:51:08 -0800 | [diff] [blame] | 1498 | public void notifyDataConnection(int state, boolean isDataAllowed, String apn, String apnType, |
| 1499 | LinkProperties linkProperties, |
| 1500 | NetworkCapabilities networkCapabilities, int networkType, |
| 1501 | boolean roaming) { |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1502 | notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_PHONE_INDEX, |
| 1503 | SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state, |
Jack Yu | 4d1c945 | 2019-01-02 16:51:08 -0800 | [diff] [blame] | 1504 | isDataAllowed, apn, apnType, linkProperties, |
| 1505 | networkCapabilities, networkType, roaming); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1506 | } |
| 1507 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1508 | public void notifyDataConnectionForSubscriber(int phoneId, int subId, int state, |
| 1509 | boolean isDataAllowed, |
Jack Yu | 4d1c945 | 2019-01-02 16:51:08 -0800 | [diff] [blame] | 1510 | String apn, String apnType, |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1511 | LinkProperties linkProperties, NetworkCapabilities networkCapabilities, |
| 1512 | int networkType, boolean roaming) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1513 | if (!checkNotifyPermission("notifyDataConnection()" )) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 1514 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1515 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1516 | if (VDBG) { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 1517 | log("notifyDataConnectionForSubscriber: subId=" + subId |
Jack Yu | baeec62 | 2017-05-01 17:01:11 -0700 | [diff] [blame] | 1518 | + " state=" + state + " isDataAllowed=" + isDataAllowed |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 1519 | + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType |
xinhe | ac11ae9 | 2014-12-18 10:02:14 -0800 | [diff] [blame] | 1520 | + " mRecords.size()=" + mRecords.size()); |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 1521 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | synchronized (mRecords) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1523 | if (validatePhoneId(phoneId)) { |
Jack Yu | b1bac54 | 2018-03-14 16:23:38 -0700 | [diff] [blame] | 1524 | // We only call the callback when the change is for default APN type. |
| 1525 | if (PhoneConstants.APN_TYPE_DEFAULT.equals(apnType) |
| 1526 | && (mDataConnectionState[phoneId] != state |
| 1527 | || mDataConnectionNetworkType[phoneId] != networkType)) { |
Jack Yu | 0c92c23 | 2019-04-04 15:10:17 -0700 | [diff] [blame] | 1528 | String str = "onDataConnectionStateChanged(" |
zoey chen | c722b45 | 2019-12-03 17:23:22 +0800 | [diff] [blame] | 1529 | + dataStateToString(state) |
| 1530 | + ", " + getNetworkTypeName(networkType) |
Jack Yu | 0c92c23 | 2019-04-04 15:10:17 -0700 | [diff] [blame] | 1531 | + ") subId=" + subId + ", phoneId=" + phoneId; |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 1532 | log(str); |
| 1533 | mLocalLog.log(str); |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1534 | for (Record r : mRecords) { |
| 1535 | if (r.matchPhoneStateListenerEvent( |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1536 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) |
| 1537 | && idMatch(r.subId, subId, phoneId)) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1538 | try { |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 1539 | if (DBG) { |
| 1540 | log("Notify data connection state changed on sub: " + subId); |
| 1541 | } |
Jack Yu | b1bac54 | 2018-03-14 16:23:38 -0700 | [diff] [blame] | 1542 | r.callback.onDataConnectionStateChanged(state, networkType); |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1543 | } catch (RemoteException ex) { |
| 1544 | mRemoveList.add(r.binder); |
| 1545 | } |
| 1546 | } |
| 1547 | } |
| 1548 | handleRemoveListLocked(); |
Jack Yu | b1bac54 | 2018-03-14 16:23:38 -0700 | [diff] [blame] | 1549 | |
| 1550 | mDataConnectionState[phoneId] = state; |
| 1551 | mDataConnectionNetworkType[phoneId] = networkType; |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1552 | } |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1553 | mPreciseDataConnectionState[phoneId] = new PreciseDataConnectionState( |
| 1554 | state, networkType, |
chen xu | 16e24cd | 2018-12-11 18:09:41 -0800 | [diff] [blame] | 1555 | ApnSetting.getApnTypesBitmaskFromString(apnType), apn, |
| 1556 | linkProperties, DataFailCause.NONE); |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1557 | for (Record r : mRecords) { |
| 1558 | if (r.matchPhoneStateListenerEvent( |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1559 | PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) |
| 1560 | && idMatch(r.subId, subId, phoneId)) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1561 | try { |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 1562 | r.callback.onPreciseDataConnectionStateChanged( |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1563 | mPreciseDataConnectionState[phoneId]); |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1564 | } catch (RemoteException ex) { |
| 1565 | mRemoveList.add(r.binder); |
| 1566 | } |
Wink Saville | 2d1ee98 | 2014-11-20 20:29:51 +0000 | [diff] [blame] | 1567 | } |
| 1568 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1569 | } |
| 1570 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1571 | } |
Jack Yu | 4d1c945 | 2019-01-02 16:51:08 -0800 | [diff] [blame] | 1572 | broadcastDataConnectionStateChanged(state, isDataAllowed, apn, apnType, linkProperties, |
| 1573 | networkCapabilities, roaming, subId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1574 | } |
| 1575 | |
Jack Yu | 4d1c945 | 2019-01-02 16:51:08 -0800 | [diff] [blame] | 1576 | public void notifyDataConnectionFailed(String apnType) { |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1577 | notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_PHONE_INDEX, |
| 1578 | SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, |
Jack Yu | 4d1c945 | 2019-01-02 16:51:08 -0800 | [diff] [blame] | 1579 | apnType); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1582 | public void notifyDataConnectionFailedForSubscriber(int phoneId, int subId, String apnType) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1583 | if (!checkNotifyPermission("notifyDataConnectionFailed()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 1584 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1585 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1586 | if (VDBG) { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 1587 | log("notifyDataConnectionFailedForSubscriber: subId=" + subId |
Jack Yu | 4d1c945 | 2019-01-02 16:51:08 -0800 | [diff] [blame] | 1588 | + " apnType=" + apnType); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1589 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1590 | synchronized (mRecords) { |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1591 | if (validatePhoneId(phoneId)) { |
| 1592 | mPreciseDataConnectionState[phoneId] = new PreciseDataConnectionState( |
| 1593 | TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN, |
| 1594 | ApnSetting.getApnTypesBitmaskFromString(apnType), null, null, |
| 1595 | DataFailCause.NONE); |
| 1596 | for (Record r : mRecords) { |
| 1597 | if (r.matchPhoneStateListenerEvent( |
| 1598 | PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) |
| 1599 | && idMatch(r.subId, subId, phoneId)) { |
| 1600 | try { |
| 1601 | r.callback.onPreciseDataConnectionStateChanged( |
| 1602 | mPreciseDataConnectionState[phoneId]); |
| 1603 | } catch (RemoteException ex) { |
| 1604 | mRemoveList.add(r.binder); |
| 1605 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1606 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1607 | } |
| 1608 | } |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1609 | |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1610 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1611 | } |
Jack Yu | 4d1c945 | 2019-01-02 16:51:08 -0800 | [diff] [blame] | 1612 | broadcastDataConnectionFailed(apnType, subId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | public void notifyCellLocation(Bundle cellLocation) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1616 | notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1619 | public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 1620 | log("notifyCellLocationForSubscriber: subId=" + subId |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1621 | + " cellLocation=" + cellLocation); |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1622 | if (!checkNotifyPermission("notifyCellLocation()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 1623 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1624 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1625 | if (VDBG) { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 1626 | log("notifyCellLocationForSubscriber: subId=" + subId |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1627 | + " cellLocation=" + cellLocation); |
| 1628 | } |
yifan.bai | e620ce7 | 2017-12-22 14:59:57 +0800 | [diff] [blame] | 1629 | int phoneId = SubscriptionManager.getPhoneId(subId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1630 | synchronized (mRecords) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1631 | if (validatePhoneId(phoneId)) { |
| 1632 | mCellLocation[phoneId] = cellLocation; |
| 1633 | for (Record r : mRecords) { |
xinhe | 43c5029 | 2014-09-18 17:56:48 -0700 | [diff] [blame] | 1634 | if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) && |
Hall Liu | 5fb337f | 2017-11-22 17:38:15 -0800 | [diff] [blame] | 1635 | idMatch(r.subId, subId, phoneId) && |
Hall Liu | ee31373 | 2018-11-27 14:36:51 -0800 | [diff] [blame] | 1636 | checkFineLocationAccess(r, Build.VERSION_CODES.Q)) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1637 | try { |
| 1638 | if (DBG_LOC) { |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 1639 | log("notifyCellLocation: cellLocation=" + cellLocation |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1640 | + " r=" + r); |
| 1641 | } |
| 1642 | r.callback.onCellLocationChanged(new Bundle(cellLocation)); |
| 1643 | } catch (RemoteException ex) { |
| 1644 | mRemoveList.add(r.binder); |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 1645 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 1646 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1647 | } |
| 1648 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 1649 | handleRemoveListLocked(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1650 | } |
| 1651 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1652 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1653 | public void notifyOtaspChanged(int subId, int otaspMode) { |
Wink Saville | fd2d013 | 2010-10-28 14:22:26 -0700 | [diff] [blame] | 1654 | if (!checkNotifyPermission("notifyOtaspChanged()" )) { |
| 1655 | return; |
| 1656 | } |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1657 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Wink Saville | fd2d013 | 2010-10-28 14:22:26 -0700 | [diff] [blame] | 1658 | synchronized (mRecords) { |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1659 | if (validatePhoneId(phoneId)) { |
| 1660 | mOtaspMode[phoneId] = otaspMode; |
| 1661 | for (Record r : mRecords) { |
| 1662 | if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED) |
| 1663 | && idMatch(r.subId, subId, phoneId)) { |
| 1664 | try { |
| 1665 | r.callback.onOtaspChanged(otaspMode); |
| 1666 | } catch (RemoteException ex) { |
| 1667 | mRemoveList.add(r.binder); |
| 1668 | } |
Wink Saville | fd2d013 | 2010-10-28 14:22:26 -0700 | [diff] [blame] | 1669 | } |
| 1670 | } |
| 1671 | } |
| 1672 | handleRemoveListLocked(); |
| 1673 | } |
| 1674 | } |
| 1675 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1676 | public void notifyPreciseCallState(int phoneId, int subId, int ringingCallState, |
| 1677 | int foregroundCallState, int backgroundCallState) { |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1678 | if (!checkNotifyPermission("notifyPreciseCallState()")) { |
| 1679 | return; |
| 1680 | } |
| 1681 | synchronized (mRecords) { |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1682 | if (validatePhoneId(phoneId)) { |
| 1683 | mRingingCallState[phoneId] = ringingCallState; |
| 1684 | mForegroundCallState[phoneId] = foregroundCallState; |
| 1685 | mBackgroundCallState[phoneId] = backgroundCallState; |
| 1686 | mPreciseCallState[phoneId] = new PreciseCallState( |
| 1687 | ringingCallState, foregroundCallState, |
| 1688 | backgroundCallState, |
| 1689 | DisconnectCause.NOT_VALID, |
| 1690 | PreciseDisconnectCause.NOT_VALID); |
| 1691 | boolean notifyCallAttributes = true; |
| 1692 | if (mCallQuality == null) { |
| 1693 | log("notifyPreciseCallState: mCallQuality is null, " |
| 1694 | + "skipping call attributes"); |
| 1695 | notifyCallAttributes = false; |
| 1696 | } else { |
| 1697 | // If the precise call state is no longer active, reset the call network type |
| 1698 | // and call quality. |
| 1699 | if (mPreciseCallState[phoneId].getForegroundCallState() |
| 1700 | != PreciseCallState.PRECISE_CALL_STATE_ACTIVE) { |
| 1701 | mCallNetworkType[phoneId] = TelephonyManager.NETWORK_TYPE_UNKNOWN; |
Meng Wang | be15dba | 2019-12-10 10:54:50 -0800 | [diff] [blame] | 1702 | mCallQuality[phoneId] = createCallQuality(); |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1703 | } |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1704 | mCallAttributes[phoneId] = new CallAttributes(mPreciseCallState[phoneId], |
| 1705 | mCallNetworkType[phoneId], mCallQuality[phoneId]); |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1706 | } |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1707 | |
| 1708 | for (Record r : mRecords) { |
| 1709 | if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE) |
| 1710 | && idMatch(r.subId, subId, phoneId)) { |
| 1711 | try { |
| 1712 | r.callback.onPreciseCallStateChanged(mPreciseCallState[phoneId]); |
| 1713 | } catch (RemoteException ex) { |
| 1714 | mRemoveList.add(r.binder); |
| 1715 | } |
| 1716 | } |
| 1717 | if (notifyCallAttributes && r.matchPhoneStateListenerEvent( |
| 1718 | PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) |
| 1719 | && idMatch(r.subId, subId, phoneId)) { |
| 1720 | try { |
| 1721 | r.callback.onCallAttributesChanged(mCallAttributes[phoneId]); |
| 1722 | } catch (RemoteException ex) { |
| 1723 | mRemoveList.add(r.binder); |
| 1724 | } |
Jordan Liu | 8218ddd | 2018-11-28 11:22:39 -0800 | [diff] [blame] | 1725 | } |
| 1726 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1727 | } |
| 1728 | handleRemoveListLocked(); |
| 1729 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1730 | } |
| 1731 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1732 | public void notifyDisconnectCause(int phoneId, int subId, int disconnectCause, |
| 1733 | int preciseDisconnectCause) { |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1734 | if (!checkNotifyPermission("notifyDisconnectCause()")) { |
| 1735 | return; |
| 1736 | } |
| 1737 | synchronized (mRecords) { |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1738 | if (validatePhoneId(phoneId)) { |
| 1739 | mCallDisconnectCause[phoneId] = disconnectCause; |
| 1740 | mCallPreciseDisconnectCause[phoneId] = preciseDisconnectCause; |
| 1741 | for (Record r : mRecords) { |
| 1742 | if (r.matchPhoneStateListenerEvent(PhoneStateListener |
| 1743 | .LISTEN_CALL_DISCONNECT_CAUSES) && idMatch(r.subId, subId, phoneId)) { |
| 1744 | try { |
| 1745 | r.callback.onCallDisconnectCauseChanged(mCallDisconnectCause[phoneId], |
| 1746 | mCallPreciseDisconnectCause[phoneId]); |
| 1747 | } catch (RemoteException ex) { |
| 1748 | mRemoveList.add(r.binder); |
| 1749 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1750 | } |
| 1751 | } |
| 1752 | } |
| 1753 | handleRemoveListLocked(); |
| 1754 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1755 | } |
| 1756 | |
chen xu | 6ac5fc1 | 2019-01-24 14:14:13 -0800 | [diff] [blame] | 1757 | public void notifyImsDisconnectCause(int subId, ImsReasonInfo imsReasonInfo) { |
| 1758 | if (!checkNotifyPermission("notifyImsCallDisconnectCause()")) { |
| 1759 | return; |
| 1760 | } |
| 1761 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 1762 | synchronized (mRecords) { |
| 1763 | if (validatePhoneId(phoneId)) { |
| 1764 | mImsReasonInfo.set(phoneId, imsReasonInfo); |
| 1765 | for (Record r : mRecords) { |
| 1766 | if (r.matchPhoneStateListenerEvent( |
| 1767 | PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) |
| 1768 | && idMatch(r.subId, subId, phoneId)) { |
| 1769 | try { |
| 1770 | if (DBG_LOC) { |
| 1771 | log("notifyImsCallDisconnectCause: mImsReasonInfo=" |
| 1772 | + imsReasonInfo + " r=" + r); |
| 1773 | } |
| 1774 | r.callback.onImsCallDisconnectCauseChanged(mImsReasonInfo.get(phoneId)); |
| 1775 | } catch (RemoteException ex) { |
| 1776 | mRemoveList.add(r.binder); |
| 1777 | } |
| 1778 | } |
| 1779 | } |
| 1780 | } |
| 1781 | handleRemoveListLocked(); |
| 1782 | } |
| 1783 | } |
| 1784 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1785 | public void notifyPreciseDataConnectionFailed(int phoneId, int subId, String apnType, |
Chen Xu | c9d4ee1 | 2019-09-26 16:11:59 -0700 | [diff] [blame] | 1786 | String apn, @DataFailureCause int failCause) { |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1787 | if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) { |
| 1788 | return; |
| 1789 | } |
| 1790 | synchronized (mRecords) { |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1791 | if (validatePhoneId(phoneId)) { |
| 1792 | mPreciseDataConnectionState[phoneId] = new PreciseDataConnectionState( |
| 1793 | TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN, |
| 1794 | ApnSetting.getApnTypesBitmaskFromString(apnType), apn, null, failCause); |
| 1795 | for (Record r : mRecords) { |
| 1796 | if (r.matchPhoneStateListenerEvent( |
| 1797 | PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) |
| 1798 | && idMatch(r.subId, subId, phoneId)) { |
| 1799 | try { |
| 1800 | r.callback.onPreciseDataConnectionStateChanged( |
| 1801 | mPreciseDataConnectionState[phoneId]); |
| 1802 | } catch (RemoteException ex) { |
| 1803 | mRemoveList.add(r.binder); |
| 1804 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1805 | } |
| 1806 | } |
| 1807 | } |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1808 | |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1809 | handleRemoveListLocked(); |
| 1810 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1811 | } |
| 1812 | |
Brad Ebinger | efed982 | 2018-10-26 10:25:57 -0700 | [diff] [blame] | 1813 | @Override |
Chen Xu | c9d4ee1 | 2019-09-26 16:11:59 -0700 | [diff] [blame] | 1814 | public void notifySrvccStateChanged(int subId, @SrvccState int state) { |
Brad Ebinger | efed982 | 2018-10-26 10:25:57 -0700 | [diff] [blame] | 1815 | if (!checkNotifyPermission("notifySrvccStateChanged()")) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1816 | return; |
| 1817 | } |
Brad Ebinger | efed982 | 2018-10-26 10:25:57 -0700 | [diff] [blame] | 1818 | if (VDBG) { |
| 1819 | log("notifySrvccStateChanged: subId=" + subId + " srvccState=" + state); |
| 1820 | } |
| 1821 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1822 | synchronized (mRecords) { |
Brad Ebinger | efed982 | 2018-10-26 10:25:57 -0700 | [diff] [blame] | 1823 | if (validatePhoneId(phoneId)) { |
chen xu | 6ac5fc1 | 2019-01-24 14:14:13 -0800 | [diff] [blame] | 1824 | mSrvccState[phoneId] = state; |
Brad Ebinger | efed982 | 2018-10-26 10:25:57 -0700 | [diff] [blame] | 1825 | for (Record r : mRecords) { |
| 1826 | if (r.matchPhoneStateListenerEvent( |
| 1827 | PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) && |
| 1828 | idMatch(r.subId, subId, phoneId)) { |
| 1829 | try { |
| 1830 | if (DBG_LOC) { |
| 1831 | log("notifySrvccStateChanged: mSrvccState=" + state + " r=" + r); |
| 1832 | } |
| 1833 | r.callback.onSrvccStateChanged(state); |
| 1834 | } catch (RemoteException ex) { |
| 1835 | mRemoveList.add(r.binder); |
| 1836 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1837 | } |
| 1838 | } |
| 1839 | } |
| 1840 | handleRemoveListLocked(); |
| 1841 | } |
| 1842 | } |
| 1843 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1844 | public void notifyOemHookRawEventForSubscriber(int phoneId, int subId, byte[] rawData) { |
Shuo Qian | 066e865 | 2018-04-25 21:02:35 +0000 | [diff] [blame] | 1845 | if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) { |
| 1846 | return; |
| 1847 | } |
| 1848 | |
| 1849 | synchronized (mRecords) { |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1850 | if (validatePhoneId(phoneId)) { |
| 1851 | for (Record r : mRecords) { |
| 1852 | if (VDBG) { |
| 1853 | log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId); |
| 1854 | } |
| 1855 | if ((r.matchPhoneStateListenerEvent( |
| 1856 | PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) |
| 1857 | && idMatch(r.subId, subId, phoneId)) { |
| 1858 | try { |
| 1859 | r.callback.onOemHookRawEvent(rawData); |
| 1860 | } catch (RemoteException ex) { |
| 1861 | mRemoveList.add(r.binder); |
| 1862 | } |
Shuo Qian | 066e865 | 2018-04-25 21:02:35 +0000 | [diff] [blame] | 1863 | } |
| 1864 | } |
| 1865 | } |
| 1866 | handleRemoveListLocked(); |
| 1867 | } |
| 1868 | } |
| 1869 | |
Malcolm Chen | e162365 | 2018-08-08 20:27:45 -0700 | [diff] [blame] | 1870 | public void notifyPhoneCapabilityChanged(PhoneCapability capability) { |
| 1871 | if (!checkNotifyPermission("notifyPhoneCapabilityChanged()")) { |
| 1872 | return; |
| 1873 | } |
| 1874 | |
| 1875 | if (VDBG) { |
| 1876 | log("notifyPhoneCapabilityChanged: capability=" + capability); |
| 1877 | } |
| 1878 | |
| 1879 | synchronized (mRecords) { |
| 1880 | mPhoneCapability = capability; |
| 1881 | |
| 1882 | for (Record r : mRecords) { |
| 1883 | if (r.matchPhoneStateListenerEvent( |
| 1884 | PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE)) { |
| 1885 | try { |
| 1886 | r.callback.onPhoneCapabilityChanged(capability); |
| 1887 | } catch (RemoteException ex) { |
| 1888 | mRemoveList.add(r.binder); |
| 1889 | } |
| 1890 | } |
| 1891 | } |
| 1892 | handleRemoveListLocked(); |
| 1893 | } |
| 1894 | } |
| 1895 | |
Malcolm Chen | 026451d | 2019-02-14 19:50:19 -0800 | [diff] [blame] | 1896 | public void notifyActiveDataSubIdChanged(int activeDataSubId) { |
| 1897 | if (!checkNotifyPermission("notifyActiveDataSubIdChanged()")) { |
Malcolm Chen | 8b53afe | 2018-09-24 20:01:32 -0700 | [diff] [blame] | 1898 | return; |
| 1899 | } |
| 1900 | |
| 1901 | if (VDBG) { |
Malcolm Chen | 026451d | 2019-02-14 19:50:19 -0800 | [diff] [blame] | 1902 | log("notifyActiveDataSubIdChanged: activeDataSubId=" + activeDataSubId); |
Malcolm Chen | 8b53afe | 2018-09-24 20:01:32 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
sqian | 9e9ed18 | 2019-03-20 16:17:09 -0700 | [diff] [blame] | 1905 | mActiveDataSubId = activeDataSubId; |
sqian | 9e9ed18 | 2019-03-20 16:17:09 -0700 | [diff] [blame] | 1906 | synchronized (mRecords) { |
Malcolm Chen | f028c3b | 2019-09-04 16:10:34 -0700 | [diff] [blame] | 1907 | for (Record r : mRecords) { |
| 1908 | if (r.matchPhoneStateListenerEvent( |
| 1909 | PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE)) { |
Malcolm Chen | 8b53afe | 2018-09-24 20:01:32 -0700 | [diff] [blame] | 1910 | try { |
Malcolm Chen | 026451d | 2019-02-14 19:50:19 -0800 | [diff] [blame] | 1911 | r.callback.onActiveDataSubIdChanged(activeDataSubId); |
Malcolm Chen | 8b53afe | 2018-09-24 20:01:32 -0700 | [diff] [blame] | 1912 | } catch (RemoteException ex) { |
| 1913 | mRemoveList.add(r.binder); |
| 1914 | } |
| 1915 | } |
| 1916 | } |
| 1917 | handleRemoveListLocked(); |
| 1918 | } |
| 1919 | } |
Malcolm Chen | e162365 | 2018-08-08 20:27:45 -0700 | [diff] [blame] | 1920 | |
Chen Xu | c9d4ee1 | 2019-09-26 16:11:59 -0700 | [diff] [blame] | 1921 | public void notifyRadioPowerStateChanged(int phoneId, int subId, @RadioPowerState int state) { |
Chen Xu | 7395c63 | 2018-10-17 17:53:47 +0000 | [diff] [blame] | 1922 | if (!checkNotifyPermission("notifyRadioPowerStateChanged()")) { |
| 1923 | return; |
| 1924 | } |
| 1925 | |
| 1926 | if (VDBG) { |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1927 | log("notifyRadioPowerStateChanged: state= " + state + " subId=" + subId); |
Chen Xu | 7395c63 | 2018-10-17 17:53:47 +0000 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | synchronized (mRecords) { |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1931 | if (validatePhoneId(phoneId)) { |
| 1932 | mRadioPowerState = state; |
Chen Xu | 7395c63 | 2018-10-17 17:53:47 +0000 | [diff] [blame] | 1933 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1934 | for (Record r : mRecords) { |
| 1935 | if (r.matchPhoneStateListenerEvent( |
| 1936 | PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) |
| 1937 | && idMatch(r.subId, subId, phoneId)) { |
| 1938 | try { |
| 1939 | r.callback.onRadioPowerStateChanged(state); |
| 1940 | } catch (RemoteException ex) { |
| 1941 | mRemoveList.add(r.binder); |
| 1942 | } |
Chen Xu | 7395c63 | 2018-10-17 17:53:47 +0000 | [diff] [blame] | 1943 | } |
| 1944 | } |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1945 | |
Chen Xu | 7395c63 | 2018-10-17 17:53:47 +0000 | [diff] [blame] | 1946 | } |
| 1947 | handleRemoveListLocked(); |
| 1948 | } |
| 1949 | } |
| 1950 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1951 | @Override |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1952 | public void notifyEmergencyNumberList(int phoneId, int subId) { |
sqian | 9f93a12 | 2018-12-03 22:40:41 -0800 | [diff] [blame] | 1953 | if (!checkNotifyPermission("notifyEmergencyNumberList()")) { |
| 1954 | return; |
| 1955 | } |
| 1956 | |
| 1957 | synchronized (mRecords) { |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1958 | if (validatePhoneId(phoneId)) { |
| 1959 | TelephonyManager tm = (TelephonyManager) mContext.getSystemService( |
| 1960 | Context.TELEPHONY_SERVICE); |
| 1961 | mEmergencyNumberList = tm.getEmergencyNumberList(); |
sqian | 9f93a12 | 2018-12-03 22:40:41 -0800 | [diff] [blame] | 1962 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1963 | for (Record r : mRecords) { |
| 1964 | if (r.matchPhoneStateListenerEvent( |
| 1965 | PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST) |
| 1966 | && idMatch(r.subId, subId, phoneId)) { |
| 1967 | try { |
| 1968 | r.callback.onEmergencyNumberListChanged(mEmergencyNumberList); |
| 1969 | if (VDBG) { |
| 1970 | log("notifyEmergencyNumberList: emergencyNumberList= " |
| 1971 | + mEmergencyNumberList); |
| 1972 | } |
| 1973 | } catch (RemoteException ex) { |
| 1974 | mRemoveList.add(r.binder); |
sqian | 9f93a12 | 2018-12-03 22:40:41 -0800 | [diff] [blame] | 1975 | } |
sqian | 9f93a12 | 2018-12-03 22:40:41 -0800 | [diff] [blame] | 1976 | } |
| 1977 | } |
| 1978 | } |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 1979 | |
sqian | 9f93a12 | 2018-12-03 22:40:41 -0800 | [diff] [blame] | 1980 | handleRemoveListLocked(); |
| 1981 | } |
sqian | bdc5a73 | 2018-10-26 13:27:51 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
Jordan Liu | 8218ddd | 2018-11-28 11:22:39 -0800 | [diff] [blame] | 1984 | @Override |
Shuo Qian | 134334b | 2019-09-12 17:00:31 -0700 | [diff] [blame] | 1985 | public void notifyOutgoingEmergencyCall(int phoneId, int subId, |
| 1986 | EmergencyNumber emergencyNumber) { |
| 1987 | if (!checkNotifyPermission("notifyOutgoingEmergencyCall()")) { |
| 1988 | return; |
| 1989 | } |
| 1990 | synchronized (mRecords) { |
| 1991 | if (validatePhoneId(phoneId)) { |
| 1992 | mOutgoingCallEmergencyNumber[phoneId] = emergencyNumber; |
| 1993 | for (Record r : mRecords) { |
| 1994 | if (r.matchPhoneStateListenerEvent( |
Shuo Qian | d966376 | 2019-10-04 13:20:45 -0700 | [diff] [blame] | 1995 | PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_CALL) |
Shuo Qian | 134334b | 2019-09-12 17:00:31 -0700 | [diff] [blame] | 1996 | && idMatch(r.subId, subId, phoneId)) { |
| 1997 | try { |
| 1998 | r.callback.onOutgoingEmergencyCall(emergencyNumber); |
| 1999 | } catch (RemoteException ex) { |
| 2000 | mRemoveList.add(r.binder); |
| 2001 | } |
| 2002 | } |
| 2003 | } |
| 2004 | } |
| 2005 | handleRemoveListLocked(); |
| 2006 | } |
| 2007 | } |
| 2008 | |
| 2009 | @Override |
| 2010 | public void notifyOutgoingEmergencySms(int phoneId, int subId, |
| 2011 | EmergencyNumber emergencyNumber) { |
| 2012 | if (!checkNotifyPermission("notifyOutgoingEmergencySms()")) { |
| 2013 | return; |
| 2014 | } |
| 2015 | synchronized (mRecords) { |
| 2016 | if (validatePhoneId(phoneId)) { |
| 2017 | mOutgoingSmsEmergencyNumber[phoneId] = emergencyNumber; |
| 2018 | for (Record r : mRecords) { |
| 2019 | if (r.matchPhoneStateListenerEvent( |
Shuo Qian | d966376 | 2019-10-04 13:20:45 -0700 | [diff] [blame] | 2020 | PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_SMS) |
Shuo Qian | 134334b | 2019-09-12 17:00:31 -0700 | [diff] [blame] | 2021 | && idMatch(r.subId, subId, phoneId)) { |
| 2022 | try { |
| 2023 | r.callback.onOutgoingEmergencySms(emergencyNumber); |
| 2024 | } catch (RemoteException ex) { |
| 2025 | mRemoveList.add(r.binder); |
| 2026 | } |
| 2027 | } |
| 2028 | } |
| 2029 | } |
| 2030 | handleRemoveListLocked(); |
| 2031 | } |
| 2032 | } |
| 2033 | |
| 2034 | @Override |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 2035 | public void notifyCallQualityChanged(CallQuality callQuality, int phoneId, int subId, |
Jordan Liu | 65ed9d9 | 2019-02-19 14:42:07 -0800 | [diff] [blame] | 2036 | int callNetworkType) { |
Jordan Liu | 8218ddd | 2018-11-28 11:22:39 -0800 | [diff] [blame] | 2037 | if (!checkNotifyPermission("notifyCallQualityChanged()")) { |
| 2038 | return; |
| 2039 | } |
| 2040 | |
Jordan Liu | 8218ddd | 2018-11-28 11:22:39 -0800 | [diff] [blame] | 2041 | synchronized (mRecords) { |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 2042 | if (validatePhoneId(phoneId)) { |
| 2043 | // merge CallQuality with PreciseCallState and network type |
| 2044 | mCallQuality[phoneId] = callQuality; |
| 2045 | mCallNetworkType[phoneId] = callNetworkType; |
| 2046 | mCallAttributes[phoneId] = new CallAttributes(mPreciseCallState[phoneId], |
| 2047 | callNetworkType, callQuality); |
Jordan Liu | 8218ddd | 2018-11-28 11:22:39 -0800 | [diff] [blame] | 2048 | |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 2049 | for (Record r : mRecords) { |
| 2050 | if (r.matchPhoneStateListenerEvent( |
| 2051 | PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) |
| 2052 | && idMatch(r.subId, subId, phoneId)) { |
| 2053 | try { |
| 2054 | r.callback.onCallAttributesChanged(mCallAttributes[phoneId]); |
| 2055 | } catch (RemoteException ex) { |
| 2056 | mRemoveList.add(r.binder); |
| 2057 | } |
Jordan Liu | 8218ddd | 2018-11-28 11:22:39 -0800 | [diff] [blame] | 2058 | } |
| 2059 | } |
| 2060 | } |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 2061 | |
Jordan Liu | 8218ddd | 2018-11-28 11:22:39 -0800 | [diff] [blame] | 2062 | handleRemoveListLocked(); |
| 2063 | } |
| 2064 | } |
| 2065 | |
sqian | bdc5a73 | 2018-10-26 13:27:51 -0700 | [diff] [blame] | 2066 | |
| 2067 | @Override |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 2068 | public void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
| 2069 | final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " "); |
| 2070 | |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 2071 | if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 2072 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2073 | synchronized (mRecords) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 2074 | final int recordCount = mRecords.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2075 | pw.println("last known state:"); |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 2076 | pw.increaseIndent(); |
Malcolm Chen | 5d35461 | 2019-11-06 15:03:23 -0800 | [diff] [blame] | 2077 | for (int i = 0; i < getTelephonyManager().getPhoneCount(); i++) { |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 2078 | pw.println("Phone Id=" + i); |
| 2079 | pw.increaseIndent(); |
| 2080 | pw.println("mCallState=" + mCallState[i]); |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 2081 | pw.println("mRingingCallState=" + mRingingCallState[i]); |
| 2082 | pw.println("mForegroundCallState=" + mForegroundCallState[i]); |
| 2083 | pw.println("mBackgroundCallState=" + mBackgroundCallState[i]); |
| 2084 | pw.println("mPreciseCallState=" + mPreciseCallState[i]); |
| 2085 | pw.println("mCallDisconnectCause=" + mCallDisconnectCause[i]); |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 2086 | pw.println("mCallIncomingNumber=" + mCallIncomingNumber[i]); |
| 2087 | pw.println("mServiceState=" + mServiceState[i]); |
| 2088 | pw.println("mVoiceActivationState= " + mVoiceActivationState[i]); |
| 2089 | pw.println("mDataActivationState= " + mDataActivationState[i]); |
zxuan | 35a4702 | 2018-01-04 11:24:04 -0800 | [diff] [blame] | 2090 | pw.println("mUserMobileDataState= " + mUserMobileDataState[i]); |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 2091 | pw.println("mSignalStrength=" + mSignalStrength[i]); |
| 2092 | pw.println("mMessageWaiting=" + mMessageWaiting[i]); |
| 2093 | pw.println("mCallForwarding=" + mCallForwarding[i]); |
| 2094 | pw.println("mDataActivity=" + mDataActivity[i]); |
| 2095 | pw.println("mDataConnectionState=" + mDataConnectionState[i]); |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 2096 | pw.println("mCellLocation=" + mCellLocation[i]); |
| 2097 | pw.println("mCellInfo=" + mCellInfo.get(i)); |
Tyler Gunn | f3f89d0 | 2019-03-25 07:26:33 -0700 | [diff] [blame] | 2098 | pw.println("mImsCallDisconnectCause=" + mImsReasonInfo.get(i)); |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 2099 | pw.println("mSrvccState=" + mSrvccState[i]); |
| 2100 | pw.println("mOtaspMode=" + mOtaspMode[i]); |
| 2101 | pw.println("mCallPreciseDisconnectCause=" + mCallPreciseDisconnectCause[i]); |
| 2102 | pw.println("mCallQuality=" + mCallQuality[i]); |
| 2103 | pw.println("mCallAttributes=" + mCallAttributes[i]); |
| 2104 | pw.println("mCallNetworkType=" + mCallNetworkType[i]); |
| 2105 | pw.println("mPreciseDataConnectionState=" + mPreciseDataConnectionState[i]); |
Shuo Qian | 134334b | 2019-09-12 17:00:31 -0700 | [diff] [blame] | 2106 | pw.println("mOutgoingCallEmergencyNumber=" + mOutgoingCallEmergencyNumber[i]); |
| 2107 | pw.println("mOutgoingSmsEmergencyNumber=" + mOutgoingSmsEmergencyNumber[i]); |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 2108 | pw.decreaseIndent(); |
Sandeep Gutta | 2f32ac2 | 2014-07-16 03:14:03 +0530 | [diff] [blame] | 2109 | } |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 2110 | pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState); |
chen xu | d5deeb1 | 2019-04-29 13:57:42 -0700 | [diff] [blame] | 2111 | |
Malcolm Chen | e162365 | 2018-08-08 20:27:45 -0700 | [diff] [blame] | 2112 | pw.println("mPhoneCapability=" + mPhoneCapability); |
Malcolm Chen | 026451d | 2019-02-14 19:50:19 -0800 | [diff] [blame] | 2113 | pw.println("mActiveDataSubId=" + mActiveDataSubId); |
Chen Xu | 7395c63 | 2018-10-17 17:53:47 +0000 | [diff] [blame] | 2114 | pw.println("mRadioPowerState=" + mRadioPowerState); |
sqian | 9f93a12 | 2018-12-03 22:40:41 -0800 | [diff] [blame] | 2115 | pw.println("mEmergencyNumberList=" + mEmergencyNumberList); |
chen xu | addc270 | 2019-05-07 16:25:12 -0700 | [diff] [blame] | 2116 | pw.println("mDefaultPhoneId=" + mDefaultPhoneId); |
| 2117 | pw.println("mDefaultSubId=" + mDefaultSubId); |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 2118 | |
| 2119 | pw.decreaseIndent(); |
| 2120 | |
| 2121 | pw.println("local logs:"); |
| 2122 | pw.increaseIndent(); |
| 2123 | mLocalLog.dump(fd, pw, args); |
Jack Yu | 0c92c23 | 2019-04-04 15:10:17 -0700 | [diff] [blame] | 2124 | pw.println("listen logs:"); |
| 2125 | mListenLog.dump(fd, pw, args); |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 2126 | pw.decreaseIndent(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 2127 | pw.println("registrations: count=" + recordCount); |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 2128 | pw.increaseIndent(); |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 2129 | for (Record r : mRecords) { |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 2130 | pw.println(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2131 | } |
Jack Yu | d19b6ae | 2017-04-05 14:12:09 -0700 | [diff] [blame] | 2132 | pw.decreaseIndent(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2133 | } |
| 2134 | } |
| 2135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2136 | // |
| 2137 | // the legacy intent broadcasting |
| 2138 | // |
| 2139 | |
Meng Wang | 4c18a3a | 2019-12-09 17:00:01 -0800 | [diff] [blame] | 2140 | // Legacy intent action. |
| 2141 | /** Fired when a subscription's phone state changes. */ |
| 2142 | private static final String ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED = |
| 2143 | "android.intent.action.SUBSCRIPTION_PHONE_STATE"; |
| 2144 | |
| 2145 | // Legacy intent extra keys, copied from PhoneConstants. |
| 2146 | // Used in legacy intents sent here, for backward compatibility. |
| 2147 | private static final String PHONE_CONSTANTS_SLOT_KEY = "slot"; |
| 2148 | private static final String PHONE_CONSTANTS_SUBSCRIPTION_KEY = "subscription"; |
| 2149 | |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 2150 | private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 2151 | long ident = Binder.clearCallingIdentity(); |
| 2152 | try { |
| 2153 | mBatteryStats.notePhoneState(state.getState()); |
| 2154 | } catch (RemoteException re) { |
| 2155 | // Can't do much |
| 2156 | } finally { |
| 2157 | Binder.restoreCallingIdentity(ident); |
| 2158 | } |
| 2159 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2160 | Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); |
Christopher Tate | 42a386b | 2016-11-07 12:21:21 -0800 | [diff] [blame] | 2161 | intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2162 | Bundle data = new Bundle(); |
| 2163 | state.fillInNotifierBundle(data); |
| 2164 | intent.putExtras(data); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 2165 | // Pass the subscription along with the intent. |
Meng Wang | 4c18a3a | 2019-12-09 17:00:01 -0800 | [diff] [blame] | 2166 | intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId); |
chen xu | 379e531 | 2018-09-28 15:53:43 -0700 | [diff] [blame] | 2167 | intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId); |
Meng Wang | 4c18a3a | 2019-12-09 17:00:01 -0800 | [diff] [blame] | 2168 | intent.putExtra(PHONE_CONSTANTS_SLOT_KEY, phoneId); |
| 2169 | intent.putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, phoneId); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2170 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2171 | } |
| 2172 | |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 2173 | private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId, |
| 2174 | int subId) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2175 | long ident = Binder.clearCallingIdentity(); |
| 2176 | try { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 2177 | mBatteryStats.notePhoneSignalStrength(signalStrength); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2178 | } catch (RemoteException e) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 2179 | /* The remote entity disappeared, we can safely ignore the exception. */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2180 | } finally { |
| 2181 | Binder.restoreCallingIdentity(ident); |
| 2182 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 2183 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2184 | Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 2185 | Bundle data = new Bundle(); |
| 2186 | signalStrength.fillInNotifierBundle(data); |
| 2187 | intent.putExtras(data); |
Meng Wang | 4c18a3a | 2019-12-09 17:00:01 -0800 | [diff] [blame] | 2188 | intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId); |
| 2189 | intent.putExtra(PHONE_CONSTANTS_SLOT_KEY, phoneId); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2190 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2191 | } |
| 2192 | |
Sharvil Nanavati | 61a3ab0 | 2015-04-23 13:57:24 -0700 | [diff] [blame] | 2193 | /** |
| 2194 | * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be |
| 2195 | * a valid subId, in which case this function fires a subId-specific intent, or it |
| 2196 | * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send |
| 2197 | * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}). |
| 2198 | */ |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 2199 | private void broadcastCallStateChanged(int state, String incomingNumber, int phoneId, |
| 2200 | int subId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2201 | long ident = Binder.clearCallingIdentity(); |
| 2202 | try { |
| 2203 | if (state == TelephonyManager.CALL_STATE_IDLE) { |
| 2204 | mBatteryStats.notePhoneOff(); |
Yangster | 4ccebea | 2018-10-09 17:09:02 -0700 | [diff] [blame] | 2205 | StatsLog.write(StatsLog.PHONE_STATE_CHANGED, |
| 2206 | StatsLog.PHONE_STATE_CHANGED__STATE__OFF); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2207 | } else { |
| 2208 | mBatteryStats.notePhoneOn(); |
Yangster | 4ccebea | 2018-10-09 17:09:02 -0700 | [diff] [blame] | 2209 | StatsLog.write(StatsLog.PHONE_STATE_CHANGED, |
| 2210 | StatsLog.PHONE_STATE_CHANGED__STATE__ON); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2211 | } |
| 2212 | } catch (RemoteException e) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 2213 | /* 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] | 2214 | } finally { |
| 2215 | Binder.restoreCallingIdentity(ident); |
| 2216 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 2217 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2218 | Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED); |
Meng Wang | 762281b | 2019-12-06 10:37:58 -0800 | [diff] [blame] | 2219 | intent.putExtra(TelephonyManager.EXTRA_STATE, callStateToString(state)); |
Sharvil Nanavati | 61a3ab0 | 2015-04-23 13:57:24 -0700 | [diff] [blame] | 2220 | |
| 2221 | // If a valid subId was specified, we should fire off a subId-specific state |
| 2222 | // change intent and include the subId. |
| 2223 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
Meng Wang | 4c18a3a | 2019-12-09 17:00:01 -0800 | [diff] [blame] | 2224 | intent.setAction(ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED); |
| 2225 | intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId); |
chen xu | 379e531 | 2018-09-28 15:53:43 -0700 | [diff] [blame] | 2226 | intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId); |
Sharvil Nanavati | 61a3ab0 | 2015-04-23 13:57:24 -0700 | [diff] [blame] | 2227 | } |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 2228 | // If the phoneId is invalid, the broadcast is for overall call state. |
| 2229 | if (phoneId != SubscriptionManager.INVALID_PHONE_INDEX) { |
Meng Wang | 4c18a3a | 2019-12-09 17:00:01 -0800 | [diff] [blame] | 2230 | intent.putExtra(PHONE_CONSTANTS_SLOT_KEY, phoneId); |
| 2231 | intent.putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, phoneId); |
Shishir Agrawal | f7e59c1 | 2016-04-13 09:55:55 -0700 | [diff] [blame] | 2232 | } |
Sharvil Nanavati | 61a3ab0 | 2015-04-23 13:57:24 -0700 | [diff] [blame] | 2233 | |
Brad Ebinger | 51de96a | 2017-04-21 17:05:18 -0700 | [diff] [blame] | 2234 | // Wakeup apps for the (SUBSCRIPTION_)PHONE_STATE broadcast. |
| 2235 | intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); |
| 2236 | |
Tyler Gunn | 1c27bb7 | 2018-06-19 09:55:43 -0700 | [diff] [blame] | 2237 | // Create a version of the intent with the number always populated. |
Tyler Gunn | f955e56 | 2018-04-26 14:43:31 -0700 | [diff] [blame] | 2238 | Intent intentWithPhoneNumber = new Intent(intent); |
Tyler Gunn | 1c27bb7 | 2018-06-19 09:55:43 -0700 | [diff] [blame] | 2239 | intentWithPhoneNumber.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber); |
| 2240 | |
Amit Mahajan | 1cfd457 | 2015-07-09 11:12:19 -0700 | [diff] [blame] | 2241 | // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those |
| 2242 | // that have the runtime one |
Tyler Gunn | f955e56 | 2018-04-26 14:43:31 -0700 | [diff] [blame] | 2243 | mContext.sendBroadcastAsUser(intentWithPhoneNumber, UserHandle.ALL, |
Amit Mahajan | 1cfd457 | 2015-07-09 11:12:19 -0700 | [diff] [blame] | 2244 | android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2245 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL, |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 2246 | android.Manifest.permission.READ_PHONE_STATE, |
| 2247 | AppOpsManager.OP_READ_PHONE_STATE); |
Tyler Gunn | f955e56 | 2018-04-26 14:43:31 -0700 | [diff] [blame] | 2248 | mContext.sendBroadcastAsUserMultiplePermissions(intentWithPhoneNumber, UserHandle.ALL, |
| 2249 | new String[] { android.Manifest.permission.READ_PHONE_STATE, |
| 2250 | android.Manifest.permission.READ_CALL_LOG}); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2251 | } |
| 2252 | |
Meng Wang | 762281b | 2019-12-06 10:37:58 -0800 | [diff] [blame] | 2253 | /** Converts TelephonyManager#CALL_STATE_* to TelephonyManager#EXTRA_STATE_*. */ |
| 2254 | private static String callStateToString(int callState) { |
| 2255 | switch (callState) { |
| 2256 | case TelephonyManager.CALL_STATE_RINGING: |
| 2257 | return TelephonyManager.EXTRA_STATE_RINGING; |
| 2258 | case TelephonyManager.CALL_STATE_OFFHOOK: |
| 2259 | return TelephonyManager.EXTRA_STATE_OFFHOOK; |
| 2260 | default: |
| 2261 | return TelephonyManager.EXTRA_STATE_IDLE; |
| 2262 | } |
| 2263 | } |
| 2264 | |
Jack Yu | 4d1c945 | 2019-01-02 16:51:08 -0800 | [diff] [blame] | 2265 | private void broadcastDataConnectionStateChanged(int state, boolean isDataAllowed, String apn, |
| 2266 | String apnType, LinkProperties linkProperties, |
| 2267 | NetworkCapabilities networkCapabilities, |
| 2268 | boolean roaming, int subId) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2269 | // Note: not reporting to the battery stats service here, because the |
| 2270 | // status bar takes care of that after taking into account all of the |
| 2271 | // required info. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2272 | Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED); |
Meng Wang | 762281b | 2019-12-06 10:37:58 -0800 | [diff] [blame] | 2273 | intent.putExtra(TelephonyManager.EXTRA_STATE, dataStateToString(state)); |
Jack Yu | baeec62 | 2017-05-01 17:01:11 -0700 | [diff] [blame] | 2274 | if (!isDataAllowed) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 2275 | intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2276 | } |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 2277 | if (linkProperties != null) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 2278 | intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties); |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 2279 | String iface = linkProperties.getInterfaceName(); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 2280 | if (iface != null) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 2281 | intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 2282 | } |
| 2283 | } |
Robert Greenwalt | f9cb86a | 2014-04-08 17:34:00 -0700 | [diff] [blame] | 2284 | if (networkCapabilities != null) { |
| 2285 | intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities); |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 2286 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 2287 | if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true); |
Robert Greenwalt | a6d4248 | 2011-09-02 15:19:31 -0700 | [diff] [blame] | 2288 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 2289 | intent.putExtra(PhoneConstants.DATA_APN_KEY, apn); |
| 2290 | intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType); |
Meng Wang | 4c18a3a | 2019-12-09 17:00:01 -0800 | [diff] [blame] | 2291 | intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2292 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2293 | } |
| 2294 | |
Jack Yu | 4d1c945 | 2019-01-02 16:51:08 -0800 | [diff] [blame] | 2295 | private void broadcastDataConnectionFailed(String apnType, int subId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2296 | Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 2297 | intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType); |
Meng Wang | 4c18a3a | 2019-12-09 17:00:01 -0800 | [diff] [blame] | 2298 | intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2299 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2300 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 2301 | |
Andrew Flynn | ceaed68 | 2015-06-09 12:36:58 +0000 | [diff] [blame] | 2302 | private void enforceNotifyPermissionOrCarrierPrivilege(String method) { |
Jeff Davidson | d7bf38a | 2018-02-13 18:11:37 -0800 | [diff] [blame] | 2303 | if (checkNotifyPermission()) { |
Andrew Flynn | ceaed68 | 2015-06-09 12:36:58 +0000 | [diff] [blame] | 2304 | return; |
Andrew Flynn | 1f45264 | 2015-04-14 22:16:04 -0400 | [diff] [blame] | 2305 | } |
| 2306 | |
Jeff Davidson | d7bf38a | 2018-02-13 18:11:37 -0800 | [diff] [blame] | 2307 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2308 | SubscriptionManager.getDefaultSubscriptionId(), method); |
Andrew Flynn | 1f45264 | 2015-04-14 22:16:04 -0400 | [diff] [blame] | 2309 | } |
| 2310 | |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 2311 | private boolean checkNotifyPermission(String method) { |
Andrew Flynn | 1f45264 | 2015-04-14 22:16:04 -0400 | [diff] [blame] | 2312 | if (checkNotifyPermission()) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 2313 | return true; |
| 2314 | } |
| 2315 | String msg = "Modify Phone State Permission Denial: " + method + " from pid=" |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 2316 | + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid(); |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 2317 | if (DBG) log(msg); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 2318 | return false; |
| 2319 | } |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 2320 | |
Andrew Flynn | 1f45264 | 2015-04-14 22:16:04 -0400 | [diff] [blame] | 2321 | private boolean checkNotifyPermission() { |
| 2322 | return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2323 | == PackageManager.PERMISSION_GRANTED; |
| 2324 | } |
| 2325 | |
Philip P. Moltmann | 33692f7 | 2019-10-03 11:56:11 -0700 | [diff] [blame] | 2326 | private boolean checkListenerPermission(int events, int subId, String callingPackage, |
| 2327 | @Nullable String callingFeatureId, String message) { |
Hall Liu | ee31373 | 2018-11-27 14:36:51 -0800 | [diff] [blame] | 2328 | LocationAccessPolicy.LocationPermissionQuery.Builder locationQueryBuilder = |
| 2329 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2330 | .setCallingPackage(callingPackage) |
| 2331 | .setMethod(message + " events: " + events) |
| 2332 | .setCallingPid(Binder.getCallingPid()) |
| 2333 | .setCallingUid(Binder.getCallingUid()); |
| 2334 | |
| 2335 | boolean shouldCheckLocationPermissions = false; |
Hall Liu | 70bbc16 | 2018-03-02 17:44:46 -0800 | [diff] [blame] | 2336 | if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) { |
Hall Liu | ee31373 | 2018-11-27 14:36:51 -0800 | [diff] [blame] | 2337 | locationQueryBuilder.setMinSdkVersionForCoarse(0); |
| 2338 | shouldCheckLocationPermissions = true; |
| 2339 | } |
| 2340 | |
| 2341 | if ((events & ENFORCE_FINE_LOCATION_PERMISSION_MASK) != 0) { |
| 2342 | // Everything that requires fine location started in Q. So far... |
| 2343 | locationQueryBuilder.setMinSdkVersionForFine(Build.VERSION_CODES.Q); |
| 2344 | shouldCheckLocationPermissions = true; |
| 2345 | } |
| 2346 | |
| 2347 | if (shouldCheckLocationPermissions) { |
| 2348 | LocationAccessPolicy.LocationPermissionResult result = |
| 2349 | LocationAccessPolicy.checkLocationPermission( |
| 2350 | mContext, locationQueryBuilder.build()); |
| 2351 | switch (result) { |
| 2352 | case DENIED_HARD: |
| 2353 | throw new SecurityException("Unable to listen for events " + events + " due to " |
| 2354 | + "insufficient location permissions."); |
| 2355 | case DENIED_SOFT: |
| 2356 | return false; |
Hall Liu | 70bbc16 | 2018-03-02 17:44:46 -0800 | [diff] [blame] | 2357 | } |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 2358 | } |
| 2359 | |
Fyodor Kupolov | 309b2f63 | 2015-06-03 16:29:01 -0700 | [diff] [blame] | 2360 | if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) { |
Jeff Davidson | 29da89f | 2018-02-28 17:50:16 -0800 | [diff] [blame] | 2361 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 33692f7 | 2019-10-03 11:56:11 -0700 | [diff] [blame] | 2362 | mContext, subId, callingPackage, callingFeatureId, message)) { |
Jeff Davidson | d7bf38a | 2018-02-13 18:11:37 -0800 | [diff] [blame] | 2363 | return false; |
Amit Mahajan | 1cfd457 | 2015-07-09 11:12:19 -0700 | [diff] [blame] | 2364 | } |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 2365 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 2366 | |
| 2367 | if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) { |
| 2368 | mContext.enforceCallingOrSelfPermission( |
| 2369 | android.Manifest.permission.READ_PRECISE_PHONE_STATE, null); |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 2370 | } |
Jeff Davidson | d7bf38a | 2018-02-13 18:11:37 -0800 | [diff] [blame] | 2371 | |
Shuo Qian | 134334b | 2019-09-12 17:00:31 -0700 | [diff] [blame] | 2372 | if ((events & READ_ACTIVE_EMERGENCY_SESSION_PERMISSION_MASK) != 0) { |
| 2373 | mContext.enforceCallingOrSelfPermission( |
| 2374 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2375 | } |
| 2376 | |
Shuo Qian | 066e865 | 2018-04-25 21:02:35 +0000 | [diff] [blame] | 2377 | if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) { |
| 2378 | mContext.enforceCallingOrSelfPermission( |
| 2379 | android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null); |
| 2380 | } |
| 2381 | |
Brad Ebinger | efed982 | 2018-10-26 10:25:57 -0700 | [diff] [blame] | 2382 | if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) { |
| 2383 | mContext.enforceCallingOrSelfPermission( |
| 2384 | android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null); |
| 2385 | } |
| 2386 | |
chen xu | 6a942d48 | 2018-12-12 19:59:30 -0800 | [diff] [blame] | 2387 | if ((events & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) { |
| 2388 | mContext.enforceCallingOrSelfPermission( |
| 2389 | android.Manifest.permission.READ_PRECISE_PHONE_STATE, null); |
| 2390 | } |
| 2391 | |
Jordan Liu | 8218ddd | 2018-11-28 11:22:39 -0800 | [diff] [blame] | 2392 | if ((events & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) { |
| 2393 | mContext.enforceCallingOrSelfPermission( |
| 2394 | android.Manifest.permission.READ_PRECISE_PHONE_STATE, null); |
| 2395 | } |
| 2396 | |
chen xu | 52797b6 | 2019-01-18 13:16:31 -0800 | [diff] [blame] | 2397 | if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) { |
| 2398 | mContext.enforceCallingOrSelfPermission( |
| 2399 | android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null); |
| 2400 | } |
| 2401 | |
| 2402 | if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) != 0) { |
| 2403 | mContext.enforceCallingOrSelfPermission( |
| 2404 | android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null); |
| 2405 | } |
| 2406 | |
chen xu | 6ac5fc1 | 2019-01-24 14:14:13 -0800 | [diff] [blame] | 2407 | if ((events & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) { |
| 2408 | mContext.enforceCallingOrSelfPermission( |
| 2409 | android.Manifest.permission.READ_PRECISE_PHONE_STATE, null); |
| 2410 | } |
| 2411 | |
Jeff Davidson | d7bf38a | 2018-02-13 18:11:37 -0800 | [diff] [blame] | 2412 | return true; |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 2413 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 2414 | |
| 2415 | private void handleRemoveListLocked() { |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 2416 | int size = mRemoveList.size(); |
| 2417 | if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size); |
| 2418 | if (size > 0) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 2419 | for (IBinder b: mRemoveList) { |
| 2420 | remove(b); |
| 2421 | } |
| 2422 | mRemoveList.clear(); |
| 2423 | } |
| 2424 | } |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 2425 | |
| 2426 | private boolean validateEventsAndUserLocked(Record r, int events) { |
| 2427 | int foregroundUser; |
| 2428 | long callingIdentity = Binder.clearCallingIdentity(); |
| 2429 | boolean valid = false; |
| 2430 | try { |
| 2431 | foregroundUser = ActivityManager.getCurrentUser(); |
Hall Liu | 5fb337f | 2017-11-22 17:38:15 -0800 | [diff] [blame] | 2432 | valid = UserHandle.getUserId(r.callerUid) == foregroundUser |
| 2433 | && r.matchPhoneStateListenerEvent(events); |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 2434 | if (DBG | DBG_LOC) { |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 2435 | log("validateEventsAndUserLocked: valid=" + valid |
Hall Liu | 5fb337f | 2017-11-22 17:38:15 -0800 | [diff] [blame] | 2436 | + " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 2437 | + " r.events=" + r.events + " events=" + events); |
| 2438 | } |
| 2439 | } finally { |
| 2440 | Binder.restoreCallingIdentity(callingIdentity); |
| 2441 | } |
| 2442 | return valid; |
| 2443 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 2444 | |
| 2445 | private boolean validatePhoneId(int phoneId) { |
| 2446 | boolean valid = (phoneId >= 0) && (phoneId < mNumPhones); |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 2447 | if (VDBG) log("validatePhoneId: " + valid); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 2448 | return valid; |
| 2449 | } |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 2450 | |
| 2451 | private static void log(String s) { |
| 2452 | Rlog.d(TAG, s); |
| 2453 | } |
Wink Saville | 47d8d1b | 2014-07-10 13:01:52 -0700 | [diff] [blame] | 2454 | |
chen xu | 627d1b2 | 2019-04-11 02:16:19 -0700 | [diff] [blame] | 2455 | private static void loge(String s) { |
| 2456 | Rlog.e(TAG, s); |
| 2457 | } |
| 2458 | |
xinhe | 8b79fb6 | 2014-11-05 14:55:03 -0800 | [diff] [blame] | 2459 | boolean idMatch(int rSubId, int subId, int phoneId) { |
xinhe | ac11ae9 | 2014-12-18 10:02:14 -0800 | [diff] [blame] | 2460 | |
| 2461 | if(subId < 0) { |
| 2462 | // Invalid case, we need compare phoneId with default one. |
| 2463 | return (mDefaultPhoneId == phoneId); |
| 2464 | } |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 2465 | if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 2466 | return (subId == mDefaultSubId); |
| 2467 | } else { |
| 2468 | return (rSubId == subId); |
| 2469 | } |
| 2470 | } |
| 2471 | |
Hall Liu | ee31373 | 2018-11-27 14:36:51 -0800 | [diff] [blame] | 2472 | private boolean checkFineLocationAccess(Record r, int minSdk) { |
| 2473 | LocationAccessPolicy.LocationPermissionQuery query = |
| 2474 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2475 | .setCallingPackage(r.callingPackage) |
| 2476 | .setCallingPid(r.callerPid) |
| 2477 | .setCallingUid(r.callerUid) |
| 2478 | .setMethod("TelephonyRegistry push") |
Hall Liu | 879024a | 2019-04-17 13:33:43 -0700 | [diff] [blame] | 2479 | .setLogAsInfo(true) // we don't need to log an error every time we push |
Hall Liu | ee31373 | 2018-11-27 14:36:51 -0800 | [diff] [blame] | 2480 | .setMinSdkVersionForFine(minSdk) |
| 2481 | .build(); |
| 2482 | |
| 2483 | return Binder.withCleanCallingIdentity(() -> { |
| 2484 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2485 | LocationAccessPolicy.checkLocationPermission(mContext, query); |
| 2486 | return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 2487 | }); |
| 2488 | } |
| 2489 | |
| 2490 | private boolean checkCoarseLocationAccess(Record r, int minSdk) { |
| 2491 | LocationAccessPolicy.LocationPermissionQuery query = |
| 2492 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2493 | .setCallingPackage(r.callingPackage) |
| 2494 | .setCallingPid(r.callerPid) |
| 2495 | .setCallingUid(r.callerUid) |
| 2496 | .setMethod("TelephonyRegistry push") |
Hall Liu | 879024a | 2019-04-17 13:33:43 -0700 | [diff] [blame] | 2497 | .setLogAsInfo(true) // we don't need to log an error every time we push |
Hall Liu | ee31373 | 2018-11-27 14:36:51 -0800 | [diff] [blame] | 2498 | .setMinSdkVersionForCoarse(minSdk) |
| 2499 | .build(); |
| 2500 | |
| 2501 | return Binder.withCleanCallingIdentity(() -> { |
| 2502 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2503 | LocationAccessPolicy.checkLocationPermission(mContext, query); |
| 2504 | return locationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 2505 | }); |
Hall Liu | 5fb337f | 2017-11-22 17:38:15 -0800 | [diff] [blame] | 2506 | } |
| 2507 | |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 2508 | private void checkPossibleMissNotify(Record r, int phoneId) { |
| 2509 | int events = r.events; |
| 2510 | |
| 2511 | if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) { |
| 2512 | try { |
| 2513 | if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" + |
| 2514 | mServiceState[phoneId]); |
| 2515 | r.callback.onServiceStateChanged( |
| 2516 | new ServiceState(mServiceState[phoneId])); |
| 2517 | } catch (RemoteException ex) { |
Etan Cohen | a33cf07 | 2014-09-30 10:35:24 -0700 | [diff] [blame] | 2518 | mRemoveList.add(r.binder); |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 2519 | } |
| 2520 | } |
| 2521 | |
| 2522 | if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) { |
| 2523 | try { |
| 2524 | SignalStrength signalStrength = mSignalStrength[phoneId]; |
| 2525 | if (DBG) { |
| 2526 | log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength); |
| 2527 | } |
| 2528 | r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength)); |
| 2529 | } catch (RemoteException ex) { |
| 2530 | mRemoveList.add(r.binder); |
| 2531 | } |
| 2532 | } |
| 2533 | |
| 2534 | if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) { |
| 2535 | try { |
| 2536 | int gsmSignalStrength = mSignalStrength[phoneId] |
| 2537 | .getGsmSignalStrength(); |
| 2538 | if (DBG) { |
| 2539 | log("checkPossibleMissNotify: onSignalStrengthChanged SS=" + |
| 2540 | gsmSignalStrength); |
| 2541 | } |
| 2542 | r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1 |
| 2543 | : gsmSignalStrength)); |
| 2544 | } catch (RemoteException ex) { |
Etan Cohen | a33cf07 | 2014-09-30 10:35:24 -0700 | [diff] [blame] | 2545 | mRemoveList.add(r.binder); |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 2546 | } |
| 2547 | } |
| 2548 | |
| 2549 | if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) { |
| 2550 | try { |
| 2551 | if (DBG_LOC) { |
| 2552 | log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = " |
| 2553 | + mCellInfo.get(phoneId)); |
| 2554 | } |
Hall Liu | ee31373 | 2018-11-27 14:36:51 -0800 | [diff] [blame] | 2555 | if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) { |
Hall Liu | 5fb337f | 2017-11-22 17:38:15 -0800 | [diff] [blame] | 2556 | r.callback.onCellInfoChanged(mCellInfo.get(phoneId)); |
| 2557 | } |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 2558 | } catch (RemoteException ex) { |
Etan Cohen | a33cf07 | 2014-09-30 10:35:24 -0700 | [diff] [blame] | 2559 | mRemoveList.add(r.binder); |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 2560 | } |
| 2561 | } |
| 2562 | |
zxuan | 35a4702 | 2018-01-04 11:24:04 -0800 | [diff] [blame] | 2563 | if ((events & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) { |
| 2564 | try { |
| 2565 | if (VDBG) { |
| 2566 | log("checkPossibleMissNotify: onUserMobileDataStateChanged phoneId=" |
| 2567 | + phoneId + " umds=" + mUserMobileDataState[phoneId]); |
| 2568 | } |
| 2569 | r.callback.onUserMobileDataStateChanged(mUserMobileDataState[phoneId]); |
| 2570 | } catch (RemoteException ex) { |
| 2571 | mRemoveList.add(r.binder); |
| 2572 | } |
| 2573 | } |
| 2574 | |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 2575 | if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) { |
| 2576 | try { |
| 2577 | if (VDBG) { |
| 2578 | log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId=" |
| 2579 | + phoneId + " mwi=" + mMessageWaiting[phoneId]); |
| 2580 | } |
| 2581 | r.callback.onMessageWaitingIndicatorChanged( |
| 2582 | mMessageWaiting[phoneId]); |
| 2583 | } catch (RemoteException ex) { |
Etan Cohen | a33cf07 | 2014-09-30 10:35:24 -0700 | [diff] [blame] | 2584 | mRemoveList.add(r.binder); |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 2585 | } |
| 2586 | } |
| 2587 | |
| 2588 | if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) { |
| 2589 | try { |
| 2590 | if (VDBG) { |
| 2591 | log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId=" |
| 2592 | + phoneId + " cfi=" + mCallForwarding[phoneId]); |
| 2593 | } |
| 2594 | r.callback.onCallForwardingIndicatorChanged( |
| 2595 | mCallForwarding[phoneId]); |
| 2596 | } catch (RemoteException ex) { |
Etan Cohen | a33cf07 | 2014-09-30 10:35:24 -0700 | [diff] [blame] | 2597 | mRemoveList.add(r.binder); |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 2598 | } |
| 2599 | } |
| 2600 | |
| 2601 | if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) { |
| 2602 | try { |
| 2603 | if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = " |
| 2604 | + mCellLocation[phoneId]); |
Hall Liu | ee31373 | 2018-11-27 14:36:51 -0800 | [diff] [blame] | 2605 | if (checkFineLocationAccess(r, Build.VERSION_CODES.Q)) { |
Hall Liu | 5fb337f | 2017-11-22 17:38:15 -0800 | [diff] [blame] | 2606 | r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId])); |
| 2607 | } |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 2608 | } catch (RemoteException ex) { |
| 2609 | mRemoveList.add(r.binder); |
| 2610 | } |
| 2611 | } |
| 2612 | |
| 2613 | if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) { |
| 2614 | try { |
| 2615 | if (DBG) { |
| 2616 | log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState" |
| 2617 | + "=" + mDataConnectionState[phoneId] |
| 2618 | + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId] |
| 2619 | + ")"); |
| 2620 | } |
| 2621 | r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId], |
| 2622 | mDataConnectionNetworkType[phoneId]); |
| 2623 | } catch (RemoteException ex) { |
Etan Cohen | a33cf07 | 2014-09-30 10:35:24 -0700 | [diff] [blame] | 2624 | mRemoveList.add(r.binder); |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 2625 | } |
| 2626 | } |
| 2627 | } |
zoey chen | c722b45 | 2019-12-03 17:23:22 +0800 | [diff] [blame] | 2628 | |
| 2629 | /** |
Meng Wang | 762281b | 2019-12-06 10:37:58 -0800 | [diff] [blame] | 2630 | * Convert TelephonyManager.DATA_* to string. |
zoey chen | c722b45 | 2019-12-03 17:23:22 +0800 | [diff] [blame] | 2631 | * |
| 2632 | * @return The data state in string format. |
| 2633 | */ |
Meng Wang | 762281b | 2019-12-06 10:37:58 -0800 | [diff] [blame] | 2634 | private static String dataStateToString(int state) { |
zoey chen | c722b45 | 2019-12-03 17:23:22 +0800 | [diff] [blame] | 2635 | switch (state) { |
| 2636 | case TelephonyManager.DATA_DISCONNECTED: return "DISCONNECTED"; |
| 2637 | case TelephonyManager.DATA_CONNECTING: return "CONNECTING"; |
| 2638 | case TelephonyManager.DATA_CONNECTED: return "CONNECTED"; |
| 2639 | case TelephonyManager.DATA_SUSPENDED: return "SUSPENDED"; |
| 2640 | } |
| 2641 | return "UNKNOWN(" + state + ")"; |
| 2642 | } |
| 2643 | |
| 2644 | /** |
| 2645 | * Returns a string representation of the radio technology (network type) |
| 2646 | * currently in use on the device. |
| 2647 | * @param subId for which network type is returned |
| 2648 | * @return the name of the radio technology |
| 2649 | * |
| 2650 | */ |
| 2651 | private String getNetworkTypeName(@Annotation.NetworkType int type) { |
| 2652 | switch (type) { |
| 2653 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 2654 | return "GPRS"; |
| 2655 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 2656 | return "EDGE"; |
| 2657 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 2658 | return "UMTS"; |
| 2659 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 2660 | return "HSDPA"; |
| 2661 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 2662 | return "HSUPA"; |
| 2663 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 2664 | return "HSPA"; |
| 2665 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 2666 | return "CDMA"; |
| 2667 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 2668 | return "CDMA - EvDo rev. 0"; |
| 2669 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 2670 | return "CDMA - EvDo rev. A"; |
| 2671 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 2672 | return "CDMA - EvDo rev. B"; |
| 2673 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 2674 | return "CDMA - 1xRTT"; |
| 2675 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 2676 | return "LTE"; |
| 2677 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 2678 | return "CDMA - eHRPD"; |
| 2679 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 2680 | return "iDEN"; |
| 2681 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 2682 | return "HSPA+"; |
| 2683 | case TelephonyManager.NETWORK_TYPE_GSM: |
| 2684 | return "GSM"; |
| 2685 | case TelephonyManager.NETWORK_TYPE_TD_SCDMA: |
| 2686 | return "TD_SCDMA"; |
| 2687 | case TelephonyManager.NETWORK_TYPE_IWLAN: |
| 2688 | return "IWLAN"; |
| 2689 | case TelephonyManager.NETWORK_TYPE_LTE_CA: |
| 2690 | return "LTE_CA"; |
| 2691 | case TelephonyManager.NETWORK_TYPE_NR: |
| 2692 | return "NR"; |
| 2693 | default: |
| 2694 | return "UNKNOWN"; |
| 2695 | } |
| 2696 | } |
Meng Wang | be15dba | 2019-12-10 10:54:50 -0800 | [diff] [blame] | 2697 | |
| 2698 | /** Returns a new CallQuality object with default values. */ |
| 2699 | private static CallQuality createCallQuality() { |
| 2700 | return new CallQuality(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
| 2701 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2702 | } |