Google Play Integrity

Technical reference for Google Play Integrity API integration with internal applications for app verification and fraud protection.

๐Ÿ” Overview

What is Google Play Integrity and why it matters for internal applications

Google Play Integrity API helps you check that the interactions with your app are coming from your unmodified and official binary. This protects both you and your users from:

  • Piracy & Clones: Unauthorized copies of your app
  • Tampering: Modified versions of your app with malicious code
  • Device Attacks: Emulators, rooted devices, and other compromised environments
  • API Abuse: Automated scripts and bots abusing your backend

Supported Applications

  • Sarathi - com.rptpl.roadpilot
  • Fleet - com.rptpl.owner
  • Dhaba - com.rptpl.roadpilotdhaba
  • Mech - com.rptpl.roadpilotmech

โš™๏ธ How It Works

The verification flow from app to server

// Step 1: App requests integrity token from Play Integrity API
App sends: app_id + hashing
โ†“
// Step 2: Play Integrity returns signed token
Token contains: app_recognition_verdict + device_integrity + account_details
โ†“
// Step 3: App sends token to your server
Request includes: metadata + integrity_token
โ†“
// Step 4: Server verifies token with Google
Server decrypts and validates token signature
โ†“
// Step 5: Server processes request if valid
Response: { success: true, data: {...} }

โœ“ App Recognition

Validates the app is from Google Play and matches your package name

โœ“ Device Integrity

Checks device hasn't been tampered with or rooted

โœ“ Account Details

Verifies the user's Google Account is linked correctly

๐Ÿš€ Integration Setup

Step-by-step guide to integrate Play Integrity into your apps

Step 1: Google Cloud Setup

  1. Go to Google Cloud Console
  2. Create a new project (e.g., "sarathi-production") for each app
  3. Enable the Play Integrity API
  4. Create a service account with "Play Integrity API Verifier" role
  5. Download the JSON key file
  6. Upload to server: storage/google-credentials/sarathi-production.json

Step 2: Android Integration

// build.gradle (app level) dependencies { implementation 'com.google.android.play:integrity:1.1.0' } // Kotlin code val integrityManager = IntegrityManagerFactory.create(applicationContext) val tokenTask = integrityManager.requestIntegrityToken(IntegrityTokenRequest.builder() .build())

Step 3: Send Token to Your API

tokenTask.addOnSuccessListener { token -> // Make API request with the token val metadata = JSONObject() .put("app_name", "sarathi") .put("integrity_token", token.token()) // Call your API endpoint }

Step 4: Server Configuration

Update .env.production with your project IDs:

SARATHI_PROD_PROJECT_ID=your-project-id-here FLEET_PROD_PROJECT_ID=your-project-id-here DHABA_PROD_PROJECT_ID=your-project-id-here MECH_PROD_PROJECT_ID=your-project-id-here GOOGLE_PLAY_INTEGRITY_ENABLED=true

โš ๏ธ Response Verdicts

Understanding the verdict values and what they mean

๐Ÿ“ฑ App Recognition Verdicts

PLAY_RECOGNIZED โœ“ Downloaded/installed from Google Play
UNRECOGNIZED_VERSION โš ๏ธ Legitimate but unrecognized version
UNEVALUATED โš ๏ธ Not enough data to evaluate
FAKE โœ— Unauthorized or modified app

๐Ÿ”ง Device Integrity Verdicts

MEETS_STRONG_INTEGRITY โœ“ Certified Android device with Google Play Services
MEETS_BASIC_INTEGRITY โœ“ Legitimate device (may be rooted/emulator)
UNEVALUATED โœ— Device integrity cannot be verified

โ„น๏ธ Note: Our system accepts both MEETS_STRONG_INTEGRITY and MEETS_BASIC_INTEGRITY for legitimate use cases, while blocking UNEVALUATED and FAKE verdicts in production.

๐ŸŒ Environment Settings

How Play Integrity is configured across environments

Production

  • โ€ข Integrity: REQUIRED
  • โ€ข Strict enforcement
  • โ€ข Blocks all fake apps
  • โ€ข Logs all failures

Staging

  • โ€ข Integrity: OPTIONAL
  • โ€ข Logs warnings only
  • โ€ข Allows testing
  • โ€ข Development friendly

Local

  • โ€ข Integrity: DISABLED
  • โ€ข No checks
  • โ€ข Full access
  • โ€ข Development mode

๐Ÿ”ง Error Handling

Common errors and how to handle them

โŒ Token Not Provided

Error: "Google Play Integrity token is required"

Solution: Ensure your Android app is properly requesting and sending the integrity token.

โŒ Token Expired

Error: "Failed integrity verification - token too old"

Solution: Tokens expire after 5 minutes. Request a fresh token for each API call.

โŒ Invalid Token

Error: "Invalid or expired integrity token"

Solution: Token signature validation failed. Ensure token hasn't been tampered with.

โš ๏ธ Configuration Error

Error: "Google Play Integrity service not configured"

Solution: Check that service account files exist in storage/google-credentials/ for the app.

๐Ÿงช Testing

How to test Play Integrity integration

Testing in Staging

In staging environment, integrity checks are optional. You can test your integration without valid tokens to ensure other functionality works.

Test License Testing

Google Play Console allows you to add test accounts that bypass normal integrity checks for development purposes.

Production Testing

For production testing, use real devices and Google Play-signed APKs. ADB installs may fail integrity checks.

๐Ÿ› ๏ธ Troubleshooting

Common issues and solutions

โ“ Why are legitimate users being blocked?

Check if users are using sideloaded APKs, modified versions, or testing on emulators. Legitimate Play Store installs should pass.

โ“ How do I debug which specific check failed?

Check server logs for detailed verdict information. Each failed token includes the reason (app_recognition_verdict, device_integrity_verdict).

โ“ Can I allow specific rooted devices?

For production security, we block UNEVALUATED verdicts. If you need to allow rooted devices for testing, use the staging environment.

โ“ What happens if Google Play Integrity API is down?

Our system treats API failures as verification failures. In staging, requests will still be allowed with a logged warning.