Google Play Integrity API: UNEVALUATED After Mobile Restart

Understanding the Google Play Integrity API: UNEVALUATED Status

The Google Play Integrity API helps developers verify the integrity of their apps on Android devices. It checks if the app is running on a legitimate device, and whether it has been tampered with. One common issue encountered is the “UNEVALUATED” result after a mobile restart.

What is “UNEVALUATED”?

The “UNEVALUATED” status indicates that the Integrity API cannot provide a definitive result about the app’s integrity. This can happen due to various factors, including:

  • Network Issues: Connectivity problems during the API call can hinder evaluation.
  • Device State: Fresh restarts or specific device configurations might trigger this status.
  • API Limitations: There may be limitations in the API’s capabilities for certain devices or scenarios.

Possible Causes for UNEVALUATED After Restart

After a mobile restart, the Integrity API might return “UNEVALUATED” for several reasons:

  • Initial Device Setup: Newly booted devices require some time to initialize and connect to Google services.
  • Background Processes: The API may not be able to function optimally while other demanding processes are running in the background.
  • System Updates: Software updates or changes in the operating system might temporarily affect the API’s behavior.

Troubleshooting UNEVALUATED Status

1. Network Connectivity Check

Ensure your app has a stable and reliable network connection before making the Integrity API call. You can use the following code to test your app’s connectivity:


import android.net.ConnectivityManager;
import android.net.NetworkInfo;

// ... 

public void checkConnectivity() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    
    if (isConnected) {
        // Proceed with API call
    } else {
        // Handle connectivity issue
    }
}

2. Delay API Call

After a restart, it might be beneficial to delay the Integrity API call to allow the device to settle and establish a connection. You can use a timer or a delayed task for this purpose.


import android.os.Handler;

// ...

Handler handler = new Handler();
Runnable delayTask = new Runnable() {
    public void run() {
        // Make the Integrity API call
    }
};
handler.postDelayed(delayTask, 5000); // Delay by 5 seconds

3. Retry Mechanism

Implement a retry mechanism to handle cases where the initial API call fails with “UNEVALUATED”. You can retry the call a specific number of times with increasing delays.


int retryCount = 0;
int maxRetries = 3;
long delay = 1000; // Initial delay of 1 second

while (retryCount < maxRetries) {
    // Make Integrity API call

    if (result == "UNEVALUATED") {
        // Increment retry count
        retryCount++;

        // Increase delay exponentially
        delay *= 2;

        // Wait for delay before retrying
        try {
            Thread.sleep(delay);
        } catch (InterruptedException e) {
            // Handle exception
        }
    } else {
        // Handle successful result
        break;
    }
}

if (retryCount == maxRetries) {
    // Handle maximum retries exceeded
}

Comparison Table

Scenario UNEVALUATED Cause Solution
Device Restart Initial device setup Delay API call, retry mechanism
Poor Network Connectivity issues Network connectivity check, retry mechanism
Heavy Background Tasks System resource constraints Delay API call, reduce background processes

Conclusion

The "UNEVALUATED" status in the Google Play Integrity API after a mobile restart can be a common occurrence, often related to network issues or device initialization. By implementing strategies like delayed API calls, retry mechanisms, and network connectivity checks, you can effectively handle this scenario and ensure the integrity verification process is successful.


Leave a Reply

Your email address will not be published. Required fields are marked *