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

Commit ec105788 authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

Update new API in debug settings

Bug: 5247957
Change-Id: I594e55a928a2870cb153b042df74a2b354bee073
parent b81ce47a
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -33,8 +33,7 @@ import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WifiConfiguration.ProxySettings;
import android.net.wifi.WifiConfiguration.Status;
import android.net.wifi.WifiInfo;
import android.net.wifi.Wps;
import android.net.wifi.Wps.Setup;
import android.net.wifi.WpsInfo;
import android.security.Credentials;
import android.security.KeyStore;
import android.text.Editable;
@@ -484,20 +483,20 @@ public class WifiConfigController implements TextWatcher,
        return MANUAL;
    }

    Wps getWpsConfig() {
        Wps config = new Wps();
    WpsInfo getWpsConfig() {
        WpsInfo config = new WpsInfo();
        switch (mNetworkSetupSpinner.getSelectedItemPosition()) {
            case WPS_PBC:
                config.setup = Setup.PBC;
                config.setup = WpsInfo.PBC;
                break;
            case WPS_KEYPAD:
                config.setup = Setup.KEYPAD;
                config.setup = WpsInfo.KEYPAD;
                break;
            case WPS_DISPLAY:
                config.setup = Setup.DISPLAY;
                config.setup = WpsInfo.DISPLAY;
                break;
            default:
                config.setup = Setup.INVALID;
                config.setup = WpsInfo.INVALID;
                Log.e(TAG, "WPS not selected type");
                return config;
        }
+6 −7
Original line number Diff line number Diff line
@@ -19,8 +19,7 @@ package com.android.settings.wifi.p2p;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.net.wifi.Wps;
import android.net.wifi.Wps.Setup;
import android.net.wifi.WpsInfo;
import android.net.wifi.p2p.WifiP2pConfig;
import android.net.wifi.p2p.WifiP2pDevice;
import android.os.Bundle;
@@ -64,21 +63,21 @@ public class WifiP2pDialog extends AlertDialog implements AdapterView.OnItemSele
    public WifiP2pConfig getConfig() {
        WifiP2pConfig config = new WifiP2pConfig();
        config.deviceAddress = mDeviceAddress.getText().toString();
        config.wps = new Wps();
        config.wps = new WpsInfo();
        switch (mWpsSetupIndex) {
            case WPS_PBC:
                config.wps.setup = Setup.PBC;
                config.wps.setup = WpsInfo.PBC;
                break;
            case WPS_KEYPAD:
                config.wps.setup = Setup.KEYPAD;
                config.wps.setup = WpsInfo.KEYPAD;
                config.wps.pin = ((TextView) mView.findViewById(R.id.wps_pin)).
                        getText().toString();
                break;
            case WPS_DISPLAY:
                config.wps.setup = Setup.DISPLAY;
                config.wps.setup = WpsInfo.DISPLAY;
                break;
            default:
                config.wps.setup = Setup.PBC;
                config.wps.setup = WpsInfo.PBC;
                break;
        }
        return config;
+1 −23
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.p2p.WifiP2pManager;
import android.os.Handler;
import android.os.Message;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
@@ -39,7 +38,6 @@ public class WifiP2pEnabler implements Preference.OnPreferenceChangeListener {
    private final Context mContext;
    private final CheckBoxPreference mCheckBox;
    private final IntentFilter mIntentFilter;
    private final Handler mHandler = new WifiP2pHandler();
    private WifiP2pManager mWifiP2pManager;
    private WifiP2pManager.Channel mChannel;

@@ -61,7 +59,7 @@ public class WifiP2pEnabler implements Preference.OnPreferenceChangeListener {

        mWifiP2pManager = (WifiP2pManager) context.getSystemService(Context.WIFI_P2P_SERVICE);
        if (mWifiP2pManager != null) {
            mChannel = mWifiP2pManager.initialize(mContext, mHandler);
            mChannel = mWifiP2pManager.initialize(mContext, mContext.getMainLooper(), null);
            if (mChannel == null) {
                //Failure to set up connection
                Log.e(TAG, "Failed to set up connection with wifi p2p service");
@@ -116,24 +114,4 @@ public class WifiP2pEnabler implements Preference.OnPreferenceChangeListener {
        }
    }

    private class WifiP2pHandler extends Handler {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case WifiP2pManager.HANDLER_DISCONNECTION:
                    //Failure to set up connection
                    Log.e(TAG, "Lost connection with wifi p2p service");
                    mWifiP2pManager = null;
                    mCheckBox.setEnabled(false);
                    break;
                case WifiP2pManager.ENABLE_P2P_FAILED:
                    mCheckBox.setEnabled(true);
                    break;
                default:
                    //Ignore
                    break;
            }
        }
    }

}
+2 −3
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.content.Context;
import android.net.wifi.WifiManager;
import android.net.wifi.p2p.WifiP2pManager;
import android.net.wifi.p2p.WifiP2pDevice;
import android.net.wifi.p2p.WifiP2pDevice.Status;
import android.preference.Preference;
import android.text.TextUtils;
import android.view.View;
@@ -74,7 +73,7 @@ public class WifiP2pPeer extends Preference {

        // devices go in the order of the status
        if (device.status != other.device.status) {
            return device.status.ordinal() < other.device.status.ordinal() ? -1 : 1;
            return device.status < other.device.status ? -1 : 1;
        }

        // Sort by name/address
@@ -99,6 +98,6 @@ public class WifiP2pPeer extends Preference {
        Context context = getContext();
        mSignal.setImageLevel(getLevel());
        String[] statusArray = context.getResources().getStringArray(R.array.wifi_p2p_status);
        setSummary(statusArray[device.status.ordinal()]);
        setSummary(statusArray[device.status]);
    }
}
+53 −37
Original line number Diff line number Diff line
@@ -31,8 +31,8 @@ import android.net.wifi.p2p.WifiP2pConfig;
import android.net.wifi.p2p.WifiP2pDevice;
import android.net.wifi.p2p.WifiP2pDeviceList;
import android.net.wifi.p2p.WifiP2pManager;
import android.net.wifi.p2p.WifiP2pManager.PeerListListener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.Preference;
import android.preference.PreferenceActivity;
@@ -53,7 +53,8 @@ import java.util.Collection;
/*
 * Displays Wi-fi p2p settings UI
 */
public class WifiP2pSettings extends SettingsPreferenceFragment {
public class WifiP2pSettings extends SettingsPreferenceFragment
        implements PeerListListener {

    private static final String TAG = "WifiP2pSettings";
    private static final int MENU_ID_SEARCH = Menu.FIRST;
@@ -62,7 +63,6 @@ public class WifiP2pSettings extends SettingsPreferenceFragment {


    private final IntentFilter mIntentFilter = new IntentFilter();
    private final Handler mHandler = new WifiP2pHandler();
    private WifiP2pManager mWifiP2pManager;
    private WifiP2pManager.Channel mChannel;
    private WifiP2pDialog mConnectDialog;
@@ -81,17 +81,15 @@ public class WifiP2pSettings extends SettingsPreferenceFragment {
            if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
                //TODO: nothing right now
            } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
                if (mWifiP2pManager != null) mWifiP2pManager.requestPeers(mChannel);
                if (mWifiP2pManager != null) {
                    mWifiP2pManager.requestPeers(mChannel, WifiP2pSettings.this);
                }
            } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
                if (mWifiP2pManager == null) return;
                NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(
                        WifiP2pManager.EXTRA_NETWORK_INFO);
                if (networkInfo.isConnected()) {
                    Log.d(TAG, "Start peer connections");
                    mWifiP2pManager.startPeerCommunication();
                } else {
                    Log.d(TAG, "Stop peer connections");
                    mWifiP2pManager.stopPeerCommunication();
                    Log.d(TAG, "Connected");
                }
            }
        }
@@ -109,7 +107,7 @@ public class WifiP2pSettings extends SettingsPreferenceFragment {
        final Activity activity = getActivity();
        mWifiP2pManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
        if (mWifiP2pManager != null) {
            mChannel = mWifiP2pManager.initialize(activity, mHandler);
            mChannel = mWifiP2pManager.initialize(activity, getActivity().getMainLooper(), null);
            if (mChannel == null) {
                //Failure to set up connection
                Log.e(TAG, "Failed to set up connection with wifi p2p service");
@@ -126,7 +124,15 @@ public class WifiP2pSettings extends SettingsPreferenceFragment {
                if (which == DialogInterface.BUTTON_POSITIVE) {
                    WifiP2pConfig config = mConnectDialog.getConfig();
                    if (mWifiP2pManager != null) {
                        mWifiP2pManager.connect(mChannel, config);
                        mWifiP2pManager.connect(mChannel, config,
                                new WifiP2pManager.ActionListener() {
                            public void onSuccess() {
                                Log.d(TAG, " connect success");
                            }
                            public void onFailure(int reason) {
                                Log.d(TAG, " connect fail " + reason);
                            }
                        });
                    }
                }
            }
@@ -138,7 +144,14 @@ public class WifiP2pSettings extends SettingsPreferenceFragment {
            public void onClick(DialogInterface dialog, int which) {
                if (which == DialogInterface.BUTTON_POSITIVE) {
                    if (mWifiP2pManager != null) {
                        mWifiP2pManager.removeGroup(mChannel);
                        mWifiP2pManager.removeGroup(mChannel, new WifiP2pManager.ActionListener() {
                            public void onSuccess() {
                                Log.d(TAG, " remove group success");
                            }
                            public void onFailure(int reason) {
                                Log.d(TAG, " remove group fail " + reason);
                            }
                        });
                    }
                }
            }
@@ -151,7 +164,16 @@ public class WifiP2pSettings extends SettingsPreferenceFragment {
        super.onResume();
        getActivity().registerReceiver(mReceiver, mIntentFilter);

        if (mWifiP2pManager != null) mWifiP2pManager.discoverPeers(mChannel);
        if (mWifiP2pManager != null) {
            mWifiP2pManager.discoverPeers(mChannel, new WifiP2pManager.ActionListener() {
                            public void onSuccess() {
                                Log.d(TAG, " discover success");
                            }
                            public void onFailure(int reason) {
                                Log.d(TAG, " discover fail " + reason);
                            }
                        });
        }
    }

    @Override
@@ -176,12 +198,26 @@ public class WifiP2pSettings extends SettingsPreferenceFragment {
        switch (item.getItemId()) {
            case MENU_ID_SEARCH:
                if (mWifiP2pManager != null) {
                    mWifiP2pManager.discoverPeers(mChannel);
                    mWifiP2pManager.discoverPeers(mChannel, new WifiP2pManager.ActionListener() {
                            public void onSuccess() {
                                Log.d(TAG, " discover success");
                            }
                            public void onFailure(int reason) {
                                Log.d(TAG, " discover fail " + reason);
                            }
                        });
                }
                return true;
            case MENU_ID_CREATE_GROUP:
                if (mWifiP2pManager != null) {
                    mWifiP2pManager.createGroup(mChannel);
                    mWifiP2pManager.createGroup(mChannel, new WifiP2pManager.ActionListener() {
                            public void onSuccess() {
                                Log.d(TAG, " create group success");
                            }
                            public void onFailure(int reason) {
                                Log.d(TAG, " create group fail " + reason);
                            }
                        });
                }
                return true;
            case MENU_ID_ADVANCED:
@@ -195,7 +231,7 @@ public class WifiP2pSettings extends SettingsPreferenceFragment {
    public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
        if (preference instanceof WifiP2pPeer) {
            mSelectedWifiPeer = (WifiP2pPeer) preference;
            if (mSelectedWifiPeer.device.status == WifiP2pDevice.Status.CONNECTED) {
            if (mSelectedWifiPeer.device.status == WifiP2pDevice.CONNECTED) {
                showDialog(DIALOG_DISCONNECT);
            } else {
                showDialog(DIALOG_CONNECT);
@@ -222,7 +258,7 @@ public class WifiP2pSettings extends SettingsPreferenceFragment {
        return null;
    }

    private void updatePeers(WifiP2pDeviceList peers) {
    public void onPeersAvailable(WifiP2pDeviceList peers) {
        final PreferenceScreen preferenceScreen = getPreferenceScreen();
        preferenceScreen.removeAll();

@@ -230,24 +266,4 @@ public class WifiP2pSettings extends SettingsPreferenceFragment {
            preferenceScreen.addPreference(new WifiP2pPeer(getActivity(), peer));
        }
    }

    private class WifiP2pHandler extends Handler {
        @Override
        public void handleMessage(Message message) {
            switch (message.what) {
                case WifiP2pManager.HANDLER_DISCONNECTION:
                    //Failure to set up connection
                    Log.e(TAG, "Lost connection with wifi p2p service");
                    mWifiP2pManager = null;
                    break;
                case WifiP2pManager.RESPONSE_PEERS:
                    updatePeers(mWifiP2pManager.peersInResponse(message));
                    break;
                default:
                    //Ignore
                    break;
            }
        }
    }

}