revert-dabc3590
milanperera 9 years ago
commit b0bc3ff3f1

@ -76,7 +76,7 @@
org.wso2.carbon.registry.core.service, org.wso2.carbon.registry.core.service,
org.wso2.carbon.registry.core.session, org.wso2.carbon.registry.core.session,
org.wso2.carbon.registry.api, org.wso2.carbon.registry.api,
org.wso2.carbon.device.mgt.extensions.license.mgt org.wso2.carbon.device.mgt.extensions.license.mgt.registry
</Import-Package> </Import-Package>
<Export-Package> <Export-Package>
!org.wso2.carbon.device.mgt.mobile.internal, !org.wso2.carbon.device.mgt.mobile.internal,

@ -19,6 +19,7 @@
package org.wso2.carbon.device.mgt.mobile.dto; package org.wso2.carbon.device.mgt.mobile.dto;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
@ -37,6 +38,10 @@ public class MobileDevice implements Serializable {
private String serial; private String serial;
private Map<String, String> deviceProperties; private Map<String, String> deviceProperties;
public MobileDevice() {
this.deviceProperties = new HashMap<>();
}
public String getMobileDeviceId() { public String getMobileDeviceId() {
return mobileDeviceId; return mobileDeviceId;
} }

@ -27,12 +27,13 @@ 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;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; 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.extensions.license.mgt.registry.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.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.Collection;
import org.wso2.carbon.registry.api.RegistryException; import org.wso2.carbon.registry.api.RegistryException;
@ -43,14 +44,21 @@ import java.util.List;
public class AndroidDeviceManager implements DeviceManager { public class AndroidDeviceManager implements DeviceManager {
private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; 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() { public AndroidDeviceManager() {
this.mobileDeviceManagementDAOFactory = new AndroidDAOFactory(); this.daoFactory = new AndroidDAOFactory();
this.licenseManager = new RegistryBasedLicenseManager(); this.licenseManager = new RegistryBasedLicenseManager();
License defaultLicense = AndroidPluginUtils.getDefaultLicense();
try {
licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, defaultLicense);
} catch (LicenseManagementException e) {
log.error("Error occurred while adding default license for Android devices", e);
}
} }
@Override @Override
@ -89,9 +97,9 @@ public class AndroidDeviceManager implements DeviceManager {
@Override @Override
public TenantConfiguration getConfiguration() throws DeviceManagementException { public TenantConfiguration getConfiguration() throws DeviceManagementException {
Collection dsCollection = null; Collection dsCollection;
TenantConfiguration tenantConfiguration; TenantConfiguration tenantConfiguration;
List<ConfigurationEntry> configs = new ArrayList<ConfigurationEntry>(); List<ConfigurationEntry> configs = new ArrayList<>();
ConfigurationEntry entry; ConfigurationEntry entry;
Resource resource; Resource resource;
try { try {
@ -135,7 +143,7 @@ public class AndroidDeviceManager implements DeviceManager {
this.modifyEnrollment(device); this.modifyEnrollment(device);
} else { } else {
AndroidDAOFactory.beginTransaction(); AndroidDAOFactory.beginTransaction();
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( status = daoFactory.getMobileDeviceDAO().addMobileDevice(
mobileDevice); mobileDevice);
AndroidDAOFactory.commitTransaction(); AndroidDAOFactory.commitTransaction();
} }
@ -162,7 +170,7 @@ public class AndroidDeviceManager implements DeviceManager {
log.debug("Modifying the Android device enrollment data"); log.debug("Modifying the Android device enrollment data");
} }
AndroidDAOFactory.beginTransaction(); AndroidDAOFactory.beginTransaction();
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() status = daoFactory.getMobileDeviceDAO()
.updateMobileDevice(mobileDevice); .updateMobileDevice(mobileDevice);
AndroidDAOFactory.commitTransaction(); AndroidDAOFactory.commitTransaction();
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
@ -189,7 +197,7 @@ public class AndroidDeviceManager implements DeviceManager {
log.debug("Dis-enrolling Android device : " + deviceId); log.debug("Dis-enrolling Android device : " + deviceId);
} }
AndroidDAOFactory.beginTransaction(); AndroidDAOFactory.beginTransaction();
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() status = daoFactory.getMobileDeviceDAO()
.deleteMobileDevice(deviceId.getId()); .deleteMobileDevice(deviceId.getId());
AndroidDAOFactory.commitTransaction(); AndroidDAOFactory.commitTransaction();
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
@ -215,7 +223,7 @@ 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 =
mobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice( daoFactory.getMobileDeviceDAO().getMobileDevice(
deviceId.getId()); deviceId.getId());
if (mobileDevice != null) { if (mobileDevice != null) {
isEnrolled = true; isEnrolled = true;
@ -245,15 +253,14 @@ public class AndroidDeviceManager implements DeviceManager {
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 = daoFactory.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(); throw new DeviceManagementException("Error occurred while fetching the Android device: '" +
log.error(msg, e); deviceId.getId() + "'", e);
throw new DeviceManagementException(msg, e);
} }
return device; return device;
} }
@ -304,25 +311,21 @@ public class AndroidDeviceManager implements DeviceManager {
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug( log.debug("updating the details of Android device : " + device.getDeviceIdentifier());
"updating the details of Android device : " + device.getDeviceIdentifier());
} }
AndroidDAOFactory.beginTransaction(); AndroidDAOFactory.beginTransaction();
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() status = daoFactory.getMobileDeviceDAO()
.updateMobileDevice(existingMobileDevice); .updateMobileDevice(existingMobileDevice);
AndroidDAOFactory.commitTransaction(); AndroidDAOFactory.commitTransaction();
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
try { try {
AndroidDAOFactory.rollbackTransaction(); AndroidDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) { } catch (MobileDeviceManagementDAOException e1) {
String msg = "Error occurred while roll back the update device info transaction :" + log.warn("Error occurred while roll back the update device info transaction : '" +
device.toString(); device.toString() + "'", e1);
log.warn(msg, mobileDAOEx);
} }
String msg = throw new DeviceManagementException("Error occurred while updating the Android device: '" +
"Error while updating the Android device : " + device.getDeviceIdentifier(); device.getDeviceIdentifier() + "'", e);
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} }
return status; return status;
} }
@ -335,18 +338,15 @@ public class AndroidDeviceManager implements DeviceManager {
log.debug("Fetching the details of all Android devices"); log.debug("Fetching the details of all Android devices");
} }
List<MobileDevice> mobileDevices = List<MobileDevice> mobileDevices =
mobileDeviceManagementDAOFactory.getMobileDeviceDAO(). daoFactory.getMobileDeviceDAO().getAllMobileDevices();
getAllMobileDevices();
if (mobileDevices != null) { if (mobileDevices != null) {
devices = new ArrayList<Device>(); 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) {
String msg = "Error while fetching all Android devices."; throw new DeviceManagementException("Error occurred while fetching all Android devices", e);
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} }
return devices; return devices;
} }

