diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml index f1a1d9f2d5..d3ec1b228a 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml @@ -165,13 +165,11 @@ org.wso2.carbon.device.mgt.mobile.android provided - commons-httpclient.wso2 commons-httpclient provided - io.swagger swagger-annotations @@ -182,5 +180,15 @@ com.google.code.gson gson + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.analytics.data.publisher + provided + + + org.wso2.carbon.analytics + org.wso2.carbon.analytics.api + provided + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/AppRestriction.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/AppRestriction.java new file mode 100644 index 0000000000..2c8d8c93db --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/AppRestriction.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.mdm.services.android.bean; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; +import java.util.List; + +/** + * This class represents information of configuring App Restriction ex: White list and Black list + */ +@ApiModel(value = "AppRestriction", + description = "This class carries all information related to application restriction.") +public class AppRestriction extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "restrictionType", value = "Restriction type of the application.", required = true) + private String restrictionType; + @ApiModelProperty(name = "restrictedList", value = "Device id list of the operation to be executed.", required = true) + private List restrictedList; + + public String getRestrictionType() { + return restrictionType; + } + + public void setRestrictionType(String restrictionType) { + this.restrictionType = restrictionType; + } + + public List getRestrictedList() { + return restrictedList; + } + + public void setRestrictedList(List restrictedList) { + this.restrictedList = restrictedList; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUpdate.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUpdate.java new file mode 100644 index 0000000000..f732f74a93 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUpdate.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.services.android.bean; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; + +/** + * This class represents the information of Update application operation. + */ +@ApiModel(value = "ApplicationUpdate", + description = "This class carries all information related to application update.") +public class ApplicationUpdate extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "appIdentifier", value = "The package name of the application " + + "to be update.", required = true) + private String appIdentifier; + @ApiModelProperty(name = "type", value = "The type of the application. The following types of applications " + + "are supported: enterprise, public and webapp.", required = true) + private String type; + @ApiModelProperty(name = "url", value = "The URL of the application.", required = true) + private String url; + @ApiModelProperty(name = "schedule", value = "Application update schedule.", required = true) + private String schedule; + + public String getAppIdentifier() { + return appIdentifier; + } + + public void setAppIdentifier(String appIdentifier) { + this.appIdentifier = appIdentifier; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getSchedule() { + return schedule; + } + + public void setSchedule(String schedule) { + this.schedule = schedule; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceLock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceLock.java new file mode 100644 index 0000000000..5dc8b7904f --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceLock.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http:www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.services.android.bean; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; +@ApiModel(value = "DeviceLock", + description = "This class carries all information related to device lock operation.") +public class DeviceLock extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "message", value = "Pop up message of the lock operation.", required = true) + private String message; + @ApiModelProperty(name = "isHardLockEnabled", value = "Hard lock enable status of the Device", required = true) + private boolean isHardLockEnabled; + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isHardLockEnabled() { + return isHardLockEnabled; + } + + public void setHardLockEnabled(boolean hardLockEnabled) { + isHardLockEnabled = hardLockEnabled; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceState.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceState.java new file mode 100644 index 0000000000..fb23b0fcc9 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceState.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http:www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.services.android.bean; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@XmlRootElement +/** + * Store Device state event/data for androidDevice. + */ +@ApiModel(value = "DeviceState", + description = "This class carries all information related to device state.") +@JsonIgnoreProperties(ignoreUnknown = true) +public class DeviceState { + + @XmlElementWrapper(required = true, name = "values") + @ApiModelProperty(name = "values", value = "Device and its statuses.", required = true) + private Map values; + + /** The id. */ + @XmlElement(required = false, name = "id") + @ApiModelProperty(name = "id", value = "Identification code.", required = true) + private String id; + + /** + * Gets the values. + * @return the values + */ + public Map getValues() { + return values; + } + + /** + * Sets the values. + * @param values the values + */ + public void setValues(Map values) { + this.values = values; + } + + /** + * Sets the id. + * @param id the new id + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets the id. + * @return the id + */ + public String getId() { + return id; + } + + @Override + public String toString(){ + List valueList = new ArrayList(); + for (Map.Entry entry : values.entrySet()) { + valueList.add(entry.getKey() + ":" + entry.getValue()); + } + return valueList.toString(); + + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java new file mode 100644 index 0000000000..ae1dad8694 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http:www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.services.android.bean; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; + +/** + * This class represents the information of sending Upgrade Firmware operation. + */ +@ApiModel(value = "UpgradeFirmware", + description = "This class carries all information related to UpgradeFirmware.") +public class UpgradeFirmware extends AndroidOperation implements Serializable { + @ApiModelProperty(name = "schedule", value = "Schedule of the UpgradeFirmware.", required = true) + private String schedule; + + public String getSchedule() { + return schedule; + } + + public void setSchedule(String schedule) { + this.schedule = schedule; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Vpn.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Vpn.java new file mode 100644 index 0000000000..188d44f8fc --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Vpn.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.services.android.bean; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; + +/** + * This class represents the information of configuring VPN operation. + */ +@ApiModel(value = "Vpn", + description = "This class carries all information related to VPN.") +public class Vpn extends AndroidOperation implements Serializable { + @ApiModelProperty(name = "serverAddress", value = "Server Address.", required = true) + private String serverAddress; + @ApiModelProperty(name = "serverPort", value = "Server Port.", required = true) + private String serverPort; + @ApiModelProperty(name = "sharedSecret", value = "Shared secret.", required = true) + private String sharedSecret; + @ApiModelProperty(name = "dnsServer", value = "DNS server.", required = true) + private String dnsServer; + + public String getServerAddress() { + return serverAddress; + } + + public void setServerAddress(String serverAddress) { + this.serverAddress = serverAddress; + } + + public String getServerPort() { + return serverPort; + } + + public void setServerPort(String serverPort) { + this.serverPort = serverPort; + } + + public String getSharedSecret() { + return sharedSecret; + } + + public void setSharedSecret(String sharedSecret) { + this.sharedSecret = sharedSecret; + } + + public String getDnsServer() { + return dnsServer; + } + + public void setDnsServer(String dnsServer) { + this.dnsServer = dnsServer; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AppRestrictionBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AppRestrictionBeanWrapper.java new file mode 100644 index 0000000000..64412336e0 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AppRestrictionBeanWrapper.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.mdm.services.android.bean.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.mdm.services.android.bean.AppRestriction; + +import java.util.List; + +/** + * This class is used to wrap AppRestriction bean with devices + */ +@ApiModel(value = "AppRestrictionBeanWrapper", + description = "Application Restriction related information.") +public class AppRestrictionBeanWrapper { + + @ApiModelProperty(name = "operation", value = "AppRestriction related information.", required = true) + private AppRestriction operation; + @ApiModelProperty(name = "deviceIDs", value = "Device id list of the operation to be executed.", required = true) + private List deviceIDs; + + public AppRestriction getOperation() { + return operation; + } + + public void setOperation(AppRestriction operation) { + this.operation = operation; + } + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/ApplicationUpdateBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/ApplicationUpdateBeanWrapper.java new file mode 100644 index 0000000000..b202bf8833 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/ApplicationUpdateBeanWrapper.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http:www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.mdm.services.android.bean.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.mdm.services.android.bean.ApplicationUpdate; + +import java.util.List; + +/** + * This class is used to wrap the UpdateApplication bean with devices. + */ +@ApiModel(value = "ApplicationUpdateBeanWrapper", + description = "Application Update related Info.") +public class ApplicationUpdateBeanWrapper { + + @ApiModelProperty(name = "deviceIDs", value = "Device id list of the operation to be executed.", required = true) + private List deviceIDs; + @ApiModelProperty(name = "operation", value = "Application Update related information.", required = true) + private ApplicationUpdate operation; + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } + + public ApplicationUpdate getOperation() { + return operation; + } + + public void setOperation(ApplicationUpdate operation) { + this.operation = operation; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DeviceLockBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DeviceLockBeanWrapper.java new file mode 100644 index 0000000000..5811c31022 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DeviceLockBeanWrapper.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http:www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.services.android.bean.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.mdm.services.android.bean.DeviceLock; + +import java.util.List; + +/** + * This class is used to wrap the Notification bean with devices. + */ +@ApiModel(value = "DeviceLockBeanWrapper", + description = "DeviceLock related Information.") +public class DeviceLockBeanWrapper { + @ApiModelProperty(name = "deviceIDs", value = "Device id list of the operation to be executed.", required = true) + private List deviceIDs; + @ApiModelProperty(name = "operation", value = "Information of the Device lock operation.", required = true) + private DeviceLock operation; + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } + + public DeviceLock getOperation() { + return operation; + } + + public void setOperation(DeviceLock operation) { + this.operation = operation; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/EventBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/EventBeanWrapper.java new file mode 100644 index 0000000000..d8e21c8d4d --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/EventBeanWrapper.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http:www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.services.android.bean.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * This class is used to wrap the events which receive from the agent application. + */ +@ApiModel(value = "EventBeanWrapper", + description = "Android agent's event related Information.") +public class EventBeanWrapper { + @ApiModelProperty(name = "deviceIdentifier", value = "DeviceIdentifier to be need to retrieve/publish Event.", required = true) + private String deviceIdentifier; + @ApiModelProperty(name = "payload", value = "Event payload.", required = true) + private String payload; + @ApiModelProperty(name = "type", value = "Type of the event.", required = true) + private String type; + + public String getPayload() { + return payload; + } + + public void setPayload(String payload) { + this.payload = payload; + } + + public String getDeviceIdentifier() { + return deviceIdentifier; + } + + public void setDeviceIdentifier(String deviceIdentifier) { + this.deviceIdentifier = deviceIdentifier; + } + + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/UpgradeFirmwareBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/UpgradeFirmwareBeanWrapper.java new file mode 100644 index 0000000000..b881422c29 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/UpgradeFirmwareBeanWrapper.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http:www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.mdm.services.android.bean.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.mdm.services.android.bean.UpgradeFirmware; + +import java.util.List; + +/** + * This class is used to wrap the UpgradeFirmware bean with devices. + */ +@ApiModel(value = "UpgradeFirmwareBeanWrapper", + description = "Information related to UpgradeFirmware.") +public class UpgradeFirmwareBeanWrapper { + @ApiModelProperty(name = "deviceIDs", + value = "List of device Ids to be need to execute UpgradeFirmware operation.", required = true) + private List deviceIDs; + @ApiModelProperty(name = "operation", value = "Information related to UpgradeFirmware operation.", required = true) + private UpgradeFirmware operation; + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } + + public UpgradeFirmware getOperation() { + return operation; + } + + public void setOperation(UpgradeFirmware operation) { + this.operation = operation; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/VpnBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/VpnBeanWrapper.java new file mode 100644 index 0000000000..bfdbd43da3 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/VpnBeanWrapper.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http:www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.mdm.services.android.bean.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.mdm.services.android.bean.Vpn; + +import java.util.List; + +/** + * This class is used to wrap the Vpn bean with devices. + */ +@ApiModel(value = "VpnBeanWrapper", + description = "Information related to VPN Configuration.") +public class VpnBeanWrapper { + @ApiModelProperty(name = "operation", + value = "List of device Ids to be need to execute UpgradeFirmware operation.", required = true) + private Vpn operation; + @ApiModelProperty(name = "deviceIDs", + value = "List of device Ids to be need to execute VPN operation.", required = true) + private List deviceIDs; + + public Vpn getOperation() { + return operation; + } + + public void setOperation(Vpn operation) { + this.operation = operation; + } + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/WebClipBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/WebClipBeanWrapper.java index 098a518bb3..fb2edc239b 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/WebClipBeanWrapper.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/WebClipBeanWrapper.java @@ -31,7 +31,7 @@ import java.util.List; description = "Mapping between web clip operation and device list to be applied.") public class WebClipBeanWrapper { - @ApiModelProperty(name = "operation", value = "the information of setting up webclip", required = true) + @ApiModelProperty(name = "operation", value = "the information of setting up webclip.", required = true) private WebClip operation; @ApiModelProperty(name = "deviceIDs", value = "List of device Ids", required = true) private List deviceIDs; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/configuration/impl/ConfigurationMgtServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/configuration/impl/ConfigurationMgtServiceImpl.java index caf138e38d..564ba62472 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/configuration/impl/ConfigurationMgtServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/configuration/impl/ConfigurationMgtServiceImpl.java @@ -25,8 +25,8 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; -import org.wso2.carbon.mdm.services.android.services.configuration.ConfigurationMgtService; import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; +import org.wso2.carbon.mdm.services.android.services.configuration.ConfigurationMgtService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.AndroidConstants; import org.wso2.carbon.mdm.services.android.util.Message; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/EventService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/EventService.java new file mode 100644 index 0000000000..30ce612d6f --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/EventService.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.services.android.services.event; + +import io.swagger.annotations.*; +import org.wso2.carbon.mdm.services.android.bean.DeviceState; +import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper; +import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +/** + * APIs related to events published from Android agent are implemented here. + */ +@Api(value = "EventService", description = "Android Device Management REST-API implementation.") +public interface EventService { + String ACCEPT = "Accept"; + + @POST + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Event Publishing via REST API.", + notes = "Publish events received by the WSO2 EMM Android client to WSO2 DAS using this API." + ) + @ApiResponses(value = { + @ApiResponse(code = 201, message = "Event is published successfully."), + @ApiResponse(code = 500, message = "Error occurred while publishing the events from Android agent.") + }) + Response publishEvents(@ApiParam(name = "acceptHeader", value = "Accept Header.") + @HeaderParam(ACCEPT) String acceptHeader, + @ApiParam(name = "eventBeanWrapper", + value = "Information of the agent event to be published on DAS.") + EventBeanWrapper eventBeanWrapper) throws AndroidAgentException; + @GET + @Path("{deviceId}") + @Produces("application/json") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting Event Details of a Device.", + notes = "Get the event details received by an Android device using this API.", + response = DeviceState.class, + responseContainer = "List" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "List of Device statuses."), + @ApiResponse(code = 500, + message = "Error occurred while getting published events for specific given device.") + }) + Response retrieveAlert(@ApiParam(name = "acceptHeader", value = "Accept Header.") + @HeaderParam(ACCEPT) String acceptHeader, + @ApiParam(name = "deviceId", value = "DeviceId which need to retrieve published events.") + @PathParam("deviceId") String deviceId) throws AndroidAgentException; + + @GET + @Path("{deviceId}/date") + @Produces("application/json") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting Event Details for a Given Time Period.", + notes = "Get the event details of a device for a given time duration using this API.", + response = DeviceState.class, + responseContainer = "List" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "event details of a device for a given time duration"), + @ApiResponse(code = 500, message = "Error occurred while getting published events for" + + " specific device on given Date.") + }) + Response retrieveAlertFromDate(@ApiParam(name = "acceptHeader", value = "Accept Header.") + @HeaderParam(ACCEPT) String acceptHeader, + @ApiParam(name = "deviceId", + value = "Device Identifier to be need to retrieve events.") + @PathParam("deviceId") String deviceId, + @ApiParam(name = "from", value = "From Date.") + @QueryParam("from") long from, + @ApiParam(name = "to", value = "To Date.") + @QueryParam("to") long to) throws AndroidAgentException; + + @GET + @Path("{deviceId}/type/{type}") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting Event Details for a Given Time Period.", + notes = "Get the event details of a device for a given time duration using this API.", + response = DeviceState.class, + responseContainer = "List" + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "event details of a device for a given time duration"), + @ApiResponse(code = 500, message = "Error occurred while getting published events for" + + " specific device on given Date.") + }) + Response retrieveAlertType(@ApiParam(name = "acceptHeader", value = "Accept Header.") + @HeaderParam(ACCEPT) String acceptHeader, + @ApiParam(name = "deviceId", value = "Device Identifier to be need to retrieve events.") + @PathParam("deviceId") String deviceId, + @ApiParam(name = "type", value = "Type of the Alert to be need to retrieve events.") + @PathParam("type") String type) throws AndroidAgentException; +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/impl/EventServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/impl/EventServiceImpl.java new file mode 100644 index 0000000000..d6be71649b --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/event/impl/EventServiceImpl.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.services.android.services.event.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; +import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; +import org.wso2.carbon.mdm.services.android.bean.DeviceState; +import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper; +import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; +import org.wso2.carbon.mdm.services.android.services.event.EventService; +import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; +import org.wso2.carbon.mdm.services.android.util.Message; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.List; + +public class EventServiceImpl implements EventService { + + private static final String ACCEPT = "Accept"; + private static Log log = LogFactory.getLog(EventService.class); + private static final String EVENT_STREAM_DEFINITION = "android_agent"; + + @POST + public Response publishEvents(@HeaderParam(ACCEPT) String acceptHeader, + EventBeanWrapper eventBeanWrapper) throws AndroidAgentException { + + if (log.isDebugEnabled()) { + log.debug("Invoking Android device even logging."); + } + Message message = new Message(); + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); + + Object payload[] = {eventBeanWrapper.getDeviceIdentifier(), eventBeanWrapper.getPayload(), eventBeanWrapper.getType()}; + try { + if (AndroidAPIUtils.getEventPublisherService().publishEvent( + EVENT_STREAM_DEFINITION, "1.0.0", new Object[0], new Object[0], payload)) { + message.setResponseCode("Event is published successfully."); + return Response.status(Response.Status.CREATED).entity(message).type(responseMediaType).build(); + } else { + message.setResponseCode("Error occurred while publishing the event."); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR). + entity(message).type(responseMediaType).build(); + } + } catch (DataPublisherConfigurationException e) { + String msg = "Error occurred while publishing the events from Android agent."; + log.error(msg, e); + throw new AndroidAgentException(msg, e); + } + } + + @Path("{deviceId}") + @Produces("application/json") + @GET + public Response retrieveAlert(@HeaderParam(ACCEPT) String acceptHeader, + @PathParam("deviceId") String deviceId) throws AndroidAgentException { + + if (log.isDebugEnabled()) { + log.debug("Retrieving events for given device Identifier."); + } + Message message = new Message(); + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); + String query = "deviceIdentifier:" + deviceId; + List deviceStates; + try { + deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); + if (deviceStates == null) { + message.setResponseCode("No any alerts are published for Device: " + deviceId + "."); + return Response.status(Response.Status.OK).entity(message).type(responseMediaType).build(); + + } else { + return Response.status(Response.Status.OK).entity(deviceStates).build(); + } + } catch (AnalyticsException e) { + String msg = "Error occurred while getting published events for specific " + + "Device: " + deviceId + "."; + log.error(msg, e); + throw new AndroidAgentException(msg, e); + } + } + + @Path("{deviceId}/date") + @Produces("application/json") + @GET + public Response retrieveAlertFromDate(@HeaderParam(ACCEPT) String acceptHeader, + @PathParam("deviceId") String deviceId, @QueryParam("from") long from, + @QueryParam("to") long to) throws AndroidAgentException { + String fromDate = String.valueOf(from); + String toDate = String.valueOf(to); + if (log.isDebugEnabled()) { + log.debug("Retrieving events for given device Identifier and time period."); + } + Message message = new Message(); + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); + + String query = "deviceIdentifier:" + deviceId + " AND _timestamp: [" + fromDate + " TO " + toDate + "]"; + List deviceStates; + try { + deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); + if (deviceStates == null) { + message. + setResponseCode("No any alerts are published on given date for given Device: " + deviceId + "."); + return Response.status(Response.Status.OK).entity(message).build(); + + } else { + return Response.status(Response.Status.OK).entity(deviceStates).type(responseMediaType).build(); + } + } catch (AnalyticsException e) { + String msg = "Error occurred while getting published events for specific " + + "Device: " + deviceId + " on given Date."; + log.error(msg, e); + throw new AndroidAgentException(msg, e); + } + } + + @Path("{deviceId}/type/{type}") + @GET + public Response retrieveAlertType(@HeaderParam(ACCEPT) String acceptHeader, + @PathParam("deviceId") String deviceId, @PathParam("type") String type) + throws AndroidAgentException { + + if (log.isDebugEnabled()) { + log.debug("Retrieving events for given device identifier and type."); + } + Message message = new Message(); + MediaType responseMediaType = AndroidAPIUtils.getResponseMediaType(acceptHeader); + String query = "deviceIdentifier:" + deviceId + " AND type:" + type; + List deviceStates; + try { + deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); + if (deviceStates == null) { + message. + setResponseCode("No any alerts are published on given date for given Device: " + deviceId + "."); + return Response.status(Response.Status.OK).entity(message).build(); + + } else { + return Response.status(Response.Status.OK).entity(deviceStates).type(responseMediaType).build(); + } + } catch (AnalyticsException e) { + String msg = "Error occurred while getting published events for specific " + + "Device: " + deviceId + "og given device Type."; + log.error(msg, e); + throw new AndroidAgentException(msg, e); + } + + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java index 01ee8d0295..72f4f7965f 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2015, 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 @@ -11,36 +11,51 @@ * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.wso2.carbon.mdm.services.android.util; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; +import com.google.gson.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.analytics.api.AnalyticsDataAPI; +import org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse; +import org.wso2.carbon.analytics.dataservice.commons.SearchResultEntry; +import org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceUtils; +import org.wso2.carbon.analytics.datasource.commons.Record; +import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; +import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService; +import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; +import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; +import org.wso2.carbon.device.mgt.core.search.mgt.impl.Utils; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.device.mgt.mobile.impl.android.gcm.GCMService; +import org.wso2.carbon.mdm.services.android.bean.DeviceState; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * AndroidAPIUtil class provides utility functions used by Android REST-API classes. @@ -60,7 +75,7 @@ public class AndroidAPIUtils { PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); String username = threadLocalCarbonContext.getUsername(); String tenantDomain = threadLocalCarbonContext.getTenantDomain(); - if (username.endsWith(tenantDomain)) { + if (username != null && username.endsWith(tenantDomain)) { return username.substring(0, username.lastIndexOf("@")); } return username; @@ -78,16 +93,16 @@ public class AndroidAPIUtils { return deviceManagementProviderService; } -// public static GCMService getGCMService() { -// PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); -// GCMService gcmService = (GCMService) ctx.getOSGiService(GCMService.class, null); -// if (gcmService == null) { -// String msg = "GCM service has not initialized."; -// log.error(msg); -// throw new IllegalStateException(msg); -// } -// return gcmService; -// } + public static GCMService getGCMService() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + GCMService gcmService = (GCMService) ctx.getOSGiService(GCMService.class, null); + if (gcmService == null) { + String msg = "GCM service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return gcmService; + } public static MediaType getResponseMediaType(String acceptHeader) { MediaType responseMediaType; @@ -107,18 +122,20 @@ public class AndroidAPIUtils { DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs, message, responseMediaType); - int status = - getDeviceManagementService().addOperation("android", operation, deviceIDHolder.getValidDeviceIDList()); -// if (status > 0) { -// GCMService gcmService = getGCMService(); -// if (gcmService.isGCMEnabled()) { -// List devices = new ArrayList(); -// for (DeviceIdentifier deviceIdentifier : deviceIDHolder.getValidDeviceIDList()) { -// devices.add(getDeviceManagementService().getDevice(deviceIdentifier)); -// } -// getGCMService().sendNotification(operation.getCode(), devices); -// } -// } + List validDeviceIds = deviceIDHolder.getValidDeviceIDList(); + int status = getDeviceManagementService().addOperation( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, operation, validDeviceIds); + if (status > 0) { + GCMService gcmService = getGCMService(); + if (gcmService.isGCMEnabled()) { + List deviceIDList = deviceIDHolder.getValidDeviceIDList(); + List devices = new ArrayList(deviceIDList.size()); + for (DeviceIdentifier deviceIdentifier : deviceIDList) { + devices.add(getDeviceManagementService().getDevice(deviceIdentifier)); + } + getGCMService().sendNotification(operation.getCode(), devices); + } + } if (!deviceIDHolder.getErrorDeviceIdList().isEmpty()) { return javax.ws.rs.core.Response.status(AndroidConstants.StatusCodes. MULTI_STATUS_HTTP_CODE).type( @@ -167,40 +184,137 @@ public class AndroidAPIUtils { return notificationManagementService; } + public static EventsPublisherService getEventPublisherService() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + EventsPublisherService eventsPublisherService = + (EventsPublisherService) ctx.getOSGiService(EventsPublisherService.class, null); + if (eventsPublisherService == null) { + String msg = "Event Publisher service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return eventsPublisherService; + } + + public static AnalyticsDataAPI getAnalyticsDataAPI() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + AnalyticsDataAPI analyticsDataAPI = + (AnalyticsDataAPI) ctx.getOSGiService(AnalyticsDataAPI.class, null); + if (analyticsDataAPI == null) { + String msg = "Analytics api service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return analyticsDataAPI; + } + + public static List getAllEventsForDevice(String tableName, String query) throws AnalyticsException { + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + AnalyticsDataAPI analyticsDataAPI = getAnalyticsDataAPI(); + int eventCount = analyticsDataAPI.searchCount(tenantId, tableName, query); + if (eventCount == 0) { + return null; + } + List resultEntries = analyticsDataAPI.search(tenantId, tableName, query, 0, eventCount); + List recordIds = getRecordIds(resultEntries); + AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds); + Map deviceStateses = createDeviceStatusData(AnalyticsDataServiceUtils.listRecords( + analyticsDataAPI, response)); + return getSortedDeviceStateData(deviceStateses, resultEntries); + } + + private static List getRecordIds(List searchResults) { + List ids = new ArrayList(); + for (SearchResultEntry searchResult : searchResults) { + ids.add(searchResult.getId()); + } + return ids; + } + + public static Map createDeviceStatusData(List records) { + Map deviceStatuses = new HashMap(); + for (Record record : records) { + DeviceState deviceState = createDeviceStatusData(record); + deviceStatuses.put(deviceState.getId(), deviceState); + } + return deviceStatuses; + } + + private static DeviceState createDeviceStatusData(Record record) { + DeviceState deviceState = new DeviceState(); + deviceState.setId(record.getId()); + deviceState.setValues(record.getValues()); + return deviceState; + } + + public static List getSortedDeviceStateData(Map sensorDatas, + List searchResults) { + List sortedRecords = new ArrayList(); + for (SearchResultEntry searchResultEntry : searchResults) { + sortedRecords.add(sensorDatas.get(searchResultEntry.getId())); + } + return sortedRecords; + } + public static void updateOperation(String deviceId, Operation operation) throws OperationManagementException, PolicyComplianceException, ApplicationManagementException { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + if (AndroidConstants.OperationCodes.MONITOR.equals(operation.getCode())) { if (log.isDebugEnabled()) { log.info("Received compliance status from MONITOR operation ID: " + operation.getId()); } - getPolicyManagerService().checkPolicyCompliance(deviceIdentifier, operation.getOperationResponse()); + getPolicyManagerService().checkPolicyCompliance(deviceIdentifier, operation.getPayLoad()); } else if (AndroidConstants.OperationCodes.APPLICATION_LIST.equals(operation.getCode())) { if (log.isDebugEnabled()) { log.info("Received applications list from device '" + deviceId + "'"); } updateApplicationList(operation, deviceIdentifier); + + } else if (AndroidConstants.OperationCodes.DEVICE_INFO.equals(operation.getCode())) { + + try { + Device device = new Gson().fromJson(operation.getOperationResponse(), Device.class); + org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo = convertDeviceToInfo(device); + deviceInfo.setDeviceIdentifier(deviceIdentifier); + updateDeviceInfo(deviceInfo); + } catch (DeviceDetailsMgtException e) { + throw new OperationManagementException("Error occurred while updating the device infomation.", e); + } + + + } else if (AndroidConstants.OperationCodes.DEVICE_LOCATION.equals(operation.getCode())) { + try { + DeviceLocation location = new Gson().fromJson(operation.getOperationResponse(), DeviceLocation.class); + if (location != null) { + location.setDeviceIdentifier(deviceIdentifier); + updateDeviceLocation(location); + } + } catch (DeviceDetailsMgtException e) { + throw new OperationManagementException("Error occurred while updating the device location.", e); + } } + getDeviceManagementService().updateOperation(deviceIdentifier, operation); } - public static List getPendingOperations + public static List getPendingOperations (DeviceIdentifier deviceIdentifier) throws OperationManagementException { - List operations; + List operations; operations = getDeviceManagementService().getPendingOperations(deviceIdentifier); return operations; } private static void updateApplicationList(Operation operation, DeviceIdentifier deviceIdentifier) throws ApplicationManagementException { - List applications = new ArrayList(); // Parsing json string to get applications list. JsonElement jsonElement = new JsonParser().parse(operation.getOperationResponse()); JsonArray jsonArray = jsonElement.getAsJsonArray(); Application app; + List applications = new ArrayList(jsonArray.size()); for (JsonElement element : jsonArray) { app = new Application(); app.setName(element.getAsJsonObject(). @@ -208,8 +322,152 @@ public class AndroidAPIUtils { app.setApplicationIdentifier(element.getAsJsonObject(). get(AndroidConstants.ApplicationProperties.IDENTIFIER).getAsString()); app.setPlatform(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS) != null) { + app.setMemoryUsage(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS).getAsInt()); + } + if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION) != null) { + app.setVersion(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION).getAsString()); + } applications.add(app); } getApplicationManagerService().updateApplicationListInstalledInDevice(deviceIdentifier, applications); } + + + private static void updateDeviceLocation(DeviceLocation deviceLocation) throws DeviceDetailsMgtException { + + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + DeviceInformationManager informationManager = + (DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null); + + informationManager.addDeviceLocation(deviceLocation); + } + + + private static void updateDeviceInfo(org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo) + throws DeviceDetailsMgtException { + + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + DeviceInformationManager informationManager = + (DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null); + + informationManager.addDeviceInfo(deviceInfo); + } + + + private static org.wso2.carbon.device.mgt.common.device.details.DeviceInfo convertDeviceToInfo(Device device) { + + org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo = + new org.wso2.carbon.device.mgt.common.device.details.DeviceInfo(); + if (deviceInfo.getDeviceDetailsMap() == null) { + deviceInfo.setDeviceDetailsMap(new HashMap()); + } + List props = device.getProperties(); + + for (Device.Property prop : props) { + if (Utils.getDeviceDetailsColumnNames().containsValue(prop.getName())) { + if (prop.getName().equalsIgnoreCase("DEVICE_MODEL")) { + deviceInfo.setDeviceModel(prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("VENDOR")) { + deviceInfo.setVendor(prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("OS_VERSION")) { + deviceInfo.setOsVersion(prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("IMEI")) { + deviceInfo.getDeviceDetailsMap().put("IMEI", prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("IMSI")) { + deviceInfo.getDeviceDetailsMap().put("IMSI", prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("MAC")) { + deviceInfo.getDeviceDetailsMap().put("mac", prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("SERIAL")) { + deviceInfo.getDeviceDetailsMap().put("serial", prop.getValue()); + } + } else { + if (prop.getName().equalsIgnoreCase("CPU_INFO")) { + deviceInfo.setTotalRAMMemory(Double.parseDouble(getProperty(prop.getValue(), "User"))); + + deviceInfo.getDeviceDetailsMap().put("cpuUser", + getProperty(prop.getValue(), "User")); + deviceInfo.getDeviceDetailsMap().put("cpuSystem", + getProperty(prop.getValue(), "System")); + deviceInfo.getDeviceDetailsMap().put("IOW", + getProperty(prop.getValue(), "IOW")); + deviceInfo.getDeviceDetailsMap().put("IRQ", + getProperty(prop.getValue(), "IRQ")); + } else if (prop.getName().equalsIgnoreCase("RAM_INFO")) { + deviceInfo.setTotalRAMMemory(Double.parseDouble(getProperty(prop.getValue(), "TOTAL_MEMORY"))); + deviceInfo.setAvailableRAMMemory(Double.parseDouble(getProperty(prop.getValue(), "AVAILABLE_MEMORY"))); + + deviceInfo.getDeviceDetailsMap().put("ramThreshold", + getProperty(prop.getValue(), "THRESHOLD")); + deviceInfo.getDeviceDetailsMap().put("ramLowMemory", + getProperty(prop.getValue(), "LOW_MEMORY")); + } else if (prop.getName().equalsIgnoreCase("BATTERY_INFO")) { + deviceInfo.setPluggedIn(Boolean.parseBoolean(getProperty(prop.getValue(), "PLUGGED"))); + + deviceInfo.getDeviceDetailsMap().put("batteryLevel", + getProperty(prop.getValue(), "BATTERY_LEVEL")); + deviceInfo.getDeviceDetailsMap().put("batteryScale", + getProperty(prop.getValue(), "SCALE")); + deviceInfo.getDeviceDetailsMap().put("batteryVoltage", + getProperty(prop.getValue(), "BATTERY_VOLTAGE")); + deviceInfo.getDeviceDetailsMap().put("batteryTemperature", + getProperty(prop.getValue(), "TEMPERATURE")); + deviceInfo.getDeviceDetailsMap().put("batteryCurrentTemperature", + getProperty(prop.getValue(), "CURRENT_AVERAGE")); + deviceInfo.getDeviceDetailsMap().put("batteryTechnology", + getProperty(prop.getValue(), "TECHNOLOGY")); + deviceInfo.getDeviceDetailsMap().put("batteryHealth", + getProperty(prop.getValue(), "HEALTH")); + deviceInfo.getDeviceDetailsMap().put("batteryStatus", + getProperty(prop.getValue(), "STATUS")); + } else if (prop.getName().equalsIgnoreCase("NETWORK_INFO")) { + deviceInfo.setSsid(getProperty(prop.getValue(), "WIFI_SSID")); + deviceInfo.setConnectionType(getProperty(prop.getValue(), "CONNECTION_TYPE")); + + deviceInfo.getDeviceDetailsMap().put("mobileSignalStrength", + getProperty(prop.getValue(), "MOBILE_SIGNAL_STRENGTH")); + deviceInfo.getDeviceDetailsMap().put("wifiSignalStrength", + getProperty(prop.getValue(), "WIFI_SIGNAL_STRENGTH")); + } else if (prop.getName().equalsIgnoreCase("DEVICE_INFO")) { + deviceInfo.setBatteryLevel(Double.parseDouble( + getProperty(prop.getValue(), "BATTERY_LEVEL"))); + deviceInfo.setInternalTotalMemory(Double.parseDouble( + getProperty(prop.getValue(), "INTERNAL_TOTAL_MEMORY"))); + deviceInfo.setInternalAvailableMemory(Double.parseDouble( + getProperty(prop.getValue(), "INTERNAL_AVAILABLE_MEMORY"))); + deviceInfo.setExternalTotalMemory(Double.parseDouble( + getProperty(prop.getValue(), "EXTERNAL_TOTAL_MEMORY"))); + deviceInfo.setExternalAvailableMemory(Double.parseDouble( + getProperty(prop.getValue(), "EXTERNAL_AVAILABLE_MEMORY"))); + + deviceInfo.getDeviceDetailsMap().put("encryptionEnabled", + getProperty(prop.getValue(), "ENCRYPTION_ENABLED")); + deviceInfo.getDeviceDetailsMap().put("passcodeEnabled", + getProperty(prop.getValue(), "PASSCODE_ENABLED")); + deviceInfo.getDeviceDetailsMap().put("operator", + getProperty(prop.getValue(), "OPERATOR")); + } + } + } + return deviceInfo; + } + + private static String getProperty(String a, String needed) { + + JsonElement jsonElement = new JsonParser().parse(a); + JsonArray jsonArray = jsonElement.getAsJsonArray(); + boolean exist = false; + for (JsonElement element : jsonArray) { + // if (((JsonObject) element).entrySet().iterator().next().getValue().getAsString().equalsIgnoreCase(needed)); + for (Map.Entry ob : ((JsonObject) element).entrySet()) { + if (exist) { + return ob.getValue().getAsString().replace("%", ""); + } + if (ob.getValue().getAsString().equalsIgnoreCase(needed)) { + exist = true; + } + } + } + return ""; + } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java index ef9131bbbf..8ba454da3d 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2015, 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 @@ -11,7 +11,7 @@ * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -65,6 +65,7 @@ public final class AndroidConstants { throw new AssertionError(); } public static final String DEVICE_LOCK = "DEVICE_LOCK"; + public static final String DEVICE_UNLOCK = "DEVICE_UNLOCK"; public static final String DEVICE_LOCATION = "DEVICE_LOCATION"; public static final String WIFI = "WIFI"; public static final String CAMERA = "CAMERA"; @@ -77,14 +78,20 @@ public final class AndroidConstants { public static final String APPLICATION_LIST = "APPLICATION_LIST"; public static final String CHANGE_LOCK_CODE = "CHANGE_LOCK_CODE"; public static final String INSTALL_APPLICATION = "INSTALL_APPLICATION"; + public static final String UPDATE_APPLICATION = "UPDATE_APPLICATION"; public static final String UNINSTALL_APPLICATION = "UNINSTALL_APPLICATION"; public static final String BLACKLIST_APPLICATIONS = "BLACKLIST_APPLICATIONS"; public static final String ENCRYPT_STORAGE = "ENCRYPT_STORAGE"; public static final String DEVICE_RING = "DEVICE_RING"; + public static final String DEVICE_REBOOT = "REBOOT"; + public static final String UPGRADE_FIRMWARE = "UPGRADE_FIRMWARE"; public static final String NOTIFICATION = "NOTIFICATION"; public static final String WEBCLIP = "WEBCLIP"; public static final String DISENROLL = "DISENROLL"; public static final String MONITOR = "MONITOR"; + public static final String VPN = "VPN"; + public static final String APP_RESTRICTION = "APP-RESTRICTION"; + public static final String WORK_PROFILE = "WORK_PROFILE"; } public final class StatusCodes{ @@ -109,6 +116,8 @@ public final class AndroidConstants { } public static final String NAME = "name"; public static final String IDENTIFIER = "package"; + public static final String USS = "USS"; + public static final String VERSION = "version"; public static final String ICON = "icon"; } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 010d83ff66..27ff000aed 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -74,6 +74,7 @@ +