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