We have been using forget() to prevent auto-reconnection when the user hits back to Wifi setup. This has the side effect of forgetting networks, which is undesirable especially for password protected APs. The new mechanism keeps a flag on whether the user has selected a connection. Only auto-advance if the user has picked a network and there is a valid WiFi connection. The new EXTRA_REQUIRE_USER_SELECTION can specify whether a user selection is required initially. That is, whether to auto finish if the system connected to a network without user input. The default is false so WiFi can be skipped if the user started setup wizard with a valid WiFi connection (e.g. after System Update). Note that a user selection is always required when the user goes back from the next screen. Since the new AP dialog does not have a connect button, the SKIP button in the navigation bar also changes to NEXT when there is a valid WiFi connection, so the user can hit NEXT if they decided not to change the network. Bug: 15333554 Bug: 15999487 Change-Id: I98e935b8e09e470a0c49c44bc299bb2eced98634
137 lines
4.9 KiB
Java
137 lines
4.9 KiB
Java
/*
|
|
* Copyright (C) 2014 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;
|
|
|
|
import android.content.Intent;
|
|
import android.content.res.TypedArray;
|
|
import android.net.wifi.WifiConfiguration;
|
|
import android.os.Bundle;
|
|
import android.view.LayoutInflater;
|
|
import android.view.Menu;
|
|
import android.view.MenuItem;
|
|
import android.view.View;
|
|
import android.view.View.OnClickListener;
|
|
import android.view.ViewGroup;
|
|
import android.widget.ImageButton;
|
|
import android.widget.ListView;
|
|
import android.widget.PopupMenu;
|
|
import android.widget.PopupMenu.OnMenuItemClickListener;
|
|
import android.widget.TextView;
|
|
|
|
import com.android.settings.R;
|
|
|
|
/**
|
|
* This customized version of WifiSettings is shown to the user only during Setup Wizard. Menu
|
|
* selections are limited, clicking on an access point will auto-advance to the next screen (once
|
|
* connected), and, if the user opts to skip ahead without a wifi connection, a warning message
|
|
* alerts of possible carrier data charges or missing software updates.
|
|
*/
|
|
public class WifiSettingsForSetupWizard extends WifiSettings {
|
|
|
|
private static final String TAG = "WifiSettingsForSetupWizard";
|
|
|
|
// show a text regarding data charges when wifi connection is required during setup wizard
|
|
protected static final String EXTRA_SHOW_WIFI_REQUIRED_INFO = "wifi_show_wifi_required_info";
|
|
|
|
@Override
|
|
public View onCreateView(final LayoutInflater inflater, ViewGroup container,
|
|
Bundle savedInstanceState) {
|
|
|
|
final View view = inflater.inflate(R.layout.setup_preference, container, false);
|
|
|
|
final ListView list = (ListView) view.findViewById(android.R.id.list);
|
|
final View title = view.findViewById(R.id.title);
|
|
if (title == null) {
|
|
final View header = inflater.inflate(R.layout.setup_wizard_header, list, false);
|
|
list.addHeaderView(header, null, false);
|
|
}
|
|
|
|
final View other = inflater.inflate(R.layout.setup_wifi_add_network, list, false);
|
|
list.addFooterView(other, null, true);
|
|
other.setOnClickListener(new OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
if (mWifiManager.isWifiEnabled()) {
|
|
onAddNetworkPressed();
|
|
}
|
|
}
|
|
});
|
|
|
|
final Intent intent = getActivity().getIntent();
|
|
if (intent.getBooleanExtra(EXTRA_SHOW_WIFI_REQUIRED_INFO, false)) {
|
|
view.findViewById(R.id.wifi_required_info).setVisibility(View.VISIBLE);
|
|
}
|
|
|
|
return view;
|
|
}
|
|
|
|
@Override
|
|
public void onActivityCreated(Bundle savedInstanceState) {
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
|
getView().setSystemUiVisibility(
|
|
View.STATUS_BAR_DISABLE_HOME |
|
|
View.STATUS_BAR_DISABLE_RECENT |
|
|
View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS |
|
|
View.STATUS_BAR_DISABLE_CLOCK);
|
|
|
|
if (hasNextButton()) {
|
|
getNextButton().setVisibility(View.GONE);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void registerForContextMenu(View view) {
|
|
// Suppressed during setup wizard
|
|
}
|
|
|
|
@Override
|
|
/* package */ WifiEnabler createWifiEnabler() {
|
|
// Not shown during setup wizard
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
/* package */ void addOptionsMenuItems(Menu menu) {
|
|
final boolean wifiIsEnabled = mWifiManager.isWifiEnabled();
|
|
final TypedArray ta = getActivity().getTheme()
|
|
.obtainStyledAttributes(new int[] {R.attr.ic_wps});
|
|
menu.add(Menu.NONE, MENU_ID_WPS_PBC, 0, R.string.wifi_menu_wps_pbc)
|
|
.setIcon(ta.getDrawable(0))
|
|
.setEnabled(wifiIsEnabled)
|
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
|
menu.add(Menu.NONE, MENU_ID_ADD_NETWORK, 0, R.string.wifi_add_network)
|
|
.setEnabled(wifiIsEnabled)
|
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
|
ta.recycle();
|
|
}
|
|
|
|
@Override
|
|
protected void connect(final WifiConfiguration config) {
|
|
WifiSetupActivity activity = (WifiSetupActivity) getActivity();
|
|
activity.networkSelected();
|
|
super.connect(config);
|
|
}
|
|
|
|
@Override
|
|
protected void connect(final int networkId) {
|
|
WifiSetupActivity activity = (WifiSetupActivity) getActivity();
|
|
activity.networkSelected();
|
|
super.connect(networkId);
|
|
}
|
|
}
|