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