fix code conflicts

revert-dabc3590
hasuniea 9 years ago
commit b30aadc438

@ -9,7 +9,14 @@ android {
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
repositories {
maven {
url "https://dl.bintray.com/alt236/maven"
}
}
buildTypes {
release {
minifyEnabled false
@ -28,13 +35,22 @@ android {
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2'
@ -42,5 +58,8 @@ dependencies {
compile 'commons-codec:commons-codec:1.4'
compile 'com.netflix.feign:feign-jaxrs:8.16.0'
compile 'com.netflix.feign:feign-jackson:8.16.0'
compile 'org.altbeacon:android-beacon-library:2.8.1'
compile 'uk.co.alt236:easycursor-android:1.0.0'
compile 'uk.co.alt236:bluetooth-le-library-android:1.0.0'
}

@ -13,6 +13,10 @@
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-sdk android:minSdkVersion="19" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="@mipmap/wso2logo"
@ -68,6 +72,18 @@
android:label="Speech Recongnizer"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<activity
android:name="org.wso2.carbon.iot.android.sense.beacon.MonitoringActivity"
android:label="Beacon Monitor"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<activity
android:name="org.wso2.carbon.iot.android.sense.bmonitor.BeaconMonitoringActivity"
android:label="Beacon Monitor"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
</application>
</manifest>

@ -0,0 +1,131 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.android.sense.beacon;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import agent.sense.android.iot.carbon.wso2.org.wso2_senseagent.R;
import org.altbeacon.beacon.BeaconConsumer;
import org.altbeacon.beacon.BeaconManager;
import org.altbeacon.beacon.MonitorNotifier;
import org.altbeacon.beacon.Region;
public class BeaconDetactorService extends Service implements BeaconConsumer {
private BeaconManager iBeaconManager = BeaconManager.getInstanceForApplication(this);
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
new Thread(){
@Override
public void run() {
iBeaconManager.bind(BeaconDetactorService.this);
}
}.start();
return START_STICKY;
}
@Override
public void onCreate() {
super.onCreate();
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
@Override
public void run() {
//stopSelf();
}
};
handler.postDelayed(runnable, 10000);
}
@Override
public void onDestroy() {
iBeaconManager.unbind(this);
super.onDestroy();
}
@Override
public void onBeaconServiceConnect() {
iBeaconManager.setMonitorNotifier(new MonitorNotifier() {
@Override
public void didEnterRegion(Region region) {
Log.e("BeaconDetactorService", "didEnterRegion");
generateNotification(BeaconDetactorService.this, region.getUniqueId()
+ ": just saw this iBeacon for the first time");
}
@Override
public void didExitRegion(Region region) {
Log.e("BeaconDetactorService", "didExitRegion");
generateNotification(BeaconDetactorService.this, region.getUniqueId() + ": is no longer visible");
}
@Override
public void didDetermineStateForRegion(int state, Region region) {
Log.e("BeaconDetactorService", "didDetermineStateForRegion:" + state);
}
});
try {
iBeaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));
} catch (RemoteException e) {
e.printStackTrace();
}
}
/**
* Issues a notification to inform the user that server has sent a message.
*/
private static void generateNotification(Context context, String message) {
Intent launchIntent = new Intent(context, MonitoringActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(
0,
new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.beacon).setTicker(message)
.setContentTitle(context.getString(R.string.app_name)).setContentText(message)
.setContentIntent(PendingIntent.getActivity(context, 0, launchIntent, 0)).setAutoCancel(true)
.build());
}
}

@ -0,0 +1,80 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.android.sense.beacon;
import java.util.Date;
public class BeaconScanedData {
private int beaconMajor;// Major
private int beaconMinor;//Minor
private String beaconProximity;// Proximity
private int beaconUuid;// Uuid
private long timestamp;// Timestamp
BeaconScanedData(int beaconMajor, int beaconMinor,String beaconProximity,int beaconUuid) {
this.beaconMajor = beaconMajor;
this.beaconMinor = beaconMinor;
this.beaconProximity = beaconProximity;
this.beaconUuid = beaconUuid;
timestamp = new Date().getTime();
}
public int getBeaconMajor() {
return beaconMajor;
}
public void setBeaconMajor(int beaconMajor) {
this.beaconMajor = beaconMajor;
}
public int getBeaconMinor() {
return beaconMinor;
}
public void setBeaconMinor(int beaconMinor) {
this.beaconMinor = beaconMinor;
}
public String getBeaconProximity() {
return beaconProximity;
}
public void setBeaconProximity(String beaconProximity) {
this.beaconProximity = beaconProximity;
}
public int getBeaconUuid() {
return beaconUuid;
}
public void setBeaconUuid(int beaconUuid) {
this.beaconUuid = beaconUuid;
}
public long getTimeStamp() {
return timestamp;
}
public void setTimeStamp(long timeStamp) {
timestamp = timeStamp;
}
}

@ -0,0 +1,71 @@
package org.wso2.carbon.iot.android.sense.beacon;
import java.util.Calendar;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import org.altbeacon.beacon.BeaconConsumer;
import org.altbeacon.beacon.BeaconManager;
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.
*/
public class BeaconServiceUtility {
private Context context;
private PendingIntent pintent;
private AlarmManager alarm;
private Intent iService;
public BeaconServiceUtility(Context context) {
super();
this.context = context;
iService = new Intent(context, BeaconDetactorService.class);
alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
pintent = PendingIntent.getService(context, 0, iService, 0);
}
public void onStart(BeaconManager iBeaconManager, BeaconConsumer consumer) {
stopBackgroundScan();
iBeaconManager.bind(consumer);
}
public void onStop(BeaconManager iBeaconManager, BeaconConsumer consumer) {
iBeaconManager.unbind(consumer);
startBackgroundScan();
}
private void stopBackgroundScan() {
alarm.cancel(pintent);
context.stopService(iService);
}
private void startBackgroundScan() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, 2);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 360000, pintent); // 6*60 * 1000
context.startService(iService);
}
}

@ -0,0 +1,252 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) 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.wso2.carbon.iot.android.sense.beacon;
import android.Manifest;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.RemoteException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.view.LayoutInflater;
import android.widget.BaseAdapter;
import org.altbeacon.beacon.BeaconConsumer;
import org.altbeacon.beacon.BeaconManager;
import org.altbeacon.beacon.Beacon;
import org.altbeacon.beacon.RangeNotifier;
import android.widget.ListView;
import android.widget.TextView;
import org.altbeacon.beacon.BeaconParser;
import org.altbeacon.beacon.MonitorNotifier;
import org.altbeacon.beacon.Region;
import org.wso2.carbon.iot.android.sense.beacon.BeaconScanedData;
import org.wso2.carbon.iot.android.sense.util.SenseDataHolder;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.logging.Handler;
import agent.sense.android.iot.carbon.wso2.org.wso2_senseagent.R;
public class MonitoringActivity extends Activity implements BeaconConsumer {
protected static final String TAG = MonitoringActivity.class.getName();
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 1;
private ListView list = null;
private BeaconAdapter adapter;
private ArrayList<Beacon> arrayL = new ArrayList<>();
private LayoutInflater inflater;
private BeaconServiceUtility beaconUtill = null;
private BeaconManager iBeaconManager = BeaconManager.getInstanceForApplication(this);
BeaconScanedData beaconData;
@Override
public void onBeaconServiceConnect() {
iBeaconManager.setBackgroundMode(true);
iBeaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> iBeacons, Region region) {
for (Beacon beacon: iBeacons) {
Log.i(TAG, "This beacon has identifiers:"+beacon.getId1()+", "+beacon.getId2()+", "+beacon.getId3());
}
arrayL.clear();
arrayL.addAll(iBeacons);
//adapter.notifyDataSetChanged();
}
});
iBeaconManager.setMonitorNotifier(new MonitorNotifier() {
@Override
public void didEnterRegion(Region region) {
Log.e("BeaconDetactorService", "didEnterRegion");
// logStatus("I just saw an iBeacon for the first time!");
}
@Override
public void didExitRegion(Region region) {
Log.e("BeaconDetactorService", "didExitRegion");
// logStatus("I no longer see an iBeacon");
}
@Override
public void didDetermineStateForRegion(int state, Region region) {
Log.e("BeaconDetactorService", "didDetermineStateForRegion");
// logStatus("I have just switched from seeing/not seeing iBeacons: " + state);
}
});
try {
iBeaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
} catch (RemoteException e) {
e.printStackTrace();
}
try {
iBeaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));
} catch (RemoteException e) {
e.printStackTrace();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_monitor);
beaconUtill = new BeaconServiceUtility(this);
list = (ListView) findViewById(R.id.list);
adapter = new BeaconAdapter();
list.setAdapter(adapter);
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//iBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
iBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
iBeaconManager.bind(this);
iBeaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
for(Beacon beacon : beacons) {
Log.d(TAG, "UUID:" + beacon.getId1() + ", major:" + beacon.getId2() + ", minor:" + beacon.getId3() + ", Distance:" + beacon.getDistance() + ",RSSI" + beacon.getRssi() + ", TxPower" + beacon.getTxPower());
}
arrayL.clear();
arrayL.addAll(beacons);
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
protected void onStart() {
super.onStart();
beaconUtill.onStart(iBeaconManager, this);
beaconUtill = new BeaconServiceUtility(this);
}
@Override
protected void onStop() {
beaconUtill.onStop(iBeaconManager, this);
super.onStop();
}
private class BeaconAdapter extends BaseAdapter {
@Override
public int getCount() {
if (arrayL != null && arrayL.size() > 0)
return arrayL.size();
else
return 0;
}
@Override
public Beacon getItem(int arg0) {
return arrayL.get(arg0);
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
try {
ViewHolder holder;
if (convertView != null) {
holder = (ViewHolder) convertView.getTag();
} else {
holder = new ViewHolder(convertView = inflater.inflate(R.layout.tupple_monitoring, null));
}
holder.beacon_uuid.setText("UUID: " + arrayL.get(position).getId1().toString().toUpperCase());
holder.beacon_major.setText("Major: " + arrayL.get(position).getId2());
holder.beacon_minor.setText(" Minor: " + arrayL.get(position).getId3());
double proximity = arrayL.get(position).getDistance();
holder.beacon_proximity.setText("Proximity: " + (new BigDecimal(proximity).setScale(5, BigDecimal.ROUND_HALF_UP).doubleValue()));
holder.beacon_rssi.setText(" Rssi: " + arrayL.get(position).getRssi());
holder.beacon_txpower.setText(" TxPower: " + arrayL.get(position).getTxPower());
holder.beacon_range.setText("" + arrayL.get(position).getDistance());
beaconData = new BeaconScanedData(arrayL.get(position).getId2().toInt(), arrayL.get(position).getId3().toInt(),holder.beacon_uuid.toString(),arrayL.get(position).getRssi());
SenseDataHolder.getBeaconScanedDataHolder().add(beaconData);
} catch (Exception e) {
e.printStackTrace();
}
return convertView;
}
private class ViewHolder {
private TextView beacon_uuid;
private TextView beacon_major;
private TextView beacon_minor;
private TextView beacon_proximity;
private TextView beacon_rssi;
private TextView beacon_txpower;
private TextView beacon_range;
public ViewHolder(View view) {
beacon_uuid = (TextView) view.findViewById(R.id.BEACON_uuid);
beacon_major = (TextView) view.findViewById(R.id.BEACON_major);
beacon_minor = (TextView) view.findViewById(R.id.BEACON_minor);
beacon_proximity = (TextView) view.findViewById(R.id.BEACON_proximity);
beacon_rssi = (TextView) view.findViewById(R.id.BEACON_rssi);
beacon_txpower = (TextView) view.findViewById(R.id.BEACON_txpower);
beacon_range = (TextView) view.findViewById(R.id.BEACON_range);
view.setTag(this);
}
}
}
}

