Boîtes de dialogue de correction

Cette page explique comment gérer les problèmes liés aux évaluations de l'intégrité.

Lorsqu'un jeton d'intégrité est demandé, vous avez la possibilité d'afficher une boîte de dialogue Google Play. Vous pouvez afficher la boîte de dialogue en cas de problème lié à l'évaluation de l'intégrité. La boîte de dialogue s'affiche en haut de votre application et invite les utilisateurs à résoudre la cause du problème. Une fois la boîte de dialogue fermée, vous pouvez vérifier que le problème est résolu en envoyant une autre requête à l'API Integrity.

Demander une boîte de dialogue d'intégrité

Lorsque le client demande un jeton d'intégrité, vous pouvez utiliser la méthode proposée dans StandardIntegrityToken (API standard) et IntegrityTokenResponse (API classique) : showDialog(Activity activity, int integrityDialogTypeCode).

Pour afficher une boîte de dialogue de correction à l'aide de l'API Play Integrity et du code de boîte de dialogue GET_LICENSED, procédez comme suit. D'autres codes de boîte de dialogue que votre application peut demander sont listés après cette section.

  1. Demandez un jeton d'intégrité à votre application et envoyez-le à votre serveur. Vous pouvez utiliser la requête standard ou classique.

    Kotlin

    // Request an integrity token
    val tokenResponse: StandardIntegrityToken = requestIntegrityToken()
    // Send token to app server and get response on what to do next
    val yourServerResponse: YourServerResponse = sendToServer(tokenResponse.token())  

    Java

    // Request an integrity token
    StandardIntegrityToken tokenResponse = requestIntegrityToken();
    // Send token to app server and get response on what to do next
    YourServerResponse yourServerResponse = sendToServer(tokenResponse.token());  

    Unity

    // Request an integrity token
    StandardIntegrityToken tokenResponse = RequestIntegrityToken();
    // Send token to app server and get response on what to do next
    YourServerResponse yourServerResponse = sendToServer(tokenResponse.Token); 

    Unreal Engine

    // Request an integrity token
    StandardIntegrityToken* Response = RequestIntegrityToken();
    // Send token to app server and get response on what to do next
    YourServerResponse YourServerResponse = SendToServer(Response->Token); 

    Natif

    /// Request an integrity token
    StandardIntegrityToken* response = requestIntegrityToken();
    /// Send token to app server and get response on what to do next
    YourServerResponse yourServerResponse = sendToServer(StandardIntegrityToken_getToken(response));
  2. Sur votre serveur, déchiffrez le jeton d'intégrité et vérifiez le champ appLicensingVerdict. Voici ce que vous pourriez voir s'afficher :

    // Licensing issue
    {
      ...
      "accountDetails": {
          "appLicensingVerdict": "UNLICENSED"
      }
    }
  3. Si le jeton contient appLicensingVerdict: "UNLICENSED", répondez au client de votre application en lui demandant d'afficher la boîte de dialogue d'attribution de licences :

    Kotlin

    private fun getDialogTypeCode(integrityToken: String): Int{
      // Get licensing verdict from decrypted and verified integritytoken
      val licensingVerdict: String = getLicensingVerdictFromDecryptedToken(integrityToken)
    
      return if (licensingVerdict == "UNLICENSED") {
              1 // GET_LICENSED
          } else 0
    }

    Java

    private int getDialogTypeCode(String integrityToken) {
      // Get licensing verdict from decrypted and verified integrityToken
      String licensingVerdict = getLicensingVerdictFromDecryptedToken(integrityToken);
    
      if (licensingVerdict.equals("UNLICENSED")) {
        return 1; // GET_LICENSED
      }
      return 0;
    }

    Unity

    private int GetDialogTypeCode(string IntegrityToken) {
      // Get licensing verdict from decrypted and verified integrityToken
      string licensingVerdict = GetLicensingVerdictFromDecryptedToken(IntegrityToken);
    
      if (licensingVerdict == "UNLICENSED") {
        return 1; // GET_LICENSED
      }
      return 0;
    } 

    Unreal Engine

    private int GetDialogTypeCode(FString IntegrityToken) {
      // Get licensing verdict from decrypted and verified integrityToken
      FString LicensingVerdict = GetLicensingVerdictFromDecryptedToken(IntegrityToken);
    
      if (LicensingVerdict == "UNLICENSED") {
        return 1; // GET_LICENSED
      }
      return 0;
    } 

    Natif

    private int getDialogTypeCode(string integrity_token) {
      /// Get licensing verdict from decrypted and verified integrityToken
      string licensing_verdict = getLicensingVerdictFromDecryptedToken(integrity_token);
    
      if (licensing_verdict == "UNLICENSED") {
        return 1; // GET_LICENSED
      }
      return 0;
    }
  4. Dans votre application, appelez showDialog avec le code demandé récupéré à partir de votre serveur :

    Kotlin

    // Show dialog as indicated by the server
    val showDialogType: Int? = yourServerResponse.integrityDialogTypeCode()
    if (showDialogType != null) {
      // Call showDialog with type code, the dialog will be shown on top of the
      // provided activity and complete when the dialog is closed.
      val integrityDialogResponseCode: Task<Int> =
      tokenResponse.showDialog(activity, showDialogType)
      // Handle response code, call the Integrity API again to confirm that
      // verdicts have been resolved.
    } 

    Java

    // Show dialog as indicated by the server
    @Nullable Integer showDialogType = yourServerResponse.integrityDialogTypeCode();
    if (showDialogType != null) {
      // Call showDialog with type code, the dialog will be shown on top of the
      // provided activity and complete when the dialog is closed.
      Task<Integer> integrityDialogResponseCode =
          tokenResponse.showDialog(activity, showDialogType);
      // Handle response code, call the Integrity API again to confirm that
      // verdicts have been resolved.
    }

    Unity

    IEnumerator ShowDialogCoroutine() {
      int showDialogType = yourServerResponse.IntegrityDialogTypeCode();
    
      // Call showDialog with type code, the dialog will be shown on top of the
      // provided activity and complete when the dialog is closed.
      var showDialogTask = tokenResponse.ShowDialog(showDialogType);
    
      // Wait for PlayAsyncOperation to complete.
      yield return showDialogTask;
    
      // Handle response code, call the Integrity API again to confirm that
      // verdicts have been resolved.
    } 

    Unreal Engine

    // .h
    void MyClass::OnShowDialogCompleted(
      EStandardIntegrityErrorCode Error,
      EIntegrityDialogResponseCode Response)
    {
      // Handle response code, call the Integrity API again to confirm that
      // verdicts have been resolved.
    }
    
    // .cpp
    void MyClass::RequestIntegrityToken()
    {
      UStandardIntegrityToken* Response = ...
      int TypeCode = YourServerResponse.integrityDialogTypeCode();
    
      // Create a delegate to bind the callback function.
      FShowDialogStandardOperationCompletedDelegate Delegate;
    
      // Bind the completion handler (OnShowDialogCompleted) to the delegate.
      Delegate.BindDynamic(this, &MyClass::OnShowDialogCompleted);
    
      // Call ShowDialog with TypeCode which completes when the dialog is closed.
      Response->ShowDialog(TypeCode, Delegate);
    }

    Natif

    // Show dialog as indicated by the server
    int show_dialog_type = yourServerResponse.integrityDialogTypeCode();
    if (show_dialog_type != 0) {
      /// Call showDialog with type code, the dialog will be shown on top of the
      /// provided activity and complete when the dialog is closed.
      StandardIntegrityErrorCode error_code =
          IntegrityTokenResponse_showDialog(response, activity, show_dialog_type);
    
      /// Proceed to polling iff error_code == STANDARD_INTEGRITY_NO_ERROR
      if (error_code != STANDARD_INTEGRITY_NO_ERROR)
      {
          /// Remember to call the *_destroy() functions.
          return;
      }
    
      /// Use polling to wait for the async operation to complete.
      /// Note, the polling shouldn't block the thread where the IntegrityManager
      /// is running.
    
      IntegrityDialogResponseCode* response_code;
      error_code = StandardIntegrityToken_getDialogResponseCode(response, response_code);
    
      if (error_code != STANDARD_INTEGRITY_NO_ERROR)
      {
          /// Remember to call the *_destroy() functions.
          return;
      }
    
      /// Handle response code, call the Integrity API again to confirm that
      /// verdicts have been resolved.
    }
  5. La boîte de dialogue s'affiche au-dessus de l'activité fournie. Lorsque l'utilisateur a fermé la boîte de dialogue, la tâche se termine avec un code de réponse.

  6. (Facultatif) Demandez un autre jeton pour afficher d'autres boîtes de dialogue. Si vous effectuez des requêtes standards, vous devez rafraîchir le fournisseur de jetons pour obtenir une nouvelle évaluation.

