Commit fab8d7d1 authored by Vinil Jain's avatar Vinil Jain Committed by Madan Lanka

Prevent issue fixes

-c++, java issues
-BLE context issue fix

Change-Id: I0f1eeee8b11f77de9524621ce425b98bc8b4f916
Signed-off-by: default avatarVinil Jain <vinil.gj@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2865Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarMadan Lanka <lanka.madan@samsung.com>
parent 962339c0
......@@ -34,8 +34,6 @@ import org.iotivity.service.easysetup.impl.WiFiOnBoardingConfig;
import org.iotivity.service.easysetup.impl.WiFiProvConfig;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.wifi.WifiConfiguration;
import android.os.Bundle;
import android.os.Handler;
......@@ -45,7 +43,6 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
......@@ -58,9 +55,6 @@ public class MainActivity extends Activity {
public static final int FAILED = 1;
public static final int STATE_CHANGED = 2;
static final int REQUEST_IMAGE_CAPTURE = 1;
ImageView imageView;
EditText mSsidText;
EditText mPassText;
......@@ -169,8 +163,7 @@ public class MainActivity extends Activity {
public void onDestroy() {
super.onDestroy();
/*Reset the Easy setup process*/
if(mEasySetupService != null)
{
if (mEasySetupService != null) {
mEasySetupService.finish();
}
}
......@@ -234,14 +227,6 @@ public class MainActivity extends Activity {
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
imageView.setImageBitmap(imageBitmap);
}
}
class ThreadHandler extends Handler {
@Override
......
......@@ -13,6 +13,6 @@
android:id="@+id/textView_ble"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
android:text="hello_world" />
</RelativeLayout>
......@@ -34,8 +34,10 @@
int quitFlag = 0;
/* SIGINT handler: set quitFlag to 1 for graceful termination */
void handleSigInt(int signum) {
if (signum == SIGINT) {
void handleSigInt(int signum)
{
if (signum == SIGINT)
{
quitFlag = 1;
}
}
......@@ -46,16 +48,18 @@ void handleSigInt(int signum) {
* and also holds the Enrollee information for which provisioning is requested
* This function can be used to update the application about the current provisioning status of the Enrollee
*/
void ProvisioningStatusCallback(ProvisioningInfo *provInfo) {
void ProvisioningStatusCallback(ProvisioningInfo *provInfo)
{
OIC_LOG_V(INFO, TAG, "Enrollee connectivity: %d", provInfo->provDeviceInfo.connType);
if(provInfo->provStatus == DEVICE_PROVISIONED)
if (provInfo->provStatus == DEVICE_PROVISIONED)
{
OIC_LOG_V(INFO, TAG, "Successfully provisioned the Enrollee with IP : %s ",
provInfo->provDeviceInfo.addr->addr);
provInfo->provDeviceInfo.addr->addr);
}
else{
else
{
OIC_LOG_V(INFO, TAG, "Provisioing Failed for the Enrollee with IP : %s",
provInfo->provDeviceInfo.addr->addr);
provInfo->provDeviceInfo.addr->addr);
}
}
......@@ -64,8 +68,8 @@ static void PrintUsage()
OIC_LOG(INFO, TAG, "Usage : occlient -d \"192.168.0.20\"");
}
int main (int argc, char**argv) {
int main(int argc, char**argv)
{
int opt;
EnrolleeNWProvInfo_t netInfo;
PrintUsage();
......@@ -75,16 +79,16 @@ int main (int argc, char**argv) {
while ((opt = getopt(argc, argv, "d:s:p:")) != -1)
{
switch(opt)
switch (opt)
{
case 'd':
strncpy(netInfo.netAddressInfo.WIFI.ipAddress, optarg, IPV4_ADDR_SIZE);
strncpy(netInfo.netAddressInfo.WIFI.ipAddress, optarg, IPV4_ADDR_SIZE - 1);
break;
case 's':
strncpy(netInfo.netAddressInfo.WIFI.ssid, optarg, NET_WIFI_SSID_SIZE);
strncpy(netInfo.netAddressInfo.WIFI.ssid, optarg, NET_WIFI_SSID_SIZE - 1);
break;
case 'p':
strncpy(netInfo.netAddressInfo.WIFI.pwd, optarg, NET_WIFI_PWD_SIZE);
strncpy(netInfo.netAddressInfo.WIFI.pwd, optarg, NET_WIFI_PWD_SIZE - 1);
break;
default:
PrintUsage();
......@@ -94,14 +98,15 @@ int main (int argc, char**argv) {
netInfo.connType = CT_ADAPTER_IP;
OIC_LOG_V(INFO, TAG, "IP Address of the Provisioning device is =%s\n",
netInfo.netAddressInfo.WIFI.ipAddress);
OIC_LOG_V(INFO, TAG, "SSID of the Enroller is =%s\n",netInfo.netAddressInfo.WIFI.ssid);
OIC_LOG_V(INFO, TAG, "Password of the Enroller is =%s\n",netInfo.netAddressInfo.WIFI.pwd);
netInfo.netAddressInfo.WIFI.ipAddress);
OIC_LOG_V(INFO, TAG, "SSID of the Enroller is =%s\n", netInfo.netAddressInfo.WIFI.ssid);
OIC_LOG_V(INFO, TAG, "Password of the Enroller is =%s\n", netInfo.netAddressInfo.WIFI.pwd);
ProvisionEnrollee(&netInfo);
signal(SIGINT, handleSigInt);
while (!quitFlag) {
while (!quitFlag)
{
sleep(1);
}
......
......@@ -151,7 +151,9 @@ int getCurrentNetworkInfo(NetworkType targetType, NetworkInfo *info)
{
info->type = ES_WIFI;
info->ipaddr = WiFi.localIP();
strcpy(info->ssid, WiFi.SSID());
if(strlen(WiFi.SSID())<=MAXSSIDLEN)
strcpy(info->ssid, WiFi.SSID());
else return -1;
return 0;
}
......
......@@ -112,6 +112,7 @@ ESResult FindNetworkForOnboarding(NetworkType networkType,
return ES_OK;
}
}
return ES_ERROR;
}
......
/**
* ***************************************************************
* <p/>
* <p>
* Copyright 2015 Samsung Electronics All Rights Reserved.
* <p/>
* <p/>
* <p/>
* <p>
* <p>
* <p>
* 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
* <p/>
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* <p>
* 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.
* <p/>
* <p>
* ****************************************************************
*/
......@@ -88,8 +88,7 @@ public class EasySetupService {
public void finish() {
//Native Api call to reset OIC stack
if(mProvisionEnrolleeInstance != null)
{
if (mProvisionEnrolleeInstance != null) {
mProvisionEnrolleeInstance.stopEnrolleeProvisioning(0);
}
}
......@@ -117,12 +116,12 @@ public class EasySetupService {
public void onFinished(OnBoardingConnection connection) {
if (connection.isConnected()) {
Log.i(TAG, "On boarding is successful ");
try {
/*try {
Log.i(TAG, "waiting for 15 seconds to start provisioning");
Thread.sleep(15000);//Sleep for allowing thin device to start the services
} catch (InterruptedException e) {
e.printStackTrace();
}
}*/
// Start provisioning here
enrolledevice.setConnection(connection);
......@@ -144,16 +143,14 @@ public class EasySetupService {
* @param enrolleedevice Device to be enrolled in network
*/
public synchronized void stopSetup(EnrolleeDevice enrolleedevice) {
if(enrolleedevice.mState == EnrolleeState.DEVICE_ON_BOARDING_STATE) {
if(mEnrolleeDeviceList.contains(enrolleedevice)) {
if (enrolleedevice.mState == EnrolleeState.DEVICE_ON_BOARDING_STATE) {
if (mEnrolleeDeviceList.contains(enrolleedevice)) {
Log.i(TAG, "stopOnBoardingProcess for enrolleedevice");
enrolleedevice.stopOnBoardingProcess();
mEnrolleeDeviceList.remove(enrolleedevice);
}
}
else if(enrolleedevice.mState == EnrolleeState.DEVICE_PROVISIONING_STATE)
{
if(mEnrolleeDeviceList.contains(enrolleedevice)) {
} else if (enrolleedevice.mState == EnrolleeState.DEVICE_PROVISIONING_STATE) {
if (mEnrolleeDeviceList.contains(enrolleedevice)) {
Log.i(TAG, "stopOnBoardingProcess for enrolleedevice");
enrolleedevice.stopOnBoardingProcess();
......@@ -180,7 +177,7 @@ public class EasySetupService {
@Override
public void onFinished(EnrolleeDevice enrolledevice) {
if(mEnrolleeDeviceList.contains(enrolledevice)) {
if (mEnrolleeDeviceList.contains(enrolledevice)) {
Log.i(TAG, "onFinished() is received " + enrolledevice.isSetupSuccessful());
mCallback.onFinished(enrolledevice);
mEnrolleeDeviceList.remove(enrolledevice);
......
......@@ -87,7 +87,9 @@ public abstract class EnrolleeDevice {
mConnection = conn;
}
public OnBoardingConnection getConnection() { return mConnection;}
public OnBoardingConnection getConnection() {
return mConnection;
}
/**
......@@ -120,6 +122,13 @@ public abstract class EnrolleeDevice {
return (mState == EnrolleeState.DEVICE_PROVISIONING_SUCCESS_STATE) ? true : false;
}
/**
* sets error occured during easy setup process
*/
public void setError(EnrolleeSetupError error) {
mError = error;
}
/**
* Returns error occured during easy setup process
*
......@@ -149,5 +158,4 @@ public abstract class EnrolleeDevice {
}
}
......@@ -29,8 +29,6 @@ public class IpOnBoardingConnection implements OnBoardingConnection {
private String mHardwareAddress;
private String mDeviceName;
private boolean isReachable;
public void setHardwareAddress(String address) {
mHardwareAddress = address;
}
......
......@@ -24,7 +24,7 @@ import android.util.Log;
import org.iotivity.base.OcConnectivityType;
import org.iotivity.service.easysetup.core.BleConnection;
import org.iotivity.service.easysetup.core.ConnectionInterface;
import org.iotivity.service.easysetup.core.OnBoardingConnection;
import org.iotivity.service.easysetup.core.EnrolleeDevice;
import org.iotivity.service.easysetup.core.EnrolleeState;
import org.iotivity.service.easysetup.core.OnBoardingConfig;
......@@ -112,7 +112,7 @@ public class EnrolleeDeviceBLEOnBoarding extends EnrolleeDevice {
}
@Override
protected void startProvisioningProcess(ConnectionInterface conn) {
protected void startProvisioningProcess(OnBoardingConnection conn) {
Log.i("start provisioning BLE", mProvConfig.getConnType() + "");
......
......@@ -31,7 +31,6 @@ import org.iotivity.service.easysetup.core.EnrolleeState;
import org.iotivity.service.easysetup.core.IpOnBoardingConnection;
import org.iotivity.service.easysetup.core.OnBoardingConfig;
import org.iotivity.service.easysetup.core.ProvisioningConfig;
import org.iotivity.service.easysetup.mediator.EasySetupCallbackHandler;
import org.iotivity.service.easysetup.mediator.EasySetupManager;
import org.iotivity.service.easysetup.mediator.EnrolleeInfo;
import org.iotivity.service.easysetup.mediator.IOnBoardingStatus;
......@@ -80,7 +79,7 @@ public class EnrolleeDeviceWiFiOnboarding extends EnrolleeDevice {
conn.setHardwareAddress(enrolleStatus.getHWAddr());
conn.setDeviceName(enrolleStatus.getDevice());
Log.d("ESSoftAPOnBoarding", "Entered");
Log.d("ESSoftAPOnBoarding", "Entered"+finalResult);
mOnBoardingCallback.onFinished(conn);
return;
......
......@@ -36,7 +36,6 @@ public class WiFiOnBoardingConfig implements OnBoardingConfig {
private final WifiConfiguration config = new WifiConfiguration();
private final ConnType mConnType = OnBoardingConfig.ConnType.WiFi;
private IpOnBoardingConnection mConnection;
@Override
public Object getConfig() {
......
/**
* ***************************************************************
* <p>
* <p/>
* Copyright 2015 Samsung Electronics All Rights Reserved.
* <p>
* <p>
* <p>
* <p/>
* <p/>
* <p/>
* 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
* <p>
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* <p/>
* 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.
* <p>
* <p/>
* ****************************************************************
*/
......@@ -27,7 +27,6 @@ import android.util.Log;
public class ProvisionEnrollee {
private static final String TAG = "ProvisionEnrollee";
private Context appContext = null;
private EasySetupManager easySetupManagerNativeInstance = null;
private IProvisioningListener provisioningListener;
......@@ -35,9 +34,6 @@ public class ProvisionEnrollee {
* Constructor for ProvisionEnrollee. Constructs a new ProvisionEnrollee.
*/
public ProvisionEnrollee(Context context) {
appContext = context;
easySetupManagerNativeInstance = EasySetupManager.getInstance();
easySetupManagerNativeInstance.initEasySetup();
}
@Override
......
......@@ -21,12 +21,7 @@ package org.iotivity.service.easysetup.mediator.ble;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.os.Handler;
import android.util.Log;
......@@ -35,7 +30,6 @@ import org.iotivity.service.easysetup.impl.BLEOnBoardingConfig;
import org.iotivity.service.easysetup.mediator.EnrolleeInfo;
import org.iotivity.service.easysetup.mediator.IOnBoardingStatus;
import java.util.List;
import java.util.UUID;
public class BLEManager {
......@@ -44,10 +38,8 @@ public class BLEManager {
private Context mcontext;
private Handler mHandler;
private static final long SCAN_PERIOD = 10000;
private BluetoothGatt gatt;
private BLEOnBoardingConfig bleOnBoardingConfig;
private IOnBoardingStatus finishlistener;
private boolean connection_successful = false;
public BLEManager(Context context, BLEOnBoardingConfig config) {
mcontext = context;
......@@ -92,18 +84,13 @@ public class BLEManager {
}
public void connect(BluetoothDevice device) {
gatt = device.connectGatt(mcontext, false, gattCallback);
}
private BluetoothAdapter.LeScanCallback mLeScanCallback =
new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
Log.d("device found", device.getAddress() + " " + device.getUuids());
Log.d("device found", device.getAddress());
bleOnBoardingConfig.setMacaddress(device.getAddress());
{
stopscan();
......@@ -112,56 +99,10 @@ public class BLEManager {
result.setHWAddr(bleOnBoardingConfig.getMacaddress());
NotifyApplication(result);
//TODO- Device will have to be disconnected so that the multicast works while discovery resources
//Not connecting to device
//connect(device);
}
}
};
private BluetoothGattCallback gattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
super.onConnectionStateChange(gatt, status, newState);
Log.d("connection state:", "status" + status + ":" + newState);
EnrolleeInfo result = new EnrolleeInfo();
switch (newState) {
case BluetoothProfile.STATE_CONNECTED:
Log.d("gattCallback", "STATE_CONNECTED");
connection_successful = true;
gatt.disconnect();
break;
case BluetoothProfile.STATE_DISCONNECTED:
Log.e("gattCallback", "STATE_DISCONNECTED");
if (connection_successful) {
result.setReachable(true);
result.setHWAddr(bleOnBoardingConfig.getMacaddress());
NotifyApplication(result);
} else {
result.setReachable(false);
NotifyApplication(result);
}
break;
default:
Log.e("gattCallback", "STATE_OTHER");
}
}
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
List<BluetoothGattService> services = gatt.getServices();
Log.i("onServicesDiscovered", services.toString());
gatt.readCharacteristic(services.get(1).getCharacteristics().get
(0));
}
@Override
public void onCharacteristicRead(BluetoothGatt gatt,
BluetoothGattCharacteristic
characteristic, int status) {
}
};
void NotifyApplication(final EnrolleeInfo result) {
// Get a handler that can be used to post to the main thread
......
......@@ -145,15 +145,15 @@ JNIEXPORT void JNICALL JNIProvisionEnrollee(JNIEnv *env, jobject thisObj,
OCConnectivityType connecitivityType;
EnrolleeNWProvInfo_t netInfo =
{ 0};
strncpy(netInfo.netAddressInfo.WIFI.ipAddress, ipAddress, IPV4_ADDR_SIZE);
strncpy(netInfo.netAddressInfo.WIFI.ssid, netSSID, NET_WIFI_SSID_SIZE);
strncpy(netInfo.netAddressInfo.WIFI.pwd, netPWD, NET_WIFI_PWD_SIZE);
strncpy(netInfo.netAddressInfo.WIFI.ipAddress, ipAddress, IPV4_ADDR_SIZE-1);
strncpy(netInfo.netAddressInfo.WIFI.ssid, netSSID, NET_WIFI_SSID_SIZE-1);
strncpy(netInfo.netAddressInfo.WIFI.pwd, netPWD, NET_WIFI_PWD_SIZE-1);
netInfo.connType = (OCConnectivityType)jConnectivityType;
if(netInfo.connType==CT_ADAPTER_GATT_BTLE)
{
strncpy(netInfo.netAddressInfo.LE.leMacAddress,ipAddress,NET_MACADDR_SIZE);
strncpy(netInfo.netAddressInfo.LE.leMacAddress,ipAddress,NET_MACADDR_SIZE-1);
LOGI("MAC set=%s",netInfo.netAddressInfo.LE.leMacAddress);
}
......@@ -169,7 +169,7 @@ JNIEXPORT void JNICALL JNIStopEnrolleeProvisioning(JNIEnv *env, jobject thisObj,
{
LOGI("JNI Stop Easy Setup: Entering");
OCConnectivityType connecitivityType;
OCConnectivityType connecitivityType=OCConnectivityType::CT_DEFAULT;
if(jConnectivityType == 0)
{
......
......@@ -233,6 +233,7 @@ JNIEnv *EasySetupJVM::getEnv() {
return env;
case JNI_EVERSION:
LOGE("JNI version not supported");
return NULL;
default:
LOGE("Failed to get the environment");
return NULL;
......
......@@ -278,7 +278,7 @@ OCStackApplicationResult GetProvisioningStatusResponse(void* ctx, OCDoHandle han
OIC_LOG_V(DEBUG, TAG, "resUri = %s", input->uri);
strncpy(resURI, input->uri, sizeof(resURI));
strncpy(resURI, input->uri, sizeof(resURI)-1);
snprintf(query, sizeof(query), UNICAST_PROV_STATUS_QUERY, clientResponse->addr->addr, IP_PORT,
resURI);
......@@ -592,7 +592,7 @@ bool ValidateEasySetupParams(const EnrolleeNWProvInfo_t *netInfo,
OCProvisioningStatusCB provisioningStatusCallback)
{
if (netInfo == NULL || netInfo->netAddressInfo.WIFI.ipAddress == NULL)
if (netInfo == NULL || strlen(netInfo->netAddressInfo.WIFI.ipAddress) == 0)
{
OIC_LOG(ERROR, TAG, "Request URI is NULL");
return false;
......@@ -642,6 +642,7 @@ bool ResetProgress()
cbData = NULL;
ca_mutex_unlock(g_provisioningMutex);
return true;
}
ProvisioningInfo* CreateCallBackObject()
......
......@@ -274,7 +274,7 @@ OCStackApplicationResult GetProvisioningStatusResponse(void* ctx, OCDoHandle han
OIC_LOG_V(DEBUG, TAG, "resUri = %s", input->uri);
strncpy(resURI, input->uri, sizeof(resURI));
strncpy(resURI, input->uri, sizeof(resURI))-1;
snprintf(query, sizeof(query), UNICAST_PROVISIONING_QUERY_BLE, clientResponse->addr->addr);
......@@ -470,15 +470,22 @@ OCStackApplicationResult SubscribeProvPresenceCallback(void* ctx, OCDoHandle han
OCStackApplicationResult response = OC_STACK_DELETE_TRANSACTION;
if (clientResponse->result != OC_STACK_OK)
if (clientResponse == NULL)
{
OIC_LOG(ERROR, TAG, "OCStack stop error");
// clientResponse is invalid
OIC_LOG(ERROR, TAG, PCF("Client Response is NULL!"));
return response;
}
if (clientResponse)
else
{
OIC_LOG(INFO, TAG, PCF("Client Response exists"));
if (clientResponse->result != OC_STACK_OK)
{
OIC_LOG(ERROR, TAG, "OCStack stop error");