@ -19,17 +19,24 @@
package org.wso2.carbon.device.mgt.mobile.impl.android; package org.wso2.carbon.device.mgt.mobile.impl.android;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService; import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class AndroidPolicyMonitoringService implements PolicyMonitoringService { public class AndroidPolicyMonitoringService implements PolicyMonitoringService {
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 {
@ -37,8 +44,25 @@ public class AndroidPolicyMonitoringService implements PolicyMonitoringService {
@Override @Override
public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object o) throws PolicyComplianceException { public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object o) throws PolicyComplianceException {
ComplianceData complianceData = new ComplianceData();
if (log.isDebugEnabled()) {
log.info("Checking policy compliance status of device '" + deviceIdentifier.getId() + "'");
}
if (o == null || policy == null) {
return null; return null;
} }
List<ComplianceFeature> complianceFeatures = (List<ComplianceFeature>) o;
log.info("size of list: " + complianceFeatures.size());
complianceData.setComplianceFeatures(complianceFeatures);
for (ComplianceFeature cf : complianceFeatures) {
if(!cf.isCompliance()){
complianceData.setStatus(false);
break;
}
}
return complianceData;
}
@Override @Override
public String getType() { public String getType() {

@ -22,14 +22,11 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceDAO; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceDAO;
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.util.MobileDeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
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.AndroidPluginConstants;
import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidUtils;
import javax.sql.DataSource;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -47,12 +44,11 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
private static final Log log = LogFactory.getLog(AndroidDeviceDAOImpl.class); private static final Log log = LogFactory.getLog(AndroidDeviceDAOImpl.class);
@Override @Override
public MobileDevice getMobileDevice(String mblDeviceId) public MobileDevice getMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException {
throws MobileDeviceManagementDAOException { Connection conn;
Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
MobileDevice mobileDevice = null; MobileDevice mobileDevice = null;
ResultSet resultSet = null; ResultSet rs = null;
try { try {
conn = AndroidDAOFactory.getConnection(); conn = AndroidDAOFactory.getConnection();
String selectDBQuery = String selectDBQuery =
@ -61,29 +57,25 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
" FROM AD_DEVICE WHERE ANDROID_DEVICE_ID = ?"; " FROM AD_DEVICE WHERE ANDROID_DEVICE_ID = ?";
stmt = conn.prepareStatement(selectDBQuery); stmt = conn.prepareStatement(selectDBQuery);
stmt.setString(1, mblDeviceId); stmt.setString(1, mblDeviceId);
resultSet = stmt.executeQuery(); rs = stmt.executeQuery();
if (resultSet.next()) { if (rs.next()) {
mobileDevice = new MobileDevice(); mobileDevice = new MobileDevice();
mobileDevice.setMobileDeviceId(resultSet.getString(AndroidPluginConstants. mobileDevice.setMobileDeviceId(rs.getString(AndroidPluginConstants.
ANDROID_DEVICE_ID)); ANDROID_DEVICE_ID));
mobileDevice.setModel(resultSet.getString(AndroidPluginConstants.DEVICE_MODEL)); mobileDevice.setModel(rs.getString(AndroidPluginConstants.DEVICE_MODEL));
mobileDevice.setSerial(resultSet.getString(AndroidPluginConstants.SERIAL)); mobileDevice.setSerial(rs.getString(AndroidPluginConstants.SERIAL));
mobileDevice.setVendor(resultSet.getString(AndroidPluginConstants.VENDOR)); mobileDevice.setVendor(rs.getString(AndroidPluginConstants.VENDOR));
mobileDevice.setLatitude(resultSet.getString(AndroidPluginConstants.LATITUDE)); mobileDevice.setLatitude(rs.getString(AndroidPluginConstants.LATITUDE));
mobileDevice.setLongitude(resultSet.getString(AndroidPluginConstants.LONGITUDE)); mobileDevice.setLongitude(rs.getString(AndroidPluginConstants.LONGITUDE));
mobileDevice.setImei(resultSet.getString(AndroidPluginConstants.IMEI)); mobileDevice.setImei(rs.getString(AndroidPluginConstants.IMEI));
mobileDevice.setImsi(resultSet.getString(AndroidPluginConstants.IMSI)); mobileDevice.setImsi(rs.getString(AndroidPluginConstants.IMSI));
mobileDevice.setOsVersion(resultSet.getString(AndroidPluginConstants.OS_VERSION)); mobileDevice.setOsVersion(rs.getString(AndroidPluginConstants.OS_VERSION));
Map<String, String> propertyMap = new HashMap<String, String>(); Map<String, String> propertyMap = new HashMap<String, String>();
propertyMap.put(AndroidPluginConstants.GCM_TOKEN, propertyMap.put(AndroidPluginConstants.GCM_TOKEN, rs.getString(AndroidPluginConstants.GCM_TOKEN));
resultSet.getString(AndroidPluginConstants.GCM_TOKEN)); propertyMap.put(AndroidPluginConstants.DEVICE_INFO, rs.getString(AndroidPluginConstants.DEVICE_INFO));
propertyMap.put(AndroidPluginConstants.DEVICE_INFO, propertyMap.put(AndroidPluginConstants.DEVICE_NAME, rs.getString(AndroidPluginConstants.DEVICE_NAME));
resultSet.getString(AndroidPluginConstants.DEVICE_INFO));
propertyMap.put(AndroidPluginConstants.DEVICE_NAME,
resultSet.getString(AndroidPluginConstants.DEVICE_NAME));
mobileDevice.setDeviceProperties(propertyMap); mobileDevice.setDeviceProperties(propertyMap);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -96,7 +88,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {
MobileDeviceManagementDAOUtil.cleanupResources(stmt, resultSet); MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
AndroidDAOFactory.closeConnection(); AndroidDAOFactory.closeConnection();
} }
@ -104,10 +96,9 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
} }
@Override @Override
public boolean addMobileDevice(MobileDevice mobileDevice) public boolean addMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException {
throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
Connection conn = null; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
conn = AndroidDAOFactory.getConnection(); conn = AndroidDAOFactory.getConnection();
@ -119,19 +110,13 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
stmt = conn.prepareStatement(createDBQuery); stmt = conn.prepareStatement(createDBQuery);
stmt.setString(1, mobileDevice.getMobileDeviceId()); stmt.setString(1, mobileDevice.getMobileDeviceId());
if (mobileDevice.getDeviceProperties() == null) { Map<String, String> properties = mobileDevice.getDeviceProperties();
mobileDevice.setDeviceProperties(new HashMap<String, String>()); stmt.setString(2, properties.get(AndroidPluginConstants.GCM_TOKEN));
} stmt.setString(3, properties.get(AndroidPluginConstants.DEVICE_INFO));
stmt.setString(2, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(),
AndroidPluginConstants.GCM_TOKEN));
stmt.setString(3, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(),
AndroidPluginConstants.DEVICE_INFO));
stmt.setString(4, mobileDevice.getSerial()); stmt.setString(4, mobileDevice.getSerial());
stmt.setString(5, mobileDevice.getVendor()); stmt.setString(5, mobileDevice.getVendor());
stmt.setString(6, mobileDevice.getMobileDeviceId()); stmt.setString(6, mobileDevice.getMobileDeviceId());
stmt.setString(7, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), stmt.setString(7, properties.get(AndroidPluginConstants.DEVICE_NAME));
AndroidPluginConstants.DEVICE_NAME));
stmt.setString(8, mobileDevice.getLongitude()); stmt.setString(8, mobileDevice.getLongitude());
stmt.setString(9, mobileDevice.getLongitude()); stmt.setString(9, mobileDevice.getLongitude());
stmt.setString(10, mobileDevice.getImei()); stmt.setString(10, mobileDevice.getImei());
@ -147,10 +132,8 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while adding the Android device '" + throw new MobileDeviceManagementDAOException("Error occurred while adding the Android device '" +
mobileDevice.getMobileDeviceId() + "' to the Android db."; mobileDevice.getMobileDeviceId() + "' information to the Android plugin data store.", e);
log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
} }
@ -158,10 +141,9 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
} }
@Override @Override
public boolean updateMobileDevice(MobileDevice mobileDevice) public boolean updateMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException {
throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
Connection conn = null; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
conn = AndroidDAOFactory.getConnection(); conn = AndroidDAOFactory.getConnection();
@ -169,23 +151,15 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
"UPDATE AD_DEVICE SET GCM_TOKEN = ?, DEVICE_INFO = ?, SERIAL = ?, VENDOR = ?, " + "UPDATE AD_DEVICE SET GCM_TOKEN = ?, DEVICE_INFO = ?, SERIAL = ?, VENDOR = ?, " +
"MAC_ADDRESS = ?, DEVICE_NAME = ?, LATITUDE = ?, LONGITUDE = ?, IMEI = ?, " + "MAC_ADDRESS = ?, DEVICE_NAME = ?, LATITUDE = ?, LONGITUDE = ?, IMEI = ?, " +
"IMSI = ?, OS_VERSION = ?, DEVICE_MODEL = ? WHERE ANDROID_DEVICE_ID = ?"; "IMSI = ?, OS_VERSION = ?, DEVICE_MODEL = ? WHERE ANDROID_DEVICE_ID = ?";
stmt = conn.prepareStatement(updateDBQuery); stmt = conn.prepareStatement(updateDBQuery);
if (mobileDevice.getDeviceProperties() == null) { Map<String, String> properties = mobileDevice.getDeviceProperties();
mobileDevice.setDeviceProperties(new HashMap<String, String>()); stmt.setString(1, properties.get(AndroidPluginConstants.GCM_TOKEN));
} stmt.setString(2, properties.get(AndroidPluginConstants.DEVICE_INFO));
stmt.setString(1, AndroidUtils.getDeviceProperty(
mobileDevice.getDeviceProperties(),
AndroidPluginConstants.GCM_TOKEN));
stmt.setString(2, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(),
AndroidPluginConstants.DEVICE_INFO));
stmt.setString(3, mobileDevice.getSerial()); stmt.setString(3, mobileDevice.getSerial());
stmt.setString(4, mobileDevice.getVendor()); stmt.setString(4, mobileDevice.getVendor());
stmt.setString(5, mobileDevice.getMobileDeviceId()); stmt.setString(5, mobileDevice.getMobileDeviceId());
stmt.setString(6, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), stmt.setString(6, properties.get(AndroidPluginConstants.DEVICE_NAME));
AndroidPluginConstants.DEVICE_NAME));
stmt.setString(7, mobileDevice.getLatitude()); stmt.setString(7, mobileDevice.getLatitude());
stmt.setString(8, mobileDevice.getLongitude()); stmt.setString(8, mobileDevice.getLongitude());
stmt.setString(9, mobileDevice.getImei()); stmt.setString(9, mobileDevice.getImei());
@ -216,7 +190,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
public boolean deleteMobileDevice(String mblDeviceId) public boolean deleteMobileDevice(String mblDeviceId)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
Connection conn = null; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
conn = AndroidDAOFactory.getConnection(); conn = AndroidDAOFactory.getConnection();
@ -233,9 +207,8 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while deleting android device " + mblDeviceId; throw new MobileDeviceManagementDAOException("Error occurred while deleting android device '" +
log.error(msg, e); mblDeviceId + "'", e);
throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
} }
@ -243,15 +216,12 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
} }
@Override @Override
public List<MobileDevice> getAllMobileDevices() public List<MobileDevice> getAllMobileDevices() throws MobileDeviceManagementDAOException {
throws MobileDeviceManagementDAOException { Connection conn;
Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet resultSet = null; ResultSet rs = null;
MobileDevice mobileDevice; MobileDevice mobileDevice;
List<MobileDevice> mobileDevices = new ArrayList<MobileDevice>(); List<MobileDevice> mobileDevices = new ArrayList<MobileDevice>();
try { try {
conn = AndroidDAOFactory.getConnection(); conn = AndroidDAOFactory.getConnection();
String selectDBQuery = String selectDBQuery =
@ -259,29 +229,27 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION " + "VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION " +
"FROM AD_DEVICE"; "FROM AD_DEVICE";
stmt = conn.prepareStatement(selectDBQuery); stmt = conn.prepareStatement(selectDBQuery);
resultSet = stmt.executeQuery(); rs = stmt.executeQuery();
while (resultSet.next()) {
while (rs.next()) {
mobileDevice = new MobileDevice(); mobileDevice = new MobileDevice();
mobileDevice.setMobileDeviceId(resultSet.getString(AndroidPluginConstants. mobileDevice.setMobileDeviceId(rs.getString(AndroidPluginConstants.
ANDROID_DEVICE_ID)); ANDROID_DEVICE_ID));
mobileDevice.setModel(resultSet.getString(AndroidPluginConstants.DEVICE_MODEL)); mobileDevice.setModel(rs.getString(AndroidPluginConstants.DEVICE_MODEL));
mobileDevice.setSerial(resultSet.getString(AndroidPluginConstants.SERIAL)); mobileDevice.setSerial(rs.getString(AndroidPluginConstants.SERIAL));
mobileDevice.setVendor(resultSet.getString(AndroidPluginConstants.VENDOR)); mobileDevice.setVendor(rs.getString(AndroidPluginConstants.VENDOR));
mobileDevice.setLatitude(resultSet.getString(AndroidPluginConstants.LATITUDE)); mobileDevice.setLatitude(rs.getString(AndroidPluginConstants.LATITUDE));
mobileDevice.setLongitude(resultSet.getString(AndroidPluginConstants.LONGITUDE)); mobileDevice.setLongitude(rs.getString(AndroidPluginConstants.LONGITUDE));
mobileDevice.setImei(resultSet.getString(AndroidPluginConstants.IMEI)); mobileDevice.setImei(rs.getString(AndroidPluginConstants.IMEI));
mobileDevice.setImsi(resultSet.getString(AndroidPluginConstants.IMSI)); mobileDevice.setImsi(rs.getString(AndroidPluginConstants.IMSI));
mobileDevice.setOsVersion(resultSet.getString(AndroidPluginConstants.OS_VERSION)); mobileDevice.setOsVersion(rs.getString(AndroidPluginConstants.OS_VERSION));
Map<String, String> propertyMap = new HashMap<String, String>(); Map<String, String> propertyMap = new HashMap<String, String>();
propertyMap.put(AndroidPluginConstants.GCM_TOKEN, propertyMap.put(AndroidPluginConstants.GCM_TOKEN, rs.getString(AndroidPluginConstants.GCM_TOKEN));
resultSet.getString(AndroidPluginConstants.GCM_TOKEN)); propertyMap.put(AndroidPluginConstants.DEVICE_INFO, rs.getString(AndroidPluginConstants.DEVICE_INFO));
propertyMap.put(AndroidPluginConstants.DEVICE_INFO, propertyMap.put(AndroidPluginConstants.DEVICE_NAME, rs.getString(AndroidPluginConstants.DEVICE_NAME));
resultSet.getString(AndroidPluginConstants.DEVICE_INFO));
propertyMap.put(AndroidPluginConstants.DEVICE_NAME,
resultSet.getString(AndroidPluginConstants.DEVICE_NAME));
mobileDevice.setDeviceProperties(propertyMap); mobileDevice.setDeviceProperties(propertyMap);
mobileDevices.add(mobileDevice); mobileDevices.add(mobileDevice);
} }
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -289,11 +257,9 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
} }
return mobileDevices; return mobileDevices;
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while fetching all Android device data'"; throw new MobileDeviceManagementDAOException("Error occurred while fetching all Android device data", e);
log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {
MobileDeviceManagementDAOUtil.cleanupResources(stmt, resultSet); MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
AndroidDAOFactory.closeConnection(); AndroidDAOFactory.closeConnection();
} }
} }

