Merge pull request #276 from hasuniea/master

sync code
revert-dabc3590
Hasunie 9 years ago
commit aa1e64738f

@ -165,13 +165,11 @@
<artifactId>org.wso2.carbon.device.mgt.mobile.android</artifactId> <artifactId>org.wso2.carbon.device.mgt.mobile.android</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-httpclient.wso2</groupId> <groupId>commons-httpclient.wso2</groupId>
<artifactId>commons-httpclient</artifactId> <artifactId>commons-httpclient</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.swagger</groupId> <groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId> <artifactId>swagger-annotations</artifactId>
@ -182,5 +180,15 @@
<groupId>com.google.code.gson</groupId> <groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId> <artifactId>gson</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.analytics.data.publisher</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.analytics</groupId>
<artifactId>org.wso2.carbon.analytics.api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -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<String> restrictedList;
public String getRestrictionType() {
return restrictionType;
}
public void setRestrictionType(String restrictionType) {
this.restrictionType = restrictionType;
}
public List<String> getRestrictedList() {
return restrictedList;
}
public void setRestrictedList(List<String> restrictedList) {
this.restrictedList = restrictedList;
}
}

@ -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;
}
}

@ -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;
}
}

@ -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<String, Object> 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<String, Object> getValues() {
return values;
}
/**
* Sets the values.
* @param values the values
*/
public void setValues(Map<String, Object> 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<String> valueList = new ArrayList<String>();
for (Map.Entry<String, Object> entry : values.entrySet()) {
valueList.add(entry.getKey() + ":" + entry.getValue());
}
return valueList.toString();
}
}

@ -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;
}
}

@ -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;
}
}

@ -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<String> deviceIDs;
public AppRestriction getOperation() {
return operation;
}
public void setOperation(AppRestriction operation) {
this.operation = operation;
}
public List<String> getDeviceIDs() {
return deviceIDs;
}
public void setDeviceIDs(List<String> deviceIDs) {
this.deviceIDs = deviceIDs;
}
}

@ -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<String> deviceIDs;
@ApiModelProperty(name = "operation", value = "Application Update related information.", required = true)
private ApplicationUpdate operation;
public List<String> getDeviceIDs() {
return deviceIDs;
}
public void setDeviceIDs(List<String> deviceIDs) {
this.deviceIDs = deviceIDs;
}
public ApplicationUpdate getOperation() {
return operation;
}
public void setOperation(ApplicationUpdate operation) {
this.operation = operation;
}
}

@ -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<String> deviceIDs;
@ApiModelProperty(name = "operation", value = "Information of the Device lock operation.", required = true)
private DeviceLock operation;
public List<String> getDeviceIDs() {
return deviceIDs;
}
public void setDeviceIDs(List<String> deviceIDs) {
this.deviceIDs = deviceIDs;
}
public DeviceLock getOperation() {
return operation;
}
public void setOperation(DeviceLock operation) {
this.operation = operation;
}
}

@ -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;
}
}

@ -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<String> deviceIDs;
@ApiModelProperty(name = "operation", value = "Information related to UpgradeFirmware operation.", required = true)
private UpgradeFirmware operation;
public List<String> getDeviceIDs() {
return deviceIDs;
}
public void setDeviceIDs(List<String> deviceIDs) {
this.deviceIDs = deviceIDs;
}
public UpgradeFirmware getOperation() {
return operation;
}
public void setOperation(UpgradeFirmware operation) {
this.operation = operation;
}
}

@ -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<String> deviceIDs;
public Vpn getOperation() {
return operation;
}
public void setOperation(Vpn operation) {
this.operation = operation;
}
public List<String> getDeviceIDs() {
return deviceIDs;
}
public void setDeviceIDs(List<String> deviceIDs) {
this.deviceIDs = deviceIDs;
}
}

