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