Search in sources :

Example 1 with ActionListener

use of android.net.wifi.p2p.WifiP2pManager.ActionListener in project android_frameworks_base by ParanoidAndroid.

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();
                    }
                }

                @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.
        mWfdEnabling = false;
        mWfdEnabled = false;
        reportFeatureState();
        disconnect();
    }
}
Also used : ActionListener(android.net.wifi.p2p.WifiP2pManager.ActionListener) WifiP2pWfdInfo(android.net.wifi.p2p.WifiP2pWfdInfo)

Example 2 with ActionListener

use of android.net.wifi.p2p.WifiP2pManager.ActionListener in project android_frameworks_base by ParanoidAndroid.

the class WifiDisplayController method tryDiscoverPeers.

private void tryDiscoverPeers() {
    mWifiP2pManager.discoverPeers(mWifiP2pChannel, new ActionListener() {

        @Override
        public void onSuccess() {
            if (DEBUG) {
                Slog.d(TAG, "Discover peers succeeded.  Requesting peers now.");
            }
            mDiscoverPeersInProgress = false;
            requestPeers();
        }

        @Override
        public void onFailure(int reason) {
            if (DEBUG) {
                Slog.d(TAG, "Discover peers failed with reason " + reason + ".");
            }
            if (mDiscoverPeersInProgress) {
                if (reason == 0 && mDiscoverPeersRetriesLeft > 0 && mWfdEnabled) {
                    mHandler.postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            if (mDiscoverPeersInProgress) {
                                if (mDiscoverPeersRetriesLeft > 0 && mWfdEnabled) {
                                    mDiscoverPeersRetriesLeft -= 1;
                                    if (DEBUG) {
                                        Slog.d(TAG, "Retrying discovery.  Retries left: " + mDiscoverPeersRetriesLeft);
                                    }
                                    tryDiscoverPeers();
                                } else {
                                    handleScanFinished();
                                    mDiscoverPeersInProgress = false;
                                }
                            }
                        }
                    }, DISCOVER_PEERS_RETRY_DELAY_MILLIS);
                } else {
                    handleScanFinished();
                    mDiscoverPeersInProgress = false;
                }
            }
        }
    });
}
Also used : ActionListener(android.net.wifi.p2p.WifiP2pManager.ActionListener)

Example 3 with ActionListener

use of android.net.wifi.p2p.WifiP2pManager.ActionListener in project platform_frameworks_base by android.

the class WifiDisplayController method tryDiscoverPeers.

private void tryDiscoverPeers() {
    mWifiP2pManager.discoverPeers(mWifiP2pChannel, new ActionListener() {

        @Override
        public void onSuccess() {
            if (DEBUG) {
                Slog.d(TAG, "Discover peers succeeded.  Requesting peers now.");
            }
            if (mDiscoverPeersInProgress) {
                requestPeers();
            }
        }

        @Override
        public void onFailure(int reason) {
            if (DEBUG) {
                Slog.d(TAG, "Discover peers failed with reason " + reason + ".");
            }
        // Ignore the error.
        // We will retry automatically in a little bit.
        }
    });
    // Retry discover peers periodically until stopped.
    mHandler.postDelayed(mDiscoverPeers, DISCOVER_PEERS_INTERVAL_MILLIS);
}
Also used : ActionListener(android.net.wifi.p2p.WifiP2pManager.ActionListener)

Example 4 with ActionListener

use of android.net.wifi.p2p.WifiP2pManager.ActionListener in project platform_frameworks_base by android.

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)

Example 5 with ActionListener

use of android.net.wifi.p2p.WifiP2pManager.ActionListener in project android_frameworks_base by DirtyUnicorns.

the class WifiDisplayController method tryDiscoverPeers.

private void tryDiscoverPeers() {
    mWifiP2pManager.discoverPeers(mWifiP2pChannel, new ActionListener() {

        @Override
        public void onSuccess() {
            if (DEBUG) {
                Slog.d(TAG, "Discover peers succeeded.  Requesting peers now.");
            }
            if (mDiscoverPeersInProgress) {
                requestPeers();
            }
        }

        @Override
        public void onFailure(int reason) {
            if (DEBUG) {
                Slog.d(TAG, "Discover peers failed with reason " + reason + ".");
            }
        // Ignore the error.
        // We will retry automatically in a little bit.
        }
    });
    // Retry discover peers periodically until stopped.
    mHandler.postDelayed(mDiscoverPeers, DISCOVER_PEERS_INTERVAL_MILLIS);
}
Also used : ActionListener(android.net.wifi.p2p.WifiP2pManager.ActionListener)

Aggregations

ActionListener (android.net.wifi.p2p.WifiP2pManager.ActionListener)20 WifiP2pConfig (android.net.wifi.p2p.WifiP2pConfig)7 WifiDisplay (android.hardware.display.WifiDisplay)6 WpsInfo (android.net.wifi.WpsInfo)6 WifiP2pDevice (android.net.wifi.p2p.WifiP2pDevice)6 GroupInfoListener (android.net.wifi.p2p.WifiP2pManager.GroupInfoListener)6 PeerListListener (android.net.wifi.p2p.WifiP2pManager.PeerListListener)6 WifiP2pWfdInfo (android.net.wifi.p2p.WifiP2pWfdInfo)6 Surface (android.view.Surface)6 Inet4Address (java.net.Inet4Address)6 RemoteDisplay (android.media.RemoteDisplay)3 StackTraceElement (java.lang.StackTraceElement)3 ProgressDialog (android.app.ProgressDialog)1 DialogInterface (android.content.DialogInterface)1 OnCancelListener (android.content.DialogInterface.OnCancelListener)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 WifiP2pGroup (android.net.wifi.p2p.WifiP2pGroup)1 WifiP2pInfo (android.net.wifi.p2p.WifiP2pInfo)1 WifiP2pManager (android.net.wifi.p2p.WifiP2pManager)1