@ -31,7 +31,7 @@ import java.util.List;
description = "Mapping between web clip operation and device list to be applied.") description = "Mapping between web clip operation and device list to be applied.")
public class WebClipBeanWrapper { 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; private WebClip operation;
@ApiModelProperty(name = "deviceIDs", value = "List of device Ids", required = true) @ApiModelProperty(name = "deviceIDs", value = "List of device Ids", required = true)
private List<String> deviceIDs; private List<String> deviceIDs;

@ -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.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
import org.wso2.carbon.device.mgt.common.license.mgt.License; 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.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.AndroidAPIUtils;
import org.wso2.carbon.mdm.services.android.util.AndroidConstants; import org.wso2.carbon.mdm.services.android.util.AndroidConstants;
import org.wso2.carbon.mdm.services.android.util.Message; import org.wso2.carbon.mdm.services.android.util.Message;

@ -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;
}

@ -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<DeviceState> 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<DeviceState> 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<DeviceState> 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);
}
}
}

@ -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, * WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * 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, * Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * "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 * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.wso2.carbon.mdm.services.android.util; package org.wso2.carbon.mdm.services.android.util;
import com.google.gson.JsonArray; import com.google.gson.*;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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.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.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; 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.Application;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; 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.notification.mgt.NotificationManagementService;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; 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.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; 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.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.common.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* AndroidAPIUtil class provides utility functions used by Android REST-API classes. * AndroidAPIUtil class provides utility functions used by Android REST-API classes.
@ -60,7 +75,7 @@ public class AndroidAPIUtils {
PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
String username = threadLocalCarbonContext.getUsername(); String username = threadLocalCarbonContext.getUsername();
String tenantDomain = threadLocalCarbonContext.getTenantDomain(); String tenantDomain = threadLocalCarbonContext.getTenantDomain();
if (username.endsWith(tenantDomain)) { if (username != null && username.endsWith(tenantDomain)) {
return username.substring(0, username.lastIndexOf("@")); return username.substring(0, username.lastIndexOf("@"));
} }
return username; return username;
@ -78,16 +93,16 @@ public class AndroidAPIUtils {
return deviceManagementProviderService; return deviceManagementProviderService;
} }
// public static GCMService getGCMService() { public static GCMService getGCMService() {
// PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
// GCMService gcmService = (GCMService) ctx.getOSGiService(GCMService.class, null); GCMService gcmService = (GCMService) ctx.getOSGiService(GCMService.class, null);
// if (gcmService == null) { if (gcmService == null) {
// String msg = "GCM service has not initialized."; String msg = "GCM service has not initialized.";
// log.error(msg); log.error(msg);
// throw new IllegalStateException(msg); throw new IllegalStateException(msg);
// } }
// return gcmService; return gcmService;
// } }
public static MediaType getResponseMediaType(String acceptHeader) { public static MediaType getResponseMediaType(String acceptHeader) {
MediaType responseMediaType; MediaType responseMediaType;
@ -107,18 +122,20 @@ public class AndroidAPIUtils {
DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs, DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs,
message, responseMediaType); message, responseMediaType);
int status = List<DeviceIdentifier> validDeviceIds = deviceIDHolder.getValidDeviceIDList();
getDeviceManagementService().addOperation("android", operation, deviceIDHolder.getValidDeviceIDList()); int status = getDeviceManagementService().addOperation(
// if (status > 0) { DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, operation, validDeviceIds);
// GCMService gcmService = getGCMService(); if (status > 0) {
// if (gcmService.isGCMEnabled()) { GCMService gcmService = getGCMService();
// List<Device> devices = new ArrayList<Device>(); if (gcmService.isGCMEnabled()) {
// for (DeviceIdentifier deviceIdentifier : deviceIDHolder.getValidDeviceIDList()) { List<DeviceIdentifier> deviceIDList = deviceIDHolder.getValidDeviceIDList();
// devices.add(getDeviceManagementService().getDevice(deviceIdentifier)); List<Device> devices = new ArrayList<Device>(deviceIDList.size());
// } for (DeviceIdentifier deviceIdentifier : deviceIDList) {
// getGCMService().sendNotification(operation.getCode(), devices); devices.add(getDeviceManagementService().getDevice(deviceIdentifier));
// } }
// } getGCMService().sendNotification(operation.getCode(), devices);
}
}
if (!deviceIDHolder.getErrorDeviceIdList().isEmpty()) { if (!deviceIDHolder.getErrorDeviceIdList().isEmpty()) {
return javax.ws.rs.core.Response.status(AndroidConstants.StatusCodes. return javax.ws.rs.core.Response.status(AndroidConstants.StatusCodes.
MULTI_STATUS_HTTP_CODE).type( MULTI_STATUS_HTTP_CODE).type(
@ -167,40 +184,137 @@ public class AndroidAPIUtils {
return notificationManagementService; 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<DeviceState> 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<SearchResultEntry> resultEntries = analyticsDataAPI.search(tenantId, tableName, query, 0, eventCount);
List<String> recordIds = getRecordIds(resultEntries);
AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds);
Map<String, DeviceState> deviceStateses = createDeviceStatusData(AnalyticsDataServiceUtils.listRecords(
analyticsDataAPI, response));
return getSortedDeviceStateData(deviceStateses, resultEntries);
}
private static List<String> getRecordIds(List<SearchResultEntry> searchResults) {
List<String> ids = new ArrayList();
for (SearchResultEntry searchResult : searchResults) {
ids.add(searchResult.getId());
}
return ids;
}
public static Map<String, DeviceState> createDeviceStatusData(List<Record> records) {
Map<String, DeviceState> 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<DeviceState> getSortedDeviceStateData(Map<String, DeviceState> sensorDatas,
List<SearchResultEntry> searchResults) {
List<DeviceState> sortedRecords = new ArrayList();
for (SearchResultEntry searchResultEntry : searchResults) {
sortedRecords.add(sensorDatas.get(searchResultEntry.getId()));
}
return sortedRecords;
}
public static void updateOperation(String deviceId, Operation operation) public static void updateOperation(String deviceId, Operation operation)
throws OperationManagementException, PolicyComplianceException, ApplicationManagementException { throws OperationManagementException, PolicyComplianceException, ApplicationManagementException {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId); deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
if (AndroidConstants.OperationCodes.MONITOR.equals(operation.getCode())) { if (AndroidConstants.OperationCodes.MONITOR.equals(operation.getCode())) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.info("Received compliance status from MONITOR operation ID: " + operation.getId()); 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())) { } else if (AndroidConstants.OperationCodes.APPLICATION_LIST.equals(operation.getCode())) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.info("Received applications list from device '" + deviceId + "'"); log.info("Received applications list from device '" + deviceId + "'");
} }
updateApplicationList(operation, deviceIdentifier); 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); getDeviceManagementService().updateOperation(deviceIdentifier, operation);
} }
public static List<? extends org.wso2.carbon.device.mgt.common.operation.mgt.Operation> getPendingOperations public static List<? extends Operation> getPendingOperations
(DeviceIdentifier deviceIdentifier) throws OperationManagementException { (DeviceIdentifier deviceIdentifier) throws OperationManagementException {
List<? extends org.wso2.carbon.device.mgt.common.operation.mgt.Operation> operations; List<? extends Operation> operations;
operations = getDeviceManagementService().getPendingOperations(deviceIdentifier); operations = getDeviceManagementService().getPendingOperations(deviceIdentifier);
return operations; return operations;
} }
private static void updateApplicationList(Operation operation, DeviceIdentifier deviceIdentifier) private static void updateApplicationList(Operation operation, DeviceIdentifier deviceIdentifier)
throws ApplicationManagementException { throws ApplicationManagementException {
List<Application> applications = new ArrayList<Application>();
// Parsing json string to get applications list. // Parsing json string to get applications list.
JsonElement jsonElement = new JsonParser().parse(operation.getOperationResponse()); JsonElement jsonElement = new JsonParser().parse(operation.getOperationResponse());
JsonArray jsonArray = jsonElement.getAsJsonArray(); JsonArray jsonArray = jsonElement.getAsJsonArray();
Application app; Application app;
List<Application> applications = new ArrayList<Application>(jsonArray.size());
for (JsonElement element : jsonArray) { for (JsonElement element : jsonArray) {
app = new Application(); app = new Application();
app.setName(element.getAsJsonObject(). app.setName(element.getAsJsonObject().
@ -208,8 +322,152 @@ public class AndroidAPIUtils {
app.setApplicationIdentifier(element.getAsJsonObject(). app.setApplicationIdentifier(element.getAsJsonObject().
get(AndroidConstants.ApplicationProperties.IDENTIFIER).getAsString()); get(AndroidConstants.ApplicationProperties.IDENTIFIER).getAsString());
app.setPlatform(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); 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); applications.add(app);
} }
getApplicationManagerService().updateApplicationListInstalledInDevice(deviceIdentifier, applications); 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<String, String>());
}
List<Device.Property> 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<String, JsonElement> ob : ((JsonObject) element).entrySet()) {
if (exist) {
return ob.getValue().getAsString().replace("%", "");
}
if (ob.getValue().getAsString().equalsIgnoreCase(needed)) {
exist = true;
}
}
}
return "";
}
} }

