1 /* 2 * Copyright (C) 2006 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.internal.telephony; 18 19 import android.annotation.NonNull; 20 import android.content.Context; 21 import android.telephony.Annotation; 22 import android.telephony.Annotation.RadioPowerState; 23 import android.telephony.Annotation.SrvccState; 24 import android.telephony.BarringInfo; 25 import android.telephony.CallQuality; 26 import android.telephony.CellIdentity; 27 import android.telephony.CellInfo; 28 import android.telephony.CellularIdentifierDisclosure; 29 import android.telephony.LinkCapacityEstimate; 30 import android.telephony.NetworkRegistrationInfo; 31 import android.telephony.PhoneCapability; 32 import android.telephony.PhysicalChannelConfig; 33 import android.telephony.PreciseCallState; 34 import android.telephony.PreciseDataConnectionState; 35 import android.telephony.SecurityAlgorithmUpdate; 36 import android.telephony.ServiceState; 37 import android.telephony.TelephonyDisplayInfo; 38 import android.telephony.TelephonyManager.DataEnabledReason; 39 import android.telephony.TelephonyManager.EmergencyCallbackModeStopReason; 40 import android.telephony.TelephonyManager.EmergencyCallbackModeType; 41 import android.telephony.TelephonyRegistryManager; 42 import android.telephony.emergency.EmergencyNumber; 43 import android.telephony.ims.ImsCallSession; 44 import android.telephony.ims.ImsReasonInfo; 45 import android.telephony.ims.MediaQualityStatus; 46 import android.telephony.satellite.NtnSignalStrength; 47 48 import com.android.internal.telephony.flags.FeatureFlags; 49 import com.android.telephony.Rlog; 50 51 import java.util.List; 52 import java.util.Set; 53 54 /** 55 * broadcast intents 56 */ 57 public class DefaultPhoneNotifier implements PhoneNotifier { 58 59 private static final String LOG_TAG = "DefaultPhoneNotifier"; 60 private static final boolean DBG = false; // STOPSHIP if true 61 62 private TelephonyRegistryManager mTelephonyRegistryMgr; 63 64 /** Feature flags */ 65 @NonNull 66 private final FeatureFlags mFeatureFlags; 67 68 DefaultPhoneNotifier(Context context, @NonNull FeatureFlags featureFlags)69 public DefaultPhoneNotifier(Context context, @NonNull FeatureFlags featureFlags) { 70 mTelephonyRegistryMgr = (TelephonyRegistryManager) context.getSystemService( 71 Context.TELEPHONY_REGISTRY_SERVICE); 72 mFeatureFlags = featureFlags; 73 } 74 75 @Override notifyPhoneState(Phone sender)76 public void notifyPhoneState(Phone sender) { 77 Call ringingCall = sender.getRingingCall(); 78 int subId = sender.getSubId(); 79 int phoneId = sender.getPhoneId(); 80 String incomingNumber = ""; 81 if (ringingCall != null && ringingCall.getEarliestConnection() != null) { 82 incomingNumber = ringingCall.getEarliestConnection().getAddress(); 83 } 84 mTelephonyRegistryMgr.notifyCallStateChanged(phoneId, subId, 85 PhoneConstantConversions.convertCallState(sender.getState()), incomingNumber); 86 } 87 88 @Override notifyServiceState(Phone sender)89 public void notifyServiceState(Phone sender) { 90 notifyServiceStateForSubId(sender, sender.getServiceState(), sender.getSubId()); 91 } 92 93 @Override notifyServiceStateForSubId(Phone sender, ServiceState ss, int subId)94 public void notifyServiceStateForSubId(Phone sender, ServiceState ss, int subId) { 95 int phoneId = sender.getPhoneId(); 96 97 Rlog.d(LOG_TAG, "notifyServiceStateForSubId: mRegistryMgr=" + mTelephonyRegistryMgr + " ss=" 98 + ss + " sender=" + sender + " phondId=" + phoneId + " subId=" + subId); 99 if (ss == null) { 100 ss = new ServiceState(); 101 ss.setStateOutOfService(); 102 } 103 mTelephonyRegistryMgr.notifyServiceStateChanged(phoneId, subId, ss); 104 } 105 106 @Override notifySignalStrength(Phone sender)107 public void notifySignalStrength(Phone sender) { 108 int phoneId = sender.getPhoneId(); 109 int subId = sender.getSubId(); 110 if (DBG) { 111 // too chatty to log constantly 112 Rlog.d(LOG_TAG, "notifySignalStrength: mRegistryMgr=" + mTelephonyRegistryMgr 113 + " ss=" + sender.getSignalStrength() + " sender=" + sender); 114 } 115 mTelephonyRegistryMgr.notifySignalStrengthChanged(phoneId, subId, 116 sender.getSignalStrength()); 117 } 118 119 @Override notifyMessageWaitingChanged(Phone sender)120 public void notifyMessageWaitingChanged(Phone sender) { 121 int phoneId = sender.getPhoneId(); 122 int subId = sender.getSubId(); 123 mTelephonyRegistryMgr.notifyMessageWaitingChanged(phoneId, subId, 124 sender.getMessageWaitingIndicator()); 125 } 126 127 @Override notifyCallForwardingChanged(Phone sender)128 public void notifyCallForwardingChanged(Phone sender) { 129 int subId = sender.getSubId(); 130 Rlog.d(LOG_TAG, "notifyCallForwardingChanged: subId=" + subId + ", isCFActive=" 131 + sender.getCallForwardingIndicator()); 132 133 mTelephonyRegistryMgr.notifyCallForwardingChanged(subId, 134 sender.getCallForwardingIndicator()); 135 } 136 137 @Override notifyDataActivity(Phone sender)138 public void notifyDataActivity(Phone sender) { 139 140 int subId = sender.getSubId(); 141 142 int phoneId = sender.getPhoneId(); 143 mTelephonyRegistryMgr.notifyDataActivityChanged(phoneId, subId, 144 sender.getDataActivityState()); 145 } 146 147 @Override notifyDataConnection(Phone sender, PreciseDataConnectionState preciseState)148 public void notifyDataConnection(Phone sender, PreciseDataConnectionState preciseState) { 149 mTelephonyRegistryMgr.notifyDataConnectionForSubscriber(sender.getPhoneId(), 150 sender.getSubId(), preciseState); 151 } 152 153 @Override notifyCellLocation(Phone sender, CellIdentity cellIdentity)154 public void notifyCellLocation(Phone sender, CellIdentity cellIdentity) { 155 int subId = sender.getSubId(); 156 mTelephonyRegistryMgr.notifyCellLocation(subId, cellIdentity); 157 } 158 159 @Override notifyCellInfo(Phone sender, List<CellInfo> cellInfo)160 public void notifyCellInfo(Phone sender, List<CellInfo> cellInfo) { 161 int subId = sender.getSubId(); 162 mTelephonyRegistryMgr.notifyCellInfoChanged(subId, cellInfo); 163 } 164 165 /** 166 * Notify precise call state of foreground, background and ringing call states. 167 * 168 * @param imsCallIds Array of IMS call session ID{@link ImsCallSession#getCallId} for 169 * ringing, foreground & background calls. 170 * @param imsCallServiceTypes Array of IMS call service type for ringing, foreground & 171 * background calls. 172 * @param imsCallTypes Array of IMS call type for ringing, foreground & background calls. 173 */ notifyPreciseCallState(Phone sender, String[] imsCallIds, @Annotation.ImsCallServiceType int[] imsCallServiceTypes, @Annotation.ImsCallType int[] imsCallTypes)174 public void notifyPreciseCallState(Phone sender, String[] imsCallIds, 175 @Annotation.ImsCallServiceType int[] imsCallServiceTypes, 176 @Annotation.ImsCallType int[] imsCallTypes) { 177 Call ringingCall = sender.getRingingCall(); 178 Call foregroundCall = sender.getForegroundCall(); 179 Call backgroundCall = sender.getBackgroundCall(); 180 181 if (ringingCall != null && foregroundCall != null && backgroundCall != null) { 182 int[] callStates = {convertPreciseCallState(ringingCall.getState()), 183 convertPreciseCallState(foregroundCall.getState()), 184 convertPreciseCallState(backgroundCall.getState())}; 185 mTelephonyRegistryMgr.notifyPreciseCallState(sender.getPhoneId(), sender.getSubId(), 186 callStates, imsCallIds, imsCallServiceTypes, imsCallTypes); 187 } 188 } 189 notifyDisconnectCause(Phone sender, int cause, int preciseCause)190 public void notifyDisconnectCause(Phone sender, int cause, int preciseCause) { 191 mTelephonyRegistryMgr.notifyDisconnectCause(sender.getPhoneId(), sender.getSubId(), cause, 192 preciseCause); 193 } 194 195 @Override notifyImsDisconnectCause(@onNull Phone sender, ImsReasonInfo imsReasonInfo)196 public void notifyImsDisconnectCause(@NonNull Phone sender, ImsReasonInfo imsReasonInfo) { 197 mTelephonyRegistryMgr.notifyImsDisconnectCause(sender.getSubId(), imsReasonInfo); 198 } 199 200 @Override notifySrvccStateChanged(Phone sender, @SrvccState int state)201 public void notifySrvccStateChanged(Phone sender, @SrvccState int state) { 202 mTelephonyRegistryMgr.notifySrvccStateChanged(sender.getSubId(), state); 203 } 204 205 @Override notifyDataActivationStateChanged(Phone sender, int activationState)206 public void notifyDataActivationStateChanged(Phone sender, int activationState) { 207 mTelephonyRegistryMgr.notifyDataActivationStateChanged(sender.getPhoneId(), 208 sender.getSubId(), activationState); 209 } 210 211 @Override notifyVoiceActivationStateChanged(Phone sender, int activationState)212 public void notifyVoiceActivationStateChanged(Phone sender, int activationState) { 213 mTelephonyRegistryMgr.notifyVoiceActivationStateChanged(sender.getPhoneId(), 214 sender.getSubId(), activationState); 215 } 216 217 @Override notifyUserMobileDataStateChanged(Phone sender, boolean state)218 public void notifyUserMobileDataStateChanged(Phone sender, boolean state) { 219 mTelephonyRegistryMgr.notifyUserMobileDataStateChanged(sender.getPhoneId(), 220 sender.getSubId(), state); 221 } 222 223 @Override notifyDisplayInfoChanged(Phone sender, TelephonyDisplayInfo telephonyDisplayInfo)224 public void notifyDisplayInfoChanged(Phone sender, TelephonyDisplayInfo telephonyDisplayInfo) { 225 mTelephonyRegistryMgr.notifyDisplayInfoChanged(sender.getPhoneId(), sender.getSubId(), 226 telephonyDisplayInfo); 227 } 228 229 @Override notifyPhoneCapabilityChanged(PhoneCapability capability)230 public void notifyPhoneCapabilityChanged(PhoneCapability capability) { 231 mTelephonyRegistryMgr.notifyPhoneCapabilityChanged(capability); 232 } 233 234 @Override notifyRadioPowerStateChanged(Phone sender, @RadioPowerState int state)235 public void notifyRadioPowerStateChanged(Phone sender, @RadioPowerState int state) { 236 mTelephonyRegistryMgr.notifyRadioPowerStateChanged(sender.getPhoneId(), sender.getSubId(), 237 state); 238 } 239 240 @Override notifyEmergencyNumberList(Phone sender)241 public void notifyEmergencyNumberList(Phone sender) { 242 mTelephonyRegistryMgr.notifyEmergencyNumberList(sender.getPhoneId(), sender.getSubId()); 243 } 244 245 @Override notifyOutgoingEmergencySms(Phone sender, EmergencyNumber emergencyNumber)246 public void notifyOutgoingEmergencySms(Phone sender, EmergencyNumber emergencyNumber) { 247 mTelephonyRegistryMgr.notifyOutgoingEmergencySms( 248 sender.getPhoneId(), sender.getSubId(), emergencyNumber); 249 } 250 251 @Override notifyCallQualityChanged(Phone sender, CallQuality callQuality, int callNetworkType)252 public void notifyCallQualityChanged(Phone sender, CallQuality callQuality, 253 int callNetworkType) { 254 mTelephonyRegistryMgr.notifyCallQualityChanged(sender.getPhoneId(), sender.getSubId(), 255 callQuality, callNetworkType); 256 } 257 258 @Override notifyMediaQualityStatusChanged(Phone sender, MediaQualityStatus status)259 public void notifyMediaQualityStatusChanged(Phone sender, MediaQualityStatus status) { 260 mTelephonyRegistryMgr.notifyMediaQualityStatusChanged( 261 sender.getPhoneId(), sender.getSubId(), status); 262 } 263 264 @Override notifyRegistrationFailed(Phone sender, @NonNull CellIdentity cellIdentity, @NonNull String chosenPlmn, int domain, int causeCode, int additionalCauseCode)265 public void notifyRegistrationFailed(Phone sender, @NonNull CellIdentity cellIdentity, 266 @NonNull String chosenPlmn, int domain, int causeCode, int additionalCauseCode) { 267 mTelephonyRegistryMgr.notifyRegistrationFailed(sender.getPhoneId(), sender.getSubId(), 268 cellIdentity, chosenPlmn, domain, causeCode, additionalCauseCode); 269 } 270 271 @Override notifyBarringInfoChanged(Phone sender, BarringInfo barringInfo)272 public void notifyBarringInfoChanged(Phone sender, BarringInfo barringInfo) { 273 mTelephonyRegistryMgr.notifyBarringInfoChanged(sender.getPhoneId(), sender.getSubId(), 274 barringInfo); 275 } 276 277 @Override notifyPhysicalChannelConfig(Phone sender, List<PhysicalChannelConfig> configs)278 public void notifyPhysicalChannelConfig(Phone sender, 279 List<PhysicalChannelConfig> configs) { 280 mTelephonyRegistryMgr.notifyPhysicalChannelConfigForSubscriber( 281 sender.getPhoneId(), sender.getSubId(), configs); 282 } 283 284 @Override notifyDataEnabled(Phone sender, boolean enabled, @DataEnabledReason int reason)285 public void notifyDataEnabled(Phone sender, boolean enabled, @DataEnabledReason int reason) { 286 mTelephonyRegistryMgr.notifyDataEnabled(sender.getPhoneId(), sender.getSubId(), 287 enabled, reason); 288 } 289 290 @Override notifyAllowedNetworkTypesChanged(Phone sender, int reason, long allowedNetworkType)291 public void notifyAllowedNetworkTypesChanged(Phone sender, int reason, 292 long allowedNetworkType) { 293 mTelephonyRegistryMgr.notifyAllowedNetworkTypesChanged(sender.getPhoneId(), 294 sender.getSubId(), reason, allowedNetworkType); 295 } 296 297 @Override notifyLinkCapacityEstimateChanged(Phone sender, List<LinkCapacityEstimate> linkCapacityEstimateList)298 public void notifyLinkCapacityEstimateChanged(Phone sender, 299 List<LinkCapacityEstimate> linkCapacityEstimateList) { 300 mTelephonyRegistryMgr.notifyLinkCapacityEstimateChanged(sender.getPhoneId(), 301 sender.getSubId(), linkCapacityEstimateList); 302 } 303 304 @Override notifySimultaneousCellularCallingSubscriptionsChanged(Set<Integer> subIds)305 public void notifySimultaneousCellularCallingSubscriptionsChanged(Set<Integer> subIds) { 306 mTelephonyRegistryMgr.notifySimultaneousCellularCallingSubscriptionsChanged(subIds); 307 } 308 309 @Override notifyCallbackModeStarted(Phone sender, @EmergencyCallbackModeType int type, long durationMillis)310 public void notifyCallbackModeStarted(Phone sender, @EmergencyCallbackModeType int type, 311 long durationMillis) { 312 if (!mFeatureFlags.emergencyCallbackModeNotification()) return; 313 314 mTelephonyRegistryMgr.notifyCallbackModeStarted(sender.getPhoneId(), 315 sender.getSubId(), type, durationMillis); 316 } 317 318 @Override notifyCallbackModeRestarted(Phone sender, @EmergencyCallbackModeType int type, long durationMillis)319 public void notifyCallbackModeRestarted(Phone sender, @EmergencyCallbackModeType int type, 320 long durationMillis) { 321 if (!mFeatureFlags.emergencyCallbackModeNotification()) return; 322 323 mTelephonyRegistryMgr.notifyCallbackModeRestarted(sender.getPhoneId(), 324 sender.getSubId(), type, durationMillis); 325 } 326 327 @Override notifyCallbackModeStopped(Phone sender, @EmergencyCallbackModeType int type, @EmergencyCallbackModeStopReason int reason)328 public void notifyCallbackModeStopped(Phone sender, @EmergencyCallbackModeType int type, 329 @EmergencyCallbackModeStopReason int reason) { 330 if (!mFeatureFlags.emergencyCallbackModeNotification()) return; 331 332 mTelephonyRegistryMgr.notifyCallbackModeStopped(sender.getPhoneId(), 333 sender.getSubId(), type, reason); 334 } 335 336 @Override notifyCarrierRoamingNtnModeChanged(Phone sender, boolean active)337 public void notifyCarrierRoamingNtnModeChanged(Phone sender, boolean active) { 338 mTelephonyRegistryMgr.notifyCarrierRoamingNtnModeChanged(sender.getSubId(), active); 339 } 340 341 @Override notifyCarrierRoamingNtnEligibleStateChanged(Phone sender, boolean eligible)342 public void notifyCarrierRoamingNtnEligibleStateChanged(Phone sender, boolean eligible) { 343 mTelephonyRegistryMgr.notifyCarrierRoamingNtnEligibleStateChanged( 344 sender.getSubId(), eligible); 345 } 346 347 @Override notifyCarrierRoamingNtnAvailableServicesChanged( Phone sender, @NetworkRegistrationInfo.ServiceType int[] availableServices)348 public void notifyCarrierRoamingNtnAvailableServicesChanged( 349 Phone sender, @NetworkRegistrationInfo.ServiceType int[] availableServices) { 350 mTelephonyRegistryMgr.notifyCarrierRoamingNtnAvailableServicesChanged( 351 sender.getSubId(), availableServices); 352 } 353 354 @Override notifyCarrierRoamingNtnSignalStrengthChanged(Phone sender, @NonNull NtnSignalStrength ntnSignalStrength)355 public void notifyCarrierRoamingNtnSignalStrengthChanged(Phone sender, 356 @NonNull NtnSignalStrength ntnSignalStrength) { 357 mTelephonyRegistryMgr.notifyCarrierRoamingNtnSignalStrengthChanged( 358 sender.getSubId(), ntnSignalStrength); 359 } 360 361 @Override notifySecurityAlgorithmsChanged(Phone sender, SecurityAlgorithmUpdate update)362 public void notifySecurityAlgorithmsChanged(Phone sender, SecurityAlgorithmUpdate update) { 363 if (!mFeatureFlags.securityAlgorithmsUpdateIndications()) return; 364 365 mTelephonyRegistryMgr.notifySecurityAlgorithmsChanged(sender.getPhoneId(), 366 sender.getSubId(), update); 367 } 368 369 @Override notifyCellularIdentifierDisclosedChanged(Phone sender, CellularIdentifierDisclosure disclosure)370 public void notifyCellularIdentifierDisclosedChanged(Phone sender, 371 CellularIdentifierDisclosure disclosure) { 372 if (!mFeatureFlags.cellularIdentifierDisclosureIndications()) return; 373 374 mTelephonyRegistryMgr.notifyCellularIdentifierDisclosedChanged(sender.getPhoneId(), 375 sender.getSubId(), disclosure); 376 } 377 378 /** 379 * Convert the {@link Call.State} enum into the PreciseCallState.PRECISE_CALL_STATE_* constants 380 * for the public API. 381 */ convertPreciseCallState(Call.State state)382 public static int convertPreciseCallState(Call.State state) { 383 switch (state) { 384 case ACTIVE: 385 return PreciseCallState.PRECISE_CALL_STATE_ACTIVE; 386 case HOLDING: 387 return PreciseCallState.PRECISE_CALL_STATE_HOLDING; 388 case DIALING: 389 return PreciseCallState.PRECISE_CALL_STATE_DIALING; 390 case ALERTING: 391 return PreciseCallState.PRECISE_CALL_STATE_ALERTING; 392 case INCOMING: 393 return PreciseCallState.PRECISE_CALL_STATE_INCOMING; 394 case WAITING: 395 return PreciseCallState.PRECISE_CALL_STATE_WAITING; 396 case DISCONNECTED: 397 return PreciseCallState.PRECISE_CALL_STATE_DISCONNECTED; 398 case DISCONNECTING: 399 return PreciseCallState.PRECISE_CALL_STATE_DISCONNECTING; 400 default: 401 return PreciseCallState.PRECISE_CALL_STATE_IDLE; 402 } 403 } 404 log(String s)405 private void log(String s) { 406 Rlog.d(LOG_TAG, s); 407 } 408 } 409