|
|
@ -19,6 +19,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.wso2.carbon.device.mgt.mobile.impl.android;
|
|
|
|
package org.wso2.carbon.device.mgt.mobile.impl.android;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
|
|
|
import com.google.gson.JsonArray;
|
|
|
|
|
|
|
|
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.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
@ -35,36 +39,49 @@ import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
public class AndroidPolicyMonitoringService implements PolicyMonitoringService {
|
|
|
|
public class AndroidPolicyMonitoringService implements PolicyMonitoringService {
|
|
|
|
|
|
|
|
|
|
|
|
private static Log log = LogFactory.getLog(AndroidPolicyMonitoringService.class);
|
|
|
|
private static Log log = LogFactory.getLog(AndroidPolicyMonitoringService.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void notifyDevices(List<Device> list) throws PolicyComplianceException {
|
|
|
|
public void notifyDevices(List<Device> list) throws PolicyComplianceException {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object o) throws PolicyComplianceException {
|
|
|
|
public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy,
|
|
|
|
ComplianceData complianceData = new ComplianceData();
|
|
|
|
Object compliancePayload) throws PolicyComplianceException {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Checking policy compliance status of device '" + deviceIdentifier.getId() + "'");
|
|
|
|
log.debug("Checking policy compliance status of device '" + deviceIdentifier.getId() + "'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (o == null || policy == null) {
|
|
|
|
if (compliancePayload == null || policy == null) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<ComplianceFeature> complianceFeatures = (List<ComplianceFeature>) o;
|
|
|
|
ComplianceData complianceData = new ComplianceData();
|
|
|
|
complianceData.setComplianceFeatures(complianceFeatures);
|
|
|
|
List<ComplianceFeature> complianceFeatures = new ArrayList<ComplianceFeature>();
|
|
|
|
|
|
|
|
|
|
|
|
for (ComplianceFeature cf : complianceFeatures) {
|
|
|
|
// Parsing json string to get compliance features.
|
|
|
|
if(!cf.isCompliance()){
|
|
|
|
JsonElement jsonElement = new JsonParser().parse((String) compliancePayload);
|
|
|
|
complianceData.setStatus(false);
|
|
|
|
JsonArray jsonArray = jsonElement.getAsJsonArray();
|
|
|
|
break;
|
|
|
|
Gson gson = new Gson();
|
|
|
|
}
|
|
|
|
ComplianceFeature complianceFeature;
|
|
|
|
}
|
|
|
|
|
|
|
|
return complianceData;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
|
public String getType() {
|
|
|
|
complianceFeature = gson.fromJson(jsonArray.get(i), ComplianceFeature.class);
|
|
|
|
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID;
|
|
|
|
complianceFeatures.add(complianceFeature);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
complianceData.setComplianceFeatures(complianceFeatures);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (ComplianceFeature cf : complianceFeatures) {
|
|
|
|
|
|
|
|
if (!cf.isCompliance()) {
|
|
|
|
|
|
|
|
complianceData.setStatus(false);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return complianceData;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public String getType() {
|
|
|
|
|
|
|
|
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|