@ -0,0 +1,58 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.mobile.impl.android.util;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagementService;
/**
* Contains utility methods used by Android plugin.
*/
public class AndroidPluginUtils {
public static License getDefaultLicense() {
License license = new License();
license.setName(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID);
license.setLanguage("en_US");
license.setVersion("1.0.0");
license.setText("This End User License Agreement (“Agreement”) is a legal agreement between you (“You”) " +
"and WSO2, Inc., regarding the enrollment of Your personal mobile device (“Device”) in SoRs " +
"mobile device management program, and the loading to and removal from Your Device and Your use " +
"of certain applications and any associated software and user documentation, whether provided in " +
"“online” or electronic format, used in connection with the operation of or provision of services " +
"to WSO2, Inc., BY SELECTING “I ACCEPT” DURING INSTALLATION, YOU ARE ENROLLING YOUR DEVICE, AND " +
"THEREBY AUTHORIZING SOR OR ITS AGENTS TO INSTALL, UPDATE AND REMOVE THE APPS FROM YOUR DEVICE AS " +
"DESCRIBED IN THIS AGREEMENT. YOU ARE ALSO EXPLICITLY ACKNOWLEDGING AND AGREEING THAT (1) THIS IS " +
"A BINDING CONTRACT AND (2) YOU HAVE READ AND AGREE TO THE TERMS OF THIS AGREEMENT.\n" +
"\n" +
"IF YOU DO NOT ACCEPT THESE TERMS, DO NOT ENROLL YOUR DEVICE AND DO NOT PROCEED ANY FURTHER.\n" +
"\n" +
"You agree that: (1) You understand and agree to be bound by the terms and conditions contained " +
"in this Agreement, and (2) You are at least 21 years old and have the legal capacity to enter " +
"into this Agreement as defined by the laws of Your jurisdiction. SoR shall have the right, " +
"without prior notice, to terminate or suspend (i) this Agreement, (ii) the enrollment of Your " +
"Device, or (iii) the functioning of the Apps in the event of a violation of this Agreement or " +
"the cessation of Your relationship with SoR (including termination of Your employment if You are " +
"an employee or expiration or termination of Your applicable franchise or supply agreement if You " +
"are a franchisee of or supplier to the WSO2 WSO2, Inc., system). SoR expressly reserves all " +
"rights not expressly granted herein.");
return license;
}
}

@ -25,7 +25,7 @@ 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;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; 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.extensions.license.mgt.registry.RegistryBasedLicenseManager;
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;

Loading…
Cancel
Save