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