mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Merge pull request #834 from charithag/master
Add unit tests for WSO2 Carbon - Android JAX-RS API
This commit is contained in:
commit
0f9e3273e8
@ -49,6 +49,44 @@
|
|||||||
<warName>api#device-mgt#android#v1.0</warName>
|
<warName>api#device-mgt#android#v1.0</warName>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jacoco</groupId>
|
||||||
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>jacoco-initialize</id>
|
||||||
|
<goals>
|
||||||
|
<goal>prepare-agent</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>jacoco-site</id>
|
||||||
|
<phase>test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>report</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
|
||||||
|
<outputDirectory>${basedir}/target/coverage-reports/site</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<log4j.configuration>file:src/test/resources/log4j.properties</log4j.configuration>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
<suiteXmlFiles>
|
||||||
|
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
|
||||||
|
</suiteXmlFiles>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
@ -262,5 +300,55 @@
|
|||||||
<groupId>javax.ws.rs</groupId>
|
<groupId>javax.ws.rs</groupId>
|
||||||
<artifactId>javax.ws.rs-api</artifactId>
|
<artifactId>javax.ws.rs-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.testng</groupId>
|
||||||
|
<artifactId>testng</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.powermock</groupId>
|
||||||
|
<artifactId>powermock-module-testng</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.powermock</groupId>
|
||||||
|
<artifactId>powermock-api-mockito</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database.wso2</groupId>
|
||||||
|
<artifactId>h2-database-engine</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.queuing</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.ndatasource.core</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-dbcp.wso2</groupId>
|
||||||
|
<artifactId>commons-dbcp</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-pool.wso2</groupId>
|
||||||
|
<artifactId>commons-pool</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>javax.cache.wso2</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javassist</groupId>
|
||||||
|
<artifactId>javassist</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
|
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
||||||
@ -61,8 +62,8 @@ import org.wso2.carbon.mdm.services.android.bean.wrapper.WipeDataBeanWrapper;
|
|||||||
import org.wso2.carbon.mdm.services.android.exception.BadRequestException;
|
import org.wso2.carbon.mdm.services.android.exception.BadRequestException;
|
||||||
import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException;
|
import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException;
|
||||||
import org.wso2.carbon.mdm.services.android.services.DeviceManagementAdminService;
|
import org.wso2.carbon.mdm.services.android.services.DeviceManagementAdminService;
|
||||||
import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils;
|
|
||||||
import org.wso2.carbon.mdm.services.android.util.AndroidConstants;
|
import org.wso2.carbon.mdm.services.android.util.AndroidConstants;
|
||||||
|
import org.wso2.carbon.mdm.services.android.util.AndroidDeviceUtils;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
@ -109,7 +110,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
operation.setType(Operation.Type.PROFILE);
|
operation.setType(Operation.Type.PROFILE);
|
||||||
operation.setEnabled(true);
|
operation.setEnabled(true);
|
||||||
operation.setPayLoad(lock.toJSON());
|
operation.setPayLoad(lock.toJSON());
|
||||||
return AndroidAPIUtils.getOperationResponse(deviceLockBeanWrapper.getDeviceIDs(), operation);
|
Activity activity = AndroidDeviceUtils.getOperationResponse(deviceLockBeanWrapper.getDeviceIDs(), operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -120,11 +122,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +138,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
operation.setCode(AndroidConstants.OperationCodes.DEVICE_UNLOCK);
|
operation.setCode(AndroidConstants.OperationCodes.DEVICE_UNLOCK);
|
||||||
operation.setType(Operation.Type.COMMAND);
|
operation.setType(Operation.Type.COMMAND);
|
||||||
operation.setEnabled(true);
|
operation.setEnabled(true);
|
||||||
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
|
Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -152,11 +150,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +165,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
CommandOperation operation = new CommandOperation();
|
CommandOperation operation = new CommandOperation();
|
||||||
operation.setCode(AndroidConstants.OperationCodes.DEVICE_LOCATION);
|
operation.setCode(AndroidConstants.OperationCodes.DEVICE_LOCATION);
|
||||||
operation.setType(Operation.Type.COMMAND);
|
operation.setType(Operation.Type.COMMAND);
|
||||||
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
|
Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -183,11 +177,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +192,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
CommandOperation operation = new CommandOperation();
|
CommandOperation operation = new CommandOperation();
|
||||||
operation.setCode(AndroidConstants.OperationCodes.CLEAR_PASSWORD);
|
operation.setCode(AndroidConstants.OperationCodes.CLEAR_PASSWORD);
|
||||||
operation.setType(Operation.Type.COMMAND);
|
operation.setType(Operation.Type.COMMAND);
|
||||||
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
|
Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -214,11 +204,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,7 +227,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
operation.setCode(AndroidConstants.OperationCodes.CAMERA);
|
operation.setCode(AndroidConstants.OperationCodes.CAMERA);
|
||||||
operation.setType(Operation.Type.COMMAND);
|
operation.setType(Operation.Type.COMMAND);
|
||||||
operation.setEnabled(camera.isEnabled());
|
operation.setEnabled(camera.isEnabled());
|
||||||
return AndroidAPIUtils.getOperationResponse(cameraBeanWrapper.getDeviceIDs(), operation);
|
Activity activity = AndroidDeviceUtils.getOperationResponse(cameraBeanWrapper.getDeviceIDs(), operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -253,11 +239,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +254,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
CommandOperation operation = new CommandOperation();
|
CommandOperation operation = new CommandOperation();
|
||||||
operation.setCode(AndroidConstants.OperationCodes.DEVICE_INFO);
|
operation.setCode(AndroidConstants.OperationCodes.DEVICE_INFO);
|
||||||
operation.setType(Operation.Type.COMMAND);
|
operation.setType(Operation.Type.COMMAND);
|
||||||
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
|
Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -283,11 +265,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
String errorMessage = "Issue in retrieving operation management service instance";
|
String errorMessage = "Issue in retrieving operation management service instance";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,7 +280,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
CommandOperation operation = new CommandOperation();
|
CommandOperation operation = new CommandOperation();
|
||||||
operation.setCode(AndroidConstants.OperationCodes.LOGCAT);
|
operation.setCode(AndroidConstants.OperationCodes.LOGCAT);
|
||||||
operation.setType(Operation.Type.COMMAND);
|
operation.setType(Operation.Type.COMMAND);
|
||||||
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
|
Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -313,11 +291,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
String errorMessage = "Issue in retrieving operation management service instance";
|
String errorMessage = "Issue in retrieving operation management service instance";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,7 +306,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
CommandOperation operation = new CommandOperation();
|
CommandOperation operation = new CommandOperation();
|
||||||
operation.setCode(AndroidConstants.OperationCodes.ENTERPRISE_WIPE);
|
operation.setCode(AndroidConstants.OperationCodes.ENTERPRISE_WIPE);
|
||||||
operation.setType(Operation.Type.COMMAND);
|
operation.setType(Operation.Type.COMMAND);
|
||||||
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
|
Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -344,11 +318,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,7 +341,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
operation.setCode(AndroidConstants.OperationCodes.WIPE_DATA);
|
operation.setCode(AndroidConstants.OperationCodes.WIPE_DATA);
|
||||||
operation.setType(Operation.Type.PROFILE);
|
operation.setType(Operation.Type.PROFILE);
|
||||||
operation.setPayLoad(wipeData.toJSON());
|
operation.setPayLoad(wipeData.toJSON());
|
||||||
return AndroidAPIUtils.getOperationResponse(wipeDataBeanWrapper.getDeviceIDs(), operation);
|
Activity activity = AndroidDeviceUtils.getOperationResponse(wipeDataBeanWrapper.getDeviceIDs(), operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -383,11 +353,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,7 +368,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
CommandOperation operation = new CommandOperation();
|
CommandOperation operation = new CommandOperation();
|
||||||
operation.setCode(AndroidConstants.OperationCodes.APPLICATION_LIST);
|
operation.setCode(AndroidConstants.OperationCodes.APPLICATION_LIST);
|
||||||
operation.setType(Operation.Type.COMMAND);
|
operation.setType(Operation.Type.COMMAND);
|
||||||
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
|
Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -414,11 +380,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,7 +395,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
CommandOperation operation = new CommandOperation();
|
CommandOperation operation = new CommandOperation();
|
||||||
operation.setCode(AndroidConstants.OperationCodes.DEVICE_RING);
|
operation.setCode(AndroidConstants.OperationCodes.DEVICE_RING);
|
||||||
operation.setType(Operation.Type.COMMAND);
|
operation.setType(Operation.Type.COMMAND);
|
||||||
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
|
Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -445,11 +407,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,7 +422,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
CommandOperation operation = new CommandOperation();
|
CommandOperation operation = new CommandOperation();
|
||||||
operation.setCode(AndroidConstants.OperationCodes.DEVICE_REBOOT);
|
operation.setCode(AndroidConstants.OperationCodes.DEVICE_REBOOT);
|
||||||
operation.setType(Operation.Type.COMMAND);
|
operation.setType(Operation.Type.COMMAND);
|
||||||
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
|
Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -476,11 +434,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -497,7 +450,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
operation.setCode(AndroidConstants.OperationCodes.DEVICE_MUTE);
|
operation.setCode(AndroidConstants.OperationCodes.DEVICE_MUTE);
|
||||||
operation.setType(Operation.Type.COMMAND);
|
operation.setType(Operation.Type.COMMAND);
|
||||||
operation.setEnabled(true);
|
operation.setEnabled(true);
|
||||||
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
|
Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -508,11 +462,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -542,8 +491,9 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
operation.setCode(AndroidConstants.OperationCodes.INSTALL_APPLICATION);
|
operation.setCode(AndroidConstants.OperationCodes.INSTALL_APPLICATION);
|
||||||
operation.setType(Operation.Type.PROFILE);
|
operation.setType(Operation.Type.PROFILE);
|
||||||
operation.setPayLoad(applicationInstallation.toJSON());
|
operation.setPayLoad(applicationInstallation.toJSON());
|
||||||
return AndroidAPIUtils.getOperationResponse(applicationInstallationBeanWrapper.getDeviceIDs(),
|
Activity activity = AndroidDeviceUtils
|
||||||
operation);
|
.getOperationResponse(applicationInstallationBeanWrapper.getDeviceIDs(), operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
String errorMessage = "Invalid payload for the operation.";
|
String errorMessage = "Invalid payload for the operation.";
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
@ -559,11 +509,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -592,8 +537,9 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
operation.setType(Operation.Type.PROFILE);
|
operation.setType(Operation.Type.PROFILE);
|
||||||
operation.setPayLoad(applicationUpdate.toJSON());
|
operation.setPayLoad(applicationUpdate.toJSON());
|
||||||
|
|
||||||
return AndroidAPIUtils.getOperationResponse(applicationUpdateBeanWrapper.getDeviceIDs(),
|
Activity activity = AndroidDeviceUtils
|
||||||
operation);
|
.getOperationResponse(applicationUpdateBeanWrapper.getDeviceIDs(), operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -604,11 +550,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -635,9 +576,9 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
operation.setCode(AndroidConstants.OperationCodes.UNINSTALL_APPLICATION);
|
operation.setCode(AndroidConstants.OperationCodes.UNINSTALL_APPLICATION);
|
||||||
operation.setType(Operation.Type.PROFILE);
|
operation.setType(Operation.Type.PROFILE);
|
||||||
operation.setPayLoad(applicationUninstallation.toJSON());
|
operation.setPayLoad(applicationUninstallation.toJSON());
|
||||||
|
Activity activity = AndroidDeviceUtils
|
||||||
return AndroidAPIUtils.getOperationResponse(applicationUninstallationBeanWrapper.getDeviceIDs(),
|
.getOperationResponse(applicationUninstallationBeanWrapper.getDeviceIDs(), operation);
|
||||||
operation);
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -648,11 +589,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -676,8 +612,9 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
operation.setCode(AndroidConstants.OperationCodes.BLACKLIST_APPLICATIONS);
|
operation.setCode(AndroidConstants.OperationCodes.BLACKLIST_APPLICATIONS);
|
||||||
operation.setType(Operation.Type.PROFILE);
|
operation.setType(Operation.Type.PROFILE);
|
||||||
operation.setPayLoad(blacklistApplications.toJSON());
|
operation.setPayLoad(blacklistApplications.toJSON());
|
||||||
return AndroidAPIUtils.getOperationResponse(blacklistApplicationsBeanWrapper.getDeviceIDs(),
|
Activity activity = AndroidDeviceUtils
|
||||||
operation);
|
.getOperationResponse(blacklistApplicationsBeanWrapper.getDeviceIDs(), operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -688,11 +625,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -718,7 +650,9 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
operation.setCode(AndroidConstants.OperationCodes.UPGRADE_FIRMWARE);
|
operation.setCode(AndroidConstants.OperationCodes.UPGRADE_FIRMWARE);
|
||||||
operation.setType(Operation.Type.PROFILE);
|
operation.setType(Operation.Type.PROFILE);
|
||||||
operation.setPayLoad(upgradeFirmware.toJSON());
|
operation.setPayLoad(upgradeFirmware.toJSON());
|
||||||
return AndroidAPIUtils.getOperationResponse(upgradeFirmwareBeanWrapper.getDeviceIDs(), operation);
|
Activity activity = AndroidDeviceUtils
|
||||||
|
.getOperationResponse(upgradeFirmwareBeanWrapper.getDeviceIDs(), operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -729,11 +663,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -757,8 +686,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
operation.setCode(AndroidConstants.OperationCodes.VPN);
|
operation.setCode(AndroidConstants.OperationCodes.VPN);
|
||||||
operation.setType(Operation.Type.PROFILE);
|
operation.setType(Operation.Type.PROFILE);
|
||||||
operation.setPayLoad(vpn.toJSON());
|
operation.setPayLoad(vpn.toJSON());
|
||||||
return AndroidAPIUtils.getOperationResponse(vpnConfiguration.getDeviceIDs(),
|
Activity activity = AndroidDeviceUtils.getOperationResponse(vpnConfiguration.getDeviceIDs(), operation);
|
||||||
operation);
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -769,11 +698,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -797,8 +721,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
operation.setCode(AndroidConstants.OperationCodes.NOTIFICATION);
|
operation.setCode(AndroidConstants.OperationCodes.NOTIFICATION);
|
||||||
operation.setType(Operation.Type.PROFILE);
|
operation.setType(Operation.Type.PROFILE);
|
||||||
operation.setPayLoad(notification.toJSON());
|
operation.setPayLoad(notification.toJSON());
|
||||||
return AndroidAPIUtils.getOperationResponse(notificationBeanWrapper.getDeviceIDs(),
|
Activity activity = AndroidDeviceUtils.getOperationResponse(notificationBeanWrapper.getDeviceIDs(), operation);
|
||||||
operation);
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -809,11 +733,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -838,8 +757,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
operation.setType(Operation.Type.PROFILE);
|
operation.setType(Operation.Type.PROFILE);
|
||||||
operation.setPayLoad(wifi.toJSON());
|
operation.setPayLoad(wifi.toJSON());
|
||||||
|
|
||||||
return AndroidAPIUtils.getOperationResponse(wifiBeanWrapper.getDeviceIDs(),
|
Activity activity = AndroidDeviceUtils.getOperationResponse(wifiBeanWrapper.getDeviceIDs(), operation);
|
||||||
operation);
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -850,11 +769,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -878,8 +792,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
operation.setCode(AndroidConstants.OperationCodes.ENCRYPT_STORAGE);
|
operation.setCode(AndroidConstants.OperationCodes.ENCRYPT_STORAGE);
|
||||||
operation.setType(Operation.Type.COMMAND);
|
operation.setType(Operation.Type.COMMAND);
|
||||||
operation.setEnabled(deviceEncryption.isEncrypted());
|
operation.setEnabled(deviceEncryption.isEncrypted());
|
||||||
return AndroidAPIUtils.getOperationResponse(encryptionBeanWrapper.getDeviceIDs(),
|
Activity activity = AndroidDeviceUtils.getOperationResponse(encryptionBeanWrapper.getDeviceIDs(), operation);
|
||||||
operation);
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -890,11 +804,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -918,8 +827,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
operation.setCode(AndroidConstants.OperationCodes.CHANGE_LOCK_CODE);
|
operation.setCode(AndroidConstants.OperationCodes.CHANGE_LOCK_CODE);
|
||||||
operation.setType(Operation.Type.PROFILE);
|
operation.setType(Operation.Type.PROFILE);
|
||||||
operation.setPayLoad(lockCode.toJSON());
|
operation.setPayLoad(lockCode.toJSON());
|
||||||
return AndroidAPIUtils.getOperationResponse(lockCodeBeanWrapper.getDeviceIDs(),
|
Activity activity = AndroidDeviceUtils.getOperationResponse(lockCodeBeanWrapper.getDeviceIDs(), operation);
|
||||||
operation);
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -930,11 +839,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -959,8 +863,9 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
operation.setType(Operation.Type.PROFILE);
|
operation.setType(Operation.Type.PROFILE);
|
||||||
operation.setPayLoad(passcodePolicy.toJSON());
|
operation.setPayLoad(passcodePolicy.toJSON());
|
||||||
|
|
||||||
return AndroidAPIUtils.getOperationResponse(passwordPolicyBeanWrapper.getDeviceIDs(),
|
Activity activity = AndroidDeviceUtils
|
||||||
operation);
|
.getOperationResponse(passwordPolicyBeanWrapper.getDeviceIDs(), operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -971,11 +876,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1000,7 +900,9 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
operation.setCode(AndroidConstants.OperationCodes.WEBCLIP);
|
operation.setCode(AndroidConstants.OperationCodes.WEBCLIP);
|
||||||
operation.setType(Operation.Type.PROFILE);
|
operation.setType(Operation.Type.PROFILE);
|
||||||
operation.setPayLoad(webClip.toJSON());
|
operation.setPayLoad(webClip.toJSON());
|
||||||
return AndroidAPIUtils.getOperationResponse(webClipBeanWrapper.getDeviceIDs(), operation);
|
|
||||||
|
Activity activity = AndroidDeviceUtils.getOperationResponse(webClipBeanWrapper.getDeviceIDs(), operation);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
||||||
} catch (InvalidDeviceException e) {
|
} catch (InvalidDeviceException e) {
|
||||||
String errorMessage = "Invalid Device Identifiers found.";
|
String errorMessage = "Invalid Device Identifiers found.";
|
||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
@ -1011,11 +913,6 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
log.error(errorMessage, e);
|
log.error(errorMessage, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
String errorMessage = "Issue in retrieving device management service instance";
|
|
||||||
log.error(errorMessage, e);
|
|
||||||
throw new UnexpectedServerErrorException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,6 @@ package org.wso2.carbon.mdm.services.android.services.impl;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
||||||
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;
|
||||||
@ -126,7 +125,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
log.error(msg);
|
log.error(msg);
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||||
}
|
}
|
||||||
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
DeviceIdentifier deviceIdentifier = AndroidDeviceUtils.convertToDeviceIdentifierObject(id);
|
||||||
try {
|
try {
|
||||||
if (!AndroidDeviceUtils.isValidDeviceIdentifier(deviceIdentifier)) {
|
if (!AndroidDeviceUtils.isValidDeviceIdentifier(deviceIdentifier)) {
|
||||||
String msg = "Device not found for identifier '" + id + "'";
|
String msg = "Device not found for identifier '" + id + "'";
|
||||||
@ -168,7 +167,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
|
|
||||||
List<? extends Operation> pendingOperations;
|
List<? extends Operation> pendingOperations;
|
||||||
try {
|
try {
|
||||||
pendingOperations = AndroidAPIUtils.getPendingOperations(deviceIdentifier);
|
pendingOperations = AndroidDeviceUtils.getPendingOperations(deviceIdentifier);
|
||||||
} catch (OperationManagementException e) {
|
} catch (OperationManagementException e) {
|
||||||
String msg = "Issue in retrieving operation management service instance";
|
String msg = "Issue in retrieving operation management service instance";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
@ -182,7 +181,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
throws OperationManagementException, PolicyComplianceException,
|
throws OperationManagementException, PolicyComplianceException,
|
||||||
ApplicationManagementException, NotificationManagementException, DeviceManagementException {
|
ApplicationManagementException, NotificationManagementException, DeviceManagementException {
|
||||||
for (org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation : operations) {
|
for (org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation : operations) {
|
||||||
AndroidAPIUtils.updateOperation(deviceId, operation);
|
AndroidDeviceUtils.updateOperation(deviceId, operation);
|
||||||
if (OPERATION_ERROR_STATUS.equals(operation.getStatus().toString())) {
|
if (OPERATION_ERROR_STATUS.equals(operation.getStatus().toString())) {
|
||||||
org.wso2.carbon.device.mgt.common.notification.mgt.Notification notification = new
|
org.wso2.carbon.device.mgt.common.notification.mgt.Notification notification = new
|
||||||
org.wso2.carbon.device.mgt.common.notification.mgt.Notification();
|
org.wso2.carbon.device.mgt.common.notification.mgt.Notification();
|
||||||
@ -233,10 +232,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
DeviceLocation deviceLocation = extractLocation(deviceIdentifier, androidDevice.getProperties());
|
DeviceLocation deviceLocation = extractLocation(deviceIdentifier, androidDevice.getProperties());
|
||||||
if (deviceLocation != null) {
|
if (deviceLocation != null) {
|
||||||
try {
|
try {
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
DeviceInformationManager informationManager = AndroidAPIUtils
|
||||||
DeviceInformationManager informationManager =
|
.getDeviceInformationManagerService();
|
||||||
(DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null);
|
|
||||||
|
|
||||||
informationManager.addDeviceLocation(deviceLocation);
|
informationManager.addDeviceLocation(deviceLocation);
|
||||||
} catch (DeviceDetailsMgtException e) {
|
} catch (DeviceDetailsMgtException e) {
|
||||||
String msg = "Error occurred while updating the device location upon android " +
|
String msg = "Error occurred while updating the device location upon android " +
|
||||||
@ -265,10 +262,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
addOperation(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID,
|
addOperation(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID,
|
||||||
operation, deviceIdentifiers);
|
operation, deviceIdentifiers);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
PolicyManagerService policyManagerService = AndroidAPIUtils.getPolicyManagerService();
|
PolicyManagerService policyManagerService = AndroidAPIUtils.getPolicyManagerService();
|
||||||
policyManagerService.getEffectivePolicy(new DeviceIdentifier(androidDevice.getDeviceIdentifier(), device.getType()));
|
policyManagerService.getEffectivePolicy(new DeviceIdentifier(androidDevice.getDeviceIdentifier(), device.getType()));
|
||||||
if (status) {
|
|
||||||
Message responseMessage = new Message();
|
Message responseMessage = new Message();
|
||||||
responseMessage.setResponseCode(Response.Status.OK.toString());
|
responseMessage.setResponseCode(Response.Status.OK.toString());
|
||||||
responseMessage.setResponseMessage("Android device, which carries the id '" +
|
responseMessage.setResponseMessage("Android device, which carries the id '" +
|
||||||
@ -316,7 +312,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
@Path("/{id}/status")
|
@Path("/{id}/status")
|
||||||
@Override
|
@Override
|
||||||
public Response isEnrolled(@PathParam("id") String id, @HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
public Response isEnrolled(@PathParam("id") String id, @HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
||||||
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
DeviceIdentifier deviceIdentifier = AndroidDeviceUtils.convertToDeviceIdentifierObject(id);
|
||||||
try {
|
try {
|
||||||
Device device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier);
|
Device device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier);
|
||||||
if (device != null) {
|
if (device != null) {
|
||||||
@ -421,7 +417,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
@Override
|
@Override
|
||||||
public Response disEnrollDevice(@PathParam("id") String id) {
|
public Response disEnrollDevice(@PathParam("id") String id) {
|
||||||
boolean result;
|
boolean result;
|
||||||
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
DeviceIdentifier deviceIdentifier = AndroidDeviceUtils.convertToDeviceIdentifierObject(id);
|
||||||
try {
|
try {
|
||||||
result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier);
|
result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier);
|
||||||
if (result) {
|
if (result) {
|
||||||
|
|||||||
@ -31,10 +31,14 @@ import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorExcep
|
|||||||
import org.wso2.carbon.mdm.services.android.services.DeviceTypeConfigurationService;
|
import org.wso2.carbon.mdm.services.android.services.DeviceTypeConfigurationService;
|
||||||
import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils;
|
import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils;
|
||||||
import org.wso2.carbon.mdm.services.android.util.AndroidConstants;
|
import org.wso2.carbon.mdm.services.android.util.AndroidConstants;
|
||||||
import org.wso2.carbon.mdm.services.android.util.Message;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.HeaderParam;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|||||||
@ -32,6 +32,7 @@ import org.wso2.carbon.mdm.services.android.exception.NotFoundException;
|
|||||||
import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException;
|
import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException;
|
||||||
import org.wso2.carbon.mdm.services.android.services.EventReceiverService;
|
import org.wso2.carbon.mdm.services.android.services.EventReceiverService;
|
||||||
import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils;
|
import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils;
|
||||||
|
import org.wso2.carbon.mdm.services.android.util.AndroidDeviceUtils;
|
||||||
import org.wso2.carbon.mdm.services.android.util.Message;
|
import org.wso2.carbon.mdm.services.android.util.Message;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
@ -127,7 +128,7 @@ public class EventReceiverServiceImpl implements EventReceiverService {
|
|||||||
String query = "deviceIdentifier:" + deviceId;
|
String query = "deviceIdentifier:" + deviceId;
|
||||||
List<DeviceState> deviceStates;
|
List<DeviceState> deviceStates;
|
||||||
try {
|
try {
|
||||||
deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query);
|
deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query);
|
||||||
if (deviceStates == null) {
|
if (deviceStates == null) {
|
||||||
throw new NotFoundException(
|
throw new NotFoundException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " +
|
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " +
|
||||||
@ -153,7 +154,7 @@ public class EventReceiverServiceImpl implements EventReceiverService {
|
|||||||
String query = "deviceIdentifier:" + deviceId + " AND _timestamp: [" + fromDate + " TO " + toDate + "]";
|
String query = "deviceIdentifier:" + deviceId + " AND _timestamp: [" + fromDate + " TO " + toDate + "]";
|
||||||
List<DeviceState> deviceStates;
|
List<DeviceState> deviceStates;
|
||||||
try {
|
try {
|
||||||
deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query);
|
deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query);
|
||||||
if (deviceStates == null) {
|
if (deviceStates == null) {
|
||||||
throw new NotFoundException(
|
throw new NotFoundException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " +
|
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " +
|
||||||
@ -178,7 +179,7 @@ public class EventReceiverServiceImpl implements EventReceiverService {
|
|||||||
String query = "deviceIdentifier:" + deviceId + " AND type:" + type;
|
String query = "deviceIdentifier:" + deviceId + " AND type:" + type;
|
||||||
List<DeviceState> deviceStates;
|
List<DeviceState> deviceStates;
|
||||||
try {
|
try {
|
||||||
deviceStates = AndroidAPIUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query);
|
deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query);
|
||||||
if (deviceStates == null) {
|
if (deviceStates == null) {
|
||||||
throw new NotFoundException(
|
throw new NotFoundException(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " +
|
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " +
|
||||||
|
|||||||
@ -18,54 +18,17 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.mdm.services.android.util;
|
package org.wso2.carbon.mdm.services.android.util;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.analytics.api.AnalyticsDataAPI;
|
import org.wso2.carbon.analytics.api.AnalyticsDataAPI;
|
||||||
import org.wso2.carbon.analytics.api.AnalyticsDataAPIUtil;
|
|
||||||
import org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse;
|
|
||||||
import org.wso2.carbon.analytics.dataservice.commons.SearchResultEntry;
|
|
||||||
import org.wso2.carbon.analytics.datasource.commons.Record;
|
|
||||||
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
|
|
||||||
import org.wso2.carbon.context.CarbonContext;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService;
|
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
|
||||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
|
||||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
|
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
|
|
||||||
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
|
||||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
|
|
||||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
||||||
import org.wso2.carbon.device.mgt.core.search.mgt.impl.Utils;
|
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.mdm.services.android.bean.DeviceState;
|
|
||||||
import org.wso2.carbon.mdm.services.android.bean.ErrorResponse;
|
|
||||||
import org.wso2.carbon.mdm.services.android.exception.BadRequestException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AndroidAPIUtil class provides utility functions used by Android REST-API classes.
|
* AndroidAPIUtil class provides utility functions used by Android REST-API classes.
|
||||||
*/
|
*/
|
||||||
@ -73,11 +36,8 @@ public class AndroidAPIUtils {
|
|||||||
|
|
||||||
private static Log log = LogFactory.getLog(AndroidAPIUtils.class);
|
private static Log log = LogFactory.getLog(AndroidAPIUtils.class);
|
||||||
|
|
||||||
public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId) {
|
private AndroidAPIUtils(){
|
||||||
DeviceIdentifier identifier = new DeviceIdentifier();
|
throw new IllegalStateException("Utility class");
|
||||||
identifier.setId(deviceId);
|
|
||||||
identifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
||||||
return identifier;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getAuthenticatedUser() {
|
public static String getAuthenticatedUser() {
|
||||||
@ -102,60 +62,18 @@ public class AndroidAPIUtils {
|
|||||||
return deviceManagementProviderService;
|
return deviceManagementProviderService;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static GCMService getGCMService() {
|
public static DeviceInformationManager getDeviceInformationManagerService() {
|
||||||
// PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
// GCMService gcmService = (GCMService) ctx.getOSGiService(GCMService.class, null);
|
DeviceInformationManager informationManager =
|
||||||
// if (gcmService == null) {
|
(DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null);
|
||||||
// String msg = "FCM service has not initialized.";
|
if (informationManager == null) {
|
||||||
// log.error(msg);
|
String msg = "Information Manager service not initialized.";
|
||||||
// throw new IllegalStateException(msg);
|
log.error(msg);
|
||||||
// }
|
throw new IllegalStateException(msg);
|
||||||
// return gcmService;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static MediaType getResponseMediaType(String acceptHeader) {
|
|
||||||
MediaType responseMediaType;
|
|
||||||
if (MediaType.WILDCARD.equals(acceptHeader)) {
|
|
||||||
responseMediaType = MediaType.APPLICATION_JSON_TYPE;
|
|
||||||
} else {
|
|
||||||
responseMediaType = MediaType.valueOf(acceptHeader);
|
|
||||||
}
|
}
|
||||||
return responseMediaType;
|
return informationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Response getOperationResponse(List<String> deviceIDs, Operation operation)
|
|
||||||
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
|
||||||
if (deviceIDs == null || deviceIDs.size() == 0) {
|
|
||||||
String errorMessage = "Device identifier list is empty";
|
|
||||||
log.error(errorMessage);
|
|
||||||
throw new BadRequestException(
|
|
||||||
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
|
|
||||||
}
|
|
||||||
DeviceIdentifier deviceIdentifier;
|
|
||||||
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
|
||||||
for (String deviceId : deviceIDs) {
|
|
||||||
deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setId(deviceId);
|
|
||||||
deviceIdentifier.setType(AndroidConstants.DEVICE_TYPE_ANDROID);
|
|
||||||
deviceIdentifiers.add(deviceIdentifier);
|
|
||||||
}
|
|
||||||
Activity activity = getDeviceManagementService().addOperation(
|
|
||||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, operation, deviceIdentifiers);
|
|
||||||
// if (activity != null) {
|
|
||||||
// GCMService gcmService = getGCMService();
|
|
||||||
// if (gcmService.isFCMEnabled()) {
|
|
||||||
// List<DeviceIdentifier> deviceIDList = deviceIDHolder.getValidDeviceIDList();
|
|
||||||
// List<Device> devices = new ArrayList<Device>(deviceIDList.size());
|
|
||||||
// for (DeviceIdentifier deviceIdentifier : deviceIDList) {
|
|
||||||
// devices.add(getDeviceManagementService().getDevice(deviceIdentifier));
|
|
||||||
// }
|
|
||||||
// getGCMService().sendNotification(operation.getCode(), devices);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
return Response.status(Response.Status.CREATED).entity(activity).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static PolicyManagerService getPolicyManagerService() {
|
public static PolicyManagerService getPolicyManagerService() {
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
PolicyManagerService policyManagerService = (PolicyManagerService) ctx.getOSGiService(
|
PolicyManagerService policyManagerService = (PolicyManagerService) ctx.getOSGiService(
|
||||||
@ -217,312 +135,4 @@ public class AndroidAPIUtils {
|
|||||||
return analyticsDataAPI;
|
return analyticsDataAPI;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<DeviceState> getAllEventsForDevice(String tableName, String query) throws AnalyticsException {
|
|
||||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
||||||
AnalyticsDataAPI analyticsDataAPI = getAnalyticsDataAPI();
|
|
||||||
int eventCount = analyticsDataAPI.searchCount(tenantId, tableName, query);
|
|
||||||
if (eventCount == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
List<SearchResultEntry> resultEntries = analyticsDataAPI.search(tenantId, tableName, query, 0, eventCount);
|
|
||||||
List<String> recordIds = getRecordIds(resultEntries);
|
|
||||||
AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds);
|
|
||||||
Map<String, DeviceState> deviceStateses = createDeviceStatusData(AnalyticsDataAPIUtil.listRecords(
|
|
||||||
analyticsDataAPI, response));
|
|
||||||
return getSortedDeviceStateData(deviceStateses, resultEntries);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<String> getRecordIds(List<SearchResultEntry> searchResults) {
|
|
||||||
List<String> ids = new ArrayList();
|
|
||||||
for (SearchResultEntry searchResult : searchResults) {
|
|
||||||
ids.add(searchResult.getId());
|
|
||||||
}
|
|
||||||
return ids;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, DeviceState> createDeviceStatusData(List<Record> records) {
|
|
||||||
Map<String, DeviceState> deviceStatuses = new HashMap();
|
|
||||||
for (Record record : records) {
|
|
||||||
DeviceState deviceState = createDeviceStatusData(record);
|
|
||||||
deviceStatuses.put(deviceState.getId(), deviceState);
|
|
||||||
}
|
|
||||||
return deviceStatuses;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static DeviceState createDeviceStatusData(Record record) {
|
|
||||||
DeviceState deviceState = new DeviceState();
|
|
||||||
deviceState.setId(record.getId());
|
|
||||||
deviceState.setValues(record.getValues());
|
|
||||||
return deviceState;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<DeviceState> getSortedDeviceStateData(Map<String, DeviceState> sensorDatas,
|
|
||||||
List<SearchResultEntry> searchResults) {
|
|
||||||
List<DeviceState> sortedRecords = new ArrayList();
|
|
||||||
for (SearchResultEntry searchResultEntry : searchResults) {
|
|
||||||
sortedRecords.add(sensorDatas.get(searchResultEntry.getId()));
|
|
||||||
}
|
|
||||||
return sortedRecords;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updateOperation(String deviceId, Operation operation)
|
|
||||||
throws OperationManagementException, PolicyComplianceException, ApplicationManagementException {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setId(deviceId);
|
|
||||||
deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
||||||
|
|
||||||
if (!Operation.Status.ERROR.equals(operation.getStatus()) &&
|
|
||||||
AndroidConstants.OperationCodes.MONITOR.equals(operation.getCode())) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.info("Received compliance status from MONITOR operation ID: " + operation.getId());
|
|
||||||
}
|
|
||||||
getPolicyManagerService().checkPolicyCompliance(deviceIdentifier,
|
|
||||||
getComplianceFeatures(operation.getPayLoad()));
|
|
||||||
} else if (!Operation.Status.ERROR.equals(operation.getStatus()) && AndroidConstants.
|
|
||||||
OperationCodes.APPLICATION_LIST.equals(operation.getCode())) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.info("Received applications list from device '" + deviceId + "'");
|
|
||||||
}
|
|
||||||
updateApplicationList(operation, deviceIdentifier);
|
|
||||||
|
|
||||||
} else if (!Operation.Status.ERROR.equals(operation.getStatus()) && AndroidConstants.
|
|
||||||
OperationCodes.DEVICE_INFO.equals(operation.getCode())) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (log.isDebugEnabled()){
|
|
||||||
log.debug("Operation response: " + operation.getOperationResponse());
|
|
||||||
}
|
|
||||||
Device device = new Gson().fromJson(operation.getOperationResponse(), Device.class);
|
|
||||||
org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo = convertDeviceToInfo(device);
|
|
||||||
updateDeviceInfo(deviceIdentifier, deviceInfo);
|
|
||||||
} catch (DeviceDetailsMgtException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while updating the device information.", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else if (!Operation.Status.ERROR.equals(operation.getStatus()) &&
|
|
||||||
AndroidConstants.OperationCodes.DEVICE_LOCATION.equals(operation.getCode())) {
|
|
||||||
try {
|
|
||||||
DeviceLocation location = new Gson().fromJson(operation.getOperationResponse(), DeviceLocation.class);
|
|
||||||
// reason for checking "location.getLatitude() != null" because when device fails to provide
|
|
||||||
// device location and send status instead, above Gson converter create new location object
|
|
||||||
// with null attributes
|
|
||||||
if (location != null && location.getLatitude() != null) {
|
|
||||||
location.setDeviceIdentifier(deviceIdentifier);
|
|
||||||
updateDeviceLocation(location);
|
|
||||||
}
|
|
||||||
} catch (DeviceDetailsMgtException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while updating the device location.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
getDeviceManagementService().updateOperation(deviceIdentifier, operation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<? extends Operation> getPendingOperations
|
|
||||||
(DeviceIdentifier deviceIdentifier) throws OperationManagementException {
|
|
||||||
|
|
||||||
List<? extends Operation> operations;
|
|
||||||
operations = getDeviceManagementService().getPendingOperations(deviceIdentifier);
|
|
||||||
return operations;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void updateApplicationList(Operation operation, DeviceIdentifier deviceIdentifier)
|
|
||||||
throws ApplicationManagementException {
|
|
||||||
// Parsing json string to get applications list.
|
|
||||||
if (operation.getOperationResponse() != null) {
|
|
||||||
JsonElement jsonElement = new JsonParser().parse(operation.getOperationResponse());
|
|
||||||
JsonArray jsonArray = jsonElement.getAsJsonArray();
|
|
||||||
Application app;
|
|
||||||
List<Application> applications = new ArrayList<Application>(jsonArray.size());
|
|
||||||
for (JsonElement element : jsonArray) {
|
|
||||||
app = new Application();
|
|
||||||
app.setName(element.getAsJsonObject().
|
|
||||||
get(AndroidConstants.ApplicationProperties.NAME).getAsString());
|
|
||||||
app.setApplicationIdentifier(element.getAsJsonObject().
|
|
||||||
get(AndroidConstants.ApplicationProperties.IDENTIFIER).getAsString());
|
|
||||||
app.setPlatform(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
||||||
if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS) != null) {
|
|
||||||
app.setMemoryUsage(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS).getAsInt());
|
|
||||||
}
|
|
||||||
if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION) != null) {
|
|
||||||
app.setVersion(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION).getAsString());
|
|
||||||
}
|
|
||||||
if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.IS_ACTIVE) != null) {
|
|
||||||
app.setActive(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.IS_ACTIVE).getAsBoolean());
|
|
||||||
}
|
|
||||||
applications.add(app);
|
|
||||||
}
|
|
||||||
getApplicationManagerService().updateApplicationListInstalledInDevice(deviceIdentifier, applications);
|
|
||||||
} else {
|
|
||||||
log.error("Operation Response is null.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static void updateDeviceLocation(DeviceLocation deviceLocation) throws DeviceDetailsMgtException {
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
DeviceInformationManager informationManager =
|
|
||||||
(DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null);
|
|
||||||
|
|
||||||
informationManager.addDeviceLocation(deviceLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static void updateDeviceInfo(DeviceIdentifier deviceId, DeviceInfo deviceInfo)
|
|
||||||
throws DeviceDetailsMgtException {
|
|
||||||
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
DeviceInformationManager informationManager =
|
|
||||||
(DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null);
|
|
||||||
|
|
||||||
informationManager.addDeviceInfo(deviceId, deviceInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static org.wso2.carbon.device.mgt.common.device.details.DeviceInfo convertDeviceToInfo(Device device) {
|
|
||||||
|
|
||||||
org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo =
|
|
||||||
new org.wso2.carbon.device.mgt.common.device.details.DeviceInfo();
|
|
||||||
if (deviceInfo.getDeviceDetailsMap() == null) {
|
|
||||||
deviceInfo.setDeviceDetailsMap(new HashMap<String, String>());
|
|
||||||
}
|
|
||||||
List<Device.Property> props = device.getProperties();
|
|
||||||
|
|
||||||
for (Device.Property prop : props) {
|
|
||||||
if (Utils.getDeviceDetailsColumnNames().containsValue(prop.getName())) {
|
|
||||||
if (prop.getName().equalsIgnoreCase("DEVICE_MODEL")) {
|
|
||||||
deviceInfo.setDeviceModel(prop.getValue());
|
|
||||||
} else if (prop.getName().equalsIgnoreCase("VENDOR")) {
|
|
||||||
deviceInfo.setVendor(prop.getValue());
|
|
||||||
} else if (prop.getName().equalsIgnoreCase("OS_VERSION")) {
|
|
||||||
deviceInfo.setOsVersion(prop.getValue());
|
|
||||||
} else if (prop.getName().equalsIgnoreCase("IMEI")) {
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("IMEI", prop.getValue());
|
|
||||||
} else if (prop.getName().equalsIgnoreCase("IMSI")) {
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("IMSI", prop.getValue());
|
|
||||||
} else if (prop.getName().equalsIgnoreCase("MAC")) {
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("mac", prop.getValue());
|
|
||||||
} else if (prop.getName().equalsIgnoreCase("SERIAL")) {
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("serial", prop.getValue());
|
|
||||||
} else if (prop.getName().equalsIgnoreCase("OS_BUILD_DATE")) {
|
|
||||||
deviceInfo.setOsBuildDate(prop.getValue());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (prop.getName().equalsIgnoreCase("CPU_INFO")) {
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("cpuUser",
|
|
||||||
getProperty(prop.getValue(), "User"));
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("cpuSystem",
|
|
||||||
getProperty(prop.getValue(), "System"));
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("IOW",
|
|
||||||
getProperty(prop.getValue(), "IOW"));
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("IRQ",
|
|
||||||
getProperty(prop.getValue(), "IRQ"));
|
|
||||||
} else if (prop.getName().equalsIgnoreCase("RAM_INFO")) {
|
|
||||||
deviceInfo.setTotalRAMMemory(Double.parseDouble(getProperty(prop.getValue(), "TOTAL_MEMORY")));
|
|
||||||
deviceInfo.setAvailableRAMMemory(Double.parseDouble(getProperty(prop.getValue(), "AVAILABLE_MEMORY")));
|
|
||||||
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("ramThreshold",
|
|
||||||
getProperty(prop.getValue(), "THRESHOLD"));
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("ramLowMemory",
|
|
||||||
getProperty(prop.getValue(), "LOW_MEMORY"));
|
|
||||||
} else if (prop.getName().equalsIgnoreCase("BATTERY_INFO")) {
|
|
||||||
deviceInfo.setPluggedIn(Boolean.parseBoolean(getProperty(prop.getValue(), "PLUGGED")));
|
|
||||||
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("batteryLevel",
|
|
||||||
getProperty(prop.getValue(), "BATTERY_LEVEL"));
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("batteryScale",
|
|
||||||
getProperty(prop.getValue(), "SCALE"));
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("batteryVoltage",
|
|
||||||
getProperty(prop.getValue(), "BATTERY_VOLTAGE"));
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("batteryTemperature",
|
|
||||||
getProperty(prop.getValue(), "TEMPERATURE"));
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("batteryCurrentTemperature",
|
|
||||||
getProperty(prop.getValue(), "CURRENT_AVERAGE"));
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("batteryTechnology",
|
|
||||||
getProperty(prop.getValue(), "TECHNOLOGY"));
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("batteryHealth",
|
|
||||||
getProperty(prop.getValue(), "HEALTH"));
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("batteryStatus",
|
|
||||||
getProperty(prop.getValue(), "STATUS"));
|
|
||||||
} else if (prop.getName().equalsIgnoreCase("NETWORK_INFO")) {
|
|
||||||
deviceInfo.setSsid(getProperty(prop.getValue(), "WIFI_SSID"));
|
|
||||||
deviceInfo.setConnectionType(getProperty(prop.getValue(), "CONNECTION_TYPE"));
|
|
||||||
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("mobileSignalStrength",
|
|
||||||
getProperty(prop.getValue(), "MOBILE_SIGNAL_STRENGTH"));
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("wifiSignalStrength",
|
|
||||||
getProperty(prop.getValue(), "WIFI_SIGNAL_STRENGTH"));
|
|
||||||
} else if (prop.getName().equalsIgnoreCase("DEVICE_INFO")) {
|
|
||||||
deviceInfo.setBatteryLevel(Double.parseDouble(
|
|
||||||
getProperty(prop.getValue(), "BATTERY_LEVEL")));
|
|
||||||
deviceInfo.setInternalTotalMemory(Double.parseDouble(
|
|
||||||
getProperty(prop.getValue(), "INTERNAL_TOTAL_MEMORY")));
|
|
||||||
deviceInfo.setInternalAvailableMemory(Double.parseDouble(
|
|
||||||
getProperty(prop.getValue(), "INTERNAL_AVAILABLE_MEMORY")));
|
|
||||||
deviceInfo.setExternalTotalMemory(Double.parseDouble(
|
|
||||||
getProperty(prop.getValue(), "EXTERNAL_TOTAL_MEMORY")));
|
|
||||||
deviceInfo.setExternalAvailableMemory(Double.parseDouble(
|
|
||||||
getProperty(prop.getValue(), "EXTERNAL_AVAILABLE_MEMORY")));
|
|
||||||
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("encryptionEnabled",
|
|
||||||
getProperty(prop.getValue(), "ENCRYPTION_ENABLED"));
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("passcodeEnabled",
|
|
||||||
getProperty(prop.getValue(), "PASSCODE_ENABLED"));
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("operator",
|
|
||||||
getProperty(prop.getValue(), "OPERATOR"));
|
|
||||||
deviceInfo.getDeviceDetailsMap().put("PhoneNumber",
|
|
||||||
getProperty(prop.getValue(), "PHONE_NUMBER"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return deviceInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getProperty(String a, String needed) {
|
|
||||||
|
|
||||||
JsonElement jsonElement = new JsonParser().parse(a);
|
|
||||||
JsonArray jsonArray = jsonElement.getAsJsonArray();
|
|
||||||
boolean exist = false;
|
|
||||||
for (JsonElement element : jsonArray) {
|
|
||||||
// if (((JsonObject) element).entrySet().iterator().next().getValue().getAsString().equalsIgnoreCase(needed));
|
|
||||||
for (Map.Entry<String, JsonElement> ob : ((JsonObject) element).entrySet()) {
|
|
||||||
JsonElement val = ob.getValue();
|
|
||||||
if (val != null && !val.isJsonNull()) {
|
|
||||||
if (exist) {
|
|
||||||
return val.getAsString().replace("%", "");
|
|
||||||
}
|
|
||||||
if (val.getAsString().equalsIgnoreCase(needed)) {
|
|
||||||
exist = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<ComplianceFeature> getComplianceFeatures(Object compliancePayload) throws PolicyComplianceException {
|
|
||||||
String compliancePayloadString = new Gson().toJson(compliancePayload);
|
|
||||||
if (compliancePayload == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// Parsing json string to get compliance features.
|
|
||||||
JsonElement jsonElement;
|
|
||||||
if (compliancePayloadString instanceof String) {
|
|
||||||
jsonElement = new JsonParser().parse(compliancePayloadString);
|
|
||||||
} else {
|
|
||||||
throw new PolicyComplianceException("Invalid policy compliance payload");
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonArray jsonArray = jsonElement.getAsJsonArray();
|
|
||||||
Gson gson = new Gson();
|
|
||||||
ComplianceFeature complianceFeature;
|
|
||||||
List<ComplianceFeature> complianceFeatures = new ArrayList<ComplianceFeature>(jsonArray.size());
|
|
||||||
|
|
||||||
for (JsonElement element : jsonArray) {
|
|
||||||
complianceFeature = gson.fromJson(element, ComplianceFeature.class);
|
|
||||||
complianceFeatures.add(complianceFeature);
|
|
||||||
}
|
|
||||||
return complianceFeatures;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,15 +18,49 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.mdm.services.android.util;
|
package org.wso2.carbon.mdm.services.android.util;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import com.google.gson.Gson;
|
||||||
import org.wso2.carbon.device.mgt.common.*;
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.analytics.api.AnalyticsDataAPI;
|
||||||
|
import org.wso2.carbon.analytics.api.AnalyticsDataAPIUtil;
|
||||||
|
import org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse;
|
||||||
|
import org.wso2.carbon.analytics.dataservice.commons.SearchResultEntry;
|
||||||
|
import org.wso2.carbon.analytics.datasource.commons.Record;
|
||||||
|
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
|
||||||
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||||
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
|
||||||
|
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
||||||
|
import org.wso2.carbon.device.mgt.core.search.mgt.impl.Utils;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.DeviceState;
|
||||||
import org.wso2.carbon.mdm.services.android.bean.ErrorListItem;
|
import org.wso2.carbon.mdm.services.android.bean.ErrorListItem;
|
||||||
import org.wso2.carbon.mdm.services.android.bean.ErrorResponse;
|
import org.wso2.carbon.mdm.services.android.bean.ErrorResponse;
|
||||||
import org.wso2.carbon.mdm.services.android.exception.BadRequestException;
|
import org.wso2.carbon.mdm.services.android.exception.BadRequestException;
|
||||||
|
|
||||||
import javax.validation.ConstraintViolation;
|
import javax.validation.ConstraintViolation;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,63 +68,350 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public class AndroidDeviceUtils {
|
public class AndroidDeviceUtils {
|
||||||
|
|
||||||
private static final String COMMA_SEPARATION_PATTERN = ", ";
|
private static Log log = LogFactory.getLog(AndroidDeviceUtils.class);
|
||||||
|
|
||||||
public DeviceIDHolder validateDeviceIdentifiers(List<String> deviceIDs) {
|
private AndroidDeviceUtils() {
|
||||||
|
throw new IllegalStateException("Utility class");
|
||||||
List<String> errorDeviceIdList = new ArrayList<String>();
|
|
||||||
List<DeviceIdentifier> validDeviceIDList = new ArrayList<DeviceIdentifier>();
|
|
||||||
|
|
||||||
int deviceIDCounter = 0;
|
|
||||||
for (String deviceID : deviceIDs) {
|
|
||||||
|
|
||||||
deviceIDCounter++;
|
|
||||||
|
|
||||||
if (deviceID == null || deviceID.isEmpty()) {
|
|
||||||
errorDeviceIdList.add(String.format(AndroidConstants.DeviceConstants.DEVICE_ID_NOT_FOUND,
|
|
||||||
deviceIDCounter));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setId(deviceID);
|
|
||||||
deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.
|
|
||||||
MOBILE_DEVICE_TYPE_ANDROID);
|
|
||||||
|
|
||||||
if (isValidDeviceIdentifier(deviceIdentifier)) {
|
|
||||||
validDeviceIDList.add(deviceIdentifier);
|
|
||||||
} else {
|
|
||||||
errorDeviceIdList.add(String.format(AndroidConstants.DeviceConstants.
|
|
||||||
DEVICE_ID_NOT_FOUND, deviceID));
|
|
||||||
}
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
errorDeviceIdList.add(String.format(AndroidConstants.DeviceConstants.DEVICE_ID_SERVICE_NOT_FOUND,
|
|
||||||
deviceIDCounter));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceIDHolder deviceIDHolder = new DeviceIDHolder();
|
|
||||||
deviceIDHolder.setValidDeviceIDList(validDeviceIDList);
|
|
||||||
deviceIDHolder.setErrorDeviceIdList(errorDeviceIdList);
|
|
||||||
|
|
||||||
return deviceIDHolder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String convertErrorMapIntoErrorMessage(List<String> errorDeviceIdList) {
|
|
||||||
return StringUtils.join(errorDeviceIdList.iterator(), COMMA_SEPARATION_PATTERN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidDeviceIdentifier(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
public static boolean isValidDeviceIdentifier(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
||||||
Device device = AndroidAPIUtils.getDeviceManagementService().
|
Device device = AndroidAPIUtils.getDeviceManagementService().
|
||||||
getDevice(deviceIdentifier, false);
|
getDevice(deviceIdentifier, false);
|
||||||
if (device == null || device.getDeviceIdentifier() == null ||
|
return !(device == null || device.getDeviceIdentifier() == null ||
|
||||||
device.getDeviceIdentifier().isEmpty() || device.getEnrolmentInfo() == null) {
|
device.getDeviceIdentifier().isEmpty() ||
|
||||||
return false;
|
device.getEnrolmentInfo() == null ||
|
||||||
} else if (EnrolmentInfo.Status.REMOVED.equals(device.getEnrolmentInfo().getStatus())) {
|
EnrolmentInfo.Status.REMOVED.equals(device.getEnrolmentInfo().getStatus()));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId) {
|
||||||
|
DeviceIdentifier identifier = new DeviceIdentifier();
|
||||||
|
identifier.setId(deviceId);
|
||||||
|
identifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||||
|
return identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Activity getOperationResponse(List<String> deviceIDs, Operation operation)
|
||||||
|
throws OperationManagementException, InvalidDeviceException {
|
||||||
|
if (deviceIDs == null || deviceIDs.isEmpty()) {
|
||||||
|
String errorMessage = "Device identifier list is empty";
|
||||||
|
log.error(errorMessage);
|
||||||
|
throw new BadRequestException(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
|
||||||
|
}
|
||||||
|
DeviceIdentifier deviceIdentifier;
|
||||||
|
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
||||||
|
for (String deviceId : deviceIDs) {
|
||||||
|
deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
deviceIdentifier.setType(AndroidConstants.DEVICE_TYPE_ANDROID);
|
||||||
|
deviceIdentifiers.add(deviceIdentifier);
|
||||||
|
}
|
||||||
|
return AndroidAPIUtils.getDeviceManagementService().addOperation(
|
||||||
|
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, operation, deviceIdentifiers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<DeviceState> getAllEventsForDevice(String tableName, String query) throws AnalyticsException {
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
AnalyticsDataAPI analyticsDataAPI = AndroidAPIUtils.getAnalyticsDataAPI();
|
||||||
|
int eventCount = analyticsDataAPI.searchCount(tenantId, tableName, query);
|
||||||
|
if (eventCount == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<SearchResultEntry> resultEntries = analyticsDataAPI.search(tenantId, tableName, query, 0, eventCount);
|
||||||
|
List<String> recordIds = getRecordIds(resultEntries);
|
||||||
|
AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds);
|
||||||
|
Map<String, DeviceState> deviceStateses = createDeviceStatusData(AnalyticsDataAPIUtil.listRecords(
|
||||||
|
analyticsDataAPI, response));
|
||||||
|
return getSortedDeviceStateData(deviceStateses, resultEntries);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> getRecordIds(List<SearchResultEntry> searchResults) {
|
||||||
|
List<String> ids = new ArrayList<>();
|
||||||
|
for (SearchResultEntry searchResult : searchResults) {
|
||||||
|
ids.add(searchResult.getId());
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, DeviceState> createDeviceStatusData(List<Record> records) {
|
||||||
|
Map<String, DeviceState> deviceStatuses = new HashMap<>();
|
||||||
|
for (Record record : records) {
|
||||||
|
DeviceState deviceState = createDeviceStatusData(record);
|
||||||
|
deviceStatuses.put(deviceState.getId(), deviceState);
|
||||||
|
}
|
||||||
|
return deviceStatuses;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DeviceState createDeviceStatusData(Record record) {
|
||||||
|
DeviceState deviceState = new DeviceState();
|
||||||
|
deviceState.setId(record.getId());
|
||||||
|
deviceState.setValues(record.getValues());
|
||||||
|
return deviceState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<DeviceState> getSortedDeviceStateData(Map<String, DeviceState> sensorDatas,
|
||||||
|
List<SearchResultEntry> searchResults) {
|
||||||
|
List<DeviceState> sortedRecords = new ArrayList<>();
|
||||||
|
for (SearchResultEntry searchResultEntry : searchResults) {
|
||||||
|
sortedRecords.add(sensorDatas.get(searchResultEntry.getId()));
|
||||||
|
}
|
||||||
|
return sortedRecords;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateOperation(String deviceId, Operation operation)
|
||||||
|
throws OperationManagementException, PolicyComplianceException, ApplicationManagementException {
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||||
|
|
||||||
|
if (!Operation.Status.ERROR.equals(operation.getStatus()) &&
|
||||||
|
AndroidConstants.OperationCodes.MONITOR.equals(operation.getCode())) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Received compliance status from MONITOR operation ID: " + operation.getId());
|
||||||
|
}
|
||||||
|
AndroidAPIUtils.getPolicyManagerService().checkPolicyCompliance(deviceIdentifier,
|
||||||
|
getComplianceFeatures(operation.getPayLoad()));
|
||||||
|
} else if (!Operation.Status.ERROR.equals(operation.getStatus()) && AndroidConstants.
|
||||||
|
OperationCodes.APPLICATION_LIST.equals(operation.getCode())) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Received applications list from device '" + deviceId + "'");
|
||||||
|
}
|
||||||
|
updateApplicationList(operation, deviceIdentifier);
|
||||||
|
|
||||||
|
} else if (!Operation.Status.ERROR.equals(operation.getStatus()) && AndroidConstants.
|
||||||
|
OperationCodes.DEVICE_INFO.equals(operation.getCode())) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Operation response: " + operation.getOperationResponse());
|
||||||
|
}
|
||||||
|
Device device = new Gson().fromJson(operation.getOperationResponse(), Device.class);
|
||||||
|
org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo = convertDeviceToInfo(device);
|
||||||
|
updateDeviceInfo(deviceIdentifier, deviceInfo);
|
||||||
|
} catch (DeviceDetailsMgtException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while updating the device information.", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (!Operation.Status.ERROR.equals(operation.getStatus()) &&
|
||||||
|
AndroidConstants.OperationCodes.DEVICE_LOCATION.equals(operation.getCode())) {
|
||||||
|
try {
|
||||||
|
DeviceLocation location = new Gson().fromJson(operation.getOperationResponse(), DeviceLocation.class);
|
||||||
|
// reason for checking "location.getLatitude() != null" because when device fails to provide
|
||||||
|
// device location and send status instead, above Gson converter create new location object
|
||||||
|
// with null attributes
|
||||||
|
if (location != null && location.getLatitude() != null) {
|
||||||
|
location.setDeviceIdentifier(deviceIdentifier);
|
||||||
|
updateDeviceLocation(location);
|
||||||
|
}
|
||||||
|
} catch (DeviceDetailsMgtException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while updating the device location.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AndroidAPIUtils.getDeviceManagementService().updateOperation(deviceIdentifier, operation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<? extends Operation> getPendingOperations
|
||||||
|
(DeviceIdentifier deviceIdentifier) throws OperationManagementException {
|
||||||
|
|
||||||
|
List<? extends Operation> operations;
|
||||||
|
operations = AndroidAPIUtils.getDeviceManagementService().getPendingOperations(deviceIdentifier);
|
||||||
|
return operations;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void updateApplicationList(Operation operation, DeviceIdentifier deviceIdentifier)
|
||||||
|
throws ApplicationManagementException {
|
||||||
|
// Parsing json string to get applications list.
|
||||||
|
if (operation.getOperationResponse() != null) {
|
||||||
|
JsonElement jsonElement = new JsonParser().parse(operation.getOperationResponse());
|
||||||
|
JsonArray jsonArray = jsonElement.getAsJsonArray();
|
||||||
|
Application app;
|
||||||
|
List<Application> applications = new ArrayList<>(jsonArray.size());
|
||||||
|
for (JsonElement element : jsonArray) {
|
||||||
|
app = new Application();
|
||||||
|
app.setName(element.getAsJsonObject().
|
||||||
|
get(AndroidConstants.ApplicationProperties.NAME).getAsString());
|
||||||
|
app.setApplicationIdentifier(element.getAsJsonObject().
|
||||||
|
get(AndroidConstants.ApplicationProperties.IDENTIFIER).getAsString());
|
||||||
|
app.setPlatform(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||||
|
if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS) != null) {
|
||||||
|
app.setMemoryUsage(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS).getAsInt());
|
||||||
|
}
|
||||||
|
if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION) != null) {
|
||||||
|
app.setVersion(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION).getAsString());
|
||||||
|
}
|
||||||
|
if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.IS_ACTIVE) != null) {
|
||||||
|
app.setActive(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.IS_ACTIVE).getAsBoolean());
|
||||||
|
}
|
||||||
|
applications.add(app);
|
||||||
|
}
|
||||||
|
AndroidAPIUtils.getApplicationManagerService().updateApplicationListInstalledInDevice(deviceIdentifier, applications);
|
||||||
|
} else {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Operation Response is null.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void updateDeviceLocation(DeviceLocation deviceLocation) throws DeviceDetailsMgtException {
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
DeviceInformationManager informationManager =
|
||||||
|
(DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null);
|
||||||
|
|
||||||
|
informationManager.addDeviceLocation(deviceLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void updateDeviceInfo(DeviceIdentifier deviceId, DeviceInfo deviceInfo)
|
||||||
|
throws DeviceDetailsMgtException {
|
||||||
|
DeviceInformationManager informationManager = AndroidAPIUtils.getDeviceInformationManagerService();
|
||||||
|
informationManager.addDeviceInfo(deviceId, deviceInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static org.wso2.carbon.device.mgt.common.device.details.DeviceInfo convertDeviceToInfo(Device device) {
|
||||||
|
|
||||||
|
org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo =
|
||||||
|
new org.wso2.carbon.device.mgt.common.device.details.DeviceInfo();
|
||||||
|
if (deviceInfo.getDeviceDetailsMap() == null) {
|
||||||
|
deviceInfo.setDeviceDetailsMap(new HashMap<>());
|
||||||
|
}
|
||||||
|
List<Device.Property> props = device.getProperties();
|
||||||
|
|
||||||
|
for (Device.Property prop : props) {
|
||||||
|
if (Utils.getDeviceDetailsColumnNames().containsValue(prop.getName())) {
|
||||||
|
extractDefinedProperties(deviceInfo, prop);
|
||||||
|
} else {
|
||||||
|
extractMapProperties(deviceInfo, prop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deviceInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void extractMapProperties(DeviceInfo deviceInfo, Device.Property prop) {
|
||||||
|
if (prop.getName().equalsIgnoreCase("CPU_INFO")) {
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("cpuUser", getProperty(prop.getValue(), "User"));
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("cpuSystem", getProperty(prop.getValue(), "System"));
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("IOW", getProperty(prop.getValue(), "IOW"));
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("IRQ", getProperty(prop.getValue(), "IRQ"));
|
||||||
|
} else if (prop.getName().equalsIgnoreCase("RAM_INFO")) {
|
||||||
|
deviceInfo.setTotalRAMMemory(Double.parseDouble(getProperty(prop.getValue(), "TOTAL_MEMORY")));
|
||||||
|
deviceInfo.setAvailableRAMMemory(Double.parseDouble(
|
||||||
|
getProperty(prop.getValue(), "AVAILABLE_MEMORY")));
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("ramThreshold", getProperty(prop.getValue(), "THRESHOLD"));
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("ramLowMemory", getProperty(prop.getValue(), "LOW_MEMORY"));
|
||||||
|
} else if (prop.getName().equalsIgnoreCase("BATTERY_INFO")) {
|
||||||
|
deviceInfo.setPluggedIn(Boolean.parseBoolean(getProperty(prop.getValue(), "PLUGGED")));
|
||||||
|
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("batteryLevel", getProperty(prop.getValue(), "BATTERY_LEVEL"));
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("batteryScale", getProperty(prop.getValue(), "SCALE"));
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("batteryVoltage",
|
||||||
|
getProperty(prop.getValue(), "BATTERY_VOLTAGE"));
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("batteryTemperature",
|
||||||
|
getProperty(prop.getValue(), "TEMPERATURE"));
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("batteryCurrentTemperature",
|
||||||
|
getProperty(prop.getValue(), "CURRENT_AVERAGE"));
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("batteryTechnology",
|
||||||
|
getProperty(prop.getValue(), "TECHNOLOGY"));
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("batteryHealth", getProperty(prop.getValue(), "HEALTH"));
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("batteryStatus", getProperty(prop.getValue(), "STATUS"));
|
||||||
|
} else if (prop.getName().equalsIgnoreCase("NETWORK_INFO")) {
|
||||||
|
deviceInfo.setSsid(getProperty(prop.getValue(), "WIFI_SSID"));
|
||||||
|
deviceInfo.setConnectionType(getProperty(prop.getValue(), "CONNECTION_TYPE"));
|
||||||
|
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("mobileSignalStrength",
|
||||||
|
getProperty(prop.getValue(), "MOBILE_SIGNAL_STRENGTH"));
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("wifiSignalStrength",
|
||||||
|
getProperty(prop.getValue(), "WIFI_SIGNAL_STRENGTH"));
|
||||||
|
} else if (prop.getName().equalsIgnoreCase("DEVICE_INFO")) {
|
||||||
|
deviceInfo.setBatteryLevel(Double.parseDouble(
|
||||||
|
getProperty(prop.getValue(), "BATTERY_LEVEL")));
|
||||||
|
deviceInfo.setInternalTotalMemory(Double.parseDouble(
|
||||||
|
getProperty(prop.getValue(), "INTERNAL_TOTAL_MEMORY")));
|
||||||
|
deviceInfo.setInternalAvailableMemory(Double.parseDouble(
|
||||||
|
getProperty(prop.getValue(), "INTERNAL_AVAILABLE_MEMORY")));
|
||||||
|
deviceInfo.setExternalTotalMemory(Double.parseDouble(
|
||||||
|
getProperty(prop.getValue(), "EXTERNAL_TOTAL_MEMORY")));
|
||||||
|
deviceInfo.setExternalAvailableMemory(Double.parseDouble(
|
||||||
|
getProperty(prop.getValue(), "EXTERNAL_AVAILABLE_MEMORY")));
|
||||||
|
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("encryptionEnabled",
|
||||||
|
getProperty(prop.getValue(), "ENCRYPTION_ENABLED"));
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("passcodeEnabled",
|
||||||
|
getProperty(prop.getValue(), "PASSCODE_ENABLED"));
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("operator",
|
||||||
|
getProperty(prop.getValue(), "OPERATOR"));
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("PhoneNumber",
|
||||||
|
getProperty(prop.getValue(), "PHONE_NUMBER"));
|
||||||
|
} else if (prop.getName().equalsIgnoreCase("IMEI")) {
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("IMEI", prop.getValue());
|
||||||
|
} else if (prop.getName().equalsIgnoreCase("IMSI")) {
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("IMSI", prop.getValue());
|
||||||
|
} else if (prop.getName().equalsIgnoreCase("MAC")) {
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("mac", prop.getValue());
|
||||||
|
} else if (prop.getName().equalsIgnoreCase("SERIAL")) {
|
||||||
|
deviceInfo.getDeviceDetailsMap().put("serial", prop.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void extractDefinedProperties(DeviceInfo deviceInfo, Device.Property prop) {
|
||||||
|
if (prop.getName().equalsIgnoreCase("DEVICE_MODEL")) {
|
||||||
|
deviceInfo.setDeviceModel(prop.getValue());
|
||||||
|
} else if (prop.getName().equalsIgnoreCase("VENDOR")) {
|
||||||
|
deviceInfo.setVendor(prop.getValue());
|
||||||
|
} else if (prop.getName().equalsIgnoreCase("OS_VERSION")) {
|
||||||
|
deviceInfo.setOsVersion(prop.getValue());
|
||||||
|
} else if (prop.getName().equalsIgnoreCase("OS_BUILD_DATE")) {
|
||||||
|
deviceInfo.setOsBuildDate(prop.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getProperty(String properties, String needed) {
|
||||||
|
// This is not a key value pair. value is the immediate element to its filed name.
|
||||||
|
// Ex:
|
||||||
|
// [{"name":"ENCRYPTION_ENABLED","value":"false"},{"name":"PASSCODE_ENABLED","value":"true"},
|
||||||
|
// {"name":"BATTERY_LEVEL","value":"100"},{"name":"INTERNAL_TOTAL_MEMORY","value":"0.76"}]
|
||||||
|
JsonElement jsonElement = new JsonParser().parse(properties);
|
||||||
|
JsonArray jsonArray = jsonElement.getAsJsonArray();
|
||||||
|
boolean exist = false;
|
||||||
|
for (JsonElement element : jsonArray) {
|
||||||
|
if (element.isJsonObject()) {
|
||||||
|
JsonObject jsonObject = element.getAsJsonObject();
|
||||||
|
if (jsonObject.has("name")
|
||||||
|
&& jsonObject.get("name").getAsString().equalsIgnoreCase(needed)) {
|
||||||
|
if (jsonObject.has("value")) {
|
||||||
|
return jsonObject.get("value").getAsString().replace("%", "");
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<ComplianceFeature> getComplianceFeatures(Object compliancePayload)
|
||||||
|
throws PolicyComplianceException {
|
||||||
|
String compliancePayloadString = new Gson().toJson(compliancePayload);
|
||||||
|
if (compliancePayload == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Parsing json string to get compliance features.
|
||||||
|
JsonElement jsonElement;
|
||||||
|
if (compliancePayloadString instanceof String) {
|
||||||
|
jsonElement = new JsonParser().parse(compliancePayloadString);
|
||||||
|
} else {
|
||||||
|
throw new PolicyComplianceException("Invalid policy compliance payload");
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonArray jsonArray = jsonElement.getAsJsonArray();
|
||||||
|
Gson gson = new Gson();
|
||||||
|
ComplianceFeature complianceFeature;
|
||||||
|
List<ComplianceFeature> complianceFeatures = new ArrayList<ComplianceFeature>(jsonArray.size());
|
||||||
|
|
||||||
|
for (JsonElement element : jsonArray) {
|
||||||
|
complianceFeature = gson.fromJson(element, ComplianceFeature.class);
|
||||||
|
complianceFeatures.add(complianceFeature);
|
||||||
|
}
|
||||||
|
return complianceFeatures;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,15 +422,16 @@ public class AndroidDeviceUtils {
|
|||||||
*/
|
*/
|
||||||
public static BadRequestException buildBadRequestException(String description) {
|
public static BadRequestException buildBadRequestException(String description) {
|
||||||
ErrorResponse errorResponse = getErrorResponse(AndroidConstants.
|
ErrorResponse errorResponse = getErrorResponse(AndroidConstants.
|
||||||
ErrorMessages.STATUS_BAD_REQUEST_MESSAGE_DEFAULT,400l, description);
|
ErrorMessages.STATUS_BAD_REQUEST_MESSAGE_DEFAULT, 400l, description);
|
||||||
return new BadRequestException(errorResponse);
|
return new BadRequestException(errorResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns generic ErrorResponse.
|
* Returns generic ErrorResponse.
|
||||||
|
*
|
||||||
* @param message specific error message
|
* @param message specific error message
|
||||||
* @param code
|
* @param code error code
|
||||||
* @param description
|
* @param description error description
|
||||||
* @return generic Response with error specific details.
|
* @return generic Response with error specific details.
|
||||||
*/
|
*/
|
||||||
public static ErrorResponse getErrorResponse(String message, Long code, String description) {
|
public static ErrorResponse getErrorResponse(String message, Long code, String description) {
|
||||||
|
|||||||
@ -0,0 +1,303 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.mdm.services.android;
|
||||||
|
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
|
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
import org.powermock.modules.testng.PowerMockObjectFactory;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.IObjectFactory;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.ObjectFactory;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
|
import org.wso2.carbon.mdm.services.android.mocks.DeviceManagementProviderServiceMock;
|
||||||
|
import org.wso2.carbon.mdm.services.android.services.impl.DeviceManagementAdminServiceImpl;
|
||||||
|
import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils;
|
||||||
|
import org.wso2.carbon.mdm.services.android.utils.TestUtils;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@PowerMockIgnore({"javax.ws.rs.*", "org.apache.log4j.*"})
|
||||||
|
@PrepareForTest(AndroidAPIUtils.class)
|
||||||
|
public class DeviceManagementAdminServiceTests {
|
||||||
|
|
||||||
|
private DeviceManagementAdminServiceImpl deviceManagementAdminService;
|
||||||
|
|
||||||
|
@ObjectFactory
|
||||||
|
public IObjectFactory getObjectFactory() {
|
||||||
|
return new PowerMockObjectFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public void init() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
deviceManagementAdminService = new DeviceManagementAdminServiceImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mockDeviceManagementService()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(new DeviceManagementProviderServiceMock());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConfigureDeviceLock()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.configureDeviceLock(TestUtils.getDeviceLockBeanWrapper());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConfigureDeviceUnlock()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.configureDeviceUnlock(TestUtils.getDeviceIds());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDeviceLocation()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.getDeviceLocation(TestUtils.getDeviceIds());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemovePassword()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.removePassword(TestUtils.getDeviceIds());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConfigureCamera()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.configureCamera(TestUtils.getCamerabeanWrapper());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDeviceInformation()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.getDeviceInformation(TestUtils.getDeviceIds());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDeviceLogcat()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.getDeviceLogcat(TestUtils.getDeviceIds());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWipeDevice()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.wipeDevice(TestUtils.getDeviceIds());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWipeData()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.wipeData(TestUtils.getWipeDataBeanWrapper());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetApplications()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.getApplications(TestUtils.getDeviceIds());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRingDevice()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.ringDevice(TestUtils.getDeviceIds());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRebootDevice()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.rebootDevice(TestUtils.getDeviceIds());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMuteDevice()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.muteDevice(TestUtils.getDeviceIds());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInstallApplication()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService
|
||||||
|
.installApplication(TestUtils.getApplicationInstallationBeanWrapper());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateApplication()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.updateApplication(TestUtils.getApplicationUpdateBeanWrapper());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUninstallApplicationPublic()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService
|
||||||
|
.uninstallApplication(TestUtils.getApplicationUninstallationBeanWrapperPublic());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUninstallApplicationWebApp()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService
|
||||||
|
.uninstallApplication(TestUtils.getApplicationUninstallationBeanWrapperWebApp());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBlacklistApplications()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService
|
||||||
|
.blacklistApplications(TestUtils.getBlacklistApplicationsBeanWrapper());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpgradeFirmware()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.upgradeFirmware(TestUtils.getUpgradeFirmwareBeanWrapper());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConfigureVPN()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.configureVPN(TestUtils.getVpnBeanWrapper());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSendNotification()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.sendNotification(TestUtils.getNotificationBeanWrapper());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConfigureWifi()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.configureWifi(TestUtils.getWifiBeanWrapper());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEncryptStorage()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.encryptStorage(TestUtils.getEncryptionBeanWrapper());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testChangeLockCode()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.changeLockCode(TestUtils.getLockCodeBeanWrapper());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetPasswordPolicy()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.setPasswordPolicy(TestUtils.getPasswordPolicyBeanWrapper());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetWebClip()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementAdminService.setWebClip(TestUtils.getWebClipBeanWrapper());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,318 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.mdm.services.android;
|
||||||
|
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
|
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
import org.powermock.modules.testng.PowerMockObjectFactory;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.IObjectFactory;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.ObjectFactory;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidDevice;
|
||||||
|
import org.wso2.carbon.mdm.services.android.mocks.ApplicationManagementProviderServiceMock;
|
||||||
|
import org.wso2.carbon.mdm.services.android.mocks.DeviceInformationManagerServiceMock;
|
||||||
|
import org.wso2.carbon.mdm.services.android.mocks.DeviceManagementProviderServiceMock;
|
||||||
|
import org.wso2.carbon.mdm.services.android.mocks.NotificationManagementServiceMock;
|
||||||
|
import org.wso2.carbon.mdm.services.android.mocks.PolicyManagerServiceMock;
|
||||||
|
import org.wso2.carbon.mdm.services.android.services.impl.DeviceManagementServiceImpl;
|
||||||
|
import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils;
|
||||||
|
import org.wso2.carbon.mdm.services.android.utils.TestUtils;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@PowerMockIgnore({"javax.ws.rs.*", "org.apache.log4j.*"})
|
||||||
|
@PrepareForTest(AndroidAPIUtils.class)
|
||||||
|
public class DeviceManagementServiceTests {
|
||||||
|
|
||||||
|
private DeviceManagementServiceImpl deviceManagementService;
|
||||||
|
|
||||||
|
@ObjectFactory
|
||||||
|
public IObjectFactory getObjectFactory() {
|
||||||
|
return new PowerMockObjectFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public void init() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
deviceManagementService = new DeviceManagementServiceImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mockDeviceManagementService()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getDeviceManagementService"))
|
||||||
|
.toReturn(new DeviceManagementProviderServiceMock());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mockApplicationManagerService()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getApplicationManagerService"))
|
||||||
|
.toReturn(new ApplicationManagementProviderServiceMock());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mockPolicyManagerService()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getPolicyManagerService"))
|
||||||
|
.toReturn(new PolicyManagerServiceMock());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mockDeviceInformationManagerService()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getDeviceInformationManagerService"))
|
||||||
|
.toReturn(new DeviceInformationManagerServiceMock());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mockNotificationManagementService()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getNotificationManagementService"))
|
||||||
|
.toReturn(new NotificationManagementServiceMock());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mockUser()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getAuthenticatedUser"))
|
||||||
|
.toReturn("admin");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateApplicationList()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockApplicationManagerService();
|
||||||
|
Response response = deviceManagementService
|
||||||
|
.updateApplicationList(TestUtils.getDeviceId(), TestUtils.getAndroidApplications());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetPendingOperationsForNullDevice()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
Response response = deviceManagementService
|
||||||
|
.getPendingOperations(null, null, null);
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetPendingOperationsInvalidDevice()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementService
|
||||||
|
.getPendingOperations("1234", null, null);
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetPendingOperationsNullResponse()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementService
|
||||||
|
.getPendingOperations(TestUtils.getDeviceId(), null, null);
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetPendingOperationsWithMonitorResponse()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
mockPolicyManagerService();
|
||||||
|
Response response = deviceManagementService
|
||||||
|
.getPendingOperations(TestUtils.getDeviceId(), null,
|
||||||
|
TestUtils.getSuccessMonitorOperationResponse());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetPendingOperationsWithApplicationResponse()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
mockApplicationManagerService();
|
||||||
|
Response response = deviceManagementService
|
||||||
|
.getPendingOperations(TestUtils.getDeviceId(), null,
|
||||||
|
TestUtils.getSuccessApplicationOperationResponse());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetPendingOperationsWithDeviceInfoResponse()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
mockDeviceInformationManagerService();
|
||||||
|
Response response = deviceManagementService
|
||||||
|
.getPendingOperations(TestUtils.getDeviceId(), null,
|
||||||
|
TestUtils.getSuccessInfoOperationResponse());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetPendingOperationsWithInProgressResponse()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementService
|
||||||
|
.getPendingOperations(TestUtils.getDeviceId(), null,
|
||||||
|
TestUtils.getInProgressOperationResponse());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetPendingOperationsWithErrorResponse()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
mockNotificationManagementService();
|
||||||
|
Response response = deviceManagementService
|
||||||
|
.getPendingOperations(TestUtils.getDeviceId(), null,
|
||||||
|
TestUtils.getErrorOperationResponse());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnrollDeviceWithoutLocationSuccess()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
mockPolicyManagerService();
|
||||||
|
mockUser();
|
||||||
|
Response response = deviceManagementService.enrollDevice(TestUtils.getBasicAndroidDevice());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnrollDeviceWithLocationSuccess()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
mockDeviceInformationManagerService();
|
||||||
|
mockPolicyManagerService();
|
||||||
|
mockUser();
|
||||||
|
AndroidDevice androidDevice = TestUtils.getBasicAndroidDevice();
|
||||||
|
|
||||||
|
List<Device.Property> properties = new ArrayList<>();
|
||||||
|
Device.Property property = new Device.Property();
|
||||||
|
property.setName("LATITUDE");
|
||||||
|
property.setValue("79.5");
|
||||||
|
properties.add(property);
|
||||||
|
property = new Device.Property();
|
||||||
|
property.setName("LONGITUDE");
|
||||||
|
property.setValue("6.9");
|
||||||
|
properties.add(property);
|
||||||
|
androidDevice.setProperties(properties);
|
||||||
|
|
||||||
|
Response response = deviceManagementService.enrollDevice(androidDevice);
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnrollDeviceUnSuccess()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
mockUser();
|
||||||
|
AndroidDevice androidDevice = TestUtils.getBasicAndroidDevice();
|
||||||
|
androidDevice.setDeviceIdentifier("1234");
|
||||||
|
Response response = deviceManagementService.enrollDevice(androidDevice);
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsEnrolledExists()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementService.isEnrolled(TestUtils.getDeviceId(), null);
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsEnrolledNonExist()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementService.isEnrolled("1234", null);
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsEnrolledNull()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementService.isEnrolled(null, null);
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testModifyEnrollmentSuccess()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
mockUser();
|
||||||
|
Response response = deviceManagementService
|
||||||
|
.modifyEnrollment(TestUtils.getDeviceId(), TestUtils.getBasicAndroidDevice());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testModifyEnrollmentUnSuccess()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
mockUser();
|
||||||
|
AndroidDevice androidDevice = TestUtils.getBasicAndroidDevice();
|
||||||
|
androidDevice.setDeviceIdentifier("1234");
|
||||||
|
Response response = deviceManagementService
|
||||||
|
.modifyEnrollment(TestUtils.getDeviceId(), androidDevice);
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.NOT_MODIFIED.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDisEnrollDeviceSuccess()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementService.disEnrollDevice(TestUtils.getDeviceId());
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDisenrollUnSuccess()
|
||||||
|
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
|
mockDeviceManagementService();
|
||||||
|
Response response = deviceManagementService.disEnrollDevice("1234");
|
||||||
|
Assert.assertNotNull(response);
|
||||||
|
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.mdm.services.android.mocks;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||||
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
|
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ApplicationManagementProviderServiceMock implements ApplicationManagementProviderService {
|
||||||
|
@Override
|
||||||
|
public void updateApplicationListInstalledInDevice(DeviceIdentifier deviceIdentifier, List<Application> list)
|
||||||
|
throws ApplicationManagementException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Application> getApplicationListForDevice(DeviceIdentifier deviceIdentifier)
|
||||||
|
throws ApplicationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Application[] getApplications(String s, int i, int i1) throws ApplicationManagementException {
|
||||||
|
return new Application[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateApplicationStatus(DeviceIdentifier deviceIdentifier, Application application, String s)
|
||||||
|
throws ApplicationManagementException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getApplicationStatus(DeviceIdentifier deviceIdentifier, Application application)
|
||||||
|
throws ApplicationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Activity installApplicationForDevices(Operation operation, List<DeviceIdentifier> list)
|
||||||
|
throws ApplicationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Activity installApplicationForUsers(Operation operation, List<String> list)
|
||||||
|
throws ApplicationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Activity installApplicationForUserRoles(Operation operation, List<String> list)
|
||||||
|
throws ApplicationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
package org.wso2.carbon.mdm.services.android.mocks;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
||||||
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DeviceInformationManagerServiceMock implements DeviceInformationManager {
|
||||||
|
@Override
|
||||||
|
public void addDeviceInfo(DeviceIdentifier deviceIdentifier, DeviceInfo deviceInfo)
|
||||||
|
throws DeviceDetailsMgtException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceInfo getDeviceInfo(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeviceInfo> getDevicesInfo(List<DeviceIdentifier> list) throws DeviceDetailsMgtException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addDeviceLocation(DeviceLocation deviceLocation) throws DeviceDetailsMgtException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceLocation getDeviceLocation(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeviceLocation> getDeviceLocations(List<DeviceIdentifier> list) throws DeviceDetailsMgtException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,504 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.mdm.services.android.mocks;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
|
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.MonitoringOperation;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
|
||||||
|
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||||
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo;
|
||||||
|
import org.wso2.carbon.mdm.services.android.utils.TestUtils;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DeviceManagementProviderServiceMock implements DeviceManagementProviderService {
|
||||||
|
@Override
|
||||||
|
public List<Device> getAllDevices(String s) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getAllDevices(String s, boolean b) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getAllDevices() throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getAllDevices(boolean b) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getDevices(Date date) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getDevices(Date date, boolean b) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult getDevicesByType(PaginationRequest paginationRequest) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult getDevicesByType(PaginationRequest paginationRequest, boolean b)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult getAllDevices(PaginationRequest paginationRequest) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult getAllDevices(PaginationRequest paginationRequest, boolean b)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Device getDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
||||||
|
if (TestUtils.getDeviceId().equals(deviceIdentifier.getId())) {
|
||||||
|
return TestUtils.getDevice();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Device getDeviceWithTypeProperties(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Device getDevice(DeviceIdentifier deviceIdentifier, boolean b) throws DeviceManagementException {
|
||||||
|
if (TestUtils.getDeviceId().equals(deviceIdentifier.getId())) {
|
||||||
|
return TestUtils.getDevice();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Device getDevice(DeviceIdentifier deviceIdentifier, String s, boolean b) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Device getDevice(DeviceIdentifier deviceIdentifier, Date date) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Device getDevice(DeviceIdentifier deviceIdentifier, Date date, boolean b) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Device getDevice(DeviceIdentifier deviceIdentifier, String s, Date date, boolean b)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Device getDevice(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status status)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Device getDevice(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status status, boolean b)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult getDevicesOfUser(PaginationRequest paginationRequest) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult getDevicesOfUser(PaginationRequest paginationRequest, boolean b)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult getDevicesByOwnership(PaginationRequest paginationRequest)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult getDevicesByOwnership(PaginationRequest paginationRequest, boolean b)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getDevicesOfUser(String s) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getDevicesOfUser(String s, boolean b) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getDevicesOfUser(String s, String s1) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getDevicesOfUser(String s, String s1, boolean b) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getAllDevicesOfRole(String s) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getAllDevicesOfRole(String s, boolean b) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult getDevicesByStatus(PaginationRequest paginationRequest) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult getDevicesByStatus(PaginationRequest paginationRequest, boolean b)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getDevicesByNameAndType(PaginationRequest paginationRequest, boolean b)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult getDevicesByName(PaginationRequest paginationRequest) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult getDevicesByName(PaginationRequest paginationRequest, boolean b)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getDevicesByStatus(EnrolmentInfo.Status status) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getDevicesByStatus(EnrolmentInfo.Status status, boolean b) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDeviceCount(String s) throws DeviceManagementException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDeviceCount() throws DeviceManagementException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashMap<Integer, Device> getTenantedDevice(DeviceIdentifier deviceIdentifier)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendEnrolmentInvitation(String s, EmailMetaInfo emailMetaInfo)
|
||||||
|
throws DeviceManagementException, ConfigurationManagementException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendRegistrationEmail(EmailMetaInfo emailMetaInfo)
|
||||||
|
throws DeviceManagementException, ConfigurationManagementException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureManager getFeatureManager(String s) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PlatformConfiguration getConfiguration(String s) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnrolled(DeviceIdentifier deviceIdentifier, String s) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NotificationStrategy getNotificationStrategyByDeviceType(String s) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public License getLicense(String s, String s1) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addLicense(String s, License license) throws DeviceManagementException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||||
|
return TestUtils.getDeviceId().equals(device.getDeviceIdentifier());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||||
|
return TestUtils.getDeviceId().equals(device.getDeviceIdentifier());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean saveConfiguration(PlatformConfiguration platformConfiguration) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean disenrollDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
||||||
|
return TestUtils.getDeviceId().equals(deviceIdentifier.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnrolled(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActive(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setActive(DeviceIdentifier deviceIdentifier, boolean b) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getAvailableDeviceTypes() throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setOwnership(DeviceIdentifier deviceIdentifier, String s) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setStatus(DeviceIdentifier deviceIdentifier, String s, EnrolmentInfo.Status status)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setStatus(String s, EnrolmentInfo.Status status) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notifyOperationToDevices(Operation operation, List<DeviceIdentifier> list)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Activity addOperation(String s, Operation operation, List<DeviceIdentifier> list)
|
||||||
|
throws OperationManagementException, InvalidDeviceException {
|
||||||
|
return TestUtils.getActivity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends Operation> getOperations(DeviceIdentifier deviceIdentifier)
|
||||||
|
throws OperationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult getOperations(DeviceIdentifier deviceIdentifier, PaginationRequest paginationRequest)
|
||||||
|
throws OperationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceIdentifier)
|
||||||
|
throws OperationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Operation getNextPendingOperation(DeviceIdentifier deviceIdentifier) throws OperationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateOperation(DeviceIdentifier deviceIdentifier, Operation operation)
|
||||||
|
throws OperationManagementException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceIdentifier, int i)
|
||||||
|
throws OperationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends Operation> getOperationsByDeviceAndStatus(DeviceIdentifier deviceIdentifier,
|
||||||
|
Operation.Status status)
|
||||||
|
throws OperationManagementException, DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Operation getOperation(String s, int i) throws OperationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Activity getOperationByActivityId(String s) throws OperationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Activity getOperationByActivityIdAndDevice(String s, DeviceIdentifier deviceIdentifier)
|
||||||
|
throws OperationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Activity> getActivitiesUpdatedAfter(long l, int i, int i1) throws OperationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getActivityCountUpdatedAfter(long l) throws OperationManagementException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MonitoringOperation> getMonitoringOperationList(String s) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDeviceMonitoringFrequency(String s) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDeviceMonitoringEnabled(String s) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PolicyMonitoringManager getPolicyMonitoringManager(String s) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean changeDeviceStatus(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status status)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerDeviceType(DeviceManagementService deviceManagementService) throws DeviceManagementException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceType getDeviceType(String s) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeviceType> getDeviceTypes() throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notifyPullNotificationSubscriber(DeviceIdentifier deviceIdentifier, Operation operation)
|
||||||
|
throws PullNotificationExecutionFailedException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Integer> getDeviceEnrolledTenants() throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.mdm.services.android.mocks;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
|
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||||
|
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class NotificationManagementServiceMock implements NotificationManagementService {
|
||||||
|
@Override
|
||||||
|
public boolean addNotification(DeviceIdentifier deviceIdentifier, Notification notification)
|
||||||
|
throws NotificationManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateNotification(Notification notification) throws NotificationManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateNotificationStatus(int i, Notification.Status status) throws NotificationManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Notification> getAllNotifications() throws NotificationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Notification getNotification(int i) throws NotificationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult getAllNotifications(PaginationRequest paginationRequest)
|
||||||
|
throws NotificationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Notification> getNotificationsByStatus(Notification.Status status)
|
||||||
|
throws NotificationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult getNotificationsByStatus(Notification.Status status, PaginationRequest paginationRequest)
|
||||||
|
throws NotificationManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,142 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.mdm.services.android.mocks;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
|
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
|
||||||
|
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
|
||||||
|
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
|
||||||
|
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
|
||||||
|
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
|
||||||
|
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PolicyManagerServiceMock implements PolicyManagerService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Profile addProfile(Profile profile) throws PolicyManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Profile updateProfile(Profile profile) throws PolicyManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Policy addPolicy(Policy policy) throws PolicyManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Policy updatePolicy(Policy policy) throws PolicyManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deletePolicy(Policy policy) throws PolicyManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deletePolicy(int i) throws PolicyManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier)
|
||||||
|
throws FeatureManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Policy> getPolicies(String s) throws PolicyManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Feature> getFeatures() throws FeatureManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PolicyAdministratorPoint getPAP() throws PolicyManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PolicyInformationPoint getPIP() throws PolicyManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PolicyEvaluationPoint getPEP() throws PolicyManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TaskScheduleService getTaskScheduleService() throws PolicyMonitoringTaskException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPolicyCount() throws PolicyManagementException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Policy getAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ComplianceFeature> checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Object o)
|
||||||
|
throws PolicyComplianceException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkCompliance(DeviceIdentifier deviceIdentifier, Object o) throws PolicyComplianceException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NonComplianceData getDeviceCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,425 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.mdm.services.android.utils;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||||
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.ApplicationInstallation;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.ApplicationUninstallation;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.ApplicationUpdate;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.BlacklistApplications;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.Camera;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.DeviceEncryption;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.DeviceLock;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.LockCode;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.Notification;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.PasscodePolicy;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.UpgradeFirmware;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.Vpn;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.WebClip;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.Wifi;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.WipeData;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidApplication;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidDevice;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationInstallationBeanWrapper;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationUninstallationBeanWrapper;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationUpdateBeanWrapper;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.BlacklistApplicationsBeanWrapper;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.CameraBeanWrapper;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.DeviceLockBeanWrapper;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.EncryptionBeanWrapper;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.LockCodeBeanWrapper;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.NotificationBeanWrapper;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.PasswordPolicyBeanWrapper;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.UpgradeFirmwareBeanWrapper;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.VpnBeanWrapper;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.WebClipBeanWrapper;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.WifiBeanWrapper;
|
||||||
|
import org.wso2.carbon.mdm.services.android.bean.wrapper.WipeDataBeanWrapper;
|
||||||
|
import org.wso2.carbon.mdm.services.android.util.AndroidConstants;
|
||||||
|
import org.wso2.carbon.mdm.services.android.util.AndroidDeviceUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TestUtils {
|
||||||
|
|
||||||
|
public static Activity getActivity() {
|
||||||
|
Activity activity = new Activity();
|
||||||
|
activity.setActivityId("ACTIVITY_1");
|
||||||
|
activity.setCode("CODE");
|
||||||
|
return activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDeviceId() {
|
||||||
|
return "1a2b3c4d5e";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getDeviceIds() {
|
||||||
|
List<String> deviceIds = new ArrayList<>();
|
||||||
|
deviceIds.add(getDeviceId());
|
||||||
|
return deviceIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Device getDevice() {
|
||||||
|
Device device = new Device();
|
||||||
|
device.setId(1);
|
||||||
|
device.setName("Test");
|
||||||
|
device.setDeviceIdentifier(getDeviceId());
|
||||||
|
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||||
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||||
|
enrolmentInfo.setId(1);
|
||||||
|
enrolmentInfo.setOwner("admin");
|
||||||
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
||||||
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
|
device.setEnrolmentInfo(enrolmentInfo);
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DeviceLockBeanWrapper getDeviceLockBeanWrapper() {
|
||||||
|
DeviceLockBeanWrapper deviceLockBeanWrapper = new DeviceLockBeanWrapper();
|
||||||
|
deviceLockBeanWrapper.setDeviceIDs(getDeviceIds());
|
||||||
|
DeviceLock deviceLockOperation = new DeviceLock();
|
||||||
|
deviceLockOperation.setHardLockEnabled(true);
|
||||||
|
deviceLockOperation.setMessage("Test Operation");
|
||||||
|
deviceLockBeanWrapper.setOperation(deviceLockOperation);
|
||||||
|
return deviceLockBeanWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CameraBeanWrapper getCamerabeanWrapper() {
|
||||||
|
CameraBeanWrapper cameraBeanWrapper = new CameraBeanWrapper();
|
||||||
|
cameraBeanWrapper.setDeviceIDs(getDeviceIds());
|
||||||
|
Camera camera = new Camera();
|
||||||
|
camera.setEnabled(false);
|
||||||
|
cameraBeanWrapper.setOperation(camera);
|
||||||
|
return cameraBeanWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WipeDataBeanWrapper getWipeDataBeanWrapper() {
|
||||||
|
WipeDataBeanWrapper wipeDataBeanWrapper = new WipeDataBeanWrapper();
|
||||||
|
wipeDataBeanWrapper.setDeviceIDs(getDeviceIds());
|
||||||
|
WipeData wipeData = new WipeData();
|
||||||
|
wipeData.setPin("1234");
|
||||||
|
wipeDataBeanWrapper.setOperation(wipeData);
|
||||||
|
return wipeDataBeanWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApplicationInstallationBeanWrapper getApplicationInstallationBeanWrapper() {
|
||||||
|
ApplicationInstallationBeanWrapper applicationInstallationBeanWrapper = new ApplicationInstallationBeanWrapper();
|
||||||
|
applicationInstallationBeanWrapper.setDeviceIDs(getDeviceIds());
|
||||||
|
ApplicationInstallation applicationInstallation = new ApplicationInstallation();
|
||||||
|
applicationInstallation.setAppIdentifier("org.wso2.iot.agent");
|
||||||
|
applicationInstallation.setUrl("https://github.com/wso2/cdmf-agent-android/releases/download/v3.1.21/client-standalone.apk");
|
||||||
|
applicationInstallation.setType("enterprise");
|
||||||
|
applicationInstallation.setSchedule("2017-10-11T18:46:19-0530");
|
||||||
|
applicationInstallationBeanWrapper.setOperation(applicationInstallation);
|
||||||
|
return applicationInstallationBeanWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApplicationUpdateBeanWrapper getApplicationUpdateBeanWrapper() {
|
||||||
|
ApplicationUpdateBeanWrapper applicationUpdateBeanWrapper = new ApplicationUpdateBeanWrapper();
|
||||||
|
applicationUpdateBeanWrapper.setDeviceIDs(getDeviceIds());
|
||||||
|
ApplicationUpdate applicationUpdate = new ApplicationUpdate();
|
||||||
|
applicationUpdate.setAppIdentifier("org.wso2.iot.agent");
|
||||||
|
applicationUpdate.setUrl("https://github.com/wso2/cdmf-agent-android/releases/download/v3.1.21/client-standalone.apk");
|
||||||
|
applicationUpdate.setType("enterprise");
|
||||||
|
applicationUpdate.setSchedule("2017-10-11T18:46:19-0530");
|
||||||
|
applicationUpdateBeanWrapper.setOperation(applicationUpdate);
|
||||||
|
return applicationUpdateBeanWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApplicationUninstallationBeanWrapper getApplicationUninstallationBeanWrapperPublic() {
|
||||||
|
ApplicationUninstallationBeanWrapper applicationUninstallationBeanWrapper = new ApplicationUninstallationBeanWrapper();
|
||||||
|
applicationUninstallationBeanWrapper.setDeviceIDs(getDeviceIds());
|
||||||
|
ApplicationUninstallation applicationUninstallation = new ApplicationUninstallation();
|
||||||
|
applicationUninstallation.setAppIdentifier("org.wso2.iot.agent");
|
||||||
|
applicationUninstallation.setType("public");
|
||||||
|
applicationUninstallationBeanWrapper.setOperation(applicationUninstallation);
|
||||||
|
return applicationUninstallationBeanWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApplicationUninstallationBeanWrapper getApplicationUninstallationBeanWrapperWebApp() {
|
||||||
|
ApplicationUninstallationBeanWrapper applicationUninstallationBeanWrapper = new ApplicationUninstallationBeanWrapper();
|
||||||
|
applicationUninstallationBeanWrapper.setDeviceIDs(getDeviceIds());
|
||||||
|
ApplicationUninstallation applicationUninstallation = new ApplicationUninstallation();
|
||||||
|
applicationUninstallation.setAppIdentifier("org.wso2.iot.agent");
|
||||||
|
applicationUninstallation.setType("webapp");
|
||||||
|
applicationUninstallationBeanWrapper.setOperation(applicationUninstallation);
|
||||||
|
return applicationUninstallationBeanWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BlacklistApplicationsBeanWrapper getBlacklistApplicationsBeanWrapper() {
|
||||||
|
BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper = new BlacklistApplicationsBeanWrapper();
|
||||||
|
blacklistApplicationsBeanWrapper.setDeviceIDs(getDeviceIds());
|
||||||
|
BlacklistApplications blacklistApplications = new BlacklistApplications();
|
||||||
|
List<String> appIds = new ArrayList<>();
|
||||||
|
appIds.add("org.wso2.iot.agent");
|
||||||
|
blacklistApplications.setAppIdentifier(appIds);
|
||||||
|
blacklistApplicationsBeanWrapper.setOperation(blacklistApplications);
|
||||||
|
return blacklistApplicationsBeanWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UpgradeFirmwareBeanWrapper getUpgradeFirmwareBeanWrapper() {
|
||||||
|
UpgradeFirmwareBeanWrapper upgradeFirmwareBeanWrapper = new UpgradeFirmwareBeanWrapper();
|
||||||
|
upgradeFirmwareBeanWrapper.setDeviceIDs(getDeviceIds());
|
||||||
|
UpgradeFirmware upgradeFirmware = new UpgradeFirmware();
|
||||||
|
upgradeFirmware.setServer("https://github.com/wso2/cdmf-agent-android/releases/download/");
|
||||||
|
upgradeFirmware.setSchedule("2017-10-11T18:46:19-0530");
|
||||||
|
upgradeFirmwareBeanWrapper.setOperation(upgradeFirmware);
|
||||||
|
return upgradeFirmwareBeanWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VpnBeanWrapper getVpnBeanWrapper() {
|
||||||
|
VpnBeanWrapper vpnBeanWrapper = new VpnBeanWrapper();
|
||||||
|
vpnBeanWrapper.setDeviceIDs(getDeviceIds());
|
||||||
|
Vpn vpn = new Vpn();
|
||||||
|
vpnBeanWrapper.setOperation(vpn);
|
||||||
|
return vpnBeanWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NotificationBeanWrapper getNotificationBeanWrapper() {
|
||||||
|
NotificationBeanWrapper notificationBeanWrapper = new NotificationBeanWrapper();
|
||||||
|
notificationBeanWrapper.setDeviceIDs(getDeviceIds());
|
||||||
|
Notification notification = new Notification();
|
||||||
|
notification.setMessageText("Message");
|
||||||
|
notification.setMessageTitle("Title");
|
||||||
|
notificationBeanWrapper.setOperation(notification);
|
||||||
|
return notificationBeanWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WifiBeanWrapper getWifiBeanWrapper() {
|
||||||
|
WifiBeanWrapper wifiBeanWrapper = new WifiBeanWrapper();
|
||||||
|
wifiBeanWrapper.setDeviceIDs(getDeviceIds());
|
||||||
|
Wifi wifi = new Wifi();
|
||||||
|
wifiBeanWrapper.setOperation(wifi);
|
||||||
|
return wifiBeanWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EncryptionBeanWrapper getEncryptionBeanWrapper() {
|
||||||
|
EncryptionBeanWrapper encryptionBeanWrapper = new EncryptionBeanWrapper();
|
||||||
|
encryptionBeanWrapper.setDeviceIDs(getDeviceIds());
|
||||||
|
DeviceEncryption deviceEncryption = new DeviceEncryption();
|
||||||
|
deviceEncryption.setEncrypted(true);
|
||||||
|
encryptionBeanWrapper.setOperation(deviceEncryption);
|
||||||
|
return encryptionBeanWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LockCodeBeanWrapper getLockCodeBeanWrapper() {
|
||||||
|
LockCodeBeanWrapper lockCodeBeanWrapper = new LockCodeBeanWrapper();
|
||||||
|
lockCodeBeanWrapper.setDeviceIDs(getDeviceIds());
|
||||||
|
LockCode lockCode = new LockCode();
|
||||||
|
lockCode.setLockCode("1234");
|
||||||
|
lockCodeBeanWrapper.setOperation(lockCode);
|
||||||
|
return lockCodeBeanWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PasswordPolicyBeanWrapper getPasswordPolicyBeanWrapper() {
|
||||||
|
PasswordPolicyBeanWrapper passwordPolicyBeanWrapper = new PasswordPolicyBeanWrapper();
|
||||||
|
passwordPolicyBeanWrapper.setDeviceIDs(getDeviceIds());
|
||||||
|
PasscodePolicy passcodePolicy = new PasscodePolicy();
|
||||||
|
passwordPolicyBeanWrapper.setOperation(passcodePolicy);
|
||||||
|
return passwordPolicyBeanWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WebClipBeanWrapper getWebClipBeanWrapper() {
|
||||||
|
WebClipBeanWrapper webClipBeanWrapper = new WebClipBeanWrapper();
|
||||||
|
webClipBeanWrapper.setDeviceIDs(getDeviceIds());
|
||||||
|
WebClip webClip = new WebClip();
|
||||||
|
webClipBeanWrapper.setOperation(webClip);
|
||||||
|
return webClipBeanWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<AndroidApplication> getAndroidApplications() {
|
||||||
|
List<AndroidApplication> androidApplications = new ArrayList<>();
|
||||||
|
AndroidApplication androidApplication = new AndroidApplication();
|
||||||
|
androidApplications.add(androidApplication);
|
||||||
|
return androidApplications;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Operation> getSuccessMonitorOperationResponse() {
|
||||||
|
List<Operation> operations = new ArrayList<>();
|
||||||
|
Operation operation = new Operation();
|
||||||
|
operation.setActivityId(getActivity().getActivityId());
|
||||||
|
operation.setCode(AndroidConstants.OperationCodes.MONITOR);
|
||||||
|
operation.setId(1);
|
||||||
|
operation.setOperationResponse("Operation success.");
|
||||||
|
operation.setStatus(Operation.Status.COMPLETED);
|
||||||
|
operations.add(operation);
|
||||||
|
return operations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Operation> getSuccessApplicationOperationResponse() {
|
||||||
|
List<Operation> operations = new ArrayList<>();
|
||||||
|
Operation operation = new Operation();
|
||||||
|
operation.setActivityId(getActivity().getActivityId());
|
||||||
|
operation.setCode(AndroidConstants.OperationCodes.APPLICATION_LIST);
|
||||||
|
operation.setId(1);
|
||||||
|
operation.setOperationResponse("[{\"name\":\"Widget%20Preview\",\"package\":\"com.android.widgetpreview\"," +
|
||||||
|
"\"version\":\"7.1.1\",\"isSystemApp\":false,\"isActive\":false}," +
|
||||||
|
"{\"name\":\"com.android.gesture.builder\"," +
|
||||||
|
"\"package\":\"com.android.gesture.builder\",\"version\":\"7.1.1\"," +
|
||||||
|
"\"isSystemApp\":false,\"isActive\":false},{\"name\":\"API%20Demos\"," +
|
||||||
|
"\"package\":\"com.example.android.apis\",\"version\":\"7.1.1\"," +
|
||||||
|
"\"isSystemApp\":false,\"isActive\":false}," +
|
||||||
|
"{\"name\":\"WSO2%20Device%20Management%20Agent\"," +
|
||||||
|
"\"package\":\"org.wso2.iot.agent\",\"version\":\"3.1.21\"," +
|
||||||
|
"\"isSystemApp\":false,\"isActive\":true}," +
|
||||||
|
"{\"name\":\"com.android.smoketest.tests\"," +
|
||||||
|
"\"package\":\"com.android.smoketest.tests\",\"version\":\"7.1.1\"," +
|
||||||
|
"\"isSystemApp\":false,\"isActive\":false}," +
|
||||||
|
"{\"name\":\"Sample%20Soft%20Keyboard\"," +
|
||||||
|
"\"package\":\"com.example.android.softkeyboard\",\"version\":\"7.1.1\"," +
|
||||||
|
"\"isSystemApp\":false,\"isActive\":false},{\"name\":\"Example%20Wallpapers\"," +
|
||||||
|
"\"package\":\"com.example.android.livecubes\",\"version\":\"7.1.1\"," +
|
||||||
|
"\"isSystemApp\":false,\"isActive\":false},{\"name\":\"com.android.smoketest\"," +
|
||||||
|
"\"package\":\"com.android.smoketest\",\"version\":\"7.1.1\"," +
|
||||||
|
"\"isSystemApp\":false,\"isActive\":false}]");
|
||||||
|
operation.setStatus(Operation.Status.COMPLETED);
|
||||||
|
operations.add(operation);
|
||||||
|
return operations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Operation> getSuccessInfoOperationResponse() {
|
||||||
|
List<Operation> operations = new ArrayList<>();
|
||||||
|
Operation operation = new Operation();
|
||||||
|
operation.setActivityId(getActivity().getActivityId());
|
||||||
|
operation.setCode(AndroidConstants.OperationCodes.DEVICE_INFO);
|
||||||
|
operation.setId(1);
|
||||||
|
operation.setOperationResponse("{\"description\":\"generic_x86\",\"deviceIdentifier\":\"1d9612def9d205f9\"," +
|
||||||
|
"\"enrolmentInfo\":null,\"name\":\"generic_x86\",\"properties\":[" +
|
||||||
|
"{\"name\":\"SERIAL\",\"value\":\"unknown\"}," +
|
||||||
|
"{\"name\":\"IMEI\",\"value\":null}," +
|
||||||
|
"{\"name\":\"IMSI\",\"value\":\"310260000000000\"}," +
|
||||||
|
"{\"name\":\"MAC\",\"value\":\"02:00:00:00:00:00\"}," +
|
||||||
|
"{\"name\":\"DEVICE_MODEL\",\"value\":\"Android SDK built for x86\"}," +
|
||||||
|
"{\"name\":\"VENDOR\",\"value\":\"unknown\"}," +
|
||||||
|
"{\"name\":\"OS_VERSION\",\"value\":\"7.1.1\"}," +
|
||||||
|
"{\"name\":\"OS_BUILD_DATE\",\"value\":\"1487782847000\"}," +
|
||||||
|
"{\"name\":\"DEVICE_NAME\",\"value\":\"generic_x86\"}," +
|
||||||
|
"{\"name\":\"LATITUDE\",\"value\":\"6.90988\"}," +
|
||||||
|
"{\"name\":\"LONGITUDE\",\"value\":\"79.85249999999999\"}," +
|
||||||
|
"{\"name\":\"NETWORK_INFO\",\"value\":\"[" +
|
||||||
|
"{\\\"name\\\":\\\"CONNECTION_TYPE\\\",\\\"value\\\":\\\"MOBILE\\\"}," +
|
||||||
|
"{\\\"name\\\":\\\"MOBILE_CONNECTION_TYPE\\\",\\\"value\\\":\\\"LTE\\\"}," +
|
||||||
|
"{\\\"name\\\":\\\"MOBILE_SIGNAL_STRENGTH\\\",\\\"value\\\":\\\"-89\\\"}]\"}," +
|
||||||
|
"{\"name\":\"CPU_INFO\",\"value\":\"[]\"},{\"name\":\"RAM_INFO\",\"value\":\"[" +
|
||||||
|
"{\\\"name\\\":\\\"TOTAL_MEMORY\\\",\\\"value\\\":\\\"1055113216\\\"}," +
|
||||||
|
"{\\\"name\\\":\\\"AVAILABLE_MEMORY\\\",\\\"value\\\":\\\"708997120\\\"}," +
|
||||||
|
"{\\\"name\\\":\\\"THRESHOLD\\\",\\\"value\\\":\\\"150994944\\\"}," +
|
||||||
|
"{\\\"name\\\":\\\"LOW_MEMORY\\\",\\\"value\\\":\\\"false\\\"}]\"}," +
|
||||||
|
"{\"name\":\"BATTERY_INFO\",\"value\":\"[" +
|
||||||
|
"{\\\"name\\\":\\\"BATTERY_LEVEL\\\",\\\"value\\\":\\\"100\\\"}," +
|
||||||
|
"{\\\"name\\\":\\\"SCALE\\\",\\\"value\\\":\\\"100\\\"}," +
|
||||||
|
"{\\\"BATTERY_VOLTAGE\\\":\\\"0\\\"}," +
|
||||||
|
"{\\\"name\\\":\\\"HEALTH\\\",\\\"value\\\":\\\"GOOD_CONDITION\\\"}," +
|
||||||
|
"{\\\"name\\\":\\\"STATUS\\\"}," +
|
||||||
|
"{\\\"name\\\":\\\"PLUGGED\\\",\\\"value\\\":\\\"AC\\\"}]\"}," +
|
||||||
|
"{\"name\":\"DEVICE_INFO\",\"value\":\"[" +
|
||||||
|
"{\\\"name\\\":\\\"ENCRYPTION_ENABLED\\\",\\\"value\\\":\\\"false\\\"}," +
|
||||||
|
"{\\\"name\\\":\\\"PASSCODE_ENABLED\\\",\\\"value\\\":\\\"true\\\"}," +
|
||||||
|
"{\\\"name\\\":\\\"BATTERY_LEVEL\\\",\\\"value\\\":\\\"100\\\"}," +
|
||||||
|
"{\\\"name\\\":\\\"INTERNAL_TOTAL_MEMORY\\\",\\\"value\\\":\\\"0.76\\\"}," +
|
||||||
|
"{\\\"name\\\":\\\"INTERNAL_AVAILABLE_MEMORY\\\",\\\"value\\\":\\\"0.67\\\"}," +
|
||||||
|
"{\\\"name\\\":\\\"EXTERNAL_TOTAL_MEMORY\\\",\\\"value\\\":\\\"0.1\\\"}," +
|
||||||
|
"{\\\"name\\\":\\\"EXTERNAL_AVAILABLE_MEMORY\\\",\\\"value\\\":\\\"0.1\\\"}," +
|
||||||
|
"{\\\"name\\\":\\\"OPERATOR\\\",\\\"value\\\":\\\"Android\\\"}," +
|
||||||
|
"{\\\"name\\\":\\\"PHONE_NUMBER\\\",\\\"value\\\":\\\"15555215554\\\"}]\"}]}");
|
||||||
|
operation.setStatus(Operation.Status.COMPLETED);
|
||||||
|
operations.add(operation);
|
||||||
|
return operations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Operation> getInProgressOperationResponse() {
|
||||||
|
List<Operation> operations = new ArrayList<>();
|
||||||
|
Operation operation = new Operation();
|
||||||
|
operation.setActivityId(getActivity().getActivityId());
|
||||||
|
operation.setCode(AndroidConstants.OperationCodes.NOTIFICATION);
|
||||||
|
operation.setId(1);
|
||||||
|
operation.setOperationResponse("Operation in progress.");
|
||||||
|
operation.setStatus(Operation.Status.IN_PROGRESS);
|
||||||
|
operations.add(operation);
|
||||||
|
return operations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Operation> getErrorOperationResponse() {
|
||||||
|
List<Operation> operations = new ArrayList<>();
|
||||||
|
Operation operation = new Operation();
|
||||||
|
operation.setActivityId(getActivity().getActivityId());
|
||||||
|
operation.setCode(AndroidConstants.OperationCodes.DEVICE_INFO);
|
||||||
|
operation.setId(1);
|
||||||
|
operation.setOperationResponse("Operation failure.");
|
||||||
|
operation.setStatus(Operation.Status.ERROR);
|
||||||
|
operations.add(operation);
|
||||||
|
return operations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DeviceLocation getDeviceLocation() {
|
||||||
|
DeviceLocation location = new DeviceLocation();
|
||||||
|
location.setCity("Colombo");
|
||||||
|
location.setCountry("Sri Lanka");
|
||||||
|
location.setLatitude(6.9);
|
||||||
|
location.setLongitude(79.5);
|
||||||
|
location.setDeviceIdentifier(AndroidDeviceUtils.convertToDeviceIdentifierObject(getDeviceId()));
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DeviceInfo getDeviceInfo() {
|
||||||
|
DeviceInfo deviceInfo = new DeviceInfo();
|
||||||
|
deviceInfo.setDeviceModel("nexus");
|
||||||
|
deviceInfo.setAvailableRAMMemory(2.0);
|
||||||
|
deviceInfo.setBatteryLevel(100.0);
|
||||||
|
deviceInfo.setConnectionType("4G");
|
||||||
|
deviceInfo.setCpuUsage(1.0);
|
||||||
|
deviceInfo.setExternalAvailableMemory(2.3);
|
||||||
|
deviceInfo.setExternalTotalMemory(4.0);
|
||||||
|
deviceInfo.setInternalAvailableMemory(1.0);
|
||||||
|
deviceInfo.setInternalTotalMemory(4.0);
|
||||||
|
deviceInfo.setLocation(getDeviceLocation());
|
||||||
|
return deviceInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Application> getApplications() {
|
||||||
|
List<Application> applications = new ArrayList<>();
|
||||||
|
Application app = new Application();
|
||||||
|
app.setName("WSO2 IoT Agent");
|
||||||
|
app.setApplicationIdentifier("org.wos2.iot.agent");
|
||||||
|
app.setVersion("1.0.0");
|
||||||
|
app.setPlatform("Android");
|
||||||
|
applications.add(app);
|
||||||
|
return applications;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AndroidDevice getBasicAndroidDevice() {
|
||||||
|
AndroidDevice androidDevice = new AndroidDevice();
|
||||||
|
androidDevice.setName(getDevice().getName());
|
||||||
|
androidDevice.setDescription(getDevice().getDescription());
|
||||||
|
androidDevice.setDeviceIdentifier(getDeviceId());
|
||||||
|
androidDevice.setDeviceInfo(getDeviceInfo());
|
||||||
|
androidDevice.setApplications(getApplications());
|
||||||
|
androidDevice.setEnrolmentInfo(getDevice().getEnrolmentInfo());
|
||||||
|
return androidDevice;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
#
|
||||||
|
# Copyright (c) 2017, 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# This is the log4j configuration file used by WSO2 Carbon
|
||||||
|
#
|
||||||
|
# IMPORTANT : Please do not remove or change the names of any
|
||||||
|
# of the Appender defined here. The layout pattern & log file
|
||||||
|
# can be changed using the WSO2 Carbon Management Console, and those
|
||||||
|
# settings will override the settings in this file.
|
||||||
|
#
|
||||||
|
|
||||||
|
log4j.rootLogger=DEBUG, STD_OUT
|
||||||
|
|
||||||
|
# Redirect log messages to console
|
||||||
|
log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender
|
||||||
|
log4j.appender.STD_OUT.Target=System.out
|
||||||
|
log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||||
|
|
||||||
|
<suite name="AndroidDeviceManagementAPIs">
|
||||||
|
|
||||||
|
<test name="API Tests" preserve-order="true">
|
||||||
|
<classes>
|
||||||
|
<class name="org.wso2.carbon.mdm.services.android.DeviceManagementAdminServiceTests" />
|
||||||
|
<class name="org.wso2.carbon.mdm.services.android.DeviceManagementServiceTests" />
|
||||||
|
</classes>
|
||||||
|
</test>
|
||||||
|
</suite>
|
||||||
@ -147,6 +147,9 @@
|
|||||||
<fileset dir="${siddhi.extensions}/${target}/${coverge-report}">
|
<fileset dir="${siddhi.extensions}/${target}/${coverge-report}">
|
||||||
<include name="${individual.test.report.name}" />
|
<include name="${individual.test.report.name}" />
|
||||||
</fileset>
|
</fileset>
|
||||||
|
<fileset dir="${android.api}/${target}/${coverge-report}">
|
||||||
|
<include name="${individual.test.report.name}" />
|
||||||
|
</fileset>
|
||||||
|
|
||||||
<!-- Need to list the newly added exec files here -->
|
<!-- Need to list the newly added exec files here -->
|
||||||
</executiondata>
|
</executiondata>
|
||||||
|
|||||||
45
pom.xml
45
pom.xml
@ -271,6 +271,12 @@
|
|||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.policy.mgt.core</artifactId>
|
<artifactId>org.wso2.carbon.policy.mgt.core</artifactId>
|
||||||
<version>${carbon.devicemgt.version}</version>
|
<version>${carbon.devicemgt.version}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
@ -293,6 +299,12 @@
|
|||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.device.mgt.analytics.data.publisher</artifactId>
|
<artifactId>org.wso2.carbon.device.mgt.analytics.data.publisher</artifactId>
|
||||||
<version>${carbon.devicemgt.version}</version>
|
<version>${carbon.devicemgt.version}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>jboss</groupId>
|
||||||
|
<artifactId>javassist</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
@ -1114,6 +1126,36 @@
|
|||||||
<version>${junit.version}</version>
|
<version>${junit.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.powermock</groupId>
|
||||||
|
<artifactId>powermock-module-testng</artifactId>
|
||||||
|
<version>${powermock.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.powermock</groupId>
|
||||||
|
<artifactId>powermock-api-mockito</artifactId>
|
||||||
|
<version>${powermock.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.queuing</artifactId>
|
||||||
|
<version>${carbon.kernel.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-dbcp.wso2</groupId>
|
||||||
|
<artifactId>commons-dbcp</artifactId>
|
||||||
|
<version>${commons.dbcp.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javassist</groupId>
|
||||||
|
<artifactId>javassist</artifactId>
|
||||||
|
<version>${javassist.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
@ -1293,6 +1335,9 @@
|
|||||||
<jacoco.maven.plugin.version>0.7.8</jacoco.maven.plugin.version>
|
<jacoco.maven.plugin.version>0.7.8</jacoco.maven.plugin.version>
|
||||||
<jacoco.ant.verision>0.7.5.201505241946</jacoco.ant.verision>
|
<jacoco.ant.verision>0.7.5.201505241946</jacoco.ant.verision>
|
||||||
<ant.contrib.version>1.0b3</ant.contrib.version>
|
<ant.contrib.version>1.0b3</ant.contrib.version>
|
||||||
|
<commons.dbcp.version>1.4.0.wso2v1</commons.dbcp.version>
|
||||||
|
<javassist.version>3.12.1.GA</javassist.version>
|
||||||
|
<powermock.version>1.7.0</powermock.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user