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

Commit 8297cb3a authored by Irfan Sheriff's avatar Irfan Sheriff Committed by Android (Google) Code Review
Browse files

Merge "Add wifi direct settings UI"

parents e711bf7c 8c2ac71b
Loading
Loading
Loading
Loading
+15 −13
Original line number Original line Diff line number Diff line
@@ -1375,23 +1375,25 @@


    <!-- Wi-Fi p2p / Wi-Fi Direct settings -->
    <!-- Wi-Fi p2p / Wi-Fi Direct settings -->
    <!-- Used in the 1st-level settings screen to launch Wi-fi Direct settings [CHAR LIMIT=25] -->
    <!-- Used in the 1st-level settings screen to launch Wi-fi Direct settings [CHAR LIMIT=25] -->
    <string name="wifi_p2p_settings_title">Wi-Fi direct</string>
    <string name="wifi_p2p_settings_title">Wi-Fi Direct</string>
    <!-- Summary for Wi-fi Direct settings item in the 1st-level settings screen [CHAR LIMIT=50]-->
    <string name="wifi_p2p_settings_summary">Set up peer-to-peer connectivity</string>
    <string name="wifi_p2p_device_info">Device information</string>
    <string name="wifi_p2p_device_info">Device information</string>
    <string name="wifi_p2p_wps_setup">Wi-Fi protected setup</string>
    <string name="wifi_p2p_wps_pin">Type PIN</string>
    <string name="wifi_p2p_persist_network">Remember this connection</string>
    <string name="wifi_p2p_persist_network">Remember this connection</string>
    <!-- Menu option to discover peers-->
    <!-- Menu option to discover peers-->
    <string name="wifi_p2p_menu_search">Search</string>
    <string name="wifi_p2p_menu_search">SEARCH FOR DEVICES</string>
    <!-- Menu option to create a group-->
    <!-- Menu option when discovery is in progress-->
    <string name="wifi_p2p_menu_create_group">Create group</string>
    <string name="wifi_p2p_menu_searching">SEARCHING</string>
    <!-- Menu option to remove a group-->
    <!-- Menu option to Rename-->
    <string name="wifi_p2p_menu_remove_group">Remove group</string>
    <string name="wifi_p2p_menu_rename">Rename device</string>
    <!-- Menu option to Wi-Fi p2p advanced settings -->
    <string name="wifi_p2p_menu_advanced">Advanced</string>
    <!-- Title for available p2p devices -->
    <!-- Title for available p2p devices -->
    <string name="wifi_p2p_available_devices">Available devices</string>
    <string name="wifi_p2p_peer_devices">PEER DEVICES</string>
    <!-- Toast text for a failed connection initiation -->
    <string name="wifi_p2p_failed_connect_message">Connect failed</string>
    <!-- Title for disconnect dialog -->
    <string name="wifi_p2p_disconnect_title">Disconnect?</string>
    <!-- Message test for disconnection from one device-->
    <string name="wifi_p2p_disconnect_message">Touching Disconnect will end your connection with <xliff:g id="peer_name">%1$s</xliff:g></string>
    <!-- Message test for disconnection from multiple devices-->
    <string name="wifi_p2p_disconnect_multiple_message">Touching Disconnect will end your connection with <xliff:g id="peer_name">%1$s</xliff:g> and <xliff:g id="peer_count">%2$s</xliff:g> other devices</string>


    <!-- Wifi AP settings-->
    <!-- Wifi AP settings-->
    <!-- Label for wifi tether checkbox. Toggles Access Point on/off -->
    <!-- Label for wifi tether checkbox. Toggles Access Point on/off -->
+1 −8
Original line number Original line Diff line number Diff line
@@ -54,17 +54,10 @@
        android:key="android_beam_settings"
        android:key="android_beam_settings"
        android:title="@string/android_beam_settings_title" />
        android:title="@string/android_beam_settings_title" />


    <CheckBoxPreference
        android:key="toggle_wifi_p2p"
        android:title="@string/wifi_p2p_settings_title"
        android:persistent="false" />

    <PreferenceScreen
    <PreferenceScreen
        android:fragment="com.android.settings.wifi.p2p.WifiP2pSettings"
        android:fragment="com.android.settings.wifi.p2p.WifiP2pSettings"
        android:key="wifi_p2p_settings"
        android:key="wifi_p2p_settings"
        android:title="@string/wifi_p2p_settings_title"
        android:title="@string/wifi_p2p_settings_title" />
        android:summary="@string/wifi_p2p_settings_summary">
    </PreferenceScreen>


    <PreferenceScreen
    <PreferenceScreen
        android:key="mobile_network_settings"
        android:key="mobile_network_settings"
