Search in sources :

Example 6 with PhoneStateListener

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];
}
Also used : PhoneStateListener(android.telephony.PhoneStateListener)

Example 7 with PhoneStateListener

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);
                }
            };
        }
    }
}
Also used : ServiceState(android.telephony.ServiceState) Phone(com.android.internal.telephony.Phone) PhoneStateListener(android.telephony.PhoneStateListener) SignalStrength(android.telephony.SignalStrength)

Example 8 with PhoneStateListener

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();
}
Also used : ServiceState(android.telephony.ServiceState) PhoneStateListener(android.telephony.PhoneStateListener)

Example 9 with PhoneStateListener

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);
    }
}
Also used : ServiceState(android.telephony.ServiceState) PhoneStateListener(android.telephony.PhoneStateListener)

Example 10 with PhoneStateListener

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();
}
Also used : ServiceState(android.telephony.ServiceState) TelephonyManager(android.telephony.TelephonyManager) PhoneStateListener(android.telephony.PhoneStateListener) BitSet(java.util.BitSet) SubscriptionInfo(android.telephony.SubscriptionInfo) Paint(android.graphics.Paint)

Aggregations

PhoneStateListener (android.telephony.PhoneStateListener)15 ServiceState (android.telephony.ServiceState)10 TelephonyManager (android.telephony.TelephonyManager)4 Paint (android.graphics.Paint)2 SubscriptionInfo (android.telephony.SubscriptionInfo)2 BitSet (java.util.BitSet)2 Dialog (android.app.Dialog)1 ComponentName (android.content.ComponentName)1 IntentFilter (android.content.IntentFilter)1 ServiceConnection (android.content.ServiceConnection)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Handler (android.os.Handler)1 IBinder (android.os.IBinder)1 NavigationView (android.support.design.widget.NavigationView)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SearchView (android.support.v7.widget.SearchView)1 SignalStrength (android.telephony.SignalStrength)1