Skip to content

Commit

Permalink
Merge pull request #234 from NordicSemiconductor/dev
Browse files Browse the repository at this point in the history
Release nRF Mesh v2.0.3
  • Loading branch information
roshanrajaratnam committed Aug 8, 2019
2 parents 9f14e1e + 91391ad commit fd90df1
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 78 deletions.
6 changes: 3 additions & 3 deletions Example/nrf-mesh/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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());
}
}
}

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Example/nrf-mesh/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<string name="title_elements">Elements</string>
<string name="title_node_element_details">Element Details</string>

<string name="generate_new_key">Generate New key</string>
<string name="generate_new_key">Generate Key</string>

<string name="title_network_name">Network Name</string>
<string name="summary_network_name">Enter a network name</string>
Expand Down
6 changes: 3 additions & 3 deletions android-nrf-mesh-library/meshprovisioner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ android {
defaultConfig {
minSdkVersion 18
targetSdkVersion 29
versionCode 50
versionName "2.0.2"
versionCode 51
versionName "2.0.3"

javaCompileOptions {
annotationProcessorOptions {
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,37 +183,59 @@ 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);
if (isNetKeyExists(newNetKey)) {
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;
}

/**
Expand Down Expand Up @@ -354,59 +376,90 @@ 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.validateAppKeyInput(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 {
for (NetworkKey netKey : netKeys) {
if (netKey.getKeyIndex() == key.getKeyIndex()) {
NetworkKey netKey = null;
for (int i = 0; i < netKeys.size(); i++) {
final NetworkKey tempKey = netKeys.get(i);
if (tempKey.getKeyIndex() == key.getKeyIndex()) {
netKey = (NetworkKey) key;
notifyNetKeyUpdated(netKey);
return true;
netKeys.set(i, netKey);
break;
}
}
if (netKey != null) {
notifyNetKeyUpdated(netKey);
return true;
}
}
return false;
}
Expand Down
Loading

0 comments on commit fd90df1

Please sign in to comment.