Use AsyncChannel in settings
Change-Id: I440f08dec986e4dad4b578ee4065d6063b8ef989
This commit is contained in:
@@ -18,11 +18,6 @@ package com.android.settings.wifi;
|
|||||||
|
|
||||||
import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID;
|
import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID;
|
||||||
|
|
||||||
import com.android.settings.ProgressCategoryBase;
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
|
||||||
import com.android.settings.Utils;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
@@ -53,6 +48,7 @@ import android.provider.Settings.Secure;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.security.Credentials;
|
import android.security.Credentials;
|
||||||
import android.security.KeyStore;
|
import android.security.KeyStore;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -64,6 +60,12 @@ import android.view.ContextMenu.ContextMenuInfo;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
|
|
||||||
|
import com.android.internal.util.AsyncChannel;
|
||||||
|
import com.android.settings.ProgressCategoryBase;
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
import com.android.settings.Utils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -82,6 +84,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
*/
|
*/
|
||||||
public class WifiSettings extends SettingsPreferenceFragment
|
public class WifiSettings extends SettingsPreferenceFragment
|
||||||
implements DialogInterface.OnClickListener, Preference.OnPreferenceChangeListener {
|
implements DialogInterface.OnClickListener, Preference.OnPreferenceChangeListener {
|
||||||
|
private static final String TAG = "WifiSettings";
|
||||||
private static final int MENU_ID_SCAN = Menu.FIRST;
|
private static final int MENU_ID_SCAN = Menu.FIRST;
|
||||||
private static final int MENU_ID_ADVANCED = Menu.FIRST + 1;
|
private static final int MENU_ID_ADVANCED = Menu.FIRST + 1;
|
||||||
private static final int MENU_ID_CONNECT = Menu.FIRST + 2;
|
private static final int MENU_ID_CONNECT = Menu.FIRST + 2;
|
||||||
@@ -168,6 +171,7 @@ public class WifiSettings extends SettingsPreferenceFragment
|
|||||||
// this method.
|
// this method.
|
||||||
|
|
||||||
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
||||||
|
mWifiManager.asyncConnect(getActivity(), new WifiServiceHandler());
|
||||||
|
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
final Intent intent = activity.getIntent();
|
final Intent intent = activity.getIntent();
|
||||||
@@ -238,6 +242,7 @@ public class WifiSettings extends SettingsPreferenceFragment
|
|||||||
if (mWifiEnabler != null) {
|
if (mWifiEnabler != null) {
|
||||||
mWifiEnabler.resume();
|
mWifiEnabler.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
getActivity().registerReceiver(mReceiver, mFilter);
|
getActivity().registerReceiver(mReceiver, mFilter);
|
||||||
if (mKeyStoreNetworkId != INVALID_NETWORK_ID &&
|
if (mKeyStoreNetworkId != INVALID_NETWORK_ID &&
|
||||||
KeyStore.getInstance().test() == KeyStore.NO_ERROR) {
|
KeyStore.getInstance().test() == KeyStore.NO_ERROR) {
|
||||||
@@ -594,6 +599,50 @@ public class WifiSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class WifiServiceHandler extends Handler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED:
|
||||||
|
if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
|
||||||
|
//AsyncChannel in msg.obj
|
||||||
|
} else {
|
||||||
|
//AsyncChannel set up failure, ignore
|
||||||
|
Log.e(TAG, "Failed to establish AsyncChannel connection");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WifiManager.CMD_WPS_COMPLETED:
|
||||||
|
WpsResult result = (WpsResult) msg.obj;
|
||||||
|
if (result == null) break;
|
||||||
|
AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity())
|
||||||
|
.setTitle(R.string.wifi_wps_setup_title)
|
||||||
|
.setPositiveButton(android.R.string.ok, null);
|
||||||
|
switch (result.status) {
|
||||||
|
case FAILURE:
|
||||||
|
dialog.setMessage(R.string.wifi_wps_failed);
|
||||||
|
dialog.show();
|
||||||
|
break;
|
||||||
|
case IN_PROGRESS:
|
||||||
|
dialog.setMessage(R.string.wifi_wps_in_progress);
|
||||||
|
dialog.show();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (result.pin != null) {
|
||||||
|
dialog.setMessage(getResources().getString(
|
||||||
|
R.string.wifi_wps_pin_output, result.pin));
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//TODO: more connectivity feedback
|
||||||
|
default:
|
||||||
|
//Ignore
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renames/replaces "Next" button when appropriate. "Next" button usually exists in
|
* Renames/replaces "Next" button when appropriate. "Next" button usually exists in
|
||||||
* Wifi setup screens, not in usual wifi settings screen.
|
* Wifi setup screens, not in usual wifi settings screen.
|
||||||
@@ -631,27 +680,7 @@ public class WifiSettings extends SettingsPreferenceFragment
|
|||||||
case WifiConfigController.WPS_PBC:
|
case WifiConfigController.WPS_PBC:
|
||||||
case WifiConfigController.WPS_PIN_FROM_ACCESS_POINT:
|
case WifiConfigController.WPS_PIN_FROM_ACCESS_POINT:
|
||||||
case WifiConfigController.WPS_PIN_FROM_DEVICE:
|
case WifiConfigController.WPS_PIN_FROM_DEVICE:
|
||||||
WpsResult result = mWifiManager.startWps(configController.getWpsConfig());
|
mWifiManager.startWps(configController.getWpsConfig());
|
||||||
AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity())
|
|
||||||
.setTitle(R.string.wifi_wps_setup_title)
|
|
||||||
.setPositiveButton(android.R.string.ok, null);
|
|
||||||
switch (result.status) {
|
|
||||||
case FAILURE:
|
|
||||||
dialog.setMessage(R.string.wifi_wps_failed);
|
|
||||||
dialog.show();
|
|
||||||
break;
|
|
||||||
case IN_PROGRESS:
|
|
||||||
dialog.setMessage(R.string.wifi_wps_in_progress);
|
|
||||||
dialog.show();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (networkSetup == WifiConfigController.WPS_PIN_FROM_DEVICE) {
|
|
||||||
dialog.setMessage(getResources().getString(R.string.wifi_wps_pin_output,
|
|
||||||
result.pin));
|
|
||||||
dialog.show();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case WifiConfigController.MANUAL:
|
case WifiConfigController.MANUAL:
|
||||||
final WifiConfiguration config = configController.getConfig();
|
final WifiConfiguration config = configController.getConfig();
|
||||||
|
@@ -26,6 +26,7 @@ import android.net.wifi.WifiConfiguration;
|
|||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
import android.preference.PreferenceCategory;
|
import android.preference.PreferenceCategory;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -41,6 +42,8 @@ import android.widget.Button;
|
|||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.android.internal.util.AsyncChannel;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -143,6 +146,7 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
|||||||
// There's no button here enabling wifi network, so we need to enable it without
|
// There's no button here enabling wifi network, so we need to enable it without
|
||||||
// users' request.
|
// users' request.
|
||||||
mWifiManager.setWifiEnabled(true);
|
mWifiManager.setWifiEnabled(true);
|
||||||
|
mWifiManager.asyncConnect(this, new WifiServiceHandler());
|
||||||
|
|
||||||
mWifiSettings =
|
mWifiSettings =
|
||||||
(WifiSettings)getFragmentManager().findFragmentById(R.id.wifi_setup_fragment);
|
(WifiSettings)getFragmentManager().findFragmentById(R.id.wifi_setup_fragment);
|
||||||
@@ -189,6 +193,25 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
|||||||
showScanningStatus();
|
showScanningStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class WifiServiceHandler extends Handler {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED:
|
||||||
|
if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
|
||||||
|
//AsyncChannel in msg.obj
|
||||||
|
} else {
|
||||||
|
//AsyncChannel set up failure, ignore
|
||||||
|
Log.e(TAG, "Failed to establish AsyncChannel connection");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//Ignore
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void restoreFirstButtonVisibilityState() {
|
private void restoreFirstButtonVisibilityState() {
|
||||||
showDefaultTitle();
|
showDefaultTitle();
|
||||||
mAddNetworkButton.setVisibility(View.VISIBLE);
|
mAddNetworkButton.setVisibility(View.VISIBLE);
|
||||||
|
Reference in New Issue
Block a user