Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 079ea155 authored by Purushottam Kushwaha's avatar Purushottam Kushwaha Committed by Michael Bestas
Browse files

WiFiDisplayController: Defer the P2P Initialization from its constructor.

P2PManager initialization from WiFiDisplayController’s constructor
would start a p2p interface on the boot up when persist.debug.wfd.enable is set.
This would block the NAN operations if NAN and P2P concurrency is not
supported.
Moreover, this initialization of P2P in WiFiDisplayController’s constructor is
needless as this would be required for any of the P2P operations that would
happen at later point of time, based on the user’s trigger.
Thus, move this P2P initialization to the first action point of P2P operation
in WiFiDisplayController.

NOTE: Once initialization of P2P is done in WiFiDisplayController, it is not
de-initialized again. Thus P2P interface would exist and further NAN start would
fail until device is rebooted. This issue need to be fixed.

Change-Id: Ia26aee2f6496cf11aba3c99dcb55c3264ea0a5c0
CRs-Fixed: 2258826
parent b81e6953
Loading
Loading
Loading
Loading
+20 −11
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ final class WifiDisplayController implements DumpUtils.Dump {
    private final Listener mListener;

    private final WifiP2pManager mWifiP2pManager;
    private final Channel mWifiP2pChannel;
    private Channel mWifiP2pChannel;

    private boolean mWifiP2pEnabled;
    private boolean mWfdEnabled;
@@ -169,7 +169,6 @@ final class WifiDisplayController implements DumpUtils.Dump {
        mListener = listener;

        mWifiP2pManager = (WifiP2pManager)context.getSystemService(Context.WIFI_P2P_SERVICE);
        mWifiP2pChannel = mWifiP2pManager.initialize(context, handler.getLooper(), null);

        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
@@ -195,6 +194,16 @@ final class WifiDisplayController implements DumpUtils.Dump {
        updateSettings();
    }

    private Channel getWifiP2pChannel() {
        if (mWifiP2pChannel == null) {
            mWifiP2pChannel = mWifiP2pManager.initialize(mContext, mHandler.getLooper(), null);
            if (DEBUG) {
                Slog.d(TAG, "Creating WifiP2pChannel");
            }
        }
        return mWifiP2pChannel;
    }

    private void updateSettings() {
        final ContentResolver resolver = mContext.getContentResolver();
        mWifiDisplayOnSetting = Settings.Global.getInt(resolver,
@@ -291,7 +300,7 @@ final class WifiDisplayController implements DumpUtils.Dump {
                wfdInfo.setSessionAvailable(true);
                wfdInfo.setControlPort(DEFAULT_CONTROL_PORT);
                wfdInfo.setMaxThroughput(MAX_THROUGHPUT);
                mWifiP2pManager.setWFDInfo(mWifiP2pChannel, wfdInfo, new ActionListener() {
                mWifiP2pManager.setWFDInfo(getWifiP2pChannel(), wfdInfo, new ActionListener() {
                    @Override
                    public void onSuccess() {
                        if (DEBUG) {
@@ -319,7 +328,7 @@ final class WifiDisplayController implements DumpUtils.Dump {
            if (mWfdEnabled || mWfdEnabling) {
                WifiP2pWfdInfo wfdInfo = new WifiP2pWfdInfo();
                wfdInfo.setWfdEnabled(false);
                mWifiP2pManager.setWFDInfo(mWifiP2pChannel, wfdInfo, new ActionListener() {
                mWifiP2pManager.setWFDInfo(getWifiP2pChannel(), wfdInfo, new ActionListener() {
                    @Override
                    public void onSuccess() {
                        if (DEBUG) {
@@ -389,7 +398,7 @@ final class WifiDisplayController implements DumpUtils.Dump {
    }

    private void tryDiscoverPeers() {
        mWifiP2pManager.discoverPeers(mWifiP2pChannel, new ActionListener() {
        mWifiP2pManager.discoverPeers(getWifiP2pChannel(), new ActionListener() {
            @Override
            public void onSuccess() {
                if (DEBUG) {
@@ -417,7 +426,7 @@ final class WifiDisplayController implements DumpUtils.Dump {
    }

    private void stopPeerDiscovery() {
        mWifiP2pManager.stopPeerDiscovery(mWifiP2pChannel, new ActionListener() {
        mWifiP2pManager.stopPeerDiscovery(getWifiP2pChannel(), new ActionListener() {
            @Override
            public void onSuccess() {
                if (DEBUG) {
@@ -435,7 +444,7 @@ final class WifiDisplayController implements DumpUtils.Dump {
    }

    private void requestPeers() {
        mWifiP2pManager.requestPeers(mWifiP2pChannel, new PeerListListener() {
        mWifiP2pManager.requestPeers(getWifiP2pChannel(), new PeerListListener() {
            @Override
            public void onPeersAvailable(WifiP2pDeviceList peers) {
                if (DEBUG) {
@@ -605,7 +614,7 @@ final class WifiDisplayController implements DumpUtils.Dump {
            unadvertiseDisplay();

            final WifiP2pDevice oldDevice = mDisconnectingDevice;
            mWifiP2pManager.removeGroup(mWifiP2pChannel, new ActionListener() {
            mWifiP2pManager.removeGroup(getWifiP2pChannel(), new ActionListener() {
                @Override
                public void onSuccess() {
                    Slog.i(TAG, "Disconnected from Wifi display: " + oldDevice.deviceName);
@@ -643,7 +652,7 @@ final class WifiDisplayController implements DumpUtils.Dump {
            mHandler.removeCallbacks(mConnectionTimeout);

            final WifiP2pDevice oldDevice = mCancelingDevice;
            mWifiP2pManager.cancelConnect(mWifiP2pChannel, new ActionListener() {
            mWifiP2pManager.cancelConnect(getWifiP2pChannel(), new ActionListener() {
                @Override
                public void onSuccess() {
                    Slog.i(TAG, "Canceled connection to Wifi display: " + oldDevice.deviceName);
@@ -760,7 +769,7 @@ final class WifiDisplayController implements DumpUtils.Dump {
            }

            final WifiP2pDevice newDevice = mDesiredDevice;
            mWifiP2pManager.connect(mWifiP2pChannel, config, new ActionListener() {
            mWifiP2pManager.connect(getWifiP2pChannel(), config, new ActionListener() {
                @Override
                public void onSuccess() {
                    // The connection may not yet be established.  We still need to wait
@@ -847,7 +856,7 @@ final class WifiDisplayController implements DumpUtils.Dump {
        mNetworkInfo = networkInfo;
        if (mWfdEnabled && networkInfo.isConnected()) {
            if (mDesiredDevice != null || mWifiDisplayCertMode) {
                mWifiP2pManager.requestGroupInfo(mWifiP2pChannel, new GroupInfoListener() {
                mWifiP2pManager.requestGroupInfo(getWifiP2pChannel(), new GroupInfoListener() {
                    @Override
                    public void onGroupInfoAvailable(WifiP2pGroup info) {
                        if (info == null) {