Android: Added Device/Platform discovery client/server examples.
authorTim Kourt <tim.a.kourt@intel.com>
Fri, 11 Sep 2015 22:47:12 +0000 (15:47 -0700)
committerPatrick Lankswert <patrick.lankswert@intel.com>
Sat, 19 Sep 2015 16:38:02 +0000 (16:38 +0000)
In addition it also modifies the respective functions in the base
Note: this commit depends on gerrit.iotivity.org/gerrit/#/c/2433/

Set 3: Changed the tests to be in accordance with the modified API

Change-Id: I1a91166a54ef7f277d95c4d62961888c782383c5
Signed-off-by: Tim Kourt <tim.a.kourt@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2489
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Patrick Lankswert <patrick.lankswert@intel.com>
50 files changed:
android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java
android/android_api/base/src/main/java/org/iotivity/base/ErrorCode.java
android/android_api/base/src/main/java/org/iotivity/base/OcDeviceInfo.java
android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java
android/android_api/base/src/main/java/org/iotivity/base/OcPlatformInfo.java
android/android_api/base/src/main/java/org/iotivity/base/OcPlatformStatus.java
android/android_api/base/src/main/java/org/iotivity/base/OcStackConfig.java [deleted file]
android/examples/devicediscoveryclient/.gitignore [new file with mode: 0644]
android/examples/devicediscoveryclient/build.gradle [new file with mode: 0644]
android/examples/devicediscoveryclient/devicediscoveryclient.iml [new file with mode: 0644]
android/examples/devicediscoveryclient/proguard-rules.pro [new file with mode: 0644]
android/examples/devicediscoveryclient/src/main/AndroidManifest.xml [new file with mode: 0644]
android/examples/devicediscoveryclient/src/main/java/org/iotivity/base/examples/DeviceDiscoveryClient.java [new file with mode: 0644]
android/examples/devicediscoveryclient/src/main/res/drawable/iotivityicon.png [new file with mode: 0644]
android/examples/devicediscoveryclient/src/main/res/drawable/iotivitylogo.png [new file with mode: 0644]
android/examples/devicediscoveryclient/src/main/res/layout/activity_device_discovery_client.xml [new file with mode: 0644]
android/examples/devicediscoveryclient/src/main/res/mipmap-hdpi/iotivityicon.png [new file with mode: 0644]
android/examples/devicediscoveryclient/src/main/res/mipmap-mdpi/iotivityicon.png [new file with mode: 0644]
android/examples/devicediscoveryclient/src/main/res/mipmap-xhdpi/iotivityicon.png [new file with mode: 0644]
android/examples/devicediscoveryclient/src/main/res/mipmap-xxhdpi/iotivityicon.png [new file with mode: 0644]
android/examples/devicediscoveryclient/src/main/res/values-v21/styles.xml [new file with mode: 0644]
android/examples/devicediscoveryclient/src/main/res/values-w820dp/dimens.xml [new file with mode: 0644]
android/examples/devicediscoveryclient/src/main/res/values/dimens.xml [new file with mode: 0644]
android/examples/devicediscoveryclient/src/main/res/values/strings.xml [new file with mode: 0644]
android/examples/devicediscoveryclient/src/main/res/values/styles.xml [new file with mode: 0644]
android/examples/devicediscoveryserver/.gitignore [new file with mode: 0644]
android/examples/devicediscoveryserver/build.gradle [new file with mode: 0644]
android/examples/devicediscoveryserver/devicediscoveryserver.iml [new file with mode: 0644]
android/examples/devicediscoveryserver/proguard-rules.pro [new file with mode: 0644]
android/examples/devicediscoveryserver/src/main/AndroidManifest.xml [new file with mode: 0644]
android/examples/devicediscoveryserver/src/main/java/org/iotivity/base/examples/DeviceDiscoveryServer.java [new file with mode: 0644]
android/examples/devicediscoveryserver/src/main/res/drawable/iotivityicon.png [new file with mode: 0644]
android/examples/devicediscoveryserver/src/main/res/drawable/iotivitylogo.png [new file with mode: 0644]
android/examples/devicediscoveryserver/src/main/res/layout/activity_device_discovery_server.xml [new file with mode: 0644]
android/examples/devicediscoveryserver/src/main/res/mipmap-hdpi/iotivityicon.png [new file with mode: 0644]
android/examples/devicediscoveryserver/src/main/res/mipmap-mdpi/iotivityicon.png [new file with mode: 0644]
android/examples/devicediscoveryserver/src/main/res/mipmap-xhdpi/iotivityicon.png [new file with mode: 0644]
android/examples/devicediscoveryserver/src/main/res/mipmap-xxhdpi/iotivityicon.png [new file with mode: 0644]
android/examples/devicediscoveryserver/src/main/res/values-v21/styles.xml [new file with mode: 0644]
android/examples/devicediscoveryserver/src/main/res/values-w820dp/dimens.xml [new file with mode: 0644]
android/examples/devicediscoveryserver/src/main/res/values/dimens.xml [new file with mode: 0644]
android/examples/devicediscoveryserver/src/main/res/values/strings.xml [new file with mode: 0644]
android/examples/devicediscoveryserver/src/main/res/values/styles.xml [new file with mode: 0644]
android/examples/presenceclient/build.gradle
android/examples/presenceclient/src/main/AndroidManifest.xml
android/examples/presenceclient/src/main/java/org/iotivity/base/examples/PresenceClient.java
android/examples/presenceclient/src/main/res/layout/activity_presence_client.xml
android/examples/presenceclient/src/main/res/values-v21/styles.xml
android/examples/presenceserver/src/main/java/org/iotivity/base/examples/PresenceServer.java
android/examples/settings.gradle

index b0fadd7..350091e 100644 (file)
@@ -995,12 +995,8 @@ public class SmokeTest extends InstrumentationTestCase {
         };
 
         OcPlatformInfo platformInfo = null;
-        try {
-            platformInfo = new OcPlatformInfo("myPlatformID", "myManuName", "myManuUrl");
-        } catch (OcException e) {
-            Log.e(TAG, "Could not construct platformInfo. " + e.getMessage());
-            assertTrue(false);
-        }
+
+        platformInfo = new OcPlatformInfo("myPlatformID", "myManuName", "myManuUrl");
 
         platformInfo.setModelNumber("myModelNumber");
         platformInfo.setDateOfManufacture("myDateOfManufacture");
