use of android.telephony.ServiceState in project android_frameworks_base by crdroidandroid.
the class CarrierText method updateCarrierText.
protected void updateCarrierText() {
boolean allSimsMissing = true;
boolean anySimReadyAndInService = false;
CharSequence displayText = null;
List<SubscriptionInfo> subs = mKeyguardUpdateMonitor.getSubscriptionInfo(false);
final int N = subs.size();
if (DEBUG)
Log.d(TAG, "updateCarrierText(): " + N);
// displayText is set according to the SIM Status.
if (N == 0) {
boolean isSimAbsent = false;
for (int i = 0; i < TelephonyManager.getDefault().getSimCount(); i++) {
if (TelephonyManager.getDefault().getSimState(i) == TelephonyManager.SIM_STATE_ABSENT) {
isSimAbsent = true;
break;
}
}
if (!isSimAbsent) {
allSimsMissing = false;
displayText = getContext().getString(R.string.keyguard_carrier_default);
}
}
for (int i = 0; i < N; i++) {
int subId = subs.get(i).getSubscriptionId();
State simState = mKeyguardUpdateMonitor.getSimState(subId);
CharSequence carrierName = subs.get(i).getCarrierName();
CharSequence carrierTextForSimState = getCarrierTextForSimState(simState, carrierName);
if (DEBUG) {
Log.d(TAG, "Handling (subId=" + subId + "): " + simState + " " + carrierName);
}
if (carrierTextForSimState != null) {
allSimsMissing = false;
displayText = concatenate(displayText, carrierTextForSimState);
}
if (simState == IccCardConstants.State.READY) {
ServiceState ss = mKeyguardUpdateMonitor.mServiceStates.get(subId);
if (ss != null && ss.getDataRegState() == ServiceState.STATE_IN_SERVICE) {
// Wi-Fi is disassociated or disabled
if (ss.getRilDataRadioTechnology() != ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN || (mWifiManager.isWifiEnabled() && mWifiManager.getConnectionInfo() != null && mWifiManager.getConnectionInfo().getBSSID() != null)) {
if (DEBUG) {
Log.d(TAG, "SIM ready and in service: subId=" + subId + ", ss=" + ss);
}
anySimReadyAndInService = true;
}
}
}
}
/*
* In the case where there is only one sim inserted in a multisim device, if
* the voice registration service state is reported as 12 (no service with emergency)
* for at least one of the sim concatenate the sim state with "Emergency calls only"
*/
if (N < TelephonyManager.getDefault().getPhoneCount() && mKeyguardUpdateMonitor.isEmergencyOnly()) {
int presentSubId = mKeyguardUpdateMonitor.getPresentSubId();
if (DEBUG) {
Log.d(TAG, " Present sim - sub id: " + presentSubId);
}
if (presentSubId != -1) {
CharSequence text = getContext().getText(com.android.internal.R.string.emergency_calls_only);
Intent spnUpdatedIntent = getContext().registerReceiver(null, new IntentFilter(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION));
if (spnUpdatedIntent != null) {
String spn = "";
if (spnUpdatedIntent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_SPN, false) && spnUpdatedIntent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, -1) == presentSubId) {
spn = spnUpdatedIntent.getStringExtra(TelephonyIntents.EXTRA_SPN);
if (!spn.equals(text.toString())) {
text = concatenate(text, spn);
}
}
}
displayText = getCarrierTextForSimState(mKeyguardUpdateMonitor.getSimState(presentSubId), text);
}
}
if (allSimsMissing) {
if (N != 0) {
// Shows "No SIM card | Emergency calls only" on devices that are voice-capable.
// This depends on mPlmn containing the text "Emergency calls only" when the radio
// has some connectivity. Otherwise, it should be null or empty and just show
// "No SIM card"
// Grab the first subscripton, because they all should contain the emergency text,
// described above.
displayText = null;
} else {
// We don't have a SubscriptionInfo to get the emergency calls only from.
// Grab it from the old sticky broadcast if possible instead. We can use it
// here because no subscriptions are active, so we don't have
// to worry about MSIM clashing.
CharSequence text = getContext().getText(com.android.internal.R.string.emergency_calls_only);
Intent i = getContext().registerReceiver(null, new IntentFilter(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION));
if (i != null) {
String spn = "";
String plmn = "";
if (i.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_SPN, false)) {
spn = i.getStringExtra(TelephonyIntents.EXTRA_SPN);
}
if (i.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_PLMN, false)) {
plmn = i.getStringExtra(TelephonyIntents.EXTRA_PLMN);
}
if (DEBUG)
Log.d(TAG, "Getting plmn/spn sticky brdcst " + plmn + "/" + spn);
if (Objects.equals(plmn, spn)) {
text = plmn;
} else {
text = concatenate(plmn, spn);
}
}
displayText = null;
}
}
displayText = updateCarrierTextWithSimIoError(displayText, allSimsMissing);
// (e.g. WFC = Wi-Fi calling) which may operate in APM.
if (!anySimReadyAndInService && WirelessUtils.isAirplaneModeOn(mContext)) {
displayText = getContext().getString(R.string.airplane_mode);
}
setText(displayText);
}
use of android.telephony.ServiceState in project android_frameworks_base by crdroidandroid.
the class NetworkControllerSignalTest method testNoEmengencyNoSubscriptions.
public void testNoEmengencyNoSubscriptions() {
setupDefaultSignal();
setSubscriptions();
mNetworkController.mLastServiceState = new ServiceState();
mNetworkController.mLastServiceState.setEmergencyOnly(false);
mNetworkController.recalculateEmergency();
verifyEmergencyOnly(false);
}
use of android.telephony.ServiceState in project android_frameworks_base by crdroidandroid.
the class TelephonyRegistry method listen.
private void listen(String callingPackage, IPhoneStateListener callback, int events, boolean notifyNow, int subId) {
int callerUserId = UserHandle.getCallingUserId();
if (VDBG) {
log("listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events) + " notifyNow=" + notifyNow + " subId=" + subId + " myUserId=" + UserHandle.myUserId() + " callerUserId=" + callerUserId);
}
if (events != PhoneStateListener.LISTEN_NONE) {
/* Checks permission and throws Security exception */
checkListenerPermission(events);
if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
try {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
// SKIP checking for run-time permission since caller or self has PRIVILEGED
// permission
} catch (SecurityException e) {
if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(), callingPackage) != AppOpsManager.MODE_ALLOWED) {
return;
}
}
}
synchronized (mRecords) {
// register
Record r;
find_and_add: {
IBinder b = callback.asBinder();
final int N = mRecords.size();
for (int i = 0; i < N; i++) {
r = mRecords.get(i);
if (b == r.binder) {
break find_and_add;
}
}
r = new Record();
r.binder = b;
mRecords.add(r);
if (DBG)
log("listen: add new record");
}
r.callback = callback;
r.callingPackage = callingPackage;
r.callerUserId = callerUserId;
boolean isPhoneStateEvent = (events & (CHECK_PHONE_STATE_PERMISSION_MASK | ENFORCE_PHONE_STATE_PERMISSION_MASK)) != 0;
r.canReadPhoneState = isPhoneStateEvent && canReadPhoneState(callingPackage);
// force all illegal subId to SubscriptionManager.DEFAULT_SUB_ID
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
r.subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
} else {
//APP specify subID
r.subId = subId;
}
r.phoneId = SubscriptionManager.getPhoneId(r.subId);
int phoneId = r.phoneId;
r.events = events;
if (DBG) {
log("listen: Register r=" + r + " r.subId=" + r.subId + " phoneId=" + phoneId);
}
if (VDBG)
toStringLogSSC("listen");
if (notifyNow && validatePhoneId(phoneId)) {
if ((events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
try {
if (VDBG)
log("listen: call onSSC state=" + mServiceState[phoneId]);
r.callback.onServiceStateChanged(new ServiceState(mServiceState[phoneId]));
} catch (RemoteException ex) {
remove(r.binder);
}
}
if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
try {
int gsmSignalStrength = mSignalStrength[phoneId].getGsmSignalStrength();
r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1 : gsmSignalStrength));
} catch (RemoteException ex) {
remove(r.binder);
}
}
if ((events & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
try {
r.callback.onMessageWaitingIndicatorChanged(mMessageWaiting[phoneId]);
} catch (RemoteException ex) {
remove(r.binder);
}
}
if ((events & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
try {
r.callback.onCallForwardingIndicatorChanged(mCallForwarding[phoneId]);
} catch (RemoteException ex) {
remove(r.binder);
}
}
if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
try {
if (DBG_LOC)
log("listen: mCellLocation = " + mCellLocation[phoneId]);
r.callback.onCellLocationChanged(new Bundle(mCellLocation[phoneId]));
} catch (RemoteException ex) {
remove(r.binder);
}
}
if ((events & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
try {
r.callback.onCallStateChanged(mCallState[phoneId], getCallIncomingNumber(r, phoneId));
} catch (RemoteException ex) {
remove(r.binder);
}
}
if ((events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
try {
r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId], mDataConnectionNetworkType[phoneId]);
} catch (RemoteException ex) {
remove(r.binder);
}
}
if ((events & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
try {
r.callback.onDataActivity(mDataActivity[phoneId]);
} catch (RemoteException ex) {
remove(r.binder);
}
}
if ((events & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
try {
r.callback.onSignalStrengthsChanged(mSignalStrength[phoneId]);
} catch (RemoteException ex) {
remove(r.binder);
}
}
if ((events & PhoneStateListener.LISTEN_OTASP_CHANGED) != 0) {
try {
r.callback.onOtaspChanged(mOtaspMode);
} catch (RemoteException ex) {
remove(r.binder);
}
}
if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
try {
if (DBG_LOC)
log("listen: mCellInfo[" + phoneId + "] = " + mCellInfo.get(phoneId));
r.callback.onCellInfoChanged(mCellInfo.get(phoneId));
} catch (RemoteException ex) {
remove(r.binder);
}
}
if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
try {
r.callback.onPreciseCallStateChanged(mPreciseCallState);
} catch (RemoteException ex) {
remove(r.binder);
}
}
if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
try {
r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
} catch (RemoteException ex) {
remove(r.binder);
}
}
if ((events & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
try {
r.callback.onCarrierNetworkChange(mCarrierNetworkChangeState);
} catch (RemoteException ex) {
remove(r.binder);
}
}
}
}
} else {
if (DBG)
log("listen: Unregister");
remove(callback.asBinder());
}
}
use of android.telephony.ServiceState in project android_frameworks_base by crdroidandroid.
the class KeyguardUpdateMonitor method isEmergencyOnly.
public boolean isEmergencyOnly() {
boolean isEmerg = false;
ServiceState state;
for (int slotId = 0; slotId < TelephonyManager.getDefault().getPhoneCount(); slotId++) {
state = null;
int[] subId = mSubscriptionManager.getSubId(slotId);
if (subId != null && subId.length > 0) {
state = mServiceStates.get(subId[0]);
}
if (state != null) {
if (state.getVoiceRegState() == ServiceState.STATE_IN_SERVICE)
return false;
else if (state.isEmergencyOnly()) {
isEmerg = true;
}
}
}
return isEmerg;
}
use of android.telephony.ServiceState in project android_frameworks_base by crdroidandroid.
the class KeyguardUpdateMonitor method isOOS.
public boolean isOOS() {
boolean ret = true;
int phoneCount = TelephonyManager.getDefault().getPhoneCount();
for (int phoneId = 0; phoneId < phoneCount; phoneId++) {
int[] subId = SubscriptionManager.getSubId(phoneId);
if (subId != null && subId.length >= 1) {
if (DEBUG)
Log.d(TAG, "slot id:" + phoneId + " subId:" + subId[0]);
ServiceState state = mServiceStates.get(subId[0]);
if (state != null) {
if (state.isEmergencyOnly())
ret = false;
if ((state.getVoiceRegState() != ServiceState.STATE_OUT_OF_SERVICE) && (state.getVoiceRegState() != ServiceState.STATE_POWER_OFF))
ret = false;
if (DEBUG) {
Log.d(TAG, "is emergency: " + state.isEmergencyOnly());
Log.d(TAG, "voice state: " + state.getVoiceRegState());
}
} else {
if (DEBUG)
Log.d(TAG, "state is NULL");
}
}
}
if (DEBUG)
Log.d(TAG, "is Emergency supported: " + ret);
return ret;
}
Aggregations