|
|
@ -21,8 +21,6 @@ package org.wso2.carbon.device.mgt.mobile.impl.android;
|
|
|
|
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.*;
|
|
|
|
import org.wso2.carbon.device.mgt.common.*;
|
|
|
|
|
|
|
|
|
|
|
|
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.device.mgt.common.license.mgt.LicenseManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
|
|
@ -33,318 +31,331 @@ import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginUtils;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginUtils;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
|
|
|
import org.wso2.carbon.registry.api.Collection;
|
|
|
|
|
|
|
|
import org.wso2.carbon.registry.api.RegistryException;
|
|
|
|
import org.wso2.carbon.registry.api.RegistryException;
|
|
|
|
import org.wso2.carbon.registry.api.Resource;
|
|
|
|
import org.wso2.carbon.registry.api.Resource;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
|
|
|
|
|
import javax.xml.bind.JAXBException;
|
|
|
|
|
|
|
|
import javax.xml.bind.Marshaller;
|
|
|
|
|
|
|
|
import javax.xml.bind.Unmarshaller;
|
|
|
|
|
|
|
|
import java.io.StringReader;
|
|
|
|
|
|
|
|
import java.io.StringWriter;
|
|
|
|
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
public class AndroidDeviceManager implements DeviceManager {
|
|
|
|
public class AndroidDeviceManager implements DeviceManager {
|
|
|
|
|
|
|
|
|
|
|
|
private MobileDeviceManagementDAOFactory daoFactory;
|
|
|
|
private MobileDeviceManagementDAOFactory daoFactory;
|
|
|
|
private static final Log log = LogFactory.getLog(AndroidDeviceManagementService.class);
|
|
|
|
private static final Log log = LogFactory.getLog(AndroidDeviceManagementService.class);
|
|
|
|
private FeatureManager featureManager = new AndroidFeatureManager();
|
|
|
|
private FeatureManager featureManager = new AndroidFeatureManager();
|
|
|
|
private LicenseManager licenseManager;
|
|
|
|
private LicenseManager licenseManager;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public AndroidDeviceManager() {
|
|
|
|
|
|
|
|
this.daoFactory = new AndroidDAOFactory();
|
|
|
|
|
|
|
|
this.licenseManager = new RegistryBasedLicenseManager();
|
|
|
|
|
|
|
|
|
|
|
|
public AndroidDeviceManager() {
|
|
|
|
License defaultLicense = AndroidPluginUtils.getDefaultLicense();
|
|
|
|
this.daoFactory = new AndroidDAOFactory();
|
|
|
|
try {
|
|
|
|
this.licenseManager = new RegistryBasedLicenseManager();
|
|
|
|
licenseManager
|
|
|
|
|
|
|
|
.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, defaultLicense);
|
|
|
|
|
|
|
|
} catch (LicenseManagementException e) {
|
|
|
|
|
|
|
|
log.error("Error occurred while adding default license for Android devices", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
License defaultLicense = AndroidPluginUtils.getDefaultLicense();
|
|
|
|
@Override
|
|
|
|
try {
|
|
|
|
public FeatureManager getFeatureManager() {
|
|
|
|
licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, defaultLicense);
|
|
|
|
return featureManager;
|
|
|
|
} catch (LicenseManagementException e) {
|
|
|
|
}
|
|
|
|
log.error("Error occurred while adding default license for Android devices", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public FeatureManager getFeatureManager() {
|
|
|
|
public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
|
|
|
|
return featureManager;
|
|
|
|
throws DeviceManagementException {
|
|
|
|
}
|
|
|
|
boolean status = false;
|
|
|
|
|
|
|
|
Resource resource;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Persisting android configurations in Registry");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath(
|
|
|
|
|
|
|
|
DeviceManagementConstants.
|
|
|
|
|
|
|
|
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
|
|
|
|
StringWriter writer = new StringWriter();
|
|
|
|
|
|
|
|
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
|
|
|
|
|
|
|
|
Marshaller marshaller = context.createMarshaller();
|
|
|
|
|
|
|
|
marshaller.marshal(tenantConfiguration, writer);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
resource = MobileDeviceManagementUtil.getRegistry().newResource();
|
|
|
|
public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
|
|
|
|
resource.setContent(writer.toString());
|
|
|
|
throws DeviceManagementException {
|
|
|
|
resource.setMediaType(AndroidPluginConstants.MEDIA_TYPE_XML);
|
|
|
|
boolean status;
|
|
|
|
MobileDeviceManagementUtil.putRegistryResource(resourcePath, resource);
|
|
|
|
Resource resource;
|
|
|
|
status = true;
|
|
|
|
try {
|
|
|
|
} catch (MobileDeviceMgtPluginException e) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
log.debug("Persisting android configurations in Registry");
|
|
|
|
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
|
|
|
|
}
|
|
|
|
} catch (RegistryException e) {
|
|
|
|
String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath(
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
DeviceManagementConstants.
|
|
|
|
"Error occurred while persisting the Registry resource : " + e.getMessage(), e);
|
|
|
|
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
} catch (JAXBException e) {
|
|
|
|
MobileDeviceManagementUtil.createRegistryCollection(resourcePath);
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
for (ConfigurationEntry configEntry : tenantConfiguration.getConfiguration()) {
|
|
|
|
"Error occurred while parsing the configuration : " + e.getMessage(), e);
|
|
|
|
resource = MobileDeviceManagementUtil.getRegistry().newResource();
|
|
|
|
}
|
|
|
|
resource.setContent(configEntry.getValue());
|
|
|
|
return status;
|
|
|
|
MobileDeviceManagementUtil.putRegistryResource(resourcePath + "/" + configEntry.getName(), resource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
status = true;
|
|
|
|
|
|
|
|
} catch (MobileDeviceMgtPluginException e) {
|
|
|
|
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
|
|
|
|
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
|
|
|
|
|
|
|
|
} catch (RegistryException e) {
|
|
|
|
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
|
|
|
|
"Error occurred while persisting the Registry resource : " + e.getMessage(), e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public TenantConfiguration getConfiguration() throws DeviceManagementException {
|
|
|
|
public TenantConfiguration getConfiguration() throws DeviceManagementException {
|
|
|
|
Collection dsCollection;
|
|
|
|
Resource resource;
|
|
|
|
TenantConfiguration tenantConfiguration;
|
|
|
|
try {
|
|
|
|
List<ConfigurationEntry> configs = new ArrayList<>();
|
|
|
|
String androidRegPath =
|
|
|
|
ConfigurationEntry entry;
|
|
|
|
MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants.
|
|
|
|
Resource resource;
|
|
|
|
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
try {
|
|
|
|
resource = MobileDeviceManagementUtil.getRegistryResource(androidRegPath);
|
|
|
|
String androidRegPath =
|
|
|
|
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
|
|
|
|
MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants.
|
|
|
|
Unmarshaller unmarshaller = context.createUnmarshaller();
|
|
|
|
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
return (TenantConfiguration) unmarshaller.unmarshal(
|
|
|
|
dsCollection =
|
|
|
|
new StringReader(new String((byte[]) resource.getContent(), Charset
|
|
|
|
(Collection) MobileDeviceManagementUtil.getRegistryResource(androidRegPath);
|
|
|
|
.forName("UTF8"))));
|
|
|
|
String[] dsmPaths = dsCollection.getChildren();
|
|
|
|
|
|
|
|
for (String dsmPath : dsmPaths) {
|
|
|
|
|
|
|
|
entry = new ConfigurationEntry();
|
|
|
|
|
|
|
|
resource = MobileDeviceManagementUtil.getRegistryResource(dsmPath);
|
|
|
|
|
|
|
|
entry.setValue(resource.getContent());
|
|
|
|
|
|
|
|
entry.setName(resource.getId());
|
|
|
|
|
|
|
|
configs.add(entry);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
tenantConfiguration = new TenantConfiguration();
|
|
|
|
|
|
|
|
tenantConfiguration.setConfiguration(configs);
|
|
|
|
|
|
|
|
tenantConfiguration.setType(DeviceManagementConstants.
|
|
|
|
|
|
|
|
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
|
|
|
|
} catch (MobileDeviceMgtPluginException e) {
|
|
|
|
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
|
|
|
|
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
|
|
|
|
|
|
|
|
} catch (RegistryException e) {
|
|
|
|
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
|
|
|
|
"Error occurred while retrieving the Registry data : " + e.getMessage(), e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return tenantConfiguration;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
} catch (MobileDeviceMgtPluginException e) {
|
|
|
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
boolean status = false;
|
|
|
|
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
|
|
|
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
|
|
|
} catch (JAXBException e) {
|
|
|
|
try {
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
"Error occurred while parsing the configuration : " + e.getMessage(), e);
|
|
|
|
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
|
|
|
|
} catch (RegistryException e) {
|
|
|
|
}
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
boolean isEnrolled = this.isEnrolled(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
|
|
|
"Error occurred while retrieving the Registry resource : " + e.getMessage(), e);
|
|
|
|
if (isEnrolled) {
|
|
|
|
}
|
|
|
|
this.modifyEnrollment(device);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
AndroidDAOFactory.beginTransaction();
|
|
|
|
|
|
|
|
status = daoFactory.getMobileDeviceDAO().addMobileDevice(mobileDevice);
|
|
|
|
|
|
|
|
AndroidDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
AndroidDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while roll back the device enrol transaction :" + device.toString();
|
|
|
|
|
|
|
|
log.warn(msg, mobileDAOEx);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String msg = "Error while enrolling the Android device : " + device.getDeviceIdentifier();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
|
|
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
|
|
|
boolean status;
|
|
|
|
boolean status = false;
|
|
|
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
|
|
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Modifying the Android device enrollment data");
|
|
|
|
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AndroidDAOFactory.beginTransaction();
|
|
|
|
boolean isEnrolled = this.isEnrolled(
|
|
|
|
status = daoFactory.getMobileDeviceDAO().updateMobileDevice(mobileDevice);
|
|
|
|
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
|
|
|
AndroidDAOFactory.commitTransaction();
|
|
|
|
if (isEnrolled) {
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
this.modifyEnrollment(device);
|
|
|
|
try {
|
|
|
|
} else {
|
|
|
|
AndroidDAOFactory.rollbackTransaction();
|
|
|
|
AndroidDAOFactory.beginTransaction();
|
|
|
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
|
|
|
status = daoFactory.getMobileDeviceDAO().addMobileDevice(mobileDevice);
|
|
|
|
String msg = "Error occurred while roll back the update device transaction :" +
|
|
|
|
AndroidDAOFactory.commitTransaction();
|
|
|
|
device.toString();
|
|
|
|
}
|
|
|
|
log.warn(msg, mobileDAOEx);
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
String msg = "Error while updating the enrollment of the Android device : " +
|
|
|
|
AndroidDAOFactory.rollbackTransaction();
|
|
|
|
device.getDeviceIdentifier();
|
|
|
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
|
|
|
log.error(msg, e);
|
|
|
|
String msg = "Error occurred while roll back the device enrol transaction :" +
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
device.toString();
|
|
|
|
}
|
|
|
|
log.warn(msg, mobileDAOEx);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String msg =
|
|
|
|
|
|
|
|
"Error while enrolling the Android device : " + device.getDeviceIdentifier();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
|
|
|
boolean status;
|
|
|
|
boolean status;
|
|
|
|
try {
|
|
|
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
try {
|
|
|
|
log.debug("Dis-enrolling Android device : " + deviceId);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
}
|
|
|
|
log.debug("Modifying the Android device enrollment data");
|
|
|
|
AndroidDAOFactory.beginTransaction();
|
|
|
|
}
|
|
|
|
status = daoFactory.getMobileDeviceDAO().deleteMobileDevice(deviceId.getId());
|
|
|
|
AndroidDAOFactory.beginTransaction();
|
|
|
|
AndroidDAOFactory.commitTransaction();
|
|
|
|
status = daoFactory.getMobileDeviceDAO().updateMobileDevice(mobileDevice);
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
AndroidDAOFactory.commitTransaction();
|
|
|
|
try {
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
AndroidDAOFactory.rollbackTransaction();
|
|
|
|
try {
|
|
|
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
|
|
|
AndroidDAOFactory.rollbackTransaction();
|
|
|
|
String msg = "Error occurred while roll back the device dis enrol transaction :" +
|
|
|
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
|
|
|
deviceId.toString();
|
|
|
|
String msg = "Error occurred while roll back the update device transaction :" +
|
|
|
|
log.warn(msg, mobileDAOEx);
|
|
|
|
device.toString();
|
|
|
|
}
|
|
|
|
log.warn(msg, mobileDAOEx);
|
|
|
|
String msg = "Error while removing the Android device : " + deviceId.getId();
|
|
|
|
}
|
|
|
|
log.error(msg, e);
|
|
|
|
String msg = "Error while updating the enrollment of the Android device : " +
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
device.getDeviceIdentifier();
|
|
|
|
}
|
|
|
|
log.error(msg, e);
|
|
|
|
return status;
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
boolean isEnrolled = false;
|
|
|
|
boolean status;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Checking the enrollment of Android device : " + deviceId.getId());
|
|
|
|
log.debug("Dis-enrolling Android device : " + deviceId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MobileDevice mobileDevice =
|
|
|
|
AndroidDAOFactory.beginTransaction();
|
|
|
|
daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId());
|
|
|
|
status = daoFactory.getMobileDeviceDAO().deleteMobileDevice(deviceId.getId());
|
|
|
|
if (mobileDevice != null) {
|
|
|
|
AndroidDAOFactory.commitTransaction();
|
|
|
|
isEnrolled = true;
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
AndroidDAOFactory.rollbackTransaction();
|
|
|
|
String msg = "Error while checking the enrollment status of Android device : " +
|
|
|
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
|
|
|
deviceId.getId();
|
|
|
|
String msg = "Error occurred while roll back the device dis enrol transaction :" +
|
|
|
|
log.error(msg, e);
|
|
|
|
deviceId.toString();
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
log.warn(msg, mobileDAOEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return isEnrolled;
|
|
|
|
String msg = "Error while removing the Android device : " + deviceId.getId();
|
|
|
|
}
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
return true;
|
|
|
|
boolean isEnrolled = false;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Checking the enrollment of Android device : " + deviceId.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
MobileDevice mobileDevice =
|
|
|
|
|
|
|
|
daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId());
|
|
|
|
|
|
|
|
if (mobileDevice != null) {
|
|
|
|
|
|
|
|
isEnrolled = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error while checking the enrollment status of Android device : " +
|
|
|
|
|
|
|
|
deviceId.getId();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return isEnrolled;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
|
|
|
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
throws DeviceManagementException {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
|
|
|
Device device;
|
|
|
|
throws DeviceManagementException {
|
|
|
|
try {
|
|
|
|
return true;
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
}
|
|
|
|
log.debug("Getting the details of Android device : '" + deviceId.getId() + "'");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
MobileDevice mobileDevice = daoFactory.getMobileDeviceDAO().
|
|
|
|
|
|
|
|
getMobileDevice(deviceId.getId());
|
|
|
|
|
|
|
|
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
|
|
|
|
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
|
|
|
|
throw new DeviceManagementException("Error occurred while fetching the Android device: '" +
|
|
|
|
|
|
|
|
deviceId.getId() + "'", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return device;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
|
|
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
throws DeviceManagementException {
|
|
|
|
Device device;
|
|
|
|
return true;
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Getting the details of Android device : '" + deviceId.getId() + "'");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
MobileDevice mobileDevice = daoFactory.getMobileDeviceDAO().
|
|
|
|
|
|
|
|
getMobileDevice(deviceId.getId());
|
|
|
|
|
|
|
|
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
|
|
|
|
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
|
|
|
|
"Error occurred while fetching the Android device: '" +
|
|
|
|
|
|
|
|
deviceId.getId() + "'", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return device;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
|
|
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
|
|
|
return false;
|
|
|
|
throws DeviceManagementException {
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser,
|
|
|
|
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
|
|
|
EnrolmentInfo.Status status) throws DeviceManagementException {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser,
|
|
|
|
|
|
|
|
EnrolmentInfo.Status status) throws DeviceManagementException {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public License getLicense(String languageCode) throws LicenseManagementException {
|
|
|
|
public License getLicense(String languageCode) throws LicenseManagementException {
|
|
|
|
return licenseManager.getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, languageCode);
|
|
|
|
return licenseManager
|
|
|
|
}
|
|
|
|
.getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, languageCode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void addLicense(License license) throws LicenseManagementException {
|
|
|
|
public void addLicense(License license) throws LicenseManagementException {
|
|
|
|
licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, license);
|
|
|
|
licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, license);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
|
|
|
|
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
|
|
|
|
throws DeviceManagementException {
|
|
|
|
throws DeviceManagementException {
|
|
|
|
boolean status;
|
|
|
|
boolean status;
|
|
|
|
Device existingDevice = this.getDevice(deviceIdentifier);
|
|
|
|
Device existingDevice = this.getDevice(deviceIdentifier);
|
|
|
|
// This object holds the current persisted device object
|
|
|
|
// This object holds the current persisted device object
|
|
|
|
MobileDevice existingMobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(existingDevice);
|
|
|
|
MobileDevice existingMobileDevice =
|
|
|
|
|
|
|
|
MobileDeviceManagementUtil.convertToMobileDevice(existingDevice);
|
|
|
|
|
|
|
|
|
|
|
|
// This object holds the newly received device object from response
|
|
|
|
// This object holds the newly received device object from response
|
|
|
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
|
|
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
|
|
|
|
|
|
|
|
|
|
|
// Updating current object features using newer ones
|
|
|
|
// Updating current object features using newer ones
|
|
|
|
existingMobileDevice.setLatitude(mobileDevice.getLatitude());
|
|
|
|
existingMobileDevice.setLatitude(mobileDevice.getLatitude());
|
|
|
|
existingMobileDevice.setLongitude(mobileDevice.getLongitude());
|
|
|
|
existingMobileDevice.setLongitude(mobileDevice.getLongitude());
|
|
|
|
existingMobileDevice.setDeviceProperties(mobileDevice.getDeviceProperties());
|
|
|
|
existingMobileDevice.setDeviceProperties(mobileDevice.getDeviceProperties());
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("updating the details of Android device : " + device.getDeviceIdentifier());
|
|
|
|
log.debug(
|
|
|
|
}
|
|
|
|
"updating the details of Android device : " + device.getDeviceIdentifier());
|
|
|
|
AndroidDAOFactory.beginTransaction();
|
|
|
|
}
|
|
|
|
status = daoFactory.getMobileDeviceDAO()
|
|
|
|
AndroidDAOFactory.beginTransaction();
|
|
|
|
.updateMobileDevice(existingMobileDevice);
|
|
|
|
status = daoFactory.getMobileDeviceDAO()
|
|
|
|
AndroidDAOFactory.commitTransaction();
|
|
|
|
.updateMobileDevice(existingMobileDevice);
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
AndroidDAOFactory.commitTransaction();
|
|
|
|
try {
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
AndroidDAOFactory.rollbackTransaction();
|
|
|
|
try {
|
|
|
|
} catch (MobileDeviceManagementDAOException e1) {
|
|
|
|
AndroidDAOFactory.rollbackTransaction();
|
|
|
|
log.warn("Error occurred while roll back the update device info transaction : '" +
|
|
|
|
} catch (MobileDeviceManagementDAOException e1) {
|
|
|
|
device.toString() + "'", e1);
|
|
|
|
log.warn("Error occurred while roll back the update device info transaction : '" +
|
|
|
|
}
|
|
|
|
device.toString() + "'", e1);
|
|
|
|
throw new DeviceManagementException("Error occurred while updating the Android device: '" +
|
|
|
|
}
|
|
|
|
device.getDeviceIdentifier() + "'", e);
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
}
|
|
|
|
"Error occurred while updating the Android device: '" +
|
|
|
|
return status;
|
|
|
|
device.getDeviceIdentifier() + "'", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Device> getAllDevices() throws DeviceManagementException {
|
|
|
|
public List<Device> getAllDevices() throws DeviceManagementException {
|
|
|
|
List<Device> devices = null;
|
|
|
|
List<Device> devices = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Fetching the details of all Android devices");
|
|
|
|
log.debug("Fetching the details of all Android devices");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<MobileDevice> mobileDevices =
|
|
|
|
List<MobileDevice> mobileDevices =
|
|
|
|
daoFactory.getMobileDeviceDAO().getAllMobileDevices();
|
|
|
|
daoFactory.getMobileDeviceDAO().getAllMobileDevices();
|
|
|
|
if (mobileDevices != null) {
|
|
|
|
if (mobileDevices != null) {
|
|
|
|
devices = new ArrayList<>();
|
|
|
|
devices = new ArrayList<>();
|
|
|
|
for (MobileDevice mobileDevice : mobileDevices) {
|
|
|
|
for (MobileDevice mobileDevice : mobileDevices) {
|
|
|
|
devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice));
|
|
|
|
devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
throw new DeviceManagementException("Error occurred while fetching all Android devices", e);
|
|
|
|
throw new DeviceManagementException("Error occurred while fetching all Android devices",
|
|
|
|
}
|
|
|
|
e);
|
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return devices;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|