@@ -1013,13 +1009,12 @@ public class SmokeTest extends InstrumentationTestCase {
 
         try {
             //server
-
             OcPlatform.registerPlatformInfo(platformInfo);
 
             //client
             OcPlatform.getPlatformInfo(
                     "",
-                    OcPlatform.MULTICAST_PREFIX + "/oic/p",
+                    OcPlatform.WELL_KNOWN_PLATFORM_QUERY,
                     EnumSet.of(OcConnectivityType.CT_DEFAULT),
                     platformFoundListener);
 
@@ -1053,17 +1048,15 @@ public class SmokeTest extends InstrumentationTestCase {
             }
         };
 
-        OcDeviceInfo devInfo = new OcDeviceInfo();
-        devInfo.setDeviceName("myDeviceName");
+        OcDeviceInfo devInfo = new OcDeviceInfo("myDeviceName");
 
         try {
             //server
             OcPlatform.registerDeviceInfo(devInfo);
-
             //client
             OcPlatform.getDeviceInfo(
                     "",
-                    OcPlatform.MULTICAST_PREFIX + OcPlatform.DEVICE_URI,
+                    OcPlatform.WELL_KNOWN_DEVICE_QUERY,
                     EnumSet.of(OcConnectivityType.CT_DEFAULT),
                     deviceFoundListener);
 
index b83e4b3..5951750 100644 (file)
@@ -55,20 +55,12 @@ public enum ErrorCode {
     PERSISTENT_BUFFER_REQUIRED("PERSISTENT_BUFFER_REQUIRED", ""),
     INVALID_REQUEST_HANDLE("INVALID_REQUEST_HANDLE", ""),
     INVALID_DEVICE_INFO("INVALID_DEVICE_INFO", ""),
-    INVALID_PLATFORM_INFO_PLATFORMID("INVALID_PLATFORM_INFO_PLATFORMID",
-            "PlatformID cannot be null or empty"),
-    INVALID_PLATFORM_INFO_MANUFACTURER_NAME("INVALID_PLATFORM_INFO_MANUFACTURER_NAME",
-            "ManufacturerName cannot be null, empty or greater than " +
-                    OcStackConfig.MAX_MANUFACTURER_NAME_LENGTH + " characters long"),
-    INVALID_PLATFORM_INFO_PLATFORMID_MANUFACTURER_URL("INVALID_PLATFORM_INFO_MANUFACTURER_URL",
-            "MANUFACTURER_URL cannot be null, empty or greater than " +
-                    OcStackConfig.MAX_MANUFACTURER_URL_LENGTH + " characters long"),
+
     ERROR("ERROR", "Generic error"),
 
     JNI_EXCEPTION("JNI_EXCEPTION", "Generic Java binder error"),
     JNI_NO_NATIVE_OBJECT("JNI_NO_NATIVE_OBJECT", ""),
     JNI_INVALID_VALUE("JNI_INVALID_VALUE", ""),
-
     INVALID_CLASS_CAST("INVALID_CLASS_CAST", ""),;
 
     private String error;
index 2cb794b..a793e7a 100644 (file)
@@ -24,25 +24,14 @@ package org.iotivity.base;
 
 public class OcDeviceInfo {
 
-    private String deviceName;
-
-    public OcDeviceInfo() {
-
-        deviceName = "";
-    }
+    private String mDeviceName;
 
     public OcDeviceInfo(String deviceName) {
 
-        this.deviceName = deviceName;
+        this.mDeviceName = deviceName;
     }
 
     public String getDeviceName() {
-
-        return deviceName;
-    }
-
-    public void setDeviceName(String deviceName) {
-
-        this.deviceName = deviceName;
+        return mDeviceName;
     }
 }
index 63b482a..8004287 100644 (file)
@@ -64,11 +64,9 @@ public final class OcPlatform {
     public static final String GROUP_INTERFACE = "oic.mi.grp";
 
     public static final String WELL_KNOWN_QUERY = "/oic/res";
-    public static final String MULTICAST_PREFIX = "224.0.1.187:5683";
-    public static final String MULTICAST_IP = "224.0.1.187";
-    public static final int MULTICAST_PORT = 5683;
+    public static final String WELL_KNOWN_DEVICE_QUERY = "/oic/d";
+    public static final String WELL_KNOWN_PLATFORM_QUERY = "/oic/p";
     public static final int DEFAULT_PRESENCE_TTL = 60;
-    public static final String DEVICE_URI = "/oic/d";
     public static final String PRESENCE_URI = "/oic/ad";
 
     private static volatile boolean sIsPlatformInitialized = false;
@@ -491,7 +489,7 @@ public final class OcPlatform {
                 resProperty |= prop.getValue();
         }
 
-        if(null == entityHandler){
+        if (null == entityHandler) {
             entityHandler = new EntityHandler() {
                 @Override
                 public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest) {
@@ -542,7 +540,7 @@ public final class OcPlatform {
             OcPlatformInfo ocPlatformInfo) throws OcException {
         OcPlatform.initCheck();
         OcPlatform.registerPlatformInfo0(
-                ocPlatformInfo.getPlatformID(),
+                ocPlatformInfo.getPlatformId(),
                 ocPlatformInfo.getManufacturerName(),
                 ocPlatformInfo.getManufacturerUrl(),
                 ocPlatformInfo.getModelNumber(),
index 53d366d..1ed7a94 100644 (file)
 
 package org.iotivity.base;
 
-import java.lang.Error;
+import java.security.InvalidParameterException;
 
 public class OcPlatformInfo {
-
-    private String platformID;
-    private String manufacturerName;
-    private String manufacturerUrl;
-    private String modelNumber;
-    private String dateOfManufacture;
-    private String platformVersion;
-    private String operatingSystemVersion;
-    private String hardwareVersion;
-    private String firmwareVersion;
-    private String supportUrl;
-    private String systemTime;
+    private String mPlatformId;
+    private String mManufacturerName;
+    private String mManufacturerUrl;
+    private String mModelNumber;
+    private String mDateOfManufacture;
+    private String mPlatformVersion;
+    private String mOperatingSystemVersion;
+    private String mHardwareVersion;
+    private String mFirmwareVersion;
+    private String mSupportUrl;
+    private String mSystemTime;
 
     // construct OcPlatformInfo with mandatory fields which cannot be null
     // manufacturerName cannot be > 16 chars
     // manufacturerUrl cannot be > 32 chars
-    protected OcPlatformInfo(String platformID, String manufacturerName,
-                             String manufacturerUrl) throws OcException {
-        ErrorCode result = validatePlatformInfo(platformID, manufacturerName, manufacturerUrl);
-        if (ErrorCode.OK == result) {
-            this.platformID = platformID;
-            this.manufacturerName = manufacturerName;
-            this.manufacturerUrl = manufacturerUrl;
-        } else {
-            throw new OcException(result, result.getDescription());
-        }
-    }
-
-    public ErrorCode validatePlatformInfo(String platformID, String manufacturerName,
-                                          String manufacturerUrl) {
-        // checks to see if the mandatory fields have non-null values or not
-        if (platformID == null || platformID.isEmpty()) return ErrorCode.INVALID_PLATFORM_INFO_PLATFORMID;
-        if (manufacturerName == null || manufacturerName.isEmpty() ||
-                manufacturerName.length() > OcStackConfig.MAX_MANUFACTURER_NAME_LENGTH)
-            return ErrorCode.INVALID_PLATFORM_INFO_MANUFACTURER_NAME;
-        if (manufacturerUrl == null || manufacturerUrl.isEmpty() ||
-                manufacturerUrl.length() > OcStackConfig.MAX_MANUFACTURER_URL_LENGTH)
-            return ErrorCode.INVALID_PLATFORM_INFO_PLATFORMID_MANUFACTURER_URL;
-        return ErrorCode.OK;
-    }
-
-    public String getPlatformID() {
-        return platformID;
-    }
-
-    public void setPlatformID(String platformID) {
-        this.platformID = platformID;
+    public OcPlatformInfo(String platformId, String manufacturerName,
+                          String manufacturerUrl) {
+        this.mPlatformId = platformId;
+        this.mManufacturerName = manufacturerName;
+        this.mManufacturerUrl = manufacturerUrl;
+    }
+
+    public OcPlatformInfo(String platformId,
+                          String manufacturerName,
+                          String manufacturerUrl,
+                          String modelNumber,
+                          String dateOfManufacture,
+                          String platformVersion,
+                          String operatingSystemVersion,
+                          String hardwareVersion,
+                          String firmwareVersion,
+                          String supportUrl,
+                          String systemTime) {
+        this(platformId, manufacturerName, manufacturerUrl);
+        this.mModelNumber = modelNumber;
+        this.mDateOfManufacture = dateOfManufacture;
+        this.mPlatformVersion = platformVersion;
+        this.mOperatingSystemVersion = operatingSystemVersion;
+        this.mHardwareVersion = hardwareVersion;
+        this.mFirmwareVersion = firmwareVersion;
+        this.mSupportUrl = supportUrl;
+        this.mSystemTime = systemTime;
+    }
+
+    public String getPlatformId() {
+        return mPlatformId;
+    }
+
+    public void setPlatformId(String platformId) {
+        this.mPlatformId = platformId;
     }
 
     public String getManufacturerName() {
-        return manufacturerName;
+        return mManufacturerName;
     }
 
     public void setManufacturerName(String manufacturerName) {
-        this.manufacturerName = manufacturerName;
+        this.mManufacturerName = manufacturerName;
     }
 
     public String getManufacturerUrl() {
-        return manufacturerUrl;
+        return mManufacturerUrl;
     }
 
     public void setManufacturerUrl(String manufacturerUrl) {
-        this.manufacturerUrl = manufacturerUrl;
+        this.mManufacturerUrl = manufacturerUrl;
     }
 
     public String getModelNumber() {
-        return modelNumber;
+        return mModelNumber;
     }
 
     public void setModelNumber(String modelNumber) {
-        this.modelNumber = modelNumber;
+        this.mModelNumber = modelNumber;
     }
 
     public String getDateOfManufacture() {
-        return dateOfManufacture;
+        return mDateOfManufacture;
     }
 
     public void setDateOfManufacture(String dateOfManufacture) {
-        this.dateOfManufacture = dateOfManufacture;
+        this.mDateOfManufacture = dateOfManufacture;
     }
 
     public String getPlatformVersion() {
-        return platformVersion;
+        return mPlatformVersion;
     }
 
     public void setPlatformVersion(String platformVersion) {
-        this.platformVersion = platformVersion;
+        this.mPlatformVersion = platformVersion;
     }
 
     public String getOperatingSystemVersion() {
-        return operatingSystemVersion;
+        return mOperatingSystemVersion;
     }
 
     public void setOperatingSystemVersion(String operatingSystemVersion) {
-        this.operatingSystemVersion = operatingSystemVersion;
+        this.mOperatingSystemVersion = operatingSystemVersion;
     }
 
     public String getHardwareVersion() {
-        return hardwareVersion;
+        return mHardwareVersion;
     }
 
     public void setHardwareVersion(String hardwareVersion) {
-        this.hardwareVersion = hardwareVersion;
+        this.mHardwareVersion = hardwareVersion;
     }
 
     public String getFirmwareVersion() {
-        return firmwareVersion;
+        return mFirmwareVersion;
     }
 
     public void setFirmwareVersion(String firmwareVersion) {
-        this.firmwareVersion = firmwareVersion;
+        this.mFirmwareVersion = firmwareVersion;
     }
 
     public String getSupportUrl() {
-        return supportUrl;
+        return mSupportUrl;
     }
 
     public void setSupportUrl(String supportUrl) {
-        this.supportUrl = supportUrl;
+        this.mSupportUrl = supportUrl;
     }
 
     public String getSystemTime() {
-        return systemTime;
+        return mSystemTime;
     }
 
     public void setSystemTime(String systemTime) {
-        this.systemTime = systemTime;
+        this.mSystemTime = systemTime;
     }
 }
diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcStackConfig.java b/android/android_api/base/src/main/java/org/iotivity/base/OcStackConfig.java
deleted file mode 100644 (file)
index ff48d22..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * //******************************************************************
- * //
- * // Copyright 2015 Intel Corporation.
- * //
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- * //
- * // Licensed under the Apache License, Version 2.0 (the "License");
- * // you may not use this file except in compliance with the License.
- * // You may obtain a copy of the License at
- * //
- * //      http://www.apache.org/licenses/LICENSE-2.0
- * //
- * // Unless required by applicable law or agreed to in writing, software
- * // distributed under the License is distributed on an "AS IS" BASIS,
- * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * // See the License for the specific language governing permissions and
- * // limitations under the License.
- * //
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- */
-
-// This file contains all the variables which can be configured/modified as
-// per platform or specific product usage scenarios.
-
-package org.iotivity.base;
-
-public interface OcStackConfig {
-    // max manufacturer name length for OcPlatformInfo supported by server
-    public static final int MAX_MANUFACTURER_NAME_LENGTH = 16;
-    // max manufacturer url length for OcPlatformInfo supported by server
-    public static final int MAX_MANUFACTURER_URL_LENGTH = 32;
-}
\ No newline at end of file
diff --git a/android/examples/devicediscoveryclient/.gitignore b/android/examples/devicediscoveryclient/.gitignore
new file mode 100644 (file)
index 0000000..796b96d
--- /dev/null
@@ -0,0 +1 @@
+/build
diff --git a/android/examples/devicediscoveryclient/build.gradle b/android/examples/devicediscoveryclient/build.gradle
new file mode 100644 (file)
index 0000000..0f56669
--- /dev/null
@@ -0,0 +1,24 @@
+apply plugin: 'com.android.application'
+
+android {
+    compileSdkVersion 22
+    buildToolsVersion "22.0.1"
+
+    defaultConfig {
+        applicationId "org.iotivity.base.examples.devicediscoveryclient"
+        minSdkVersion 21
+        targetSdkVersion 22
+        versionCode 1
+        versionName "1.0"
+    }
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+        }
+    }
+}
+
+dependencies {
+    compile fileTree(dir: 'libs', include: ['*.jar'])
+}
diff --git a/android/examples/devicediscoveryclient/devicediscoveryclient.iml b/android/examples/devicediscoveryclient/devicediscoveryclient.iml
new file mode 100644 (file)
index 0000000..ee457b3
--- /dev/null
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.id=":devicediscoveryclient" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="examples" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="android-gradle" name="Android-Gradle">
+      <configuration>
+        <option name="GRADLE_PROJECT_PATH" value=":devicediscoveryclient" />
+      </configuration>
+    </facet>
+    <facet type="android" name="Android">
+      <configuration>
+        <option name="SELECTED_BUILD_VARIANT" value="debug" />
+        <option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
+        <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
+        <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
+        <option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
+        <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
+        <option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugTestSources" />
+        <option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
+        <option name="ALLOW_USER_CONFIGURATION" value="false" />
+        <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
+        <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
+        <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
+        <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
+      </configuration>
+    </facet>
+  </component>
+  <component name="NewModuleRootManager" inherit-compiler-output="false">
+    <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
+    <output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
+      <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
+    </content>
+    <orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" exported="" name="iotivity-armeabi-base-debug-unspecified" level="project" />
+  </component>
+</module>
\ No newline at end of file
diff --git a/android/examples/devicediscoveryclient/proguard-rules.pro b/android/examples/devicediscoveryclient/proguard-rules.pro
new file mode 100644 (file)
index 0000000..d26150c
--- /dev/null
@@ -0,0 +1,17 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in /home/rahul/sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
diff --git a/android/examples/devicediscoveryclient/src/main/AndroidManifest.xml b/android/examples/devicediscoveryclient/src/main/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..ca6ea94
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.iotivity.base.examples" >
+
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.BLUETOOTH"/>
+    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
+    <uses-permission android:name="android.permission.INTERNET"/>
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
+    <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
+    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
+    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
+
+    <application
+        android:allowBackup="true"
+        android:icon="@mipmap/iotivityicon"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:screenOrientation="portrait"
+            android:name=".DeviceDiscoveryClient"
+            android:label="@string/app_name" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>
diff --git a/android/examples/devicediscoveryclient/src/main/java/org/iotivity/base/examples/DeviceDiscoveryClient.java b/android/examples/devicediscoveryclient/src/main/java/org/iotivity/base/examples/DeviceDiscoveryClient.java
new file mode 100644 (file)
index 0000000..309fc3b
--- /dev/null
@@ -0,0 +1,233 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Intel Corporation.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * //      http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+package org.iotivity.base.examples;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.text.method.ScrollingMovementMethod;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.ScrollView;
+import android.widget.TextView;
+
+import org.iotivity.base.ModeType;
+import org.iotivity.base.OcConnectivityType;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.base.PlatformConfig;
+import org.iotivity.base.QualityOfService;
+import org.iotivity.base.ServiceType;
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This sample demonstrates the device discovery feature.
+ * The client queries for the device related information stored by the server.
+ */
+public class DeviceDiscoveryClient extends Activity implements
+        OcPlatform.OnDeviceFoundListener,
+        OcPlatform.OnPlatformFoundListener {
+    private void startDeviceDiscoveryClient() {
+        Context context = this;
+
+        PlatformConfig platformConfig = new PlatformConfig(
+                context,
+                ServiceType.IN_PROC,
+                ModeType.CLIENT,
+                "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+                0,         // Uses randomly available port
+                QualityOfService.LOW
+        );
+
+        msg("Configuring platform.");
+        OcPlatform.Configure(platformConfig);
+        sleep(1);
+
+        try {
+            msg("Querying for platform information...");
+            OcPlatform.getPlatformInfo("",
+                    OcPlatform.WELL_KNOWN_PLATFORM_QUERY,
+                    EnumSet.of(OcConnectivityType.CT_DEFAULT),
+                    this);
+        } catch (OcException e) {
+            Log.e(TAG, e.toString());
+            msg("Failed to query for platform information");
+        }
+        sleep(2);
+
+        try {
+            msg("Querying for device information...");
+            OcPlatform.getDeviceInfo("",
+                    OcPlatform.WELL_KNOWN_DEVICE_QUERY,
+                    EnumSet.of(OcConnectivityType.CT_DEFAULT),
+                    this);
+        } catch (OcException e) {
+            Log.e(TAG, e.toString());
+            msg("Failed to query for device information");
+        }
+        sleep(2);
+
+        enableStartButton();
+        printLine();
+    }
+
+    private final static Map<String, String> PLATFORM_INFO_KEYS = new HashMap<String, String>() {{
+        put("pi", "Platform ID: ");
+        put("mnmn", "Manufacturer name: ");
+        put("mnml", "Manufacturer url: ");
+        put("mnmo", "Manufacturer Model No: ");
+        put("mndt", "Manufactured Date: ");
+        put("mnpv", "Manufacturer Platform Version: ");
+        put("mnos", "Manufacturer OS version: ");
+        put("mnhw", "Manufacturer hardware version: ");
+        put("mnfv", "Manufacturer firmware version: ");
+        put("mnsl", "Manufacturer support url: ");
+        put("st", "Manufacturer system time: ");
+    }};
+
+    @Override
+    public synchronized void onPlatformFound(OcRepresentation ocRepresentation) {
+        msg("Platform Information received:");
+        try {
+            for (String key : PLATFORM_INFO_KEYS.keySet()) {
+                msg("\t" + PLATFORM_INFO_KEYS.get(key) + ocRepresentation.getValue(key));
+            }
+        } catch (OcException e) {
+            Log.e(TAG, e.toString());
+            msg("Failed to read platform info values.");
+        }
+
+        printLine();
+    }
+
+    private final static Map<String, String> DEVICE_INFO_KEYS = new HashMap<String, String>() {{
+        put("di", "Device ID: ");
+        put("n", "Device name: ");
+        put("lcv", "Spec version url: ");
+        put("dmv", "Data Model: ");
+    }};
+
+    @Override
+    public synchronized void onDeviceFound(OcRepresentation ocRepresentation) {
+        msg("Device Information received:");
+        try {
+            for (String key : DEVICE_INFO_KEYS.keySet()) {
+                msg("\t" + DEVICE_INFO_KEYS.get(key) + ocRepresentation.getValue(key));
+            }
+        } catch (OcException e) {
+            Log.e(TAG, e.toString());
+            msg("Failed to read device info values.");
+        }
+
+        printLine();
+    }
+
+    //******************************************************************************
+    // End of the OIC specific code
+    //******************************************************************************
+
+    private final static String TAG = DeviceDiscoveryClient.class.getSimpleName();
+    private TextView mConsoleTextView;
+    private ScrollView mScrollView;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_device_discovery_client);
+
+        mConsoleTextView = (TextView) findViewById(R.id.consoleTextView);
+        mConsoleTextView.setMovementMethod(new ScrollingMovementMethod());
+        mScrollView = (ScrollView) findViewById(R.id.scrollView);
+        mScrollView.fullScroll(View.FOCUS_DOWN);
+        final Button button = (Button) findViewById(R.id.button);
+
+        if (null == savedInstanceState) {
+            button.setOnClickListener(new View.OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    button.setText("Re-start");
+                    button.setEnabled(false);
+                    new Thread(new Runnable() {
+                        public void run() {
+                            startDeviceDiscoveryClient();
+                        }
+                    }).start();
+                }
+            });
+        } else {
+            String consoleOutput = savedInstanceState.getString("consoleOutputString");
+            mConsoleTextView.setText(consoleOutput);
+        }
+    }
+
+    @Override
+    protected void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        outState.putString("consoleOutputString", mConsoleTextView.getText().toString());
+    }
+
+    @Override
+    protected void onRestoreInstanceState(Bundle savedInstanceState) {
+        super.onRestoreInstanceState(savedInstanceState);
+
+        String consoleOutput = savedInstanceState.getString("consoleOutputString");
+        mConsoleTextView.setText(consoleOutput);
+    }
+
+    private void enableStartButton() {
+        runOnUiThread(new Runnable() {
+            public void run() {
+                Button button = (Button) findViewById(R.id.button);
+                button.setEnabled(true);
+            }
+        });
+    }
+
+    private void sleep(int seconds) {
+        try {
+            Thread.sleep(seconds * 1000);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+            Log.e(TAG, e.toString());
+        }
+    }
+
+    private void msg(final String text) {
+        runOnUiThread(new Runnable() {
+            public void run() {
+                mConsoleTextView.append("\n");
+                mConsoleTextView.append(text);
+                mScrollView.fullScroll(View.FOCUS_DOWN);
+            }
+        });
+        Log.i(TAG, text);
+    }
+
+    private void printLine() {
+        msg("------------------------------------------------------------------------");
+    }
+}
diff --git a/android/examples/devicediscoveryclient/src/main/res/drawable/iotivityicon.png b/android/examples/devicediscoveryclient/src/main/res/drawable/iotivityicon.png
new file mode 100644 (file)
index 0000000..e1e4aa7
Binary files /dev/null and b/android/examples/devicediscoveryclient/src/main/res/drawable/iotivityicon.png differ
diff --git a/android/examples/devicediscoveryclient/src/main/res/drawable/iotivitylogo.png b/android/examples/devicediscoveryclient/src/main/res/drawable/iotivitylogo.png
new file mode 100644 (file)
index 0000000..a7d3115
Binary files /dev/null and b/android/examples/devicediscoveryclient/src/main/res/drawable/iotivitylogo.png differ
diff --git a/android/examples/devicediscoveryclient/src/main/res/layout/activity_device_discovery_client.xml b/android/examples/devicediscoveryclient/src/main/res/layout/activity_device_discovery_client.xml
new file mode 100644 (file)
index 0000000..621533b
--- /dev/null
@@ -0,0 +1,37 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
+    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
+    android:orientation="vertical"
+    android:paddingRight="@dimen/activity_horizontal_margin"
+    android:paddingTop="@dimen/activity_vertical_margin"
+    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".DeviceDiscoveryClient">
+    <Button
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:id="@+id/button"
+        android:layout_centerHorizontal="true"
+        android:textOff="Start"
+        android:textOn="Stop"
+        android:layout_alignParentEnd="true"
+        android:layout_alignParentStart="true"
+        android:text="Start" />
+    <ScrollView
+        android:layout_below="@id/button"
+        android:layout_above="@+id/imageView"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:fillViewport="true"
+        android:id="@+id/scrollView">
+        <TextView android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:id="@+id/consoleTextView" />
+    </ScrollView>
+    <ImageView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:id="@+id/imageView"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentEnd="true"
+        android:layout_alignParentStart="true"
+        android:src="@drawable/iotivitylogo" />
+</RelativeLayout>
\ No newline at end of file
diff --git a/android/examples/devicediscoveryclient/src/main/res/mipmap-hdpi/iotivityicon.png b/android/examples/devicediscoveryclient/src/main/res/mipmap-hdpi/iotivityicon.png
new file mode 100644 (file)
index 0000000..e1e4aa7
Binary files /dev/null and b/android/examples/devicediscoveryclient/src/main/res/mipmap-hdpi/iotivityicon.png differ
diff --git a/android/examples/devicediscoveryclient/src/main/res/mipmap-mdpi/iotivityicon.png b/android/examples/devicediscoveryclient/src/main/res/mipmap-mdpi/iotivityicon.png
new file mode 100644 (file)
index 0000000..2e7bce6
Binary files /dev/null and b/android/examples/devicediscoveryclient/src/main/res/mipmap-mdpi/iotivityicon.png differ
diff --git a/android/examples/devicediscoveryclient/src/main/res/mipmap-xhdpi/iotivityicon.png b/android/examples/devicediscoveryclient/src/main/res/mipmap-xhdpi/iotivityicon.png
new file mode 100644 (file)
index 0000000..afa486b
Binary files /dev/null and b/android/examples/devicediscoveryclient/src/main/res/mipmap-xhdpi/iotivityicon.png differ
diff --git a/android/examples/devicediscoveryclient/src/main/res/mipmap-xxhdpi/iotivityicon.png b/android/examples/devicediscoveryclient/src/main/res/mipmap-xxhdpi/iotivityicon.png
new file mode 100644 (file)
index 0000000..3e6bc6a
Binary files /dev/null and b/android/examples/devicediscoveryclient/src/main/res/mipmap-xxhdpi/iotivityicon.png differ
diff --git a/android/examples/devicediscoveryclient/src/main/res/values-v21/styles.xml b/android/examples/devicediscoveryclient/src/main/res/values-v21/styles.xml
new file mode 100644 (file)
index 0000000..dba3c41
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <style name="AppTheme" parent="android:Theme.Material.Light">
+    </style>
+</resources>
diff --git a/android/examples/devicediscoveryclient/src/main/res/values-w820dp/dimens.xml b/android/examples/devicediscoveryclient/src/main/res/values-w820dp/dimens.xml
new file mode 100644 (file)
index 0000000..63fc816
--- /dev/null
@@ -0,0 +1,6 @@
+<resources>
+    <!-- Example customization of dimensions originally defined in res/values/dimens.xml
+         (such as screen margins) for screens with more than 820dp of available width. This
+         would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
+    <dimen name="activity_horizontal_margin">64dp</dimen>
+</resources>
diff --git a/android/examples/devicediscoveryclient/src/main/res/values/dimens.xml b/android/examples/devicediscoveryclient/src/main/res/values/dimens.xml
new file mode 100644 (file)
index 0000000..47c8224
--- /dev/null
@@ -0,0 +1,5 @@
+<resources>
+    <!-- Default screen margins, per the Android Design guidelines. -->
+    <dimen name="activity_horizontal_margin">16dp</dimen>
+    <dimen name="activity_vertical_margin">16dp</dimen>
+</resources>
diff --git a/android/examples/devicediscoveryclient/src/main/res/values/strings.xml b/android/examples/devicediscoveryclient/src/main/res/values/strings.xml
new file mode 100644 (file)
index 0000000..c6a638a
--- /dev/null
@@ -0,0 +1,3 @@
+<resources>
+    <string name="app_name">Device Discovery Client</string>
+</resources>
diff --git a/android/examples/devicediscoveryclient/src/main/res/values/styles.xml b/android/examples/devicediscoveryclient/src/main/res/values/styles.xml
new file mode 100644 (file)
index 0000000..ff6c9d2
--- /dev/null
@@ -0,0 +1,8 @@
+<resources>
+
+    <!-- Base application theme. -->
+    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- Customize your theme here. -->
+    </style>
+
+</resources>
diff --git a/android/examples/devicediscoveryserver/.gitignore b/android/examples/devicediscoveryserver/.gitignore
new file mode 100644 (file)
index 0000000..796b96d
--- /dev/null
@@ -0,0 +1 @@
+/build
diff --git a/android/examples/devicediscoveryserver/build.gradle b/android/examples/devicediscoveryserver/build.gradle
new file mode 100644 (file)
index 0000000..7b7bd0d
--- /dev/null
@@ -0,0 +1,24 @@
+apply plugin: 'com.android.application'
+
+android {
+    compileSdkVersion 22
+    buildToolsVersion "22.0.1"
+
+    defaultConfig {
+        applicationId "org.iotivity.base.examples.devicediscoveryserver"
+        minSdkVersion 21
+        targetSdkVersion 22
+        versionCode 1
+        versionName "1.0"
+    }
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+        }
+    }
+}
+
+dependencies {
+    compile fileTree(dir: 'libs', include: ['*.jar'])
+}
diff --git a/android/examples/devicediscoveryserver/devicediscoveryserver.iml b/android/examples/devicediscoveryserver/devicediscoveryserver.iml
new file mode 100644 (file)
index 0000000..56b2db8
--- /dev/null
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.id=":devicediscoveryserver" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="examples" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="android-gradle" name="Android-Gradle">
+      <configuration>
+        <option name="GRADLE_PROJECT_PATH" value=":devicediscoveryserver" />
+      </configuration>
+    </facet>
+    <facet type="android" name="Android">
+      <configuration>
+        <option name="SELECTED_BUILD_VARIANT" value="debug" />
+        <option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
+        <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
+        <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
+        <option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
+        <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
+        <option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugTestSources" />
+        <option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
+        <option name="ALLOW_USER_CONFIGURATION" value="false" />
+        <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
+        <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
+        <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
+        <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
+      </configuration>
+    </facet>
+  </component>
+  <component name="NewModuleRootManager" inherit-compiler-output="false">
+    <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
+    <output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
+      <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
+    </content>
+    <orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" exported="" name="iotivity-armeabi-base-debug-unspecified" level="project" />
+  </component>
+</module>
\ No newline at end of file
diff --git a/android/examples/devicediscoveryserver/proguard-rules.pro b/android/examples/devicediscoveryserver/proguard-rules.pro
new file mode 100644 (file)
index 0000000..d26150c
--- /dev/null
@@ -0,0 +1,17 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in /home/rahul/sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
diff --git a/android/examples/devicediscoveryserver/src/main/AndroidManifest.xml b/android/examples/devicediscoveryserver/src/main/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..fbdd71f
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.iotivity.base.examples" >
+
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.BLUETOOTH"/>
+    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
+    <uses-permission android:name="android.permission.INTERNET"/>
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
+    <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
+    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
+    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
+
+    <application
+        android:allowBackup="true"
+        android:icon="@mipmap/iotivityicon"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:screenOrientation="portrait"
+            android:name=".DeviceDiscoveryServer"
+            android:label="@string/app_name" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>
diff --git a/android/examples/devicediscoveryserver/src/main/java/org/iotivity/base/examples/DeviceDiscoveryServer.java b/android/examples/devicediscoveryserver/src/main/java/org/iotivity/base/examples/DeviceDiscoveryServer.java
new file mode 100644 (file)
index 0000000..b022f0c
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Intel Corporation.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * //      http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+package org.iotivity.base.examples;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.text.method.ScrollingMovementMethod;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.ScrollView;
+import android.widget.TextView;
+
+import org.iotivity.base.ModeType;
+import org.iotivity.base.OcDeviceInfo;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcPlatformInfo;
+import org.iotivity.base.PlatformConfig;
+import org.iotivity.base.QualityOfService;
+import org.iotivity.base.ServiceType;
+
+/**
+ * This sample demonstrates platform and device discovery feature.
+ * The server sets the platform and device related info. which can be later retrieved by a client.
+ */
+public class DeviceDiscoveryServer extends Activity {
+
+    private void startDeviceDiscoveryServer() {
+        Context context = this;
+
+        PlatformConfig platformConfig = new PlatformConfig(
+                context,
+                ServiceType.IN_PROC,
+                ModeType.SERVER,
+                "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+                0,         // Uses randomly available port
+                QualityOfService.LOW
+        );
+
+        msg("Configuring platform.");
+        OcPlatform.Configure(platformConfig);
+
+        OcDeviceInfo deviceInfo = new OcDeviceInfo("myDeviceName");
+        try {
+            msg("Registering device info");
+            OcPlatform.registerDeviceInfo(deviceInfo);
+        } catch (OcException e) {
+            Log.e(TAG, e.toString());
+            msg("Failed to register device info.");
+        }
+
+        OcPlatformInfo platformInfo = new OcPlatformInfo(
+                "myPlatformId",             //Platform ID
+                "myManufactName",           //Manufacturer Name
+                "www.myurl.com",            //Manufacturer URL
+                "myModelNumber",            //Model Number
+                "myDateOfManufacture",      //Date of Manufacture
+                "myPlatformVersion",        //Platform Version
+                "Manufacturer OS version",  //Operating System Version
+                "myHardwareVersion",        //Hardware Version
+                "myFirmwareVersion",        //Firmware Version
+                "www.mysupporturl.com",     //Support URL
+                String.valueOf(System.currentTimeMillis()) // System Time
+        );
+        try {
+            msg("Registering platform info");
+            OcPlatform.registerPlatformInfo(platformInfo);
+        } catch (OcException e) {
+            Log.e(TAG, e.toString());
+            msg("Failed to register platform info.");
+        }
+
+        msg("Waiting for the requests...");
+        printLine();
+    }
+
+    //******************************************************************************
+    // End of the OIC specific code
+    //******************************************************************************
+
+    private final static String TAG = DeviceDiscoveryServer.class.getSimpleName();
+    private TextView mConsoleTextView;
+    private ScrollView mScrollView;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_device_discovery_server);
+
+        mConsoleTextView = (TextView) findViewById(R.id.consoleTextView);
+        mConsoleTextView.setMovementMethod(new ScrollingMovementMethod());
+        mScrollView = (ScrollView) findViewById(R.id.scrollView);
+        mScrollView.fullScroll(View.FOCUS_DOWN);
+        final Button button = (Button) findViewById(R.id.button);
+
+        if (null == savedInstanceState) {
+            button.setOnClickListener(new View.OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    button.setEnabled(false);
+                    new Thread(new Runnable() {
+                        public void run() {
+                            startDeviceDiscoveryServer();
+                        }
+                    }).start();
+                }
+            });
+        } else {
+            String consoleOutput = savedInstanceState.getString("consoleOutputString");
+            mConsoleTextView.setText(consoleOutput);
+        }
+    }
+
+    @Override
+    protected void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        outState.putString("consoleOutputString", mConsoleTextView.getText().toString());
+    }
+
+    @Override
+    protected void onRestoreInstanceState(Bundle savedInstanceState) {
+        super.onRestoreInstanceState(savedInstanceState);
+
+        String consoleOutput = savedInstanceState.getString("consoleOutputString");
+        mConsoleTextView.setText(consoleOutput);
+    }
+
+    private void msg(final String text) {
+        runOnUiThread(new Runnable() {
+            public void run() {
+                mConsoleTextView.append("\n");
+                mConsoleTextView.append(text);
+                mScrollView.fullScroll(View.FOCUS_DOWN);
+            }
+        });
+        Log.i(TAG, text);
+    }
+
+    private void printLine() {
+        msg("------------------------------------------------------------------------");
+    }
+}
diff --git a/android/examples/devicediscoveryserver/src/main/res/drawable/iotivityicon.png b/android/examples/devicediscoveryserver/src/main/res/drawable/iotivityicon.png
new file mode 100644 (file)
index 0000000..e1e4aa7
Binary files /dev/null and b/android/examples/devicediscoveryserver/src/main/res/drawable/iotivityicon.png differ
diff --git a/android/examples/devicediscoveryserver/src/main/res/drawable/iotivitylogo.png b/android/examples/devicediscoveryserver/src/main/res/drawable/iotivitylogo.png
new file mode 100644 (file)
index 0000000..a7d3115
Binary files /dev/null and b/android/examples/devicediscoveryserver/src/main/res/drawable/iotivitylogo.png differ
diff --git a/android/examples/devicediscoveryserver/src/main/res/layout/activity_device_discovery_server.xml b/android/examples/devicediscoveryserver/src/main/res/layout/activity_device_discovery_server.xml
new file mode 100644 (file)
index 0000000..78258b5
--- /dev/null
@@ -0,0 +1,37 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
+android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
+android:orientation="vertical"
+android:paddingRight="@dimen/activity_horizontal_margin"
+android:paddingTop="@dimen/activity_vertical_margin"
+android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".DeviceDiscoveryServer">
+    <Button
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:id="@+id/button"
+        android:layout_centerHorizontal="true"
+        android:textOff="Start"
+        android:textOn="Stop"
+        android:layout_alignParentEnd="true"
+        android:layout_alignParentStart="true"
+        android:text="Start" />
+    <ScrollView
+        android:layout_below="@id/button"
+        android:layout_above="@+id/imageView"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:fillViewport="true"
+        android:id="@+id/scrollView">
+        <TextView android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:id="@+id/consoleTextView" />
+    </ScrollView>
+    <ImageView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:id="@+id/imageView"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentEnd="true"
+        android:layout_alignParentStart="true"
+        android:src="@drawable/iotivitylogo" />
+</RelativeLayout>
\ No newline at end of file
diff --git a/android/examples/devicediscoveryserver/src/main/res/mipmap-hdpi/iotivityicon.png b/android/examples/devicediscoveryserver/src/main/res/mipmap-hdpi/iotivityicon.png
new file mode 100644 (file)
index 0000000..e1e4aa7
Binary files /dev/null and b/android/examples/devicediscoveryserver/src/main/res/mipmap-hdpi/iotivityicon.png differ
diff --git a/android/examples/devicediscoveryserver/src/main/res/mipmap-mdpi/iotivityicon.png b/android/examples/devicediscoveryserver/src/main/res/mipmap-mdpi/iotivityicon.png
new file mode 100644 (file)
index 0000000..2e7bce6
Binary files /dev/null and b/android/examples/devicediscoveryserver/src/main/res/mipmap-mdpi/iotivityicon.png differ
diff --git a/android/examples/devicediscoveryserver/src/main/res/mipmap-xhdpi/iotivityicon.png b/android/examples/devicediscoveryserver/src/main/res/mipmap-xhdpi/iotivityicon.png
new file mode 100644 (file)
index 0000000..afa486b
Binary files /dev/null and b/android/examples/devicediscoveryserver/src/main/res/mipmap-xhdpi/iotivityicon.png differ
diff --git a/android/examples/devicediscoveryserver/src/main/res/mipmap-xxhdpi/iotivityicon.png b/android/examples/devicediscoveryserver/src/main/res/mipmap-xxhdpi/iotivityicon.png
new file mode 100644 (file)
index 0000000..3e6bc6a
Binary files /dev/null and b/android/examples/devicediscoveryserver/src/main/res/mipmap-xxhdpi/iotivityicon.png differ
diff --git a/android/examples/devicediscoveryserver/src/main/res/values-v21/styles.xml b/android/examples/devicediscoveryserver/src/main/res/values-v21/styles.xml
new file mode 100644 (file)
index 0000000..dba3c41
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <style name="AppTheme" parent="android:Theme.Material.Light">
+    </style>
+</resources>
diff --git a/android/examples/devicediscoveryserver/src/main/res/values-w820dp/dimens.xml b/android/examples/devicediscoveryserver/src/main/res/values-w820dp/dimens.xml
new file mode 100644 (file)
index 0000000..63fc816
--- /dev/null
@@ -0,0 +1,6 @@
+<resources>
+    <!-- Example customization of dimensions originally defined in res/values/dimens.xml
+         (such as screen margins) for screens with more than 820dp of available width. This
+         would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
+    <dimen name="activity_horizontal_margin">64dp</dimen>
+</resources>
diff --git a/android/examples/devicediscoveryserver/src/main/res/values/dimens.xml b/android/examples/devicediscoveryserver/src/main/res/values/dimens.xml
new file mode 100644 (file)
index 0000000..47c8224
--- /dev/null
@@ -0,0 +1,5 @@
+<resources>
+    <!-- Default screen margins, per the Android Design guidelines. -->
+    <dimen name="activity_horizontal_margin">16dp</dimen>
+    <dimen name="activity_vertical_margin">16dp</dimen>
+</resources>
diff --git a/android/examples/devicediscoveryserver/src/main/res/values/strings.xml b/android/examples/devicediscoveryserver/src/main/res/values/strings.xml
new file mode 100644 (file)
index 0000000..7002528
--- /dev/null
@@ -0,0 +1,3 @@
+<resources>
+    <string name="app_name">Device Discovery Server</string>
+</resources>
diff --git a/android/examples/devicediscoveryserver/src/main/res/values/styles.xml b/android/examples/devicediscoveryserver/src/main/res/values/styles.xml
new file mode 100644 (file)
index 0000000..ff6c9d2
--- /dev/null
@@ -0,0 +1,8 @@
+<resources>
+
+    <!-- Base application theme. -->
+    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- Customize your theme here. -->
+    </style>
+
+</resources>
index ddb5f29..c7e2a4f 100644 (file)
@@ -5,7 +5,7 @@ android {
     buildToolsVersion "22.0.1"
 
     defaultConfig {
-        applicationId "org.iotivity.base.examples"
+        applicationId "org.iotivity.base.examples.presenceclient"
         minSdkVersion 21
         targetSdkVersion 22
         versionCode 1
index df7d065..d4e6866 100644 (file)
@@ -1,28 +1,28 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="org.iotivity.base.examples" >
+    package="org.iotivity.base.examples">
 
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
-    <uses-permission android:name="android.permission.BLUETOOTH"/>
-    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
-    <uses-permission android:name="android.permission.INTERNET"/>
-    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
-    <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
-    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
-    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
-    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
+    <uses-permission android:name="android.permission.BLUETOOTH" />
+    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+    <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
+    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
 
 
     <application
         android:allowBackup="true"
         android:icon="@mipmap/iotivityicon"
         android:label="@string/app_name"
-        android:theme="@style/AppTheme" >
+        android:theme="@style/AppTheme">
         <activity
-            android:screenOrientation="portrait"
             android:name=".PresenceClient"
-            android:label="@string/app_name" >
+            android:label="@string/app_name"
+            android:screenOrientation="portrait">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
 
index 237ae27..2a9b0f0 100644 (file)
@@ -39,22 +39,23 @@ import org.iotivity.base.OcPlatform;
 import org.iotivity.base.OcPresenceHandle;
 import org.iotivity.base.OcPresenceStatus;
 import org.iotivity.base.OcResource;
-import org.iotivity.base.OcResourceHandle;
 import org.iotivity.base.PlatformConfig;
 import org.iotivity.base.QualityOfService;
-import org.iotivity.base.ResourceProperty;
 import org.iotivity.base.ServiceType;
 
 import java.util.EnumSet;
-import java.util.LinkedList;
-import java.util.List;
-
 
+/**
+ * A client example for presence notification
+ */
 public class PresenceClient extends Activity implements
         OcPlatform.OnResourceFoundListener,
         OcPlatform.OnPresenceListener {
+    private final static String TAG = PresenceClient.class.getSimpleName();
     private OcResource mResource;
     private OcPresenceHandle mPresenceHandle;
+    private TextView mConsoleTextView;
+    private ScrollView mScrollView;
 
     private void startPresenceClient() {
         Context context = this;
@@ -83,6 +84,10 @@ public class PresenceClient extends Activity implements
         enableStartStopButton();
     }
 
+    //******************************************************************************
+    // End of the OIC specific code
+    //******************************************************************************
+
     @Override
     public synchronized void onResourceFound(OcResource foundResource) {
         String resourceUri = foundResource.getUri();
@@ -151,14 +156,6 @@ public class PresenceClient extends Activity implements
         enableStartStopButton();
     }
 
-    //******************************************************************************
-    // End of the OIC specific code
-    //******************************************************************************
-
-    private final static String TAG = PresenceClient.class.getSimpleName();
-    private TextView mConsoleTextView;
-    private ScrollView mScrollView;
-
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -189,9 +186,7 @@ public class PresenceClient extends Activity implements
                     }
                 }
             });
