|
|
@ -21,6 +21,7 @@ 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.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;
|
|
|
@ -131,26 +132,30 @@ public class AndroidDeviceManager implements DeviceManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean enrollDevice(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("Enrolling a new Android device : " + device.getDeviceIdentifier());
|
|
|
|
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean isEnrolled = this.isEnrolled(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
|
|
|
|
|
|
|
if (isEnrolled) {
|
|
|
|
|
|
|
|
this.modifyEnrollment(device);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
AndroidDAOFactory.beginTransaction();
|
|
|
|
AndroidDAOFactory.beginTransaction();
|
|
|
|
status = daoFactory.getMobileDeviceDAO().addMobileDevice(
|
|
|
|
status = daoFactory.getMobileDeviceDAO().addMobileDevice(mobileDevice);
|
|
|
|
mobileDevice);
|
|
|
|
|
|
|
|
AndroidDAOFactory.commitTransaction();
|
|
|
|
AndroidDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
AndroidDAOFactory.rollbackTransaction();
|
|
|
|
AndroidDAOFactory.rollbackTransaction();
|
|
|
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
|
|
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
|
|
|
String msg = "Error occurred while roll back the device enrol transaction :" +
|
|
|
|
String msg = "Error occurred while roll back the device enrol transaction :" + device.toString();
|
|
|
|
device.toString();
|
|
|
|
|
|
|
|
log.warn(msg, mobileDAOEx);
|
|
|
|
log.warn(msg, mobileDAOEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new DeviceManagementException("Error while enrolling the Android device: '" +
|
|
|
|
String msg = "Error while enrolling the Android device : " + device.getDeviceIdentifier();
|
|
|
|
device.getDeviceIdentifier() + "'", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -174,8 +179,10 @@ public class AndroidDeviceManager implements DeviceManager {
|
|
|
|
device.toString();
|
|
|
|
device.toString();
|
|
|
|
log.warn(msg, mobileDAOEx);
|
|
|
|
log.warn(msg, mobileDAOEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new DeviceManagementException("Error while updating the enrollment of the Android device: '" +
|
|
|
|
String msg = "Error while updating the enrollment of the Android device : " +
|
|
|
|
device.getDeviceIdentifier() + "'", e);
|
|
|
|
device.getDeviceIdentifier();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -185,22 +192,22 @@ public class AndroidDeviceManager implements DeviceManager {
|
|
|
|
boolean status;
|
|
|
|
boolean status;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Dis-enrolling Android device: " + deviceId);
|
|
|
|
log.debug("Dis-enrolling Android device : " + deviceId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AndroidDAOFactory.beginTransaction();
|
|
|
|
AndroidDAOFactory.beginTransaction();
|
|
|
|
status = daoFactory.getMobileDeviceDAO()
|
|
|
|
status = daoFactory.getMobileDeviceDAO().deleteMobileDevice(deviceId.getId());
|
|
|
|
.deleteMobileDevice(deviceId.getId());
|
|
|
|
|
|
|
|
AndroidDAOFactory.commitTransaction();
|
|
|
|
AndroidDAOFactory.commitTransaction();
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
AndroidDAOFactory.rollbackTransaction();
|
|
|
|
AndroidDAOFactory.rollbackTransaction();
|
|
|
|
} catch (MobileDeviceManagementDAOException e1) {
|
|
|
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
|
|
|
String msg = "Error occurred while roll back the device dis enrol transaction :" +
|
|
|
|
String msg = "Error occurred while roll back the device dis enrol transaction :" +
|
|
|
|
deviceId.toString();
|
|
|
|
deviceId.toString();
|
|
|
|
log.warn(msg, e1);
|
|
|
|
log.warn(msg, mobileDAOEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new DeviceManagementException("Error occurred while removing the Android device: '" +
|
|
|
|
String msg = "Error while removing the Android device : " + deviceId.getId();
|
|
|
|
deviceId.getId() + "'", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -213,14 +220,15 @@ public class AndroidDeviceManager implements DeviceManager {
|
|
|
|
log.debug("Checking the enrollment of Android device : " + deviceId.getId());
|
|
|
|
log.debug("Checking the enrollment of Android device : " + deviceId.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MobileDevice mobileDevice =
|
|
|
|
MobileDevice mobileDevice =
|
|
|
|
daoFactory.getMobileDeviceDAO().getMobileDevice(
|
|
|
|
daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId());
|
|
|
|
deviceId.getId());
|
|
|
|
|
|
|
|
if (mobileDevice != null) {
|
|
|
|
if (mobileDevice != null) {
|
|
|
|
isEnrolled = true;
|
|
|
|
isEnrolled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
throw new DeviceManagementException("Error occurred while checking the enrollment status of Android " +
|
|
|
|
String msg = "Error while checking the enrollment status of Android device : " +
|
|
|
|
"device: '" + deviceId.getId() + "'", e);
|
|
|
|
deviceId.getId();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return isEnrolled;
|
|
|
|
return isEnrolled;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -270,6 +278,7 @@ public class AndroidDeviceManager implements DeviceManager {
|
|
|
|
return false;
|
|
|
|
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);
|
|
|
@ -284,17 +293,17 @@ public class AndroidDeviceManager implements DeviceManager {
|
|
|
|
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
|
|
|
|
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
|
|
|
|
throws DeviceManagementException {
|
|
|
|
throws DeviceManagementException {
|
|
|
|
boolean status;
|
|
|
|
boolean status;
|
|
|
|
Device deviceDB = 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 mobileDeviceDB = MobileDeviceManagementUtil.convertToMobileDevice(deviceDB);
|
|
|
|
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
|
|
|
|
mobileDeviceDB.setLatitude(mobileDevice.getLatitude());
|
|
|
|
existingMobileDevice.setLatitude(mobileDevice.getLatitude());
|
|
|
|
mobileDeviceDB.setLongitude(mobileDevice.getLongitude());
|
|
|
|
existingMobileDevice.setLongitude(mobileDevice.getLongitude());
|
|
|
|
mobileDeviceDB.setDeviceProperties(mobileDevice.getDeviceProperties());
|
|
|
|
existingMobileDevice.setDeviceProperties(mobileDevice.getDeviceProperties());
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
@ -302,7 +311,7 @@ public class AndroidDeviceManager implements DeviceManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AndroidDAOFactory.beginTransaction();
|
|
|
|
AndroidDAOFactory.beginTransaction();
|
|
|
|
status = daoFactory.getMobileDeviceDAO()
|
|
|
|
status = daoFactory.getMobileDeviceDAO()
|
|
|
|
.updateMobileDevice(mobileDeviceDB);
|
|
|
|
.updateMobileDevice(existingMobileDevice);
|
|
|
|
AndroidDAOFactory.commitTransaction();
|
|
|
|
AndroidDAOFactory.commitTransaction();
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|