Refactor ConfigureWifiSettings for better testing

Fix: 34205150
Test: make -j40 RunSettingsRoboTests
Change-Id: I7a8a0c89c087365fb50f3a9edd2cf64b2dda647c
This commit is contained in:
Fan Zhang
2017-01-10 15:22:56 -08:00
parent c8cae26b21
commit 925f23244a
13 changed files with 960 additions and 204 deletions

View File

@@ -0,0 +1,76 @@
/*
* Copyright (C) 2017 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.Context;
import android.net.wifi.WifiManager;
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.text.TextUtils;
import com.android.settings.core.PreferenceController;
/**
* {@link PreferenceController} that controls whether we should notify user when open network is
* available.
*/
public class NotifyOpenNetworksPreferenceController extends PreferenceController {
private static final String KEY_NOTIFY_OPEN_NETWORKS = "notify_open_networks";
private final WifiManager mWifiManager;
public NotifyOpenNetworksPreferenceController(Context context, WifiManager wifiManager) {
super(context);
mWifiManager = wifiManager;
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (!TextUtils.equals(preference.getKey(), KEY_NOTIFY_OPEN_NETWORKS)) {
return false;
}
if (!(preference instanceof SwitchPreference)) {
return false;
}
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
((SwitchPreference) preference).isChecked() ? 1 : 0);
return true;
}
@Override
public String getPreferenceKey() {
return KEY_NOTIFY_OPEN_NETWORKS;
}
@Override
public void updateState(Preference preference) {
if (!(preference instanceof SwitchPreference)) {
return;
}
final SwitchPreference notifyOpenNetworks = (SwitchPreference) preference;
notifyOpenNetworks.setChecked(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0) == 1);
notifyOpenNetworks.setEnabled(mWifiManager.isWifiEnabled());
}
}