-        }
-
-        if (null != savedInstanceState) {
+        } else {
             String consoleOutput = savedInstanceState.getString("consoleOutputString");
             mConsoleTextView.setText(consoleOutput);
             boolean buttonCheked = savedInstanceState.getBoolean("toggleButtonChecked");
@@ -234,15 +229,6 @@ public class PresenceClient extends Activity implements
         msg("------------------------------------------------------------------------");
     }
 
-    private void sleep(int seconds) {
-        try {
-            Thread.sleep(seconds * 1000);
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-            Log.e(TAG, e.toString());
-        }
-    }
-
     private void enableStartStopButton() {
         runOnUiThread(new Runnable() {
             public void run() {
index ac5037f..b02eded 100644 (file)
@@ -1,34 +1,42 @@
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
-    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
     android:orientation="vertical"
+    android:paddingBottom="@dimen/activity_vertical_margin"
+    android:paddingLeft="@dimen/activity_horizontal_margin"
     android:paddingRight="@dimen/activity_horizontal_margin"
     android:paddingTop="@dimen/activity_vertical_margin"
-    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".PresenceClient">
+    tools:context=".PresenceClient">
+
     <ToggleButton
+        android:id="@+id/toggleButton"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:id="@+id/toggleButton"
+        android:layout_alignParentEnd="true"
+        android:layout_alignParentStart="true"
         android:layout_centerHorizontal="true"
         android:textOff="Start"
-        android:textOn="Stop"
-        android:layout_alignParentEnd="true"
-        android:layout_alignParentStart="true" />
+        android:textOn="Stop" />
+
     <ScrollView
-        android:layout_below="@id/toggleButton"
-        android:layout_above="@+id/imageView"
+        android:id="@+id/scrollView"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
-        android:fillViewport="true"
-        android:id="@+id/scrollView">
-        <TextView android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:id="@+id/consoleTextView" />
+        android:layout_above="@+id/imageView"
+        android:layout_below="@id/toggleButton"
+        android:fillViewport="true">
+
+        <TextView
+            android:id="@+id/consoleTextView"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content" />
     </ScrollView>
+
     <ImageView
+        android:id="@+id/imageView"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:id="@+id/imageView"
         android:layout_alignParentBottom="true"
         android:layout_alignParentEnd="true"
         android:layout_alignParentStart="true"
index dba3c41..e9d9014 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-    <style name="AppTheme" parent="android:Theme.Material.Light">
-    </style>
+
+    <style name="AppTheme" parent="android:Theme.Material.Light"></style>
 </resources>
index 809c8ff..0c61f27 100644 (file)
@@ -26,29 +26,26 @@ import android.content.Context;
 import android.os.Bundle;
 import android.text.method.ScrollingMovementMethod;
 import android.util.Log;
-
 import android.view.View;
 import android.widget.CompoundButton;
 import android.widget.ScrollView;
 import android.widget.TextView;
 import android.widget.ToggleButton;
 
-import org.iotivity.base.EntityHandlerResult;
 import org.iotivity.base.ModeType;
 import org.iotivity.base.OcException;
 import org.iotivity.base.OcPlatform;
 import org.iotivity.base.OcResourceHandle;
-import org.iotivity.base.OcResourceRequest;
 import org.iotivity.base.PlatformConfig;
 import org.iotivity.base.QualityOfService;
 import org.iotivity.base.ResourceProperty;
 import org.iotivity.base.ServiceType;
 
 import java.util.EnumSet;
-import java.util.LinkedList;
-import java.util.List;
-
 
+/**
+ * A server example for presence notification
+ */
 public class PresenceServer extends Activity {
     private OcResourceHandle mResourceHandle;
 
@@ -159,9 +156,7 @@ public class PresenceServer extends Activity {
                     }
                 }
             });
-        }
-
-        if (null != savedInstanceState) {
+        } else {
             String consoleOutput = savedInstanceState.getString("consoleOutputString");
             mConsoleTextView.setText(consoleOutput);
             boolean buttonCheked = savedInstanceState.getBoolean("toggleButtonChecked");
index 0237a05..388afde 100755 (executable)
@@ -1 +1 @@
-include ':simpleserver', ':simpleclient', ':message', ':fridgeserver', ':fridgeclient', ':guiclient', ':presenceserver', ':presenceclient'
+include ':simpleserver', ':simpleclient', ':message', ':fridgeserver', ':fridgeclient', ':guiclient', ':presenceserver', ':presenceclient', ':devicediscoveryclient', ':devicediscoveryserver', ':iotivity-armeabi-base-debug'