@ -167,14 +167,14 @@ public class AndroidDeviceUtils {
if ( ! Operation . Status . ERROR . equals ( operation . getStatus ( ) ) & &
if ( ! Operation . Status . ERROR . equals ( operation . getStatus ( ) ) & &
AndroidConstants . OperationCodes . MONITOR . equals ( operation . getCode ( ) ) ) {
AndroidConstants . OperationCodes . MONITOR . equals ( operation . getCode ( ) ) ) {
if ( log . isDebugEnabled ( ) ) {
if ( log . isDebugEnabled ( ) ) {
log . info ( "Received compliance status from MONITOR operation ID: " + operation . getId ( ) ) ;
log . debug ( "Received compliance status from MONITOR operation ID: " + operation . getId ( ) ) ;
}
}
AndroidAPIUtils . getPolicyManagerService ( ) . checkPolicyCompliance ( deviceIdentifier ,
AndroidAPIUtils . getPolicyManagerService ( ) . checkPolicyCompliance ( deviceIdentifier ,
getComplianceFeatures ( operation . getPayLoad ( ) ) ) ;
getComplianceFeatures ( operation . getPayLoad ( ) ) ) ;
} else if ( ! Operation . Status . ERROR . equals ( operation . getStatus ( ) ) & & AndroidConstants .
} else if ( ! Operation . Status . ERROR . equals ( operation . getStatus ( ) ) & & AndroidConstants .
OperationCodes . APPLICATION_LIST . equals ( operation . getCode ( ) ) ) {
OperationCodes . APPLICATION_LIST . equals ( operation . getCode ( ) ) ) {
if ( log . isDebugEnabled ( ) ) {
if ( log . isDebugEnabled ( ) ) {
log . info ( "Received applications list from device '" + deviceId + "'" ) ;
log . debug ( "Received applications list from device '" + deviceId + "'" ) ;
}
}
updateApplicationList ( operation , deviceIdentifier ) ;
updateApplicationList ( operation , deviceIdentifier ) ;
@ -192,7 +192,6 @@ public class AndroidDeviceUtils {
throw new OperationManagementException ( "Error occurred while updating the device information." , e ) ;
throw new OperationManagementException ( "Error occurred while updating the device information." , e ) ;
}
}
} else if ( ! Operation . Status . ERROR . equals ( operation . getStatus ( ) ) & &
} else if ( ! Operation . Status . ERROR . equals ( operation . getStatus ( ) ) & &
AndroidConstants . OperationCodes . DEVICE_LOCATION . equals ( operation . getCode ( ) ) ) {
AndroidConstants . OperationCodes . DEVICE_LOCATION . equals ( operation . getCode ( ) ) ) {
try {
try {
@ -247,7 +246,9 @@ public class AndroidDeviceUtils {
}
}
AndroidAPIUtils . getApplicationManagerService ( ) . updateApplicationListInstalledInDevice ( deviceIdentifier , applications ) ;
AndroidAPIUtils . getApplicationManagerService ( ) . updateApplicationListInstalledInDevice ( deviceIdentifier , applications ) ;
} else {
} else {
log . error ( "Operation Response is null." ) ;
if ( log . isDebugEnabled ( ) ) {
log . debug ( "Operation Response is null." ) ;
}
}
}
}
}
@ -277,48 +278,31 @@ public class AndroidDeviceUtils {
for ( Device . Property prop : props ) {
for ( Device . Property prop : props ) {
if ( Utils . getDeviceDetailsColumnNames ( ) . containsValue ( prop . getName ( ) ) ) {
if ( Utils . getDeviceDetailsColumnNames ( ) . containsValue ( prop . getName ( ) ) ) {
if ( prop . getName ( ) . equalsIgnoreCase ( "DEVICE_MODEL" ) ) {
extractDefinedProperties ( deviceInfo , prop ) ;
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 {
} else {
extractMapProperties ( deviceInfo , prop ) ;
}
}
return deviceInfo ;
}
private static void extractMapProperties ( DeviceInfo deviceInfo , Device . Property prop ) {
if ( prop . getName ( ) . equalsIgnoreCase ( "CPU_INFO" ) ) {
if ( prop . getName ( ) . equalsIgnoreCase ( "CPU_INFO" ) ) {
deviceInfo . getDeviceDetailsMap ( ) . put ( "cpuUser" ,
deviceInfo . getDeviceDetailsMap ( ) . put ( "cpuUser" , getProperty ( prop . getValue ( ) , "User" ) ) ;
getProperty ( prop . getValue ( ) , "User" ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "cpuSystem" , getProperty ( prop . getValue ( ) , "System" ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "cpuSystem" ,
deviceInfo . getDeviceDetailsMap ( ) . put ( "IOW" , getProperty ( prop . getValue ( ) , "IOW" ) ) ;
getProperty ( prop . getValue ( ) , "System" ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "IRQ" , getProperty ( prop . getValue ( ) , "IRQ" ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "IOW" ,
getProperty ( prop . getValue ( ) , "IOW" ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "IRQ" ,
getProperty ( prop . getValue ( ) , "IRQ" ) ) ;
} else if ( prop . getName ( ) . equalsIgnoreCase ( "RAM_INFO" ) ) {
} else if ( prop . getName ( ) . equalsIgnoreCase ( "RAM_INFO" ) ) {
deviceInfo . setTotalRAMMemory ( Double . parseDouble ( getProperty ( prop . getValue ( ) , "TOTAL_MEMORY" ) ) ) ;
deviceInfo . setTotalRAMMemory ( Double . parseDouble ( getProperty ( prop . getValue ( ) , "TOTAL_MEMORY" ) ) ) ;
deviceInfo . setAvailableRAMMemory ( Double . parseDouble ( getProperty ( prop . getValue ( ) , "AVAILABLE_MEMORY" ) ) ) ;
deviceInfo . setAvailableRAMMemory ( Double . parseDouble (
getProperty ( prop . getValue ( ) , "AVAILABLE_MEMORY" ) ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "ramThreshold" ,
deviceInfo . getDeviceDetailsMap ( ) . put ( "ramThreshold" , getProperty ( prop . getValue ( ) , "THRESHOLD" ) ) ;
getProperty ( prop . getValue ( ) , "THRESHOLD" ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "ramLowMemory" , getProperty ( prop . getValue ( ) , "LOW_MEMORY" ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "ramLowMemory" ,
getProperty ( prop . getValue ( ) , "LOW_MEMORY" ) ) ;
} else if ( prop . getName ( ) . equalsIgnoreCase ( "BATTERY_INFO" ) ) {
} else if ( prop . getName ( ) . equalsIgnoreCase ( "BATTERY_INFO" ) ) {
deviceInfo . setPluggedIn ( Boolean . parseBoolean ( getProperty ( prop . getValue ( ) , "PLUGGED" ) ) ) ;
deviceInfo . setPluggedIn ( Boolean . parseBoolean ( getProperty ( prop . getValue ( ) , "PLUGGED" ) ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "batteryLevel" ,
deviceInfo . getDeviceDetailsMap ( ) . put ( "batteryLevel" , getProperty ( prop . getValue ( ) , "BATTERY_LEVEL" ) ) ;
getProperty ( prop . getValue ( ) , "BATTERY_LEVEL" ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "batteryScale" , getProperty ( prop . getValue ( ) , "SCALE" ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "batteryScale" ,
getProperty ( prop . getValue ( ) , "SCALE" ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "batteryVoltage" ,
deviceInfo . getDeviceDetailsMap ( ) . put ( "batteryVoltage" ,
getProperty ( prop . getValue ( ) , "BATTERY_VOLTAGE" ) ) ;
getProperty ( prop . getValue ( ) , "BATTERY_VOLTAGE" ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "batteryTemperature" ,
deviceInfo . getDeviceDetailsMap ( ) . put ( "batteryTemperature" ,
@ -327,10 +311,8 @@ public class AndroidDeviceUtils {
getProperty ( prop . getValue ( ) , "CURRENT_AVERAGE" ) ) ;
getProperty ( prop . getValue ( ) , "CURRENT_AVERAGE" ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "batteryTechnology" ,
deviceInfo . getDeviceDetailsMap ( ) . put ( "batteryTechnology" ,
getProperty ( prop . getValue ( ) , "TECHNOLOGY" ) ) ;
getProperty ( prop . getValue ( ) , "TECHNOLOGY" ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "batteryHealth" ,
deviceInfo . getDeviceDetailsMap ( ) . put ( "batteryHealth" , getProperty ( prop . getValue ( ) , "HEALTH" ) ) ;
getProperty ( prop . getValue ( ) , "HEALTH" ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "batteryStatus" , getProperty ( prop . getValue ( ) , "STATUS" ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "batteryStatus" ,
getProperty ( prop . getValue ( ) , "STATUS" ) ) ;
} else if ( prop . getName ( ) . equalsIgnoreCase ( "NETWORK_INFO" ) ) {
} else if ( prop . getName ( ) . equalsIgnoreCase ( "NETWORK_INFO" ) ) {
deviceInfo . setSsid ( getProperty ( prop . getValue ( ) , "WIFI_SSID" ) ) ;
deviceInfo . setSsid ( getProperty ( prop . getValue ( ) , "WIFI_SSID" ) ) ;
deviceInfo . setConnectionType ( getProperty ( prop . getValue ( ) , "CONNECTION_TYPE" ) ) ;
deviceInfo . setConnectionType ( getProperty ( prop . getValue ( ) , "CONNECTION_TYPE" ) ) ;
@ -359,26 +341,46 @@ public class AndroidDeviceUtils {
getProperty ( prop . getValue ( ) , "OPERATOR" ) ) ;
getProperty ( prop . getValue ( ) , "OPERATOR" ) ) ;
deviceInfo . getDeviceDetailsMap ( ) . put ( "PhoneNumber" ,
deviceInfo . getDeviceDetailsMap ( ) . put ( "PhoneNumber" ,
getProperty ( prop . getValue ( ) , "PHONE_NUMBER" ) ) ;
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 ( ) ) ;
}
}
return deviceInfo ;
}
}
private static String getProperty ( String a , String needed ) {
private static String getProperty ( String properties , String needed ) {
// This is not a key value pair. value is the immediate element to its filed name.
JsonElement jsonElement = new JsonParser ( ) . parse ( a ) ;
// 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 ( ) ;
JsonArray jsonArray = jsonElement . getAsJsonArray ( ) ;
boolean exist = false ;
boolean exist = false ;
for ( JsonElement element : jsonArray ) {
for ( JsonElement element : jsonArray ) {
for ( Map . Entry < String , JsonElement > ob : ( ( JsonObject ) element ) . entrySe t( ) ) {
if ( element . isJsonObjec t( ) ) {
Json Element val = ob . getValue ( ) ;
Json Object jsonObject = element . getAsJsonObject ( ) ;
if ( val ! = null & & ! val . isJsonNull ( ) ) {
if ( jsonObject. has ( "name" )
if ( exist ) {
& & jsonObject . get ( "name" ) . getAsString ( ) . equalsIgnoreCase ( needed ) ) {
return val . getAsString ( ) . replace ( "%" , "" ) ;
if ( jsonObject . has ( "value" ) ) {
}
return jsonObject . get ( "value" ) . getAsString ( ) . replace ( "%" , "" ) ;
if ( val . getAsString ( ) . equalsIgnoreCase ( needed ) ) {
} else {
exist = true ;
return "" ;
}
}
}
}
}
}
@ -386,7 +388,8 @@ public class AndroidDeviceUtils {
return "" ;
return "" ;
}
}
private static List < ComplianceFeature > getComplianceFeatures ( Object compliancePayload ) throws PolicyComplianceException {
private static List < ComplianceFeature > getComplianceFeatures ( Object compliancePayload )
throws PolicyComplianceException {
String compliancePayloadString = new Gson ( ) . toJson ( compliancePayload ) ;
String compliancePayloadString = new Gson ( ) . toJson ( compliancePayload ) ;
if ( compliancePayload = = null ) {
if ( compliancePayload = = null ) {
return null ;
return null ;