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 | |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [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(); |
| 293 | mConnectedApns = new ArrayList<String>(); |
| 294 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 295 | int numPhones = TelephonyManager.getDefault().getPhoneCount(); |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 296 | if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 297 | mNumPhones = numPhones; |
| 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); |
| 328 | } |
| 329 | |
David 'Digit' Turner | 4ef8ec3 | 2009-09-25 11:33:24 -0700 | [diff] [blame] | 330 | // Note that location can be null for non-phone builds like |
| 331 | // like the generic one. |
| 332 | if (location != null) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 333 | for (int i = 0; i < numPhones; i++) { |
| 334 | location.fillInNotifierBundle(mCellLocation[i]); |
| 335 | } |
David 'Digit' Turner | 4ef8ec3 | 2009-09-25 11:33:24 -0700 | [diff] [blame] | 336 | } |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 337 | mConnectedApns = new ArrayList<String>(); |
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 | } |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 717 | broadcastCallStateChanged(state, incomingNumber, |
Sharvil Nanavati | 61a3ab0 | 2015-04-23 13:57:24 -0700 | [diff] [blame] | 718 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 719 | } |
| 720 | |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 721 | public void notifyCallStateForSubscriber(int subId, int state, String incomingNumber) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 722 | if (!checkNotifyPermission("notifyCallState()")) { |
| 723 | return; |
| 724 | } |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 725 | if (VDBG) { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 726 | log("notifyCallStateForSubscriber: subId=" + subId |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 727 | + " state=" + state + " incomingNumber=" + incomingNumber); |
| 728 | } |
| 729 | synchronized (mRecords) { |
| 730 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 731 | if (validatePhoneId(phoneId)) { |
| 732 | mCallState[phoneId] = state; |
| 733 | mCallIncomingNumber[phoneId] = incomingNumber; |
| 734 | for (Record r : mRecords) { |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 735 | if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) && |
xinhe | 43c5029 | 2014-09-18 17:56:48 -0700 | [diff] [blame] | 736 | (r.subId == subId) && |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 737 | (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 738 | try { |
Fyodor Kupolov | 309b2f63 | 2015-06-03 16:29:01 -0700 | [diff] [blame] | 739 | String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId); |
| 740 | r.callback.onCallStateChanged(state, incomingNumberOrEmpty); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 741 | } catch (RemoteException ex) { |
| 742 | mRemoveList.add(r.binder); |
| 743 | } |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | handleRemoveListLocked(); |
| 748 | } |
| 749 | broadcastCallStateChanged(state, incomingNumber, subId); |
| 750 | } |
| 751 | |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 752 | public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 753 | if (!checkNotifyPermission("notifyServiceState()")){ |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 754 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 755 | } |
xinhe | 43c5029 | 2014-09-18 17:56:48 -0700 | [diff] [blame] | 756 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 757 | synchronized (mRecords) { |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 758 | if (VDBG) { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 759 | log("notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId |
Wink Saville | 47d8d1b | 2014-07-10 13:01:52 -0700 | [diff] [blame] | 760 | + " state=" + state); |
| 761 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 762 | if (validatePhoneId(phoneId)) { |
| 763 | mServiceState[phoneId] = state; |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 764 | logServiceStateChanged("notifyServiceStateForSubscriber", subId, phoneId, state); |
| 765 | if (VDBG) toStringLogSSC("notifyServiceStateForSubscriber"); |
Wink Saville | 47d8d1b | 2014-07-10 13:01:52 -0700 | [diff] [blame] | 766 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 767 | for (Record r : mRecords) { |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 768 | if (VDBG) { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 769 | log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 770 | + " phoneId=" + phoneId + " state=" + state); |
| 771 | } |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 772 | if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) && |
xinhe | 8b79fb6 | 2014-11-05 14:55:03 -0800 | [diff] [blame] | 773 | idMatch(r.subId, subId, phoneId)) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 774 | try { |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 775 | if (DBG) { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 776 | log("notifyServiceStateForSubscriber: callback.onSSC r=" + r |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 777 | + " subId=" + subId + " phoneId=" + phoneId |
| 778 | + " state=" + state); |
| 779 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 780 | r.callback.onServiceStateChanged(new ServiceState(state)); |
| 781 | } catch (RemoteException ex) { |
| 782 | mRemoveList.add(r.binder); |
| 783 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 784 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 785 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 786 | } else { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 787 | log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 789 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 790 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 791 | broadcastServiceStateChanged(state, subId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 792 | } |
| 793 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 794 | public void notifySignalStrength(SignalStrength signalStrength) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 795 | notifySignalStrengthForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, |
| 796 | signalStrength); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 799 | public void notifySignalStrengthForSubscriber(int subId, 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) { |
| 804 | log("notifySignalStrengthForSubscriber: subId=" + subId |
| 805 | + " signalStrength=" + signalStrength); |
| 806 | toStringLogSSC("notifySignalStrengthForSubscriber"); |
| 807 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | synchronized (mRecords) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 809 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 810 | if (validatePhoneId(phoneId)) { |
Amit Mahajan | 1466a9c | 2015-04-27 22:58:29 +0000 | [diff] [blame] | 811 | if (VDBG) log("notifySignalStrengthForSubscriber: 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) { |
| 815 | log("notifySignalStrengthForSubscriber: r=" + r + " subId=" + subId |
| 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) { |
| 823 | log("notifySignalStrengthForSubscriber: callback.onSsS r=" + r |
| 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) { |
| 838 | log("notifySignalStrengthForSubscriber: callback.onSS r=" + r |
| 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 { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 849 | log("notifySignalStrengthForSubscriber: 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 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 853 | broadcastSignalStrengthChanged(signalStrength, 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) { |
| 988 | if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY)) { |
| 989 | try { |
| 990 | r.callback.onDataActivity(state); |
| 991 | } catch (RemoteException ex) { |
| 992 | mRemoveList.add(r.binder); |
| 993 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 997 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 998 | } |
| 999 | } |
| 1000 | |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1001 | public void notifyDataConnection(int state, boolean isDataConnectivityPossible, |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 1002 | String reason, String apn, String apnType, LinkProperties linkProperties, |
Robert Greenwalt | f9cb86a | 2014-04-08 17:34:00 -0700 | [diff] [blame] | 1003 | NetworkCapabilities networkCapabilities, int networkType, boolean roaming) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1004 | notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state, |
xinhe | 43c5029 | 2014-09-18 17:56:48 -0700 | [diff] [blame] | 1005 | isDataConnectivityPossible,reason, apn, apnType, linkProperties, |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1006 | networkCapabilities, networkType, roaming); |
| 1007 | } |
| 1008 | |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1009 | public void notifyDataConnectionForSubscriber(int subId, int state, |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1010 | boolean isDataConnectivityPossible, String reason, String apn, String apnType, |
| 1011 | LinkProperties linkProperties, NetworkCapabilities networkCapabilities, |
| 1012 | int networkType, boolean roaming) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1013 | if (!checkNotifyPermission("notifyDataConnection()" )) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 1014 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1015 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1016 | if (VDBG) { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 1017 | log("notifyDataConnectionForSubscriber: subId=" + subId |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1018 | + " state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible |
| 1019 | + " reason='" + reason |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 1020 | + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType |
xinhe | ac11ae9 | 2014-12-18 10:02:14 -0800 | [diff] [blame] | 1021 | + " mRecords.size()=" + mRecords.size()); |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 1022 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1023 | synchronized (mRecords) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1024 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1025 | if (validatePhoneId(phoneId)) { |
| 1026 | boolean modified = false; |
| 1027 | if (state == TelephonyManager.DATA_CONNECTED) { |
| 1028 | if (!mConnectedApns.contains(apnType)) { |
| 1029 | mConnectedApns.add(apnType); |
| 1030 | if (mDataConnectionState[phoneId] != state) { |
| 1031 | mDataConnectionState[phoneId] = state; |
| 1032 | modified = true; |
| 1033 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1034 | } |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1035 | } else { |
| 1036 | if (mConnectedApns.remove(apnType)) { |
| 1037 | if (mConnectedApns.isEmpty()) { |
| 1038 | mDataConnectionState[phoneId] = state; |
| 1039 | modified = true; |
| 1040 | } else { |
| 1041 | // leave mDataConnectionState as is and |
| 1042 | // send out the new status for the APN in question. |
Wink Saville | baf21da | 2014-11-19 16:03:09 -0800 | [diff] [blame] | 1043 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1044 | } |
| 1045 | } |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1046 | mDataConnectionPossible[phoneId] = isDataConnectivityPossible; |
| 1047 | mDataConnectionReason[phoneId] = reason; |
| 1048 | mDataConnectionLinkProperties[phoneId] = linkProperties; |
| 1049 | mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities; |
| 1050 | if (mDataConnectionNetworkType[phoneId] != networkType) { |
| 1051 | mDataConnectionNetworkType[phoneId] = networkType; |
| 1052 | // need to tell registered listeners about the new network type |
| 1053 | modified = true; |
| 1054 | } |
| 1055 | if (modified) { |
| 1056 | if (DBG) { |
| 1057 | log("onDataConnectionStateChanged(" + mDataConnectionState[phoneId] |
| 1058 | + ", " + mDataConnectionNetworkType[phoneId] + ")"); |
| 1059 | } |
| 1060 | for (Record r : mRecords) { |
| 1061 | if (r.matchPhoneStateListenerEvent( |
| 1062 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) && |
| 1063 | idMatch(r.subId, subId, phoneId)) { |
| 1064 | try { |
| 1065 | log("Notify data connection state changed on sub: " + |
| 1066 | subId); |
| 1067 | r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId], |
| 1068 | mDataConnectionNetworkType[phoneId]); |
| 1069 | } catch (RemoteException ex) { |
| 1070 | mRemoveList.add(r.binder); |
| 1071 | } |
| 1072 | } |
| 1073 | } |
| 1074 | handleRemoveListLocked(); |
| 1075 | } |
| 1076 | mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType, |
| 1077 | apnType, apn, reason, linkProperties, ""); |
| 1078 | for (Record r : mRecords) { |
| 1079 | if (r.matchPhoneStateListenerEvent( |
| 1080 | PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) { |
| 1081 | try { |
| 1082 | r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState); |
| 1083 | } catch (RemoteException ex) { |
| 1084 | mRemoveList.add(r.binder); |
| 1085 | } |
Wink Saville | 2d1ee98 | 2014-11-20 20:29:51 +0000 | [diff] [blame] | 1086 | } |
| 1087 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1088 | } |
| 1089 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1090 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1091 | broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn, |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1092 | apnType, linkProperties, networkCapabilities, roaming, subId); |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1093 | broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason, |
| 1094 | linkProperties, ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1095 | } |
| 1096 | |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 1097 | public void notifyDataConnectionFailed(String reason, String apnType) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1098 | notifyDataConnectionFailedForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, |
xinhe | 43c5029 | 2014-09-18 17:56:48 -0700 | [diff] [blame] | 1099 | reason, apnType); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1100 | } |
| 1101 | |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1102 | public void notifyDataConnectionFailedForSubscriber(int subId, |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1103 | String reason, String apnType) { |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1104 | if (!checkNotifyPermission("notifyDataConnectionFailed()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 1105 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1106 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1107 | if (VDBG) { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 1108 | log("notifyDataConnectionFailedForSubscriber: subId=" + subId |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1109 | + " reason=" + reason + " apnType=" + apnType); |
| 1110 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1111 | synchronized (mRecords) { |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1112 | mPreciseDataConnectionState = new PreciseDataConnectionState( |
| 1113 | TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN, |
| 1114 | apnType, "", reason, null, ""); |
| 1115 | for (Record r : mRecords) { |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 1116 | if (r.matchPhoneStateListenerEvent( |
| 1117 | PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) { |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1118 | try { |
| 1119 | r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState); |
| 1120 | } catch (RemoteException ex) { |
| 1121 | mRemoveList.add(r.binder); |
| 1122 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1123 | } |
| 1124 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1125 | handleRemoveListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1126 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1127 | broadcastDataConnectionFailed(reason, apnType, subId); |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1128 | broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN, |
| 1129 | TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | public void notifyCellLocation(Bundle cellLocation) { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1133 | notifyCellLocationForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, cellLocation); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1136 | public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 1137 | log("notifyCellLocationForSubscriber: subId=" + subId |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1138 | + " cellLocation=" + cellLocation); |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1139 | if (!checkNotifyPermission("notifyCellLocation()")) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 1140 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1141 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1142 | if (VDBG) { |
Wink Saville | bc02727 | 2014-09-08 14:50:58 -0700 | [diff] [blame] | 1143 | log("notifyCellLocationForSubscriber: subId=" + subId |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1144 | + " cellLocation=" + cellLocation); |
| 1145 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1146 | synchronized (mRecords) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1147 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 1148 | if (validatePhoneId(phoneId)) { |
| 1149 | mCellLocation[phoneId] = cellLocation; |
| 1150 | for (Record r : mRecords) { |
xinhe | 43c5029 | 2014-09-18 17:56:48 -0700 | [diff] [blame] | 1151 | if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) && |
xinhe | 8b79fb6 | 2014-11-05 14:55:03 -0800 | [diff] [blame] | 1152 | idMatch(r.subId, subId, phoneId)) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1153 | try { |
| 1154 | if (DBG_LOC) { |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 1155 | log("notifyCellLocation: cellLocation=" + cellLocation |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1156 | + " r=" + r); |
| 1157 | } |
| 1158 | r.callback.onCellLocationChanged(new Bundle(cellLocation)); |
| 1159 | } catch (RemoteException ex) { |
| 1160 | mRemoveList.add(r.binder); |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 1161 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 1162 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | } |
| 1164 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 1165 | handleRemoveListLocked(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1166 | } |
| 1167 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1168 | |
Wink Saville | fd2d013 | 2010-10-28 14:22:26 -0700 | [diff] [blame] | 1169 | public void notifyOtaspChanged(int otaspMode) { |
| 1170 | if (!checkNotifyPermission("notifyOtaspChanged()" )) { |
| 1171 | return; |
| 1172 | } |
| 1173 | synchronized (mRecords) { |
| 1174 | mOtaspMode = otaspMode; |
| 1175 | for (Record r : mRecords) { |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 1176 | if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_OTASP_CHANGED)) { |
Wink Saville | fd2d013 | 2010-10-28 14:22:26 -0700 | [diff] [blame] | 1177 | try { |
| 1178 | r.callback.onOtaspChanged(otaspMode); |
| 1179 | } catch (RemoteException ex) { |
| 1180 | mRemoveList.add(r.binder); |
| 1181 | } |
| 1182 | } |
| 1183 | } |
| 1184 | handleRemoveListLocked(); |
| 1185 | } |
| 1186 | } |
| 1187 | |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1188 | public void notifyPreciseCallState(int ringingCallState, int foregroundCallState, |
| 1189 | int backgroundCallState) { |
| 1190 | if (!checkNotifyPermission("notifyPreciseCallState()")) { |
| 1191 | return; |
| 1192 | } |
| 1193 | synchronized (mRecords) { |
| 1194 | mRingingCallState = ringingCallState; |
| 1195 | mForegroundCallState = foregroundCallState; |
| 1196 | mBackgroundCallState = backgroundCallState; |
| 1197 | mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState, |
| 1198 | backgroundCallState, |
| 1199 | DisconnectCause.NOT_VALID, |
| 1200 | PreciseDisconnectCause.NOT_VALID); |
| 1201 | for (Record r : mRecords) { |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 1202 | if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) { |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1203 | try { |
| 1204 | r.callback.onPreciseCallStateChanged(mPreciseCallState); |
| 1205 | } catch (RemoteException ex) { |
| 1206 | mRemoveList.add(r.binder); |
| 1207 | } |
| 1208 | } |
| 1209 | } |
| 1210 | handleRemoveListLocked(); |
| 1211 | } |
| 1212 | broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState, |
| 1213 | DisconnectCause.NOT_VALID, |
| 1214 | PreciseDisconnectCause.NOT_VALID); |
| 1215 | } |
| 1216 | |
| 1217 | public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) { |
| 1218 | if (!checkNotifyPermission("notifyDisconnectCause()")) { |
| 1219 | return; |
| 1220 | } |
| 1221 | synchronized (mRecords) { |
| 1222 | mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState, |
| 1223 | mBackgroundCallState, disconnectCause, preciseDisconnectCause); |
| 1224 | for (Record r : mRecords) { |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 1225 | if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_CALL_STATE)) { |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1226 | try { |
| 1227 | r.callback.onPreciseCallStateChanged(mPreciseCallState); |
| 1228 | } catch (RemoteException ex) { |
| 1229 | mRemoveList.add(r.binder); |
| 1230 | } |
| 1231 | } |
| 1232 | } |
| 1233 | handleRemoveListLocked(); |
| 1234 | } |
| 1235 | broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState, |
| 1236 | mBackgroundCallState, disconnectCause, preciseDisconnectCause); |
| 1237 | } |
| 1238 | |
| 1239 | public void notifyPreciseDataConnectionFailed(String reason, String apnType, |
| 1240 | String apn, String failCause) { |
| 1241 | if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) { |
| 1242 | return; |
| 1243 | } |
| 1244 | synchronized (mRecords) { |
| 1245 | mPreciseDataConnectionState = new PreciseDataConnectionState( |
| 1246 | TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN, |
| 1247 | apnType, apn, reason, null, failCause); |
| 1248 | for (Record r : mRecords) { |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 1249 | if (r.matchPhoneStateListenerEvent( |
| 1250 | PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) { |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1251 | try { |
| 1252 | r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState); |
| 1253 | } catch (RemoteException ex) { |
| 1254 | mRemoveList.add(r.binder); |
| 1255 | } |
| 1256 | } |
| 1257 | } |
| 1258 | handleRemoveListLocked(); |
| 1259 | } |
| 1260 | broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN, |
| 1261 | TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause); |
| 1262 | } |
| 1263 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1264 | public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) { |
| 1265 | if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) { |
| 1266 | return; |
| 1267 | } |
| 1268 | synchronized (mRecords) { |
| 1269 | mVoLteServiceState = lteState; |
| 1270 | for (Record r : mRecords) { |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 1271 | if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1272 | try { |
| 1273 | r.callback.onVoLteServiceStateChanged( |
| 1274 | new VoLteServiceState(mVoLteServiceState)); |
| 1275 | } catch (RemoteException ex) { |
| 1276 | mRemoveList.add(r.binder); |
| 1277 | } |
| 1278 | } |
| 1279 | } |
| 1280 | handleRemoveListLocked(); |
| 1281 | } |
| 1282 | } |
| 1283 | |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1284 | public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) { |
New Author Steven Liu | 485f209 | 2014-09-11 10:18:45 -0500 | [diff] [blame] | 1285 | if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) { |
| 1286 | return; |
| 1287 | } |
| 1288 | |
| 1289 | synchronized (mRecords) { |
| 1290 | for (Record r : mRecords) { |
| 1291 | if (VDBG) { |
| 1292 | log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId); |
| 1293 | } |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 1294 | if ((r.matchPhoneStateListenerEvent( |
| 1295 | PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) && |
New Author Steven Liu | 485f209 | 2014-09-11 10:18:45 -0500 | [diff] [blame] | 1296 | ((r.subId == subId) || |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1297 | (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) { |
New Author Steven Liu | 485f209 | 2014-09-11 10:18:45 -0500 | [diff] [blame] | 1298 | try { |
| 1299 | r.callback.onOemHookRawEvent(rawData); |
| 1300 | } catch (RemoteException ex) { |
| 1301 | mRemoveList.add(r.binder); |
| 1302 | } |
| 1303 | } |
| 1304 | } |
| 1305 | handleRemoveListLocked(); |
| 1306 | } |
| 1307 | } |
| 1308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1309 | @Override |
| 1310 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1311 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 1312 | != PackageManager.PERMISSION_GRANTED) { |
| 1313 | pw.println("Permission Denial: can't dump telephony.registry from from pid=" |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1314 | + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1315 | return; |
| 1316 | } |
| 1317 | synchronized (mRecords) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1318 | final int recordCount = mRecords.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1319 | pw.println("last known state:"); |
Sandeep Gutta | 2f32ac2 | 2014-07-16 03:14:03 +0530 | [diff] [blame] | 1320 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1321 | pw.println(" Phone Id=" + i); |
| 1322 | pw.println(" mCallState=" + mCallState[i]); |
| 1323 | pw.println(" mCallIncomingNumber=" + mCallIncomingNumber[i]); |
| 1324 | pw.println(" mServiceState=" + mServiceState[i]); |
| 1325 | pw.println(" mSignalStrength=" + mSignalStrength[i]); |
| 1326 | pw.println(" mMessageWaiting=" + mMessageWaiting[i]); |
| 1327 | pw.println(" mCallForwarding=" + mCallForwarding[i]); |
| 1328 | pw.println(" mDataActivity=" + mDataActivity[i]); |
| 1329 | pw.println(" mDataConnectionState=" + mDataConnectionState[i]); |
| 1330 | pw.println(" mDataConnectionPossible=" + mDataConnectionPossible[i]); |
| 1331 | pw.println(" mDataConnectionReason=" + mDataConnectionReason[i]); |
| 1332 | pw.println(" mDataConnectionApn=" + mDataConnectionApn[i]); |
| 1333 | pw.println(" mDataConnectionLinkProperties=" + mDataConnectionLinkProperties[i]); |
| 1334 | pw.println(" mDataConnectionNetworkCapabilities=" + |
| 1335 | mDataConnectionNetworkCapabilities[i]); |
| 1336 | pw.println(" mCellLocation=" + mCellLocation[i]); |
| 1337 | pw.println(" mCellInfo=" + mCellInfo.get(i)); |
| 1338 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1339 | pw.println("registrations: count=" + recordCount); |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 1340 | for (Record r : mRecords) { |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 1341 | pw.println(" " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1342 | } |
| 1343 | } |
| 1344 | } |
| 1345 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1346 | // |
| 1347 | // the legacy intent broadcasting |
| 1348 | // |
| 1349 | |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1350 | private void broadcastServiceStateChanged(ServiceState state, int subId) { |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1351 | long ident = Binder.clearCallingIdentity(); |
| 1352 | try { |
| 1353 | mBatteryStats.notePhoneState(state.getState()); |
| 1354 | } catch (RemoteException re) { |
| 1355 | // Can't do much |
| 1356 | } finally { |
| 1357 | Binder.restoreCallingIdentity(ident); |
| 1358 | } |
| 1359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1360 | Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); |
| 1361 | Bundle data = new Bundle(); |
| 1362 | state.fillInNotifierBundle(data); |
| 1363 | intent.putExtras(data); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1364 | // Pass the subscription along with the intent. |
| 1365 | intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 1366 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1367 | } |
| 1368 | |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1369 | private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int subId) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1370 | long ident = Binder.clearCallingIdentity(); |
| 1371 | try { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1372 | mBatteryStats.notePhoneSignalStrength(signalStrength); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1373 | } catch (RemoteException e) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1374 | /* The remote entity disappeared, we can safely ignore the exception. */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1375 | } finally { |
| 1376 | Binder.restoreCallingIdentity(ident); |
| 1377 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1378 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1379 | Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED); |
Dianne Hackborn | 1c633fc | 2009-12-08 19:45:14 -0800 | [diff] [blame] | 1380 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1381 | Bundle data = new Bundle(); |
| 1382 | signalStrength.fillInNotifierBundle(data); |
| 1383 | intent.putExtras(data); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1384 | intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 1385 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1386 | } |
| 1387 | |
Sharvil Nanavati | 61a3ab0 | 2015-04-23 13:57:24 -0700 | [diff] [blame] | 1388 | /** |
| 1389 | * Broadcasts an intent notifying apps of a phone state change. {@code subId} can be |
| 1390 | * a valid subId, in which case this function fires a subId-specific intent, or it |
| 1391 | * can be {@code SubscriptionManager.INVALID_SUBSCRIPTION_ID}, in which case we send |
| 1392 | * a global state change broadcast ({@code TelephonyManager.ACTION_PHONE_STATE_CHANGED}). |
| 1393 | */ |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1394 | private void broadcastCallStateChanged(int state, String incomingNumber, int subId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1395 | long ident = Binder.clearCallingIdentity(); |
| 1396 | try { |
| 1397 | if (state == TelephonyManager.CALL_STATE_IDLE) { |
| 1398 | mBatteryStats.notePhoneOff(); |
| 1399 | } else { |
| 1400 | mBatteryStats.notePhoneOn(); |
| 1401 | } |
| 1402 | } catch (RemoteException e) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1403 | /* 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] | 1404 | } finally { |
| 1405 | Binder.restoreCallingIdentity(ident); |
| 1406 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1407 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1408 | Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1409 | intent.putExtra(PhoneConstants.STATE_KEY, |
| 1410 | DefaultPhoneNotifier.convertCallState(state).toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1411 | if (!TextUtils.isEmpty(incomingNumber)) { |
| 1412 | intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber); |
| 1413 | } |
Sharvil Nanavati | 61a3ab0 | 2015-04-23 13:57:24 -0700 | [diff] [blame] | 1414 | |
| 1415 | // If a valid subId was specified, we should fire off a subId-specific state |
| 1416 | // change intent and include the subId. |
| 1417 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 1418 | intent.setAction(PhoneConstants.ACTION_SUBSCRIPTION_PHONE_STATE_CHANGED); |
| 1419 | intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId); |
| 1420 | } |
| 1421 | |
Amit Mahajan | 1cfd457 | 2015-07-09 11:12:19 -0700 | [diff] [blame] | 1422 | // Send broadcast twice, once for apps that have PRIVILEGED permission and once for those |
| 1423 | // that have the runtime one |
| 1424 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL, |
| 1425 | android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 1426 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL, |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 1427 | android.Manifest.permission.READ_PHONE_STATE, |
| 1428 | AppOpsManager.OP_READ_PHONE_STATE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1429 | } |
| 1430 | |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 1431 | private void broadcastDataConnectionStateChanged(int state, |
| 1432 | boolean isDataConnectivityPossible, |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 1433 | String reason, String apn, String apnType, LinkProperties linkProperties, |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1434 | NetworkCapabilities networkCapabilities, boolean roaming, int subId) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1435 | // Note: not reporting to the battery stats service here, because the |
| 1436 | // status bar takes care of that after taking into account all of the |
| 1437 | // required info. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1438 | Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1439 | intent.putExtra(PhoneConstants.STATE_KEY, |
| 1440 | DefaultPhoneNotifier.convertDataState(state).toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1441 | if (!isDataConnectivityPossible) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1442 | intent.putExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1443 | } |
| 1444 | if (reason != null) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1445 | intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | } |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 1447 | if (linkProperties != null) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1448 | intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties); |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 1449 | String iface = linkProperties.getInterfaceName(); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1450 | if (iface != null) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1451 | intent.putExtra(PhoneConstants.DATA_IFACE_NAME_KEY, iface); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1452 | } |
| 1453 | } |
Robert Greenwalt | f9cb86a | 2014-04-08 17:34:00 -0700 | [diff] [blame] | 1454 | if (networkCapabilities != null) { |
| 1455 | intent.putExtra(PhoneConstants.DATA_NETWORK_CAPABILITIES_KEY, networkCapabilities); |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 1456 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1457 | if (roaming) intent.putExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, true); |
Robert Greenwalt | a6d4248 | 2011-09-02 15:19:31 -0700 | [diff] [blame] | 1458 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1459 | intent.putExtra(PhoneConstants.DATA_APN_KEY, apn); |
| 1460 | intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1461 | intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 1462 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1463 | } |
| 1464 | |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1465 | private void broadcastDataConnectionFailed(String reason, String apnType, |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1466 | int subId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1467 | Intent intent = new Intent(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1468 | intent.putExtra(PhoneConstants.FAILURE_REASON_KEY, reason); |
| 1469 | intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1470 | intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 1471 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1472 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1473 | |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1474 | private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState, |
| 1475 | int backgroundCallState, int disconnectCause, int preciseDisconnectCause) { |
| 1476 | Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED); |
| 1477 | intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState); |
| 1478 | intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState); |
| 1479 | intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState); |
| 1480 | intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause); |
| 1481 | intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause); |
| 1482 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL, |
| 1483 | android.Manifest.permission.READ_PRECISE_PHONE_STATE); |
| 1484 | } |
| 1485 | |
| 1486 | private void broadcastPreciseDataConnectionStateChanged(int state, int networkType, |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1487 | String apnType, String apn, String reason, LinkProperties linkProperties, |
| 1488 | String failCause) { |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1489 | Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED); |
| 1490 | intent.putExtra(PhoneConstants.STATE_KEY, state); |
| 1491 | intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType); |
| 1492 | if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason); |
| 1493 | if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType); |
| 1494 | if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn); |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1495 | if (linkProperties != null) { |
| 1496 | intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY,linkProperties); |
| 1497 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1498 | if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause); |
| 1499 | |
| 1500 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL, |
| 1501 | android.Manifest.permission.READ_PRECISE_PHONE_STATE); |
| 1502 | } |
| 1503 | |
Andrew Flynn | ceaed68 | 2015-06-09 12:36:58 +0000 | [diff] [blame] | 1504 | private void enforceNotifyPermissionOrCarrierPrivilege(String method) { |
| 1505 | if (checkNotifyPermission()) { |
| 1506 | return; |
Andrew Flynn | 1f45264 | 2015-04-14 22:16:04 -0400 | [diff] [blame] | 1507 | } |
| 1508 | |
Andrew Flynn | ceaed68 | 2015-06-09 12:36:58 +0000 | [diff] [blame] | 1509 | enforceCarrierPrivilege(); |
Andrew Flynn | 1f45264 | 2015-04-14 22:16:04 -0400 | [diff] [blame] | 1510 | } |
| 1511 | |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1512 | private boolean checkNotifyPermission(String method) { |
Andrew Flynn | 1f45264 | 2015-04-14 22:16:04 -0400 | [diff] [blame] | 1513 | if (checkNotifyPermission()) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 1514 | return true; |
| 1515 | } |
| 1516 | String msg = "Modify Phone State Permission Denial: " + method + " from pid=" |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1517 | + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid(); |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 1518 | if (DBG) log(msg); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 1519 | return false; |
| 1520 | } |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1521 | |
Andrew Flynn | 1f45264 | 2015-04-14 22:16:04 -0400 | [diff] [blame] | 1522 | private boolean checkNotifyPermission() { |
| 1523 | return mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 1524 | == PackageManager.PERMISSION_GRANTED; |
| 1525 | } |
| 1526 | |
Andrew Flynn | ceaed68 | 2015-06-09 12:36:58 +0000 | [diff] [blame] | 1527 | private void enforceCarrierPrivilege() { |
Andrew Flynn | 1f45264 | 2015-04-14 22:16:04 -0400 | [diff] [blame] | 1528 | TelephonyManager tm = TelephonyManager.getDefault(); |
| 1529 | String[] pkgs = mContext.getPackageManager().getPackagesForUid(Binder.getCallingUid()); |
| 1530 | for (String pkg : pkgs) { |
| 1531 | if (tm.checkCarrierPrivilegesForPackage(pkg) == |
| 1532 | TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Andrew Flynn | ceaed68 | 2015-06-09 12:36:58 +0000 | [diff] [blame] | 1533 | return; |
Andrew Flynn | 1f45264 | 2015-04-14 22:16:04 -0400 | [diff] [blame] | 1534 | } |
| 1535 | } |
| 1536 | |
Andrew Flynn | ceaed68 | 2015-06-09 12:36:58 +0000 | [diff] [blame] | 1537 | String msg = "Carrier Privilege Permission Denial: from pid=" + Binder.getCallingPid() |
| 1538 | + ", uid=" + Binder.getCallingUid(); |
| 1539 | if (DBG) log(msg); |
| 1540 | throw new SecurityException(msg); |
Andrew Flynn | 1f45264 | 2015-04-14 22:16:04 -0400 | [diff] [blame] | 1541 | } |
| 1542 | |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1543 | private void checkListenerPermission(int events) { |
| 1544 | if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) { |
| 1545 | mContext.enforceCallingOrSelfPermission( |
| 1546 | android.Manifest.permission.ACCESS_COARSE_LOCATION, null); |
| 1547 | |
| 1548 | } |
| 1549 | |
John Wang | 963db55d | 2012-03-30 16:04:06 -0700 | [diff] [blame] | 1550 | if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) { |
| 1551 | mContext.enforceCallingOrSelfPermission( |
| 1552 | android.Manifest.permission.ACCESS_COARSE_LOCATION, null); |
| 1553 | |
| 1554 | } |
| 1555 | |
Fyodor Kupolov | 309b2f63 | 2015-06-03 16:29:01 -0700 | [diff] [blame] | 1556 | if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) { |
Amit Mahajan | 1cfd457 | 2015-07-09 11:12:19 -0700 | [diff] [blame] | 1557 | try { |
Amit Mahajan | a9e72a7 | 2015-07-30 16:04:13 -0700 | [diff] [blame] | 1558 | mContext.enforceCallingOrSelfPermission( |
Amit Mahajan | 1cfd457 | 2015-07-09 11:12:19 -0700 | [diff] [blame] | 1559 | android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null); |
Amit Mahajan | a9e72a7 | 2015-07-30 16:04:13 -0700 | [diff] [blame] | 1560 | // SKIP checking for run-time permission since caller or self has PRIVILEGED |
| 1561 | // permission |
Amit Mahajan | 1cfd457 | 2015-07-09 11:12:19 -0700 | [diff] [blame] | 1562 | } catch (SecurityException e) { |
| 1563 | mContext.enforceCallingOrSelfPermission( |
| 1564 | android.Manifest.permission.READ_PHONE_STATE, null); |
| 1565 | } |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1566 | } |
Antonio Marín Cerezuela | c5ac15a | 2013-05-27 11:36:36 +0200 | [diff] [blame] | 1567 | |
| 1568 | if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) { |
| 1569 | mContext.enforceCallingOrSelfPermission( |
| 1570 | android.Manifest.permission.READ_PRECISE_PHONE_STATE, null); |
| 1571 | |
| 1572 | } |
New Author Steven Liu | 485f209 | 2014-09-11 10:18:45 -0500 | [diff] [blame] | 1573 | |
| 1574 | if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) { |
| 1575 | mContext.enforceCallingOrSelfPermission( |
| 1576 | android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null); |
| 1577 | } |
Jaikumar Ganesh | 4551565 | 2009-04-23 15:20:21 -0700 | [diff] [blame] | 1578 | } |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 1579 | |
| 1580 | private void handleRemoveListLocked() { |
Wink Saville | a374c3d | 2014-11-11 11:48:04 -0800 | [diff] [blame] | 1581 | int size = mRemoveList.size(); |
| 1582 | if (VDBG) log("handleRemoveListLocked: mRemoveList.size()=" + size); |
| 1583 | if (size > 0) { |
Joe Onorato | 163d8d9 | 2010-10-21 13:21:20 -0400 | [diff] [blame] | 1584 | for (IBinder b: mRemoveList) { |
| 1585 | remove(b); |
| 1586 | } |
| 1587 | mRemoveList.clear(); |
| 1588 | } |
| 1589 | } |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 1590 | |
| 1591 | private boolean validateEventsAndUserLocked(Record r, int events) { |
| 1592 | int foregroundUser; |
| 1593 | long callingIdentity = Binder.clearCallingIdentity(); |
| 1594 | boolean valid = false; |
| 1595 | try { |
| 1596 | foregroundUser = ActivityManager.getCurrentUser(); |
Fyodor Kupolov | 309b2f63 | 2015-06-03 16:29:01 -0700 | [diff] [blame] | 1597 | valid = r.callerUserId == foregroundUser && r.matchPhoneStateListenerEvent(events); |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 1598 | if (DBG | DBG_LOC) { |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 1599 | log("validateEventsAndUserLocked: valid=" + valid |
Fyodor Kupolov | 309b2f63 | 2015-06-03 16:29:01 -0700 | [diff] [blame] | 1600 | + " r.callerUserId=" + r.callerUserId + " foregroundUser=" + foregroundUser |
Wink Saville | a12a7b3 | 2012-09-20 10:09:45 -0700 | [diff] [blame] | 1601 | + " r.events=" + r.events + " events=" + events); |
| 1602 | } |
| 1603 | } finally { |
| 1604 | Binder.restoreCallingIdentity(callingIdentity); |
| 1605 | } |
| 1606 | return valid; |
| 1607 | } |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1608 | |
| 1609 | private boolean validatePhoneId(int phoneId) { |
| 1610 | boolean valid = (phoneId >= 0) && (phoneId < mNumPhones); |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 1611 | if (VDBG) log("validatePhoneId: " + valid); |
Wink Saville | fb40dd4 | 2014-06-12 17:02:31 -0700 | [diff] [blame] | 1612 | return valid; |
| 1613 | } |
Wink Saville | f4cd25b | 2014-07-08 19:03:20 -0700 | [diff] [blame] | 1614 | |
| 1615 | private static void log(String s) { |
| 1616 | Rlog.d(TAG, s); |
| 1617 | } |
Wink Saville | 47d8d1b | 2014-07-10 13:01:52 -0700 | [diff] [blame] | 1618 | |
| 1619 | private static class LogSSC { |
| 1620 | private Time mTime; |
| 1621 | private String mS; |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1622 | private int mSubId; |
Wink Saville | 47d8d1b | 2014-07-10 13:01:52 -0700 | [diff] [blame] | 1623 | private int mPhoneId; |
| 1624 | private ServiceState mState; |
| 1625 | |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1626 | 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] | 1627 | mTime = t; mS = s; mSubId = subId; mPhoneId = phoneId; mState = state; |
| 1628 | } |
| 1629 | |
| 1630 | @Override |
| 1631 | public String toString() { |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1632 | return mS + " Time " + mTime.toString() + " mSubId " + mSubId + " mPhoneId " |
| 1633 | + mPhoneId + " mState " + mState; |
Wink Saville | 47d8d1b | 2014-07-10 13:01:52 -0700 | [diff] [blame] | 1634 | } |
| 1635 | } |
| 1636 | |
| 1637 | private LogSSC logSSC [] = new LogSSC[10]; |
| 1638 | private int next = 0; |
| 1639 | |
Wink Saville | 63f03dd | 2014-10-23 10:44:45 -0700 | [diff] [blame] | 1640 | private void logServiceStateChanged(String s, int subId, int phoneId, ServiceState state) { |
Wink Saville | 47d8d1b | 2014-07-10 13:01:52 -0700 | [diff] [blame] | 1641 | if (logSSC == null || logSSC.length == 0) { |
| 1642 | return; |
| 1643 | } |
| 1644 | if (logSSC[next] == null) { |
| 1645 | logSSC[next] = new LogSSC(); |
| 1646 | } |
| 1647 | Time t = new Time(); |
| 1648 | t.setToNow(); |
| 1649 | logSSC[next].set(t, s, subId, phoneId, state); |
| 1650 | if (++next >= logSSC.length) { |
| 1651 | next = 0; |
| 1652 | } |
| 1653 | } |
| 1654 | |
| 1655 | private void toStringLogSSC(String prompt) { |
| 1656 | if (logSSC == null || logSSC.length == 0 || (next == 0 && logSSC[next] == null)) { |
| 1657 | log(prompt + ": logSSC is empty"); |
| 1658 | } else { |
| 1659 | // There is at least one element |
| 1660 | log(prompt + ": logSSC.length=" + logSSC.length + " next=" + next); |
| 1661 | int i = next; |
| 1662 | if (logSSC[i] == null) { |
| 1663 | // logSSC is not full so back to the beginning |
| 1664 | i = 0; |
| 1665 | } |
| 1666 | do { |
| 1667 | log(logSSC[i].toString()); |
| 1668 | if (++i >= logSSC.length) { |
| 1669 | i = 0; |
| 1670 | } |
| 1671 | } while (i != next); |
Wink Saville | e380b98 | 2014-07-26 18:24:22 -0700 | [diff] [blame] | 1672 | log(prompt + ": ----------------"); |
Wink Saville | 47d8d1b | 2014-07-10 13:01:52 -0700 | [diff] [blame] | 1673 | } |
| 1674 | } |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 1675 | |
xinhe | 8b79fb6 | 2014-11-05 14:55:03 -0800 | [diff] [blame] | 1676 | boolean idMatch(int rSubId, int subId, int phoneId) { |
xinhe | ac11ae9 | 2014-12-18 10:02:14 -0800 | [diff] [blame] | 1677 | |
| 1678 | if(subId < 0) { |
| 1679 | // Invalid case, we need compare phoneId with default one. |
| 1680 | return (mDefaultPhoneId == phoneId); |
| 1681 | } |
Wink Saville | d09c4ca | 2014-11-22 10:08:16 -0800 | [diff] [blame] | 1682 | if(rSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 1683 | return (subId == mDefaultSubId); |
| 1684 | } else { |
| 1685 | return (rSubId == subId); |
| 1686 | } |
| 1687 | } |
| 1688 | |
| 1689 | private void checkPossibleMissNotify(Record r, int phoneId) { |
| 1690 | int events = r.events; |
| 1691 | |
| 1692 | if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) { |
| 1693 | try { |
| 1694 | if (VDBG) log("checkPossibleMissNotify: onServiceStateChanged state=" + |
| 1695 | mServiceState[phoneId]); |
| 1696 | r.callback.onServiceStateChanged( |
| 1697 | new ServiceState(mServiceState[phoneId])); |
| 1698 | } catch (RemoteException ex) { |
Etan Cohen | a33cf07 | 2014-09-30 10:35:24 -0700 | [diff] [blame] | 1699 | mRemoveList.add(r.binder); |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 1700 | } |
| 1701 | } |
| 1702 | |
| 1703 | if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) { |
| 1704 | try { |
| 1705 | SignalStrength signalStrength = mSignalStrength[phoneId]; |
| 1706 | if (DBG) { |
| 1707 | log("checkPossibleMissNotify: onSignalStrengthsChanged SS=" + signalStrength); |
| 1708 | } |
| 1709 | r.callback.onSignalStrengthsChanged(new SignalStrength(signalStrength)); |
| 1710 | } catch (RemoteException ex) { |
| 1711 | mRemoveList.add(r.binder); |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) { |
| 1716 | try { |
| 1717 | int gsmSignalStrength = mSignalStrength[phoneId] |
| 1718 | .getGsmSignalStrength(); |
| 1719 | if (DBG) { |
| 1720 | log("checkPossibleMissNotify: onSignalStrengthChanged SS=" + |
| 1721 | gsmSignalStrength); |
| 1722 | } |
| 1723 | r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1 |
| 1724 | : gsmSignalStrength)); |
| 1725 | } catch (RemoteException ex) { |
Etan Cohen | a33cf07 | 2014-09-30 10:35:24 -0700 | [diff] [blame] | 1726 | mRemoveList.add(r.binder); |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 1727 | } |
| 1728 | } |
| 1729 | |
| 1730 | if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) { |
| 1731 | try { |
| 1732 | if (DBG_LOC) { |
| 1733 | log("checkPossibleMissNotify: onCellInfoChanged[" + phoneId + "] = " |
| 1734 | + mCellInfo.get(phoneId)); |
| 1735 | } |
| 1736 | r.callback.onCellInfoChanged(mCellInfo.get(phoneId)); |
| 1737 | } catch (RemoteException ex) { |
Etan Cohen | a33cf07 | 2014-09-30 10:35:24 -0700 | [diff] [blame] | 1738 | mRemoveList.add(r.binder); |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 1739 | } |
| 1740 | } |
| 1741 | |
| 1742 | if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) { |
| 1743 | try { |
| 1744 | if (VDBG) { |
| 1745 | log("checkPossibleMissNotify: onMessageWaitingIndicatorChanged phoneId=" |
| 1746 | + phoneId + " mwi=" + mMessageWaiting[phoneId]); |
| 1747 | } |
| 1748 | r.callback.onMessageWaitingIndicatorChanged( |
| 1749 | mMessageWaiting[phoneId]); |
| 1750 | } catch (RemoteException ex) { |
Etan Cohen | a33cf07 | 2014-09-30 10:35:24 -0700 | [diff] [blame] | 1751 | mRemoveList.add(r.binder); |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 1752 | } |
| 1753 | } |
| 1754 | |
| 1755 | if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) { |
| 1756 | try { |
| 1757 | if (VDBG) { |
| 1758 | log("checkPossibleMissNotify: onCallForwardingIndicatorChanged phoneId=" |
| 1759 | + phoneId + " cfi=" + mCallForwarding[phoneId]); |
| 1760 | } |
| 1761 | r.callback.onCallForwardingIndicatorChanged( |
| 1762 | mCallForwarding[phoneId]); |
| 1763 | } catch (RemoteException ex) { |
Etan Cohen | a33cf07 | 2014-09-30 10:35:24 -0700 | [diff] [blame] | 1764 | mRemoveList.add(r.binder); |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 1765 | } |
| 1766 | } |
| 1767 | |
| 1768 | if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) { |
| 1769 | try { |
| 1770 | if (DBG_LOC) log("checkPossibleMissNotify: onCellLocationChanged mCellLocation = " |
| 1771 | + mCellLocation[phoneId]); |
| 1772 | r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId])); |
| 1773 | } catch (RemoteException ex) { |
| 1774 | mRemoveList.add(r.binder); |
| 1775 | } |
| 1776 | } |
| 1777 | |
| 1778 | if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) { |
| 1779 | try { |
| 1780 | if (DBG) { |
| 1781 | log("checkPossibleMissNotify: onDataConnectionStateChanged(mDataConnectionState" |
| 1782 | + "=" + mDataConnectionState[phoneId] |
| 1783 | + ", mDataConnectionNetworkType=" + mDataConnectionNetworkType[phoneId] |
| 1784 | + ")"); |
| 1785 | } |
| 1786 | r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId], |
| 1787 | mDataConnectionNetworkType[phoneId]); |
| 1788 | } catch (RemoteException ex) { |
Etan Cohen | a33cf07 | 2014-09-30 10:35:24 -0700 | [diff] [blame] | 1789 | mRemoveList.add(r.binder); |
xinhe | e9f1640 | 2014-09-25 16:39:28 -0700 | [diff] [blame] | 1790 | } |
| 1791 | } |
| 1792 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1793 | } |