@ -0,0 +1,121 @@
/*
*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) 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.wso2.carbon.iot.android.sense.bmonitor;
import android.annotation.TargetApi;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import java.util.HashMap;
import java.util.Map;
import agent.sense.android.iot.carbon.wso2.org.wso2_senseagent.R;
import uk.co.alt236.bluetoothlelib.device.BluetoothLeDevice;
import uk.co.alt236.easycursor.objectcursor.EasyObjectCursor;
public class BeaconMonitoringActivity extends AppCompatActivity {
private BluetoothLeScanner mScanner;
private BluetoothUtils mBluetoothUtils;
private LeDeviceListAdapter mLeDeviceListAdapter;
private BluetoothLeDeviceStore mDeviceStore;
protected ListView mList;
public static final int MINIMUM_DISTANCE = -70;
public static Map itemMap;
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_beacon_monitoring);
itemMap = new HashMap<String, String>();
itemMap.put("DC:5F:BD:68:88:D5", "Noodles");
itemMap.put("EF:0F:50:D5:BA:A1", "Vegetables");
itemMap.put("FA:F2:CF:84:C2:F7", "Oil");
mList = (ListView) this.findViewById(android.R.id.list);
mDeviceStore = new BluetoothLeDeviceStore();
mBluetoothUtils = new BluetoothUtils(this);
mScanner = new BluetoothLeScanner(mLeScanCallback, mBluetoothUtils);
startScan();
}
private final BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, final int rssi, final byte[] scanRecord) {
final BluetoothLeDevice deviceLe = new BluetoothLeDevice(device, rssi, scanRecord, System.currentTimeMillis());
if(deviceLe!= null && deviceLe.getName()!= null && !deviceLe.getName().equals("Unknown Device")){
mDeviceStore.addDevice(deviceLe);
if(deviceLe.getRssi() > MINIMUM_DISTANCE){
Object[] objects = new Object[4];
objects[0] = deviceLe.getName();
objects[1] = deviceLe.getAddress();
objects[2] = deviceLe.getRssi();
objects[3] = itemMap.get(device.getAddress());
new SendToSiddi().execute(objects);
}
final EasyObjectCursor<BluetoothLeDevice> c = mDeviceStore.getDeviceCursor();
runOnUiThread(new Runnable() {
@Override
public void run() {
mLeDeviceListAdapter.swapCursor(c);
}
});
}
}
};
private void startScan() {
mLeDeviceListAdapter = new LeDeviceListAdapter(this, mDeviceStore.getDeviceCursor());
mList.setAdapter(mLeDeviceListAdapter);
final boolean mIsBluetoothOn = mBluetoothUtils.isBluetoothOn();
final boolean mIsBluetoothLePresent = mBluetoothUtils.isBluetoothLeSupported();
mBluetoothUtils.askUserToEnableBluetoothIfNeeded();
if (mIsBluetoothOn && mIsBluetoothLePresent) {
mScanner.scanLeDevice(-1, true);
invalidateOptionsMenu();
}
}
public class SendToSiddi extends AsyncTask<Object, Object, Void>{
@Override
protected Void doInBackground(Object... objects) {
return null;
}
}
}

@ -0,0 +1,193 @@
/*
*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) 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.wso2.carbon.iot.android.sense.bmonitor;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import uk.co.alt236.bluetoothlelib.device.BluetoothLeDevice;
import uk.co.alt236.bluetoothlelib.device.beacon.BeaconType;
import uk.co.alt236.bluetoothlelib.device.beacon.BeaconUtils;
import uk.co.alt236.bluetoothlelib.device.beacon.ibeacon.IBeaconDevice;
import uk.co.alt236.bluetoothlelib.util.ByteUtils;
import uk.co.alt236.easycursor.objectcursor.EasyObjectCursor;
public class BluetoothLeDeviceStore {
private final Map<String, BluetoothLeDevice> mDeviceMap;
public BluetoothLeDeviceStore() {
mDeviceMap = new HashMap<>();
}
public void addDevice(final BluetoothLeDevice device) {
if (mDeviceMap.containsKey(device.getAddress())) {
mDeviceMap.get(device.getAddress()).updateRssiReading(device.getTimestamp(), device.getRssi());
} else {
mDeviceMap.put(device.getAddress(), device);
}
}
public void clear() {
mDeviceMap.clear();
}
public EasyObjectCursor<BluetoothLeDevice> getDeviceCursor() {
return new EasyObjectCursor<>(
BluetoothLeDevice.class,
getDeviceList(),
"address");
}
public List<BluetoothLeDevice> getDeviceList() {
final List<BluetoothLeDevice> methodResult = new ArrayList<>(mDeviceMap.values());
Collections.sort(methodResult, new Comparator<BluetoothLeDevice>() {
@Override
public int compare(final BluetoothLeDevice arg0, final BluetoothLeDevice arg1) {
return arg0.getAddress().compareToIgnoreCase(arg1.getAddress());
}
});
return methodResult;
}
private String getListAsCsv() {
final List<BluetoothLeDevice> list = getDeviceList();
final StringBuilder sb = new StringBuilder();
sb.append(CsvWriterHelper.addStuff("mac"));
sb.append(CsvWriterHelper.addStuff("name"));
sb.append(CsvWriterHelper.addStuff("firstTimestamp"));
sb.append(CsvWriterHelper.addStuff("firstRssi"));
sb.append(CsvWriterHelper.addStuff("currentTimestamp"));
sb.append(CsvWriterHelper.addStuff("currentRssi"));
sb.append(CsvWriterHelper.addStuff("adRecord"));
sb.append(CsvWriterHelper.addStuff("iBeacon"));
sb.append(CsvWriterHelper.addStuff("uuid"));
sb.append(CsvWriterHelper.addStuff("major"));
sb.append(CsvWriterHelper.addStuff("minor"));
sb.append(CsvWriterHelper.addStuff("txPower"));
sb.append(CsvWriterHelper.addStuff("distance"));
sb.append(CsvWriterHelper.addStuff("accuracy"));
sb.append('\n');
for (final BluetoothLeDevice device : list) {
sb.append(CsvWriterHelper.addStuff(device.getAddress()));
sb.append(CsvWriterHelper.addStuff(device.getName()));
sb.append(CsvWriterHelper.addStuff(TimeFormatter.getIsoDateTime(device.getFirstTimestamp())));
sb.append(CsvWriterHelper.addStuff(device.getFirstRssi()));
sb.append(CsvWriterHelper.addStuff(TimeFormatter.getIsoDateTime(device.getTimestamp())));
sb.append(CsvWriterHelper.addStuff(device.getRssi()));
sb.append(CsvWriterHelper.addStuff(ByteUtils.byteArrayToHexString(device.getScanRecord())));
final boolean isIBeacon = BeaconUtils.getBeaconType(device) == BeaconType.IBEACON;
final String uuid;
final String minor;
final String major;
final String txPower;
final String distance;
final String accuracy;
if (isIBeacon) {
final IBeaconDevice beacon = new IBeaconDevice(device);
uuid = String.valueOf(beacon.getUUID());
minor = String.valueOf(beacon.getMinor());
major = String.valueOf(beacon.getMajor());
txPower = String.valueOf(beacon.getCalibratedTxPower());
distance = beacon.getDistanceDescriptor().toString().toLowerCase(Locale.US);
accuracy = String.valueOf(beacon.getAccuracy());
} else {
uuid = "";
minor = "";
major = "";
txPower = "";
distance = "";
accuracy = "";
}
sb.append(CsvWriterHelper.addStuff(isIBeacon));
sb.append(CsvWriterHelper.addStuff(uuid));
sb.append(CsvWriterHelper.addStuff(minor));
sb.append(CsvWriterHelper.addStuff(major));
sb.append(CsvWriterHelper.addStuff(txPower));
sb.append(CsvWriterHelper.addStuff(distance));
sb.append(CsvWriterHelper.addStuff(accuracy));
sb.append('\n');
}
return sb.toString();
}
public void shareDataAsEmail(final Context context) {
final long timeInMillis = System.currentTimeMillis();
final String to = null;
final String subject = "";
final String message = "";
final Intent i = new Intent(Intent.ACTION_SEND);
i.setType("plain/text");
try {
final File outputDir = context.getCacheDir();
final File outputFile = File.createTempFile("bluetooth_le_" + timeInMillis, ".csv", outputDir);
outputFile.setReadable(true, false);
generateFile(outputFile, getListAsCsv());
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(outputFile));
i.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
i.putExtra(Intent.EXTRA_SUBJECT, subject);
i.putExtra(Intent.EXTRA_TEXT, message);
context.startActivity(Intent.createChooser(i, "Email Subject"));
} catch (final IOException e) {
e.printStackTrace();
}
}
private static FileWriter generateFile(final File file, final String contents) {
FileWriter writer = null;
try {
writer = new FileWriter(file);
writer.append(contents);
writer.flush();
} catch (final IOException e) {
e.printStackTrace();
} finally {
try {
writer.close();
} catch (final IOException e) {
e.printStackTrace();
}
}
return writer;
}
}

@ -0,0 +1,65 @@
/*
*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) 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.wso2.carbon.iot.android.sense.bmonitor;
import android.bluetooth.BluetoothAdapter;
import android.os.Handler;
import android.util.Log;
public class BluetoothLeScanner {
private final Handler mHandler;
private final BluetoothAdapter.LeScanCallback mLeScanCallback;
private final BluetoothUtils mBluetoothUtils;
private boolean mScanning;
public BluetoothLeScanner(final BluetoothAdapter.LeScanCallback leScanCallback, final BluetoothUtils bluetoothUtils) {
mHandler = new Handler();
mLeScanCallback = leScanCallback;
mBluetoothUtils = bluetoothUtils;
}
public boolean isScanning() {
return mScanning;
}
public void scanLeDevice(final int duration, final boolean enable) {
if (enable) {
if (mScanning) {
return;
}
Log.d("TAG", "~ Starting Scan");
// Stops scanning after a pre-defined scan period.
if (duration > 0) {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
Log.d("TAG", "~ Stopping Scan (timeout)");
mScanning = false;
mBluetoothUtils.getBluetoothAdapter().stopLeScan(mLeScanCallback);
}
}, duration);
}
mScanning = true;
mBluetoothUtils.getBluetoothAdapter().startLeScan(mLeScanCallback);
} else {
Log.d("TAG", "~ Stopping Scan");
mScanning = false;
mBluetoothUtils.getBluetoothAdapter().stopLeScan(mLeScanCallback);
}
}
}

@ -0,0 +1,60 @@
/*
*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) 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.wso2.carbon.iot.android.sense.bmonitor;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
public final class BluetoothUtils {
public final static int REQUEST_ENABLE_BT = 2001;
private final Activity mActivity;
private final BluetoothAdapter mBluetoothAdapter;
public BluetoothUtils(final Activity activity) {
mActivity = activity;
final BluetoothManager btManager = (BluetoothManager) mActivity.getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = btManager.getAdapter();
}
public void askUserToEnableBluetoothIfNeeded() {
if (isBluetoothLeSupported() && (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled())) {
final Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
mActivity.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
}
public BluetoothAdapter getBluetoothAdapter() {
return mBluetoothAdapter;
}
public boolean isBluetoothLeSupported() {
return mActivity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE);
}
public boolean isBluetoothOn() {
if (mBluetoothAdapter == null) {
return false;
} else {
return mBluetoothAdapter.isEnabled();
}
}
}

@ -0,0 +1,43 @@
/*
*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) 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.wso2.carbon.iot.android.sense.bmonitor;
public class CsvWriterHelper {
private static final String QUOTE = "\"";
public static String addStuff(final Integer text) {
return QUOTE + text + QUOTE + ",";
}
public static String addStuff(final Long text) {
return QUOTE + text + QUOTE + ",";
}
public static String addStuff(final boolean value) {
return QUOTE + value + QUOTE + ",";
}
public static String addStuff(String text) {
if (text == null) {
text = "<blank>";
}
text = text.replace(QUOTE, "'");
return QUOTE + text.trim() + QUOTE + ",";
}
}

@ -0,0 +1,154 @@
/*
*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) 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.wso2.carbon.iot.android.sense.bmonitor;
import android.app.Activity;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.text.DecimalFormat;
import agent.sense.android.iot.carbon.wso2.org.wso2_senseagent.R;
import uk.co.alt236.bluetoothlelib.device.BluetoothLeDevice;
import uk.co.alt236.bluetoothlelib.device.beacon.BeaconType;
import uk.co.alt236.bluetoothlelib.device.beacon.BeaconUtils;
import uk.co.alt236.bluetoothlelib.device.beacon.ibeacon.IBeaconDevice;
import uk.co.alt236.easycursor.objectcursor.EasyObjectCursor;
public class LeDeviceListAdapter extends SimpleCursorAdapter {
private final LayoutInflater mInflator;
private final Activity mActivity;
public static final DecimalFormat DOUBLE_TWO_DIGIT_ACCURACY = new DecimalFormat("#.##");
public static final String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
public LeDeviceListAdapter(final Activity activity, final EasyObjectCursor<BluetoothLeDevice> cursor) {
super(activity, R.layout.list_item_device, cursor, new String[0], new int[0], 0);
mInflator = activity.getLayoutInflater();
mActivity = activity;
}
@SuppressWarnings("unchecked")
@Override
public EasyObjectCursor<BluetoothLeDevice> getCursor() {
return ((EasyObjectCursor<BluetoothLeDevice>) super.getCursor());
}
@Override
public BluetoothLeDevice getItem(final int i) {
return getCursor().getItem(i);
}
@Override
public long getItemId(final int i) {
return i;
}
@Override
public View getView(final int i, View view, final ViewGroup viewGroup) {
final ViewHolder viewHolder;
// General ListView optimization code.
if (view == null) {
view = mInflator.inflate(R.layout.list_item_device, null);
viewHolder = new ViewHolder();
viewHolder.deviceAddress = (TextView) view.findViewById(R.id.device_address);
viewHolder.deviceName = (TextView) view.findViewById(R.id.device_name);
viewHolder.deviceRssi = (TextView) view.findViewById(R.id.device_rssi);
viewHolder.deviceIcon = (ImageView) view.findViewById(R.id.device_icon);
viewHolder.deviceLastUpdated = (TextView) view.findViewById(R.id.device_last_update);
viewHolder.ibeaconMajor = (TextView) view.findViewById(R.id.ibeacon_major);
viewHolder.ibeaconMinor = (TextView) view.findViewById(R.id.ibeacon_minor);
viewHolder.ibeaconDistance = (TextView) view.findViewById(R.id.ibeacon_distance);
viewHolder.ibeaconUUID = (TextView) view.findViewById(R.id.ibeacon_uuid);
viewHolder.ibeaconTxPower = (TextView) view.findViewById(R.id.ibeacon_tx_power);
viewHolder.ibeaconSection = view.findViewById(R.id.ibeacon_section);
viewHolder.ibeaconDistanceDescriptor = (TextView) view.findViewById(R.id.ibeacon_distance_descriptor);
view.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) view.getTag();
}
final BluetoothLeDevice device = getCursor().getItem(i);
final String deviceName = device.getName();
final double rssi = device.getRssi();
if (deviceName != null && deviceName.length() > 0) {
viewHolder.deviceName.setText(deviceName + " (" + BeaconMonitoringActivity.itemMap.get(device.getAddress()) + ")");
} else {
viewHolder.deviceName.setText(R.string.unknown_device);
}
if (BeaconUtils.getBeaconType(device) == BeaconType.IBEACON) {
final IBeaconDevice iBeacon = new IBeaconDevice(device);
final String accuracy = DOUBLE_TWO_DIGIT_ACCURACY.format(iBeacon.getAccuracy());
viewHolder.deviceIcon.setImageResource(R.drawable.beacon);
viewHolder.ibeaconSection.setVisibility(View.VISIBLE);
viewHolder.ibeaconMajor.setText(String.valueOf(iBeacon.getMajor()));
viewHolder.ibeaconMinor.setText(String.valueOf(iBeacon.getMinor()));
viewHolder.ibeaconTxPower.setText(String.valueOf(iBeacon.getCalibratedTxPower()));
viewHolder.ibeaconUUID.setText(iBeacon.getUUID());
viewHolder.ibeaconDistance.setText(
mActivity.getString(R.string.formatter_meters, accuracy));
viewHolder.ibeaconDistanceDescriptor.setText(iBeacon.getDistanceDescriptor().toString());
} else {
if(device.getRssi() > BeaconMonitoringActivity.MINIMUM_DISTANCE){
viewHolder.deviceIcon.setImageResource(R.drawable.beacon_red);
}else{
viewHolder.deviceIcon.setImageResource(R.drawable.beacon);
}
viewHolder.ibeaconSection.setVisibility(View.GONE);
}
final String rssiString =
mActivity.getString(R.string.formatter_db, String.valueOf(rssi));
final String runningAverageRssiString =
mActivity.getString(R.string.formatter_db, String.valueOf(device.getRunningAverageRssi()));
viewHolder.deviceLastUpdated.setText(
android.text.format.DateFormat.format(
TIME_FORMAT, new java.util.Date(device.getTimestamp())));
viewHolder.deviceAddress.setText(device.getAddress());
viewHolder.deviceRssi.setText(rssiString + " / " + runningAverageRssiString);
return view;
}
static class ViewHolder {
TextView deviceName;
TextView deviceAddress;
TextView deviceRssi;
TextView ibeaconUUID;
TextView ibeaconMajor;
TextView ibeaconMinor;
TextView ibeaconTxPower;
TextView ibeaconDistance;
TextView ibeaconDistanceDescriptor;
TextView deviceLastUpdated;
View ibeaconSection;
ImageView deviceIcon;
}
}

@ -0,0 +1,35 @@
/*
*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) 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.wso2.carbon.iot.android.sense.bmonitor;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class TimeFormatter {
private final static String ISO_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS zzz";
private final static SimpleDateFormat ISO_FORMATTER = new UtcDateFormatter(ISO_FORMAT, Locale.US);
public static String getIsoDateTime(final Date date) {
return ISO_FORMATTER.format(date);
}
public static String getIsoDateTime(final long millis) {
return getIsoDateTime(new Date(millis));
}
}

@ -0,0 +1,74 @@
/**
* ****************************************************************************
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
* <p/>
* GenieConnect Ltd. ("COMPANY") CONFIDENTIAL
* Unpublished Copyright (c) 2010-2013 GenieConnect Ltd., All Rights Reserved.
* <p/>
* NOTICE:
* All information contained herein is, and remains the property of COMPANY.
* The intellectual and technical concepts contained herein are proprietary to
* COMPANY and may be covered by U.S. and Foreign Patents, patents in process, and
* are protected by trade secret or copyright law. Dissemination of this
* information or reproduction of this material is strictly forbidden unless prior
* written permission is obtained from COMPANY. Access to the source code
* contained herein is hereby forbidden to anyone except current COMPANY employees,
* managers or contractors who have executed Confidentiality and Non-disclosure
* agreements explicitly covering such access.
* <p/>
* The copyright notice above does not evidence any actual or intended publication
* or disclosure of this source code, which includes information that is
* confidential and/or proprietary, and is a trade secret, of COMPANY.
* <p/>
* ANY REPRODUCTION, MODIFICATION, DISTRIBUTION, PUBLIC PERFORMANCE, OR PUBLIC
* DISPLAY OF OR THROUGH USE OF THIS SOURCE CODE WITHOUT THE EXPRESS WRITTEN
* CONSENT OF COMPANY IS STRICTLY PROHIBITED, AND IN VIOLATION OF APPLICABLE LAWS
* AND INTERNATIONAL TREATIES. THE RECEIPT OR POSSESSION OF THIS SOURCE CODE
* AND/OR RELATED INFORMATION DOES NOT CONVEY OR IMPLY ANY RIGHTS TO REPRODUCE,
* DISCLOSE OR DISTRIBUTE ITS CONTENTS, OR TO MANUFACTURE, USE, OR SELL ANYTHING
* THAT IT MAY DESCRIBE, IN WHOLE OR IN PART.
* ****************************************************************************
*/
package org.wso2.carbon.iot.android.sense.bmonitor;
import android.annotation.SuppressLint;
import java.text.DateFormatSymbols;
import java.util.Locale;
import java.util.TimeZone;
public class UtcDateFormatter extends java.text.SimpleDateFormat {
private static final long serialVersionUID = 1L;
private static final String TIME_ZONE_STRING = "UTC";
private static final TimeZone TIME_ZONE_UTC = TimeZone.getTimeZone(TIME_ZONE_STRING);
@SuppressLint("SimpleDateFormat")
public UtcDateFormatter(final String template) {
super(template);
super.setTimeZone(TIME_ZONE_UTC);
}
@SuppressLint("SimpleDateFormat")
public UtcDateFormatter(final String template, final DateFormatSymbols symbols) {
super(template, symbols);
super.setTimeZone(TIME_ZONE_UTC);
}
public UtcDateFormatter(final String template, final Locale locale) {
super(template, locale);
super.setTimeZone(TIME_ZONE_UTC);
}
/*
* This function will throw an UnsupportedOperationException.
* You are not be able to change the TimeZone of this object
*
* (non-Javadoc)
* @see java.text.DateFormat#setTimeZone(java.util.TimeZone)
*/
@Override
public void setTimeZone(final TimeZone timezone) {
throw new UnsupportedOperationException("This SimpleDateFormat can only be in " + TIME_ZONE_STRING);
}
}

