use of android.telephony.PhoneStateListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SimSettings method getPhoneStateListener.
private PhoneStateListener getPhoneStateListener(int phoneId, int subId) {
// Disable Sim selection for Data when voice call is going on as changing the default data
// sim causes a modem reset currently and call gets disconnected
// ToDo : Add subtext on disabled preference to let user know that default data sim cannot
// be changed while call is going on
final int i = phoneId;
mPhoneStateListener[phoneId] = new PhoneStateListener(subId) {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (DBG)
log("PhoneStateListener.onCallStateChanged: state=" + state);
mCallState[i] = state;
updateCellularDataValues();
}
};
return mPhoneStateListener[phoneId];
}
use of android.telephony.PhoneStateListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SimStatus method updatePhoneInfos.
private void updatePhoneInfos() {
if (mSir != null) {
// TODO: http://b/23763013
final Phone phone = PhoneFactory.getPhone(SubscriptionManager.getPhoneId(mSir.getSubscriptionId()));
if (UserManager.get(getContext()).isAdminUser() && SubscriptionManager.isValidSubscriptionId(mSir.getSubscriptionId())) {
if (phone == null) {
Log.e(TAG, "Unable to locate a phone object for the given Subscription ID.");
return;
}
mPhone = phone;
//avoid left at TelephonyManager Memory leak before create a new PhoneStateLister
if (mPhoneStateListener != null && mTelephonyManager != null) {
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
}
mPhoneStateListener = new PhoneStateListener(mSir.getSubscriptionId()) {
@Override
public void onDataConnectionStateChanged(int state) {
updateDataState();
updateNetworkType();
}
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
updateSignalStrength(signalStrength);
}
@Override
public void onServiceStateChanged(ServiceState serviceState) {
updateServiceState(serviceState);
}
};
}
}
}
use of android.telephony.PhoneStateListener in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class CellTracker method startTrackingFemto.
//=================================================================================================
// TODO: Consider REMOVAL! See issues: #6, #457, #489
// TODO: Summary: We can detect femtocells by other means, using network data that we already have!
// The below code section was copied and modified with permission from
// Femtocatcher at: https://github.com/iSECPartners/femtocatcher
//
// Copyright (C) 2013 iSEC Partners
//=================================================================================================
/**
* Start FemtoCell detection tracking (For CDMA Devices ONLY!)
*/
public void startTrackingFemto() {
/* Check if it is a CDMA phone */
if (device.getPhoneId() != TelephonyManager.PHONE_TYPE_CDMA) {
Helpers.msgShort(context, context.getString(R.string.femtocell_only_on_cdma_devices));
return;
}
trackingFemtocell = true;
mPhoneStateListener = new PhoneStateListener() {
public void onServiceStateChanged(ServiceState s) {
log.debug(context.getString(R.string.service_state_changed));
getServiceStateInfo(s);
}
};
tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION);
tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
setNotification();
}
use of android.telephony.PhoneStateListener in project android_frameworks_base by crdroidandroid.
the class ComprehensiveCountryDetector method addPhoneStateListener.
protected synchronized void addPhoneStateListener() {
if (mPhoneStateListener == null) {
mPhoneStateListener = new PhoneStateListener() {
@Override
public void onServiceStateChanged(ServiceState serviceState) {
mCountServiceStateChanges++;
mTotalCountServiceStateChanges++;
if (!isNetworkCountryCodeAvailable()) {
return;
}
if (DEBUG)
Slog.d(TAG, "onServiceStateChanged: " + serviceState.getState());
detectCountry(true, true);
}
};
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
}
}
use of android.telephony.PhoneStateListener in project android_frameworks_base by crdroidandroid.
the class GlobalActions method setupAirplaneModeListeners.
/**
* Since there are two ways of handling airplane mode (with telephony, we depend on the internal
* device telephony state), and MSIM devices do not report phone state for missing SIMs, we
* need to dynamically setup listeners based on subscription changes.
*
* So if there is _any_ active SIM in the device, we can depend on the phone state,
* otherwise fall back to {@link Settings.Global#AIRPLANE_MODE_ON}.
*/
private void setupAirplaneModeListeners() {
TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
for (PhoneStateListener listener : mPhoneStateListeners) {
telephonyManager.listen(listener, PhoneStateListener.LISTEN_NONE);
}
mPhoneStateListeners.clear();
final List<SubscriptionInfo> subInfoList = SubscriptionManager.from(mContext).getActiveSubscriptionInfoList();
if (subInfoList != null) {
mHasTelephony = true;
mAirplaneModeBits = new BitSet(subInfoList.size());
for (int i = 0; i < subInfoList.size(); i++) {
final int finalI = i;
PhoneStateListener subListener = new PhoneStateListener(subInfoList.get(finalI).getSubscriptionId()) {
@Override
public void onServiceStateChanged(ServiceState serviceState) {
final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
mAirplaneModeBits.set(finalI, inAirplaneMode);
// we're in airplane mode if _any_ of the subscriptions say we are
mAirplaneState = mAirplaneModeBits.cardinality() > 0 ? ToggleAction.State.On : ToggleAction.State.Off;
mAirplaneModeOn.updateState(mAirplaneState);
if (mAdapter != null) {
mAdapter.notifyDataSetChanged();
}
}
};
mPhoneStateListeners.add(subListener);
telephonyManager.listen(subListener, PhoneStateListener.LISTEN_SERVICE_STATE);
}
} else {
mHasTelephony = false;
}
// Set the initial status of airplane mode toggle
mAirplaneState = getUpdatedAirplaneToggleState();
}
Aggregations