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