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