wifi-display: add certification options
- Checkbox to show certification menu in "Developer options" - Certification menu to Wireless Display Settings, providing misc control options required to certify Bug: 9371882 Change-Id: Icf74d1122a9dc813b2cf95b6606a8a600a6b9cd1
This commit is contained in:
@@ -19,6 +19,7 @@ package com.android.settings.wfd;
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
@@ -29,8 +30,14 @@ import android.hardware.display.DisplayManager;
|
||||
import android.hardware.display.WifiDisplay;
|
||||
import android.hardware.display.WifiDisplayStatus;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.p2p.WifiP2pManager;
|
||||
import android.net.wifi.p2p.WifiP2pManager.ActionListener;
|
||||
import android.net.wifi.p2p.WifiP2pManager.Channel;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceCategory;
|
||||
@@ -38,12 +45,17 @@ import android.preference.PreferenceGroup;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.provider.Settings;
|
||||
import android.text.Html;
|
||||
import android.util.Slog;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
@@ -59,6 +71,7 @@ import com.android.settings.SettingsPreferenceFragment;
|
||||
*/
|
||||
public final class WifiDisplaySettings extends SettingsPreferenceFragment {
|
||||
private static final String TAG = "WifiDisplaySettings";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private static final int MENU_ID_SCAN = Menu.FIRST;
|
||||
|
||||
@@ -74,6 +87,16 @@ public final class WifiDisplaySettings extends SettingsPreferenceFragment {
|
||||
|
||||
private Switch mActionBarSwitch;
|
||||
|
||||
/* certification */
|
||||
private boolean mWifiDisplayCertificationOn;
|
||||
private WifiP2pManager mWifiP2pManager;
|
||||
private Channel mWifiP2pChannel;
|
||||
private PreferenceGroup mCertCategory;
|
||||
private boolean mListen;
|
||||
private boolean mAutoGO;
|
||||
private int mListenChannel;
|
||||
private int mOperatingChannel;
|
||||
|
||||
public WifiDisplaySettings() {
|
||||
}
|
||||
|
||||
@@ -82,6 +105,8 @@ public final class WifiDisplaySettings extends SettingsPreferenceFragment {
|
||||
super.onCreate(icicle);
|
||||
|
||||
mDisplayManager = (DisplayManager)getActivity().getSystemService(Context.DISPLAY_SERVICE);
|
||||
mWifiP2pManager = (WifiP2pManager)getActivity().getSystemService(Context.WIFI_P2P_SERVICE);
|
||||
mWifiP2pChannel = mWifiP2pManager.initialize(getActivity(), Looper.getMainLooper(), null);
|
||||
|
||||
addPreferencesFromResource(R.xml.wifi_display_settings);
|
||||
setHasOptionsMenu(true);
|
||||
@@ -131,8 +156,10 @@ public final class WifiDisplaySettings extends SettingsPreferenceFragment {
|
||||
filter.addAction(DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED);
|
||||
context.registerReceiver(mReceiver, filter);
|
||||
|
||||
getContentResolver().registerContentObserver(Settings.Secure.getUriFor(
|
||||
getContentResolver().registerContentObserver(Settings.Global.getUriFor(
|
||||
Settings.Global.WIFI_DISPLAY_ON), false, mSettingsObserver);
|
||||
getContentResolver().registerContentObserver(Settings.Global.getUriFor(
|
||||
Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON), false, mSettingsObserver);
|
||||
|
||||
mDisplayManager.scanWifiDisplays();
|
||||
|
||||
@@ -193,6 +220,8 @@ public final class WifiDisplaySettings extends SettingsPreferenceFragment {
|
||||
private void update() {
|
||||
mWifiDisplayOnSetting = Settings.Global.getInt(getContentResolver(),
|
||||
Settings.Global.WIFI_DISPLAY_ON, 0) != 0;
|
||||
mWifiDisplayCertificationOn = Settings.Global.getInt(getContentResolver(),
|
||||
Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, 0) != 0;
|
||||
mWifiDisplayStatus = mDisplayManager.getWifiDisplayStatus();
|
||||
|
||||
applyState();
|
||||
@@ -209,6 +238,10 @@ public final class WifiDisplaySettings extends SettingsPreferenceFragment {
|
||||
if (featureState == WifiDisplayStatus.FEATURE_STATE_ON) {
|
||||
final WifiDisplay[] displays = mWifiDisplayStatus.getDisplays();
|
||||
|
||||
if (mWifiDisplayCertificationOn) {
|
||||
buildCertificationMenu(preferenceScreen);
|
||||
}
|
||||
|
||||
if (mPairedDevicesCategory == null) {
|
||||
mPairedDevicesCategory = new PreferenceCategory(getActivity());
|
||||
mPairedDevicesCategory.setTitle(R.string.wifi_display_paired_devices);
|
||||
@@ -250,6 +283,214 @@ public final class WifiDisplaySettings extends SettingsPreferenceFragment {
|
||||
getActivity().invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
private void buildCertificationMenu(final PreferenceScreen preferenceScreen) {
|
||||
if (mCertCategory == null) {
|
||||
mCertCategory = new PreferenceCategory(getActivity());
|
||||
mCertCategory.setTitle(R.string.wifi_display_certification_heading);
|
||||
} else {
|
||||
mCertCategory.removeAll();
|
||||
}
|
||||
preferenceScreen.addPreference(mCertCategory);
|
||||
|
||||
// display session info if there is an active p2p session
|
||||
if (!mWifiDisplayStatus.getSessionInfo().getGroupId().isEmpty()) {
|
||||
Preference p = new Preference(getActivity());
|
||||
p.setTitle(R.string.wifi_display_session_info);
|
||||
p.setSummary(mWifiDisplayStatus.getSessionInfo().toString());
|
||||
mCertCategory.addPreference(p);
|
||||
|
||||
// show buttons for Pause/Resume when a WFD session is established
|
||||
if (mWifiDisplayStatus.getSessionInfo().getSessionId() != 0) {
|
||||
mCertCategory.addPreference(new Preference(getActivity()) {
|
||||
@Override
|
||||
public View getView(View convertView, ViewGroup parent) {
|
||||
final View v;
|
||||
if (convertView == null) {
|
||||
LayoutInflater li = (LayoutInflater) getActivity().
|
||||
getSystemService(Service.LAYOUT_INFLATER_SERVICE);
|
||||
v = li.inflate(R.layout.two_buttons_panel, null);
|
||||
} else {
|
||||
v = convertView;
|
||||
}
|
||||
|
||||
Button b = (Button)v.findViewById(R.id.left_button);
|
||||
b.setText(R.string.wifi_display_pause);
|
||||
b.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mDisplayManager.pauseWifiDisplay();
|
||||
}
|
||||
});
|
||||
|
||||
b = (Button)v.findViewById(R.id.right_button);
|
||||
b.setText(R.string.wifi_display_resume);
|
||||
b.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mDisplayManager.resumeWifiDisplay();
|
||||
}
|
||||
});
|
||||
|
||||
return v;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// switch for Listen Mode
|
||||
CheckBoxPreference cbp = new CheckBoxPreference(getActivity()) {
|
||||
@Override
|
||||
protected void onClick() {
|
||||
mListen = !mListen;
|
||||
setListenMode(mListen);
|
||||
setChecked(mListen);
|
||||
}
|
||||
};
|
||||
cbp.setTitle(R.string.wifi_display_listen_mode);
|
||||
cbp.setChecked(mListen);
|
||||
mCertCategory.addPreference(cbp);
|
||||
|
||||
// switch for Autonomous GO
|
||||
cbp = new CheckBoxPreference(getActivity()) {
|
||||
@Override
|
||||
protected void onClick() {
|
||||
mAutoGO = !mAutoGO;
|
||||
if (mAutoGO) {
|
||||
startAutoGO();
|
||||
} else {
|
||||
stopAutoGO();
|
||||
}
|
||||
setChecked(mAutoGO);
|
||||
}
|
||||
};
|
||||
cbp.setTitle(R.string.wifi_display_autonomous_go);
|
||||
cbp.setChecked(mAutoGO);
|
||||
mCertCategory.addPreference(cbp);
|
||||
|
||||
// Drop down list for choosing listen channel
|
||||
ListPreference lp = new ListPreference(getActivity()) {
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
super.onDialogClosed(positiveResult);
|
||||
if (positiveResult) {
|
||||
mListenChannel = Integer.parseInt(getValue());
|
||||
setSummary("%1$s");
|
||||
getActivity().invalidateOptionsMenu();
|
||||
setWifiP2pChannels(mListenChannel, mOperatingChannel);
|
||||
}
|
||||
}
|
||||
};
|
||||
String[] lcEntries = { "Auto", "1", "6", "11" };
|
||||
String[] lcValues = { "0", "1", "6", "11" };
|
||||
lp.setTitle(R.string.wifi_display_listen_channel);
|
||||
lp.setEntries(lcEntries);
|
||||
lp.setEntryValues(lcValues);
|
||||
lp.setValue("" + mListenChannel);
|
||||
lp.setSummary("%1$s");
|
||||
mCertCategory.addPreference(lp);
|
||||
|
||||
// Drop down list for choosing operating channel
|
||||
lp = new ListPreference(getActivity()) {
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
super.onDialogClosed(positiveResult);
|
||||
if (positiveResult) {
|
||||
mOperatingChannel = Integer.parseInt(getValue());
|
||||
setSummary("%1$s");
|
||||
getActivity().invalidateOptionsMenu();
|
||||
setWifiP2pChannels(mListenChannel, mOperatingChannel);
|
||||
}
|
||||
}
|
||||
};
|
||||
String[] ocEntries = { "Auto", "1", "6", "11", "36" };
|
||||
String[] ocValues = { "0", "1", "6", "11", "36" };
|
||||
lp.setTitle(R.string.wifi_display_operating_channel);
|
||||
lp.setEntries(ocEntries);
|
||||
lp.setEntryValues(ocValues);
|
||||
lp.setValue("" + mOperatingChannel);
|
||||
lp.setSummary("%1$s");
|
||||
mCertCategory.addPreference(lp);
|
||||
}
|
||||
|
||||
private void startAutoGO() {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "Starting Autonomous GO...");
|
||||
}
|
||||
mWifiP2pManager.createGroup(mWifiP2pChannel, new ActionListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "Successfully started AutoGO.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int reason) {
|
||||
Slog.e(TAG, "Failed to start AutoGO with reason " + reason + ".");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void stopAutoGO() {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "Stopping Autonomous GO...");
|
||||
}
|
||||
mWifiP2pManager.removeGroup(mWifiP2pChannel, new ActionListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "Successfully stopped AutoGO.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int reason) {
|
||||
Slog.e(TAG, "Failed to stop AutoGO with reason " + reason + ".");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setListenMode(final boolean enable) {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "Setting listen mode to: " + enable);
|
||||
}
|
||||
mWifiP2pManager.listen(mWifiP2pChannel, enable, new ActionListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "Successfully " + (enable ? "entered" : "exited")
|
||||
+" listen mode.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int reason) {
|
||||
Slog.e(TAG, "Failed to " + (enable ? "entered" : "exited")
|
||||
+" listen mode with reason " + reason + ".");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setWifiP2pChannels(final int lc, final int oc) {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "Setting wifi p2p channel: lc=" + lc + ", oc=" + oc);
|
||||
}
|
||||
mWifiP2pManager.setWifiP2pChannels(mWifiP2pChannel,
|
||||
lc, oc, new ActionListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "Successfully set wifi p2p channels.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int reason) {
|
||||
Slog.e(TAG, "Failed to set wifi p2p channels with reason " + reason + ".");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Preference createWifiDisplayPreference(final WifiDisplay d) {
|
||||
WifiDisplayPreference p = new WifiDisplayPreference(getActivity(), d);
|
||||
if (d.equals(mWifiDisplayStatus.getActiveDisplay())) {
|
||||
|
Reference in New Issue
Block a user