Search in sources :

Example 6 with WifiP2pWfdInfo

use of android.net.wifi.p2p.WifiP2pWfdInfo in project android_frameworks_base by crdroidandroid.

the class WifiDisplayController method updateWfdEnableState.

private void updateWfdEnableState() {
    if (mWifiDisplayOnSetting && mWifiP2pEnabled) {
        // WFD should be enabled.
        if (!mWfdEnabled && !mWfdEnabling) {
            mWfdEnabling = true;
            WifiP2pWfdInfo wfdInfo = new WifiP2pWfdInfo();
            wfdInfo.setWfdEnabled(true);
            wfdInfo.setDeviceType(WifiP2pWfdInfo.WFD_SOURCE);
            wfdInfo.setSessionAvailable(true);
            wfdInfo.setControlPort(DEFAULT_CONTROL_PORT);
            wfdInfo.setMaxThroughput(MAX_THROUGHPUT);
            mWifiP2pManager.setWFDInfo(mWifiP2pChannel, wfdInfo, new ActionListener() {

                @Override
                public void onSuccess() {
                    if (DEBUG) {
                        Slog.d(TAG, "Successfully set WFD info.");
                    }
                    if (mWfdEnabling) {
                        mWfdEnabling = false;
                        mWfdEnabled = true;
                        reportFeatureState();
                        updateScanState();
                    }
                }

                @Override
                public void onFailure(int reason) {
                    if (DEBUG) {
                        Slog.d(TAG, "Failed to set WFD info with reason " + reason + ".");
                    }
                    mWfdEnabling = false;
                }
            });
        }
    } else {
        // WFD should be disabled.
        if (mWfdEnabled || mWfdEnabling) {
            WifiP2pWfdInfo wfdInfo = new WifiP2pWfdInfo();
            wfdInfo.setWfdEnabled(false);
            mWifiP2pManager.setWFDInfo(mWifiP2pChannel, wfdInfo, new ActionListener() {

                @Override
                public void onSuccess() {
                    if (DEBUG) {
                        Slog.d(TAG, "Successfully set WFD info.");
                    }
                }

                @Override
                public void onFailure(int reason) {
                    if (DEBUG) {
                        Slog.d(TAG, "Failed to set WFD info with reason " + reason + ".");
                    }
                }
            });
        }
        mWfdEnabling = false;
        mWfdEnabled = false;
        reportFeatureState();
        updateScanState();
        disconnect();
    }
}
Also used : ActionListener(android.net.wifi.p2p.WifiP2pManager.ActionListener) WifiP2pWfdInfo(android.net.wifi.p2p.WifiP2pWfdInfo)

Aggregations

ActionListener (android.net.wifi.p2p.WifiP2pManager.ActionListener)6 WifiP2pWfdInfo (android.net.wifi.p2p.WifiP2pWfdInfo)6