Skip to content

Commit

Permalink
Merge pull request #511 from NordicSemiconductor/bugfix/provisioning-…
Browse files Browse the repository at this point in the history
…failure-#510

Provisioning failure
  • Loading branch information
roshanrajaratnam authored May 26, 2022
2 parents 8cac8fb + ed44f19 commit 8dea6a1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -91,16 +90,13 @@ public void afterTextChanged(final Editable s) {
final AlertDialog alertDialog = alertDialogBuilder.show();
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(v -> {
final String key = binding.textInput.getEditableText().toString().trim();
if (TextUtils.isEmpty(key)) {
((DialogFragmentOobPublicKeysListener) requireContext()).onPublicKeyAdded(MeshParserUtils.toByteArray(key));
dismiss();
} else if (validatePublicKeyInput(key)) {
try {
try {
if (validatePublicKeyInput(key)) {
((DialogFragmentOobPublicKeysListener) requireContext()).onPublicKeyAdded(MeshParserUtils.toByteArray(key));
dismiss();
} catch (IllegalArgumentException ex) {
binding.textInputLayout.setError(ex.getMessage());
}
} catch (IllegalArgumentException ex) {
binding.textInputLayout.setError(ex.getMessage());
}
});
alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setOnClickListener(v -> {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/dialog_fragment_public_key_input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,14 @@
android:textSize="16sp"/>

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textview.MaterialTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/skip_oob_public_key_summary"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/text_input_layout" />
</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -688,4 +688,5 @@
<string name="hint_public_key">Public key</string>
<string name="message_public_key">Enter the 128-character hexadecimal Public Key of the device.</string>
<string name="skip">skip</string>
<string name="skip_oob_public_key_summary">Skipping this process will mark the provisioned node and any Network Key associated with this node as insecure.</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ public static boolean validateKeyInput(@NonNull final String key) throws Illegal
* @throws IllegalArgumentException in case of an invalid was entered as an input and the message containing the error
*/
public static boolean validatePublicKeyInput(@NonNull final String key) throws IllegalArgumentException {
if (!key.matches(PATTERN_PUBLIC_KEY)) {
if (TextUtils.isEmpty(key)) {
throw new IllegalArgumentException("Key cannot be empty!");
} else if (!key.matches(PATTERN_PUBLIC_KEY)) {
throw new IllegalArgumentException("key must be a 128-character hexadecimal string!");
}

Expand Down

0 comments on commit 8dea6a1

Please sign in to comment.