Search in sources :

Example 1 with MobileDataStateTracker

use of android.net.MobileDataStateTracker in project android_frameworks_base by ParanoidAndroid.

the class ConnectivityService method handleMobileProvisioningAction.

private void handleMobileProvisioningAction(String url) {
    // Notication mark notification as not visible
    setProvNotificationVisible(false, ConnectivityManager.TYPE_NONE, null, null);
    // If provisioning network handle as a special case,
    // otherwise launch browser with the intent directly.
    NetworkInfo ni = getProvisioningNetworkInfo();
    if ((ni != null) && ni.isConnectedToProvisioningNetwork()) {
        if (DBG)
            log("handleMobileProvisioningAction: on provisioning network");
        MobileDataStateTracker mdst = (MobileDataStateTracker) mNetTrackers[ConnectivityManager.TYPE_MOBILE];
        mdst.enableMobileProvisioning(url);
    } else {
        if (DBG)
            log("handleMobileProvisioningAction: on default network");
        Intent newIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        newIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
        try {
            mContext.startActivity(newIntent);
        } catch (ActivityNotFoundException e) {
            loge("handleMobileProvisioningAction: startActivity failed" + e);
        }
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) ActivityNotFoundException(android.content.ActivityNotFoundException) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) MobileDataStateTracker(android.net.MobileDataStateTracker)

Example 2 with MobileDataStateTracker

use of android.net.MobileDataStateTracker in project android_frameworks_base by ParanoidAndroid.

the class ConnectivityService method checkMobileProvisioning.

@Override
public int checkMobileProvisioning(int suggestedTimeOutMs) {
    int timeOutMs = -1;
    if (DBG)
        log("checkMobileProvisioning: E suggestedTimeOutMs=" + suggestedTimeOutMs);
    enforceConnectivityInternalPermission();
    final long token = Binder.clearCallingIdentity();
    try {
        timeOutMs = suggestedTimeOutMs;
        if (suggestedTimeOutMs > CheckMp.MAX_TIMEOUT_MS) {
            timeOutMs = CheckMp.MAX_TIMEOUT_MS;
        }
        // Check that mobile networks are supported
        if (!isNetworkSupported(ConnectivityManager.TYPE_MOBILE) || !isNetworkSupported(ConnectivityManager.TYPE_MOBILE_HIPRI)) {
            if (DBG)
                log("checkMobileProvisioning: X no mobile network");
            return timeOutMs;
        }
        // TODO: Add a queue of results...
        if (mIsCheckingMobileProvisioning.getAndSet(true)) {
            if (DBG)
                log("checkMobileProvisioning: X already checking ignore for the moment");
            return timeOutMs;
        }
        // Start off with notification off
        setProvNotificationVisible(false, ConnectivityManager.TYPE_NONE, null, null);
        // See if we've alreadying determined if we've got a provsioning connection
        // if so we don't need to do anything active
        MobileDataStateTracker mdstDefault = (MobileDataStateTracker) mNetTrackers[ConnectivityManager.TYPE_MOBILE];
        boolean isDefaultProvisioning = mdstDefault.isProvisioningNetwork();
        MobileDataStateTracker mdstHipri = (MobileDataStateTracker) mNetTrackers[ConnectivityManager.TYPE_MOBILE_HIPRI];
        boolean isHipriProvisioning = mdstHipri.isProvisioningNetwork();
        if (isDefaultProvisioning || isHipriProvisioning) {
            if (mIsNotificationVisible) {
                if (DBG) {
                    log("checkMobileProvisioning: provisioning-ignore notification is visible");
                }
            } else {
                NetworkInfo ni = null;
                if (isDefaultProvisioning) {
                    ni = mdstDefault.getNetworkInfo();
                }
                if (isHipriProvisioning) {
                    ni = mdstHipri.getNetworkInfo();
                }
                String url = getMobileProvisioningUrl();
                if ((ni != null) && (!TextUtils.isEmpty(url))) {
                    setProvNotificationVisible(true, ni.getType(), ni.getExtraInfo(), url);
                } else {
                    if (DBG)
                        log("checkMobileProvisioning: provisioning but no url, ignore");
                }
            }
            mIsCheckingMobileProvisioning.set(false);
            return timeOutMs;
        }
        CheckMp checkMp = new CheckMp(mContext, this);
        CheckMp.CallBack cb = new CheckMp.CallBack() {

            @Override
            void onComplete(Integer result) {
                if (DBG)
                    log("CheckMp.onComplete: result=" + result);
                NetworkInfo ni = mNetTrackers[ConnectivityManager.TYPE_MOBILE_HIPRI].getNetworkInfo();
                switch(result) {
                    case CMP_RESULT_CODE_CONNECTABLE:
                    case CMP_RESULT_CODE_NO_CONNECTION:
                        {
                            if (DBG)
                                log("CheckMp.onComplete: ignore, connected or no connection");
                            break;
                        }
                    case CMP_RESULT_CODE_REDIRECTED:
                        {
                            if (DBG)
                                log("CheckMp.onComplete: warm sim");
                            String url = getMobileProvisioningUrl();
                            if (TextUtils.isEmpty(url)) {
                                url = getMobileRedirectedProvisioningUrl();
                            }
                            if (TextUtils.isEmpty(url) == false) {
                                if (DBG)
                                    log("CheckMp.onComplete: warm (redirected), url=" + url);
                                setProvNotificationVisible(true, ni.getType(), ni.getExtraInfo(), url);
                            } else {
                                if (DBG)
                                    log("CheckMp.onComplete: warm (redirected), no url");
                            }
                            break;
                        }
                    case CMP_RESULT_CODE_NO_DNS:
                    case CMP_RESULT_CODE_NO_TCP_CONNECTION:
                        {
                            String url = getMobileProvisioningUrl();
                            if (TextUtils.isEmpty(url) == false) {
                                if (DBG)
                                    log("CheckMp.onComplete: warm (no dns/tcp), url=" + url);
                                setProvNotificationVisible(true, ni.getType(), ni.getExtraInfo(), url);
                            } else {
                                if (DBG)
                                    log("CheckMp.onComplete: warm (no dns/tcp), no url");
                            }
                            break;
                        }
                    default:
                        {
                            loge("CheckMp.onComplete: ignore unexpected result=" + result);
                            break;
                        }
                }
                mIsCheckingMobileProvisioning.set(false);
            }
        };
        CheckMp.Params params = new CheckMp.Params(checkMp.getDefaultUrl(), timeOutMs, cb);
        if (DBG)
            log("checkMobileProvisioning: params=" + params);
        checkMp.execute(params);
    } finally {
        Binder.restoreCallingIdentity(token);
        if (DBG)
            log("checkMobileProvisioning: X");
    }
    return timeOutMs;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NetworkInfo(android.net.NetworkInfo) MobileDataStateTracker(android.net.MobileDataStateTracker)

Aggregations

MobileDataStateTracker (android.net.MobileDataStateTracker)2 NetworkInfo (android.net.NetworkInfo)2 PendingIntent (android.app.PendingIntent)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1