Fix "Add Network" button on SavedAccessPoints page.

The old onSubmit was a no-op. It now correctly pipes onSubmit to
WifiManager#save() with the new WifiConfiguration. On successful save,
it displays the new network in the list, and on failure, it displays a
toast indicating that the save action failed. Adds a test for the
WifiDialog behaviors on this page.

Bug: 66177765
Test: make RunSettingsRoboTests, manual - tested with Wifi enabled and
disabled, and with networks that were visible and not.
Change-Id: I27446aa49bc9efaf1ea1d6c6158928b62ce01ba2
Merged-In: I27446aa49bc9efaf1ea1d6c6158928b62ce01ba2
This commit is contained in:
Eric Schwarzenbach
2017-09-20 16:34:23 -07:00
parent 6fe50e7224
commit c069669ddf
2 changed files with 107 additions and 1 deletions

View File

@@ -17,6 +17,7 @@
package com.android.settings.wifi;
import android.annotation.Nullable;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
@@ -28,6 +29,7 @@ import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.util.Log;
import android.widget.Toast;
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
@@ -78,6 +80,22 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
}
};
private final WifiManager.ActionListener mSaveListener = new WifiManager.ActionListener() {
@Override
public void onSuccess() {
initPreferences();
}
@Override
public void onFailure(int reason) {
Activity activity = getActivity();
if (activity != null) {
Toast.makeText(activity,
R.string.wifi_failed_save_message,
Toast.LENGTH_SHORT).show();
}
}
};
private WifiDialog mDialog;
private WifiManager mWifiManager;
private AccessPoint mDlgAccessPoint;
@@ -251,7 +269,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
@Override
public void onSubmit(WifiDialog dialog) {
// Ignored
mWifiManager.save(dialog.getController().getConfig(), mSaveListener);
}
@Override