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