@ -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, * WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * 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, * Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * "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 * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
@ -65,6 +65,7 @@ public final class AndroidConstants {
throw new AssertionError(); throw new AssertionError();
} }
public static final String DEVICE_LOCK = "DEVICE_LOCK"; 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 DEVICE_LOCATION = "DEVICE_LOCATION";
public static final String WIFI = "WIFI"; public static final String WIFI = "WIFI";
public static final String CAMERA = "CAMERA"; 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 APPLICATION_LIST = "APPLICATION_LIST";
public static final String CHANGE_LOCK_CODE = "CHANGE_LOCK_CODE"; public static final String CHANGE_LOCK_CODE = "CHANGE_LOCK_CODE";
public static final String INSTALL_APPLICATION = "INSTALL_APPLICATION"; 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 UNINSTALL_APPLICATION = "UNINSTALL_APPLICATION";
public static final String BLACKLIST_APPLICATIONS = "BLACKLIST_APPLICATIONS"; public static final String BLACKLIST_APPLICATIONS = "BLACKLIST_APPLICATIONS";
public static final String ENCRYPT_STORAGE = "ENCRYPT_STORAGE"; public static final String ENCRYPT_STORAGE = "ENCRYPT_STORAGE";
public static final String DEVICE_RING = "DEVICE_RING"; 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 NOTIFICATION = "NOTIFICATION";
public static final String WEBCLIP = "WEBCLIP"; public static final String WEBCLIP = "WEBCLIP";
public static final String DISENROLL = "DISENROLL"; public static final String DISENROLL = "DISENROLL";
public static final String MONITOR = "MONITOR"; 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{ public final class StatusCodes{
@ -109,6 +116,8 @@ public final class AndroidConstants {
} }
public static final String NAME = "name"; public static final String NAME = "name";
public static final String IDENTIFIER = "package"; public static final String IDENTIFIER = "package";
public static final String USS = "USS";
public static final String VERSION = "version";
public static final String ICON = "icon"; public static final String ICON = "icon";
} }
} }

