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