@ -24,6 +24,7 @@ import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.wso2.carbon.iot.android.sense.beacon.BeaconScanedData;
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.AndroidSenseMQTTHandler;
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.MQTTTransportHandler;
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.TransportHandlerException;
@ -140,8 +141,24 @@ public class DataPublisherService extends Service {
for (SpeedData speedData : speedDataMap) {
Event event = new Event();
event.setTimestamp(speedData.getTimeStamp());
event.setSpeed(speedData.getSpeed());
event.setTurns(speedData.getTurns());
event.setSpeed(speedData.getSpeed());
events.add(event);
}
}
SenseDataHolder.resetSpeedDataHolder();
//retrieve speed data.
List<BeaconScanedData> beaconDataMap = SenseDataHolder.getBeaconScanedDataHolder();
if (!speedDataMap.isEmpty()) {
for (BeaconScanedData beaconData : beaconDataMap) {
Event event = new Event();
event.setBeaconMajor(beaconData.getBeaconMajor());
event.setBeaconMinor(beaconData.getBeaconMinor());
event.setBeaconProximity(beaconData.getBeaconProximity());
event.setBeaconUuid(beaconData.getBeaconUuid());
events.add(event);
}
}

@ -28,6 +28,12 @@ public class Event {
private static float speed;
private String turn;
public static final float SPEED_LIMIT = 60;
private int beaconMajor;
private int beaconMinor;
private int beaconUuid;
private String beaconProximity;
private int getBattery() {
return battery;
@ -174,9 +180,7 @@ public class Event {
}
public float getSpeed() {
this.type = "speed";
return speed;
}
@ -194,6 +198,46 @@ public class Event {
return turn;
}
public void setBeaconMajor(int beaconMajor) {
this.type = "beaconMajor";
this.beaconMajor = beaconMajor;
}
public int getBeaconMajor() {
this.type = "beaconMajor";
return beaconMajor;
}
public void setBeaconMinor(int beaconMinor) {
this.type = "beaconMinor";
this.beaconMinor = beaconMinor;
}
public int getBeaconMinor() {
this.type = "beaconMinor";
return beaconMinor;
}
public void setBeaconUuid(int beaconUuid) {
this.type = "beaconUuid";
this.beaconUuid = beaconUuid;
}
public int getBeaconUuid() {
this.type = "beaconUuid";
return beaconUuid;
}
public void setBeaconProximity(String beaconProximity) {
this.type = "beaconProximity";
this.beaconProximity = beaconProximity;
}
public String getBeaconProximity() {
this.type = "beaconProximity";
return beaconProximity;
}
public JSONObject getEvent() throws JSONException {
JSONObject jsonEvent = new JSONObject();
JSONObject jsonMetaData = new JSONObject();
@ -209,18 +253,23 @@ public class Event {
double gpsEvents[] = getGps();
jsonPayloadData.put("gps_lat", gpsEvents[0]);
jsonPayloadData.put("gps_long", gpsEvents[1]);
//acceleromter
//accelerometer
float events[] = getAccelerometer();
jsonPayloadData.put("accelerometer_x", events[0]);
jsonPayloadData.put("accelerometer_y", events[1]);
jsonPayloadData.put("accelerometer_z", events[2]);
//speed
//if (getSpeed()>SPEED_LIMIT) {
jsonPayloadData.put("speed_limit", getSpeed());
//}
//Beacon Data
jsonPayloadData.put("beacon_major", getBeaconMajor());
jsonPayloadData.put("beacon_minor", getBeaconMinor());
jsonPayloadData.put("beacon_proximity", getBeaconProximity());
jsonPayloadData.put("beacon_uuid", getBeaconUuid());
//turn
jsonPayloadData.put("turn_way", getTurns());
//magnetic

@ -40,7 +40,6 @@ public class LocationDataReader extends DataReader implements LocationListener {
static final Double EARTH_RADIUS = 6371.00;
// flag for GPS status
private boolean isGPSEnabled = false;
@ -176,8 +175,6 @@ public class LocationDataReader extends DataReader implements LocationListener {
time=c.get(Calendar.HOUR);
locationManager.removeUpdates(LocationDataReader.this);
//String Speed = "Device Speed: " +location.getSpeed();
latitude=location.getLongitude();
@ -185,7 +182,6 @@ public class LocationDataReader extends DataReader implements LocationListener {
double distance =CalculationByDistance(latitude, longitude, lat_old, lon_old)/1000;
speed = (float)distance/(float)time;
Toast.makeText(mContext, longitude+"\n"+latitude+"\nDistance is: "
+distance+"\nSpeed is: "+speed , Toast.LENGTH_SHORT).show();
@ -219,7 +215,6 @@ public class LocationDataReader extends DataReader implements LocationListener {
}
@Override
public void run() {
Log.d(TAG, "running -Location");

@ -18,6 +18,7 @@ import android.content.Context;
import org.wso2.carbon.iot.android.sense.event.streams.Location.LocationDataReader;
import org.wso2.carbon.iot.android.sense.event.streams.Sensor.SensorDataReader;
import org.wso2.carbon.iot.android.sense.event.streams.Speed.SpeedDataReader;
import org.wso2.carbon.iot.android.sense.beacon.MonitoringActivity;
/**
* This class triggered by service to collect the sensor data.
@ -39,6 +40,7 @@ public class SenseDataCollector {
case SPEED:
dr = new SpeedDataReader(ctx);
break;
}
if (dr != null) {
Thread DataCollector = new Thread(dr);

@ -35,8 +35,10 @@ import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import android.app.AlertDialog;
import android.content.DialogInterface;
import org.wso2.carbon.iot.android.sense.RegisterActivity;
import org.wso2.carbon.iot.android.sense.bmonitor.BeaconMonitoringActivity;
import org.wso2.carbon.iot.android.sense.data.publisher.DataPublisherReceiver;
import org.wso2.carbon.iot.android.sense.data.publisher.DataPublisherService;
import org.wso2.carbon.iot.android.sense.event.SenseScheduleReceiver;
@ -48,11 +50,13 @@ import org.wso2.carbon.iot.android.sense.realtimeviewer.sensorlisting.SupportedS
import org.wso2.carbon.iot.android.sense.realtimeviewer.view.adaptor.SensorViewAdaptor;
import org.wso2.carbon.iot.android.sense.realtimeviewer.view.sensor.selector.SelectSensorDialog;
import org.wso2.carbon.iot.android.sense.speech.detector.WordRecognitionActivity;
import org.wso2.carbon.iot.android.sense.util.LocalRegistry;
import org.wso2.carbon.iot.android.sense.beacon.MonitoringActivity;
import org.wso2.carbon.iot.android.sense.util.LocalRegistry;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import org.altbeacon.beacon.BeaconManager;
import agent.sense.android.iot.carbon.wso2.org.wso2_senseagent.R;
@ -73,6 +77,8 @@ public class ActivitySelectSensor extends AppCompatActivity
private RealTimeSensorReader sensorReader = null;
private RealTimeSensorChangeReceiver realTimeSensorChangeReceiver = new RealTimeSensorChangeReceiver();
private SupportedSensors supportedSensors = SupportedSensors.getInstance();
protected static final String TAG = ActivitySelectSensor.class.getName();
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -85,6 +91,7 @@ public class ActivitySelectSensor extends AppCompatActivity
sessionIdText.setCursorVisible(false);
listView = (ListView) findViewById(R.id.senseListContainer);
verifyBluetooth();
registerReceiver(realTimeSensorChangeReceiver, new IntentFilter("sensorDataMap"));
@ -136,6 +143,18 @@ public class ActivitySelectSensor extends AppCompatActivity
}
});
FloatingActionButton fbtnBeaconMonitor = (FloatingActionButton) findViewById(R.id.beacon);
fbtnBeaconMonitor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), BeaconMonitoringActivity.class);
startActivity(intent);
}
});
sharedPreferences = getSharedPreferences(SupportedSensors.SELECTED_SENSORS, 0);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
@ -293,4 +312,44 @@ public class ActivitySelectSensor extends AppCompatActivity
public void unregisterReceivers() {
unregisterReceiver(realTimeSensorChangeReceiver);
}
private void verifyBluetooth() {
try {
if (!BeaconManager.getInstanceForApplication(this).checkAvailability()) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Bluetooth not enabled");
builder.setMessage("Please enable bluetooth in settings and restart this application.");
builder.setPositiveButton(android.R.string.ok, null);
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
finish();
System.exit(0);
}
});
builder.show();
}
} catch (RuntimeException e) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Bluetooth LE not available");
builder.setMessage("Sorry, this device does not support Bluetooth LE.");
builder.setPositiveButton(android.R.string.ok, null);
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
finish();
System.exit(0);
}
});
builder.show();
}
}
}

@ -51,7 +51,7 @@ public class SenseClient {
String responseStatus = response.get("status");
RegisterInfo registerInfo = new RegisterInfo();
if (responseStatus.trim().contains(SenseConstants.Request.REQUEST_SUCCESSFUL)) {
registerInfo.setMsg("Login Succesful");
registerInfo.setMsg("Login Successful");
registerInfo.setIsRegistered(true);
return registerInfo;
} else {

@ -13,6 +13,7 @@
*/
package org.wso2.carbon.iot.android.sense.util;
import org.wso2.carbon.iot.android.sense.beacon.BeaconScanedData;
import org.wso2.carbon.iot.android.sense.event.streams.Location.LocationData;
import org.wso2.carbon.iot.android.sense.event.streams.Sensor.SensorData;
import org.wso2.carbon.iot.android.sense.event.streams.Speed.SpeedData;
@ -33,7 +34,7 @@ public class SenseDataHolder {
private static List<LocationData> locationDataHolder;
private static List<WordData> wordDataHolder;
private static List<SpeedData> speedDataHolder;
private static List<BeaconScanedData> beaconScanedDataHolder;
//LocationData gps;
@ -80,6 +81,13 @@ public class SenseDataHolder {
return speedDataHolder;
}
public static List<BeaconScanedData> getBeaconScanedDataHolder(){
if(beaconScanedDataHolder == null){
beaconScanedDataHolder = new CopyOnWriteArrayList<>();
}
return beaconScanedDataHolder;
}
public static void resetSensorDataHolder(){
sensorDataHolder = null;
}
@ -100,5 +108,9 @@ public class SenseDataHolder {
speedDataHolder = null;
}
public static void resetBeaconScanedDataHolder() {
beaconScanedDataHolder = null;
}
}

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape android:shape="oval">
<solid android:color="#fa09ad"/>
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="oval">
<solid android:color="#c20586"/>
</shape>
</item>
</selector>

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/listContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:orientation="vertical">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal"
android:text="@string/no_data"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>

@ -0,0 +1,21 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dip" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center_horizontal"
android:text="Scanning..." />
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@android:color/darker_gray"
android:dividerHeight="1dip" />
</RelativeLayout>

@ -6,7 +6,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="org.wso2.carbon.iot.android.sense.realtimeviewer.ActivitySelectSensor">
tools:context="org.wso2.carbon.iot.android.sense.realtimeviewer.ActivitySelectSensor"
android:touchscreenBlocksFocus="false">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
@ -24,30 +25,42 @@
<include layout="@layout/content_activity_select_sensor"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_gravity="bottom|center"
android:layout_height="wrap_content" >
<android.support.design.widget.FloatingActionButton
android:id="@+id/publish"
android:id="@+id/beacon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:adjustViewBounds="false"
android:src="@drawable/pushtoserver"/>
android:src="@drawable/beacon"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/addSensors"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_input_add"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/speech"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/mic"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/addSensors"
android:id="@+id/publish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_input_add"/>
android:adjustViewBounds="false"
android:src="@drawable/pushtoserver"/>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/round_button"
android:gravity="center"
android:layout_marginTop="20dp"
android:layout_marginStart="20dp"/>
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/round_button"
android:layout_marginTop="20dp"
android:layout_marginStart="20dp"
android:gravity="center" />
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/round_button"
android:layout_marginTop="20dp"
android:layout_marginStart="20dp"
android:gravity="center" />
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/round_button"
android:layout_marginTop="20dp"
android:layout_marginStart="20dp"
android:gravity="center" />
</LinearLayout>

@ -0,0 +1,203 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2013 The Android Open Source Project
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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:orientation="horizontal">
<ImageView
android:id="@+id/device_icon"
android:layout_width="100dp"
android:layout_height="100dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:src="@drawable/beacon"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/device_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24sp"/>
<GridLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnCount="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:text="@string/label_mac"
android:textSize="12sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/device_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:typeface="monospace"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:text="@string/label_updated"
android:textSize="12sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/device_last_update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:textSize="12sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:text="@string/label_rssi"
android:textSize="12sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/device_rssi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:textSize="12sp"/>
</GridLayout>
<GridLayout
android:id="@+id/ibeacon_section"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnCount="4">
<!-- ROW 1 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:text="@string/label_uuid"
android:textSize="12sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/ibeacon_uuid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnSpan="3"
android:paddingRight="5dp"
android:textSize="12sp"/>
<!-- ROW 2 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:text="@string/label_major"
android:textSize="12sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/ibeacon_major"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:textSize="12sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="@string/label_minor"
android:textSize="12sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/ibeacon_minor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:textSize="12sp"/>
<!-- ROW 3 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:text="@string/label_tx_power"
android:textSize="12sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/ibeacon_tx_power"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:textSize="12sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="@string/label_distance"
android:textSize="12sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/ibeacon_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:textSize="12sp"/>
<!-- ROW 4 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:text="@string/label_decriptor"
android:textSize="12sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/ibeacon_distance_descriptor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnSpan="3"
android:paddingRight="5dp"
android:textSize="12sp"/>
</GridLayout>
</LinearLayout>
</LinearLayout>

@ -0,0 +1,80 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:paddingBottom="10dip"
android:paddingTop="10dip" >
<TextView
android:id="@+id/BEACON_uuid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left|top" >
</TextView>
<TextView
android:id="@+id/BEACON_major"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/BEACON_uuid"
android:layout_marginTop="5dp"
android:gravity="left|top" >
</TextView>
<TextView
android:id="@+id/BEACON_minor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/BEACON_uuid"
android:layout_marginLeft="10dip"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/BEACON_major"
android:gravity="left|top" >
</TextView>
<TextView
android:id="@+id/BEACON_proximity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/BEACON_major"
android:layout_marginTop="5dp"
android:gravity="left|top" >
</TextView>
<TextView
android:id="@+id/BEACON_rssi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/BEACON_major"
android:layout_marginLeft="10dip"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/BEACON_proximity"
android:gravity="left|top" >
</TextView>
<TextView
android:id="@+id/BEACON_txpower"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/BEACON_major"
android:layout_marginLeft="10dip"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/BEACON_rssi"
android:gravity="left|top" >
</TextView>
<TextView
android:id="@+id/BEACON_range"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/BEACON_proximity"
android:layout_marginLeft="10dip"
android:layout_marginTop="5dp"
android:gravity="left|top" >
</TextView>
</RelativeLayout>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

@ -5,5 +5,5 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="nav_header_vertical_spacing">16dp</dimen>
<dimen name="nav_header_height">160dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="fab_margin">40dp</dimen>
</resources>

@ -11,4 +11,75 @@
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<!-- Labels -->
<string name="about_dialog_text">This is a sample application using the Bluetooth LE Library.\n\nGithub: https://github.com/alt236/Bluetooth-LE-Library---Android\n\nCopyright: Alexandros Schillings</string>
<string name="header_device_info">Device Info</string>
<string name="header_ibeacon_data">iBeacon Data</string>
<string name="header_raw_ad_records">Raw Ad Records</string>
<string name="header_rssi_info">RSSI Info</string>
<string name="header_scan_record">Scan Record</string>
<string name="label_advertisement">Advertisement:</string>
<string name="label_as_array">As Array:</string>
<string name="label_as_string">As String:</string>
<string name="label_bluetooth_le_status">Bluetooth LE:</string>
<string name="label_bluetooth_status">Bluetooth:</string>
<string name="label_bonding_state">Bonding State:</string>
<string name="label_company_id">Company ID:</string>
<string name="label_data">Data:</string>
<string name="label_desc">Desc:</string>
<string name="label_device_address">Device address:</string>
<string name="label_device_class">Device Class:</string>
<string name="label_device_major_class">Major Class:</string>
<string name="label_device_services">Services:</string>
<string name="label_device_name">Device Name:</string>
<string name="label_distance">Distance:</string>
<string name="label_first_rssi">First RSSI:</string>
<string name="label_first_timestamp">First Timestamp:</string>
<string name="label_last_rssi">Last RSSI:</string>
<string name="label_last_timestamp">Last Timestamp:</string>
<string name="label_mac">MAC:</string>
<string name="label_major">Major:</string>
<string name="label_minor">Minor:</string>
<string name="label_rssi">RSSI:</string>
<string name="label_running_average_rssi">Running Average RSSI:</string>
<string name="label_state">State:</string>
<string name="label_tx_power">TX Power:</string>
<string name="label_uuid">UUID:</string>
<string name="label_updated">Updated:</string>
<string name="label_decriptor">Descriptor:</string>
<string name="connected">Connected</string>
<string name="disconnected">Disconnected</string>
<string name="invalid_device_data">Invalid Device Data!</string>
<string name="no_data">No data</string>
<string name="not_supported">Not supported</string>
<string name="off">Off</string>
<string name="on">On</string>
<string name="supported">Supported</string>
<string name="unknown">unknown</string>
<string name="unknown_characteristic">Unknown characteristic</string>
<string name="unknown_device">Unknown device</string>
<string name="unknown_service">Unknown service</string>
<string name="no_known_services">No known services</string>
<string name="formatter_meters">%sm</string>
<string name="formatter_db">%sdb</string>
<string name="formatter_item_count">Items: %s</string>
<!-- Menu items -->
<string name="menu_about">About</string>
<string name="menu_connect">Connect</string>
<string name="menu_disconnect">Disconnect</string>
<string name="menu_scan">Scan</string>
<string name="menu_stop">Stop</string>
<string name="menu_share">Share</string>
<!-- Export Email Strings -->
<string name="exporter_email_device_list_subject">Bluetooth LE Scan Results (%s)</string>
<string name="exporter_email_device_services_subject" formatted="false">Bluetooth LE Device GATT Results (%s, %s)</string>
<string name="exporter_email_device_list_body">Please find attached the scan results.</string>
<string name="exporter_email_device_list_picker_text">Please select your email client:</string>
</resources>

@ -51,4 +51,70 @@
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>wso2-nexus</id>
<name>WSO2 internal Repository</name>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
</repository>
<repository>
<id>wso2.releases</id>
<name>WSO2 internal Repository</name>
<url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
</repository>
</repositories>
<dependencies>
<!--Dependency on Sidhdhi - required for PolicyMgt-->
<dependency>
<groupId>org.wso2.siddhi</groupId>
<artifactId>siddhi-query-compiler</artifactId>
<version>${sidhdhi.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.siddhi</groupId>
<artifactId>siddhi-query-api</artifactId>
<version>${sidhdhi.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.siddhi</groupId>
<artifactId>siddhi-core</artifactId>
<version>${sidhdhi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${apache-httpclient.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
</dependencies>
<properties>
<!-- Java Version Compatibility -->
<wso2.maven.compiler.source>1.7</wso2.maven.compiler.source>
<wso2.maven.compiler.target>1.7</wso2.maven.compiler.target>
<!--Apache HTTP Components-->
<apache-httpclient.version>4.5</apache-httpclient.version>
<!-- Sidhdhi Version -->
<sidhdhi.version>3.0.5</sidhdhi.version>
<gson.version>2.3.1</gson.version>
</properties>
</project>

@ -21,7 +21,7 @@
<mapping customMapping="disable" type="text"/>
<to eventAdapterType="email">
<property name="email.subject">Email Alerts Speed</property>
<property name="email.address"></property>
<property name="email.address">pacificcontrolsapps@gmail.com</property>
<property name="email.type">text/html</property>
</to>
</eventPublisher>

@ -21,7 +21,7 @@
<mapping customMapping="disable" type="text"/>
<to eventAdapterType="email">
<property name="email.subject">Email Alerts Turn</property>
<property name="email.address"></property>
<property name="email.address">pacificcontrolsapps@gmail.com</property>
<property name="email.type">text/html</property>
</to>
</eventPublisher>

@ -32,7 +32,7 @@ import java.util.List;
description = "Information related to VPN Configuration.")
public class VpnBeanWrapper {
@ApiModelProperty(name = "operation",
value = "List of device Ids to be need to execute UpgradeFirmware operation.", required = true)
value = "List of device Ids to be need to execute VPN operation.", required = true)
private Vpn operation;
@ApiModelProperty(name = "deviceIDs",
value = "List of device Ids to be need to execute VPN operation.", required = true)

@ -354,6 +354,61 @@ public interface DeviceManagementAdminService {
@ApiParam(name = "deviceIds", value = "Device IDs to be requested to get device information")
List<String> deviceIDs);
@POST
@Path("/info")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Requesting Information from Android Devices",
notes = "Using this REST API you are able to request for Android device details. Once this REST API is" +
" executed it will be in the Android operation queue until the device calls the server to retrieve " +
"the list of operations that needs to be executed on the device",
response = Activity.class,
tags = "Android Device Management Administrative Service"
)
@ApiResponses(value = {
@ApiResponse(
code = 201,
message = "Created. \n Device logcat operation has successfully been scheduled",
response = Activity.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "URL of the activity instance that refers to the scheduled operation."),
@ResponseHeader(
name = "Content-Type",
description = "Content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests.")}),
@ApiResponse(
code = 303,
message = "See Other. \n Source can be retrieved from the URL specified at the Location header.",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "The Source URL of the document.")}),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 415,
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
"Server error occurred while adding a new device logcat operation.")
})
Response getDeviceLogcat(
@ApiParam(name = "deviceIds", value = "Device IDs to be requested to get device logcat")
List<String> deviceIDs);
@POST
@Path("/enterprise-wipe")
@ApiOperation(

@ -222,6 +222,31 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
}
}
@POST
@Path("/logcat")
@Override
public Response getDeviceLogcat(List<String> deviceIDs) {
if (log.isDebugEnabled()) {
log.debug("Invoking get Android device logcat operation");
}
try {
CommandOperation operation = new CommandOperation();
operation.setCode(AndroidConstants.OperationCodes.LOGCAT);
operation.setType(Operation.Type.COMMAND);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
} catch (DeviceManagementException e) {
String errorMessage = "Issue in retrieving device management service instance";
log.error(errorMessage, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
}
}
@POST
@Path("/enterprise-wipe")
@Override
@ -569,24 +594,24 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
@POST
@Path("/configure-vpn")
@Override
public Response configureVPN(@Valid VpnBeanWrapper vpnBeanWrapper) {
public Response configureVPN(VpnBeanWrapper vpnConfiguration) {
if (log.isDebugEnabled()) {
log.debug("Invoking Android VPN device operation");
}
try {
if (vpnBeanWrapper == null || vpnBeanWrapper.getOperation() == null) {
if (vpnConfiguration == null || vpnConfiguration.getOperation() == null) {
String errorMessage = "The payload of the VPN operation is incorrect";
log.error(errorMessage);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
}
Vpn vpn = vpnBeanWrapper.getOperation();
Vpn vpn = vpnConfiguration.getOperation();
ProfileOperation operation = new ProfileOperation();
operation.setCode(AndroidConstants.OperationCodes.VPN);
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(vpn.toJSON());
return AndroidAPIUtils.getOperationResponse(vpnBeanWrapper.getDeviceIDs(),
return AndroidAPIUtils.getOperationResponse(vpnConfiguration.getDeviceIDs(),
operation);
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";

@ -338,6 +338,9 @@ public class AndroidAPIUtils {
if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION) != null) {
app.setVersion(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION).getAsString());
}
if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.IS_ACTIVE) != null) {
app.setActive(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.IS_ACTIVE).getAsBoolean());
}
applications.add(app);
}
getApplicationManagerService().updateApplicationListInstalledInDevice(deviceIdentifier, applications);
@ -393,6 +396,8 @@ public class AndroidAPIUtils {
deviceInfo.getDeviceDetailsMap().put("mac", prop.getValue());
} else if (prop.getName().equalsIgnoreCase("SERIAL")) {
deviceInfo.getDeviceDetailsMap().put("serial", prop.getValue());
} else if (prop.getName().equalsIgnoreCase("OS_BUILD_DATE")) {
deviceInfo.setOsBuildDate(prop.getValue());
}
} else {
if (prop.getName().equalsIgnoreCase("CPU_INFO")) {

@ -98,6 +98,7 @@ public final class AndroidConstants {
public static final String DISENROLL = "DISENROLL";
public static final String MONITOR = "MONITOR";
public static final String VPN = "VPN";
public static final String LOGCAT = "LOGCAT";
public static final String APP_RESTRICTION = "APP-RESTRICTION";
public static final String WORK_PROFILE = "WORK_PROFILE";
}
@ -130,6 +131,7 @@ public final class AndroidConstants {
public static final String USS = "USS";
public static final String VERSION = "version";
public static final String ICON = "icon";
public static final String IS_ACTIVE = "isActive";
}
public final class ErrorMessages {

@ -19,7 +19,7 @@
<!-- This file contains the list of permissions that are associated with URL end points
of the web app. Each permission should contain the name, permission path, API path
(URL) , HTTP method and authorization scope (OAuth2).
(URL) and HTTP method.
When defining dynamic paths for APIs, path variables are denoted by '*' notation.
For ex:
Actual API endpoint: mdm-android-agent/1.0.0/operation/{device-id}
@ -29,368 +29,266 @@
-->
<PermissionConfiguration>
<APIVersion></APIVersion>
<!-- Operations management related permissions for admin -->
<!-- Configuration related permissions -->
<Permission>
<name>Lock</name>
<path>/device-mgt/admin/operations/android/lock</path>
<url>/admin/devices/lock-devices</url>
<method>POST</method>
<scope>emm_admin,emm_user</scope>
<name>View Tenant configuration</name>
<path>/device-mgt/admin/platform-configs/view</path>
<url>/configuration</url>
<method>GET</method>
</Permission>
<Permission>
<name>Unlock</name>
<path>/device-mgt/admin/operations/android/unlock</path>
<url>/admin/devices/unlock-devices</url>
<name>Add Tenant configuration</name>
<path>/device-mgt/admin/platform-configs/add</path>
<url>/configuration</url>
<method>POST</method>
<scope>emm_admin,emm_user</scope>
</Permission>
<Permission>
<name>Mute</name>
<path>/device-mgt/admin/operations/android/mute</path>
<url>/admin/devices/mute</url>
<method>POST</method>
<scope>emm_admin,emm_user</scope>
<name>Enroll</name>
<path>/device-mgt/user/device/android/enroll</path>
<url>/configuration/license</url>
<method>GET</method>
</Permission>
<Permission>
<name>Location</name>
<path>/device-mgt/admin/operations/android/location</path>
<url>/admin/devices/location</url>
<method>POST</method>
<scope>emm_admin,emm_user</scope>
</Permission>
<!-- End of Configuration related permissions -->
<Permission>
<name>Clear Passcode</name>
<path>/device-mgt/admin/operations/android/clear-password</path>
<url>/admin/devices/clear-password</url>
<method>POST</method>
<scope>emm_admin</scope>
</Permission>
<!-- Device related permissions -->
<Permission>
<name>Camera</name>
<path>/device-mgt/admin/operations/android/camera</path>
<url>/admin/devices/control-camera</url>
<name>Enroll</name>
<path>/device-mgt/user/device/android/enroll</path>
<url>/devices</url>
<method>POST</method>
<scope>emm_admin,emm_user</scope>
</Permission>
<Permission>
<name>Device Info</name>
<path>/device-mgt/admin/operations/android/device-info</path>
<url>/admin/devices/info</url>
<method>POST</method>
<scope>emm_admin,emm_user</scope>
<name>Enroll</name>
<path>/device-mgt/user/device/android/enroll</path>
<url>/devices/*</url>
<method>DELETE</method>
</Permission>
<Permission>
<name>Enterprise Wipe</name>
<path>/device-mgt/admin/operations/android/enterprise-wipe</path>
<url>/admin/devices/enterprise-wipe</url>
<method>POST</method>
<scope>emm_admin</scope>
<name>Enroll</name>
<path>/device-mgt/user/device/android/enroll</path>
<url>/devices/*</url>
<method>PUT</method>
</Permission>
<Permission>
<name>Wipe Data</name>
<path>/device-mgt/admin/operations/android/wipe-data</path>
<url>/admin/devices/wipe</url>
<method>POST</method>
<scope>emm_admin</scope>
<name>Enroll</name>
<path>/device-mgt/user/device/android/enroll</path>
<url>/device/*/applications</url>
<method>PUT</method>
</Permission>
<Permission>
<name>Application List</name>
<path>/device-mgt/admin/operations/android/application-list</path>
<url>/admin/devices/applications</url>
<method>POST</method>
<scope>emm_admin,emm_user</scope>
<name>Enroll</name>
<path>/device-mgt/user/device/android/enroll</path>
<url>/device/*/pending-operations</url>
<method>PUT</method>
</Permission>
<Permission>
<name>Ring</name>
<path>/device-mgt/admin/operations/android/ring-device</path>
<url>/admin/devices/ring</url>
<method>POST</method>
<scope>emm_admin,emm_user</scope>
<name>Enroll</name>
<path>/device-mgt/user/device/android/enroll</path>
<url>/device/*/status</url>
<method>GET</method>
</Permission>
<Permission>
<name>Reboot</name>
<path>/device-mgt/admin/operations/android/reboot-device</path>
<url>/admin/devices/reboot</url>
<method>POST</method>
<scope>emm_admin,emm_user</scope>
</Permission>
<!-- End of device related permissions -->
<Permission>
<name>Upgrade Firmware</name>
<path>/device-mgt/admin/operations/android/upgrade-firmware</path>
<url>/admin/devices/upgrade-firmware</url>
<method>POST</method>
<scope>emm_admin</scope>
</Permission>
<!-- Event related permissions -->
<Permission>
<name>Configure VPN</name>
<path>/device-mgt/admin/operations/android/vpn</path>
<url>/admin/devices/configure-vpn</url>
<name>Enroll</name>
<path>/device-mgt/user/device/android/enroll</path>
<url>/events/publish</url>
<method>POST</method>
<scope>emm_admin,emm_user</scope>
</Permission>
<Permission>
<name>Install Application</name>
<path>/device-mgt/android/operations/install-application</path>
<url>/admin/devices/install-application</url>
<name>View Events</name>
<path>/device-mgt/admin/events/view</path>
<url>/events/publish</url>
<method>POST</method>
<scope>emm_admin,emm_user</scope>
</Permission>
<Permission>
<name>Update Application</name>
<path>/device-mgt/admin/operations/android/install-application</path>
<url>/admin/devices/update-application</url>
<method>POST</method>
<scope>emm_admin,emm_user</scope>
</Permission>
<!-- End of event related permissions -->
<!-- Operations related permissions -->
<Permission>
<name>Uninstall Application</name>
<path>/device-mgt/admin/operations/android/uninstall-application</path>
<url>/admin/devices/uninstall-application</url>
<name>Get installed applications</name>
<path>/device-mgt/admin/device/android/operation/get-installed-applications</path>
<url>/admin/devices/applications</url>
<method>POST</method>
<scope>emm_admin,emm_user</scope>
</Permission>
<Permission>
<name>Blacklist Applications</name>
<path>/device-mgt/admin/operations/android/blacklist-applications</path>
<name>Blacklist applications</name>
<path>/device-mgt/admin/device/android/operation/blacklist-applications</path>
<url>/admin/devices/blacklist-applications</url>
<method>POST</method>
<scope>emm_admin</scope>
</Permission>
<Permission>
<name>Notification</name>
<path>/device-mgt/admin/operations/android/notification</path>
<url>/admin/devices/send-notification</url>
<name>Change lock code</name>
<path>/device-mgt/admin/device/android/operation/change-lock-code</path>
<url>/admin/devices/change-lock-code</url>
<method>POST</method>
<scope>emm_admin,emm_user</scope>
</Permission>
<Permission>
<name>Wifi</name>
<path>/device-mgt/admin/operations/android/wifi</path>
<url>/admin/devices/configure-wifi</url>
<name>Clear password</name>
<path>/device-mgt/admin/device/android/operation/clear-password</path>
<url>/admin/devices/clear-password</url>
<method>POST</method>
<scope>emm_admin</scope>
</Permission>
<Permission>
<name>Encryption</name>
<path>/device-mgt/admin/operations/android/encrypt</path>
<url>/admin/devices/encrypt-storage</url>
<name>Configure VPN</name>
<path>/device-mgt/admin/device/android/operation/configure-vpn</path>
<url>/admin/devices/configure-vpn</url>
<method>POST</method>
<scope>emm_admin</scope>
</Permission>
<Permission>
<name>Change lock code</name>
<path>/device-mgt/admin/operations/android/change-lock-code</path>
<url>/admin/devices/change-lock-code</url>
<name>Configure WiFi</name>
<path>/device-mgt/admin/device/android/operation/configure-wifi</path>
<url>/admin/devices/configure-wifi</url>
<method>POST</method>
<scope>emm_admin</scope>
</Permission>
<Permission>
<name>Password Policy</name>
<path>/device-mgt/admin/operations/android/password-policy</path>
<url>/admin/devices/set-password-policy</url>
<name>Control camera</name>
<path>/device-mgt/admin/device/android/operation/control-camera</path>
<url>/admin/devices/control-camera</url>
<method>POST</method>
<scope>emm_admin</scope>
</Permission>
<Permission>
<name>Webclip</name>
<path>/device-mgt/admin/operations/android/webclip</path>
<url>/admin/devices/set-webclip</url>
<name>Encrypt storage</name>
<path>/device-mgt/admin/device/android/operation/encrypt-storage</path>
<url>/admin/devices/encrypt-storage</url>
<method>POST</method>
<scope>emm_admin</scope>
</Permission>
<Permission>
<name>Disenroll</name>
<path>/device-mgt/admin/operations/android/disenroll</path>
<url>/operation/disenroll</url>
<name>Enterprise wipe</name>
<path>/device-mgt/admin/device/android/operation/enterprise-wipe</path>
<url>/admin/devices/enterprise-wipe</url>
<method>POST</method>
<scope>emm_android_agent</scope>
</Permission>
<!-- Device management related permissions -->
<Permission>
<name>View devices</name>
<path>/device-mgt/admin/devices/view</path>
<url>/device</url>
<method>GET</method>
<scope>emm_admin</scope>
</Permission>
<Permission>
<name>View device</name>
<path>/device-mgt/admin/devices/view</path>
<url>/device/*</url>
<method>GET</method>
<scope>emm_admin,emm_user</scope>
</Permission>
<Permission>
<name>Update device</name>
<path>/device-mgt/admin/devices/update</path>
<url>/device/*</url>
<method>PUT</method>
<scope>emm_admin,emm_user</scope>
</Permission>
<Permission>
<name>Update application list</name>
<path>/device-mgt/admin/operations/android/update-applist</path>
<url>/device/appList/*</url>
<name>Get device info</name>
<path>/device-mgt/admin/device/android/operation/get-info</path>
<url>/admin/devices/info/url>
<method>POST</method>
<scope>emm_admin</scope>
</Permission>
<Permission>
<name>View license</name>
<path>/device-mgt/user/enroll/android</path>
<url>/configuration/license</url>
<method>GET</method>
<scope>emm_android_agent</scope>
<name>Install application</name>
<path>/device-mgt/admin/device/android/operation/install-application</path>
<url>/admin/devices/install-application</url>
<method>POST</method>
</Permission>
<!-- Enrollment related permissions -->
<Permission>
<name>Enroll device</name>
<path>/device-mgt/user/enroll/android</path>
<url>/devices</url>
<name>Get location details</name>
<path>/device-mgt/admin/device/android/operation/location</path>
<url>/admin/devices/location</url>
<method>POST</method>
<scope>emm_android_agent</scope>
</Permission>
<Permission>
<name>Devices related Operations</name>
<path>/device-mgt/user/enroll/android</path>
<url>/devices/*</url>
<method>GET</method>
<scope>emm_android_agent</scope>
<name>Lock device</name>
<path>/device-mgt/admin/device/android/operation/lock-device</path>
<url>/admin/devices/lock-devices</url>
<method>POST</method>
</Permission>
<Permission>
<name>Device is enrolled</name>
<path>/device-mgt/user/enroll/android</path>
<url>/devices/*/status</url>
<method>GET</method>
<scope>emm_android_agent</scope>
<name>Mute device</name>
<path>/device-mgt/admin/device/android/operation/mute</path>
<url>/admin/devices/mute</url>
<method>POST</method>
</Permission>
<Permission>
<name>Devices related Operations</name>
<path>/device-mgt/user/enroll/android</path>
<url>/devices/*/pending-operations</url>
<method>PUT</method>
<scope>emm_android_agent</scope>
<name>Reboot device</name>
<path>/device-mgt/admin/device/android/operation/reboot</path>
<url>/admin/devices/reboot</url>
<method>POST</method>
</Permission>
<Permission>
<name>Modify devices</name>
<path>/device-mgt/user/enroll/android</path>
<url>/devices/*</url>
<method>PUT</method>
<scope>emm_android_agent</scope>
<name>Ring device</name>
<path>/device-mgt/admin/device/android/operation/ring</path>
<url>/admin/devices/ring</url>
<method>POST</method>
</Permission>
<Permission>
<name>Delete devices</name>
<path>/device-mgt/user/enroll/android</path>
<url>/devices/*</url>
<method>DELETE</method>
<scope>emm_android_agent</scope>
<name>Send notification</name>
<path>/device-mgt/admin/device/android/operation/send-notification</path>
<url>/admin/devices/send-notification</url>
<method>POST</method>
</Permission>
<Permission>
<name>Update Enrollment</name>
<path>/device-mgt/android/devices/enroll</path>
<url>/enrollment/*</url>
<method>PUT</method>
<scope>emm_user,emm_admin</scope>
<name>Set password policy</name>
<path>/device-mgt/admin/device/android/operation/set-password-policy</path>
<url>/admin/devices/set-password-policy</url>
<method>POST</method>
</Permission>
<Permission>
<name>Disenroll device</name>
<path>/device-mgt/android/devices/enroll</path>
<url>/enrollment/*</url>
<method>DELETE</method>
<scope>emm_user,emm_admin</scope>
<name>Set web clip</name>
<path>/device-mgt/admin/device/android/operation/set-webclip</path>
<url>/admin/devices/set-webclip</url>
<method>POST</method>
</Permission>
<!-- Policy related permissions -->
<Permission>
<name>View Policies</name>
<path>/device-mgt/user/enroll/android</path>
<url>/policy/*</url>
<method>GET</method>
<scope>emm_admin</scope>
<name>Uninstall application</name>
<path>/device-mgt/admin/device/android/operation/uninstall-application</path>
<url>/admin/devices/uninstall-application</url>
<method>POST</method>
</Permission>
<Permission>
<name>View Policy Features</name>
<path>/device-mgt/user/enroll/android</path>
<url>/policy/features/*</url>
<method>GET</method>
<scope>emm_admin</scope>
<name>Unlock device</name>
<path>/device-mgt/admin/device/android/operation/unlock-device</path>
<url>/admin/devices/unlock-devices</url>
<method>POST</method>
</Permission>
<!-- Configuration related permissions -->
<Permission>
<name>View Tenant configuration</name>
<path>/device-mgt/admin/platform-configs/view</path>
<url>/configuration</url>
<method>GET</method>
<scope>emm_admin</scope>
<name>Update applications</name>
<path>/device-mgt/admin/device/android/operation/update-application</path>
<url>/admin/devices/update-application</url>
<method>POST</method>
</Permission>
<Permission>
<name>Add Tenant configuration</name>
<path>/device-mgt/admin/platform-configs/add</path>
<url>/configuration</url>
<name>Upgrade firmware</name>
<path>/device-mgt/admin/device/android/operation/upgrade-firmware</path>
<url>/admin/devices/upgrade-firmware</url>
<method>POST</method>
<scope>emm_admin</scope>
</Permission>
<Permission>
<name>Update Tenant configuration</name>
<path>/device-mgt/admin/platform-configs/modify</path>
<url>/configuration</url>
<method>PUT</method>
<scope>emm_admin</scope>
</Permission>
<Permission>
<name>Event Addition</name>
<path>/device-mgt/android/events/add</path>
<url>/events/publish</url>
<name>Wipe device</name>
<path>/device-mgt/admin/device/android/operation/wipe</path>
<url>/admin/devices/wipe</url>
<method>POST</method>
<scope>emm_user,emm_admin</scope>
</Permission>
<Permission>
<name>Event Retrieve</name>
<path>/device-mgt/android/events/view</path>
<url>/events</url>
<method>GET</method>
<scope>emm_admin</scope>
</Permission>
<!-- End of operation related permissions -->
</PermissionConfiguration>

@ -457,6 +457,12 @@ public class AndroidFeatureManager implements FeatureManager {
feature.setDescription("remove device owner");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("LOGCAT");
feature.setName("Fetch Logcat");
feature.setDescription("Fetch device logcat");
supportedFeatures.add(feature);
return supportedFeatures;
}
}

@ -53,7 +53,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
conn = AndroidDAOFactory.getConnection();
String selectDBQuery =
"SELECT DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " +
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION" +
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION, OS_BUILD_DATE" +
" FROM AD_DEVICE WHERE DEVICE_ID = ?";
stmt = conn.prepareStatement(selectDBQuery);
stmt.setString(1, mblDeviceId);
@ -70,6 +70,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
mobileDevice.setImei(rs.getString(AndroidPluginConstants.IMEI));
mobileDevice.setImsi(rs.getString(AndroidPluginConstants.IMSI));
mobileDevice.setOsVersion(rs.getString(AndroidPluginConstants.OS_VERSION));
mobileDevice.setOsBuildDate(rs.getString(AndroidPluginConstants.OS_BUILD_DATE));
Map<String, String> propertyMap = new HashMap<String, String>();
propertyMap.put(AndroidPluginConstants.GCM_TOKEN, rs.getString(AndroidPluginConstants.GCM_TOKEN));
@ -104,7 +105,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
String createDBQuery =
"INSERT INTO AD_DEVICE(DEVICE_ID, GCM_TOKEN, DEVICE_INFO, SERIAL, " +
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, " +
"OS_VERSION, DEVICE_MODEL) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
"OS_VERSION, DEVICE_MODEL, OS_BUILD_DATE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(createDBQuery);
stmt.setString(1, mobileDevice.getMobileDeviceId());
@ -122,6 +123,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
stmt.setString(11, mobileDevice.getImsi());
stmt.setString(12, mobileDevice.getOsVersion());
stmt.setString(13, mobileDevice.getModel());
stmt.setString(14, mobileDevice.getOsBuildDate());
int rows = stmt.executeUpdate();
if (rows > 0) {
status = true;
@ -149,7 +151,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
String updateDBQuery =
"UPDATE AD_DEVICE SET GCM_TOKEN = ?, DEVICE_INFO = ?, SERIAL = ?, VENDOR = ?, " +
"MAC_ADDRESS = ?, DEVICE_NAME = ?, LATITUDE = ?, LONGITUDE = ?, IMEI = ?, " +
"IMSI = ?, OS_VERSION = ?, DEVICE_MODEL = ? WHERE DEVICE_ID = ?";
"IMSI = ?, OS_VERSION = ?, DEVICE_MODEL = ?, OS_BUILD_DATE = ? WHERE DEVICE_ID = ?";
stmt = conn.prepareStatement(updateDBQuery);
Map<String, String> properties = mobileDevice.getDeviceProperties();
@ -166,6 +168,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
stmt.setString(11, mobileDevice.getOsVersion());
stmt.setString(12, mobileDevice.getModel());
stmt.setString(13, mobileDevice.getMobileDeviceId());
stmt.setString(14, mobileDevice.getOsBuildDate());
int rows = stmt.executeUpdate();
if (rows > 0) {
status = true;
@ -225,7 +228,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
conn = AndroidDAOFactory.getConnection();
String selectDBQuery =
"SELECT DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " +
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION " +
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION, OS_BUILD_DATE " +
"FROM AD_DEVICE";
stmt = conn.prepareStatement(selectDBQuery);
rs = stmt.executeQuery();
@ -241,6 +244,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
mobileDevice.setImei(rs.getString(AndroidPluginConstants.IMEI));
mobileDevice.setImsi(rs.getString(AndroidPluginConstants.IMSI));
mobileDevice.setOsVersion(rs.getString(AndroidPluginConstants.OS_VERSION));
mobileDevice.setOsBuildDate(rs.getString(AndroidPluginConstants.OS_BUILD_DATE));
Map<String, String> propertyMap = new HashMap<>();
propertyMap.put(AndroidPluginConstants.GCM_TOKEN, rs.getString(AndroidPluginConstants.GCM_TOKEN));

@ -36,6 +36,7 @@ public class AndroidPluginConstants {
public static final String IMSI = "IMSI";
public static final String VENDOR = "VENDOR";
public static final String OS_VERSION = "OS_VERSION";
public static final String OS_BUILD_DATE = "OS_BUILD_DATE";
public static final String MAC_ADDRESS = "MAC_ADDRESS";
//Properties related to AD_FEATURE table

@ -19,6 +19,7 @@
package org.wso2.carbon.device.mgt.mobile.dto;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@ -36,6 +37,8 @@ public class MobileDevice implements Serializable {
private String imei;
private String imsi;
private String serial;
private String osBuildDate;
private Map<String, String> deviceProperties;
public MobileDevice() {
@ -122,4 +125,11 @@ public class MobileDevice implements Serializable {
this.deviceProperties = deviceProperties;
}
public String getOsBuildDate() {
return osBuildDate;
}
public void setOsBuildDate(String osBuildDate) {
this.osBuildDate = osBuildDate;
}
}

@ -38,6 +38,9 @@ import org.wso2.carbon.registry.core.Registry;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
@ -54,6 +57,7 @@ public class MobileDeviceManagementUtil {
private static final String MOBILE_DEVICE_LATITUDE = "LATITUDE";
private static final String MOBILE_DEVICE_LONGITUDE = "LONGITUDE";
private static final String MOBILE_DEVICE_SERIAL = "SERIAL";
private static final String MOBILE_DEVICE_OS_BUILD_DATE = "OS_BUILD_DATE";
public static Document convertToDocument(File file) throws DeviceManagementException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
@ -100,6 +104,7 @@ public class MobileDeviceManagementUtil {
mobileDevice.setLatitude(getPropertyValue(device, MOBILE_DEVICE_LATITUDE));
mobileDevice.setLongitude(getPropertyValue(device, MOBILE_DEVICE_LONGITUDE));
mobileDevice.setSerial(getPropertyValue(device, MOBILE_DEVICE_SERIAL));
mobileDevice.setOsBuildDate(getPropertyValue(device, MOBILE_DEVICE_OS_BUILD_DATE));
if (device.getProperties() != null) {
Map<String, String> deviceProperties = new HashMap<String, String>();
@ -124,6 +129,7 @@ public class MobileDeviceManagementUtil {
propertyList.add(getProperty(MOBILE_DEVICE_IMSI, mobileDevice.getImsi()));
propertyList.add(getProperty(MOBILE_DEVICE_MODEL, mobileDevice.getModel()));
propertyList.add(getProperty(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion()));
propertyList.add(getProperty(MOBILE_DEVICE_OS_BUILD_DATE, mobileDevice.getOsBuildDate()));
propertyList.add(getProperty(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor()));
if(mobileDevice.getLatitude() != null) {
propertyList.add(getProperty(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude()));

@ -16,6 +16,7 @@ CREATE TABLE IF NOT EXISTS `AD_DEVICE` (
`TOKEN` VARCHAR(500) NULL DEFAULT NULL,
`UNLOCK_TOKEN` VARCHAR(500) NULL DEFAULT NULL,
`SERIAL` VARCHAR(45) NULL DEFAULT NULL,
`OS_BUILD_DATE` VARCHAR(45) NULL DEFAULT NULL,
PRIMARY KEY (`DEVICE_ID`) );

@ -16,6 +16,7 @@ CREATE TABLE IF NOT EXISTS `AD_DEVICE` (
`SERIAL` VARCHAR(45) NULL DEFAULT NULL,
`MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL,
`DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL,
`OS_BUILD_DATE` VARCHAR(100) NULL DEFAULT NULL,
PRIMARY KEY (`DEVICE_ID`));
-- -----------------------------------------------------

@ -15,6 +15,7 @@ CREATE TABLE AD_DEVICE (
SERIAL VARCHAR(45) NULL DEFAULT NULL,
MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL,
DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL,
OS_BUILD_DATE VARCHAR(100) NULL DEFAULT NULL,
PRIMARY KEY (DEVICE_ID));
-- -----------------------------------------------------

@ -15,6 +15,7 @@ CREATE TABLE IF NOT EXISTS `AD_DEVICE` (
`SERIAL` VARCHAR(45) NULL DEFAULT NULL,
`MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL,
`DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL,
`OS_BUILD_DATE` VARCHAR(100) NULL DEFAULT NULL,
PRIMARY KEY (`DEVICE_ID`))
ENGINE = InnoDB;

@ -15,6 +15,7 @@ CREATE TABLE AD_DEVICE (
SERIAL VARCHAR(45) DEFAULT NULL,
MAC_ADDRESS VARCHAR(45) DEFAULT NULL,
DEVICE_NAME VARCHAR(100) DEFAULT NULL,
OS_BUILD_DATE VARCHAR(100) DEFAULT NULL,
CONSTRAINT PK_AD_DEVICE PRIMARY KEY (DEVICE_ID)
)
/

@ -15,6 +15,7 @@ CREATE TABLE IF NOT EXISTS AD_DEVICE (
SERIAL VARCHAR(45) NULL DEFAULT NULL,
MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL,
DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL,
OS_BUILD_DATE VARCHAR(100) NULL DEFAULT NULL,
PRIMARY KEY (DEVICE_ID)
);

@ -16,6 +16,7 @@ CREATE TABLE IF NOT EXISTS `AD_DEVICE` (
`SERIAL` VARCHAR(45) NULL DEFAULT NULL,
`MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL,
`DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL,
`OS_BUILD_DATE` VARCHAR(100) NULL DEFAULT NULL,
PRIMARY KEY (`DEVICE_ID`));
-- -----------------------------------------------------

@ -15,6 +15,7 @@ CREATE TABLE AD_DEVICE (
SERIAL VARCHAR(45) NULL DEFAULT NULL,
MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL,
DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL,
OS_BUILD_DATE VARCHAR(100) NULL DEFAULT NULL,
PRIMARY KEY (DEVICE_ID));
-- -----------------------------------------------------

@ -15,6 +15,7 @@ CREATE TABLE IF NOT EXISTS `AD_DEVICE` (
`SERIAL` VARCHAR(45) NULL DEFAULT NULL,
`MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL,
`DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL,
`OS_BUILD_DATE` VARCHAR(100) NULL DEFAULT NULL,
PRIMARY KEY (`DEVICE_ID`))
ENGINE = InnoDB;

@ -15,6 +15,7 @@ CREATE TABLE AD_DEVICE (
SERIAL VARCHAR(45) DEFAULT NULL,
MAC_ADDRESS VARCHAR(45) DEFAULT NULL,
DEVICE_NAME VARCHAR(100) DEFAULT NULL,
OS_BUILD_DATE VARCHAR(100) DEFAULT NULL,
CONSTRAINT PK_AD_DEVICE PRIMARY KEY (DEVICE_ID)
)
/

@ -15,6 +15,7 @@ CREATE TABLE IF NOT EXISTS AD_DEVICE (
SERIAL VARCHAR(45) NULL DEFAULT NULL,
MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL,
DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL,
OS_BUILD_DATE VARCHAR(100) NULL DEFAULT NULL,
PRIMARY KEY (DEVICE_ID)
);

@ -2,11 +2,11 @@
-- Table IOS_FEATURE
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS IOS_FEATURE (
ID SERIAL NOT NULL,
FEATURE_ID SERIAL NOT NULL,
CODE VARCHAR(45) NOT NULL,
NAME VARCHAR(100) NULL,
DESCRIPTION VARCHAR(200) NULL,
PRIMARY KEY (ID)
PRIMARY KEY (FEATURE_ID)
);
-- -----------------------------------------------------

Loading…
Cancel
Save