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