mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt-plugins
This commit is contained in:
commit
37dd3f5d88
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>iot-analytics</artifactId>
|
<artifactId>iot-analytics</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>iot-analytics</artifactId>
|
<artifactId>iot-analytics</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -19,24 +19,24 @@
|
|||||||
|
|
||||||
<eventPublisher name="WSO2IoT-DeviceOperation-Publisher" xmlns="http://wso2.org/carbon/eventpublisher">
|
<eventPublisher name="WSO2IoT-DeviceOperation-Publisher" xmlns="http://wso2.org/carbon/eventpublisher">
|
||||||
<from streamName="org.wso2.iot.operation" version="1.0.0"/>
|
<from streamName="org.wso2.iot.operation" version="1.0.0"/>
|
||||||
<mapping customMapping="enable" type="json">
|
<mapping customMapping="enable" type="text">
|
||||||
<inline>
|
<inline>
|
||||||
{
|
{
|
||||||
"deviceIdentifiers": [
|
"deviceIdentifiers": {{meta_deviceIdentifiers}},
|
||||||
{{meta_deviceIdentifier}}
|
"deviceType": "{{meta_deviceType}}",
|
||||||
],
|
|
||||||
"operation": {
|
"operation": {
|
||||||
"code": {{code}},
|
"code": "{{code}}",
|
||||||
"type": {{type}},
|
"type": "{{type}}",
|
||||||
"status": "PENDING",
|
"status": "PENDING",
|
||||||
"isEnabled": {{isEnabled}},
|
"isEnabled": "{{isEnabled}}",
|
||||||
"payLoad": {{payLoad}}
|
"payLoad": "{{payLoad}}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</inline>
|
</inline>
|
||||||
</mapping>
|
</mapping>
|
||||||
<to eventAdapterType="oauth-http">
|
<to eventAdapterType="oauth-http">
|
||||||
<property name="http.client.method">HttpPost</property>
|
<property name="http.client.method">HttpPost</property>
|
||||||
<property name="http.url">https://localhost:9443/api/device-mgt/v1.0/devices/android/operations</property>
|
<property name="http.url">https://localhost:9443/api/device-mgt/v1.0/devices/{deviceType}/operations</property>
|
||||||
|
<property name="http.url.templated">true</property>
|
||||||
</to>
|
</to>
|
||||||
</eventPublisher>
|
</eventPublisher>
|
||||||
@ -1,11 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "org.wso2.iot.operation",
|
"name": "org.wso2.iot.operation",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"nickName": "",
|
"nickName": "Operation Stream",
|
||||||
"description": "Operation stream for WSO2 IoT Devices",
|
"description": "Operation stream for WSO2 IoT Devices",
|
||||||
"metaData": [
|
"metaData": [
|
||||||
{
|
{
|
||||||
"name": "deviceIdentifier",
|
"name": "deviceIdentifiers",
|
||||||
|
"type": "STRING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "deviceType",
|
||||||
"type": "STRING"
|
"type": "STRING"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>iot-analytics</artifactId>
|
<artifactId>iot-analytics</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>iot-analytics</artifactId>
|
<artifactId>iot-analytics</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>analytics</artifactId>
|
<artifactId>analytics</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>carbon-device-mgt-plugins-parent</artifactId>
|
<artifactId>carbon-device-mgt-plugins-parent</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -43,7 +43,6 @@ import org.wso2.carbon.iot.android.sense.util.dto.RegisterInfo;
|
|||||||
|
|
||||||
import agent.sense.android.iot.carbon.wso2.org.wso2_senseagent.R;
|
import agent.sense.android.iot.carbon.wso2.org.wso2_senseagent.R;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A login screen that offers to register the device.
|
* A login screen that offers to register the device.
|
||||||
*/
|
*/
|
||||||
@ -159,7 +158,6 @@ public class RegisterActivity extends Activity {
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
mUiHandler.post(new Runnable() {
|
mUiHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -167,11 +165,9 @@ public class RegisterActivity extends Activity {
|
|||||||
showProgress(false);
|
showProgress(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
myThread.start();
|
myThread.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,6 +204,4 @@ public class RegisterActivity extends Activity {
|
|||||||
deviceRegisterButton.setVisibility(show? View.VISIBLE : View.GONE);
|
deviceRegisterButton.setVisibility(show? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -34,5 +34,4 @@ public class DataPublisherReceiver extends BroadcastReceiver {
|
|||||||
PendingIntent pending = PendingIntent.getService(context, 0, i, 0);
|
PendingIntent pending = PendingIntent.getService(context, 0, i, 0);
|
||||||
service.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), ALARM_INTERVAL, pending);
|
service.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), ALARM_INTERVAL, pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -20,7 +20,6 @@ import android.hardware.Sensor;
|
|||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -29,17 +28,17 @@ import org.wso2.carbon.iot.android.sense.constants.SenseConstants;
|
|||||||
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.AndroidSenseMQTTHandler;
|
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.MQTTTransportHandler;
|
||||||
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.TransportHandlerException;
|
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.TransportHandlerException;
|
||||||
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;
|
|
||||||
import org.wso2.carbon.iot.android.sense.event.streams.activity.ActivityData;
|
import org.wso2.carbon.iot.android.sense.event.streams.activity.ActivityData;
|
||||||
import org.wso2.carbon.iot.android.sense.event.streams.application.ApplicationData;
|
import org.wso2.carbon.iot.android.sense.event.streams.application.ApplicationData;
|
||||||
import org.wso2.carbon.iot.android.sense.event.streams.audio.AudioData;
|
import org.wso2.carbon.iot.android.sense.event.streams.audio.AudioData;
|
||||||
import org.wso2.carbon.iot.android.sense.event.streams.battery.BatteryData;
|
import org.wso2.carbon.iot.android.sense.event.streams.battery.BatteryData;
|
||||||
import org.wso2.carbon.iot.android.sense.event.streams.call.CallData;
|
import org.wso2.carbon.iot.android.sense.event.streams.call.CallData;
|
||||||
import org.wso2.carbon.iot.android.sense.event.streams.data.NetworkData;
|
import org.wso2.carbon.iot.android.sense.event.streams.data.NetworkData;
|
||||||
|
import org.wso2.carbon.iot.android.sense.event.streams.location.LocationData;
|
||||||
import org.wso2.carbon.iot.android.sense.event.streams.screen.ScreenData;
|
import org.wso2.carbon.iot.android.sense.event.streams.screen.ScreenData;
|
||||||
|
import org.wso2.carbon.iot.android.sense.event.streams.sensor.SensorData;
|
||||||
import org.wso2.carbon.iot.android.sense.event.streams.sms.SmsData;
|
import org.wso2.carbon.iot.android.sense.event.streams.sms.SmsData;
|
||||||
|
import org.wso2.carbon.iot.android.sense.event.streams.speed.SpeedData;
|
||||||
import org.wso2.carbon.iot.android.sense.speech.detector.util.ProcessWords;
|
import org.wso2.carbon.iot.android.sense.speech.detector.util.ProcessWords;
|
||||||
import org.wso2.carbon.iot.android.sense.speech.detector.util.WordData;
|
import org.wso2.carbon.iot.android.sense.speech.detector.util.WordData;
|
||||||
import org.wso2.carbon.iot.android.sense.util.LocalRegistry;
|
import org.wso2.carbon.iot.android.sense.util.LocalRegistry;
|
||||||
@ -65,257 +64,250 @@ public class DataPublisherService extends Service {
|
|||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
context = this;
|
context = this;
|
||||||
Log.d(TAG, "service started");
|
Log.d(TAG, "service started");
|
||||||
// Runnable runnable = new Runnable() {
|
try {
|
||||||
// @Override
|
List<Event> events = new ArrayList<>();
|
||||||
// public void run() {
|
//retrieve sensor data.
|
||||||
try {
|
List<SensorData> sensorDataMap = SenseDataHolder.getSensorDataHolder();
|
||||||
List<Event> events = new ArrayList<>();
|
if (!sensorDataMap.isEmpty()) {
|
||||||
//retrieve sensor data.
|
for (SensorData sensorData : sensorDataMap) {
|
||||||
List<SensorData> sensorDataMap = SenseDataHolder.getSensorDataHolder();
|
Event event = new Event();
|
||||||
if (!sensorDataMap.isEmpty()) {
|
event.setTimestamp(sensorData.getTimestamp());
|
||||||
for (SensorData sensorData : sensorDataMap) {
|
switch (sensorData.getSensorType()) {
|
||||||
Event event = new Event();
|
case Sensor.TYPE_ACCELEROMETER:
|
||||||
event.setTimestamp(sensorData.getTimestamp());
|
event.setAccelerometer(sensorData.getSensorValues());
|
||||||
switch (sensorData.getSensorType()) {
|
|
||||||
case Sensor.TYPE_ACCELEROMETER:
|
|
||||||
event.setAccelerometer(sensorData.getSensorValues());
|
|
||||||
events.add(event);
|
|
||||||
break;
|
|
||||||
case Sensor.TYPE_MAGNETIC_FIELD:
|
|
||||||
event.setMagnetic(sensorData.getSensorValues());
|
|
||||||
events.add(event);
|
|
||||||
break;
|
|
||||||
case Sensor.TYPE_GYROSCOPE:
|
|
||||||
event.setGyroscope(sensorData.getSensorValues());
|
|
||||||
events.add(event);
|
|
||||||
break;
|
|
||||||
case Sensor.TYPE_LIGHT:
|
|
||||||
event.setLight(sensorData.getSensorValues()[0]);
|
|
||||||
break;
|
|
||||||
case Sensor.TYPE_PRESSURE:
|
|
||||||
event.setPressure(sensorData.getSensorValues()[0]);
|
|
||||||
events.add(event);
|
|
||||||
break;
|
|
||||||
case Sensor.TYPE_PROXIMITY:
|
|
||||||
event.setProximity(sensorData.getSensorValues()[0]);
|
|
||||||
events.add(event);
|
|
||||||
break;
|
|
||||||
case Sensor.TYPE_GRAVITY:
|
|
||||||
event.setGravity(sensorData.getSensorValues());
|
|
||||||
events.add(event);
|
|
||||||
break;
|
|
||||||
case Sensor.TYPE_GAME_ROTATION_VECTOR:
|
|
||||||
event.setRotation(sensorData.getSensorValues());
|
|
||||||
events.add(event);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SenseDataHolder.resetSensorDataHolder();
|
|
||||||
|
|
||||||
//retrieve battery data.
|
|
||||||
List<BatteryData> batteryDataMap = SenseDataHolder.getBatteryDataHolder();
|
|
||||||
if (!batteryDataMap.isEmpty()) {
|
|
||||||
for (BatteryData batteryData : batteryDataMap) {
|
|
||||||
Event event = new Event();
|
|
||||||
event.setTimestamp(batteryData.getTimestamp());
|
|
||||||
event.setBattery(batteryData.getLevel());
|
|
||||||
event.setBatteryTemperature(batteryData.getTemperature());
|
|
||||||
event.setBatteryStatus(batteryData.getStatus());
|
|
||||||
event.setBatteryState(batteryData.getState().toString());
|
|
||||||
events.add(event);
|
events.add(event);
|
||||||
}
|
break;
|
||||||
}
|
case Sensor.TYPE_MAGNETIC_FIELD:
|
||||||
SenseDataHolder.resetBatteryDataHolder();
|
event.setMagnetic(sensorData.getSensorValues());
|
||||||
|
|
||||||
//retrieve location data.
|
|
||||||
List<LocationData> locationDataMap = SenseDataHolder.getLocationDataHolder();
|
|
||||||
|
|
||||||
if (!locationDataMap.isEmpty()) {
|
|
||||||
for (LocationData locationData : locationDataMap) {
|
|
||||||
Event event = new Event();
|
|
||||||
event.setTimestamp(locationData.getTimeStamp());
|
|
||||||
event.setGps(new double[]{locationData.getLatitude(), locationData.getLongitude()});
|
|
||||||
events.add(event);
|
events.add(event);
|
||||||
}
|
break;
|
||||||
}
|
case Sensor.TYPE_GYROSCOPE:
|
||||||
SenseDataHolder.resetLocationDataHolder();
|
event.setGyroscope(sensorData.getSensorValues());
|
||||||
|
|
||||||
//retrieve speed data.
|
|
||||||
List<SpeedData> speedDataMap = SenseDataHolder.getSpeedDataHolder();
|
|
||||||
if (!speedDataMap.isEmpty()) {
|
|
||||||
for (SpeedData speedData : speedDataMap) {
|
|
||||||
Event event = new Event();
|
|
||||||
event.setTimestamp(speedData.getTimeStamp());
|
|
||||||
event.setTurns(speedData.getTurns());
|
|
||||||
event.setSpeed(speedData.getSpeed());
|
|
||||||
|
|
||||||
events.add(event);
|
events.add(event);
|
||||||
}
|
break;
|
||||||
}
|
case Sensor.TYPE_LIGHT:
|
||||||
SenseDataHolder.resetSpeedDataHolder();
|
event.setLight(sensorData.getSensorValues()[0]);
|
||||||
|
break;
|
||||||
//retrieve speed data.
|
case Sensor.TYPE_PRESSURE:
|
||||||
List<BeaconScanedData> beaconDataMap = SenseDataHolder.getBeaconScanedDataHolder();
|
event.setPressure(sensorData.getSensorValues()[0]);
|
||||||
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);
|
events.add(event);
|
||||||
}
|
break;
|
||||||
}
|
case Sensor.TYPE_PROXIMITY:
|
||||||
SenseDataHolder.resetSpeedDataHolder();
|
event.setProximity(sensorData.getSensorValues()[0]);
|
||||||
|
|
||||||
//retrieve words
|
|
||||||
ProcessWords.cleanAndPushToWordMap();
|
|
||||||
List<WordData> wordDatMap = SenseDataHolder.getWordDataHolder();
|
|
||||||
for (WordData wordData : wordDatMap) {
|
|
||||||
if (wordData.getOccurences() == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < wordData.getOccurences(); i++) {
|
|
||||||
Event event = new Event();
|
|
||||||
event.setTimestamp(wordData.getTimestamp());
|
|
||||||
event.setWord(wordData.getWord());
|
|
||||||
String word = wordData.getWord();
|
|
||||||
String status = word;
|
|
||||||
if ((!word.equals(SenseConstants.EVENT_LISTENER_STARTED)) && (!word.equals(SenseConstants
|
|
||||||
.EVENT_LISTENER_FINISHED))) {
|
|
||||||
status = SenseConstants.EVENT_LISTENER_ONGOING;
|
|
||||||
}
|
|
||||||
event.setWordStatus(status);
|
|
||||||
events.add(event);
|
events.add(event);
|
||||||
}
|
break;
|
||||||
}
|
case Sensor.TYPE_GRAVITY:
|
||||||
SenseDataHolder.resetWordDataHolder();
|
event.setGravity(sensorData.getSensorValues());
|
||||||
|
|
||||||
// retrieve call data.
|
|
||||||
List<CallData> callDataList = SenseDataHolder.getCallDataHolder();
|
|
||||||
if (!callDataList.isEmpty()) {
|
|
||||||
for (CallData callData : callDataList) {
|
|
||||||
Event event = new Event();
|
|
||||||
event.setCallNumber(callData.getPhoneNumber());
|
|
||||||
event.setCallType(callData.getType().toString().toLowerCase());
|
|
||||||
event.setCallStartTime(callData.getStartTime());
|
|
||||||
event.setCallEndTime(callData.getEndTime());
|
|
||||||
event.setTimestamp(callData.getStartTime());
|
|
||||||
|
|
||||||
events.add(event);
|
events.add(event);
|
||||||
}
|
break;
|
||||||
}
|
case Sensor.TYPE_GAME_ROTATION_VECTOR:
|
||||||
SenseDataHolder.resetCallDataHolder();
|
event.setRotation(sensorData.getSensorValues());
|
||||||
|
|
||||||
// retrieve screen data.
|
|
||||||
List<ScreenData> screenDataList = SenseDataHolder.getScreenDataHolder();
|
|
||||||
if (!screenDataList.isEmpty()) {
|
|
||||||
for (ScreenData screenData : screenDataList) {
|
|
||||||
Event event = new Event();
|
|
||||||
event.setScreenState(screenData.getAction());
|
|
||||||
event.setTimestamp(screenData.getTimestamp());
|
|
||||||
|
|
||||||
events.add(event);
|
events.add(event);
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
SenseDataHolder.resetScreenDataHolder();
|
|
||||||
|
|
||||||
// retrieve audio data.
|
|
||||||
List<AudioData> audioDataList = SenseDataHolder.getAudioDataHolder();
|
|
||||||
if (!audioDataList.isEmpty()) {
|
|
||||||
for (AudioData audioData : audioDataList) {
|
|
||||||
Event event = new Event();
|
|
||||||
event.setTimestamp(audioData.getTimestamp());
|
|
||||||
event.setAudioPlaying(audioData.isPlaying());
|
|
||||||
event.setHeadsetOn(audioData.isHeadsetOn());
|
|
||||||
event.setMusicVolume(audioData.getMusicVolume());
|
|
||||||
events.add(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SenseDataHolder.resetAudioDataHolder();
|
|
||||||
|
|
||||||
// retrieve activity data.
|
|
||||||
List<ActivityData> activityDataList = SenseDataHolder.getActivityDataHolder();
|
|
||||||
if (!activityDataList.isEmpty()) {
|
|
||||||
for (ActivityData activityData : activityDataList) {
|
|
||||||
Event event = new Event();
|
|
||||||
event.setTimestamp(activityData.getTimestamp());
|
|
||||||
event.setActivityType(activityData.getActivity());
|
|
||||||
event.setConfidence(activityData.getConfidence());
|
|
||||||
events.add(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SenseDataHolder.resetActivityDataHolder();
|
|
||||||
|
|
||||||
// retrieve sms data.
|
|
||||||
List<SmsData> smsDataList = SenseDataHolder.getSmsDataHolder();
|
|
||||||
if (!smsDataList.isEmpty()) {
|
|
||||||
for (SmsData smsData : smsDataList) {
|
|
||||||
Event event = new Event();
|
|
||||||
event.setTimestamp(smsData.getTimestamp());
|
|
||||||
event.setSmsNumber(smsData.getPhoneNumber());
|
|
||||||
events.add(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SenseDataHolder.resetSmsDataHolder();
|
|
||||||
|
|
||||||
|
|
||||||
// retrieve application data.
|
|
||||||
List<ApplicationData> appDataList = SenseDataHolder.getApplicationDataHolder();
|
|
||||||
if (!appDataList.isEmpty()) {
|
|
||||||
for (ApplicationData appData : appDataList) {
|
|
||||||
Event event = new Event();
|
|
||||||
event.setTimestamp(appData.getTimestamp());
|
|
||||||
event.setPackageName(appData.getPackageName());
|
|
||||||
event.setAction(appData.getAction().toString());
|
|
||||||
events.add(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SenseDataHolder.resetApplicationDataHolder();
|
|
||||||
|
|
||||||
//Retrieve network data
|
|
||||||
List<NetworkData> networkDataList = SenseDataHolder.getNetworkDataHolder();
|
|
||||||
if (!networkDataList.isEmpty()) {
|
|
||||||
for (NetworkData networkData : networkDataList) {
|
|
||||||
Event event = new Event();
|
|
||||||
event.setTimestamp(networkData.getTimeStamp());
|
|
||||||
event.setDataType(networkData.getDataType());
|
|
||||||
event.setDataReceived(networkData.getDataReceived());
|
|
||||||
event.setDataSent(networkData.getDataSent());
|
|
||||||
events.add(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SenseDataHolder.resetNetworkDataHolder();
|
|
||||||
|
|
||||||
//publish the data
|
|
||||||
if (events.size() > 0 && LocalRegistry.isEnrolled(context)) {
|
|
||||||
String user = LocalRegistry.getUsername(context);
|
|
||||||
String deviceId = LocalRegistry.getDeviceId(context);
|
|
||||||
JSONArray jsonArray = new JSONArray();
|
|
||||||
for (Event event : events) {
|
|
||||||
event.setOwner(user);
|
|
||||||
event.setDeviceId(deviceId);
|
|
||||||
jsonArray.put(new JSONObject().put("event", event.getEvent()));
|
|
||||||
}
|
|
||||||
|
|
||||||
MQTTTransportHandler mqttTransportHandler = AndroidSenseMQTTHandler.getInstance(context);
|
|
||||||
if (!mqttTransportHandler.isConnected()) {
|
|
||||||
mqttTransportHandler.connect();
|
|
||||||
}
|
|
||||||
String topic = LocalRegistry.getTenantDomain(context) + "/" + SenseConstants.DEVICE_TYPE + "/" + deviceId + "/data";
|
|
||||||
mqttTransportHandler.publishDeviceData(user, deviceId, jsonArray.toString(), topic);
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Log.e(TAG, "Json Data Parsing Exception", e);
|
|
||||||
} catch (TransportHandlerException e) {
|
|
||||||
Log.e(TAG, "Data Publish Failed", e);
|
|
||||||
}
|
}
|
||||||
// }
|
}
|
||||||
// };
|
SenseDataHolder.resetSensorDataHolder();
|
||||||
// Thread dataUploaderThread = new Thread(runnable);
|
|
||||||
// dataUploaderThread.start();
|
//retrieve battery data.
|
||||||
|
List<BatteryData> batteryDataMap = SenseDataHolder.getBatteryDataHolder();
|
||||||
|
if (!batteryDataMap.isEmpty()) {
|
||||||
|
for (BatteryData batteryData : batteryDataMap) {
|
||||||
|
Event event = new Event();
|
||||||
|
event.setTimestamp(batteryData.getTimestamp());
|
||||||
|
event.setBattery(batteryData.getLevel());
|
||||||
|
event.setBatteryTemperature(batteryData.getTemperature());
|
||||||
|
event.setBatteryStatus(batteryData.getStatus());
|
||||||
|
event.setBatteryState(batteryData.getState().toString());
|
||||||
|
events.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SenseDataHolder.resetBatteryDataHolder();
|
||||||
|
|
||||||
|
//retrieve location data.
|
||||||
|
List<LocationData> locationDataMap = SenseDataHolder.getLocationDataHolder();
|
||||||
|
|
||||||
|
if (!locationDataMap.isEmpty()) {
|
||||||
|
for (LocationData locationData : locationDataMap) {
|
||||||
|
Event event = new Event();
|
||||||
|
event.setTimestamp(locationData.getTimeStamp());
|
||||||
|
event.setGps(new double[]{locationData.getLatitude(), locationData.getLongitude()});
|
||||||
|
events.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SenseDataHolder.resetLocationDataHolder();
|
||||||
|
|
||||||
|
//retrieve speed data.
|
||||||
|
List<SpeedData> speedDataMap = SenseDataHolder.getSpeedDataHolder();
|
||||||
|
if (!speedDataMap.isEmpty()) {
|
||||||
|
for (SpeedData speedData : speedDataMap) {
|
||||||
|
Event event = new Event();
|
||||||
|
event.setTimestamp(speedData.getTimeStamp());
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SenseDataHolder.resetSpeedDataHolder();
|
||||||
|
|
||||||
|
//retrieve words
|
||||||
|
ProcessWords.cleanAndPushToWordMap();
|
||||||
|
List<WordData> wordDatMap = SenseDataHolder.getWordDataHolder();
|
||||||
|
for (WordData wordData : wordDatMap) {
|
||||||
|
if (wordData.getOccurences() == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < wordData.getOccurences(); i++) {
|
||||||
|
Event event = new Event();
|
||||||
|
event.setTimestamp(wordData.getTimestamp());
|
||||||
|
event.setWord(wordData.getWord());
|
||||||
|
String word = wordData.getWord();
|
||||||
|
String status = word;
|
||||||
|
if ((!word.equals(SenseConstants.EVENT_LISTENER_STARTED)) && (!word.equals(SenseConstants
|
||||||
|
.EVENT_LISTENER_FINISHED))) {
|
||||||
|
status = SenseConstants.EVENT_LISTENER_ONGOING;
|
||||||
|
}
|
||||||
|
event.setWordStatus(status);
|
||||||
|
events.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SenseDataHolder.resetWordDataHolder();
|
||||||
|
|
||||||
|
// retrieve call data.
|
||||||
|
List<CallData> callDataList = SenseDataHolder.getCallDataHolder();
|
||||||
|
if (!callDataList.isEmpty()) {
|
||||||
|
for (CallData callData : callDataList) {
|
||||||
|
Event event = new Event();
|
||||||
|
event.setCallNumber(callData.getPhoneNumber());
|
||||||
|
event.setCallType(callData.getType().toString().toLowerCase());
|
||||||
|
event.setCallStartTime(callData.getStartTime());
|
||||||
|
event.setCallEndTime(callData.getEndTime());
|
||||||
|
event.setTimestamp(callData.getStartTime());
|
||||||
|
|
||||||
|
events.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SenseDataHolder.resetCallDataHolder();
|
||||||
|
|
||||||
|
// retrieve screen data.
|
||||||
|
List<ScreenData> screenDataList = SenseDataHolder.getScreenDataHolder();
|
||||||
|
if (!screenDataList.isEmpty()) {
|
||||||
|
for (ScreenData screenData : screenDataList) {
|
||||||
|
Event event = new Event();
|
||||||
|
event.setScreenState(screenData.getAction());
|
||||||
|
event.setTimestamp(screenData.getTimestamp());
|
||||||
|
|
||||||
|
events.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SenseDataHolder.resetScreenDataHolder();
|
||||||
|
|
||||||
|
// retrieve audio data.
|
||||||
|
List<AudioData> audioDataList = SenseDataHolder.getAudioDataHolder();
|
||||||
|
if (!audioDataList.isEmpty()) {
|
||||||
|
for (AudioData audioData : audioDataList) {
|
||||||
|
Event event = new Event();
|
||||||
|
event.setTimestamp(audioData.getTimestamp());
|
||||||
|
event.setAudioPlaying(audioData.isPlaying());
|
||||||
|
event.setHeadsetOn(audioData.isHeadsetOn());
|
||||||
|
event.setMusicVolume(audioData.getMusicVolume());
|
||||||
|
events.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SenseDataHolder.resetAudioDataHolder();
|
||||||
|
|
||||||
|
// retrieve activity data.
|
||||||
|
List<ActivityData> activityDataList = SenseDataHolder.getActivityDataHolder();
|
||||||
|
if (!activityDataList.isEmpty()) {
|
||||||
|
for (ActivityData activityData : activityDataList) {
|
||||||
|
Event event = new Event();
|
||||||
|
event.setTimestamp(activityData.getTimestamp());
|
||||||
|
event.setActivityType(activityData.getActivity());
|
||||||
|
event.setConfidence(activityData.getConfidence());
|
||||||
|
events.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SenseDataHolder.resetActivityDataHolder();
|
||||||
|
|
||||||
|
// retrieve sms data.
|
||||||
|
List<SmsData> smsDataList = SenseDataHolder.getSmsDataHolder();
|
||||||
|
if (!smsDataList.isEmpty()) {
|
||||||
|
for (SmsData smsData : smsDataList) {
|
||||||
|
Event event = new Event();
|
||||||
|
event.setTimestamp(smsData.getTimestamp());
|
||||||
|
event.setSmsNumber(smsData.getPhoneNumber());
|
||||||
|
events.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SenseDataHolder.resetSmsDataHolder();
|
||||||
|
|
||||||
|
|
||||||
|
// retrieve application data.
|
||||||
|
List<ApplicationData> appDataList = SenseDataHolder.getApplicationDataHolder();
|
||||||
|
if (!appDataList.isEmpty()) {
|
||||||
|
for (ApplicationData appData : appDataList) {
|
||||||
|
Event event = new Event();
|
||||||
|
event.setTimestamp(appData.getTimestamp());
|
||||||
|
event.setPackageName(appData.getPackageName());
|
||||||
|
event.setAction(appData.getAction().toString());
|
||||||
|
events.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SenseDataHolder.resetApplicationDataHolder();
|
||||||
|
|
||||||
|
//Retrieve network data
|
||||||
|
List<NetworkData> networkDataList = SenseDataHolder.getNetworkDataHolder();
|
||||||
|
if (!networkDataList.isEmpty()) {
|
||||||
|
for (NetworkData networkData : networkDataList) {
|
||||||
|
Event event = new Event();
|
||||||
|
event.setTimestamp(networkData.getTimeStamp());
|
||||||
|
event.setDataType(networkData.getDataType());
|
||||||
|
event.setDataReceived(networkData.getDataReceived());
|
||||||
|
event.setDataSent(networkData.getDataSent());
|
||||||
|
events.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SenseDataHolder.resetNetworkDataHolder();
|
||||||
|
|
||||||
|
//publish the data
|
||||||
|
if (events.size() > 0 && LocalRegistry.isEnrolled(context)) {
|
||||||
|
String user = LocalRegistry.getUsername(context);
|
||||||
|
String deviceId = LocalRegistry.getDeviceId(context);
|
||||||
|
JSONArray jsonArray = new JSONArray();
|
||||||
|
for (Event event : events) {
|
||||||
|
event.setOwner(user);
|
||||||
|
event.setDeviceId(deviceId);
|
||||||
|
jsonArray.put(new JSONObject().put("event", event.getEvent()));
|
||||||
|
}
|
||||||
|
|
||||||
|
MQTTTransportHandler mqttTransportHandler = AndroidSenseMQTTHandler.getInstance(context);
|
||||||
|
if (!mqttTransportHandler.isConnected()) {
|
||||||
|
mqttTransportHandler.connect();
|
||||||
|
}
|
||||||
|
String topic = LocalRegistry.getTenantDomain(context) + "/" + SenseConstants.DEVICE_TYPE + "/" + deviceId + "/data";
|
||||||
|
mqttTransportHandler.publishDeviceData(user, deviceId, jsonArray.toString(), topic);
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.e(TAG, "Json Data Parsing Exception", e);
|
||||||
|
} catch (TransportHandlerException e) {
|
||||||
|
Log.e(TAG, "Data Publish Failed", e);
|
||||||
|
}
|
||||||
return Service.START_NOT_STICKY;
|
return Service.START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -552,5 +552,4 @@ public class Event {
|
|||||||
|
|
||||||
return jsonEvent;
|
return jsonEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -236,6 +236,5 @@ public class AndroidSenseMQTTHandler extends MQTTTransportHandler {
|
|||||||
public void processIncomingMessage(MqttMessage message) throws TransportHandlerException {
|
public void processIncomingMessage(MqttMessage message) throws TransportHandlerException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -38,5 +38,4 @@ public class SenseScheduleReceiver extends BroadcastReceiver {
|
|||||||
cal.add(Calendar.SECOND, 10);
|
cal.add(Calendar.SECOND, 10);
|
||||||
service.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), ALARM_INTERVAL, pending);
|
service.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), ALARM_INTERVAL, pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,7 +59,6 @@ public class SenseService extends Service {
|
|||||||
SenseDataReceiverManager.registerNetworkDataReader(this);
|
SenseDataReceiverManager.registerNetworkDataReader(this);
|
||||||
//service will not be stopped until we manually stop the service
|
//service will not be stopped until we manually stop the service
|
||||||
return Service.START_NOT_STICKY;
|
return Service.START_NOT_STICKY;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -25,7 +25,6 @@ import android.net.TrafficStats;
|
|||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.wso2.carbon.iot.android.sense.util.SenseDataHolder;
|
import org.wso2.carbon.iot.android.sense.util.SenseDataHolder;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|||||||
@ -56,7 +56,6 @@ public class SensorDataReader extends DataReader implements SensorEventListener
|
|||||||
for (Sensor sensor : sensorList) {
|
for (Sensor sensor : sensorList) {
|
||||||
mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
|
mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void collectSensorData() {
|
private void collectSensorData() {
|
||||||
@ -112,5 +111,4 @@ public class SensorDataReader extends DataReader implements SensorEventListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -73,7 +73,6 @@ public class ActivitySelectSensor extends AppCompatActivity
|
|||||||
private ListView listView;
|
private ListView listView;
|
||||||
private SensorManager sensorManager;
|
private SensorManager sensorManager;
|
||||||
private ArrayList<Sensor> sensors = new ArrayList<>();
|
private ArrayList<Sensor> sensors = new ArrayList<>();
|
||||||
// private EditText sessionIdText;
|
|
||||||
private RealTimeSensorReader sensorReader = null;
|
private RealTimeSensorReader sensorReader = null;
|
||||||
private RealTimeSensorChangeReceiver realTimeSensorChangeReceiver = new RealTimeSensorChangeReceiver();
|
private RealTimeSensorChangeReceiver realTimeSensorChangeReceiver = new RealTimeSensorChangeReceiver();
|
||||||
private SupportedSensors supportedSensors = SupportedSensors.getInstance();
|
private SupportedSensors supportedSensors = SupportedSensors.getInstance();
|
||||||
@ -87,22 +86,10 @@ public class ActivitySelectSensor extends AppCompatActivity
|
|||||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
||||||
//sessionIdText = (EditText) findViewById(R.id.sessionId);
|
|
||||||
// sessionIdText.setCursorVisible(false);
|
|
||||||
|
|
||||||
listView = (ListView) findViewById(R.id.senseListContainer);
|
listView = (ListView) findViewById(R.id.senseListContainer);
|
||||||
//verifyBluetooth();
|
|
||||||
|
|
||||||
registerReceiver(realTimeSensorChangeReceiver, new IntentFilter("sensorDataMap"));
|
registerReceiver(realTimeSensorChangeReceiver, new IntentFilter("sensorDataMap"));
|
||||||
|
|
||||||
// sessionIdText.setOnClickListener(new View.OnClickListener() {
|
|
||||||
// @Override
|
|
||||||
// public void onClick(View v) {
|
|
||||||
// sessionIdText.setCursorVisible(true);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
//Publish data
|
//Publish data
|
||||||
FloatingActionButton fbtnPublishData = (FloatingActionButton) findViewById(R.id.publish);
|
FloatingActionButton fbtnPublishData = (FloatingActionButton) findViewById(R.id.publish);
|
||||||
|
|
||||||
@ -126,35 +113,6 @@ public class ActivitySelectSensor extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//FloatingActionButton fbtnSpeechRecongnizer = (FloatingActionButton) findViewById(R.id.speech);
|
|
||||||
// fbtnSpeechRecongnizer.setOnClickListener(new View.OnClickListener() {
|
|
||||||
// @Override
|
|
||||||
// public void onClick(View v) {
|
|
||||||
// String sessionId = sessionIdText.getText().toString();
|
|
||||||
// if (!sessionId.isEmpty()) {
|
|
||||||
// Intent intent = new Intent(getApplicationContext(), WordRecognitionActivity.class);
|
|
||||||
// intent.putExtra("sessionId", sessionId);
|
|
||||||
// startActivity(intent);
|
|
||||||
// } else {
|
|
||||||
// Toast.makeText(ActivitySelectSensor.this, "Please type a session id value", Toast.LENGTH_SHORT)
|
|
||||||
// .show();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// 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);
|
sharedPreferences = getSharedPreferences(SupportedSensors.SELECTED_SENSORS, 0);
|
||||||
|
|
||||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||||
@ -223,7 +181,6 @@ public class ActivitySelectSensor extends AppCompatActivity
|
|||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +229,6 @@ public class ActivitySelectSensor extends AppCompatActivity
|
|||||||
|
|
||||||
realTimeSensorChangeReceiver.updateOnChange(adaptor1);
|
realTimeSensorChangeReceiver.updateOnChange(adaptor1);
|
||||||
listView.setAdapter(adaptor1);
|
listView.setAdapter(adaptor1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
@ -305,51 +261,10 @@ public class ActivitySelectSensor extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method unregisters the real-time broadcast receiver.
|
* This method unregisters the real-time broadcast receiver.
|
||||||
*/
|
*/
|
||||||
public void unregisterReceivers() {
|
public void unregisterReceivers() {
|
||||||
unregisterReceiver(realTimeSensorChangeReceiver);
|
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();
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,5 +33,4 @@ public class TempStore {
|
|||||||
* Array List which is used to populate the List view.
|
* Array List which is used to populate the List view.
|
||||||
*/
|
*/
|
||||||
public static ArrayList<RealTimeSensor> sensorArrayList = new ArrayList<>();
|
public static ArrayList<RealTimeSensor> sensorArrayList = new ArrayList<>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,5 +37,4 @@ public class RealTimeSensorChangeReceiver extends BroadcastReceiver {
|
|||||||
TempStore.sensorArrayList.clear();
|
TempStore.sensorArrayList.clear();
|
||||||
TempStore.sensorArrayList.addAll(TempStore.sensorDataMap.values());
|
TempStore.sensorArrayList.addAll(TempStore.sensorDataMap.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,5 +58,4 @@ public class RealTimeSensorReader implements SensorEventListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,6 +60,4 @@ public class AvailableSensorsInDevice {
|
|||||||
editor.putStringSet(SupportedSensors.GET_AVAILABLE_SENSORS, sensorSet);
|
editor.putStringSet(SupportedSensors.GET_AVAILABLE_SENSORS, sensorSet);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -119,5 +119,4 @@ public class SupportedSensors {
|
|||||||
public String getType(int type) {
|
public String getType(int type) {
|
||||||
return typeSensorMap.get(type);
|
return typeSensorMap.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,7 +83,6 @@ public class SensorViewAdaptor extends BaseAdapter {
|
|||||||
holder.valuesZ.setText(data.getValueZ());
|
holder.valuesZ.setText(data.getValueZ());
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ViewHolder {
|
private class ViewHolder {
|
||||||
|
|||||||
@ -36,7 +36,6 @@ import java.util.Set;
|
|||||||
* Get the user selections
|
* Get the user selections
|
||||||
* Put them in to shared preferences
|
* Put them in to shared preferences
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class SelectSensorDialog extends DialogFragment {
|
public class SelectSensorDialog extends DialogFragment {
|
||||||
|
|
||||||
protected boolean[] selections = new boolean[SupportedSensors.SUPPORTED_SENSOR_COUNT];
|
protected boolean[] selections = new boolean[SupportedSensors.SUPPORTED_SENSOR_COUNT];
|
||||||
@ -79,7 +78,6 @@ public class SelectSensorDialog extends DialogFragment {
|
|||||||
Log.d("Click", "Ok");
|
Log.d("Click", "Ok");
|
||||||
//call sensorDataMap reading class
|
//call sensorDataMap reading class
|
||||||
sensorListListener.onDialogPositiveClick(SelectSensorDialog.this);
|
sensorListListener.onDialogPositiveClick(SelectSensorDialog.this);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -96,7 +94,6 @@ public class SelectSensorDialog extends DialogFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return builder.create();
|
return builder.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,5 +140,4 @@ public class SelectSensorDialog extends DialogFragment {
|
|||||||
public interface SensorListListener {
|
public interface SensorListListener {
|
||||||
void onDialogPositiveClick(SelectSensorDialog dialog);
|
void onDialogPositiveClick(SelectSensorDialog dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>androidsense-plugin</artifactId>
|
<artifactId>androidsense-plugin</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<Analytics>
|
<Analytics>
|
||||||
<Editable>true</Editable>
|
<Editable>true</Editable>
|
||||||
<Name>AndroidActivityScript</Name>
|
<Name>AndroidActivityScript</Name>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<Analytics>
|
<Analytics>
|
||||||
<Editable>true</Editable>
|
<Editable>true</Editable>
|
||||||
<Name>AndroidAudioScript</Name>
|
<Name>AndroidAudioScript</Name>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<Analytics>
|
<Analytics>
|
||||||
<Editable>true</Editable>
|
<Editable>true</Editable>
|
||||||
<Name>AndroidBatteryScript</Name>
|
<Name>AndroidBatteryScript</Name>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<Analytics>
|
<Analytics>
|
||||||
<Editable>true</Editable>
|
<Editable>true</Editable>
|
||||||
<Name>AndroidCallScript</Name>
|
<Name>AndroidCallScript</Name>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<Analytics>
|
<Analytics>
|
||||||
<Editable>true</Editable>
|
<Editable>true</Editable>
|
||||||
<Name>AndroidDataScript</Name>
|
<Name>AndroidDataScript</Name>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<Analytics>
|
<Analytics>
|
||||||
<Editable>true</Editable>
|
<Editable>true</Editable>
|
||||||
<Name>AndroidFrequentContactsScript</Name>
|
<Name>AndroidFrequentContactsScript</Name>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<Analytics>
|
<Analytics>
|
||||||
<Editable>true</Editable>
|
<Editable>true</Editable>
|
||||||
<Name>HeadsetScript</Name>
|
<Name>HeadsetScript</Name>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
<EventStoreConfiguration>
|
<EventStoreConfiguration>
|
||||||
<TableSchema>
|
<TableSchema>
|
||||||
<ColumnDefinition>
|
<ColumnDefinition>
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>androidsense-plugin</artifactId>
|
<artifactId>androidsense-plugin</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -32,10 +32,13 @@ import javax.servlet.ServletContextListener;
|
|||||||
public class AndroidSensePermissionUpdateListener implements ServletContextListener {
|
public class AndroidSensePermissionUpdateListener implements ServletContextListener {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(AndroidSensePermissionUpdateListener.class);
|
private static Log log = LogFactory.getLog(AndroidSensePermissionUpdateListener.class);
|
||||||
|
private static PrivilegedCarbonContext threadLocalCarbonContext;
|
||||||
|
private static RealmService realmService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
||||||
|
threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
realmService = (RealmService) threadLocalCarbonContext.getOSGiService(RealmService.class, null);
|
||||||
UserStoreManager userStoreManager = getUserStoreManager();
|
UserStoreManager userStoreManager = getUserStoreManager();
|
||||||
try {
|
try {
|
||||||
if (userStoreManager != null) {
|
if (userStoreManager != null) {
|
||||||
@ -47,7 +50,8 @@ public class AndroidSensePermissionUpdateListener implements ServletContextListe
|
|||||||
getAuthorizationManager().authorizeRole(AndroidSenseConstants.ROLE_NAME,
|
getAuthorizationManager().authorizeRole(AndroidSenseConstants.ROLE_NAME,
|
||||||
AndroidSenseConstants.PERM_OWNING_DEVICE_VIEW, CarbonConstants.UI_PERMISSION_ACTION);
|
AndroidSenseConstants.PERM_OWNING_DEVICE_VIEW, CarbonConstants.UI_PERMISSION_ACTION);
|
||||||
}
|
}
|
||||||
} } catch (UserStoreException e) {
|
}
|
||||||
|
} catch (UserStoreException e) {
|
||||||
log.error("Error while creating a role and adding a user for Android Sense.", e);
|
log.error("Error while creating a role and adding a user for Android Sense.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,57 +61,44 @@ public class AndroidSensePermissionUpdateListener implements ServletContextListe
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UserStoreManager getUserStoreManager() {
|
private UserStoreManager getUserStoreManager() {
|
||||||
RealmService realmService;
|
|
||||||
UserStoreManager userStoreManager;
|
UserStoreManager userStoreManager;
|
||||||
try {
|
try {
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
|
||||||
if (realmService == null) {
|
if (realmService == null) {
|
||||||
String msg = "Realm service has not initialized.";
|
String msg = "Realm service has not initialized.";
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
int tenantId = ctx.getTenantId();
|
int tenantId = threadLocalCarbonContext.getTenantId();
|
||||||
userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
|
userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
|
||||||
realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
String msg = "Error occurred while retrieving current user store manager";
|
String msg = "Error occurred while retrieving current user store manager";
|
||||||
log.error(msg, e);
|
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
return userStoreManager;
|
return userStoreManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AuthorizationManager getAuthorizationManager() {
|
private AuthorizationManager getAuthorizationManager() {
|
||||||
RealmService realmService;
|
|
||||||
AuthorizationManager authorizationManager;
|
AuthorizationManager authorizationManager;
|
||||||
try {
|
try {
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
|
||||||
if (realmService == null) {
|
if (realmService == null) {
|
||||||
String msg = "Realm service has not initialized.";
|
String msg = "Realm service has not initialized.";
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
int tenantId = ctx.getTenantId();
|
int tenantId = threadLocalCarbonContext.getTenantId();
|
||||||
authorizationManager = realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
authorizationManager = realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
String msg = "Error occurred while retrieving current user store manager";
|
String msg = "Error occurred while retrieving current user store manager";
|
||||||
log.error(msg, e);
|
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
return authorizationManager;
|
return authorizationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Permission[] getPermissions() {
|
private Permission[] getPermissions() {
|
||||||
|
Permission androidSense = new Permission(AndroidSenseConstants.PERM_ENROLL_ANDROID_SENSE,
|
||||||
Permission androidSense = new Permission(AndroidSenseConstants.PERM_ENROLL_ANDROID_SENSE,
|
CarbonConstants.UI_PERMISSION_ACTION);
|
||||||
CarbonConstants.UI_PERMISSION_ACTION);
|
Permission view = new Permission(AndroidSenseConstants.PERM_OWNING_DEVICE_VIEW,
|
||||||
Permission view = new Permission(AndroidSenseConstants.PERM_OWNING_DEVICE_VIEW, CarbonConstants
|
CarbonConstants.UI_PERMISSION_ACTION);
|
||||||
.UI_PERMISSION_ACTION);
|
return new Permission[]{androidSense, view};
|
||||||
|
|
||||||
return new Permission[]{androidSense, view};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>androidsense-plugin</artifactId>
|
<artifactId>androidsense-plugin</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>device-types</artifactId>
|
<artifactId>device-types</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>arduino-plugin</artifactId>
|
<artifactId>arduino-plugin</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>arduino-plugin</artifactId>
|
<artifactId>arduino-plugin</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -32,10 +32,13 @@ import javax.servlet.ServletContextListener;
|
|||||||
public class ArduinoPermissionUpdateListener implements ServletContextListener {
|
public class ArduinoPermissionUpdateListener implements ServletContextListener {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(ArduinoPermissionUpdateListener.class);
|
private static Log log = LogFactory.getLog(ArduinoPermissionUpdateListener.class);
|
||||||
|
private static PrivilegedCarbonContext threadLocalCarbonContext;
|
||||||
|
private static RealmService realmService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
||||||
|
threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
realmService = (RealmService) threadLocalCarbonContext.getOSGiService(RealmService.class, null);
|
||||||
UserStoreManager userStoreManager = getUserStoreManager();
|
UserStoreManager userStoreManager = getUserStoreManager();
|
||||||
try {
|
try {
|
||||||
if (userStoreManager != null) {
|
if (userStoreManager != null) {
|
||||||
@ -47,7 +50,8 @@ public class ArduinoPermissionUpdateListener implements ServletContextListener {
|
|||||||
getAuthorizationManager().authorizeRole(ArduinoConstants.ROLE_NAME,
|
getAuthorizationManager().authorizeRole(ArduinoConstants.ROLE_NAME,
|
||||||
ArduinoConstants.PERM_OWNING_DEVICE_VIEW, CarbonConstants.UI_PERMISSION_ACTION);
|
ArduinoConstants.PERM_OWNING_DEVICE_VIEW, CarbonConstants.UI_PERMISSION_ACTION);
|
||||||
}
|
}
|
||||||
} } catch (UserStoreException e) {
|
}
|
||||||
|
} catch (UserStoreException e) {
|
||||||
log.error("Error while creating a role and adding a user for Arduino.", e);
|
log.error("Error while creating a role and adding a user for Arduino.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,57 +61,44 @@ public class ArduinoPermissionUpdateListener implements ServletContextListener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UserStoreManager getUserStoreManager() {
|
private UserStoreManager getUserStoreManager() {
|
||||||
RealmService realmService;
|
|
||||||
UserStoreManager userStoreManager;
|
UserStoreManager userStoreManager;
|
||||||
try {
|
try {
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
|
||||||
if (realmService == null) {
|
if (realmService == null) {
|
||||||
String msg = "Realm service has not initialized.";
|
String msg = "Realm service has not initialized.";
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
int tenantId = ctx.getTenantId();
|
int tenantId = threadLocalCarbonContext.getTenantId();
|
||||||
userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
|
userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
|
||||||
realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
String msg = "Error occurred while retrieving current user store manager";
|
String msg = "Error occurred while retrieving current user store manager";
|
||||||
log.error(msg, e);
|
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
return userStoreManager;
|
return userStoreManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AuthorizationManager getAuthorizationManager() {
|
private AuthorizationManager getAuthorizationManager() {
|
||||||
RealmService realmService;
|
|
||||||
AuthorizationManager authorizationManager;
|
AuthorizationManager authorizationManager;
|
||||||
try {
|
try {
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
|
||||||
if (realmService == null) {
|
if (realmService == null) {
|
||||||
String msg = "Realm service has not initialized.";
|
String msg = "Realm service has not initialized.";
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
int tenantId = ctx.getTenantId();
|
int tenantId = threadLocalCarbonContext.getTenantId();
|
||||||
authorizationManager = realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
authorizationManager = realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
String msg = "Error occurred while retrieving current user store manager";
|
String msg = "Error occurred while retrieving current user store manager";
|
||||||
log.error(msg, e);
|
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
return authorizationManager;
|
return authorizationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Permission[] getPermissions() {
|
private Permission[] getPermissions() {
|
||||||
|
Permission androidSense = new Permission(ArduinoConstants.PERM_ENROLL_ARDUINO,
|
||||||
Permission androidSense = new Permission(ArduinoConstants.PERM_ENROLL_ARDUINO,
|
CarbonConstants.UI_PERMISSION_ACTION);
|
||||||
CarbonConstants.UI_PERMISSION_ACTION);
|
Permission view = new Permission(ArduinoConstants.PERM_OWNING_DEVICE_VIEW,
|
||||||
Permission view = new Permission(ArduinoConstants.PERM_OWNING_DEVICE_VIEW, CarbonConstants
|
CarbonConstants.UI_PERMISSION_ACTION);
|
||||||
.UI_PERMISSION_ACTION);
|
return new Permission[]{androidSense, view};
|
||||||
|
|
||||||
return new Permission[]{androidSense, view};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>arduino-plugin</artifactId>
|
<artifactId>arduino-plugin</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>device-types</artifactId>
|
<artifactId>device-types</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>carbon-device-mgt-plugins-parent</artifactId>
|
<artifactId>carbon-device-mgt-plugins-parent</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>raspberrypi-plugin</artifactId>
|
<artifactId>raspberrypi-plugin</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>raspberrypi-plugin</artifactId>
|
<artifactId>raspberrypi-plugin</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -32,10 +32,13 @@ import javax.servlet.ServletContextListener;
|
|||||||
public class RaspberryPIPermissionUpdateListener implements ServletContextListener {
|
public class RaspberryPIPermissionUpdateListener implements ServletContextListener {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(RaspberryPIPermissionUpdateListener.class);
|
private static Log log = LogFactory.getLog(RaspberryPIPermissionUpdateListener.class);
|
||||||
|
private static PrivilegedCarbonContext threadLocalCarbonContext;
|
||||||
|
private static RealmService realmService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
||||||
|
threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
realmService = (RealmService) threadLocalCarbonContext.getOSGiService(RealmService.class, null);
|
||||||
UserStoreManager userStoreManager = getUserStoreManager();
|
UserStoreManager userStoreManager = getUserStoreManager();
|
||||||
try {
|
try {
|
||||||
if (userStoreManager != null) {
|
if (userStoreManager != null) {
|
||||||
@ -47,7 +50,8 @@ public class RaspberryPIPermissionUpdateListener implements ServletContextListen
|
|||||||
getAuthorizationManager().authorizeRole(RaspberrypiConstants.ROLE_NAME,
|
getAuthorizationManager().authorizeRole(RaspberrypiConstants.ROLE_NAME,
|
||||||
RaspberrypiConstants.PERM_OWNING_DEVICE_VIEW, CarbonConstants.UI_PERMISSION_ACTION);
|
RaspberrypiConstants.PERM_OWNING_DEVICE_VIEW, CarbonConstants.UI_PERMISSION_ACTION);
|
||||||
}
|
}
|
||||||
} } catch (UserStoreException e) {
|
}
|
||||||
|
} catch (UserStoreException e) {
|
||||||
log.error("Error while creating a role and adding a user for Raspberry PI.", e);
|
log.error("Error while creating a role and adding a user for Raspberry PI.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,57 +61,44 @@ public class RaspberryPIPermissionUpdateListener implements ServletContextListen
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UserStoreManager getUserStoreManager() {
|
private UserStoreManager getUserStoreManager() {
|
||||||
RealmService realmService;
|
|
||||||
UserStoreManager userStoreManager;
|
UserStoreManager userStoreManager;
|
||||||
try {
|
try {
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
|
||||||
if (realmService == null) {
|
if (realmService == null) {
|
||||||
String msg = "Realm service has not initialized.";
|
String msg = "Realm service has not initialized.";
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
int tenantId = ctx.getTenantId();
|
int tenantId = threadLocalCarbonContext.getTenantId();
|
||||||
userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
|
userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
|
||||||
realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
String msg = "Error occurred while retrieving current user store manager";
|
String msg = "Error occurred while retrieving current user store manager";
|
||||||
log.error(msg, e);
|
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
return userStoreManager;
|
return userStoreManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AuthorizationManager getAuthorizationManager() {
|
private AuthorizationManager getAuthorizationManager() {
|
||||||
RealmService realmService;
|
|
||||||
AuthorizationManager authorizationManager;
|
AuthorizationManager authorizationManager;
|
||||||
try {
|
try {
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
|
||||||
if (realmService == null) {
|
if (realmService == null) {
|
||||||
String msg = "Realm service has not initialized.";
|
String msg = "Realm service has not initialized.";
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
int tenantId = ctx.getTenantId();
|
int tenantId = threadLocalCarbonContext.getTenantId();
|
||||||
authorizationManager = realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
authorizationManager = realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
String msg = "Error occurred while retrieving current user store manager";
|
String msg = "Error occurred while retrieving current user store manager";
|
||||||
log.error(msg, e);
|
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
return authorizationManager;
|
return authorizationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Permission[] getPermissions() {
|
private Permission[] getPermissions() {
|
||||||
|
Permission androidSense = new Permission(RaspberrypiConstants.PERM_ENROLL_RASPBERRYPI,
|
||||||
Permission androidSense = new Permission(RaspberrypiConstants.PERM_ENROLL_RASPBERRYPI,
|
CarbonConstants.UI_PERMISSION_ACTION);
|
||||||
CarbonConstants.UI_PERMISSION_ACTION);
|
Permission view = new Permission(RaspberrypiConstants.PERM_OWNING_DEVICE_VIEW,
|
||||||
Permission view = new Permission(RaspberrypiConstants.PERM_OWNING_DEVICE_VIEW, CarbonConstants
|
CarbonConstants.UI_PERMISSION_ACTION);
|
||||||
.UI_PERMISSION_ACTION);
|
return new Permission[]{androidSense, view};
|
||||||
|
|
||||||
return new Permission[]{androidSense, view};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>raspberrypi-plugin</artifactId>
|
<artifactId>raspberrypi-plugin</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>device-types</artifactId>
|
<artifactId>device-types</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>virtual-fire-alarm-plugin</artifactId>
|
<artifactId>virtual-fire-alarm-plugin</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>virtual-fire-alarm-plugin</artifactId>
|
<artifactId>virtual-fire-alarm-plugin</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>virtual-fire-alarm-plugin</artifactId>
|
<artifactId>virtual-fire-alarm-plugin</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -32,10 +32,13 @@ import javax.servlet.ServletContextListener;
|
|||||||
public class VirtualFireAlarmPermissionUpdateListener implements ServletContextListener {
|
public class VirtualFireAlarmPermissionUpdateListener implements ServletContextListener {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(VirtualFireAlarmPermissionUpdateListener.class);
|
private static Log log = LogFactory.getLog(VirtualFireAlarmPermissionUpdateListener.class);
|
||||||
|
private static PrivilegedCarbonContext threadLocalCarbonContext;
|
||||||
|
private static RealmService realmService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
||||||
|
threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
realmService = (RealmService) threadLocalCarbonContext.getOSGiService(RealmService.class, null);
|
||||||
UserStoreManager userStoreManager = getUserStoreManager();
|
UserStoreManager userStoreManager = getUserStoreManager();
|
||||||
try {
|
try {
|
||||||
if (userStoreManager != null) {
|
if (userStoreManager != null) {
|
||||||
@ -47,7 +50,8 @@ public class VirtualFireAlarmPermissionUpdateListener implements ServletContextL
|
|||||||
getAuthorizationManager().authorizeRole(VirtualFireAlarmConstants.ROLE_NAME,
|
getAuthorizationManager().authorizeRole(VirtualFireAlarmConstants.ROLE_NAME,
|
||||||
VirtualFireAlarmConstants.PERM_OWNING_DEVICE_VIEW, CarbonConstants.UI_PERMISSION_ACTION);
|
VirtualFireAlarmConstants.PERM_OWNING_DEVICE_VIEW, CarbonConstants.UI_PERMISSION_ACTION);
|
||||||
}
|
}
|
||||||
} } catch (UserStoreException e) {
|
}
|
||||||
|
} catch (UserStoreException e) {
|
||||||
log.error("Error while creating a role and adding a user for Raspberry PI.", e);
|
log.error("Error while creating a role and adding a user for Raspberry PI.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,57 +61,44 @@ public class VirtualFireAlarmPermissionUpdateListener implements ServletContextL
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UserStoreManager getUserStoreManager() {
|
private UserStoreManager getUserStoreManager() {
|
||||||
RealmService realmService;
|
|
||||||
UserStoreManager userStoreManager;
|
UserStoreManager userStoreManager;
|
||||||
try {
|
try {
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
|
||||||
if (realmService == null) {
|
if (realmService == null) {
|
||||||
String msg = "Realm service has not initialized.";
|
String msg = "Realm service has not initialized.";
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
int tenantId = ctx.getTenantId();
|
int tenantId = threadLocalCarbonContext.getTenantId();
|
||||||
userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
|
userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
|
||||||
realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
String msg = "Error occurred while retrieving current user store manager";
|
String msg = "Error occurred while retrieving current user store manager";
|
||||||
log.error(msg, e);
|
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
return userStoreManager;
|
return userStoreManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AuthorizationManager getAuthorizationManager() {
|
private AuthorizationManager getAuthorizationManager() {
|
||||||
RealmService realmService;
|
|
||||||
AuthorizationManager authorizationManager;
|
AuthorizationManager authorizationManager;
|
||||||
try {
|
try {
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
|
||||||
if (realmService == null) {
|
if (realmService == null) {
|
||||||
String msg = "Realm service has not initialized.";
|
String msg = "Realm service has not initialized.";
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
int tenantId = ctx.getTenantId();
|
int tenantId = threadLocalCarbonContext.getTenantId();
|
||||||
authorizationManager = realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
authorizationManager = realmService.getTenantUserRealm(tenantId).getAuthorizationManager();
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
String msg = "Error occurred while retrieving current user store manager";
|
String msg = "Error occurred while retrieving current user store manager";
|
||||||
log.error(msg, e);
|
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
return authorizationManager;
|
return authorizationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Permission[] getPermissions() {
|
private Permission[] getPermissions() {
|
||||||
|
Permission androidSense = new Permission(VirtualFireAlarmConstants.PERM_ENROLL_FIRE_ALARM,
|
||||||
Permission androidSense = new Permission(VirtualFireAlarmConstants.PERM_ENROLL_FIRE_ALARM,
|
CarbonConstants.UI_PERMISSION_ACTION);
|
||||||
CarbonConstants.UI_PERMISSION_ACTION);
|
Permission view = new Permission(VirtualFireAlarmConstants.PERM_OWNING_DEVICE_VIEW,
|
||||||
Permission view = new Permission(VirtualFireAlarmConstants.PERM_OWNING_DEVICE_VIEW, CarbonConstants
|
CarbonConstants.UI_PERMISSION_ACTION);
|
||||||
.UI_PERMISSION_ACTION);
|
return new Permission[]{androidSense, view};
|
||||||
|
|
||||||
return new Permission[]{androidSense, view};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -23,7 +23,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>virtual-fire-alarm-plugin</artifactId>
|
<artifactId>virtual-fire-alarm-plugin</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>device-types</artifactId>
|
<artifactId>device-types</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>appm-connector</artifactId>
|
<artifactId>appm-connector</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>appm-connector</artifactId>
|
<artifactId>appm-connector</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>extensions</artifactId>
|
<artifactId>extensions</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>cdmf-transport-adapters</artifactId>
|
<artifactId>cdmf-transport-adapters</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>cdmf-transport-adapters</artifactId>
|
<artifactId>cdmf-transport-adapters</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>cdmf-transport-adapters</artifactId>
|
<artifactId>cdmf-transport-adapters</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>cdmf-transport-adapters</artifactId>
|
<artifactId>cdmf-transport-adapters</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>cdmf-transport-adapters</artifactId>
|
<artifactId>cdmf-transport-adapters</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>cdmf-transport-adapters</artifactId>
|
<artifactId>cdmf-transport-adapters</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@ -59,13 +59,17 @@ import java.net.UnknownHostException;
|
|||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
import java.security.KeyStoreException;
|
import java.security.KeyStoreException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.RejectedExecutionException;
|
import java.util.concurrent.RejectedExecutionException;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class HTTPEventAdapter implements OutputEventAdapter {
|
public class HTTPEventAdapter implements OutputEventAdapter {
|
||||||
|
|
||||||
@ -181,6 +185,34 @@ public class HTTPEventAdapter implements OutputEventAdapter {
|
|||||||
.extractHeaders(dynamicProperties.get(HTTPEventAdapterConstants.ADAPTER_HEADERS));
|
.extractHeaders(dynamicProperties.get(HTTPEventAdapterConstants.ADAPTER_HEADERS));
|
||||||
String payload = message.toString();
|
String payload = message.toString();
|
||||||
|
|
||||||
|
if ("true".equals(dynamicProperties.get(HTTPEventAdapterConstants.ADAPTER_MESSAGE_URL_TEMPLATED))) {
|
||||||
|
contentType = "application/json";
|
||||||
|
payload = payload.replace("'", "\\\"");
|
||||||
|
try {
|
||||||
|
JSONParser jsonParser = new JSONParser();
|
||||||
|
JSONObject jsonPayload = (JSONObject) jsonParser.parse(payload);
|
||||||
|
|
||||||
|
List<String> matchList = new ArrayList<>();
|
||||||
|
Pattern regex = Pattern.compile("\\{(.*?)\\}");
|
||||||
|
Matcher regexMatcher = regex.matcher(url);
|
||||||
|
|
||||||
|
while (regexMatcher.find()) {//Finds Matching Pattern in String
|
||||||
|
matchList.add(regexMatcher.group(1));//Fetching Group from String
|
||||||
|
}
|
||||||
|
|
||||||
|
for(String str:matchList) {
|
||||||
|
if (jsonPayload.containsKey(str)) {
|
||||||
|
url = url.replace("{" + str + "}", jsonPayload.get(str).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Modified url: " + url);
|
||||||
|
}
|
||||||
|
} catch (ParseException e) {
|
||||||
|
log.error("Unable to parse request body to Json.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
executorService.submit(new HTTPSender(url, payload, headers, httpClient));
|
executorService.submit(new HTTPSender(url, payload, headers, httpClient));
|
||||||
} catch (RejectedExecutionException e) {
|
} catch (RejectedExecutionException e) {
|
||||||
|
|||||||
@ -76,6 +76,12 @@ public class HTTPEventAdapterFactory extends OutputEventAdapterFactory {
|
|||||||
urlProp.setHint(resourceBundle.getString(HTTPEventAdapterConstants.ADAPTER_MESSAGE_URL_HINT));
|
urlProp.setHint(resourceBundle.getString(HTTPEventAdapterConstants.ADAPTER_MESSAGE_URL_HINT));
|
||||||
urlProp.setRequired(true);
|
urlProp.setRequired(true);
|
||||||
|
|
||||||
|
Property urlTemplateProp = new Property(HTTPEventAdapterConstants.ADAPTER_MESSAGE_URL_TEMPLATED);
|
||||||
|
urlTemplateProp.setDisplayName(resourceBundle.getString(HTTPEventAdapterConstants.ADAPTER_MESSAGE_URL_TEMPLATED));
|
||||||
|
urlTemplateProp.setHint(resourceBundle.getString(HTTPEventAdapterConstants.ADAPTER_MESSAGE_URL_TEMPLATED_HINT));
|
||||||
|
urlTemplateProp.setRequired(true);
|
||||||
|
urlTemplateProp.setOptions(new String[]{"true", "false"});
|
||||||
|
|
||||||
Property usernameProp = new Property(HTTPEventAdapterConstants.ADAPTER_USERNAME);
|
Property usernameProp = new Property(HTTPEventAdapterConstants.ADAPTER_USERNAME);
|
||||||
usernameProp.setDisplayName(resourceBundle.getString(HTTPEventAdapterConstants.ADAPTER_USERNAME));
|
usernameProp.setDisplayName(resourceBundle.getString(HTTPEventAdapterConstants.ADAPTER_USERNAME));
|
||||||
usernameProp.setHint(resourceBundle.getString(HTTPEventAdapterConstants.ADAPTER_USERNAME_HINT));
|
usernameProp.setHint(resourceBundle.getString(HTTPEventAdapterConstants.ADAPTER_USERNAME_HINT));
|
||||||
@ -94,6 +100,7 @@ public class HTTPEventAdapterFactory extends OutputEventAdapterFactory {
|
|||||||
headersProp.setRequired(false);
|
headersProp.setRequired(false);
|
||||||
|
|
||||||
dynamicPropertyList.add(urlProp);
|
dynamicPropertyList.add(urlProp);
|
||||||
|
dynamicPropertyList.add(urlTemplateProp);
|
||||||
dynamicPropertyList.add(usernameProp);
|
dynamicPropertyList.add(usernameProp);
|
||||||
dynamicPropertyList.add(passwordProp);
|
dynamicPropertyList.add(passwordProp);
|
||||||
dynamicPropertyList.add(headersProp);
|
dynamicPropertyList.add(headersProp);
|
||||||
|
|||||||
@ -21,6 +21,8 @@ public class HTTPEventAdapterConstants {
|
|||||||
|
|
||||||
public static final String ADAPTER_TYPE_HTTP = "oauth-http";
|
public static final String ADAPTER_TYPE_HTTP = "oauth-http";
|
||||||
public static final String ADAPTER_MESSAGE_URL = "http.url";
|
public static final String ADAPTER_MESSAGE_URL = "http.url";
|
||||||
|
public static final String ADAPTER_MESSAGE_URL_TEMPLATED = "http.url.templated";
|
||||||
|
public static final String ADAPTER_MESSAGE_URL_TEMPLATED_HINT = "http.url.templated.hint";
|
||||||
public static final String ADAPTER_MESSAGE_URL_HINT = "http.url.hint";
|
public static final String ADAPTER_MESSAGE_URL_HINT = "http.url.hint";
|
||||||
public static final String ADAPTER_CONF_DCR_URL = "dcrUrl";
|
public static final String ADAPTER_CONF_DCR_URL = "dcrUrl";
|
||||||
public static final String ADAPTER_CONF_TOKEN_URL = "tokenUrl";
|
public static final String ADAPTER_CONF_TOKEN_URL = "tokenUrl";
|
||||||
|
|||||||
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
http.url=URL
|
http.url=URL
|
||||||
http.url.hint=The target HTTP/HTTPS URL, e.g. "http://yourhost:8080/service (URL will auto format for tenants)"
|
http.url.hint=The target HTTP/HTTPS URL, e.g. "http://yourhost:8080/service (URL will auto format for tenants)"
|
||||||
|
http.url.templated=URL Templated
|
||||||
|
http.url.templated.hint=The target HTTP/HTTPS URL has template value(s) to fill from event. e.g. "http://yourhost:8080/service/{variable1}/{variable2}" variable1 & variable2 should be available in the event and event should be in json format
|
||||||
username=Username
|
username=Username
|
||||||
http.username.hint=Username to obtain oauth token. Leave empty to use default.
|
http.username.hint=Username to obtain oauth token. Leave empty to use default.
|
||||||
password=Password
|
password=Password
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>cdmf-transport-adapters</artifactId>
|
<artifactId>cdmf-transport-adapters</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>cdmf-transport-adapters</artifactId>
|
<artifactId>cdmf-transport-adapters</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>cdmf-transport-adapters</artifactId>
|
<artifactId>cdmf-transport-adapters</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>cdmf-transport-adapters</artifactId>
|
<artifactId>cdmf-transport-adapters</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>extensions</artifactId>
|
<artifactId>extensions</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>mb-extensions</artifactId>
|
<artifactId>mb-extensions</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>mb-extensions</artifactId>
|
<artifactId>mb-extensions</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>extensions</artifactId>
|
<artifactId>extensions</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>carbon-device-mgt-plugins-parent</artifactId>
|
<artifactId>carbon-device-mgt-plugins-parent</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@ -38,6 +38,7 @@
|
|||||||
<module>mb-extensions</module>
|
<module>mb-extensions</module>
|
||||||
<module>siddhi-extensions</module>
|
<module>siddhi-extensions</module>
|
||||||
<module>pull-notification-listeners</module>
|
<module>pull-notification-listeners</module>
|
||||||
|
<module>remote-session-extension</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>pull-notification-listeners</artifactId>
|
<artifactId>pull-notification-listeners</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
<artifactId>extensions</artifactId>
|
<artifactId>extensions</artifactId>
|
||||||
<version>4.0.91-SNAPSHOT</version>
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,68 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
|
<artifactId>remote-session-extension</artifactId>
|
||||||
|
<version>4.0.100-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.extensions.remote.session.endpoint</artifactId>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
<name>WSO2 - Webapp for UI Remote Session</name>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.tomcat</groupId>
|
||||||
|
<artifactId>tomcat-websocket-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.ws.rs</groupId>
|
||||||
|
<artifactId>javax.ws.rs-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.cxf</groupId>
|
||||||
|
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.json.wso2</groupId>
|
||||||
|
<artifactId>json</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.extensions.remote.session</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>remote#session</finalName>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* deviceId 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.device.mgt.extensions.remote.session.endpoint;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.remote.session.endpoint.utils.HttpSessionConfigurator;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.remote.session.endpoint.utils.ServiceHolder;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.remote.session.exception.RemoteSessionManagementException;
|
||||||
|
|
||||||
|
import javax.websocket.CloseReason;
|
||||||
|
import javax.websocket.OnClose;
|
||||||
|
import javax.websocket.OnError;
|
||||||
|
import javax.websocket.OnMessage;
|
||||||
|
import javax.websocket.OnOpen;
|
||||||
|
import javax.websocket.Session;
|
||||||
|
import javax.websocket.server.PathParam;
|
||||||
|
import javax.websocket.server.ServerEndpoint;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents web socket endpoint to manage Remote Sessions
|
||||||
|
*/
|
||||||
|
@ServerEndpoint(value = "/clients/{deviceType}/{deviceId}", configurator = HttpSessionConfigurator.class)
|
||||||
|
public class ClientSessionSubscriptionEndpoint extends SubscriptionEndpoint {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(ClientSessionSubscriptionEndpoint.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web socket onOpen use when client connect to web socket url
|
||||||
|
*
|
||||||
|
* @param session - Registered session.
|
||||||
|
* @param deviceType - DeviceType
|
||||||
|
* @param deviceId - Device Identifier
|
||||||
|
*/
|
||||||
|
@OnOpen
|
||||||
|
public void onOpen(Session session, @PathParam("deviceType") String deviceType, @PathParam("deviceId") String
|
||||||
|
deviceId) {
|
||||||
|
try {
|
||||||
|
ServiceHolder.getInstance().getRemoteSessionManagementService().initializeSession(session, deviceType,
|
||||||
|
deviceId);
|
||||||
|
} catch (RemoteSessionManagementException e) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.error("Error occurred while initializing session ", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
session.close(e.getCloseReason());
|
||||||
|
} catch (IOException ex) {
|
||||||
|
log.error("Failed to disconnect the client.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web socket onMessage use when client sends a string message
|
||||||
|
*
|
||||||
|
* @param session - Registered session.
|
||||||
|
* @param deviceType - DeviceType
|
||||||
|
* @param deviceId - Device Identifier
|
||||||
|
*/
|
||||||
|
@OnMessage
|
||||||
|
public void onMessage(Session session, String message, @PathParam("deviceType") String deviceType, @PathParam
|
||||||
|
("deviceId") String deviceId) {
|
||||||
|
super.onMessage(session, message, deviceType, deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web socket onMessage use when client sends a byte message
|
||||||
|
*
|
||||||
|
* @param session - Registered session.
|
||||||
|
* @param deviceType - DeviceType
|
||||||
|
* @param deviceId - Device Identifier
|
||||||
|
* @param message - Byte message which needs to send to peer
|
||||||
|
*/
|
||||||
|
@OnMessage
|
||||||
|
public void onMessage(Session session, byte[] message, @PathParam("deviceType") String deviceType, @PathParam
|
||||||
|
("deviceId") String deviceId) {
|
||||||
|
super.onMessage(session, message, deviceType, deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web socket onClose use to handle socket connection close
|
||||||
|
*
|
||||||
|
* @param session - Registered session.
|
||||||
|
* @param deviceType - DeviceType
|
||||||
|
* @param deviceId - Device Identifier
|
||||||
|
* @param reason - Status code for web-socket close.
|
||||||
|
*/
|
||||||
|
@OnClose
|
||||||
|
public void onClose(Session session, CloseReason reason, @PathParam("deviceType") String deviceType, @PathParam
|
||||||
|
("deviceId") String deviceId) {
|
||||||
|
super.onClose(session, reason, deviceType, deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web socket onError use to handle socket connection error
|
||||||
|
*
|
||||||
|
* @param session - Registered session.
|
||||||
|
* @param throwable - Web socket exception
|
||||||
|
* @param deviceType - DeviceType
|
||||||
|
* @param deviceId - Device Identifier
|
||||||
|
*/
|
||||||
|
@OnError
|
||||||
|
public void onError(Session session, Throwable throwable, @PathParam("deviceType") String deviceType, @PathParam
|
||||||
|
("deviceId") String deviceId) {
|
||||||
|
super.onError(session, throwable, deviceType, deviceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* deviceId 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.device.mgt.extensions.remote.session.endpoint;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.remote.session.endpoint.utils.HttpSessionConfigurator;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.remote.session.endpoint.utils.ServiceHolder;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.remote.session.exception.RemoteSessionManagementException;
|
||||||
|
|
||||||
|
import javax.websocket.CloseReason;
|
||||||
|
import javax.websocket.OnClose;
|
||||||
|
import javax.websocket.OnError;
|
||||||
|
import javax.websocket.OnMessage;
|
||||||
|
import javax.websocket.OnOpen;
|
||||||
|
import javax.websocket.Session;
|
||||||
|
import javax.websocket.server.PathParam;
|
||||||
|
import javax.websocket.server.ServerEndpoint;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents web socket endpoint to manage Remote Sessions
|
||||||
|
*/
|
||||||
|
@ServerEndpoint(value = "/devices/{deviceType}/{deviceId}/{operationId}", configurator = HttpSessionConfigurator.class)
|
||||||
|
public class DeviceSessionSubscriptionEndpoint extends SubscriptionEndpoint {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(DeviceSessionSubscriptionEndpoint.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web socket onOpen use when device connect to web socket url
|
||||||
|
*
|
||||||
|
* @param session - Web socket Session
|
||||||
|
* @param deviceType - DeviceType
|
||||||
|
* @param deviceId - Device Identifier
|
||||||
|
* @param operationId - Operations Id
|
||||||
|
*/
|
||||||
|
@OnOpen
|
||||||
|
public void onOpen(Session session, @PathParam("deviceType") String deviceType, @PathParam("deviceId") String
|
||||||
|
deviceId, @PathParam("operationId") String operationId) {
|
||||||
|
try {
|
||||||
|
ServiceHolder.getInstance().getRemoteSessionManagementService().initializeSession(session, deviceType,
|
||||||
|
deviceId, operationId);
|
||||||
|
} catch (RemoteSessionManagementException e) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.error("Error occurred while initializing session ", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
session.close(e.getCloseReason());
|
||||||
|
} catch (IOException ex) {
|
||||||
|
log.error("Failed to disconnect the client.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web socket onMessage use when device sends a string message
|
||||||
|
*
|
||||||
|
* @param session - Registered session.
|
||||||
|
* @param message - String message which needs to send to peer
|
||||||
|
* @param deviceType - DeviceType
|
||||||
|
* @param deviceId - Device Identifier
|
||||||
|
*/
|
||||||
|
@OnMessage
|
||||||
|
public void onMessage(Session session, String message, @PathParam("deviceType") String deviceType, @PathParam
|
||||||
|
("deviceId") String deviceId) {
|
||||||
|
super.onMessage(session, message, deviceType, deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web socket onMessage use when device sends a byte message
|
||||||
|
*
|
||||||
|
* @param session - Registered session.
|
||||||
|
* @param message - Byte message which needs to send to peer
|
||||||
|
* @param deviceType - DeviceType
|
||||||
|
* @param deviceId - Device Identifier
|
||||||
|
*/
|
||||||
|
@OnMessage
|
||||||
|
public void onMessage(Session session, byte[] message, @PathParam("deviceType") String deviceType, @PathParam
|
||||||
|
("deviceId") String deviceId) {
|
||||||
|
super.onMessage(session, message, deviceType, deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web socket onClose use to handle socket connection close
|
||||||
|
*
|
||||||
|
* @param session - Registered session.
|
||||||
|
* @param deviceType - DeviceType
|
||||||
|
* @param deviceId - Device Identifier
|
||||||
|
* @param reason - Status code for web-socket close.
|
||||||
|
*/
|
||||||
|
@OnClose
|
||||||
|
public void onClose(Session session, CloseReason reason, @PathParam("deviceType") String deviceType, @PathParam
|
||||||
|
("deviceId") String deviceId) {
|
||||||
|
super.onClose(session, reason, deviceType, deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web socket onError use to handle socket connection error
|
||||||
|
*
|
||||||
|
* @param session - Registered session.
|
||||||
|
* @param throwable - Web socket exception
|
||||||
|
* @param deviceType - DeviceType
|
||||||
|
* @param deviceId - Device Identifier
|
||||||
|
*/
|
||||||
|
@OnError
|
||||||
|
public void onError(Session session, Throwable throwable, @PathParam("deviceType") String deviceType, @PathParam
|
||||||
|
("deviceId") String deviceId) {
|
||||||
|
super.onError(session, throwable, deviceType, deviceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,150 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* deviceId 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.device.mgt.extensions.remote.session.endpoint;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.remote.session.endpoint.utils.ServiceHolder;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.remote.session.exception.RemoteSessionManagementException;
|
||||||
|
|
||||||
|
import javax.websocket.CloseReason;
|
||||||
|
import javax.websocket.Session;
|
||||||
|
import javax.websocket.server.PathParam;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents common web socket endpoint to manage Remote Sessions
|
||||||
|
*/
|
||||||
|
public class SubscriptionEndpoint {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(SubscriptionEndpoint.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web socket onMessage - When client sends a message
|
||||||
|
*
|
||||||
|
* @param session - Registered session.
|
||||||
|
* @param deviceType - DeviceType
|
||||||
|
* @param message - String Message which needs to send to peer
|
||||||
|
*/
|
||||||
|
public void onMessage(Session session, String message, @PathParam("deviceType") String deviceType, @PathParam
|
||||||
|
("deviceId") String deviceId) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Received message from client for RemoteSession id: " + session.getId() + " device type: " +
|
||||||
|
deviceType + " device id: " + deviceId);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ServiceHolder.getInstance().getRemoteSessionManagementService().sendMessageToPeer(session, message);
|
||||||
|
} catch (RemoteSessionManagementException e) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.error("Error occurred while send message to peer session ", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
session.close(e.getCloseReason());
|
||||||
|
} catch (IOException ex) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.error("Failed to disconnect the client.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web socket onMessage use When client sends a message
|
||||||
|
*
|
||||||
|
* @param session - Registered session.
|
||||||
|
* @param deviceType - DeviceType
|
||||||
|
* @param deviceId - Device Identifier
|
||||||
|
* @param message - Byte Message which needs to send to peer
|
||||||
|
*/
|
||||||
|
public void onMessage(Session session, byte[] message, @PathParam("deviceType") String deviceType, @PathParam
|
||||||
|
("deviceId") String deviceId) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Received message from client for RemoteSession id: " + session.getId() + " device type: " +
|
||||||
|
deviceType + " device id: " + deviceId);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ServiceHolder.getInstance().getRemoteSessionManagementService().sendMessageToPeer(session, message);
|
||||||
|
} catch (RemoteSessionManagementException e) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.error("Error occurred while send message to peer session ", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
session.close(e.getCloseReason());
|
||||||
|
} catch (IOException ex) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.error("Failed to disconnect the client.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web socket onClose use to handle socket connection close
|
||||||
|
*
|
||||||
|
* @param session - Registered session.
|
||||||
|
* @param deviceType - DeviceType
|
||||||
|
* @param deviceId - Device Identifier
|
||||||
|
* @param reason - Status code for web-socket close.
|
||||||
|
*/
|
||||||
|
public void onClose(Session session, CloseReason reason, @PathParam("deviceType") String deviceType, @PathParam
|
||||||
|
("deviceId") String deviceId) {
|
||||||
|
|
||||||
|
ServiceHolder.getInstance().getRemoteSessionManagementService().endSession(session, "Remote session closed");
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("websocket closed due to " + reason.getReasonPhrase() + ", for session ID:" + session.getId
|
||||||
|
() + ", for request URI - " + session.getRequestURI() + " device type: " + deviceType + " device " +
|
||||||
|
"id: " + deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web socket onError use to handle socket connection error
|
||||||
|
*
|
||||||
|
* @param session - Registered session.
|
||||||
|
* @param throwable - Web socket exception
|
||||||
|
* @param deviceType - DeviceType
|
||||||
|
* @param deviceId - Device Identifier
|
||||||
|
*/
|
||||||
|
public void onError(Session session, Throwable throwable, @PathParam("deviceType") String deviceType, @PathParam
|
||||||
|
("deviceId") String deviceId) {
|
||||||
|
|
||||||
|
if (throwable instanceof IOException) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.error("Error occurred in session ID: " + session.getId() + " device type: " + deviceType +
|
||||||
|
"device id: " + deviceId + ", for request URI - " + session.getRequestURI() +
|
||||||
|
", " + throwable.getMessage(), throwable);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.error("Error occurred in session ID: " + session.getId() + " device type: " + deviceType + " device " +
|
||||||
|
"id: " + deviceId + ", for request URI - " + session.getRequestURI() + ", " + throwable.getMessage
|
||||||
|
(), throwable);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ServiceHolder.getInstance().getRemoteSessionManagementService().endSession(session, "Remote session closed");
|
||||||
|
if (session.isOpen()) {
|
||||||
|
session.close(new CloseReason(CloseReason.CloseCodes.PROTOCOL_ERROR, "Unexpected Error Occurred"));
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.error("Failed to disconnect the client.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user