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