Unverified Commit 543d902b authored by Javier Guerra's avatar Javier Guerra Committed by GitHub

Merge pull request #7 from openconnectivity/develop

Merge develop into master
parents eea51bd4 f6f184ec
......@@ -30,7 +30,7 @@ android {
minSdkVersion 21
targetSdkVersion 28
versionCode 13
versionName "2.0.4"
versionName "2.0.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
compileOptions {
......
......@@ -32,7 +32,7 @@ import javax.inject.Singleton;
@Singleton
public class AndroidPreferencesRepository implements PreferencesRepository {
private static final String DISCOVERY_TIMEOUT_DEFAULT = "5";
//private static final int DISCOVERY_TIMEOUT_DEFAULT = 5;
private static final String DISCOVERY_SCOPE_DEFAULT = "Link-Local";
private final SharedPreferences mPreferences;
......@@ -71,4 +71,9 @@ public class AndroidPreferencesRepository implements PreferencesRepository {
editor.putString("Piid", piid);
editor.apply();
}
@Override
public String getDiscoveryScope() {
return mPreferences.getString("discovery_scope", DISCOVERY_SCOPE_DEFAULT);
}
}
......@@ -43,11 +43,13 @@ 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;
import org.openconnectivity.otgc.domain.model.resource.virtual.res.OcRes;
import org.openconnectivity.otgc.domain.model.resource.virtual.res.OcResource;
import org.openconnectivity.otgc.utils.constant.DiscoveryScope;
import org.openconnectivity.otgc.utils.constant.OcfResourceType;
import org.openconnectivity.otgc.data.entity.DeviceEntity;
import org.openconnectivity.otgc.data.persistence.dao.DeviceDao;
......@@ -202,7 +204,15 @@ public class IotivityRepository {
unownedDevices.add(new Device(DeviceType.UNOWNED, deviceId, new OcDeviceInfo(), endpoints, Device.NOTHING_PERMITS));
};
int ret = OCObt.discoverUnownedDevices(handler);
int ret;
String scope = preferencesRepository.getDiscoveryScope();
if (scope.equals(DiscoveryScope.DISCOVERY_SCOPE_SITE)) {
ret = OCObt.discoverUnownedDevicesSiteLocalIPv6(handler);
} else if (scope.equals(DiscoveryScope.DISCOVERY_SCOPE_REALM)) {
ret = OCObt.discoverUnownedDevicesRealmLocalIPv6(handler);
} else {
ret = OCObt.discoverUnownedDevices(handler);
}
if (ret < 0) {
String error = "ERROR discovering un-owned Devices.";
Timber.e(error);
......@@ -232,7 +242,15 @@ public class IotivityRepository {
ownedDevices.add(new Device(DeviceType.OWNED_BY_SELF, deviceId, new OcDeviceInfo(), endpoints, Device.FULL_PERMITS));
};
int ret = OCObt.discoverOwnedDevices(handler);
int ret;
String scope = preferencesRepository.getDiscoveryScope();
if (scope.equals(DiscoveryScope.DISCOVERY_SCOPE_SITE)) {
ret = OCObt.discoverOwnedDevicesSiteLocalIPv6(handler);
} else if (scope.equals(DiscoveryScope.DISCOVERY_SCOPE_REALM)) {
ret = OCObt.discoverOwnedDevicesRealmLocalIPv6(handler);
} else {
ret = OCObt.discoverOwnedDevices(handler);
}
if (ret < 0) {
String error = "ERROR discovering owned Devices.";
Timber.e(error);
......@@ -273,8 +291,19 @@ public class IotivityRepository {
}
};
if (!OCMain.doIPMulticast(OcfResourceUri.RES_URI, null, handler)) {
emitter.onError(new Exception("Error scanning hosts"));
String scope = preferencesRepository.getDiscoveryScope();
if (scope.equals(DiscoveryScope.DISCOVERY_SCOPE_SITE)) {
if (!OCMain.doRealmLocalIPv6Multicast(OcfResourceUri.RES_URI, null, handler)) {
emitter.onError(new Exception("Error scanning hosts"));
}
} else if (scope.equals(DiscoveryScope.DISCOVERY_SCOPE_REALM)) {
if (!OCMain.doSiteLocalIPv6Multicast(OcfResourceUri.RES_URI, null, handler)) {
emitter.onError(new Exception("Error scanning hosts"));
}
} else {
if (!OCMain.doIPMulticast(OcfResourceUri.RES_URI, null, handler)) {
emitter.onError(new Exception("Error scanning hosts"));
}
}
}).timeout(getDiscoveryTimeout(), TimeUnit.SECONDS)
......
......@@ -30,4 +30,6 @@ public interface PreferencesRepository {
void setFirstRun(boolean firstRun);
void setPiid(String piid);
String getPiid();
String getDiscoveryScope();
}
package org.openconnectivity.otgc.utils.constant;
public class DiscoveryScope {
private DiscoveryScope() {}
public static String DISCOVERY_SCOPE_LINK = "Link-Local";
public static String DISCOVERY_SCOPE_SITE = "Site-Local";
public static String DISCOVERY_SCOPE_REALM = "Realm-Local";
}
......@@ -26,6 +26,7 @@ import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import org.openconnectivity.otgc.domain.usecase.GetDeviceDatabaseUseCase;
import org.openconnectivity.otgc.domain.usecase.accesscontrol.CreateAclUseCase;
import org.openconnectivity.otgc.domain.usecase.wifi.CheckConnectionUseCase;
import org.openconnectivity.otgc.domain.usecase.GetDeviceInfoUseCase;
import org.openconnectivity.otgc.domain.model.exception.NetworkDisconnectedException;
......@@ -52,6 +53,7 @@ import org.openconnectivity.otgc.domain.model.WifiNetwork;
import org.openconnectivity.otgc.domain.usecase.wifi.RegisterScanResultsReceiverUseCase;
import org.openconnectivity.otgc.domain.usecase.wifi.ScanWiFiNetworksUseCase;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
......@@ -63,6 +65,7 @@ public class DoxsViewModel extends BaseViewModel {
private final ScanDevicesUseCase mScanDevicesUseCase;
private final GetOTMethodsUseCase mGetOTMethodsUseCase;
private final OnboardUseCase mOnboardUseCase;
private final CreateAclUseCase mCreateAclUseCase;
private final OffboardUseCase mOffboardUseCase;
private final GetDeviceInfoUseCase mGetDeviceInfoUseCase;
private final SetDeviceNameUseCase mSetDeviceNameUseCase;
......@@ -92,6 +95,7 @@ public class DoxsViewModel extends BaseViewModel {
ScanDevicesUseCase scanDevicesUseCase,
GetOTMethodsUseCase getOTMethodsUseCase,
OnboardUseCase onboardUseCase,
CreateAclUseCase createAclUseCase,
OffboardUseCase offboardUseCase,
GetDeviceInfoUseCase getDeviceInfoUseCase,
SetDeviceNameUseCase setDeviceNameUseCase,
......@@ -107,6 +111,7 @@ public class DoxsViewModel extends BaseViewModel {
this.mScanDevicesUseCase = scanDevicesUseCase;
this.mGetOTMethodsUseCase = getOTMethodsUseCase;
this.mOnboardUseCase = onboardUseCase;
this.mCreateAclUseCase = createAclUseCase;
this.mOffboardUseCase = offboardUseCase;
this.mGetDeviceInfoUseCase = getDeviceInfoUseCase;
this.mSetDeviceNameUseCase = setDeviceNameUseCase;
......@@ -228,7 +233,13 @@ public class DoxsViewModel extends BaseViewModel {
.subscribeOn(mSchedulersFacade.io())
.observeOn(mSchedulersFacade.ui())
.subscribe(
ownedDevice -> otmResponse.setValue(Response.success(ownedDevice)),
ownedDevice -> mCreateAclUseCase.execute(ownedDevice, true, Arrays.asList("*"), 31)
.subscribeOn(mSchedulersFacade.io())
.observeOn(mSchedulersFacade.ui())
.subscribe(
() -> otmResponse.setValue(Response.success(ownedDevice)),
throwable -> otmResponse.setValue(Response.error(throwable))
),
throwable -> {
if (throwable instanceof NetworkDisconnectedException) {
mError.setValue(new ViewModelError(CommonError.NETWORK_DISCONNECTED, null));
......
......@@ -46,4 +46,14 @@
<item>@string/client_drawer_platform_man_support_url</item>
<item>@string/client_drawer_platform_man_system_time</item>
</string-array>
<string-array name="pref_iotivity_discovery_entries_array">
<item>Link-Local scope</item>
<item>Site-Local scope</item>
<item>Realm-Local scope</item>
</string-array>
<string-array name="pref_iotivity_discovery_entry_values_array">
<item>Link-Local</item>
<item>Site-Local</item>
<item>Realm-Local</item>
</string-array>
</resources>
\ No newline at end of file
......@@ -247,6 +247,8 @@
<string name="pref_iotivity_header" translatable="false">IoTivity</string>
<string name="pref_iotivity_title_discovery_timeout">Discovery timeout (in seconds)</string>
<string name="pref_iotivity_default_discovery_timeout" translatable="false">5</string>
<string name="pref_iotivity_title_discovery_scope">Multicast IPv6 scope</string>
<string name="pref_iotivity_default_discovery_scope">Link-Local</string>
<string name="pref_help_header">Help</string>
<string name="pref_help_app_info">App info</string>
......
......@@ -32,4 +32,11 @@
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/pref_iotivity_title_discovery_timeout" />
<ListPreference
android:key="discovery_scope"
android:title="@string/pref_iotivity_title_discovery_scope"
android:defaultValue="@string/pref_iotivity_default_discovery_scope"
android:entries="@array/pref_iotivity_discovery_entries_array"
android:entryValues="@array/pref_iotivity_discovery_entry_values_array"
android:summary="Select IPv6 scope" />
</PreferenceScreen>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment