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