Unverified Commit 857cb317 authored by Javier Guerra's avatar Javier Guerra Committed by GitHub

Merge pull request #8 from openconnectivity/develop

Merge develop into master
parents 543d902b 39db4e13
......@@ -27,40 +27,45 @@ IoTivity uses the [Android Java Coding Standard](https://source.android.com/setu
## Project Setup
The OTGC Android App uses the binary distribution of the [IoTivity Base Android API](#iotivity-base-android-api).
The OTGC Android App uses the binary distribution of the IoTivity-lite Android API.
IoTivity Base Android API is compiled for a minimum SDK of API 21: Android 5.0 (Lollipop), so OTGC Android App shall use the same value.
IoTivity-lite Android API is compiled for a minimum SDK of API 21: Android 5.0 (Lollipop), so OTGC Android App shall use the same value.
To import the IoTivity Base Android API Binary into the OTGC Android App project:
To import the IoTivity-lite Android API Binary into the OTGC Android App project:
1. From the File menu, select **New Module**.
2. In the **Choose Module Type** window, do the following:
1. Select **Import .JAR or .AAR Package**.
2. Click **Next**.
3. In the Create New Module window, click the **...** button to locate the .aar file.
4. Navigate to the <iotivity>/java/iotivity-android/base/build/outputs/aar directory and select the .aar file. In the example below, iotivity-base-armeabi-release.aar is selected.
5. Click **OK**. Then in the Create New Module window, click **Finish**.
6. In the Android Studio project view, right click the dependent module and select **Open Module Settings**.
7. In the Project Structure window, select the **Dependencies** tab.
8. Right click the **+** icon. From the dropdown, select **Module dependency**.
9. Select the iotivity-base-&lt;target_arch>-&lt;release> module from the list of available modules and click **OK**. In the example below, iotivity-base-armeabi-release.aar is selected.
10. In the Project Structure Window, click **OK**.
1. Go to &lt;iotivity-lite>/swig/iotivity-lite-java/libs.
2. Copy **iotivity-lite.jar** into &lt;otgc-android>/otgc/src/main/jniLibs.
3. Copy **libiotivity-lite-jni.so** into &lt;otgc-android>/otgc/src/main/&lt;target_arch>
where &lt;target_arch> is one of the following values: x86, x86_64, armeabi, armeabi-v7a, armeabi-v7a-hard or arm64-v8a.
Android Studio rebuilds the module, including the contents of the library module the next time the project or module is built. IoTivity Base Android APIs can now be used in the OTGC Android App project.
Android Studio loads the library, including the contents of the library module. IoTivity-lite Android APIs can now be used in the OTGC Android App project.
## Build
### IoTivity Base Android API
### IoTivity-lite Android API
The binary distribution of the IoTivity Base Android API (a .aar file) can be built following the [Android build instructions](https://wiki.iotivity.org/android_build_instructions). Once built, it can be found at:
The steps required to build the binary of the IoTivity-lite Android API is shown below:
<iotivity>/java/iotivity-android/build/outputs/aar/iotivity-base-<your arch>-<release mode>.aar
1. Change to the **swig** branch.
```
git checkout swig
```
2. Go to the **android** directory.
```
cd <iotivity-lite>/port/android
```
3. Execute the command to build the library.
```
make NDK_HOME=<ndk-directory> ANDROID_API=21 DEBUG=1 SECURE=1 IPV4=1 TCP=0 PKI=1 DYNAMIC=1 CLOUD=0 JAVA=1 IDD=1
```
Currently, this binary cannot be built using Windows but Linux as host system. The command required to build the binary is shown below.
scons TARGET_OS=android TARGET_ARCH=<target_arch>
where &lt;target_arch> is one of the following values: x86, x86_64, armeabi, armeabi-v7a, armeabi-v7a-hard or arm64-v8a.
Once built, the library can be found at:
```
<iotivity-lite>/swig/iotivity-lite-java/libs
```
## Testing
......
iotivity-lite @ 1b955e8d
Subproject commit a2722849a41b724fa759199f4f296ac1f85c96e6
Subproject commit 1b955e8d56e87d8fe7c18098f7df4740e9ce0867
......@@ -30,7 +30,7 @@ android {
minSdkVersion 21
targetSdkVersion 28
versionCode 13
versionName "2.0.5"
versionName "2.0.6"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
compileOptions {
......
......@@ -23,12 +23,18 @@
package org.openconnectivity.otgc.data.repository;
import org.iotivity.CborEncoder;
import org.iotivity.OCAceConnectionType;
import org.iotivity.OCAceResource;
import org.iotivity.OCAceWildcard;
import org.iotivity.OCClientResponse;
import org.iotivity.OCEndpoint;
import org.iotivity.OCEndpointUtil;
import org.iotivity.OCMain;
import org.iotivity.OCObt;
import org.iotivity.OCObtDeviceStatusHandler;
import org.iotivity.OCQos;
import org.iotivity.OCResponseHandler;
import org.iotivity.OCSecurityAce;
import org.iotivity.OCStatus;
import org.iotivity.OCUuid;
import org.iotivity.OCUuidUtil;
......@@ -61,8 +67,7 @@ public class AmsRepository {
public Single<OcAcl> getAcl(String endpoint, String deviceId) {
return Single.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid uuid = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, uuid);
......@@ -87,8 +92,7 @@ public class AmsRepository {
private Completable provisionAcl(String endpoint, String deviceId, OcAcl acl) {
return Completable.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid uuid = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, uuid);
......@@ -122,6 +126,42 @@ public class AmsRepository {
});
}
private Completable provisionAce(String deviceId, OCSecurityAce ace, List<String> verticalResources, long permission) {
return Completable.create(emitter -> {
int ret;
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
ret = setAceResources(ace, verticalResources);
if (ret == -1) {
String errorMsg = "ERROR: Could not create ACE resources";
Timber.e(errorMsg);
emitter.onError(new Exception(errorMsg));
}
OCObt.aceAddPermission(ace, (int)permission);
OCObtDeviceStatusHandler handler = (OCUuid uuid, int status) -> {
if (status >= 0) {
Timber.d("Successfully provisioned ACE to device " + OCUuidUtil.uuidToString(uuid));
emitter.onComplete();
} else {
String errorMsg = "ERROR provisioning ACE to device " + OCUuidUtil.uuidToString(uuid);
Timber.e(errorMsg);
emitter.onError(new Exception(errorMsg));
}
};
ret = OCObt.provisionAce(di, ace, handler);
if (ret >= 0) {
Timber.d("Successfully issued request to provision ACE");
} else {
String errorMsg = "ERROR issuing request to provision ACE";
Timber.e(errorMsg);
emitter.onError(new Exception(errorMsg));
}
});
}
public Completable provisionUuidAcl(String endpoint, String deviceId, String subjectId, List<String> verticalResources, long permission) {
OcAceSubject subject = new OcAceSubject();
subject.setType(OcAceSubjectType.UUID_TYPE);
......@@ -138,6 +178,19 @@ public class AmsRepository {
return provisionAcl(endpoint, deviceId, acl);
}
public Completable provisionUuidAce(String deviceId, String subjectId, List<String> verticalResources, long permission) {
OCUuid di = OCUuidUtil.stringToUuid(subjectId);
OCSecurityAce ace = OCObt.newAceForSubject(di);
if (ace == null) {
String errorMsg = "ERROR: Could not create ACE";
Timber.e(errorMsg);
return Completable.error(new Exception(errorMsg));
}
return provisionAce(deviceId, ace, verticalResources, permission);
}
public Completable provisionRoleAcl(String endpoint, String deviceId, String roleId, String roleAuthority, List<String> verticalResources, long permission) {
OcAceSubject subject = new OcAceSubject();
subject.setType(OcAceSubjectType.ROLE_TYPE);
......@@ -155,6 +208,17 @@ public class AmsRepository {
return provisionAcl(endpoint, deviceId, acl);
}
public Completable provisionRoleAce(String deviceId, String roleId, String roleAuthority, List<String> verticalResources, long permission) {
OCSecurityAce ace = OCObt.newAceForRole(roleId, roleAuthority);
if (ace == null) {
String errorMsg = "ERROR: Could not create ACE";
Timber.e(errorMsg);
return Completable.error(new Exception(errorMsg));
}
return provisionAce(deviceId, ace, verticalResources, permission);
}
public Completable provisionConntypeAcl(String endpoint, String deviceId, boolean isAuthCrypt, List<String> verticalResources, long permission) {
OcAceSubject subject = new OcAceSubject();
subject.setType(OcAceSubjectType.CONN_TYPE);
......@@ -171,10 +235,72 @@ public class AmsRepository {
return provisionAcl(endpoint, deviceId, acl);
}
public Completable provisionConntypeAce(String deviceId, boolean isAuthCrypt, List<String> verticalResources, long permission) {
OCSecurityAce ace = OCObt.newAceForConnection(isAuthCrypt ? OCAceConnectionType.OC_CONN_AUTH_CRYPT : OCAceConnectionType.OC_CONN_ANON_CLEAR);
if (ace == null) {
String errorMsg = "ERROR: Could not create ACE";
Timber.e(errorMsg);
return Completable.error(new Exception(errorMsg));
}
return provisionAce(deviceId, ace, verticalResources, permission);
}
public Completable provisionAuthWildcardAce(String deviceId) {
return Completable.create(emitter -> {
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCObtDeviceStatusHandler handler = (OCUuid uuid, int status) -> {
if (status >= 0) {
Timber.d("Successfully provisioned auth-crypt * ACE to device " + OCUuidUtil.uuidToString(uuid));
emitter.onComplete();
} else {
String errorMsg = "ERROR provisioning ACE to device " + OCUuidUtil.uuidToString(uuid);
Timber.e(errorMsg);
emitter.onError(new IOException(errorMsg));
}
};
int ret = OCObt.provisionAuthWildcardAce(di, handler);
if (ret >= 0) {
Timber.d("Successfully issued request to provision auth-crypt * ACE");
} else {
String errorMsg = "ERROR issuing request to provision auth-crypt * ACE";
Timber.e(errorMsg);
emitter.onError(new IOException(errorMsg));
}
});
}
public Completable provisionRoleWildcardAce(String deviceId, String roleId, String roleAuthority) {
return Completable.create(emitter -> {
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCObtDeviceStatusHandler handler = (OCUuid uuid, int status) -> {
if (status >= 0) {
Timber.d("Successfully provisioned role * ACE to device " + OCUuidUtil.uuidToString(uuid));
emitter.onComplete();
} else {
String errorMsg = "ERROR provisioning ACE to device " + OCUuidUtil.uuidToString(uuid);
Timber.e(errorMsg);
emitter.onError(new IOException(errorMsg));
}
};
int ret = OCObt.provisionRoleWildcardAce(di, roleId, roleAuthority, handler);
if (ret >= 0) {
Timber.d("Successfully issued request to provision role * ACE");
} else {
String errorMsg = "ERROR issuing request to provision role * ACE";
Timber.e(errorMsg);
emitter.onError(new IOException(errorMsg));
}
});
}
public Completable deleteAcl(String endpoint, String deviceId, long aceId) {
return Completable.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid uuid = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, uuid);
......@@ -218,4 +344,35 @@ public class AmsRepository {
return resources;
}
private int setAceResources(OCSecurityAce ace, List<String> resources) {
for (String resource : resources) {
OCAceResource res = OCObt.aceNewResource(ace);
if (res == null) {
String errorMsg = "ERROR: Could not allocate new resource for ACE";
Timber.e(errorMsg);
OCObt.freeAce(ace);
return -1;
}
if (OcfWildcard.isWildcard(resource)) {
if (resource.equals(OcfWildcard.OC_WILDCARD_ALL_NCR)) {
OCObt.aceResourceSetWc(res, OCAceWildcard.OC_ACE_WC_ALL);
} else if (resource.equals(OcfWildcard.OC_WILDCARD_ALL_SECURE_NCR)) {
OCObt.aceResourceSetWc(res, OCAceWildcard.OC_ACE_WC_ALL_SECURED);
} else if (resource.equals(OcfWildcard.OC_WILDCARD_ALL_NON_SECURE_NCR)) {
OCObt.aceResourceSetWc(res, OCAceWildcard.OC_ACE_WC_ALL_PUBLIC);
}
} else {
OCObt.aceResourceSetHref(res, resource);
OCObt.aceResourceSetWc(res, OCAceWildcard.OC_ACE_NO_WC);
}
// TODO: Set resource types
// TODO: Set interfaces
}
return 0;
}
}
......@@ -26,12 +26,15 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import org.openconnectivity.otgc.utils.constant.OtgcMode;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class AndroidPreferencesRepository implements PreferencesRepository {
private static final String DISCOVERY_TIMEOUT_DEFAULT = "5";
private static final String REQUESTS_DELAY_DEFAULT = "1";
private static final String DISCOVERY_SCOPE_DEFAULT = "Link-Local";
private final SharedPreferences mPreferences;
......@@ -48,6 +51,12 @@ public class AndroidPreferencesRepository implements PreferencesRepository {
mPreferences.getString("discovery_timeout", DISCOVERY_TIMEOUT_DEFAULT));
}
@Override
public int getRequestsDelay() {
return Integer.parseInt(
mPreferences.getString("requests_delay", REQUESTS_DELAY_DEFAULT));
}
@Override
public boolean isFirstRun() {
return mPreferences.getBoolean("FIRSTRUN", true);
......@@ -72,6 +81,18 @@ public class AndroidPreferencesRepository implements PreferencesRepository {
editor.apply();
}
@Override
public String getMode() {
return mPreferences.getString("Mode", OtgcMode.OBT);
}
@Override
public void setMode(String mode) {
SharedPreferences.Editor editor = mPreferences.edit();
editor.putString("Mode", mode);
editor.apply();
}
@Override
public String getDiscoveryScope() {
return mPreferences.getString("discovery_scope", DISCOVERY_SCOPE_DEFAULT);
......
......@@ -56,8 +56,7 @@ public class CmsRepository {
public Single<OcCredentials> getCredentials(String endpoint, String deviceId) {
return Single.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid uuid = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, uuid);
......@@ -84,8 +83,7 @@ public class CmsRepository {
public Single<OcCsr> retrieveCsr(String endpoint, String deviceId) {
return Single.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid uuid = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, uuid);
......@@ -110,8 +108,7 @@ public class CmsRepository {
public Completable provisionTrustAnchor(String endpoint, String deviceId, String rootCert) {
return Completable.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, di);
......@@ -163,8 +160,7 @@ public class CmsRepository {
return provisionTrustAnchor(endpoint, deviceId, rootCert)
.andThen(
Completable.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, di);
......@@ -212,10 +208,29 @@ public class CmsRepository {
}));
}
public Completable provisionIdentityCertificate(String deviceId) {
return Completable.create(emitter -> {
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCObtStatusHandler handler = (int status) -> {
if (status >= 0) {
Timber.d("Provision identity certificate succeeded");
emitter.onComplete();
} else {
emitter.onError(new IOException("Provision identity certificate error"));
}
};
int ret = OCObt.provisionIdentityCertificate(di, handler);
if (ret < 0) {
emitter.onError(new IOException("Provision identity certificate error"));
}
});
}
public Completable provisionRoleCertificate(String endpoint, String deviceId, String roleCert, String roleId, String roleAuthority) {
return Completable.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, di);
......@@ -268,10 +283,33 @@ public class CmsRepository {
});
}
public Completable provisionRoleCertificate(String deviceId, String roleId, String roleAuthority) {
return Completable.create(emitter -> {
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCRole role = new OCRole();
role.setRole(roleId);
role.setAuthority(roleAuthority);
OCObtStatusHandler handler = (int status) -> {
if (status >= 0) {
Timber.d("Provision role certificate succeeded");
emitter.onComplete();
} else {
emitter.onError(new IOException("Provision role certificate error"));
}
};
int ret = OCObt.provisionRoleCertificate(role, di, handler);
if (ret < 0) {
emitter.onError(new IOException("Provision role certificate error"));
}
});
}
public Completable createPskCredential(String endpoint, String deviceId, String targetUuid, byte[] symmetricKey) {
return Completable.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, di);
......@@ -318,10 +356,36 @@ public class CmsRepository {
});
}
public Completable provisionPairwiseCredential(String clientId, String serverId) {
return Completable.create(emitter -> {
OCUuid cliendDi = OCUuidUtil.stringToUuid(clientId);
OCUuid serverDi = OCUuidUtil.stringToUuid(serverId);
OCObtStatusHandler handler = (int status) -> {
if (status >= 0) {
Timber.d("Successfully provisioned pair-wise credentials");
emitter.onComplete();
} else {
String errorMsg = "ERROR provisioning pair-wise credentials";
Timber.e(errorMsg);
emitter.onError(new Exception(errorMsg));
}
};
int ret = OCObt.provisionPairwiseCredentials(cliendDi, serverDi, handler);
if (ret >= 0) {
Timber.d("Successfully issued request to provision credentials");
} else {
String errorMsg = "ERROR issuing request to provision credentials";
Timber.e(errorMsg);
emitter.onError(new Exception(errorMsg));
}
});
}
public Completable deleteCredential(String endpoint, String deviceId, long credId) {
return Completable.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, di);
......
......@@ -78,7 +78,7 @@ public class DoxsRepository {
if (status >= 0) {
Timber.d("Successfully request Random PIN " + OCUuidUtil.uuidToString(ocUuid));
String pin = randomPinHandler.handler();
if (OCObt.performRandomPinOtm(uuid, pin, pin.length(), handler) != -1){
if (OCObt.performRandomPinOtm(uuid, pin, handler) != -1){
emitter.onComplete();
} else {
String error = "ERROR send random PIN on device " + OCUuidUtil.uuidToString(ocUuid);
......@@ -133,8 +133,7 @@ public class DoxsRepository {
public Single<OcDoxm> retrieveOTMethods(String endpoint) {
return Single.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCResponseHandler handler = (OCClientResponse response) -> {
OCStatus code = response.getCode();
......@@ -169,8 +168,7 @@ public class DoxsRepository {
public Single<OcDoxm> get(String endpoint, String deviceId) {
return Single.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, di);
......@@ -195,8 +193,7 @@ public class DoxsRepository {
public Completable post(String endpoint, String deviceId, OcDoxm doxm) {
return Completable.create(emitter -> {
OCEndpoint ep = OCEndpointUtil.newEndpoint();
OCEndpointUtil.stringToEndpoint(endpoint, ep, new String[1]);
OCEndpoint ep = OCEndpointUtil.stringToEndpoint(endpoint, new String[1]);
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
OCEndpointUtil.setDi(ep, di);
......
......@@ -43,7 +43,6 @@ import org.iotivity.OCStorage;
import org.iotivity.OCUuid;
import org.iotivity.OCUuidUtil;
import org.openconnectivity.otgc.R;
import org.openconnectivity.otgc.domain.model.resource.virtual.d.OcDeviceInfo;
import org.openconnectivity.otgc.domain.model.resource.virtual.p.OcPlatformInfo;
import org.openconnectivity.otgc.domain.model.resource.virtual.res.OcEndpoint;
......@@ -63,7 +62,6 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
......@@ -272,22 +270,45 @@ public class IotivityRepository {
OcRes res = new OcRes();
res.parseOCRepresentation(response.getPayload());
OcResource resource = res.getResourceList().get(0);
String deviceId = resource.getAnchor().replace("ocf://", "");
List<String> endpoints = new ArrayList<>();
for (OcEndpoint ep : resource.getEndpoints()) {
endpoints.add(ep.getEndpoint());
}
if (!res.getResourceList().isEmpty()) {
OcResource resource = res.getResourceList().get(0);
String deviceId = resource.getAnchor().replace("ocf://", "");
List<String> endpoints = new ArrayList<>();
for (OcEndpoint ep : resource.getEndpoints()) {
endpoints.add(ep.getEndpoint());
}
DeviceEntity device = deviceDao.findById(deviceId).blockingGet();
if (device == null) {
deviceDao.insert(new DeviceEntity(deviceId, "", endpoints, DeviceType.OWNED_BY_OTHER, Device.NOTHING_PERMITS));
allDevices.add(new Device(DeviceType.OWNED_BY_OTHER, deviceId, new OcDeviceInfo(), endpoints, Device.NOTHING_PERMITS));
} else {
deviceDao.insert(new DeviceEntity(deviceId, device.getName(), endpoints, device.getType(), device.getPermits()));
allDevices.add(new Device(device.getType(), deviceId, new OcDeviceInfo(), endpoints, device.getPermits()));