+1 −18
Original line number Original line Diff line number Diff line
@@ -37,7 +37,6 @@ import android.widget.Switch;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.TelephonyProperties;
import com.android.internal.telephony.TelephonyProperties;
import com.android.settings.nfc.NfcEnabler;
import com.android.settings.nfc.NfcEnabler;
import com.android.settings.wifi.p2p.WifiP2pEnabler;


public class WirelessSettings extends SettingsPreferenceFragment {
public class WirelessSettings extends SettingsPreferenceFragment {


@@ -46,7 +45,6 @@ public class WirelessSettings extends SettingsPreferenceFragment {
    private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
    private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
    private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
    private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
    private static final String KEY_VPN_SETTINGS = "vpn_settings";
    private static final String KEY_VPN_SETTINGS = "vpn_settings";
    private static final String KEY_TOGGLE_WIFI_P2P = "toggle_wifi_p2p";
    private static final String KEY_WIFI_P2P_SETTINGS = "wifi_p2p_settings";
    private static final String KEY_WIFI_P2P_SETTINGS = "wifi_p2p_settings";
    private static final String KEY_TETHER_SETTINGS = "tether_settings";
    private static final String KEY_TETHER_SETTINGS = "tether_settings";
    private static final String KEY_PROXY_SETTINGS = "proxy_settings";
    private static final String KEY_PROXY_SETTINGS = "proxy_settings";
@@ -60,8 +58,6 @@ public class WirelessSettings extends SettingsPreferenceFragment {
    private NfcEnabler mNfcEnabler;
    private NfcEnabler mNfcEnabler;
    private NfcAdapter mNfcAdapter;
    private NfcAdapter mNfcAdapter;


    private WifiP2pEnabler mWifiP2pEnabler;

    /**
    /**
     * Invoked on each preference click in this hierarchy, overrides
     * Invoked on each preference click in this hierarchy, overrides
     * PreferenceActivity's implementation.  Used to make sure we track the
     * PreferenceActivity's implementation.  Used to make sure we track the
@@ -102,8 +98,6 @@ public class WirelessSettings extends SettingsPreferenceFragment {
        CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC);
        CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC);
        PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
        PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);


        CheckBoxPreference wifiP2p = (CheckBoxPreference) findPreference(KEY_TOGGLE_WIFI_P2P);

        mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
        mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
        mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
        mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);


@@ -156,11 +150,8 @@ public class WirelessSettings extends SettingsPreferenceFragment {
        WifiP2pManager p2p = (WifiP2pManager) activity.getSystemService(Context.WIFI_P2P_SERVICE);
        WifiP2pManager p2p = (WifiP2pManager) activity.getSystemService(Context.WIFI_P2P_SERVICE);


        if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT)) {
        if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT)) {
            getPreferenceScreen().removePreference(wifiP2p);
        } else {
            mWifiP2pEnabler = new WifiP2pEnabler(activity, wifiP2p);
        }
            getPreferenceScreen().removePreference(findPreference(KEY_WIFI_P2P_SETTINGS));
            getPreferenceScreen().removePreference(findPreference(KEY_WIFI_P2P_SETTINGS));
        }


        // Enable Proxy selector settings if allowed.
        // Enable Proxy selector settings if allowed.
        Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
        Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
@@ -189,10 +180,6 @@ public class WirelessSettings extends SettingsPreferenceFragment {
        if (mNfcEnabler != null) {
        if (mNfcEnabler != null) {
            mNfcEnabler.resume();
            mNfcEnabler.resume();
        }
        }

        if (mWifiP2pEnabler != null) {
            mWifiP2pEnabler.resume();
        }
    }
    }


    @Override
    @Override
@@ -203,10 +190,6 @@ public class WirelessSettings extends SettingsPreferenceFragment {
        if (mNfcEnabler != null) {
        if (mNfcEnabler != null) {
            mNfcEnabler.pause();
            mNfcEnabler.pause();
        }
        }

        if (mWifiP2pEnabler != null) {
            mWifiP2pEnabler.pause();
        }
    }
    }


    @Override
    @Override
+0 −132
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.wifi.p2p;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.net.wifi.WpsInfo;
import android.net.wifi.p2p.WifiP2pConfig;
import android.net.wifi.p2p.WifiP2pDevice;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.Spinner;
import android.widget.TextView;

import com.android.settings.R;

/**
 * Dialog to setup a p2p connection
 */
public class WifiP2pDialog extends AlertDialog implements AdapterView.OnItemSelectedListener {

    static final int BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE;

    private final DialogInterface.OnClickListener mListener;

    private View mView;
    private TextView mDeviceName;
    private TextView mDeviceAddress;

    /* These values come from "wifi_p2p_wps_setup" resource array */
    private static final int WPS_PBC = 0;
    private static final int WPS_KEYPAD = 1;
    private static final int WPS_DISPLAY = 2;

    private int mWpsSetupIndex = WPS_PBC; //default is pbc

    WifiP2pDevice mDevice;

    public WifiP2pDialog(Context context, DialogInterface.OnClickListener listener,
            WifiP2pDevice device) {
        super(context);
        mListener = listener;
        mDevice = device;
    }

    public WifiP2pConfig getConfig() {
        WifiP2pConfig config = new WifiP2pConfig();
        config.deviceAddress = mDeviceAddress.getText().toString();
        config.wps = new WpsInfo();
        switch (mWpsSetupIndex) {
            case WPS_PBC:
                config.wps.setup = WpsInfo.PBC;
                break;
            case WPS_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 = WpsInfo.DISPLAY;
                break;
            default:
                config.wps.setup = WpsInfo.PBC;
                break;
        }
        return config;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        mView = getLayoutInflater().inflate(R.layout.wifi_p2p_dialog, null);
        Spinner mWpsSetup = ((Spinner) mView.findViewById(R.id.wps_setup));

        setView(mView);
        setInverseBackgroundForced(true);

        Context context = getContext();

        setTitle(R.string.wifi_p2p_settings_title);
        mDeviceName = (TextView) mView.findViewById(R.id.device_name);
        mDeviceAddress = (TextView) mView.findViewById(R.id.device_address);

        setButton(BUTTON_SUBMIT, context.getString(R.string.wifi_connect), mListener);
        setButton(DialogInterface.BUTTON_NEGATIVE,
                    context.getString(R.string.wifi_cancel), mListener);

        if (mDevice != null) {
            mDeviceName.setText(mDevice.deviceName);
            mDeviceAddress.setText(mDevice.deviceAddress);
            mWpsSetup.setSelection(mWpsSetupIndex); //keep pbc as default
       }

        mWpsSetup.setOnItemSelectedListener(this);

        super.onCreate(savedInstanceState);
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        mWpsSetupIndex = position;

        if (mWpsSetupIndex == WPS_KEYPAD) {
            mView.findViewById(R.id.wps_pin_entry).setVisibility(View.VISIBLE);
        } else {
            mView.findViewById(R.id.wps_pin_entry).setVisibility(View.GONE);
        }
        return;
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {
    }

}
+31 −16
Original line number Original line Diff line number Diff line
@@ -27,18 +27,21 @@ import android.os.Message;
import android.preference.CheckBoxPreference;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.Preference;
import android.provider.Settings;
import android.provider.Settings;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.util.Log;
import android.util.Log;


/**
/**
 * WifiP2pEnabler is a helper to manage the Wifi p2p on/off
 * WifiP2pEnabler is a helper to manage the Wifi p2p on/off
 */
 */
public class WifiP2pEnabler implements Preference.OnPreferenceChangeListener {
public class WifiP2pEnabler implements CompoundButton.OnCheckedChangeListener {
    private static final String TAG = "WifiP2pEnabler";
    private static final String TAG = "WifiP2pEnabler";


    private final Context mContext;
    private final Context mContext;
    private final CheckBoxPreference mCheckBox;
    private final IntentFilter mIntentFilter;
    private final IntentFilter mIntentFilter;
    private Switch mSwitch;
    private WifiP2pManager mWifiP2pManager;
    private WifiP2pManager mWifiP2pManager;
    private boolean mStateMachineEvent;
    private WifiP2pManager.Channel mChannel;
    private WifiP2pManager.Channel mChannel;


    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@@ -53,9 +56,9 @@ public class WifiP2pEnabler implements Preference.OnPreferenceChangeListener {
        }
        }
    };
    };


    public WifiP2pEnabler(Context context, CheckBoxPreference checkBox) {
    public WifiP2pEnabler(Context context, Switch switch_) {
        mContext = context;
        mContext = context;
        mCheckBox = checkBox;
        mSwitch = switch_;


        mWifiP2pManager = (WifiP2pManager) context.getSystemService(Context.WIFI_P2P_SERVICE);
        mWifiP2pManager = (WifiP2pManager) context.getSystemService(Context.WIFI_P2P_SERVICE);
        if (mWifiP2pManager != null) {
        if (mWifiP2pManager != null) {
@@ -64,7 +67,7 @@ public class WifiP2pEnabler implements Preference.OnPreferenceChangeListener {
                //Failure to set up connection
                //Failure to set up connection
                Log.e(TAG, "Failed to set up connection with wifi p2p service");
                Log.e(TAG, "Failed to set up connection with wifi p2p service");
                mWifiP2pManager = null;
                mWifiP2pManager = null;
                mCheckBox.setEnabled(false);
                mSwitch.setEnabled(false);
            }
            }
        } else {
        } else {
            Log.e(TAG, "mWifiP2pManager is null!");
            Log.e(TAG, "mWifiP2pManager is null!");
@@ -76,42 +79,54 @@ public class WifiP2pEnabler implements Preference.OnPreferenceChangeListener {
    public void resume() {
    public void resume() {
        if (mWifiP2pManager == null) return;
        if (mWifiP2pManager == null) return;
        mContext.registerReceiver(mReceiver, mIntentFilter);
        mContext.registerReceiver(mReceiver, mIntentFilter);
        mCheckBox.setOnPreferenceChangeListener(this);
        mSwitch.setOnCheckedChangeListener(this);
    }
    }


    public void pause() {
    public void pause() {
        if (mWifiP2pManager == null) return;
        if (mWifiP2pManager == null) return;
        mContext.unregisterReceiver(mReceiver);
        mContext.unregisterReceiver(mReceiver);
        mCheckBox.setOnPreferenceChangeListener(null);
        mSwitch.setOnCheckedChangeListener(null);
    }
    }


    public boolean onPreferenceChange(Preference preference, Object value) {
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {


        if (mWifiP2pManager == null) return false;
        if (mStateMachineEvent) return;


        mCheckBox.setEnabled(false);
        if (mWifiP2pManager == null) return;
        final boolean enable = (Boolean) value;

        if (enable) {
        mSwitch.setEnabled(false);
        if (isChecked) {
            mWifiP2pManager.enableP2p(mChannel);
            mWifiP2pManager.enableP2p(mChannel);
        } else {
        } else {
            mWifiP2pManager.disableP2p(mChannel);
            mWifiP2pManager.disableP2p(mChannel);
        }
        }
        return false;
    }
    }


    private void handleP2pStateChanged(int state) {
    private void handleP2pStateChanged(int state) {
        mCheckBox.setEnabled(true);
        setSwitchChecked(true);
        switch (state) {
        switch (state) {
            case WifiP2pManager.WIFI_P2P_STATE_ENABLED:
            case WifiP2pManager.WIFI_P2P_STATE_ENABLED:
                mCheckBox.setChecked(true);
                setSwitchChecked(true);
                mSwitch.setEnabled(true);
                break;
                break;
            case WifiP2pManager.WIFI_P2P_STATE_DISABLED:
            case WifiP2pManager.WIFI_P2P_STATE_DISABLED:
                mCheckBox.setChecked(false);
                setSwitchChecked(false);
                mSwitch.setEnabled(true);
                break;
                break;
            default:
            default:
                mSwitch.setEnabled(false);
                setSwitchChecked(false);
                Log.e(TAG,"Unhandled wifi state " + state);
                Log.e(TAG,"Unhandled wifi state " + state);
                break;
                break;
        }
        }
    }
    }


    private void setSwitchChecked(boolean checked) {
        if (checked != mSwitch.isChecked()) {
            mStateMachineEvent = true;
            mSwitch.setChecked(checked);
            mStateMachineEvent = false;
        }
    }

}
}
Loading