summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIrfan Sheriff <isheriff@google.com>2012-01-10 16:24:19 -0800
committerIrfan Sheriff <isheriff@google.com>2012-01-18 15:33:31 -0800
commitd37422a3a056bf1b6c9fa7c69d04a4450f88bff9 (patch)
tree4c4095ba2d0263450e4f045b6146e3d9985a7656 /src
parentfaee5f4bdfce82b920dc27119cafcdda7b4c4a8a (diff)
downloadpackages_apps_settings-d37422a3a056bf1b6c9fa7c69d04a4450f88bff9.zip
packages_apps_settings-d37422a3a056bf1b6c9fa7c69d04a4450f88bff9.tar.gz
packages_apps_settings-d37422a3a056bf1b6c9fa7c69d04a4450f88bff9.tar.bz2
Concurrency wifi p2p and client operation support
Change-Id: I095b7e7ce143cc37ec454a8e43ed579258d72ea1
Diffstat (limited to 'src')
-rw-r--r--src/com/android/settings/wifi/p2p/WifiP2pEnabler.java132
-rw-r--r--src/com/android/settings/wifi/p2p/WifiP2pSettings.java23
2 files changed, 1 insertions, 154 deletions
diff --git a/src/com/android/settings/wifi/p2p/WifiP2pEnabler.java b/src/com/android/settings/wifi/p2p/WifiP2pEnabler.java
deleted file mode 100644
index cde44cd..0000000
--- a/src/com/android/settings/wifi/p2p/WifiP2pEnabler.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * 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 com.android.settings.R;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.net.wifi.p2p.WifiP2pManager;
-import android.os.Message;
-import android.preference.CheckBoxPreference;
-import android.preference.Preference;
-import android.provider.Settings;
-import android.widget.CompoundButton;
-import android.widget.Switch;
-import android.util.Log;
-
-/**
- * WifiP2pEnabler is a helper to manage the Wifi p2p on/off
- */
-public class WifiP2pEnabler implements CompoundButton.OnCheckedChangeListener {
- private static final String TAG = "WifiP2pEnabler";
-
- private final Context mContext;
- private final IntentFilter mIntentFilter;
- private Switch mSwitch;
- private WifiP2pManager mWifiP2pManager;
- private boolean mStateMachineEvent;
- private WifiP2pManager.Channel mChannel;
-
- private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
-
- if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
- handleP2pStateChanged(intent.getIntExtra(
- WifiP2pManager.EXTRA_WIFI_STATE, WifiP2pManager.WIFI_P2P_STATE_DISABLED));
- }
- }
- };
-
- public WifiP2pEnabler(Context context, Switch switch_) {
- mContext = context;
- mSwitch = switch_;
-
- mWifiP2pManager = (WifiP2pManager) context.getSystemService(Context.WIFI_P2P_SERVICE);
- if (mWifiP2pManager != null) {
- 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");
- mWifiP2pManager = null;
- mSwitch.setEnabled(false);
- }
- } else {
- Log.e(TAG, "mWifiP2pManager is null!");
- }
- mIntentFilter = new IntentFilter(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
-
- }
-
- public void resume() {
- if (mWifiP2pManager == null) return;
- mContext.registerReceiver(mReceiver, mIntentFilter);
- mSwitch.setOnCheckedChangeListener(this);
- }
-
- public void pause() {
- if (mWifiP2pManager == null) return;
- mContext.unregisterReceiver(mReceiver);
- mSwitch.setOnCheckedChangeListener(null);
- }
-
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-
- if (mStateMachineEvent) return;
-
- if (mWifiP2pManager == null) return;
-
- mSwitch.setEnabled(false);
- if (isChecked) {
- mWifiP2pManager.enableP2p(mChannel);
- } else {
- mWifiP2pManager.disableP2p(mChannel);
- }
- }
-
- private void handleP2pStateChanged(int state) {
- setSwitchChecked(true);
- switch (state) {
- case WifiP2pManager.WIFI_P2P_STATE_ENABLED:
- setSwitchChecked(true);
- mSwitch.setEnabled(true);
- break;
- case WifiP2pManager.WIFI_P2P_STATE_DISABLED:
- setSwitchChecked(false);
- mSwitch.setEnabled(true);
- break;
- default:
- mSwitch.setEnabled(false);
- setSwitchChecked(false);
- Log.e(TAG,"Unhandled wifi state " + state);
- break;
- }
- }
-
- private void setSwitchChecked(boolean checked) {
- if (checked != mSwitch.isChecked()) {
- mStateMachineEvent = true;
- mSwitch.setChecked(checked);
- mStateMachineEvent = false;
- }
- }
-
-}
diff --git a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
index cf3b303..369506e 100644
--- a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
+++ b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
@@ -74,7 +74,6 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
private OnClickListener mDisconnectListener;
private WifiP2pPeer mSelectedWifiPeer;
- private WifiP2pEnabler mWifiP2pEnabler;
private boolean mWifiP2pEnabled;
private boolean mWifiP2pSearching;
private int mConnectedDevices;
@@ -162,25 +161,6 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
}
};
- Switch actionBarSwitch = new Switch(activity);
-
- if (activity instanceof PreferenceActivity) {
- PreferenceActivity preferenceActivity = (PreferenceActivity) activity;
- if (preferenceActivity.onIsHidingHeaders() || !preferenceActivity.onIsMultiPane()) {
- final int padding = activity.getResources().getDimensionPixelSize(
- R.dimen.action_bar_switch_padding);
- actionBarSwitch.setPadding(0, 0, padding, 0);
- activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
- ActionBar.DISPLAY_SHOW_CUSTOM);
- activity.getActionBar().setCustomView(actionBarSwitch, new ActionBar.LayoutParams(
- ActionBar.LayoutParams.WRAP_CONTENT,
- ActionBar.LayoutParams.WRAP_CONTENT,
- Gravity.CENTER_VERTICAL | Gravity.RIGHT));
- }
- }
-
- mWifiP2pEnabler = new WifiP2pEnabler(activity, actionBarSwitch);
-
final PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.removeAll();
@@ -194,7 +174,6 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
@Override
public void onResume() {
super.onResume();
- mWifiP2pEnabler.resume();
getActivity().registerReceiver(mReceiver, mIntentFilter);
startSearch();
}
@@ -202,7 +181,7 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
@Override
public void onPause() {
super.onPause();
- mWifiP2pEnabler.pause();
+ mWifiP2pManager.stopPeerDiscovery(mChannel, null);
getActivity().unregisterReceiver(mReceiver);
}