Codes des boîtes de dialogue sur l'intégrité

GET_LICENSED (code de type 1)

Problème d'évaluation

Cette boîte de dialogue convient pour deux problèmes :

  • Accès non autorisé : appLicensingVerdict: "UNLICENSED". Cela signifie que le compte utilisateur ne dispose pas d'un droit d'accès à votre application, ce qui peut se produire si l'utilisateur l'a téléchargée indépendamment ou l'a acquise sur une autre plate-forme de téléchargement que Google Play.
  • Application falsifiée : appRecognitionVerdict: "UNRECOGNIZED_VERSION". Cela signifie que le binaire de votre application a été modifié ou qu'il ne s'agit pas d'une version reconnue par Google Play.

Correction

Vous pouvez afficher la boîte de dialogue GET_LICENSED pour inviter l'utilisateur à télécharger l'application authentique depuis Google Play. Cette boîte de dialogue unique s'applique aux deux scénarios :

  • Pour un utilisateur sans licence, elle lui accorde une licence Play. Cela permet à l'utilisateur de recevoir les mises à jour de l'application depuis Google Play.
  • Pour un utilisateur disposant d'une version frelatée de l'application, il l'invite à installer la version non modifiée depuis Google Play.

Lorsque l'utilisateur termine la boîte de dialogue, les vérifications de l'intégrité suivantes renvoient appLicensingVerdict: "LICENSED" et appRecognitionVerdict: "PLAY_RECOGNIZED".

