|
|
@ -25,13 +25,18 @@ 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;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.license.mgt.RegistryBasedLicenseManager;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException;
|
|
|
|
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.AndroidDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementDataHolder;
|
|
|
|
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.Collection;
|
|
|
|
|
|
|
|
import org.wso2.carbon.registry.api.Registry;
|
|
|
|
import org.wso2.carbon.registry.api.Resource;
|
|
|
|
import org.wso2.carbon.registry.api.Resource;
|
|
|
|
import org.wso2.carbon.registry.api.RegistryException;
|
|
|
|
import org.wso2.carbon.registry.api.RegistryException;
|
|
|
|
|
|
|
|
|
|
|
@ -40,48 +45,56 @@ 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(AndroidDeviceManagementService.class);
|
|
|
|
private static final Log log = LogFactory.getLog(AndroidDeviceManagementService.class);
|
|
|
|
private FeatureManager featureManager = new AndroidFeatureManager();
|
|
|
|
private FeatureManager featureManager = new AndroidFeatureManager();
|
|
|
|
private License license;
|
|
|
|
private LicenseManager licenseManager;
|
|
|
|
|
|
|
|
|
|
|
|
public AndroidDeviceManager() {
|
|
|
|
public AndroidDeviceManager() {
|
|
|
|
mobileDeviceManagementDAOFactory = new AndroidDAOFactory();
|
|
|
|
this.mobileDeviceManagementDAOFactory = new AndroidDAOFactory();
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
|
|
|
|
Registry registry =
|
|
|
|
|
|
|
|
MobileDeviceManagementDataHolder.getInstance().getRegistryService().getConfigSystemRegistry();
|
|
|
|
|
|
|
|
this.licenseManager = new RegistryBasedLicenseManager(registry);
|
|
|
|
|
|
|
|
} catch (org.wso2.carbon.registry.core.exceptions.RegistryException e) {
|
|
|
|
|
|
|
|
throw new IllegalStateException("Error occurred while retrieving config system registry of the tenant, " +
|
|
|
|
|
|
|
|
"which in turns fails the initialization of Android Device Manager", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public FeatureManager getFeatureManager() {
|
|
|
|
public FeatureManager getFeatureManager() {
|
|
|
|
return featureManager;
|
|
|
|
return featureManager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
|
|
|
|
public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
|
|
|
|
throws DeviceManagementException {
|
|
|
|
throws DeviceManagementException {
|
|
|
|
boolean status = false;
|
|
|
|
boolean status = false;
|
|
|
|
Resource resource;
|
|
|
|
Resource resource;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Persisting android configurations in Registry");
|
|
|
|
log.debug("Persisting android configurations in Registry");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath(
|
|
|
|
String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath(
|
|
|
|
DeviceManagementConstants.
|
|
|
|
DeviceManagementConstants.
|
|
|
|
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
MobileDeviceManagementUtil.createRegistryCollection(resourcePath);
|
|
|
|
MobileDeviceManagementUtil.createRegistryCollection(resourcePath);
|
|
|
|
for (ConfigurationEntry configEntry : tenantConfiguration.getConfiguration()) {
|
|
|
|
for (ConfigurationEntry configEntry : tenantConfiguration.getConfiguration()) {
|
|
|
|
resource = MobileDeviceManagementUtil.getRegistry().newResource();
|
|
|
|
resource = MobileDeviceManagementUtil.getRegistry().newResource();
|
|
|
|
resource.setContent(configEntry.getValue());
|
|
|
|
resource.setContent(configEntry.getValue());
|
|
|
|
MobileDeviceManagementUtil.putRegistryResource(resourcePath + "/" + configEntry.getName(), resource);
|
|
|
|
MobileDeviceManagementUtil.putRegistryResource(resourcePath + "/" + configEntry.getName(), resource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
status = true;
|
|
|
|
status = true;
|
|
|
|
} catch (MobileDeviceMgtPluginException e) {
|
|
|
|
} catch (MobileDeviceMgtPluginException e) {
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
|
|
|
|
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
|
|
|
|
} catch (RegistryException e) {
|
|
|
|
} catch (RegistryException e) {
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
"Error occurred while persisting the Registry resource : " + e.getMessage(), e);
|
|
|
|
"Error occurred while persisting the Registry resource : " + e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public TenantConfiguration getConfiguration() throws DeviceManagementException {
|
|
|
|
public TenantConfiguration getConfiguration() throws DeviceManagementException {
|
|
|
@ -223,45 +236,45 @@ public class AndroidDeviceManager implements DeviceManager {
|
|
|
|
return isEnrolled;
|
|
|
|
return isEnrolled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
|
|
|
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
|
|
|
throws DeviceManagementException {
|
|
|
|
throws DeviceManagementException {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
Device device;
|
|
|
|
Device device;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Getting the details of Android device : " + deviceId.getId());
|
|
|
|
log.debug("Getting the details of Android device : " + deviceId.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MobileDevice mobileDevice = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().
|
|
|
|
MobileDevice mobileDevice = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().
|
|
|
|
getMobileDevice(deviceId.getId());
|
|
|
|
getMobileDevice(deviceId.getId());
|
|
|
|
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
|
|
|
|
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
String msg = "Error while fetching the Android device : " + deviceId.getId();
|
|
|
|
String msg = "Error while fetching the Android device : " + deviceId.getId();
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return device;
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
|
|
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
|
|
|
throws DeviceManagementException {
|
|
|
|
throws DeviceManagementException {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
|
|
|
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser,
|
|
|
|
public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser,
|
|
|
@ -269,69 +282,80 @@ public class AndroidDeviceManager implements DeviceManager {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
|
|
|
|
|
|
|
|
throws DeviceManagementException {
|
|
|
|
|
|
|
|
boolean status;
|
|
|
|
|
|
|
|
Device deviceDB = this.getDevice(deviceIdentifier);
|
|
|
|
|
|
|
|
// This object holds the current persisted device object
|
|
|
|
|
|
|
|
MobileDevice mobileDeviceDB = MobileDeviceManagementUtil.convertToMobileDevice(deviceDB);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This object holds the newly received device object from response
|
|
|
|
@Override
|
|
|
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
|
|
|
public License getLicense(String languageCode) throws LicenseManagementException {
|
|
|
|
|
|
|
|
return licenseManager.getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, languageCode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Updating current object features using newer ones
|
|
|
|
@Override
|
|
|
|
mobileDeviceDB.setLatitude(mobileDevice.getLatitude());
|
|
|
|
public void addLicense(License license) throws LicenseManagementException {
|
|
|
|
mobileDeviceDB.setLongitude(mobileDevice.getLongitude());
|
|
|
|
licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, license);
|
|
|
|
mobileDeviceDB.setDeviceProperties(mobileDevice.getDeviceProperties());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
@Override
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
|
|
|
|
log.debug(
|
|
|
|
throws DeviceManagementException {
|
|
|
|
"updating the details of Android device : " + device.getDeviceIdentifier());
|
|
|
|
boolean status;
|
|
|
|
}
|
|
|
|
Device deviceDB = this.getDevice(deviceIdentifier);
|
|
|
|
AndroidDAOFactory.beginTransaction();
|
|
|
|
// This object holds the current persisted device object
|
|
|
|
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
|
|
|
MobileDevice mobileDeviceDB = MobileDeviceManagementUtil.convertToMobileDevice(deviceDB);
|
|
|
|
.updateMobileDevice(mobileDeviceDB);
|
|
|
|
|
|
|
|
AndroidDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
AndroidDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while roll back the update device info transaction :" +
|
|
|
|
|
|
|
|
device.toString();
|
|
|
|
|
|
|
|
log.warn(msg, mobileDAOEx);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String msg =
|
|
|
|
|
|
|
|
"Error while updating the Android device : " + device.getDeviceIdentifier();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
// This object holds the newly received device object from response
|
|
|
|
public List<Device> getAllDevices() throws DeviceManagementException {
|
|
|
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
|
|
|
List<Device> devices = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Updating current object features using newer ones
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
mobileDeviceDB.setLatitude(mobileDevice.getLatitude());
|
|
|
|
log.debug("Fetching the details of all Android devices");
|
|
|
|
mobileDeviceDB.setLongitude(mobileDevice.getLongitude());
|
|
|
|
}
|
|
|
|
mobileDeviceDB.setDeviceProperties(mobileDevice.getDeviceProperties());
|
|
|
|
List<MobileDevice> mobileDevices =
|
|
|
|
|
|
|
|
mobileDeviceManagementDAOFactory.getMobileDeviceDAO().
|
|
|
|
try {
|
|
|
|
getAllMobileDevices();
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (mobileDevices != null) {
|
|
|
|
log.debug(
|
|
|
|
devices = new ArrayList<Device>();
|
|
|
|
"updating the details of Android device : " + device.getDeviceIdentifier());
|
|
|
|
for (MobileDevice mobileDevice : mobileDevices) {
|
|
|
|
}
|
|
|
|
devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice));
|
|
|
|
AndroidDAOFactory.beginTransaction();
|
|
|
|
}
|
|
|
|
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
|
|
|
}
|
|
|
|
.updateMobileDevice(mobileDeviceDB);
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
AndroidDAOFactory.commitTransaction();
|
|
|
|
String msg = "Error while fetching all Android devices.";
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
log.error(msg, e);
|
|
|
|
try {
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
AndroidDAOFactory.rollbackTransaction();
|
|
|
|
}
|
|
|
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
|
|
|
return devices;
|
|
|
|
String msg = "Error occurred while roll back the update device info transaction :" +
|
|
|
|
}
|
|
|
|
device.toString();
|
|
|
|
|
|
|
|
log.warn(msg, mobileDAOEx);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String msg =
|
|
|
|
|
|
|
|
"Error while updating the Android device : " + device.getDeviceIdentifier();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<Device> getAllDevices() throws DeviceManagementException {
|
|
|
|
|
|
|
|
List<Device> devices = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Fetching the details of all Android devices");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<MobileDevice> mobileDevices =
|
|
|
|
|
|
|
|
mobileDeviceManagementDAOFactory.getMobileDeviceDAO().
|
|
|
|
|
|
|
|
getAllMobileDevices();
|
|
|
|
|
|
|
|
if (mobileDevices != null) {
|
|
|
|
|
|
|
|
devices = new ArrayList<Device>();
|
|
|
|
|
|
|
|
for (MobileDevice mobileDevice : mobileDevices) {
|
|
|
|
|
|
|
|
devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error while fetching all Android devices.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return devices;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|