From: jihwanseo Date: Mon, 28 Mar 2016 07:16:18 +0000 (+0900) Subject: removed CASample App for CA X-Git-Tag: 1.2.0+RC1~478 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bae922f874d686b72657385a8f465f74475af0f9;p=platform%2Fupstream%2Fiotivity.git removed CASample App for CA since simpleserver and simpleclient can be covered it. remove all sample sources. Change-Id: Ib5960c0e9ee3ef8093718f0dd5f0e93b3db8e16f Signed-off-by: jihwan.seo Signed-off-by: Abhishek Sharma Signed-off-by: jihwan.seo Reviewed-on: https://gerrit.iotivity.org/gerrit/7381 Tested-by: jenkins-iotivity Reviewed-by: Tim Kourt Reviewed-by: Jon A. Cruz Signed-off-by: jihwan.seo Reviewed-on: https://gerrit.iotivity.org/gerrit/7463 --- diff --git a/auto_build.sh b/auto_build.sh index 1a279d0..aa2dcd4 100755 --- a/auto_build.sh +++ b/auto_build.sh @@ -142,12 +142,6 @@ function build_tizen() echo "*********** Build for Tizen *************" ./gbsbuild.sh - echo "*********** Build for Tizen CA lib and sample *************" - scons -f resource/csdk/connectivity/build/tizen/SConscript TARGET_OS=tizen TARGET_TRANSPORT=IP LOGGING=true RELEASE=$1 $2 - - echo "*********** Build for Tizen CA lib and sample with Security *************" - scons -f resource/csdk/connectivity/build/tizen/SConscript TARGET_OS=tizen TARGET_TRANSPORT=IP LOGGING=true SECURED=1 RELEASE=$1 $2 - echo "*********** Build for Tizen octbstack lib and sample *************" scons -f resource/csdk/stack/samples/tizen/build/SConscript TARGET_OS=tizen TARGET_TRANSPORT=IP LOGGING=true RELEASE=$1 $2 diff --git a/resource/csdk/connectivity/samples/android/SConscript b/resource/csdk/connectivity/samples/android/SConscript deleted file mode 100644 index 6fe7388..0000000 --- a/resource/csdk/connectivity/samples/android/SConscript +++ /dev/null @@ -1,55 +0,0 @@ -## -# Building sample application -## - -Import('env') - -app_env = env.Clone() - -ca_os = app_env.get('TARGET_OS') -ca_transport = app_env.get('TARGET_TRANSPORT') -secured = app_env.get('SECURED') - -root_dir = './../../' -main_dir = Dir('.').srcnode().abspath -jni_dir = main_dir + '/sample_serivce/android/jni' -env.PrependUnique(CPPPATH = ['jni_dir']) -app_env.PrependUnique(CPPDEFINES = ['__ANDROID__']) - -##################################################################### -# Source files and Target(s) -###################################################################### - -print"Reading ca script %s"%ca_transport - -app_env.AppendUnique(CPPPATH = [root_dir + '/api/']) -app_env.AppendUnique(CPPPATH = [root_dir + '/inc/']) -app_env.AppendUnique(CPPPATH = [root_dir + '/common/inc/']) -app_env.AppendUnique(CPPPATH = [root_dir + 'lib/libcoap-4.1.1']) - -print "Reading sample application build script" - -build_dir = app_env.get('BUILD_DIR') -secured = app_env.get('SECURED') - -print "Sample secured flag is %s" % secured - -sample_dir = 'casample/sampleService/src/main/jni/' -sample_src = [sample_dir + 'ResourceModel.c',] - -print " sample src %s" % sample_src - -app_env.AppendUnique(LIBPATH = [app_env.get('BUILD_DIR'), '.',]) -app_env.AppendUnique(CPPPATH = ['lib/android']) -app_env.PrependUnique(LIBS = ['connectivity_abstraction']) -app_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined']) - - -if secured == '1': - app_env.AppendUnique(CPPPATH = [root_dir + 'external/inc/']) - app_env.PrependUnique(CPPDEFINES = ['__WITH_DTLS__']) - -libRMInterface = app_env.SharedLibrary('RMInterface', sample_src, OBJPREFIX='libRMInterface_') -app_env.InstallTarget(libRMInterface, 'RMInterface') - - diff --git a/resource/csdk/connectivity/samples/android/casample/.gitignore b/resource/csdk/connectivity/samples/android/casample/.gitignore deleted file mode 100644 index 6f9b76a..0000000 --- a/resource/csdk/connectivity/samples/android/casample/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -local.properties -import-summary.txt -/.idea/ -/.gradle/ -/build/ diff --git a/resource/csdk/connectivity/samples/android/casample/SConscript b/resource/csdk/connectivity/samples/android/casample/SConscript deleted file mode 100644 index e285068..0000000 --- a/resource/csdk/connectivity/samples/android/casample/SConscript +++ /dev/null @@ -1,28 +0,0 @@ -import os -import platform -Import('env') - -ANDROID_TARGET_ARCH = env.get('TARGET_ARCH') -if env.get('RELEASE'): - ANDROID_RELEASE="release" -else: - ANDROID_RELEASE="debug" - -print ''' -***************************************** Info ******************************** -* NOTE: If you have a problem in downloading the gradle-core-1.1.0.jar file * -* please do one time setup as below * -* * -* Edit resource/csdk/connectivity/samples/android/casample/gradle.properties * -* Add the proxy information as below : * -* systemProp.http.proxyPort= * -* systemProp.http.proxyHost= * -* systemProp.https.proxyPort= * -* systemProp.https.proxyHost= * -* * -******************************************************************************* -''' -jdk_env = Environment(ENV=os.environ) -jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + Dir('.').srcnode().abspath + '/build.gradle -PTARGET_ARCH=%s -PRELEASE=%s' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE)) -jdk_env.Gradle(target="base/objs", source="sampleService/src/main/java/org/iotivity/ca/service/MainActivity.java") - diff --git a/resource/csdk/connectivity/samples/android/casample/build.gradle b/resource/csdk/connectivity/samples/android/casample/build.gradle deleted file mode 100755 index 2712137..0000000 --- a/resource/csdk/connectivity/samples/android/casample/build.gradle +++ /dev/null @@ -1,21 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. -buildscript { - repositories { - jcenter() - { - url "http://jcenter.bintray.com" - } - } - dependencies { - classpath 'com.android.tools.build:gradle:1.3.0' - } -} - -allprojects { - repositories { - jcenter() - { - url "http://jcenter.bintray.com" - } - } -} diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/.gitignore b/resource/csdk/connectivity/samples/android/casample/cAInterface/.gitignore deleted file mode 100644 index 84c048a..0000000 --- a/resource/csdk/connectivity/samples/android/casample/cAInterface/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build/ diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/build.gradle b/resource/csdk/connectivity/samples/android/casample/cAInterface/build.gradle deleted file mode 100755 index 6ca1fe0..0000000 --- a/resource/csdk/connectivity/samples/android/casample/cAInterface/build.gradle +++ /dev/null @@ -1,26 +0,0 @@ -apply plugin: 'com.android.library' - -android { - compileSdkVersion 21 - buildToolsVersion "20.0.0" - - defaultConfig { - minSdkVersion 21 - targetSdkVersion 21 - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' - } - } - - lintOptions { - abortOnError false - } -} - -dependencies { -// compile 'com.android.support:support-v4:21.0.3' -} diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/cAInterface.iml b/resource/csdk/connectivity/samples/android/casample/cAInterface/cAInterface.iml deleted file mode 100755 index 217b60e..0000000 --- a/resource/csdk/connectivity/samples/android/casample/cAInterface/cAInterface.iml +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/.gitignore b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/.gitignore deleted file mode 100644 index 7cf58ac..0000000 --- a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/assets/ diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/AndroidManifest.xml b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/AndroidManifest.xml deleted file mode 100755 index 4bc64f6..0000000 --- a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/AndroidManifest.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaEdrInterface.java b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaEdrInterface.java deleted file mode 100644 index 7a07b24..0000000 --- a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaEdrInterface.java +++ /dev/null @@ -1,92 +0,0 @@ -/****************************************************************** - * - * Copyright 2014 Samsung Electronics All Rights Reserved. - * - * - * - * 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.ca; - -import android.bluetooth.BluetoothAdapter; -import android.bluetooth.BluetoothDevice; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; - -public class CaEdrInterface { - private static Context mContext; - - private CaEdrInterface(Context context) { - mContext = context; - registerIntentFilter(); - } - - private static IntentFilter registerIntentFilter() { - IntentFilter filter = new IntentFilter(); - filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); - filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); - mContext.registerReceiver(mReceiver, filter); - return filter; - } - - public static void destroyEdrInterface() { - mContext.unregisterReceiver(mReceiver); - } - - // Network Monitor - private native static void caEdrStateChangedCallback(int state); - - private native static void caEdrBondStateChangedCallback(String addr); - - private static final BroadcastReceiver mReceiver = new BroadcastReceiver() { - - @Override - public void onReceive(Context context, Intent intent) { - - String action = intent.getAction(); - - if (action != null && action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { - - int state = - intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); - - // STATE_ON:12, STATE_OFF:10 - if (state == BluetoothAdapter.STATE_ON || state == BluetoothAdapter.STATE_OFF) - { - caEdrStateChangedCallback(state); - } - } - - if (action != null && action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) { - - int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, - BluetoothDevice.ERROR); - - if (bondState == BluetoothDevice.BOND_NONE) { - if ((intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, - BluetoothDevice.ERROR) - == BluetoothDevice.BOND_BONDED)) { - BluetoothDevice device - = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); - - caEdrBondStateChangedCallback(device.getAddress()); - } - } - } - } - }; -} diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaIpInterface.java b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaIpInterface.java deleted file mode 100644 index 1b85af5..0000000 --- a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaIpInterface.java +++ /dev/null @@ -1,72 +0,0 @@ -/****************************************************************** - * - * Copyright 2014 Samsung Electronics All Rights Reserved. - * - * - * - * 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.ca; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.net.wifi.WifiManager; - -public class CaIpInterface { - private static Context mContext; - - private CaIpInterface(Context context) { - mContext = context; - registerIpStateReceiver(); - } - - private void registerIpStateReceiver() { - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); - intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); - - mContext.registerReceiver(mReceiver, intentFilter); - } - - public static void destroyIpInterface() { - mContext.unregisterReceiver(mReceiver); - } - - private static BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, - WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_DISABLED) { - caIpStateDisabled(); - } else if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { - ConnectivityManager manager = (ConnectivityManager) - mContext.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo nwInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); - - if(nwInfo.isConnected()) { - caIpStateEnabled(); - } - } - } - }; - - private native static void caIpStateEnabled(); - - private native static void caIpStateDisabled(); -} \ No newline at end of file diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaLeClientInterface.java b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaLeClientInterface.java deleted file mode 100644 index 019438a..0000000 --- a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaLeClientInterface.java +++ /dev/null @@ -1,276 +0,0 @@ -/****************************************************************** - * - * Copyright 2014 Samsung Electronics All Rights Reserved. - * - * - * - * 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.ca; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -import android.bluetooth.BluetoothAdapter; -import android.bluetooth.BluetoothDevice; -import android.bluetooth.BluetoothGatt; -import android.bluetooth.BluetoothGattCallback; -import android.bluetooth.BluetoothGattCharacteristic; -import android.bluetooth.BluetoothGattDescriptor; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.util.Log; - -public class CaLeClientInterface { - - private static String SERVICE_UUID = "ADE3D529-C784-4F63-A987-EB69F70EE816"; - private static String TAG = "Sample_Service : CaLeClientInterface"; - private static Context mContext; - - private CaLeClientInterface(Context context) { - caLeRegisterLeScanCallback(mLeScanCallback); - caLeRegisterGattCallback(mGattCallback); - mContext = context; - registerIntentFilter(); - } - - public static void getLeScanCallback() { - caLeRegisterLeScanCallback(mLeScanCallback); - } - - public static void getLeGattCallback() { - caLeRegisterGattCallback(mGattCallback); - } - - private static IntentFilter registerIntentFilter() { - IntentFilter filter = new IntentFilter(); - filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); - filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); - mContext.registerReceiver(mReceiver, filter); - return filter; - } - - public static void destroyLeInterface() { - mContext.unregisterReceiver(mReceiver); - } - - private native static void caLeRegisterLeScanCallback(BluetoothAdapter.LeScanCallback callback); - - private native static void caLeRegisterGattCallback(BluetoothGattCallback callback); - - // BluetoothAdapter.LeScanCallback - private native static void caLeScanCallback(BluetoothDevice device); - - // BluetoothGattCallback - private native static void caLeGattConnectionStateChangeCallback( - BluetoothGatt gatt, int status, int newState); - - private native static void caLeGattServicesDiscoveredCallback(BluetoothGatt gatt, int status); - - private native static void caLeGattCharacteristicWriteCallback( - BluetoothGatt gatt, byte[] data, int status); - - private native static void caLeGattCharacteristicChangedCallback( - BluetoothGatt gatt, byte[] data); - - private native static void caLeGattDescriptorWriteCallback(BluetoothGatt gatt, int status); - - private native static void caLeGattReliableWriteCompletedCallback(BluetoothGatt gatt, - int status); - - private native static void caLeGattReadRemoteRssiCallback(BluetoothGatt gatt, int rssi, - int status); - - // Network Monitor - private native static void caLeStateChangedCallback(int state); - - // bond state - private native static void caLeBondStateChangedCallback(String address); - - // Callback - private static BluetoothAdapter.LeScanCallback mLeScanCallback = - new BluetoothAdapter.LeScanCallback() { - - @Override - public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { - - try { - List uuids = getUuids(scanRecord); - for (UUID uuid : uuids) { - Log.d(TAG, "UUID : " + uuid.toString()); - if(uuid.toString().contains(SERVICE_UUID.toLowerCase())) { - Log.d(TAG, "we found that has the Device"); - caLeScanCallback(device); - } - } - } catch(UnsatisfiedLinkError e) { - - } - } - }; - - private static List getUuids(final byte[] scanRecord) { - List uuids = new ArrayList(); - - int offset = 0; - while (offset < (scanRecord.length - 2)) { - int len = scanRecord[offset++]; - if (len == 0) - break; - - int type = scanRecord[offset++]; - - switch (type) { - case 0x02: - case 0x03: - while (len > 1) { - int uuid16 = scanRecord[offset++]; - uuid16 += (scanRecord[offset++] << 8); - len -= 2; - uuids.add(UUID.fromString(String.format( - "%08x-0000-1000-8000-00805f9b34fb", uuid16))); - } - break; - case 0x06: - case 0x07: - while (len >= 16) { - try { - ByteBuffer buffer = ByteBuffer.wrap(scanRecord, offset++, 16). - order(ByteOrder.LITTLE_ENDIAN); - long mostSigBits = buffer.getLong(); - long leastSigBits = buffer.getLong(); - uuids.add(new UUID(leastSigBits, mostSigBits)); - } catch (IndexOutOfBoundsException e) { - Log.e(TAG, e.toString()); - continue; - } finally { - offset += 15; - len -= 16; - } - } - break; - default: - offset += (len - 1); - break; - } - } - return uuids; - } - - private static final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { - - @Override - public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { - super.onConnectionStateChange(gatt, status, newState); - - caLeGattConnectionStateChangeCallback(gatt, status, newState); - } - - @Override - public void onServicesDiscovered(BluetoothGatt gatt, int status) { - super.onServicesDiscovered(gatt, status); - - caLeGattServicesDiscoveredCallback(gatt, status); - } - - @Override - public void onCharacteristicRead(BluetoothGatt gatt, - BluetoothGattCharacteristic characteristic, int status) { - super.onCharacteristicRead(gatt, characteristic, status); - } - - @Override - public void onCharacteristicWrite(BluetoothGatt gatt, - BluetoothGattCharacteristic characteristic, int status) { - super.onCharacteristicWrite(gatt, characteristic, status); - - caLeGattCharacteristicWriteCallback(gatt, characteristic.getValue(), status); - } - - @Override - public void onCharacteristicChanged(BluetoothGatt gatt, - BluetoothGattCharacteristic characteristic) { - super.onCharacteristicChanged(gatt, characteristic); - - caLeGattCharacteristicChangedCallback(gatt, characteristic.getValue()); - } - - @Override - public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, - int status) { - super.onDescriptorRead(gatt, descriptor, status); - } - - @Override - public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, - int status) { - super.onDescriptorWrite(gatt, descriptor, status); - - caLeGattDescriptorWriteCallback(gatt, status); - } - - @Override - public void onReliableWriteCompleted(BluetoothGatt gatt, int status) { - super.onReliableWriteCompleted(gatt, status); - } - - @Override - public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) { - super.onReadRemoteRssi(gatt, rssi, status); - } - }; - - private static final BroadcastReceiver mReceiver = new BroadcastReceiver() { - - @Override - public void onReceive(Context context, Intent intent) { - - String action = intent.getAction(); - - if (action != null && action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { - - int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, - BluetoothAdapter.ERROR); - - if (state == BluetoothAdapter.STATE_ON || state == BluetoothAdapter.STATE_OFF) - { - caLeStateChangedCallback(state); - } - } - - if (action != null && action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) { - - int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, - BluetoothDevice.ERROR); - - if (bondState == BluetoothDevice.BOND_NONE) { - if ((intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, - BluetoothDevice.ERROR) == BluetoothDevice.BOND_BONDED)) { - BluetoothDevice device = intent - .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); - - caLeBondStateChangedCallback(device.getAddress()); - } - } - } - } - }; -} - diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaLeServerInterface.java b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaLeServerInterface.java deleted file mode 100644 index b2ed163..0000000 --- a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaLeServerInterface.java +++ /dev/null @@ -1,155 +0,0 @@ -/****************************************************************** - * - * Copyright 2014 Samsung Electronics All Rights Reserved. - * - * - * - * 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.ca; - -import android.bluetooth.BluetoothDevice; -import android.bluetooth.BluetoothGattCharacteristic; -import android.bluetooth.BluetoothGattDescriptor; -import android.bluetooth.BluetoothGattServerCallback; -import android.bluetooth.BluetoothGattService; -import android.bluetooth.le.AdvertiseCallback; -import android.bluetooth.le.AdvertiseSettings; - -public class CaLeServerInterface { - - private CaLeServerInterface() { - - caLeRegisterGattServerCallback(mGattServerCallback); - caLeRegisterBluetoothLeAdvertiseCallback(mAdvertiseCallback); - } - - public static void getLeGattServerCallback() { - caLeRegisterGattServerCallback(mGattServerCallback); - } - - public static void getBluetoothLeAdvertiseCallback() { - caLeRegisterBluetoothLeAdvertiseCallback(mAdvertiseCallback); - } - - private native static void caLeRegisterGattServerCallback(BluetoothGattServerCallback callback); - - private native static void caLeRegisterBluetoothLeAdvertiseCallback(AdvertiseCallback callback); - - // BluetoothGattServerCallback - private native static void caLeGattServerConnectionStateChangeCallback( - BluetoothDevice device, int status, int newState); - - private native static void caLeGattServerServiceAddedCallback(int status, - BluetoothGattService service); - - private native static void caLeGattServerCharacteristicReadRequestCallback( - BluetoothDevice device, byte[] data); - - private native static void caLeGattServerCharacteristicWriteRequestCallback( - BluetoothDevice device, byte[] data); - - private native static void caLeGattServerNotificationSentCallback(BluetoothDevice device, - int status); - - // AdvertiseCallback - private native static void caLeAdvertiseStartSuccessCallback( - AdvertiseSettings settingsInEffect); - - private native static void caLeAdvertiseStartFailureCallback(int errorCode); - - private static final BluetoothGattServerCallback mGattServerCallback = - new BluetoothGattServerCallback() { - - @Override - public void onConnectionStateChange(BluetoothDevice device, int status, - int newState) { - super.onConnectionStateChange(device, status, newState); - - caLeGattServerConnectionStateChangeCallback(device, status, newState); - } - - @Override - public void onServiceAdded(int status, BluetoothGattService service) { - super.onServiceAdded(status, service); - - caLeGattServerServiceAddedCallback(status, service); - } - - @Override - public void onCharacteristicReadRequest( - BluetoothDevice device, int requestId, int offset, - BluetoothGattCharacteristic characteristic) { - super.onCharacteristicReadRequest(device, requestId, offset, characteristic); - - caLeGattServerCharacteristicReadRequestCallback(device, characteristic.getValue()); - } - - @Override - public void onCharacteristicWriteRequest( - BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, - boolean preparedWrite, boolean responseNeeded, int offset, byte[] value) { - super.onCharacteristicWriteRequest(device, requestId, characteristic, - preparedWrite, responseNeeded, offset, value); - - caLeGattServerCharacteristicWriteRequestCallback(device, value); - } - - @Override - public void onDescriptorReadRequest( - BluetoothDevice device, - int requestId, int offset, BluetoothGattDescriptor descriptor) { - super.onDescriptorReadRequest(device, requestId, offset, descriptor); - } - - @Override - public void onDescriptorWriteRequest( - BluetoothDevice device, int requestId, BluetoothGattDescriptor descriptor, - boolean preparedWrite, boolean responseNeeded, int offset, - byte[] value) { - super.onDescriptorWriteRequest(device, requestId, descriptor, preparedWrite, - responseNeeded, offset, value); - } - - @Override - public void onExecuteWrite(BluetoothDevice device, int requestId, boolean execute) { - super.onExecuteWrite(device, requestId, execute); - } - - @Override - public void onNotificationSent(BluetoothDevice device, int status) { - super.onNotificationSent(device, status); - - caLeGattServerNotificationSentCallback(device, status); - } - }; - - private static final AdvertiseCallback mAdvertiseCallback = new AdvertiseCallback() { - - @Override - public void onStartSuccess(AdvertiseSettings settingsInEffect) { - super.onStartSuccess(settingsInEffect); - - caLeAdvertiseStartSuccessCallback(settingsInEffect); - } - - @Override - public void onStartFailure(int errorCode) { - super.onStartFailure(errorCode); - - caLeAdvertiseStartFailureCallback(errorCode); - } - }; -} diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaNfcInterface.java b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaNfcInterface.java deleted file mode 100644 index ebb273b..0000000 --- a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/java/org/iotivity/ca/CaNfcInterface.java +++ /dev/null @@ -1,140 +0,0 @@ -/* ***************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * 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.ca; - -import java.util.ArrayList; - -import android.app.Activity; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.app.PendingIntent; -import android.content.IntentFilter.MalformedMimeTypeException; -import android.net.NetworkInfo; -import android.nfc.NdefMessage; -import android.nfc.NdefRecord; -import android.nfc.NfcAdapter; -import android.nfc.NfcEvent; -import android.os.Parcelable; -import android.util.Log; - - - -public class CaNfcInterface implements NfcAdapter.CreateNdefMessageCallback { - private final static String MYTAG = CaNfcInterface.class.getSimpleName(); - private static Context mContext; - private Activity mActivity; - private NfcAdapter mAdapter; - private NdefMessage mMessage; - private boolean misInvokeBeam; - - private CaNfcInterface(Context context, Activity activity) { - Log.d(MYTAG, "NFC registerNfcReceiver"); - mContext = context; - mActivity = activity; - - mAdapter = NfcAdapter.getDefaultAdapter(mContext); - if (null == mAdapter) - { - Log.e(MYTAG, "Failed to get the Adapter"); - return; - } - } - - private native static void caNativeNfcPacketReceived(byte[] receivedData); - private native static NdefMessage caNativeNfcCreateNdefMessage(byte[] sendData); - private native static boolean caNativeNfcInvokeBeam(); - - @Override - public NdefMessage createNdefMessage(NfcEvent event) { - Log.d(MYTAG, "NFC createNdefMessage"); - - // Returns the already created message - return mMessage; - } - - public void processSendRquest(byte[] sendData) { - - Log.d(MYTAG, "NFC processSendRquest IN"); - - mMessage = caNativeNfcCreateNdefMessage(sendData); - misInvokeBeam = caNativeNfcInvokeBeam(); - - if (!misInvokeBeam) - { - Log.e(MYTAG, "NFC Beam error"); - } - } - - public void caNfcInitialize() { - Log.d(MYTAG, "caNfcInitialize"); - - if ((null == mActivity) || (null == mContext) || (null == mAdapter)) { - Log.e(MYTAG, "caNfcInitialize failed, invalid parameters"); - return; - } - - PendingIntent pendingIntent = PendingIntent.getActivity(mActivity, 0, - new Intent(mActivity, mActivity.getClass()) - .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP - | Intent.FLAG_ACTIVITY_CLEAR_TOP), 0); - - IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); - - try { - ndef.addDataType("*/*"); /* Handles all MIME based dispatches. - You should specify only the ones that you need. */ - } catch (MalformedMimeTypeException e) { - throw new RuntimeException("fail", e); - } - - IntentFilter[] intentFiltersArray = new IntentFilter[] {ndef, }; - - mAdapter.enableForegroundDispatch(mActivity, pendingIntent, intentFiltersArray, null); - Log.d(MYTAG, " enableForegroundDispatch "); - - mContext.registerReceiver(mReceiver, new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED)); - Log.d(MYTAG, "NFC caNfcInitialize OUT"); - } - - private static BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - Log.d(MYTAG, "onReceive broadcast intent updated - disable callback"); - - if (intent.getAction().equals(NfcAdapter.ACTION_NDEF_DISCOVERED)) - { - processIntent(intent); - } - } - - private void processIntent(Intent intent) { - - Log.d(MYTAG, "processIntent"); - Parcelable[] rawMsgs = intent - .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); - NdefMessage msg = (NdefMessage) rawMsgs[0]; - Log.d(MYTAG, msg.getRecords()[0].toMimeType().toString()); - caNativeNfcPacketReceived(msg.getRecords()[0].getPayload()); - } - }; -} diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-hdpi/ic_launcher.png b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-hdpi/ic_launcher.png deleted file mode 100755 index 96a442e..0000000 Binary files a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-hdpi/ic_launcher.png and /dev/null differ diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-mdpi/ic_launcher.png b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-mdpi/ic_launcher.png deleted file mode 100755 index 359047d..0000000 Binary files a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-mdpi/ic_launcher.png and /dev/null differ diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-xhdpi/ic_launcher.png b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-xhdpi/ic_launcher.png deleted file mode 100755 index 71c6d76..0000000 Binary files a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/drawable-xhdpi/ic_launcher.png and /dev/null differ diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values-v11/styles.xml b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values-v11/styles.xml deleted file mode 100755 index 3c02242..0000000 --- a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values-v11/styles.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values-v14/styles.xml b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values-v14/styles.xml deleted file mode 100755 index a91fd03..0000000 --- a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values-v14/styles.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values/strings.xml b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values/strings.xml deleted file mode 100755 index 0e63d00..0000000 --- a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values/strings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - CAInterface - - diff --git a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values/styles.xml b/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values/styles.xml deleted file mode 100755 index 6ce89c7..0000000 --- a/resource/csdk/connectivity/samples/android/casample/cAInterface/src/main/res/values/styles.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - diff --git a/resource/csdk/connectivity/samples/android/casample/casample.iml b/resource/csdk/connectivity/samples/android/casample/casample.iml deleted file mode 100755 index ed92464..0000000 --- a/resource/csdk/connectivity/samples/android/casample/casample.iml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/resource/csdk/connectivity/samples/android/casample/gradle.properties b/resource/csdk/connectivity/samples/android/casample/gradle.properties deleted file mode 100755 index b0f079c..0000000 --- a/resource/csdk/connectivity/samples/android/casample/gradle.properties +++ /dev/null @@ -1,41 +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. -# // -# //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -# - -# Project-wide Gradle settings. - -# IDE (e.g. Android Studio) users: -# Gradle settings configured through the IDE *will override* -# any settings specified in this file. - -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html - -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -# Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true - diff --git a/resource/csdk/connectivity/samples/android/casample/gradle/wrapper/gradle-wrapper.jar b/resource/csdk/connectivity/samples/android/casample/gradle/wrapper/gradle-wrapper.jar deleted file mode 100755 index 8c0fb64..0000000 Binary files a/resource/csdk/connectivity/samples/android/casample/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/resource/csdk/connectivity/samples/android/casample/gradle/wrapper/gradle-wrapper.properties b/resource/csdk/connectivity/samples/android/casample/gradle/wrapper/gradle-wrapper.properties deleted file mode 100755 index 0c71e76..0000000 --- a/resource/csdk/connectivity/samples/android/casample/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Wed Apr 10 15:27:10 PDT 2013 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip diff --git a/resource/csdk/connectivity/samples/android/casample/gradlew b/resource/csdk/connectivity/samples/android/casample/gradlew deleted file mode 100755 index 91a7e26..0000000 --- a/resource/csdk/connectivity/samples/android/casample/gradlew +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/env bash - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; -esac - -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/resource/csdk/connectivity/samples/android/casample/gradlew.bat b/resource/csdk/connectivity/samples/android/casample/gradlew.bat deleted file mode 100755 index 8a0b282..0000000 --- a/resource/csdk/connectivity/samples/android/casample/gradlew.bat +++ /dev/null @@ -1,90 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/.gitignore b/resource/csdk/connectivity/samples/android/casample/sampleService/.gitignore deleted file mode 100644 index 84c048a..0000000 --- a/resource/csdk/connectivity/samples/android/casample/sampleService/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build/ diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/build.gradle b/resource/csdk/connectivity/samples/android/casample/sampleService/build.gradle deleted file mode 100755 index 1e31192..0000000 --- a/resource/csdk/connectivity/samples/android/casample/sampleService/build.gradle +++ /dev/null @@ -1,70 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 21 - buildToolsVersion "20.0.0" - - defaultConfig { - applicationId "org.iotivity.ca.sample_service" - minSdkVersion 21 - targetSdkVersion 21 - - ndk { - moduleName "RMInterface" - } - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' - } - } - - lintOptions { - abortOnError false - } - - sourceSets { - main { - manifest.srcFile 'src/main/AndroidManifest.xml' - jniLibs.srcDir 'libs' - jni.srcDirs = [] //disable automatic ndk-build call - } - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile project(':cAInterface') -} - -task copyNativeLibs(type: Copy, dependsOn: 'buildNative') { - dependsOn 'buildNative' - from(new File('src/main/libs')) { include '**/*.so' } - into new File(buildDir, 'native-libs') -} - -tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs } - -clean.dependsOn 'cleanCopyNativeLibs' - -tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask -> - pkgTask.jniFolders = new HashSet() - pkgTask.jniFolders.add(new File(buildDir, 'native-libs')) -} - -task buildNative(type: Exec) { - if (System.env.ANDROID_NDK_HOME != null) { - //for windows use 'ndk-build.cmd' - //def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build.cmd') - def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build') - commandLine ndkBuild, "-C", file("src/main"), "-B", "-j", Runtime.runtime.availableProcessors(), - "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE" - } else { - println '##################' - println 'Skipping NDK build' - println 'Reason: ANDROID_NDK_HOME not set.' - println '##################' - } -} diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/sampleService.iml b/resource/csdk/connectivity/samples/android/casample/sampleService/sampleService.iml deleted file mode 100755 index 145e474..0000000 --- a/resource/csdk/connectivity/samples/android/casample/sampleService/sampleService.iml +++ /dev/null @@ -1,91 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/.gitignore b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/.gitignore deleted file mode 100644 index 89a3c7d..0000000 --- a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/libs/ -/obj/ -/assets/ diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/AndroidManifest.xml b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/AndroidManifest.xml deleted file mode 100755 index 60a2aad..0000000 --- a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/AndroidManifest.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/DLog.java b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/DLog.java deleted file mode 100644 index 9fe8422..0000000 --- a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/DLog.java +++ /dev/null @@ -1,90 +0,0 @@ - -package org.iotivity.ca.service; - -import android.os.Handler; -import android.widget.TextView; - -public final class DLog { - - private final static String MAIN_TAG = "Sample_Service : DLog"; - - private static TextView mLogView = null; - - private static Handler mHandler = null; - - public static void setTextView(Handler handler, TextView logView) { - mHandler = handler; - mLogView = logView; - } - - private static void addLogText(final String msg) { - - mHandler.post(new Runnable() { - - @Override - public void run() { - - if (mLogView == null) - return; - - StringBuilder builder = new StringBuilder(mLogView.getText()); - // add front - builder.append(msg + "\n"); - - mLogView.setText(builder.toString()); - } - - }); - - } - - public static final void v(String className, String msg) { - android.util.Log.v(MAIN_TAG, className + "." + msg); - - if (mLogView != null) { - addLogText(msg); - } - } - - public static final void d(String className, String msg) { - android.util.Log.d(MAIN_TAG, className + "." + msg); - - if (mLogView != null) { - addLogText(msg); - } - } - - public static final void i(String className, String msg) { - android.util.Log.i(MAIN_TAG, className + "." + msg); - - if (mLogView != null) { - addLogText(msg); - } - } - - public static final void w(String className, String msg) { - android.util.Log.w(MAIN_TAG, className + "." + msg); - - if (mLogView != null) { - addLogText(msg); - } - } - - public static final void w(String className, String msg, Exception ex) { - android.util.Log.w(MAIN_TAG, className + "." + msg + ":" + ex.getMessage()); - - if (mLogView != null) { - addLogText(msg); - } - } - - public static final void w(String className, String msg, Error e) { - android.util.Log.w(MAIN_TAG, className + "." + msg + ":" + e.getMessage()); - - if (mLogView != null) { - addLogText(msg); - } - } - -} - diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/FileChooser.java b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/FileChooser.java deleted file mode 100644 index d2e50d8..0000000 --- a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/FileChooser.java +++ /dev/null @@ -1,135 +0,0 @@ -package org.iotivity.ca.service; - -import android.app.Activity; -import android.app.Dialog; -import android.os.Environment; -import android.view.View; -import android.view.ViewGroup; -import android.view.WindowManager.LayoutParams; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.ListView; -import android.widget.TextView; -import java.io.File; -import java.io.FileFilter; -import java.util.Arrays; - -public class FileChooser { - private static final String PARENT_DIR = ".."; - - private final Activity activity; - private ListView list; - private Dialog dialog; - private File currentPath; - - // filter on file extension - private String extension = null; - public void setExtension(String extension) { - this.extension = (extension == null) ? null : - extension.toLowerCase(); - } - - // file selection event handling - public interface FileSelectedListener { - void fileSelected(File file); - } - public FileChooser setFileListener(FileSelectedListener fileListener) { - this.fileListener = fileListener; - return this; - } - private FileSelectedListener fileListener; - - public FileChooser(Activity activity) { - this.activity = activity; - dialog = new Dialog(activity); - list = new ListView(activity); - list.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override public void onItemClick(AdapterView parent, View view, int which, long id) { - String fileChosen = (String) list.getItemAtPosition(which); - File chosenFile = getChosenFile(fileChosen); - if (chosenFile.isDirectory()) { - refresh(chosenFile); - } else { - if (fileListener != null) { - fileListener.fileSelected(chosenFile); - } - dialog.dismiss(); - } - } - }); - dialog.setContentView(list); - dialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); - refresh(Environment.getExternalStorageDirectory()); - } - - public void showDialog() { - dialog.show(); - } - - - /** - * Sort, filter and display the files for the given path. - */ - private void refresh(File path) { - this.currentPath = path; - if (path.exists()) { - File[] dirs = path.listFiles(new FileFilter() { - @Override public boolean accept(File file) { - return (file.isDirectory() && file.canRead()); - } - }); - File[] files = path.listFiles(new FileFilter() { - @Override public boolean accept(File file) { - if (!file.isDirectory()) { - if (!file.canRead()) { - return false; - } else if (extension == null) { - return true; - } else { - return file.getName().toLowerCase().endsWith(extension); - } - } else { - return false; - } - } - }); - - // convert to an array - int i = 0; - String[] fileList; - if (path.getParentFile() == null) { - fileList = new String[dirs.length + files.length]; - } else { - fileList = new String[dirs.length + files.length + 1]; - fileList[i++] = PARENT_DIR; - } - Arrays.sort(dirs); - Arrays.sort(files); - for (File dir : dirs) { fileList[i++] = dir.getName(); } - for (File file : files ) { fileList[i++] = file.getName(); } - - // refresh the user interface - dialog.setTitle(currentPath.getPath()); - list.setAdapter(new ArrayAdapter(activity, - android.R.layout.simple_list_item_1, fileList) { - @Override public View getView(int pos, View view, ViewGroup parent) { - view = super.getView(pos, view, parent); - ((TextView) view).setSingleLine(true); - return view; - } - }); - } - } - - - /** - * Convert a relative filename into an actual File object. - */ - private File getChosenFile(String fileChosen) { - if (fileChosen.equals(PARENT_DIR)) { - return currentPath.getParentFile(); - } else { - return new File(currentPath, fileChosen); - } - } -} diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/MainActivity.java b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/MainActivity.java deleted file mode 100644 index d7dd726..0000000 --- a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/MainActivity.java +++ /dev/null @@ -1,775 +0,0 @@ -package org.iotivity.ca.service; - -import android.app.Activity; -import android.app.AlertDialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.nfc.NfcAdapter; -import android.os.Bundle; -import android.os.Handler; -import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.Button; -import android.widget.EditText; -import android.widget.RelativeLayout; -import android.widget.TextView; -import android.widget.Toast; -import java.io.File; - -import org.iotivity.ca.sample_service.R; -import org.iotivity.ca.service.FileChooser; -import org.iotivity.ca.service.FileChooser.FileSelectedListener; - -public class MainActivity extends Activity { - - static RMInterface RM = new RMInterface(); - - private final static String TAG = "Sample_Service : MainActivity"; - - private final CharSequence[] mNetworkCheckBoxItems = { Network.IP.name(), - Network.LE.name(), Network.EDR.name(), Network.TCP.name(), Network.NFC.name()}; - - private final CharSequence[] mDTLSCheckBoxItems = { DTLS.UNSECURED.name(), - DTLS.SECURED.name() }; - - private final CharSequence[] mMsgTyleCheckBoxItems = { MsgType.CON.name(), - MsgType.NON.name(), MsgType.ACK.name(), MsgType.RESET.name() }; - - private final CharSequence[] mResponseResultCheckBoxItems = { - ResponseResult.CA_CREATED.name(), ResponseResult.CA_DELETED.name(), - ResponseResult.CA_VALID.name(), ResponseResult.CA_CHANGED.name(), - ResponseResult.CA_CONTENT.name(), ResponseResult.CA_EMPTY.name(), - ResponseResult.CA_BAD_REQ.name(), ResponseResult.CA_BAD_OPT.name(), - ResponseResult.CA_NOT_FOUND.name(), ResponseResult.CA_INTERNAL_SERVER_ERROR.name(), - ResponseResult.CA_RETRANSMIT_TIMEOUT.name() }; - - private enum Mode { - SERVER, CLIENT, BOTH, UNKNOWN - }; - - private enum Network { - IP, LE, EDR, TCP, NFC - }; - - private enum DTLS { - UNSECURED, SECURED - }; - - private enum MsgType { - CON, NON, ACK, RESET - }; - - private enum ResponseResult { - CA_CREATED, CA_DELETED, CA_VALID, CA_CHANGED, CA_CONTENT, CA_EMPTY, - CA_BAD_REQ, CA_BAD_OPT, CA_NOT_FOUND, CA_INTERNAL_SERVER_ERROR, CA_RETRANSMIT_TIMEOUT - } - - private boolean mCheckedItems[] = { - false, false, false, false, false - }; - - private int mSelectedItems[] = { 0, 0, 0, 0, 0, 0}; - - private int mUnSelectedItems[] = { 0, 0, 0, 0, 0, 0}; - - private Mode mCurrentMode = Mode.UNKNOWN; - - private RelativeLayout mSendNotificationLayout = null; - - private RelativeLayout mSendRequestLayout = null; - - private RelativeLayout mSendRequestToAllLayout = null; - - private RelativeLayout mSendRequestSettingLayout = null; - - private RelativeLayout mSendRequestToAllSettingLayout = null; - - private RelativeLayout mSendResponseNotiSettingLayout = null; - - private RelativeLayout mReceiveLayout = null; - - private RelativeLayout mRequestTitleLayout = null; - - private RelativeLayout mRequestToAllTitleLayout = null; - - private RelativeLayout mResponseNotificationTitleLayout = null; - - private RelativeLayout mHandleTitleLayout = null; - - private TextView mMode_tv = null; - - private TextView mNetwork_tv = null; - - private EditText mNotification_ed = null; - - private EditText mReqData_ed = null; - - private EditText mReqToAllData_ed = null; - - private Button mNotify_btn = null; - - private Button mReqeust_btn = null; - - private Button mReqeust_setting_btn = null; - - private Button mReqeustToAll_btn = null; - - private Button mReqeustToAll_setting_btn = null; - - private Button mResponse_Notify_setting_btn = null; - - private Button mResponse_btn = null; - - private Button mGetNetworkInfo_btn = null; - - private Button mRecv_btn = null; - - private Button mBig_btn = null; - - private Handler mLogHandler = null; - - /** - * Defined ConnectivityType in cacommon.c - * - * CA_IP = (1 << 0) CA_LE = (1 << 1) CA_EDR = (1 << 2) CA_TCP = (1 << 4) CA_NFC= (1 << 5) - */ - private int CA_IP = (1 << 0); - private int CA_LE = (1 << 1); - private int CA_EDR = (1 << 2); - private int CA_TCP = (1 << 4); - private int CA_NFC = (1 << 5); - private int isSecured = 0; - private int msgType = 1; - private int responseValue = 0; - private int selectedNetworkType = -1; - private int selectedMsgType = 1; - private int selectedMsgSecured = 0; - private int selectedResponseValue = 0; - int selectedNetwork = -1; - int interestedNetwork = 0; - int uninterestedNetwork = 0; - private boolean isSendResponseSetting = false; - private boolean isSendRequestToAllSetting = false; - private boolean isBigData = false; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - RM.setResponseListener(this); - - mLogHandler = new Handler(); - TextView logView = (TextView) findViewById(R.id.tv_result); - DLog.setTextView(mLogHandler, logView); - - // Initialize UI - // common - mReceiveLayout = (RelativeLayout) findViewById(R.id.layout_receive); - - // client - mSendRequestLayout = (RelativeLayout) findViewById(R.id.layout_request); - mSendRequestToAllLayout = (RelativeLayout) findViewById(R.id.layout_request_to_all); - mSendRequestSettingLayout = (RelativeLayout) - findViewById(R.id.layout_request_setting_for_client); - mSendRequestToAllSettingLayout = (RelativeLayout) - findViewById(R.id.layout_request_to_all_setting_for_client); - mRequestTitleLayout = (RelativeLayout) findViewById(R.id.layout_request_title); - mRequestToAllTitleLayout = (RelativeLayout) findViewById(R.id.layout_request_to_all_title); - mHandleTitleLayout = (RelativeLayout) findViewById(R.id.layout_handle_title); - - // server - mSendNotificationLayout = (RelativeLayout) findViewById(R.id.layout_notify); - mSendResponseNotiSettingLayout = (RelativeLayout) - findViewById(R.id.layout_request_setting_for_server); - mResponseNotificationTitleLayout = (RelativeLayout) - findViewById(R.id.layout_Response_Noti_title); - - mMode_tv = (TextView) findViewById(R.id.tv_mode); - mNetwork_tv = (TextView) findViewById(R.id.tv_network); - - mNotification_ed = (EditText) findViewById(R.id.et_notification); - mReqData_ed = (EditText) findViewById(R.id.et_req_data); - mReqToAllData_ed = (EditText) findViewById(R.id.et_req_to_all_data); - - mResponse_btn = (Button) findViewById(R.id.btn_sendresponse); - mNotify_btn = (Button) findViewById(R.id.btn_notify); - mReqeust_btn = (Button) findViewById(R.id.btn_Request); - mReqeust_setting_btn = (Button) findViewById(R.id.btn_Request_setting_for_client); - mReqeustToAll_btn = (Button) findViewById(R.id.btn_request_to_all); - mReqeustToAll_setting_btn = (Button) - findViewById(R.id.btn_request_to_all_setting_for_client); - mResponse_Notify_setting_btn = (Button) findViewById(R.id.btn_Request_setting_for_server); - mGetNetworkInfo_btn = (Button) findViewById(R.id.btn_get_network_info); - mRecv_btn = (Button) findViewById(R.id.btn_receive); - mBig_btn = (Button) findViewById(R.id.btn_big_data); - mBig_btn.setOnClickListener(mSelectLargeDataButtonHandler); - - mResponse_btn.setOnClickListener(mSendResponseHandler); - mNotify_btn.setOnClickListener(mNotifyHandler); - mReqeust_btn.setOnClickListener(mSendRequestHandler); - mReqeust_setting_btn.setOnClickListener(mSendRequestSettingHandler); - mReqeustToAll_btn.setOnClickListener(mSendRequestToAllHandler); - mReqeustToAll_setting_btn.setOnClickListener(mSendRequestToAllSettingHandler); - mResponse_Notify_setting_btn - .setOnClickListener(mSendResponseNotiSettingHandler); - mRecv_btn.setOnClickListener(mResponseHandler); - mGetNetworkInfo_btn.setOnClickListener(mGetNetworkInfoHandler); - - showSelectModeView(); - - // Initialize Connectivity Abstraction - RM.RMInitialize(getApplicationContext(), this); - // set handler - RM.RMRegisterHandler(); - } - - private void showSelectModeView() { - - mSendNotificationLayout.setVisibility(View.INVISIBLE); - mSendRequestLayout.setVisibility(View.INVISIBLE); - mSendRequestToAllLayout.setVisibility(View.INVISIBLE); - mSendRequestSettingLayout.setVisibility(View.INVISIBLE); - mSendRequestToAllSettingLayout.setVisibility(View.INVISIBLE); - mReceiveLayout.setVisibility(View.INVISIBLE); - mRequestTitleLayout.setVisibility(View.INVISIBLE); - mRequestToAllTitleLayout.setVisibility(View.INVISIBLE); - mHandleTitleLayout.setVisibility(View.INVISIBLE); - mResponseNotificationTitleLayout.setVisibility(View.INVISIBLE); - mSendResponseNotiSettingLayout.setVisibility(View.INVISIBLE); - - mMode_tv.setText("Select Mode (Server or Client)"); - Log.i(TAG, "Select Mode (Server or Client)"); - } - - private void showNetworkView() { - - mNetwork_tv.setText("Select Network Type"); - Log.i(TAG, "Select Network Type"); - } - - private void showModeView() { - - mReceiveLayout.setVisibility(View.VISIBLE); - mSendRequestToAllLayout.setVisibility(View.VISIBLE); - mSendRequestToAllSettingLayout.setVisibility(View.VISIBLE); - mRequestToAllTitleLayout.setVisibility(View.VISIBLE); - mHandleTitleLayout.setVisibility(View.VISIBLE); - - if (mCurrentMode == Mode.SERVER) { - - mSendNotificationLayout.setVisibility(View.VISIBLE); - mSendRequestLayout.setVisibility(View.INVISIBLE); - mSendRequestSettingLayout.setVisibility(View.INVISIBLE); - - mRequestTitleLayout.setVisibility(View.INVISIBLE); - - mResponseNotificationTitleLayout.setVisibility(View.VISIBLE); - mSendResponseNotiSettingLayout.setVisibility(View.VISIBLE); - - } else if (mCurrentMode == Mode.CLIENT) { - - mSendNotificationLayout.setVisibility(View.INVISIBLE); - mSendRequestLayout.setVisibility(View.VISIBLE); - mSendRequestSettingLayout.setVisibility(View.VISIBLE); - - mRequestTitleLayout.setVisibility(View.VISIBLE); - - mResponseNotificationTitleLayout.setVisibility(View.INVISIBLE); - mSendResponseNotiSettingLayout.setVisibility(View.INVISIBLE); - } - mNetwork_tv.setText(""); - } - - @Override - public void onNewIntent(Intent intent) { - super.onNewIntent(intent); - Intent i = new Intent(); - i.setAction(intent.getAction()); - i.putExtra(NfcAdapter.EXTRA_NDEF_MESSAGES, - intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)); - sendBroadcast(i); - Log.d(TAG, "Broadcast intent complete"); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - - // Terminate Connectivity Abstraction - RM.RMTerminate(); - android.os.Process.killProcess(android.os.Process.myPid()); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - - menu.add(0, 1, Menu.NONE, "Start Server"); - menu.add(0, 2, Menu.NONE, "Start Client"); - menu.add(0, 3, Menu.NONE, "Select Network"); - - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - - switch (item.getItemId()) { - - case 1: - - RM.RMStartListeningServer(); - - if (interestedNetwork == 0) { - mCurrentMode = Mode.SERVER; - mMode_tv.setText("MODE: " + mCurrentMode.toString()); - Log.i(TAG, "MODE: " + mCurrentMode.toString()); - showNetworkView(); - - } else { - mCurrentMode = Mode.SERVER; - mMode_tv.setText("MODE: " + mCurrentMode.toString()); - Log.i(TAG, "MODE: " + mCurrentMode.toString()); - showModeView(); - } - - break; - - case 2: - - RM.RMStartDiscoveryServer(); - - if (interestedNetwork == 0) { - mCurrentMode = Mode.CLIENT; - mMode_tv.setText("MODE: " + mCurrentMode.toString()); - Log.i(TAG, "MODE: " + mCurrentMode.toString()); - showNetworkView(); - - } else { - mCurrentMode = Mode.CLIENT; - mMode_tv.setText("MODE: " + mCurrentMode.toString()); - Log.i(TAG, "MODE: " + mCurrentMode.toString()); - showModeView(); - } - - break; - - case 3: - - checkInterestedNetwork("Select Network"); - - break; - } - - return super.onOptionsItemSelected(item); - } - - private OnClickListener mSendResponseHandler = new OnClickListener() { - - @Override - public void onClick(View v) { - - DLog.v(TAG, "SendResponse click"); - if ( selectedNetwork != -1) { - RM.RMSendResponse(selectedNetwork, isSecured, msgType, responseValue); - } - else { - DLog.v(TAG, "Please Select Network Type"); - } - } - }; - - private OnClickListener mNotifyHandler = new OnClickListener() { - - @Override - public void onClick(View v) { - - DLog.v(TAG, "SendNotification click"); - if ( selectedNetwork != -1) { - RM.RMSendNotification(mNotification_ed.getText().toString(), - null, selectedNetwork, isSecured, msgType); - } - else { - DLog.v(TAG, "Please Select Network Type"); - } - } - }; - - private OnClickListener mSendRequestHandler = new OnClickListener() { - - @Override - public void onClick(View v) { - - DLog.v(TAG, "SendRequest click"); - if ( selectedNetwork != -1) { - RM.RMSendRequest(mReqData_ed.getText().toString(), null, - selectedNetwork, isSecured, msgType, false); - } - else { - DLog.v(TAG, "Please Select Network Type"); - } - } - }; - - private OnClickListener mSendRequestSettingHandler = new OnClickListener() { - - @Override - public void onClick(View v) { - checkSendNetworkType("Select Send Network Type"); - } - }; - - private OnClickListener mSendRequestToAllHandler = new OnClickListener() { - - @Override - public void onClick(View v) { - - DLog.v(TAG, "SendRequestToAll click"); - if ( selectedNetwork != -1) { - RM.RMSendReqestToAll(mReqToAllData_ed.getText().toString(), selectedNetwork); - } - else { - DLog.v(TAG, "Please Select Network Type"); - } - } - }; - - private OnClickListener mSendRequestToAllSettingHandler = new OnClickListener() { - - @Override - public void onClick(View v) { - isSendRequestToAllSetting = true; - checkSendNetworkType("Select Send Network Type"); - } - }; - - private OnClickListener mSendResponseNotiSettingHandler = new OnClickListener() { - - @Override - public void onClick(View v) { - isSendResponseSetting = true; - checkSendNetworkType("Select Send Network Type"); - } - }; - - private OnClickListener mGetNetworkInfoHandler = new OnClickListener() { - @Override - public void onClick(View v) { - - RM.RMGetNetworkInfomation(); - } - }; - - private OnClickListener mResponseHandler = new OnClickListener() { - - @Override - public void onClick(View v) { - - RM.RMHandleRequestResponse(); - } - }; - - private OnClickListener mSelectLargeDataButtonHandler = new OnClickListener() { - @Override - public void onClick(View v) { - - isBigData = true; - checkSendNetworkType("Select Send Network Type"); - } - }; - - private void checkInterestedNetwork(String title) { - - AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); - builder.setTitle(title) - .setMultiChoiceItems(mNetworkCheckBoxItems, mCheckedItems, - new DialogInterface.OnMultiChoiceClickListener() { - - @Override - public void onClick(DialogInterface dialog, - int which, boolean isChecked) { - - // in case of TCP increase value, - // because CASample not support RA. - // which: 0(IP), 1(BT), 2(BLE), 3(TCP) - if (which == 3) { - which = 4; - } - if (isChecked) { - mSelectedItems[which] = 1; - mUnSelectedItems[which] = 0; - - } else if (mSelectedItems[which] == 1) { - - mSelectedItems[which] = 0; - mUnSelectedItems[which] = 1; - } - } - }) - .setPositiveButton("OK", new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - - interestedNetwork = 0; - - for (int i = 0; i < mSelectedItems.length; i++) { - if (mSelectedItems[i] == 1) { - interestedNetwork |= (1 << i); - } - } - if(0 != interestedNetwork) - RM.RMSelectNetwork(interestedNetwork); - - uninterestedNetwork = 0; - - for (int i = 0; i < mUnSelectedItems.length; i++) { - if (mUnSelectedItems[i] == 1) { - uninterestedNetwork |= (1 << i); - } - } - if(0 != uninterestedNetwork) - RM.RMUnSelectNetwork(uninterestedNetwork); - - } - }).show(); - } - - private void checkMsgSecured(String title) { - - AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); - - builder.setTitle(title) - .setSingleChoiceItems(mDTLSCheckBoxItems, selectedMsgSecured, - new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, - int which) { - selectedMsgSecured = which; - } - }) - .setPositiveButton("OK", new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - - if (selectedMsgSecured == DTLS.SECURED.ordinal()) { - isSecured = 1; - DLog.v(TAG, "Send secured message"); - - } else if (selectedMsgSecured == DTLS.UNSECURED.ordinal()) { - isSecured = 0; - DLog.v(TAG, "Send unsecured message"); - } - checkMsgType("Select Msg Type"); - } - - }).show(); - } - - private void checkMsgType(String title) { - - AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); - builder.setTitle(title) - .setSingleChoiceItems(mMsgTyleCheckBoxItems, selectedMsgType, - new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, - int which) { - selectedMsgType = which; - } - }) - .setPositiveButton("OK", new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - - if (selectedMsgType == MsgType.CON.ordinal()) { - msgType = 0; - DLog.v(TAG, "Message Type is CON"); - - } else if (selectedMsgType == MsgType.NON.ordinal()) { - msgType = 1; - DLog.v(TAG, "Message Type is NON"); - } else if (selectedMsgType == MsgType.ACK.ordinal()) { - msgType = 2; - DLog.v(TAG, "Message Type is ACK"); - } else if (selectedMsgType == MsgType.RESET.ordinal()) { - msgType = 3; - DLog.v(TAG, "Message Type is RESET"); - } - - if (isSendResponseSetting == true && msgType != 3) { - checkResponseResult("Select Value of Response Result"); - isSendResponseSetting = false; - } - } - }).show(); - } - - private void checkResponseResult(String title) { - - AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); - builder.setTitle(title) - .setSingleChoiceItems(mResponseResultCheckBoxItems, selectedResponseValue, - new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, - int which) { - selectedResponseValue = which; - } - }) - .setPositiveButton("OK", new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - - if (selectedResponseValue == ResponseResult.CA_CREATED.ordinal()) { - responseValue = 201; - DLog.v(TAG, "Response Value is CA_CREATED"); - } else if (selectedResponseValue == ResponseResult.CA_DELETED - .ordinal()) { - responseValue = 202; - DLog.v(TAG, "Response Value is CA_DELETED"); - } else if (selectedResponseValue == ResponseResult.CA_VALID - .ordinal()) { - responseValue = 203; - DLog.v(TAG, "Response Value is CA_VALID"); - } else if (selectedResponseValue == ResponseResult.CA_CHANGED - .ordinal()) { - responseValue = 204; - DLog.v(TAG, "Response Value is CA_CHANGED"); - } else if (selectedResponseValue == ResponseResult.CA_CONTENT - .ordinal()) { - responseValue = 205; - DLog.v(TAG, "Response Value is CA_CONTENT"); - } else if (selectedResponseValue == ResponseResult.CA_EMPTY - .ordinal()) { - responseValue = 0; - DLog.v(TAG, "Response Value is CA_EMPTY"); - } else if (selectedResponseValue == ResponseResult.CA_BAD_REQ - .ordinal()) { - responseValue = 400; - DLog.v(TAG, "Response Value is CA_BAD_REQ"); - } else if (selectedResponseValue == ResponseResult.CA_BAD_OPT - .ordinal()) { - responseValue = 402; - DLog.v(TAG, "Response Value is CA_BAD_OPT"); - } else if (selectedResponseValue == ResponseResult.CA_NOT_FOUND - .ordinal()) { - responseValue = 404; - DLog.v(TAG, "Response Value is CA_NOT_FOUND"); - } else if (selectedResponseValue == - ResponseResult.CA_INTERNAL_SERVER_ERROR - .ordinal()) { - responseValue = 500; - DLog.v(TAG, "Response Value is CA_INTERNAL_SERVER_ERROR"); - } else if (selectedResponseValue == ResponseResult.CA_RETRANSMIT_TIMEOUT - .ordinal()) { - responseValue = 504; - DLog.v(TAG, "Response Value is CA_RETRANSMIT_TIMEOUT"); - } - } - }).show(); - } - - private void checkSendNetworkType(String title) { - selectedNetworkType = -1; - AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); - - builder.setTitle(title) - .setSingleChoiceItems(mNetworkCheckBoxItems, -1, - new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, - int which) { - selectedNetworkType = which; - } - }) - .setPositiveButton("OK", new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - - if (selectedNetworkType == Network.IP.ordinal()) { - selectedNetwork = CA_IP; - DLog.v(TAG, "Selected Network is IP"); - } else if (selectedNetworkType == Network.LE.ordinal()) { - selectedNetwork = CA_LE; - DLog.v(TAG, "Selected Network is LE"); - } else if (selectedNetworkType == Network.EDR.ordinal()) { - selectedNetwork = CA_EDR; - DLog.v(TAG, "Selected Network is EDR"); - } else if (selectedNetworkType == Network.TCP.ordinal()) { - selectedNetwork = CA_TCP; - DLog.v(TAG, "Selected Network is TCP"); - } else if (selectedNetworkType == Network.NFC.ordinal()) { - selectedNetwork = CA_NFC; - DLog.v(TAG, "Selected Network is NFC"); - } else { - DLog.v(TAG, "Selected Network is NULL"); - selectedNetwork = -1; - } - - if (isBigData) - { - new FileChooser(MainActivity.this).setFileListener( - new FileSelectedListener() { - public void fileSelected(final File file) { - if (selectedNetwork != -1) { - - String path = file.getAbsolutePath(); - Log.d(TAG, "File Path: " + path); - - RM.RMSendRequest(mReqData_ed.getText().toString(), path, - selectedNetwork, isSecured, msgType, true); - } else { - Toast.makeText(getApplicationContext(), - "Request Setting Fisrt!!", - Toast.LENGTH_LONG).show(); - } - } - } ).showDialog(); - isBigData = false; - } else { - if (isSendRequestToAllSetting != true) { - checkMsgSecured("Select DTLS Type"); - } - } - - isSendRequestToAllSetting = false; - isBigData = false; - } - }).show(); - } - - public void OnResponseReceived(String subject, String receivedData) { - String callbackData = subject + receivedData; - DLog.v(TAG, callbackData); - - if (subject.equals(getString(R.string.remote_address))) { - StringBuilder sb = new StringBuilder(); - sb.append(getString(R.string.coap_prefix)).append(receivedData); - mReqData_ed.setText(sb.toString()); - mNotification_ed.setText(sb.toString()); - } else if (subject.equals(getString(R.string.remote_port))) { - StringBuilder sb = new StringBuilder(); - String uri = mReqData_ed.getText().toString(); - sb.append(uri); - if (null != receivedData && uri.contains(".")) - { - sb.append(":").append(receivedData); - } - sb.append(getString(R.string.uri)); - mReqData_ed.setText(sb.toString()); - mNotification_ed.setText(sb.toString()); - } - } -} \ No newline at end of file diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/RMInterface.java b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/RMInterface.java deleted file mode 100644 index 18f1b64..0000000 --- a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/java/org/iotivity/ca/service/RMInterface.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.iotivity.ca.service; - -import android.content.Context; -import android.app.Activity; - -public class RMInterface { - - static { - // Load RI JNI interface - System.loadLibrary("RMInterface"); - } - - private org.iotivity.ca.service.MainActivity mResponseListener = null; - - public native void setNativeResponseListener(Object listener); - - public native void RMInitialize(Context context, Activity activity); - - public native void RMTerminate(); - - public native void RMStartListeningServer(); - - public native void RMStartDiscoveryServer(); - - public native void RMRegisterHandler(); - - public native void RMFindResource(String uri); - - public native void RMSendRequest(String uri, String payload, - int selectedNetwork, int isSecured, int msgType, boolean isBigData); - - public native void RMSendReqestToAll(String uri, int selectedNetwork); - - public native void RMSendResponse(int selectedNetwork, int isSecured, - int msgType, int responseValue); - - public native void RMAdvertiseResource(String advertiseResource); - - public native void RMSendNotification(String uri, String payload, - int selectedNetwork, int isSecured, int msgType); - - public native void RMSelectNetwork(int interestedNetwork); - - public native void RMUnSelectNetwork(int uninterestedNetwork); - - public native void RMGetNetworkInfomation(); - - public native void RMHandleRequestResponse(); - - public void setResponseListener(org.iotivity.ca.service.MainActivity listener) { - mResponseListener = listener; - setNativeResponseListener(this); - } - - private void OnResponseReceived(String subject, String receivedData) { - if (null != mResponseListener) { - mResponseListener.OnResponseReceived(subject, receivedData); - } - } - -} diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/Android.mk b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/Android.mk deleted file mode 100755 index be764d8..0000000 --- a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/Android.mk +++ /dev/null @@ -1,14 +0,0 @@ -APP_PATH := $(call my-dir) -#specify project root path here wrt make file directory -PROJECT_ROOT_PATH = ../../../../../../ -include $(CLEAR_VARS) -LOCAL_PATH= $(PROJECT_ROOT_PATH)/../../../out/android/$(APP_ABI)/$(APP_OPTIM)/resource/csdk/connectivity/src -LOCAL_SRC_FILES = libconnectivity_abstraction.so -LOCAL_MODULE = CA -include $(PREBUILT_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_PATH= $(PROJECT_ROOT_PATH)/../../../out/android/$(APP_ABI)/$(APP_OPTIM)/resource/csdk/connectivity/samples/android -LOCAL_SRC_FILES = libRMInterface.so -LOCAL_MODULE = CASAMPLE -include $(PREBUILT_SHARED_LIBRARY) diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/Application.mk b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/Application.mk deleted file mode 100755 index ed9b8b6..0000000 --- a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/Application.mk +++ /dev/null @@ -1,8 +0,0 @@ - -APP_PROJECT_PATH = ./ -APP_STL := gnustl_shared - -APP_PLATFORM = android-21 -APP_CPPFLAGS += -fexceptions -APP_CPPFLAGS += -frtti -APP_CFLAGS = -Wno-error=format-security diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/ResourceModel.c b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/ResourceModel.c deleted file mode 100644 index 56f1ba6..0000000 --- a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/ResourceModel.c +++ /dev/null @@ -1,1765 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "cainterface.h" -#include "cacommon.h" -#include "caadapterutils.h" -#include "oic_string.h" - -#include "org_iotivity_ca_service_RMInterface.h" - -#define LOG_TAG "JNI_INTERFACE_SAMPLE" -#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) -#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) - -// Iotivity Device Identity. -const unsigned char IDENTITY[] = ("1111111111111111"); - -// PSK between this device and peer device. -const unsigned char RS_CLIENT_PSK[] = ("AAAAAAAAAAAAAAAA"); - -#define PORT_LENGTH 5 -#define SECURE_DEFAULT_PORT 5684 -#define RESOURCE_URI_LENGTH 14 -#define OPTION_INFO_LENGTH 1024 -#define NETWORK_INFO_LENGTH 1024 -#define BIG_PAYLOAD_LENGTH 1024 -#define RECEIVED_FILE_NAME_PREFIX_LENGTH 7 -#define RECEIVED_FILE_NAME_LENGTH 14 - -typedef struct -{ - char ipAddress[CA_IPADDR_SIZE]; - uint16_t port; -} addressSet_t; - -static void request_handler(const CAEndpoint_t* object, const CARequestInfo_t* requestInfo); -static void response_handler(const CAEndpoint_t* object, const CAResponseInfo_t* responseInfo); -static void error_handler(const CAEndpoint_t *object, const CAErrorInfo_t* errorInfo); -static void get_resource_uri(const char *URI, char *resourceURI, int32_t length); -static uint32_t get_secure_information(CAPayload_t payLoad); -static CAResult_t get_network_type(uint32_t selectedNetwork, CATransportFlags_t *flags); -static void callback(char *subject, char *receivedData); -static CAResult_t get_remote_address(const char *address); -static void parsing_coap_uri(const char* uri, addressSet_t* address, CATransportFlags_t *flags); -static void delete_global_references(JNIEnv *env, jobject obj); -static int get_address_set(const char *pAddress, addressSet_t* outAddress); -bool read_file(const char* name, char** bytes, size_t* length); -uint32_t gettodaydate(); -void saveFile(const char *payload, size_t payloadSize); - -uint16_t g_localSecurePort = SECURE_DEFAULT_PORT; -CATransportAdapter_t g_selectedNwType = CA_ADAPTER_IP; -static CAToken_t g_lastRequestToken = NULL; -static uint8_t g_lastRequestTokenLength = 0; - -static const char COAP_PREFIX[] = "coap://"; -static const char COAPS_PREFIX[] = "coaps://"; -static const char COAP_TCP_PREFIX[] = "coap+tcp://"; - -static const uint16_t COAP_PREFIX_LEN = sizeof(COAP_PREFIX) - 1; -static const uint16_t COAPS_PREFIX_LEN = sizeof(COAPS_PREFIX) - 1; -static const uint16_t COAP_TCP_PREFIX_LEN = sizeof(COAP_TCP_PREFIX) - 1; - -static const char RECEIVED_FILE_PATH[] = "/storage/emulated/0/Download/%d%s.txt"; - -static const char SECURE_INFO_DATA[] - = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"]," - "\"if\":[\"oic.if.baseline\"],\"obs\":1,\"sec\":1,\"port\":" - "%d}}]}"; -static const char NORMAL_INFO_DATA[] - = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"]," - "\"if\":[\"oic.if.baseline\"],\"obs\":1}}]}"; - -static jobject g_responseListenerObject = NULL; -static JavaVM *g_jvm; - -static CAEndpoint_t *g_clientEndpoint = NULL; -static char *g_resourceUri = NULL; -static CAToken_t g_clientToken = NULL; -static uint8_t g_clientTokenLength = 0; - -static uint16_t g_clientMsgId = 0; -static char *g_remoteAddress = NULL; - -// init -JNIEXPORT void JNICALL -Java_org_iotivity_ca_service_RMInterface_setNativeResponseListener(JNIEnv *env, jobject obj, - jobject listener) -{ - LOGI("setNativeResponseListener"); - if (!env || !obj || !listener) - { - LOGI("Invalid input parameter"); - return; - } - - g_responseListenerObject = (*env)->NewGlobalRef(env, listener); -} - -#ifdef __WITH_DTLS__ -// Internal API. Invoked by OC stack to retrieve credentials from this module -int32_t CAGetDtlsPskCredentials( CADtlsPskCredType_t type, - const unsigned char *desc, size_t desc_len, - unsigned char *result, size_t result_length) -{ - LOGI("CAGetDtlsPskCredentials IN"); - - int32_t ret = -1; - - if (NULL == result) - { - return ret; - } - - switch (type) - { - case CA_DTLS_PSK_HINT: - case CA_DTLS_PSK_IDENTITY: - - if (result_length < sizeof(IDENTITY)) - { - LOGE("ERROR : Wrong value for result for storing IDENTITY"); - return ret; - } - - memcpy(result, IDENTITY, sizeof(IDENTITY)); - ret = sizeof(IDENTITY); - break; - - case CA_DTLS_PSK_KEY: - - if ((desc_len == sizeof(IDENTITY)) && - memcmp(desc, IDENTITY, sizeof(IDENTITY)) == 0) - { - if (result_length < sizeof(RS_CLIENT_PSK)) - { - LOGE("ERROR : Wrong value for result for storing RS_CLIENT_PSK"); - return ret; - } - - memcpy(result, RS_CLIENT_PSK, sizeof(RS_CLIENT_PSK)); - ret = sizeof(RS_CLIENT_PSK); - } - break; - - default: - - LOGE("Wrong value passed for PSK_CRED_TYPE."); - ret = -1; - } - - LOGI("CAGetDtlsPskCredentials OUT\n"); - return ret; -} - -#endif - -JNIEXPORT jint JNI_OnLoad(JavaVM *jvm, void *reserved) -{ - LOGI("JNI_OnLoad"); - (void)reserved; - - JNIEnv* env; - if (JNI_OK != (*jvm)->GetEnv(jvm, (void**) &env, JNI_VERSION_1_6)) - { - return -1; - } - g_jvm = jvm; /* cache the JavaVM pointer */ - - CANativeJNISetJavaVM(g_jvm); - - return JNI_VERSION_1_6; -} - -void JNI_OnUnload(JavaVM *jvm, void *reserved) -{ - LOGI("JNI_OnUnload"); - (void)reserved; - - JNIEnv* env; - if (JNI_OK != (*jvm)->GetEnv(jvm, (void**) &env, JNI_VERSION_1_6)) - { - return; - } - g_jvm = 0; - return; -} - -JNIEXPORT void JNICALL -Java_org_iotivity_ca_service_RMInterface_RMInitialize(JNIEnv *env, jobject obj, jobject context, - jobject activity) -{ - LOGI("RMInitialize"); - if (!env || !obj || !context || !activity) - { - LOGI("Invalid input parameter"); - return; - } - - //Currently set context for Android Platform - CANativeJNISetContext(env, context); - CANativeSetActivity(env, activity); - - CAResult_t res = CAInitialize(); - - if (CA_STATUS_OK != res) - { - LOGE("Could not Initialize"); - } - -#ifdef __WITH_DTLS__ - res = CARegisterDTLSCredentialsHandler(CAGetDtlsPskCredentials); - if(CA_STATUS_OK != res) - { - LOGE("Set credential handler fail"); - return; - } -#endif -} - -JNIEXPORT void JNICALL -Java_org_iotivity_ca_service_RMInterface_RMTerminate(JNIEnv *env, jobject obj) -{ - LOGI("RMTerminate"); - if (!env || !obj) - { - LOGI("Invalid input parameter"); - return; - } - - CADestroyToken(g_lastRequestToken); - CATerminate(); - delete_global_references(env, obj); -} - -JNIEXPORT void JNICALL -Java_org_iotivity_ca_service_RMInterface_RMStartListeningServer(JNIEnv *env, jobject obj) -{ - LOGI("RMStartListeningServer"); - if (!env || !obj) - { - LOGI("Invalid input parameter"); - return; - } - - if (CA_STATUS_OK != CAStartListeningServer()) - { - LOGE("Could not start Listening server"); - } -} - -JNIEXPORT void JNICALL -Java_org_iotivity_ca_service_RMInterface_RMStartDiscoveryServer(JNIEnv *env, jobject obj) -{ - LOGI("RMStartDiscoveryServer"); - if (!env || !obj) - { - LOGI("Invalid input parameter"); - return; - } - - if (CA_STATUS_OK != CAStartDiscoveryServer()) - { - LOGE("Could not start discovery server"); - } -} - -JNIEXPORT void JNICALL -Java_org_iotivity_ca_service_RMInterface_RMRegisterHandler(JNIEnv *env, jobject obj) -{ - LOGI("RMRegisterHandler"); - if(!env || !obj) - { - LOGI("Invalid input parameter"); - return; - } - - CARegisterHandler(request_handler, response_handler, error_handler); -} - -JNIEXPORT void JNICALL -Java_org_iotivity_ca_service_RMInterface_RMSendRequest(JNIEnv *env, jobject obj, jstring uri, - jstring payload, jint selectedNetwork, - jint isSecured, jint msgType, - jboolean isBigData) -{ - LOGI("selectedNetwork - %d", selectedNetwork); - if (!env || !obj) - { - LOGI("Invalid input parameter"); - return; - } - - if (!uri) - { - LOGE("Invalid input parameter : uri"); - return; - } - - CATransportFlags_t flags = CA_DEFAULT_FLAGS; - CAResult_t res = get_network_type(selectedNetwork, &flags); - if (CA_STATUS_OK != res) - { - return; - } - - const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL); - LOGI("RMSendRequest - %s", strUri); - - addressSet_t address = {{0}, 0}; - parsing_coap_uri(strUri, &address, &flags); - - //create remote endpoint - CAEndpoint_t* endpoint = NULL; - res = CACreateEndpoint(flags, g_selectedNwType, (const char*)(address.ipAddress), - address.port, &endpoint); - if (CA_STATUS_OK != res) - { - LOGE("Could not create remote end point"); - (*env)->ReleaseStringUTFChars(env, uri, strUri); - return; - } - - CAMessageType_t messageType = msgType; - - // create token - CAToken_t token = NULL; - uint8_t tokenLength = CA_MAX_TOKEN_LEN; - - res = CAGenerateToken(&token, tokenLength); - if ((CA_STATUS_OK != res) || (!token)) - { - LOGE("token generate error!!"); - // destroy remote endpoint - CADestroyEndpoint(endpoint); - (*env)->ReleaseStringUTFChars(env, uri, strUri); - return; - } - - char resourceURI[RESOURCE_URI_LENGTH + 1] = { 0 }; - - get_resource_uri((const CAURI_t) strUri, resourceURI, RESOURCE_URI_LENGTH); - (*env)->ReleaseStringUTFChars(env, uri, strUri); - - CAInfo_t requestData = { 0 }; - requestData.token = token; - requestData.tokenLength = tokenLength; - - size_t payloadLength = 0; - if (isBigData) - { - const char* path = NULL; - if (payload) - { - path = (*env)->GetStringUTFChars(env, payload, NULL); - if(path) - { - char* bigData = NULL; - bool result = read_file(path, &bigData, &payloadLength); - if (!result) - { - LOGE("read has failed"); - (*env)->ReleaseStringUTFChars(env, payload, path); - CADestroyToken(token); - CADestroyEndpoint(endpoint); - return; - } - (*env)->ReleaseStringUTFChars(env, payload, path); - - requestData.payload = (CAPayload_t) malloc(payloadLength); - if (NULL == requestData.payload) - { - LOGE("Memory allocation failed!"); - // destroy token - CADestroyToken(token); - // destroy remote endpoint - CADestroyEndpoint(endpoint); - return; - } - memcpy(requestData.payload, bigData, payloadLength); - requestData.payloadSize = payloadLength; - } - } - } - else - { - if (isSecured) - { - payloadLength = sizeof(SECURE_INFO_DATA) + strlen(resourceURI); - requestData.payload = (CAPayload_t) malloc(payloadLength); - if (NULL == requestData.payload) - { - LOGE("Memory allocation failed!"); - // destroy token - CADestroyToken(token); - // destroy remote endpoint - CADestroyEndpoint(endpoint); - return; - } - snprintf((char *) requestData.payload, payloadLength, SECURE_INFO_DATA, - resourceURI, g_localSecurePort); - requestData.payloadSize = payloadLength; - } - else - { - payloadLength = sizeof(NORMAL_INFO_DATA) + strlen(resourceURI); - requestData.payload = (CAPayload_t) malloc(payloadLength); - if (NULL == requestData.payload) - { - LOGE("Memory allocation failed!"); - // destroy token - CADestroyToken(token); - // destroy remote endpoint - CADestroyEndpoint(endpoint); - return; - } - snprintf((char *) requestData.payload, payloadLength, NORMAL_INFO_DATA, resourceURI); - requestData.payloadSize = payloadLength; - } - } - - requestData.type = messageType; - requestData.resourceUri = (CAURI_t) malloc(sizeof(resourceURI)); - if (NULL == requestData.resourceUri) - { - LOGE("Memory allocation failed!"); - // destroy token - CADestroyToken(token); - // destroy remote endpoint - CADestroyEndpoint(endpoint); - free(requestData.payload); - return; - } - memcpy(requestData.resourceUri, resourceURI, sizeof(resourceURI)); - - CARequestInfo_t requestInfo = { 0 }; - requestInfo.method = CA_GET; - requestInfo.isMulticast = false; - requestInfo.info = requestData; - - // send request - if (CA_STATUS_OK != CASendRequest(endpoint, &requestInfo)) - { - LOGE("Could not send request"); - } - - // destroy token - CADestroyToken(token); - - // destroy remote endpoint - CADestroyEndpoint(endpoint); - - free(requestData.payload); - free(requestData.resourceUri); - LOGI("send request success"); -} - -JNIEXPORT void JNICALL -Java_org_iotivity_ca_service_RMInterface_RMSendReqestToAll(JNIEnv *env, jobject obj, jstring uri, - jint selectedNetwork) -{ - LOGI("selectedNetwork - %d", selectedNetwork); - if (!env || !obj) - { - LOGI("Invalid input parameter"); - return; - } - - CATransportFlags_t flags = CA_DEFAULT_FLAGS; - CAResult_t res = get_network_type(selectedNetwork, &flags); - if (CA_STATUS_OK != res) - { - LOGE("Not supported network type"); - return; - } - - // create remote endpoint - CAEndpoint_t *endpoint = NULL; - res = CACreateEndpoint(flags, g_selectedNwType, NULL, 0, &endpoint); - - if (CA_STATUS_OK != res) - { - LOGE("create remote endpoint error, error code: %d", res); - return; - } - - // create token - CAToken_t token = NULL; - uint8_t tokenLength = CA_MAX_TOKEN_LEN; - - res = CAGenerateToken(&token, tokenLength); - if ((CA_STATUS_OK != res) || (!token)) - { - LOGE("token generate error!!"); - // destroy remote endpoint - CADestroyEndpoint(endpoint); - return; - } - - LOGI("generated token %s", token); - - CAInfo_t requestData = { 0 }; - requestData.token = token; - requestData.tokenLength = tokenLength; - requestData.payload = (CAPayload_t) "TempJsonPayload"; - requestData.payloadSize = strlen((const char *) requestData.payload); - requestData.type = CA_MSG_NONCONFIRM; - - const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL); - LOGI("resourceUri - %s", strUri); - requestData.resourceUri = (CAURI_t)strUri; - - uint8_t optionNum = 2; - CAHeaderOption_t *headerOpt = (CAHeaderOption_t*) calloc(1, - sizeof(CAHeaderOption_t) * optionNum); - if (NULL == headerOpt) - { - LOGE("Memory allocation failed"); - // destroy remote endpoint - CADestroyEndpoint(endpoint); - return; - } - - char* FirstOptionData = "Hello"; - headerOpt[0].optionID = 3000; - memcpy(headerOpt[0].optionData, FirstOptionData, strlen(FirstOptionData)); - headerOpt[0].optionLength = (uint16_t) strlen(FirstOptionData); - - char* SecondOptionData2 = "World"; - headerOpt[1].optionID = 3001; - memcpy(headerOpt[1].optionData, SecondOptionData2, strlen(SecondOptionData2)); - headerOpt[1].optionLength = (uint16_t) strlen(SecondOptionData2); - - requestData.numOptions = optionNum; - requestData.options = headerOpt; - - CARequestInfo_t requestInfo = { 0 }; - requestInfo.method = CA_GET; - requestInfo.isMulticast = true; - requestInfo.info = requestData; - - // send request to all - res = CASendRequest(endpoint, &requestInfo); - if (CA_STATUS_OK != res) - { - LOGE("Could not send request to all"); - //destroy token - CADestroyToken(token); - } - else - { - CADestroyToken(g_lastRequestToken); - g_lastRequestToken = token; - g_lastRequestTokenLength = tokenLength; - } - - //ReleaseStringUTFChars for strUri - (*env)->ReleaseStringUTFChars(env, uri, strUri); - - free(headerOpt); - - // destroy remote endpoint - CADestroyEndpoint(endpoint); -} - -JNIEXPORT void JNICALL -Java_org_iotivity_ca_service_RMInterface_RMSendResponse(JNIEnv *env, jobject obj, - jint selectedNetwork, - jint isSecured, jint msgType, - jint responseValue) -{ - LOGI("RMSendResponse"); - if (!env || !obj) - { - LOGI("Invalid input parameter"); - return; - } - - LOGI("selectedNetwork - %d", selectedNetwork); - - CATransportFlags_t flags = CA_DEFAULT_FLAGS; - CAResult_t res = get_network_type(selectedNetwork, &flags); - if (CA_STATUS_OK != res) - { - LOGE("Not supported network type"); - return; - } - - if (NULL == g_clientEndpoint) - { - LOGE("No Request received"); - return; - } - - CAMessageType_t messageType = msgType; - - CAInfo_t responseData = { 0 }; - responseData.type = messageType; - responseData.messageId = g_clientMsgId; - responseData.resourceUri = (CAURI_t)g_resourceUri; - - CAResponseInfo_t responseInfo = { 0 }; - - if (CA_MSG_RESET == msgType || - (CA_MSG_ACKNOWLEDGE == msgType && CA_EMPTY == responseValue)) - { - printf("RESET or ACK/EMPTY. there will be not payload/option\n"); - responseInfo.result = CA_EMPTY; - } - else - { - responseData.token = g_clientToken; - responseData.tokenLength = g_clientTokenLength; - responseInfo.result = responseValue; - - if (1 == isSecured) - { - uint32_t length = strlen(SECURE_INFO_DATA) + strlen(g_resourceUri) + 1; - responseData.payload = (CAPayload_t) malloc(length); - snprintf((char *) responseData.payload, length, SECURE_INFO_DATA, - g_resourceUri, g_localSecurePort); - responseData.payloadSize = length; - } - else - { - uint32_t length = strlen(NORMAL_INFO_DATA) + strlen(g_resourceUri) + 1; - responseData.payload = (CAPayload_t) malloc(length); - snprintf((char *) responseData.payload, length, NORMAL_INFO_DATA, g_resourceUri); - responseData.payloadSize = length; - } - } - - responseInfo.info = responseData; - - // send response - res = CASendResponse(g_clientEndpoint, &responseInfo); - if (CA_STATUS_OK != res) - { - LOGE("Could not send response"); - } - - // destroy token - CADestroyToken(g_clientToken); - g_clientToken = NULL; - g_clientTokenLength = 0; - - // destroy remote endpoint - CADestroyEndpoint(g_clientEndpoint); - g_clientEndpoint = NULL; - free(responseData.payload); -} - -JNIEXPORT void JNICALL -Java_org_iotivity_ca_service_RMInterface_RMSendNotification(JNIEnv *env, jobject obj, jstring uri, - jstring payload, jint selectedNetwork, - jint isSecured, jint msgType) -{ - LOGI("selectedNetwork - %d", selectedNetwork); - if (!env || !obj) - { - LOGI("Invalid input parameter"); - return; - } - - if (!payload) - { - LOGE("payload is NULL"); - } - - if (!uri) - { - LOGE("Invalid input parameter : uri"); - return; - } - - CATransportFlags_t flags = CA_DEFAULT_FLAGS; - CAResult_t res = get_network_type(selectedNetwork, &flags); - if (CA_STATUS_OK != res) - { - LOGE("Not supported network type"); - return; - } - - const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL); - LOGI("RMSendNotification - %s", strUri); - - addressSet_t address = {{0}, 0}; - parsing_coap_uri(strUri, &address, &flags); - - //create remote endpoint - CAEndpoint_t* endpoint = NULL; - if (CA_STATUS_OK != CACreateEndpoint(flags, g_selectedNwType, - (const char*)address.ipAddress, - address.port, &endpoint)) - { - //ReleaseStringUTFChars for strUri - (*env)->ReleaseStringUTFChars(env, uri, strUri); - LOGE("Could not create remote end point"); - return; - } - - char resourceURI[RESOURCE_URI_LENGTH + 1] = { 0 }; - get_resource_uri(strUri, resourceURI, RESOURCE_URI_LENGTH); - - //ReleaseStringUTFChars for strUri - (*env)->ReleaseStringUTFChars(env, uri, strUri); - - CAMessageType_t messageType = msgType; - - // create token - CAToken_t token = NULL; - uint8_t tokenLength = CA_MAX_TOKEN_LEN; - - res = CAGenerateToken(&token, tokenLength); - if ((CA_STATUS_OK != res) || (!token)) - { - LOGE("token generate error!"); - CADestroyEndpoint(endpoint); - return; - } - - CAInfo_t requestData = { 0 }; - requestData.token = token; - requestData.tokenLength = tokenLength; - requestData.resourceUri = (CAURI_t) malloc(sizeof(resourceURI)); - if (NULL == requestData.resourceUri) - { - LOGE("Memory allocation failed!"); - // destroy token - CADestroyToken(token); - // destroy remote endpoint - CADestroyEndpoint(endpoint); - return; - } - memcpy(requestData.resourceUri, resourceURI, sizeof(resourceURI)); - - if (1 == isSecured) - { - uint32_t length = sizeof(SECURE_INFO_DATA) + strlen(resourceURI); - requestData.payload = (CAPayload_t) malloc(length); - if (NULL == requestData.payload) - { - LOGE("Memory allocation failed!"); - // destroy token - CADestroyToken(token); - // destroy remote endpoint - CADestroyEndpoint(endpoint); - - free(requestData.resourceUri); - return; - } - snprintf((char *) requestData.payload, length, SECURE_INFO_DATA, - resourceURI, g_localSecurePort); - requestData.payloadSize = length; - } - else - { - uint32_t length = sizeof(NORMAL_INFO_DATA) + strlen(resourceURI); - requestData.payload = (CAPayload_t) malloc(length); - if (NULL == requestData.payload) - { - LOGE("Memory allocation failed!"); - // destroy token - CADestroyToken(token); - // destroy remote endpoint - CADestroyEndpoint(endpoint); - - free(requestData.resourceUri); - return; - } - snprintf((char *) requestData.payload, length, NORMAL_INFO_DATA, resourceURI); - requestData.payloadSize = length; - } - - requestData.type = messageType; - - CARequestInfo_t requestInfo = { 0 }; - requestInfo.method = CA_GET; - requestInfo.info = requestData; - - // send notification - if (CA_STATUS_OK != CASendRequest(endpoint, &requestInfo)) - { - LOGE("Could not send notification"); - } - - LOGI("Send Notification"); - - // destroy token - CADestroyToken(token); - - // destroy remote endpoint - CADestroyEndpoint(endpoint); - - free(requestData.payload); - free(requestData.resourceUri); -} - -JNIEXPORT void JNICALL -Java_org_iotivity_ca_service_RMInterface_RMSelectNetwork(JNIEnv *env, jobject obj, - jint networkType) -{ - LOGI("RMSelectNetwork Type : %d", networkType); - if (!env || !obj) - { - LOGI("Invalid input parameter"); - return; - } - - if (CA_STATUS_OK != CASelectNetwork(networkType)) - { - LOGE("Could not select network"); - } -} - -JNIEXPORT void JNICALL -Java_org_iotivity_ca_service_RMInterface_RMUnSelectNetwork(JNIEnv *env, jobject obj, - jint networkType) -{ - LOGI("RMUnSelectNetwork Type : %d", networkType); - if (!env || !obj) - { - LOGI("Invalid input parameter"); - return; - } - - if (CA_STATUS_OK != CAUnSelectNetwork(networkType)) - { - LOGE("Could not unselect network"); - } -} - -JNIEXPORT void JNICALL -Java_org_iotivity_ca_service_RMInterface_RMGetNetworkInfomation(JNIEnv *env, jobject obj) -{ - LOGI("RMGetNetworkInfomation"); - if (!env || !obj) - { - LOGI("Invalid input parameter"); - return; - } - - CAEndpoint_t *tempInfo = NULL; - uint32_t tempSize = 0; - - CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize); - if (CA_STATUS_OK != res) - { - LOGE("Could not start get network information"); - free(tempInfo); - return; - } - - LOGI("################## Network Information #######################"); - callback("######## Network Information", "#######"); - LOGI("Network info total size is %d", tempSize); - - uint32_t index; - for (index = 0; index < tempSize; index++) - { - res = get_remote_address(tempInfo[index].addr); - if (CA_STATUS_OK != res) - { - free(tempInfo); - return; - } - if (NULL != g_responseListenerObject) - { - char networkInfo[NETWORK_INFO_LENGTH]; - LOGI("Type: %d", tempInfo[index].adapter); - snprintf(networkInfo, NETWORK_INFO_LENGTH, "%d",tempInfo[index].adapter); - callback("Type :", networkInfo); - if (CA_ADAPTER_IP == tempInfo[index].adapter) - { - LOGI("Port: %d", tempInfo[index].port); - snprintf(networkInfo, NETWORK_INFO_LENGTH, "%d",tempInfo[index].port); - callback("Port: ", networkInfo); - } - LOGI("Secured: %d", (tempInfo[index].flags & CA_SECURE)); - LOGI("Address: %s", g_remoteAddress); - callback("Address: ", g_remoteAddress); - free(g_remoteAddress); - } - if (tempInfo[index].flags & CA_SECURE) - { - g_localSecurePort = tempInfo[index].port; - } - } - - // free - free(tempInfo); - - LOGI("##############################################################"); -} - -JNIEXPORT void JNICALL -Java_org_iotivity_ca_service_RMInterface_RMHandleRequestResponse(JNIEnv *env, jobject obj) -{ - LOGI("RMHandleRequestResponse"); - if(!env || !obj) - { - LOGI("Invalid input parameter"); - return; - } - - if (CA_STATUS_OK != CAHandleRequestResponse()) - { - LOGE("Could not handle request and response"); - } -} - -void request_handler(const CAEndpoint_t* object, const CARequestInfo_t* requestInfo) -{ - - if (!object) - { - LOGE("Remote endpoint is NULL!"); - return; - } - - if (!requestInfo) - { - LOGE("Request info is NULL!"); - return; - } - - if ((NULL != g_lastRequestToken) && (NULL != requestInfo->info.token) && - (strncmp(g_lastRequestToken, requestInfo->info.token, - requestInfo->info.tokenLength) == 0)) - { - LOGI("token is same. received request of it's own. skip.. "); - return; - } - - CAResult_t res = get_remote_address(object->addr); - if (CA_STATUS_OK != res) - { - return; - } - - LOGI("##########received request from remote device #############"); - LOGI("Remote Address: %s", g_remoteAddress); - LOGI("Remote Port: %d", object->port); - LOGI("Uri: %s", requestInfo->info.resourceUri); - LOGI("Data: %s", requestInfo->info.payload); - LOGI("Token: %s", requestInfo->info.token); - LOGI("Code: %d", requestInfo->method); - LOGI("MessageType: %d", requestInfo->info.type); - - if (NULL != g_responseListenerObject) - { - char *cloneUri = NULL; - uint32_t len = 0; - - if (NULL != requestInfo->info.resourceUri) - { - len = strlen(requestInfo->info.resourceUri); - cloneUri = (char *)malloc(sizeof(char) * (len + 1)); - - if (NULL == cloneUri) - { - LOGE("cloneUri Out of memory"); - free(g_remoteAddress); - return; - } - - memcpy(cloneUri, requestInfo->info.resourceUri, len + 1); - callback("Uri: ", cloneUri); - } - - len = strlen(g_remoteAddress); - char *cloneRemoteAddress = (char *) malloc(sizeof(char) * (len + 1)); - - if (NULL == cloneRemoteAddress) - { - LOGE("cloneRemoteAddress Out of memory"); - free(g_remoteAddress); - free(cloneUri); - return; - } - - memcpy(cloneRemoteAddress, g_remoteAddress, len + 1); - - callback("Remote Address: ", cloneRemoteAddress); - free(cloneRemoteAddress); - free(g_remoteAddress); - - char portInfo[PORT_LENGTH] = { 0, }; - snprintf(portInfo, PORT_LENGTH, "%d", object->port); - callback("Remote Port: ", portInfo); - - //clone g_clientEndpoint - g_clientEndpoint = (CAEndpoint_t *) malloc(sizeof(CAEndpoint_t)); - if (NULL == g_clientEndpoint) - { - LOGE("g_clientEndpoint Out of memory"); - free(cloneUri); - return; - } - memcpy(g_clientEndpoint, object, sizeof(CAEndpoint_t)); - - if (NULL != cloneUri) - { - len = strlen(cloneUri); - g_resourceUri = (char *) malloc(sizeof(char) * (len + 1)); - if (NULL == g_resourceUri) - { - LOGE("g_clientEndpoint->resourceUri Out of memory"); - free(g_clientEndpoint); - free(cloneUri); - return; - } - memcpy(g_resourceUri, cloneUri, len + 1); - free(cloneUri); - } - //clone g_clientToken - len = requestInfo->info.tokenLength; - - g_clientToken = (char *) malloc(sizeof(char) * len); - if (NULL == g_clientToken) - { - LOGE("g_clientToken Out of memory"); - free(g_clientEndpoint); - return; - } - - if (NULL != requestInfo->info.token) - { - memcpy(g_clientToken, requestInfo->info.token, len); - g_clientTokenLength = len; - - } - - //clone g_clientMsgId - g_clientMsgId = requestInfo->info.messageId; - - if (NULL != requestInfo->info.payload && requestInfo->info.payloadSize > 0) - { - len = requestInfo->info.payloadSize; - char *clonePayload = (char *) malloc(len + 1); - if (NULL == clonePayload) - { - LOGE("clonePayload Out of memory"); - free(g_clientEndpoint); - return; - } - - memcpy(clonePayload, requestInfo->info.payload, len); - clonePayload[len] = '\0'; - - if (len > BIG_PAYLOAD_LENGTH) - { - saveFile(clonePayload, len); - } - else - { - callback("Data: ", clonePayload); - } - free(clonePayload); - } - } - - if (requestInfo->info.options) - { - uint32_t len = requestInfo->info.numOptions; - uint32_t i; - - LOGI("Option count: %d", requestInfo->info.numOptions); - - for (i = 0; i < len; i++) - { - LOGI("Option %d", i + 1); - LOGI("ID : %d", requestInfo->info.options[i].optionID); - LOGI("Data[%d]: %s", requestInfo->info.options[i].optionLength, - requestInfo->info.options[i].optionData); - - if (NULL != g_responseListenerObject) - { - char optionInfo[OPTION_INFO_LENGTH] = { 0, }; - snprintf(optionInfo, OPTION_INFO_LENGTH, - "Num[%d] - ID : %d, Option Length : %d", i + 1, - requestInfo->info.options[i].optionID, - requestInfo->info.options[i].optionLength); - - callback("Option info: ", optionInfo); - - size_t optionDataLen = strlen(requestInfo->info.options[i].optionData); - char *cloneOptionData = (char *) malloc(sizeof(char) * (optionDataLen + 1)); - if (NULL == cloneOptionData) - { - LOGE("cloneOptionData Out of memory"); - free(g_clientEndpoint); - return; - } - - memcpy(cloneOptionData, requestInfo->info.options[i].optionData, - optionDataLen + 1); - - callback("Option Data: ", cloneOptionData); - free(cloneOptionData); - } - } - } - LOGI("############################################################"); - - //Check if this has secure communication information - if (requestInfo->info.payload && CA_ADAPTER_IP == object->adapter) - { - uint32_t securePort = get_secure_information(requestInfo->info.payload); - if (0 < securePort) //Set the remote endpoint secure details and send response - { - LOGI("This is secure resource..."); - - CAEndpoint_t *endpoint = NULL; - if (CA_STATUS_OK != CACreateEndpoint(CA_SECURE, - object->adapter, object->addr, securePort, &endpoint)) - { - LOGE("Failed to create duplicate of remote endpoint!"); - return; - } - object = endpoint; - } - } -} - -void response_handler(const CAEndpoint_t* object, const CAResponseInfo_t* responseInfo) -{ - if (!object || !responseInfo) - { - LOGE("Invalid input parameter"); - return; - } - - CAResult_t res = get_remote_address(object->addr); - if (CA_STATUS_OK != res) - { - return; - } - - LOGI("##########Received response from remote device #############"); - LOGI("Uri: %s", responseInfo->info.resourceUri); - LOGI("Remote Address: %s", g_remoteAddress); - LOGI("Remote Port: %d", object->port); - LOGI("response result: %d", responseInfo->result); - LOGI("Data: %s", responseInfo->info.payload); - LOGI("Token: %s", responseInfo->info.token); - LOGI("MessageType: %d", responseInfo->info.type); - - if (NULL != g_responseListenerObject) - { - uint32_t len = 0; - - if (NULL != responseInfo->info.resourceUri) - { - len = strlen(responseInfo->info.resourceUri); - char *cloneUri = (char *) malloc(sizeof(char) * (len + 1)); - - if (NULL == cloneUri) - { - LOGE("cloneUri Out of memory"); - free(g_remoteAddress); - return; - } - - memcpy(cloneUri, responseInfo->info.resourceUri, len + 1); - - callback("Uri: ", cloneUri); - free(cloneUri); - } - - len = strlen(g_remoteAddress); - char *cloneRemoteAddress = (char *) malloc(sizeof(char) * (len + 1)); - - if (NULL == cloneRemoteAddress) - { - LOGE("cloneRemoteAddress Out of memory"); - free(g_remoteAddress); - return; - } - - memcpy(cloneRemoteAddress, g_remoteAddress, len + 1); - - callback("Remote Address: ", cloneRemoteAddress); - free(cloneRemoteAddress); - free(g_remoteAddress); - - char portInfo[PORT_LENGTH] = { 0, }; - snprintf(portInfo, PORT_LENGTH, "%d", object->port); - callback("Remote Port: ", portInfo); - - if (NULL != responseInfo->info.payload && responseInfo->info.payloadSize) - { - len = responseInfo->info.payloadSize; - char *clonePayload = (char *) malloc(len + 1); - if (NULL == clonePayload) - { - LOGE("clonePayload Out of memory"); - return; - } - - memcpy(clonePayload, responseInfo->info.payload, len); - clonePayload[len] = '\0'; - - if (len > BIG_PAYLOAD_LENGTH) - { - saveFile(clonePayload, len); - } - else - { - callback("Data: ", clonePayload); - } - free(clonePayload); - } - } - - if (responseInfo->info.options) - { - uint32_t len = responseInfo->info.numOptions; - uint32_t i; - for (i = 0; i < len; i++) - { - LOGI("Option %d", i + 1); - LOGI("ID : %d", responseInfo->info.options[i].optionID); - LOGI("Data[%d]: %s", responseInfo->info.options[i].optionLength, - responseInfo->info.options[i].optionData); - - if (NULL != g_responseListenerObject) - { - char optionInfo[OPTION_INFO_LENGTH] = { 0, }; - snprintf(optionInfo, OPTION_INFO_LENGTH, - "Num[%d] - ID : %d, Option Length : %d", i + 1, - responseInfo->info.options[i].optionID, - responseInfo->info.options[i].optionLength); - - callback("Option info: ", optionInfo); - - size_t optionDataLen = strlen(responseInfo->info.options[i].optionData); - char *cloneOptionData = (char *) malloc(sizeof(char) * (optionDataLen + 1)); - if (NULL == cloneOptionData) - { - LOGE("cloneOptionData Out of memory"); - return; - } - memcpy(cloneOptionData, responseInfo->info.options[i].optionData, - optionDataLen + 1); - callback("Option Data: ", cloneOptionData); - free(cloneOptionData); - } - } - } - LOGI("############################################################"); - - //Check if this has secure communication information - if (responseInfo->info.payload && CA_ADAPTER_IP == object->adapter) - { - uint32_t securePort = get_secure_information(responseInfo->info.payload); - if (0 < securePort) //Set the remote endpoint secure details and send response - { - LOGI("This is secure resource..."); - } - } -} - -void error_handler(const CAEndpoint_t *rep, const CAErrorInfo_t* errorInfo) -{ - LOGI("+++++++++++++++++++++++++++++++++++ErrorInfo+++++++++++++++++++++++++++++++++++"); - - if (rep) - { - LOGI("Error Handler, Adapter Type : %d", rep->adapter); - LOGI("Error Handler, Adapter Type : %s", rep->addr); - } - - if (errorInfo) - { - const CAInfo_t *info = &errorInfo->info; - LOGI("Error Handler, ErrorInfo :"); - LOGI("Error Handler result : %d", errorInfo->result); - LOGI("Error Handler token : %s", info->token); - LOGI("Error Handler messageId : %d", (uint16_t) info->messageId); - LOGI("Error Handler resourceUri : %s", info->resourceUri); - LOGI("Error Handler type : %d", info->type); - LOGI("Error Handler payload : %s", info->payload); - - if(CA_ADAPTER_NOT_ENABLED == errorInfo->result) - { - LOGE("CA_ADAPTER_NOT_ENABLED, enable the adapter"); - } - else if(CA_SEND_FAILED == errorInfo->result) - { - LOGE("CA_SEND_FAILED, unable to send the message, check parameters"); - } - else if(CA_MEMORY_ALLOC_FAILED == errorInfo->result) - { - LOGE("CA_MEMORY_ALLOC_FAILED, insufficient memory"); - } - else if(CA_SOCKET_OPERATION_FAILED == errorInfo->result) - { - LOGE("CA_SOCKET_OPERATION_FAILED, socket operation failed"); - } - else if(CA_STATUS_FAILED == errorInfo->result) - { - LOGE("CA_STATUS_FAILED, message could not be delivered, internal error"); - } - } - LOGI("++++++++++++++++++++++++++++++++End of ErrorInfo++++++++++++++++++++++++++++++++"); - - return; -} - -void get_resource_uri(const char *URI, char *resourceURI, int32_t length) -{ - const char *startPos = URI; - const char *temp = strstr(URI, "://"); - if (NULL != temp) - { - startPos = strchr(temp + 3, '/'); - if (!startPos) - { - LOGE("Resource URI is missing"); - return; - } - } - - const char *endPos = strchr(startPos, '?'); - if (!endPos) - { - endPos = URI + strlen(URI); - } - --endPos; - - if (endPos - startPos <= length) - { - memcpy(resourceURI, startPos + 1, endPos - startPos); - } - - LOGI("URI: %s, ResourceURI: %s", URI, resourceURI); -} - -uint32_t get_secure_information(CAPayload_t payLoad) -{ - LOGI("entering get_secure_information"); - - if (!payLoad) - { - LOGE("Payload is NULL"); - return -1; - } - - const char *subString = NULL; - if (NULL == (subString = strstr((const char *) payLoad, "\"sec\":1"))) - { - LOGE("This is not secure resource"); - return -1; - } - - if (NULL == (subString = strstr((const char *) payLoad, "\"port\":"))) - { - LOGE("This secure resource does not have port information"); - return -1; - } - - const char *startPos = strstr(subString, ":"); - if (!startPos) - { - LOGE("Parsing failed !"); - return -1; - } - - const char *endPos = strstr(startPos, "}"); - if (!endPos) - { - LOGE("Parsing failed !"); - return -1; - } - - char portStr[6] = { 0 }; - memcpy(portStr, startPos + 1, (endPos - 1) - startPos); - - LOGI("secured port is: %s", portStr); - return atoi(portStr); -} - -CAResult_t get_network_type(uint32_t selectedNetwork, CATransportFlags_t *flags) -{ - - uint32_t number = selectedNetwork; - - if (!(number & CA_ALL_ADAPTERS)) - { - LOGE("get_network_type Out of range"); - return CA_NOT_SUPPORTED; - } - if ((number & CA_ADAPTER_IP) == CA_ADAPTER_IP) - { - *flags = CA_IPV4; - g_selectedNwType = CA_ADAPTER_IP; - return CA_STATUS_OK; - } - if ((number & CA_ADAPTER_RFCOMM_BTEDR) == CA_ADAPTER_RFCOMM_BTEDR) - { - g_selectedNwType = CA_ADAPTER_RFCOMM_BTEDR; - return CA_STATUS_OK; - } - if ((number & CA_ADAPTER_GATT_BTLE) == CA_ADAPTER_GATT_BTLE) - { - g_selectedNwType = CA_ADAPTER_GATT_BTLE; - return CA_STATUS_OK; - } - if ((number & CA_ADAPTER_TCP) == CA_ADAPTER_TCP) - { - g_selectedNwType = CA_ADAPTER_TCP; - return CA_STATUS_OK; - } - if ((number & CA_ADAPTER_NFC) == CA_ADAPTER_NFC) - { - g_selectedNwType = CA_ADAPTER_NFC; - return CA_STATUS_OK; - } - - LOGE("Invalid transport"); - return CA_NOT_SUPPORTED; -} - -void callback(char *subject, char *receivedData) -{ - bool isAttached = false; - JNIEnv* env; - - if (!g_responseListenerObject) - { - LOGE("g_responseListenerObject is NULL, cannot have callback"); - return; - } - - jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6); - if (JNI_OK != res) - { - LOGI("Could not get JNIEnv pointer"); - res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL); - - if (JNI_OK != res) - { - LOGE("AttachCurrentThread has failed"); - return; - } - isAttached = true; - } - - jclass cls = (*env)->GetObjectClass(env, g_responseListenerObject); - if (!cls) - { - LOGE("could not get class"); - goto detach_thread; - } - - jmethodID mid = (*env)->GetMethodID(env, cls, "OnResponseReceived", - "(Ljava/lang/String;Ljava/lang/String;)V"); - if (!mid) - { - LOGE("could not get Method ID"); - goto detach_thread; - } - - jstring jsubject = (*env)->NewStringUTF(env, (char*) subject); - if (!jsubject) - { - LOGE("NewStringUTF failed"); - goto detach_thread; - } - - jstring jreceivedData = (*env)->NewStringUTF(env, (char*) receivedData); - if (!jreceivedData) - { - LOGE("NewStringUTF failed"); - goto detach_thread; - } - - (*env)->CallVoidMethod(env, g_responseListenerObject, mid, jsubject, jreceivedData); - -detach_thread : - if (isAttached) - { - (*g_jvm)->DetachCurrentThread(g_jvm); - LOGI("DetachCurrentThread"); - } -} - -CAResult_t get_remote_address(const char *address) -{ - uint32_t len = strlen(address); - - g_remoteAddress = (char *)malloc(sizeof (char) * (len + 1)); - if (NULL == g_remoteAddress) - { - LOGE("g_remoteAddress Out of memory"); - return CA_MEMORY_ALLOC_FAILED; - } - - memcpy(g_remoteAddress, address, len + 1); - - return CA_STATUS_OK; -} - - -void parsing_coap_uri(const char* uri, addressSet_t* address, CATransportFlags_t *flags) -{ - if (NULL == uri || NULL == address) - { - LOGE("parameter is null"); - return; - } - - // parse uri - // #1. check prefix - uint8_t startIndex = 0; - if (strncmp(COAPS_PREFIX, uri, COAPS_PREFIX_LEN) == 0) - { - LOGI("uri has '%s' prefix", COAPS_PREFIX); - startIndex = COAPS_PREFIX_LEN; - *flags = CA_SECURE; - } - else if (strncmp(COAP_PREFIX, uri, COAP_PREFIX_LEN) == 0) - { - LOGI("uri has '%s' prefix", COAP_PREFIX); - startIndex = COAP_PREFIX_LEN; - } - else if (strncmp(COAP_TCP_PREFIX, uri, COAP_TCP_PREFIX_LEN) == 0) - { - LOGI("uri has '%s' prefix\n", COAP_TCP_PREFIX); - startIndex = COAP_TCP_PREFIX_LEN; - *flags = CA_IPV4; - } - - // #2. copy uri for parse - size_t len = strlen(uri) - startIndex; - - if (len <= 0) - { - LOGE("uri length is 0!"); - return; - } - - char *cloneUri = (char *) calloc(len + 1, sizeof(char)); - if (NULL == cloneUri) - { - LOGE("Out of memory"); - return; - } - - OICStrcpy(cloneUri, len+1, &uri[startIndex]); - - char *pstr = NULL; - //filter out the resource uri - char *pUrl = strtok_r(cloneUri, "/", &pstr); - - if (pUrl) - { - LOGI("pAddress : %s", pUrl); - int res = get_address_set(pUrl, address); - if (res == -1) - { - LOGE("address parse error"); - return; - } - } - else - { - LOGE("strtok_r error, could not get the address"); - } - - return; -} - -int get_address_set(const char *pAddress, addressSet_t* outAddress) -{ - if (NULL == pAddress || NULL == outAddress) - { - LOGE("parameter is null"); - return -1; - } - - size_t len = strlen(pAddress); - int isIp = 0; - size_t ipLen = 0; - - for (size_t i = 0; i < len; i++) - { - if (pAddress[i] == '.') - { - isIp = 1; - } - - // found port number start index - if (isIp && pAddress[i] == ':') - { - ipLen = i; - break; - } - } - - if (isIp) - { - if(ipLen && (ipLen < sizeof(outAddress->ipAddress))) - { - strncpy(outAddress->ipAddress, pAddress, ipLen); - outAddress->ipAddress[ipLen] = '\0'; - } - else if (!ipLen && (len < sizeof(outAddress->ipAddress))) - { - strncpy(outAddress->ipAddress, pAddress, len); - outAddress->ipAddress[len] = '\0'; - } - else - { - LOGE("IP Address too long: %d", ipLen==0 ? len : ipLen); - return -1; - } - - if (ipLen > 0) - { - outAddress->port = atoi(pAddress + ipLen + 1); - } - } - else - { - strncpy(outAddress->ipAddress, pAddress, len); - outAddress->ipAddress[len] = '\0'; - } - - return isIp; -} - -void delete_global_references(JNIEnv *env, jobject obj) -{ - LOGI("delete_global_references"); - if (!env || !obj ) - { - LOGI("Invalid input parameter"); - return; - } - - CADeleteGlobalReferences(env); - (*env)->DeleteGlobalRef(env, g_responseListenerObject); -} - - -bool read_file(const char* name, char** bytes, size_t* length) -{ - if (NULL == name) - { - LOGE("parameter is null"); - return false; - } - - FILE* file; - char* buffer; - long fileLen; - - // Open file - file = fopen(name, "rt"); - if (!file) - { - fprintf(stderr, "Unable to open file %s", name); - return false; - } - - // Get file length - fseek(file, 0, SEEK_END); - fileLen = ftell(file); - if (-1 == fileLen) - { - fprintf(stderr, "Failed to read file length"); - fclose(file); - return false; - } - fseek(file, 0, SEEK_SET); - - LOGI("file size: %ld", fileLen); - - // Allocate memory - buffer = calloc(1, sizeof(char) * fileLen + 1); - if (!buffer) - { - fprintf(stderr, "Memory error!"); - fclose(file); - return false; - } - - // Read file contents into buffer - size_t ret = fread(buffer, fileLen, 1, file); - if (ret != 1) - { - printf("Failed to read data from file, %s\n", name); - fclose(file); - free(buffer); - return false; - } - - fclose(file); - - LOGI("file bytes: %s", buffer); - - *bytes = buffer; - *length = fileLen; - - return true; -} - -void saveFile(const char *payload, size_t payloadSize) -{ - // 1. get day - uint32_t day = gettodaydate(); - - // 2. get time - time_t current_time; - struct tm * time_info; - char timeString[RECEIVED_FILE_NAME_PREFIX_LENGTH]; - - time(¤t_time); - time_info = localtime(¤t_time); - - strftime(timeString, sizeof(timeString), "%H%M%S", time_info); - - uint32_t path_length = strlen(RECEIVED_FILE_PATH) + RECEIVED_FILE_NAME_LENGTH + 1; - char* path = calloc(1, sizeof(char) * path_length); - if (path != NULL) - { - snprintf(path, path_length, RECEIVED_FILE_PATH, day, timeString); - LOGI("received file path: %s", path); - - FILE *fp = fopen(path, "wt"); - fwrite(payload, 1, payloadSize, fp); - fclose(fp); - - callback("File Path: ", path); - } - else - { - LOGE("path Out of memory"); - } -} - -uint32_t gettodaydate() -{ - uint32_t ldate; - time_t clock; - struct tm *date; - - clock = time(0); - date = localtime(&clock); - ldate = date->tm_year * 100000; - ldate += (date->tm_mon + 1) * 1000; - ldate += date->tm_mday * 10; - ldate += date->tm_wday; - ldate += 190000000; - ldate /= 10; - - return(ldate); -} diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/org_iotivity_ca_service_RMInterface.h b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/org_iotivity_ca_service_RMInterface.h deleted file mode 100644 index cdf6a99..0000000 --- a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/jni/org_iotivity_ca_service_RMInterface.h +++ /dev/null @@ -1,118 +0,0 @@ -#include -/* Header for class org_iotivity_ca_service_RMInterface */ - -#ifndef _Included_org_iotivity_ca_service_RMInterface -#define _Included_org_iotivity_ca_service_RMInterface -#ifdef __cplusplus -extern "C" { -#endif -JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_setNativeResponseListener - (JNIEnv *, jobject, jobject); -/* - * Class: org_iotivity_ca_service_RMInterface - * Method: RMInitialize - * Signature: (Landroid/content/Context;Landroid/app/activity;)V - */ -JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMInitialize - (JNIEnv *, jobject, jobject, jobject); - -/* - * Class: org_iotivity_ca_service_RMInterface - * Method: RMTerminate - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMTerminate - (JNIEnv *, jobject); - -/* - * Class: org_iotivity_ca_service_RMInterface - * Method: RMStartListeningServer - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMStartListeningServer - (JNIEnv *, jobject); - -/* - * Class: org_iotivity_ca_service_RMInterface - * Method: RMStartDiscoveryServer - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMStartDiscoveryServer - (JNIEnv *, jobject); - -/* - * Class: org_iotivity_ca_service_RMInterface - * Method: RMRegisterHandler - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMRegisterHandler - (JNIEnv *, jobject); - -/* - * Class: org_iotivity_ca_service_RMInterface - * Method: RMSendRequest - * Signature: (Ljava/lang/String;Ljava/lang/String;III)V - */ -JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMSendRequest - (JNIEnv *, jobject, jstring, jstring, jint, jint, jint, jboolean); - -/* - * Class: org_iotivity_ca_service_RMInterface - * Method: RMSendReqestToAll - * Signature: (Ljava/lang/String;I)V - */ -JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMSendReqestToAll - (JNIEnv *, jobject, jstring, jint); - -/* - * Class: org_iotivity_ca_service_RMInterface - * Method: RMSendResponse - * Signature: (IIII)V - */ -JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMSendResponse - (JNIEnv *, jobject, jint, jint, jint, jint); - -/* - * Class: org_iotivity_ca_service_RMInterface - * Method: RMSendNotification - * Signature: (Ljava/lang/String;Ljava/lang/String;IIII)V - */ -JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMSendNotification - (JNIEnv *, jobject, jstring, jstring, jint, jint, jint); - -/* - * Class: org_iotivity_ca_service_RMInterface - * Method: RMSelectNetwork - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMSelectNetwork - (JNIEnv *, jobject, jint); - -/* - * Class: org_iotivity_ca_service_RMInterface - * Method: RMUnSelectNetwork - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMUnSelectNetwork - (JNIEnv *, jobject, jint); - -/* - * Class: org_iotivity_ca_service_RMInterface - * Method: RMGetNetworkInfomation - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMGetNetworkInfomation - (JNIEnv *, jobject); - -/* - * Class: org_iotivity_ca_service_RMInterface - * Method: RMHandleRequestResponse - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_iotivity_ca_service_RMInterface_RMHandleRequestResponse - (JNIEnv *, jobject); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/layout/activity_main.xml b/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/layout/activity_main.xml deleted file mode 100755 index 69642b6..0000000 --- a/resource/csdk/connectivity/samples/android/casample/sampleService/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,265 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -