The s method starts the analysis process, which detects whether a device is rooted or jailbroken. As of version 4.4 of the Root Detection SDK, this method also checks the version of the signature file. The signature file version must be higher than or equal to the version defined in the Root Detection SDK (indicated by the constant t). The aim is to prevent anyone from using signature files that may contain deprecated verification rules.

For Android platforms, another signature for this method exists: public static S s(String c), which does not use the Android context. However, the Android context is necessary to improve the root detection process. As a result, the deprecated method must only be used for backward-compatibility to manage earlier client integrations (Root Detection SDK 4.3 or earlier versions).

Syntax

Android

public static S s(String c, Context a)

iOS

+(s) s: (NSData*) c

Parameters

Start the analysis parameters lists the available signatures for this function:

Start the analysis parameters
Parameter name Data type Use Description
c String/NSData* I (mandatory) Signature file content.
a Context I (mandatory) Android context (Android only).

Return values

This method returns the S response object, which contains the following:

Android:

  • A return code that indicates the result of the analysis.
  • An exception if an unknown error occurs.

Exceptions

Start the analysis exceptions lists the possible error codes for this function.

Start the analysis exceptions
Name Value Error message
n 0 Indicates that the device is not rooted/jailbroken.
z –4600 Indicates an unknown error.
r –4601 Indicates that the device is rooted/jailbroken.
e –4602 Indicates that the signature file is null.
l –4603 Indicates that the signature file length is incorrect—it must be at least 256 characters.
f –4604 Indicates that the signature file format is incorrect—only hexadecimal characters are allowed.
i –4605 Indicates that the signature file is invalid: wrong signature or XML parsing error.
a –4606 Indicates that the version of the signature file is too old to be used by the Root Detection SDK.

Examples

This section illustrates how to integrate and use the s method to start the analysis. For more information, refer to the Root Detection SDK sample project in the OneSpan Mobile Security Suite package.

Android

  1. // Retrieve the signature file
  2. InputStream ins = assetManager.open(path);
  3.  
  4. // Start analysis process
  5. S response = P.s(convertInsToString(ins),
  6. this.getApplicationContext());
  7. int returnCode = response.r();
  8.  
  9. // Check the result from the analysis process
  10. if (returnCode == O.n)
  11. {
  12.   System.out.println("Device is not rooted.");
  13. }
  14. else if (returnCode == O.r)
  15. {
  16.   System.out.println("Device is rooted.");
  17. }
  18. else
  19. {
  20.   System.out.println(getMsgFromReturnCode(returnCode));
  21.   System.out.println("Error code: " + returnCode);
  22. }

iOS

  1. // Get file signature path
  2. NSString * filePath = [[NSBundlemainBundle] pathForResource:@"signature" ofType:nil];
  3.  
  4. // Load signature file
  5. NSData * d = [NSData dataWithContentsOfFile:filePath];
  6.  
  7. // Call s method: check if phone is rooted
  8. s response = [P s:d];
  9.  
  10. NSString * resultText = @"";
  11.  
  12. // Parse result
  13. switch(response.r){
  14.  
  15. case P_r:
  16.   resultText = @"** Device is rooted **";
  17. break;
  18. case P_n:
  19.   resultText = @"** Device is not rooted **";
  20. break;
  21.   ...
  22. ...