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