From 244268b98d37d81f0bfe2ad470542e334201c7d8 Mon Sep 17 00:00:00 2001 From: changbetty Date: Sun, 25 Apr 2021 14:33:36 +0800 Subject: [PATCH] Add TextWatcher for the ip config field [Root Cause] We always check the valid for the ip config field. If the text is empty we will set the default for user even if user deleted the values. [Solution] Add TextWatcher for the ip config field (include gateway/network prefix length/dns1). If the text change and the text is empty, we will set the hint for user, not the default. Bug: 179331339 Test: manual test make RunSettingsRoboTests ROBOTEST_FILTER=WifiConfigController2 Change-Id: I1976200c70ae768285a44aff5df54ced00a78171 --- .../settings/wifi/WifiConfigController2.java | 48 +++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/wifi/WifiConfigController2.java b/src/com/android/settings/wifi/WifiConfigController2.java index 9f3b1a711d9..1e0670788ad 100644 --- a/src/com/android/settings/wifi/WifiConfigController2.java +++ b/src/com/android/settings/wifi/WifiConfigController2.java @@ -1339,12 +1339,13 @@ public class WifiConfigController2 implements TextWatcher, mIpAddressView = (TextView) mView.findViewById(R.id.ipaddress); mIpAddressView.addTextChangedListener(this); mGatewayView = (TextView) mView.findViewById(R.id.gateway); - mGatewayView.addTextChangedListener(this); + mGatewayView.addTextChangedListener(getIpConfigFieldsTextWatcher(mGatewayView)); mNetworkPrefixLengthView = (TextView) mView.findViewById( R.id.network_prefix_length); - mNetworkPrefixLengthView.addTextChangedListener(this); + mNetworkPrefixLengthView.addTextChangedListener( + getIpConfigFieldsTextWatcher(mNetworkPrefixLengthView)); mDns1View = (TextView) mView.findViewById(R.id.dns1); - mDns1View.addTextChangedListener(this); + mDns1View.addTextChangedListener(getIpConfigFieldsTextWatcher(mDns1View)); mDns2View = (TextView) mView.findViewById(R.id.dns2); mDns2View.addTextChangedListener(this); } @@ -1562,6 +1563,47 @@ public class WifiConfigController2 implements TextWatcher, // work done in afterTextChanged } + /* TODO: Add more test cases for this TextWatcher b/186368002 + * This TextWatcher is for IP config fields (Gateway/Network Prefix Length/DNS1) to prevent + * to rewrite the value in these columns that the user wanted to change after they saved. + * When afterTextChanged we will check the text is empty or not then set the Hint for user. + */ + private TextWatcher getIpConfigFieldsTextWatcher(final TextView view) { + return new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + // work done in afterTextChanged + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + // work done in afterTextChanged + } + + @Override + public void afterTextChanged(Editable s) { + if (s.length() == 0) { + if (view.getId() == R.id.gateway) { + mGatewayView.setHint(R.string.wifi_gateway_hint); + } else if (view.getId() == R.id.network_prefix_length) { + mNetworkPrefixLengthView.setHint(R.string.wifi_network_prefix_length_hint); + } else if (view.getId() == R.id.dns1) { + mDns1View.setHint(R.string.wifi_dns1_hint); + } + Button submit = mConfigUi.getSubmitButton(); + if (submit == null) return; + + submit.setEnabled(false); + } else { + ThreadUtils.postOnMainThread(() -> { + showWarningMessagesIfAppropriate(); + enableSubmitIfAppropriate(); + }); + } + } + }; + } + @Override public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { if (textView == mPasswordView) {