|
|
@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
|
|
|
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.FeatureManagementDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
@ -35,176 +36,180 @@ import java.util.List;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class AndroidDeviceManager implements DeviceManager {
|
|
|
|
public class AndroidDeviceManager implements DeviceManager {
|
|
|
|
|
|
|
|
|
|
|
|
private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory;
|
|
|
|
private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory;
|
|
|
|
private static final Log log = LogFactory.getLog(AndroidDeviceManager.class);
|
|
|
|
private static final Log log = LogFactory.getLog(AndroidDeviceManager.class);
|
|
|
|
|
|
|
|
|
|
|
|
public AndroidDeviceManager() {
|
|
|
|
public AndroidDeviceManager() {
|
|
|
|
mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory(
|
|
|
|
mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory(
|
|
|
|
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
}
|
|
|
|
FeatureManagementDAOFactory
|
|
|
|
|
|
|
|
.init(mobileDeviceManagementDAOFactory.getDataSource(this.getProviderType()));
|
|
|
|
@Override
|
|
|
|
}
|
|
|
|
public String getProviderType() {
|
|
|
|
|
|
|
|
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID;
|
|
|
|
@Override
|
|
|
|
}
|
|
|
|
public String getProviderType() {
|
|
|
|
|
|
|
|
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID;
|
|
|
|
@Override
|
|
|
|
}
|
|
|
|
public FeatureManager getFeatureManager() {
|
|
|
|
|
|
|
|
return new AndroidFeatureManager();
|
|
|
|
@Override
|
|
|
|
}
|
|
|
|
public FeatureManager getFeatureManager() {
|
|
|
|
|
|
|
|
return new AndroidFeatureManager();
|
|
|
|
@Override
|
|
|
|
}
|
|
|
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
|
|
|
|
|
|
|
boolean status;
|
|
|
|
@Override
|
|
|
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
|
|
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
|
|
|
try {
|
|
|
|
boolean status;
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
|
|
|
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice(
|
|
|
|
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
|
|
|
|
mobileDevice);
|
|
|
|
}
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice(
|
|
|
|
String msg = "Error while enrolling the Android device : " +
|
|
|
|
mobileDevice);
|
|
|
|
device.getDeviceIdentifier();
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
log.error(msg, e);
|
|
|
|
String msg = "Error while enrolling the Android device : " +
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
device.getDeviceIdentifier();
|
|
|
|
}
|
|
|
|
log.error(msg, e);
|
|
|
|
return status;
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
@Override
|
|
|
|
}
|
|
|
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
|
|
|
|
|
|
|
boolean status;
|
|
|
|
@Override
|
|
|
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
|
|
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
|
|
|
try {
|
|
|
|
boolean status;
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
|
|
|
log.debug("Modifying the Android device enrollment data");
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
|
|
|
log.debug("Modifying the Android device enrollment data");
|
|
|
|
.updateMobileDevice(mobileDevice);
|
|
|
|
}
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
|
|
|
String msg = "Error while updating the enrollment of the Android device : " +
|
|
|
|
.updateMobileDevice(mobileDevice);
|
|
|
|
device.getDeviceIdentifier();
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
|
|
|
|
boolean status;
|
|
|
|
@Override
|
|
|
|
try {
|
|
|
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
boolean status;
|
|
|
|
log.debug("Dis-enrolling Android device : " + deviceId);
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
|
|
|
log.debug("Dis-enrolling Android device : " + deviceId);
|
|
|
|
.deleteMobileDevice(deviceId.getId());
|
|
|
|
}
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
|
|
|
String msg = "Error while removing the Android device : " + deviceId.getId();
|
|
|
|
.deleteMobileDevice(deviceId.getId());
|
|
|
|
log.error(msg, e);
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
String msg = "Error while removing the Android device : " + deviceId.getId();
|
|
|
|
}
|
|
|
|
log.error(msg, e);
|
|
|
|
return status;
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
@Override
|
|
|
|
}
|
|
|
|
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
|
|
|
|
boolean isEnrolled = false;
|
|
|
|
@Override
|
|
|
|
try {
|
|
|
|
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
boolean isEnrolled = false;
|
|
|
|
log.debug("Checking the enrollment of Android device : " + deviceId.getId());
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
MobileDevice mobileDevice =
|
|
|
|
log.debug("Checking the enrollment of Android device : " + deviceId.getId());
|
|
|
|
mobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice(
|
|
|
|
}
|
|
|
|
deviceId.getId());
|
|
|
|
MobileDevice mobileDevice =
|
|
|
|
if (mobileDevice != null) {
|
|
|
|
mobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice(
|
|
|
|
isEnrolled = true;
|
|
|
|
deviceId.getId());
|
|
|
|
}
|
|
|
|
if (mobileDevice != null) {
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
isEnrolled = true;
|
|
|
|
String msg = "Error while checking the enrollment status of Android device : " +
|
|
|
|
}
|
|
|
|
deviceId.getId();
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
log.error(msg, e);
|
|
|
|
String msg = "Error while checking the enrollment status of Android device : " +
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
deviceId.getId();
|
|
|
|
}
|
|
|
|
log.error(msg, e);
|
|
|
|
return isEnrolled;
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return isEnrolled;
|
|
|
|
@Override
|
|
|
|
}
|
|
|
|
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
@Override
|
|
|
|
}
|
|
|
|
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
@Override
|
|
|
|
}
|
|
|
|
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
|
|
|
|
|
|
|
throws DeviceManagementException {
|
|
|
|
@Override
|
|
|
|
return true;
|
|
|
|
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
|
|
|
}
|
|
|
|
throws DeviceManagementException {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
@Override
|
|
|
|
}
|
|
|
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
|
|
|
|
Device device;
|
|
|
|
@Override
|
|
|
|
try {
|
|
|
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
Device device;
|
|
|
|
log.debug("Getting the details of Android device : " + deviceId.getId());
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
MobileDevice mobileDevice = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().
|
|
|
|
log.debug("Getting the details of Android device : " + deviceId.getId());
|
|
|
|
getMobileDevice(deviceId.getId());
|
|
|
|
}
|
|
|
|
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
|
|
|
|
MobileDevice mobileDevice = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
getMobileDevice(deviceId.getId());
|
|
|
|
String msg = "Error while fetching the Android device : " + deviceId.getId();
|
|
|
|
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
|
|
|
|
log.error(msg, e);
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
String msg = "Error while fetching the Android device : " + deviceId.getId();
|
|
|
|
}
|
|
|
|
log.error(msg, e);
|
|
|
|
return device;
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return device;
|
|
|
|
@Override
|
|
|
|
}
|
|
|
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
|
|
|
|
|
|
|
throws DeviceManagementException {
|
|
|
|
@Override
|
|
|
|
return true;
|
|
|
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
|
|
|
}
|
|
|
|
throws DeviceManagementException {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
@Override
|
|
|
|
}
|
|
|
|
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
|
|
|
|
|
|
|
boolean status;
|
|
|
|
@Override
|
|
|
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
|
|
|
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
|
|
|
try {
|
|
|
|
boolean status;
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
|
|
|
log.debug("updating the details of Android device : " + device.getDeviceIdentifier());
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
|
|
|
log.debug(
|
|
|
|
.updateMobileDevice(mobileDevice);
|
|
|
|
"updating the details of Android device : " + device.getDeviceIdentifier());
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
}
|
|
|
|
String msg = "Error while updating the Android device : " + device.getDeviceIdentifier();
|
|
|
|
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
|
|
|
log.error(msg, e);
|
|
|
|
.updateMobileDevice(mobileDevice);
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
}
|
|
|
|
String msg =
|
|
|
|
return status;
|
|
|
|
"Error while updating the Android device : " + device.getDeviceIdentifier();
|
|
|
|
}
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
@Override
|
|
|
|
}
|
|
|
|
public List<Device> getAllDevices() throws DeviceManagementException {
|
|
|
|
return status;
|
|
|
|
List<Device> devices = null;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
@Override
|
|
|
|
log.debug("Fetching the details of all Android devices");
|
|
|
|
public List<Device> getAllDevices() throws DeviceManagementException {
|
|
|
|
}
|
|
|
|
List<Device> devices = null;
|
|
|
|
List<MobileDevice> mobileDevices =
|
|
|
|
try {
|
|
|
|
mobileDeviceManagementDAOFactory.getMobileDeviceDAO().
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
getAllMobileDevices();
|
|
|
|
log.debug("Fetching the details of all Android devices");
|
|
|
|
if (mobileDevices != null) {
|
|
|
|
}
|
|
|
|
devices = new ArrayList<Device>();
|
|
|
|
List<MobileDevice> mobileDevices =
|
|
|
|
for (MobileDevice mobileDevice : mobileDevices) {
|
|
|
|
mobileDeviceManagementDAOFactory.getMobileDeviceDAO().
|
|
|
|
devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice));
|
|
|
|
getAllMobileDevices();
|
|
|
|
}
|
|
|
|
if (mobileDevices != null) {
|
|
|
|
}
|
|
|
|
devices = new ArrayList<Device>();
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
for (MobileDevice mobileDevice : mobileDevices) {
|
|
|
|
String msg = "Error while fetching all Android devices.";
|
|
|
|
devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice));
|
|
|
|
log.error(msg, e);
|
|
|
|
}
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
return devices;
|
|
|
|
String msg = "Error while fetching all Android devices.";
|
|
|
|
}
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return devices;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|