@ -74,6 +74,7 @@
<bean id="operationServiceBean" class="org.wso2.carbon.mdm.services.android.services.operationmgt.OperationMgtServiceImpl"/> <bean id="operationServiceBean" class="org.wso2.carbon.mdm.services.android.services.operationmgt.OperationMgtServiceImpl"/>
<bean id="policyServiceBean" class="org.wso2.carbon.mdm.services.android.services.policymgt.PolicyMgtServiceImpl"/> <bean id="policyServiceBean" class="org.wso2.carbon.mdm.services.android.services.policymgt.PolicyMgtServiceImpl"/>
<bean id="configurationServiceBean" class="org.wso2.carbon.mdm.services.android.services.configuration.ConfigurationMgtServiceImpl"/> <bean id="configurationServiceBean" class="org.wso2.carbon.mdm.services.android.services.configuration.ConfigurationMgtServiceImpl"/>
<bean id="eventServiceBean" class="org.wso2.carbon.mdm.services.android.services.EventServiceImpl"/>
<bean id="jsonProvider" class="org.wso2.carbon.mdm.services.android.common.GsonMessageBodyHandler"/> <bean id="jsonProvider" class="org.wso2.carbon.mdm.services.android.common.GsonMessageBodyHandler"/>
<bean id="errorHandler" class="org.wso2.carbon.mdm.services.android.common.ErrorHandler"/> <bean id="errorHandler" class="org.wso2.carbon.mdm.services.android.common.ErrorHandler"/>
</beans> </beans>

Loading…
Cancel
Save