From d156ee8fa57201201bcd3ac16579d4eb3eae17d7 Mon Sep 17 00:00:00 2001 From: "Rajaratnam, Roshan" Date: Wed, 7 Aug 2019 13:19:09 +0200 Subject: [PATCH 1/8] Scanner improvements, when enabling and disabling bluetooth. --- .../nrfmeshprovisioner/ble/ReconnectActivity.java | 3 ++- .../nrfmeshprovisioner/ble/ScannerActivity.java | 12 ++++++++---- .../viewmodels/ScannerRepository.java | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/ble/ReconnectActivity.java b/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/ble/ReconnectActivity.java index 7f40e43ca..c9593fffc 100644 --- a/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/ble/ReconnectActivity.java +++ b/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/ble/ReconnectActivity.java @@ -31,6 +31,7 @@ import javax.inject.Inject; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; @@ -96,7 +97,7 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) { } @Override - public boolean onOptionsItemSelected(final MenuItem item) { + public boolean onOptionsItemSelected(@NonNull final MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); return true; diff --git a/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/ble/ScannerActivity.java b/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/ble/ScannerActivity.java index df61d61ff..99e080886 100644 --- a/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/ble/ScannerActivity.java +++ b/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/ble/ScannerActivity.java @@ -60,6 +60,7 @@ public class ScannerActivity extends AppCompatActivity implements Injectable, DevicesAdapter.OnItemClickListener { + private static final int REQUEST_ENABLE_BLUETOOTH = 1021; // random number private static final int REQUEST_ACCESS_COARSE_LOCATION = 1022; // random number @Inject @@ -120,14 +121,13 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) { adapter.setOnItemClickListener(this); recyclerViewDevices.setAdapter(adapter); - + mViewModel.getScannerRepository().getScannerState().observe(this, this::startScan); } @Override protected void onStart() { super.onStart(); mViewModel.getScannerRepository().getScannerState().startScanning(); - mViewModel.getScannerRepository().getScannerState().observe(this, this::startScan); } @Override @@ -137,7 +137,7 @@ protected void onStop() { } @Override - public boolean onOptionsItemSelected(final MenuItem item) { + public boolean onOptionsItemSelected(@NonNull final MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); return true; @@ -163,6 +163,10 @@ protected void onActivityResult(final int requestCode, final int resultCode, fin if (resultCode == RESULT_OK) { finish(); } + } else if (requestCode == REQUEST_ENABLE_BLUETOOTH) { + if (resultCode == RESULT_OK) { + startScan(mViewModel.getScannerRepository().getScannerState()); + } } } @@ -200,7 +204,7 @@ public void onEnableLocationClicked() { @OnClick(R.id.action_enable_bluetooth) public void onEnableBluetoothClicked() { final Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); - startActivity(enableIntent); + startActivityForResult(enableIntent, REQUEST_ENABLE_BLUETOOTH); } @OnClick(R.id.action_grant_location_permission) diff --git a/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/viewmodels/ScannerRepository.java b/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/viewmodels/ScannerRepository.java index a5ecec6ff..83d59c261 100644 --- a/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/viewmodels/ScannerRepository.java +++ b/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/viewmodels/ScannerRepository.java @@ -137,6 +137,7 @@ public void onReceive(final Context context, final Intent intent) { switch (state) { case BluetoothAdapter.STATE_ON: mScannerLiveData.bluetoothEnabled(); + mScannerLiveData.startScanning(); break; case BluetoothAdapter.STATE_TURNING_OFF: case BluetoothAdapter.STATE_OFF: From d98f483e84ed3ea9cf9afd48446f200a01c4f92b Mon Sep 17 00:00:00 2001 From: "Rajaratnam, Roshan" Date: Thu, 8 Aug 2019 09:32:57 +0200 Subject: [PATCH 2/8] Fix editing network keys --- .../keys/EditNetKeyActivity.java | 5 +- .../keys/dialogs/DialogFragmentAddKey.java | 2 +- .../meshprovisioner/ApplicationKey.java | 1 + .../meshprovisioner/BaseMeshNetwork.java | 75 +++++++++++++------ .../android/meshprovisioner/MeshKey.java | 4 +- .../android/meshprovisioner/NetworkKey.java | 1 + .../utils/MeshParserUtils.java | 16 ++-- 7 files changed, 68 insertions(+), 36 deletions(-) diff --git a/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/keys/EditNetKeyActivity.java b/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/keys/EditNetKeyActivity.java index b80091325..4d8912792 100644 --- a/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/keys/EditNetKeyActivity.java +++ b/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/keys/EditNetKeyActivity.java @@ -124,7 +124,7 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) { } @Override - public boolean onOptionsItemSelected(final MenuItem item) { + public boolean onOptionsItemSelected(@NonNull final MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); return true; @@ -137,7 +137,8 @@ public boolean onKeyNameUpdated(@NonNull final String name) { if (networkKey != null) { final MeshNetwork network = mViewModel.getMeshManagerApi().getMeshNetwork(); if (network != null) { - return network.updateNetKey(networkKey, name); + networkKey.setName(name); + return network.updateNetKey(networkKey); } } return false; diff --git a/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/keys/dialogs/DialogFragmentAddKey.java b/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/keys/dialogs/DialogFragmentAddKey.java index 33a60abab..defacf881 100644 --- a/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/keys/dialogs/DialogFragmentAddKey.java +++ b/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/keys/dialogs/DialogFragmentAddKey.java @@ -131,7 +131,7 @@ public void afterTextChanged(final Editable s) { private boolean validateInput(final String appKey) { try { - if(MeshParserUtils.validateAppKeyInput(appKey)) { + if(MeshParserUtils.validateKeyInput(appKey)) { return true; } } catch (IllegalArgumentException ex) { diff --git a/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/ApplicationKey.java b/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/ApplicationKey.java index 5f686912a..394588d0a 100644 --- a/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/ApplicationKey.java +++ b/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/ApplicationKey.java @@ -108,6 +108,7 @@ public final boolean equals(@Nullable final Object obj) { return false; } + @NonNull @Override public ApplicationKey clone() throws CloneNotSupportedException { return (ApplicationKey) super.clone(); diff --git a/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/BaseMeshNetwork.java b/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/BaseMeshNetwork.java index 06605ede3..1d73e195d 100644 --- a/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/BaseMeshNetwork.java +++ b/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/BaseMeshNetwork.java @@ -183,37 +183,61 @@ private int getAvailableNetKeyIndex() { } /** - * Update a network key in the mesh network. + * Update a network key with the given 16-byte hexadecimal string in the mesh network. * * @param networkKey Network key + * @param newNetKey 16-byte hexadecimal string */ - public boolean updateNetKey(@NonNull final NetworkKey networkKey) throws IllegalArgumentException { - final int keyIndex = networkKey.getKeyIndex(); - final NetworkKey key = getNetKey(keyIndex); - if (isKeyInUse(key)) { - //We check if the contents of the key are the same - //This will return true only if the key index and the key are the same - if (key.equals(networkKey)) { - return updateMeshKey(networkKey); + public boolean updateNetKey(@NonNull final NetworkKey networkKey, @NonNull final String newNetKey) throws IllegalArgumentException { + if (MeshParserUtils.validateKeyInput(newNetKey)) { + final byte[] key = MeshParserUtils.toByteArray(newNetKey); + for (final NetworkKey netKey : netKeys) { + if (Arrays.equals(netKey.getKey(), key)) { + throw new IllegalArgumentException("Net key already in use"); + } + } + + final int keyIndex = networkKey.getKeyIndex(); + final NetworkKey netKey = getNetKey(keyIndex); + if (!isKeyInUse(netKey)) { + //We check if the contents of the key are the same + //This will return true only if the key index and the key are the same + if (netKey.equals(networkKey)) { + netKey.setKey(key); + return updateMeshKey(netKey); + } else { + return false; + } } else { throw new IllegalArgumentException("Unable to update a network key that's already in use"); } - } else { - return updateMeshKey(networkKey); } + return false; } /** - * Updates an network key in the mesh network with a new key. + * Update a network key in the mesh network. * - * @param key {@link ApplicationKey} - * @param appKey Application key + * @param networkKey Network key + * @throws IllegalArgumentException if the key is already in use */ - public boolean updateNetKey(@NonNull final NetworkKey key, @NonNull final String appKey) throws IllegalArgumentException { - if (MeshParserUtils.validateAppKeyInput(appKey)) { - return updateNetKey(key); + public boolean updateNetKey(@NonNull final NetworkKey networkKey) throws IllegalArgumentException { + final int keyIndex = networkKey.getKeyIndex(); + final NetworkKey key = getNetKey(keyIndex); + //We check if the contents of the key are the same + //This will return true only if the key index and the key are the same + if (key.equals(networkKey)) { + return updateMeshKey(networkKey); + } else { + //If the keys are not the same we check if its in use before updating the key + if (!isKeyInUse(key)) { + //We check if the contents of the key are the same + //This will return true only if the key index and the key are the same + return updateMeshKey(networkKey); + } else { + throw new IllegalArgumentException("Unable to update a network key that's already in use"); + } } - return false; } /** @@ -384,7 +408,7 @@ public boolean updateAppKey(@NonNull final ApplicationKey appKey) throws Illegal * @param appKey Application key */ public boolean updateAppKey(@NonNull final ApplicationKey key, @NonNull final String appKey) throws IllegalArgumentException { - if (MeshParserUtils.validateAppKeyInput(appKey)) { + if (MeshParserUtils.validateKeyInput(appKey)) { return updateAppKey(key); } return false; @@ -400,13 +424,18 @@ private boolean updateMeshKey(@NonNull final MeshKey key) { } } } else { - for (NetworkKey netKey : netKeys) { + NetworkKey netKey = null; + for (int i = 0; i < netKeys.size(); i++) { + netKey = netKeys.get(i); if (netKey.getKeyIndex() == key.getKeyIndex()) { - netKey = (NetworkKey) key; - notifyNetKeyUpdated(netKey); - return true; + netKeys.set(i, (NetworkKey) key); + break; } } + if (netKey != null) { + notifyNetKeyUpdated(netKey); + return true; + } } return false; } diff --git a/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/MeshKey.java b/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/MeshKey.java index 9d80c316c..a04b5aba6 100644 --- a/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/MeshKey.java +++ b/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/MeshKey.java @@ -108,12 +108,11 @@ public byte[] getKey() { * Sets a network key. * *

- * In order to change the key call {@link BaseMeshNetwork#updateNetKey(NetworkKey) or {@link BaseMeshNetwork#updateNetKey(NetworkKey)}} + * In order to change the key call {@link BaseMeshNetwork#updateNetKey(NetworkKey, String)} or {@link BaseMeshNetwork#updateAppKey(ApplicationKey, String)})}} *

* * @param key 16-byte network key */ - @RestrictTo(RestrictTo.Scope.LIBRARY) public void setKey(@NonNull final byte[] key) { this.key = key; } @@ -173,6 +172,7 @@ public boolean equals(@Nullable final Object obj) { return false; } + @NonNull @Override public MeshKey clone() throws CloneNotSupportedException { return (MeshKey) super.clone(); diff --git a/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/NetworkKey.java b/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/NetworkKey.java index 8b593f190..2299a737d 100644 --- a/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/NetworkKey.java +++ b/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/NetworkKey.java @@ -168,6 +168,7 @@ public void setTimestamp(final long timestamp) { public @interface KeyRefreshPhases { } + @NonNull @Override public NetworkKey clone() throws CloneNotSupportedException { return (NetworkKey) super.clone(); diff --git a/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/utils/MeshParserUtils.java b/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/utils/MeshParserUtils.java index 79d060ab1..24271ea98 100644 --- a/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/utils/MeshParserUtils.java +++ b/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/utils/MeshParserUtils.java @@ -253,17 +253,17 @@ public static boolean validateIvIndexInput(final Context context, final Integer } /** - * Validates the app key input + * Validates the key input * - * @param appKey App key - * @return true if the Network Key is a valid value + * @param key key + * @return true if the Key is a valid value * @throws IllegalArgumentException in case of an invalid was entered as an input and the message containing the error */ - public static boolean validateAppKeyInput(@NonNull final String appKey) throws IllegalArgumentException { - if (TextUtils.isEmpty(appKey)) { - throw new IllegalArgumentException("App key cannot be empty!"); - } else if (!appKey.matches(PATTERN_KEY)) { - throw new IllegalArgumentException("The key must be a 32-character hexadecimal string!"); + public static boolean validateKeyInput(@NonNull final String key) throws IllegalArgumentException { + if (TextUtils.isEmpty(key)) { + throw new IllegalArgumentException("Key cannot be empty!"); + } else if (!key.matches(PATTERN_KEY)) { + throw new IllegalArgumentException("key must be a 32-character hexadecimal string!"); } return true; From 250d4747fff4099475572606f417d84da954a931 Mon Sep 17 00:00:00 2001 From: "Rajaratnam, Roshan" Date: Thu, 8 Aug 2019 09:56:40 +0200 Subject: [PATCH 3/8] Fix editing application keys --- .../meshprovisioner/BaseMeshNetwork.java | 90 ++++++++++++------- 1 file changed, 57 insertions(+), 33 deletions(-) diff --git a/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/BaseMeshNetwork.java b/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/BaseMeshNetwork.java index 1d73e195d..43d16b40d 100644 --- a/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/BaseMeshNetwork.java +++ b/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/BaseMeshNetwork.java @@ -191,10 +191,8 @@ private int getAvailableNetKeyIndex() { public boolean updateNetKey(@NonNull final NetworkKey networkKey, @NonNull final String newNetKey) throws IllegalArgumentException { if (MeshParserUtils.validateKeyInput(newNetKey)) { final byte[] key = MeshParserUtils.toByteArray(newNetKey); - for (final NetworkKey netKey : netKeys) { - if (Arrays.equals(netKey.getKey(), key)) { - throw new IllegalArgumentException("Net key already in use"); - } + if (isNetKeyExists(newNetKey)) { + throw new IllegalArgumentException("Net key already in use"); } final int keyIndex = networkKey.getKeyIndex(); @@ -378,57 +376,83 @@ private boolean isAppKeyExists(@NonNull final byte[] appKey) { } /** - * Updates an app key in the mesh network. + * Updates an app key with a given key in the mesh network. * - * @param appKey {@link ApplicationKey} - * returns true if succeeded and false otherwise - * @throws IllegalArgumentException if the key is in use + * @param applicationKey {@link ApplicationKey} + * @param newAppKey Application key */ - public boolean updateAppKey(@NonNull final ApplicationKey appKey) throws IllegalArgumentException { - final int keyIndex = appKey.getKeyIndex(); - final ApplicationKey key = getAppKey(keyIndex); - if (isKeyInUse(key)) { - // We check if the contents of the key are the same - // This will return true only if the key index and the key are the same - // If the user has changed the name of the key that would be updated - if (key.equals(appKey)) { - return updateMeshKey(appKey); + public boolean updateAppKey(@NonNull final ApplicationKey applicationKey, @NonNull final String newAppKey) throws IllegalArgumentException { + if (MeshParserUtils.validateKeyInput(newAppKey)) { + final byte[] key = MeshParserUtils.toByteArray(newAppKey); + if (isNetKeyExists(newAppKey)) { + throw new IllegalArgumentException("Net key already in use"); + } + + final int keyIndex = applicationKey.getKeyIndex(); + final ApplicationKey appKey = getAppKey(keyIndex); + if (!isKeyInUse(appKey)) { + //We check if the contents of the key are the same + //This will return true only if the key index and the key are the same + if (appKey.equals(applicationKey)) { + appKey.setKey(key); + return updateMeshKey(appKey); + } else { + return false; + } } else { - throw new IllegalArgumentException("Unable to update an app key that's already in use."); + throw new IllegalArgumentException("Unable to update a application key that's already in use"); } - } else { - return updateMeshKey(appKey); } + return false; } /** * Updates an app key in the mesh network. * - * @param key {@link ApplicationKey} - * @param appKey Application key + * @param applicationKey {@link ApplicationKey} + * @throws IllegalArgumentException if the key is already in use */ - public boolean updateAppKey(@NonNull final ApplicationKey key, @NonNull final String appKey) throws IllegalArgumentException { - if (MeshParserUtils.validateKeyInput(appKey)) { - return updateAppKey(key); + public boolean updateAppKey(@NonNull final ApplicationKey applicationKey) throws IllegalArgumentException { + final int keyIndex = applicationKey.getKeyIndex(); + final ApplicationKey key = getAppKey(keyIndex); + //We check if the contents of the key are the same + //This will return true only if the key index and the key are the same + if (key.equals(applicationKey)) { + return updateMeshKey(applicationKey); + } else { + //If the keys are not the same we check if its in use before updating the key + if (!isKeyInUse(key)) { + //We check if the contents of the key are the same + //This will return true only if the key index and the key are the same + return updateMeshKey(applicationKey); + } else { + throw new IllegalArgumentException("Unable to update a application key that's already in use"); + } } - return false; } private boolean updateMeshKey(@NonNull final MeshKey key) { if (key instanceof ApplicationKey) { - for (ApplicationKey appKey : appKeys) { - if (appKey.getKeyIndex() == key.getKeyIndex()) { + ApplicationKey appKey = null; + for (int i = 0; i < appKeys.size(); i++) { + final ApplicationKey tempKey = appKeys.get(i); + if (tempKey.getKeyIndex() == key.getKeyIndex()) { appKey = (ApplicationKey) key; - notifyAppKeyUpdated(appKey); - return true; + appKeys.set(i, appKey); + break; } } + if (appKey != null) { + notifyAppKeyUpdated(appKey); + return true; + } } else { NetworkKey netKey = null; for (int i = 0; i < netKeys.size(); i++) { - netKey = netKeys.get(i); - if (netKey.getKeyIndex() == key.getKeyIndex()) { - netKeys.set(i, (NetworkKey) key); + final NetworkKey tempKey = netKeys.get(i); + if (tempKey.getKeyIndex() == key.getKeyIndex()) { + netKey = (NetworkKey) key; + netKeys.set(i, netKey); break; } } From 358701ab6c21e804964d087825b7aefce6763f47 Mon Sep 17 00:00:00 2001 From: "Rajaratnam, Roshan" Date: Thu, 8 Aug 2019 09:59:06 +0200 Subject: [PATCH 4/8] Strings update --- Example/nrf-mesh/app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/nrf-mesh/app/src/main/res/values/strings.xml b/Example/nrf-mesh/app/src/main/res/values/strings.xml index d6ba642df..b09d29fae 100644 --- a/Example/nrf-mesh/app/src/main/res/values/strings.xml +++ b/Example/nrf-mesh/app/src/main/res/values/strings.xml @@ -106,7 +106,7 @@ Elements Element Details - Generate New key + Generate Key Network Name Enter a network name From 1427c6200d971f35dac94ffc9623965c1ea359c6 Mon Sep 17 00:00:00 2001 From: "Rajaratnam, Roshan" Date: Thu, 8 Aug 2019 10:50:41 +0200 Subject: [PATCH 5/8] Fix parcelable implementation for Publication Settings --- .../transport/PublicationSettings.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/transport/PublicationSettings.java b/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/transport/PublicationSettings.java index 23358b9c2..54b05f479 100644 --- a/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/transport/PublicationSettings.java +++ b/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/transport/PublicationSettings.java @@ -131,9 +131,11 @@ public PublicationSettings(final int publishAddress, private PublicationSettings(Parcel in) { publishAddress = in.readInt(); - final ParcelUuid parcelUuid = in.readParcelable(ParcelUuid.class.getClassLoader()); - if (parcelUuid != null) { - labelUUID = parcelUuid.getUuid(); + if (MeshAddress.isValidVirtualAddress(publishAddress)) { + final ParcelUuid parcelUuid = in.readParcelable(ParcelUuid.class.getClassLoader()); + if (parcelUuid != null) { + labelUUID = parcelUuid.getUuid(); + } } appKeyIndex = in.readInt(); credentialFlag = in.readInt() == 1; @@ -395,7 +397,9 @@ public int describeContents() { @Override public void writeToParcel(final Parcel dest, final int flags) { dest.writeInt(publishAddress); - dest.writeParcelable(new ParcelUuid(labelUUID), flags); + if (MeshAddress.isValidVirtualAddress(publishAddress)) { + dest.writeParcelable(new ParcelUuid(labelUUID), flags); + } dest.writeInt(appKeyIndex); dest.writeInt(credentialFlag ? 1 : 0); dest.writeInt(publishTtl); From 7427d434e7339d035872cce26d5480a12c3a7db4 Mon Sep 17 00:00:00 2001 From: "Rajaratnam, Roshan" Date: Thu, 8 Aug 2019 11:04:03 +0200 Subject: [PATCH 6/8] Clean up --- .../android/nrfmeshprovisioner/GroupControlsActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/GroupControlsActivity.java b/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/GroupControlsActivity.java index aa9476f16..8d1c748a7 100644 --- a/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/GroupControlsActivity.java +++ b/Example/nrf-mesh/app/src/main/java/no/nordicsemi/android/nrfmeshprovisioner/GroupControlsActivity.java @@ -171,7 +171,7 @@ public boolean onCreateOptionsMenu(final Menu menu) { } @Override - public boolean onOptionsItemSelected(final MenuItem item) { + public boolean onOptionsItemSelected(@NonNull final MenuItem item) { switch (item.getItemId()) { case android.R.id.home: onBackPressed(); From 324273c39f239f67e3e27ac4018951c08cf6e672 Mon Sep 17 00:00:00 2001 From: "Rajaratnam, Roshan" Date: Thu, 8 Aug 2019 11:04:36 +0200 Subject: [PATCH 7/8] Fix parcelable implementation for groups --- .../android/meshprovisioner/Group.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/Group.java b/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/Group.java index 2732cf8db..69c3ccb9f 100644 --- a/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/Group.java +++ b/android-nrf-mesh-library/meshprovisioner/src/main/java/no/nordicsemi/android/meshprovisioner/Group.java @@ -1,6 +1,7 @@ package no.nordicsemi.android.meshprovisioner; import android.os.Parcel; +import android.os.ParcelUuid; import android.os.Parcelable; import com.google.gson.annotations.Expose; @@ -202,19 +203,39 @@ protected Group(Parcel in) { id = in.readInt(); name = in.readString(); address = in.readInt(); + addressLabel = readVirtualLabelFromParcelable(in, address); parentAddress = in.readInt(); + parentAddressLabel = readVirtualLabelFromParcelable(in, parentAddress); meshUuid = in.readString(); } + private UUID readVirtualLabelFromParcelable(Parcel in, final int address) { + if (MeshAddress.isValidVirtualAddress(address)) { + final ParcelUuid parcelUuid = in.readParcelable(ParcelUuid.class.getClassLoader()); + if (parcelUuid != null) { + return parcelUuid.getUuid(); + } + } + return null; + } + @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(id); dest.writeString(name); dest.writeInt(address); + writeVirtualLabelToParcel(dest, flags, address, addressLabel); dest.writeInt(parentAddress); + writeVirtualLabelToParcel(dest, flags, parentAddress, parentAddressLabel); dest.writeString(meshUuid); } + private void writeVirtualLabelToParcel(Parcel dest, int flags, final int address, final UUID addressLabel) { + if (MeshAddress.isValidVirtualAddress(address)) { + dest.writeParcelable(new ParcelUuid(addressLabel), flags); + } + } + @Override public int describeContents() { return 0; From 91391adc94cd7965c4116573bd40d686db83f28c Mon Sep 17 00:00:00 2001 From: "Rajaratnam, Roshan" Date: Thu, 8 Aug 2019 11:17:19 +0200 Subject: [PATCH 8/8] Bump version code for release --- Example/nrf-mesh/app/build.gradle | 6 +++--- android-nrf-mesh-library/meshprovisioner/build.gradle | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Example/nrf-mesh/app/build.gradle b/Example/nrf-mesh/app/build.gradle index 19b5981a9..a0f29f492 100644 --- a/Example/nrf-mesh/app/build.gradle +++ b/Example/nrf-mesh/app/build.gradle @@ -30,8 +30,8 @@ android { applicationId "no.nordicsemi.android.nrfmeshprovisioner" minSdkVersion 18 targetSdkVersion 29 - versionCode 50 - versionName "2.0.2" + versionCode 51 + versionName "2.0.3" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled true vectorDrawables.useSupportLibrary = true @@ -65,7 +65,7 @@ dependencies { implementation 'androidx.test:runner:1.2.0' implementation 'androidx.appcompat:appcompat:1.0.2' - implementation 'com.google.android.material:material:1.1.0-alpha08' + implementation 'com.google.android.material:material:1.1.0-alpha09' implementation 'androidx.recyclerview:recyclerview:1.0.0' implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' diff --git a/android-nrf-mesh-library/meshprovisioner/build.gradle b/android-nrf-mesh-library/meshprovisioner/build.gradle index 812a6b648..c5a75fed8 100644 --- a/android-nrf-mesh-library/meshprovisioner/build.gradle +++ b/android-nrf-mesh-library/meshprovisioner/build.gradle @@ -29,8 +29,8 @@ android { defaultConfig { minSdkVersion 18 targetSdkVersion 29 - versionCode 50 - versionName "2.0.2" + versionCode 51 + versionName "2.0.3" javaCompileOptions { annotationProcessorOptions { @@ -59,7 +59,7 @@ android { dependencies { // Required -- JUnit 4 framework testImplementation 'junit:junit:4.12' - testImplementation 'org.mockito:mockito-core:2.6.3' + testImplementation 'org.mockito:mockito-core:2.18.0' androidTestImplementation 'org.mockito:mockito-android:2.6.3' implementation 'androidx.annotation:annotation:1.1.0' api 'no.nordicsemi.android:log:2.2.0'