diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index e9c4e1bf9e..f07d667b43 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -855,4 +855,13 @@ public interface DeviceDAO { * @throws DeviceManagementDAOException */ List getAgentVersions(int tenantId) throws DeviceManagementDAOException; + + /** + * This method is used to retrieve the icon info of an installed app in device. + * + * @param applicationIdentifier application identifier. + * @return returns the application icon path. + * @throws DeviceManagementDAOException + */ + String getIconPath(String applicationIdentifier) throws DeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index 08725aeddb..4bc3cd4326 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -3236,4 +3236,27 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } return agentVersions; } + + @Override + public String getIconPath(String applicationIdentifier) throws DeviceManagementDAOException{ + Connection conn; + PreparedStatement stmt = null; + String iconPath = null; + try{ + conn = this.getConnection(); + stmt = conn.prepareStatement("SELECT ICON_PATH FROM DM_APP_ICONS" + + " WHERE PACKAGE_NAME = ?"); + stmt.setString(1,applicationIdentifier); + try (ResultSet rs = stmt.executeQuery()) { + if (rs.next()) { + iconPath = rs.getString("ICON_PATH"); + } + return iconPath; + } + } catch (SQLException e) { + throw new DeviceManagementDAOException("Error occurred while retrieving app icon path"); + } finally { + DeviceManagementDAOUtil.cleanupResources(stmt, null); + } + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index d3363717ad..0cb7937057 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -3707,6 +3707,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } finally { DeviceManagementDAOFactory.closeConnection(); } + if (applications != null){ + this.getInstalledAppIconInfo(device); + } return applications; } @@ -4921,4 +4924,48 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv throw new DeviceManagementException(msg, e); } } + + @Override + public void saveApplicationIcon(String iconPath, String packageName, String version) throws DeviceManagementException{ + try{ + DeviceManagementDAOFactory.beginTransaction(); + if(applicationDAO.getApplicationPackageCount(packageName) == 0){ + applicationDAO.saveApplicationIcon(iconPath, packageName, version); + } + DeviceManagementDAOFactory.commitTransaction(); + } catch (TransactionManagementException e) { + String msg = "Error occurred while initiating transaction"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (DeviceManagementDAOException e) { + DeviceManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred while saving app icon info"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } finally { + DeviceManagementDAOFactory.closeConnection(); + } + } + + private void getInstalledAppIconInfo(Device device) throws DeviceManagementException { + List applications = device.getApplications(); + String iconPath; + try { + DeviceManagementDAOFactory.openConnection(); + for (Application app : applications) { + iconPath = deviceDAO.getIconPath(app.getApplicationIdentifier()); + app.setImageUrl(iconPath); + } + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred while retrieving installed app icon info"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg); + throw new DeviceManagementException(msg, e); + } finally { + DeviceManagementDAOFactory.closeConnection(); + } + } }