From ca5beeabe3219731942854f318fc26137c0ba649 Mon Sep 17 00:00:00 2001 From: charitha Date: Tue, 5 May 2020 22:31:25 +0530 Subject: [PATCH] Performance improvements --- .../impl/DeviceManagementServiceImpl.java | 11 +++----- .../impl/EventReceiverServiceImpl.java | 2 +- .../android/util/AndroidDeviceUtils.java | 4 +-- .../DeviceInformationManagerServiceMock.java | 5 ++++ .../DeviceManagementProviderServiceMock.java | 26 +++++++++++++------ .../android/impl/AndroidDeviceManager.java | 5 ---- 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java index a6f1a7159..9b3a0aec6 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java @@ -223,10 +223,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { private void updateOperations(Device device, List operations) throws OperationManagementException, PolicyComplianceException, - ApplicationManagementException, NotificationManagementException, DeviceManagementException { - DeviceIdentifier id = new DeviceIdentifier(); - id.setId(device.getDeviceIdentifier()); - id.setType(AndroidConstants.DEVICE_TYPE_ANDROID); + ApplicationManagementException, NotificationManagementException { String deviceName = device.getName(); for (Operation operation : operations) { AndroidDeviceUtils.updateOperation(device, operation); @@ -238,7 +235,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { Status.NEW.toString()); notification.setDescription(operation.getCode() + " operation failed to execute on device " + deviceName + " (ID: " + device.getDeviceIdentifier() + ")"); - AndroidAPIUtils.getNotificationManagementService().addNotification(id, notification); + AndroidAPIUtils.getNotificationManagementService().addNotification(device, notification); } if (log.isDebugEnabled()) { log.debug("Updating operation '" + operation.toString() + "'"); @@ -358,7 +355,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { public Response isEnrolled(@PathParam("id") String id, @HeaderParam("If-Modified-Since") String ifModifiedSince) { DeviceIdentifier deviceIdentifier = AndroidDeviceUtils.convertToDeviceIdentifierObject(id); try { - Device device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier); + Device device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier, false); if (device != null) { String status = String.valueOf(device.getEnrolmentInfo().getStatus()); Message responseMessage = new Message(); @@ -389,7 +386,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { deviceIdentifier.setId(id); deviceIdentifier.setType(AndroidConstants.DEVICE_TYPE_ANDROID); try { - device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier); + device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier, false); } catch (DeviceManagementException e) { String msg = "Error occurred while getting enrollment details of the Android device that carries the id '" + id + "'"; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java index ba86a8a22..0de1ac7ab 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java @@ -76,7 +76,7 @@ public class EventReceiverServiceImpl implements EventReceiverService { } DeviceIdentifier deviceIdentifier = new DeviceIdentifier(eventBeanWrapper.getDeviceIdentifier(), AndroidConstants.DEVICE_TYPE_ANDROID); - device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier); + device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier, false); if (device != null && EnrolmentInfo.Status.ACTIVE != device.getEnrolmentInfo().getStatus()){ return Response.status(Response.Status.ACCEPTED).entity("Device is not in Active state.").build(); } else if (device == null){ diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java index 60b2dd266..7617047c9 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java @@ -167,8 +167,8 @@ public class AndroidDeviceUtils { if (log.isDebugEnabled()) { log.debug("Received compliance status from MONITOR operation ID: " + operation.getId()); } - AndroidAPIUtils.getPolicyManagerService().checkPolicyCompliance(deviceIdentifier, - getComplianceFeatures(operation.getPayLoad())); + AndroidAPIUtils.getPolicyManagerService().checkPolicyCompliance(device, + getComplianceFeatures(operation.getPayLoad())); } else if (!Operation.Status.ERROR.equals(operation.getStatus()) && AndroidConstants. OperationCodes.APPLICATION_LIST.equals(operation.getCode())) { if (log.isDebugEnabled()) { diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceInformationManagerServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceInformationManagerServiceMock.java index 02d086f18..c9fbf5705 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceInformationManagerServiceMock.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceInformationManagerServiceMock.java @@ -26,6 +26,11 @@ public class DeviceInformationManagerServiceMock implements DeviceInformationMan return null; } + @Override + public DeviceInfo getDeviceInfo(Device device) throws DeviceDetailsMgtException { + return null; + } + @Override public List getDevicesInfo(List list) throws DeviceDetailsMgtException { return null; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java index 76c576d48..1893fa582 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java @@ -429,13 +429,7 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv } @Override - public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { - return false; - } - - @Override - public boolean setStatus(DeviceIdentifier deviceIdentifier, String s, EnrolmentInfo.Status status) - throws DeviceManagementException { + public boolean setStatus(Device device, EnrolmentInfo.Status status) throws DeviceManagementException { return false; } @@ -456,6 +450,11 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv return TestUtils.getActivity(); } + @Override + public void addTaskOperation(String s, Operation operation) throws OperationManagementException { + + } + @Override public List getOperations(DeviceIdentifier deviceIdentifier) throws OperationManagementException { @@ -468,6 +467,11 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv return null; } + @Override + public List getOperations(DeviceIdentifier deviceIdentifier, Operation.Status status) throws OperationManagementException { + return null; + } + @Override public List getPendingOperations(DeviceIdentifier deviceIdentifier) throws OperationManagementException { @@ -668,7 +672,7 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv } @Override - public boolean updateEnrollment(String s, List list) throws DeviceManagementException, UserNotFoundException, InvalidDeviceException { + public boolean updateEnrollment(String s, boolean b, List list) throws DeviceManagementException, UserNotFoundException, InvalidDeviceException { return false; } @@ -741,4 +745,10 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv public int getFunctioningDevicesInSystem() throws DeviceManagementException { return 0; } + + @Override + public boolean isOperationExist(DeviceIdentifier deviceIdentifier, int i) throws OperationManagementException { + return false; + } + } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManager.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManager.java index 72dc73fe9..b62390275 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManager.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManager.java @@ -285,11 +285,6 @@ public class AndroidDeviceManager implements DeviceManager { return true; } - @Override - public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { - return false; - } - @Override public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser, EnrolmentInfo.Status status) throws DeviceManagementException {