Exemple d'expérience utilisateur

Figure 1 : Boîte de dialogue Google Play GET_LICENSED.

CLOSE_UNKNOWN_ACCESS_RISK (code de type 2)

Problème d'évaluation

Lorsque environmentDetails.appAccessRiskVerdict.appsDetected contient "UNKNOWN_CAPTURING" ou "UNKNOWN_CONTROLLING", cela signifie que des applications inconnues sont en cours d'exécution sur l'appareil et qu'elles pourraient capturer l'écran ou contrôler l'appareil.

Correction

Vous pouvez afficher la boîte de dialogue CLOSE_UNKNOWN_ACCESS_RISK pour inviter l'utilisateur à fermer toutes les applications inconnues susceptibles de capturer l'écran ou de contrôler l'appareil. Si l'utilisateur appuie sur le bouton Close all, toutes ces applications sont fermées.

Exemple d'expérience utilisateur

Figure 2 : Boîte de dialogue permettant de fermer le risque d'accès inconnu.

CLOSE_ALL_ACCESS_RISK (code de type 3)

Problème d'évaluation

Lorsque environmentDetails.appAccessRiskVerdict.appsDetected contient l'un des éléments suivants : "KNOWN_CAPTURING", "KNOWN_CONTROLLING","UNKNOWN_CAPTURING" ou "UNKNOWN_CONTROLLING", cela signifie que des applications s'exécutent sur l'appareil et peuvent capturer l'écran ou contrôler l'appareil.

Correction

Vous pouvez afficher la boîte de dialogue CLOSE_ALL_ACCESS_RISK pour inviter l'utilisateur à fermer toutes les applications susceptibles de capturer l'écran ou de contrôler l'appareil. Si l'utilisateur appuie sur le bouton Close all, toutes ces applications sont fermées sur l'appareil.

Exemple d'expérience utilisateur

Figure 3 : Boîte de dialogue pour fermer tous les risques d'accès.