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