תיבות דו-שיח של תיקונים

בדף הזה מוסבר איך לטפל בבעיות שקשורות לתוצאות של בדיקות יושרה.

כשמבקשים אסימון יושרה, יש לכם אפשרות להציג למשתמש תיבת דו-שיח של Google Play. אפשר להציג את תיבת הדו-שיח אם יש בעיה אחת או יותר בתוצאת הבדיקה של תקינות המכשיר. תיבת הדו-שיח מוצגת מעל האפליקציה, ומבקשת מהמשתמשים לפתור את הגורם לבעיה. אחרי שסוגרים את תיבת הדו-שיח, אפשר לשלוח בקשה נוספת ל-Integrity API כדי לוודא שהבעיה נפתרה.

בקשה להצגת תיבת דו-שיח של מהימנות

כשהלקוח מבקש אסימון תקינות, אפשר להשתמש בשיטה שמוצעת ב-StandardIntegrityToken (Standard API) וב-IntegrityTokenResponse (Classic API): showDialog(Activity activity, int integrityDialogTypeCode).

בשלבים הבאים מוסבר איך להשתמש ב-Play Integrity API כדי להציג תיבת דו-שיח לתיקון באמצעות קוד תיבת הדו-שיח GET_LICENSED. אחרי הקטע הזה מפורטים קודי דו-שיח אחרים שהאפליקציה יכולה לבקש.

  1. מבקשים טוקן יושרה מהאפליקציה ושולחים את הטוקן לשרת. אפשר להשתמש בבקשה הרגילה או בבקשה הקלאסית.

    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); 

    מותאמת

    /// 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. בשרת, מפענחים את אסימון השלמות ובודקים את השדה appLicensingVerdict. הוא יכול להיראות בערך כך:

    // Licensing issue
    {
      ...
      accountDetails: {
          appLicensingVerdict: "UNLICENSED"
      }
    }
  3. אם האסימון מכיל את הערך appLicensingVerdict: "UNLICENSED", צריך להשיב ללקוח של האפליקציה ולבקש ממנו להציג את תיבת הדו-שיח של הרישיון:

    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;
    } 

    מותאמת

    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. באפליקציה, מפעילים את showDialog עם הקוד המבוקש שאוחזר מהשרת:

    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);
    }

    מותאמת

    // 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. תיבת הדו-שיח מוצגת מעל הפעילות שצוינה. כשהמשתמש סוגר את תיבת הדו-שיח, המשימה מסתיימת עם קוד תגובה.

  6. (אופציונלי) מבקשים עוד אסימון כדי להציג עוד תיבות דו-שיח. אם אתם שולחים בקשות רגילות, אתם צריכים להפעיל מחדש את ספק הטוקנים כדי לקבל פסיקה חדשה.

קודים בתיבת הדו-שיח של תקינות

GET_LICENSED (קוד סוג 1)

בעיה בתוצאה

תיבת הדו-שיח הזו מתאימה לשתי בעיות:

  • גישה לא מורשית: appLicensingVerdict: "UNLICENSED". המשמעות היא שלמשתמש אין הרשאה לאפליקציה, וזה יכול לקרות אם המשתמש העביר אותה למכשיר שלו ממקור אחר או רכש אותה מחנות אפליקציות אחרת ולא מ-Google Play.
  • אפליקציה שבוצעה בה התערבות: appRecognitionVerdict: "UNRECOGNIZED_VERSION". המשמעות היא שהקובץ הבינארי של האפליקציה שלך עבר שינוי או שהוא לא גרסה שמזוהה על ידי Google Play.

תיקון

אפשר להציג את תיבת הדו-שיח GET_LICENSED כדי להציע למשתמש להוריד את האפליקציה המקורית מ-Google Play. תיבת הדו-שיח הזו מתייחסת לשני התרחישים:

  • למשתמש ללא רישיון, הוא מעניק רישיון ל-Play. כך המשתמש יוכל לקבל עדכונים לאפליקציות מ-Google Play.
  • למשתמש עם גרסה שעברה שינוי לא מורשה של האפליקציה, המערכת מציגה הנחיה להתקין את הגרסה המקורית של האפליקציה מ-Google Play.

כשהמשתמש משלים את תיבת הדו-שיח, בדיקות השלמות הבאות מחזירות את הערכים appLicensingVerdict: "LICENSED" ו-appRecognitionVerdict: "PLAY_RECOGNIZED".

דוגמה לחוויית משתמש

איור 1. תיבת הדו-שיח GET_LICENSED ב-Play.

CLOSE_UNKNOWN_ACCESS_RISK (קוד סוג 2)

בעיה בתוצאה

אם הערך של environmentDetails.appAccessRiskVerdict.appsDetected הוא "UNKNOWN_CAPTURING" או "UNKNOWN_CONTROLLING", המשמעות היא שיש אפליקציות לא מוכרות שפועלות במכשיר ויכולות לצלם את המסך או לשלוט במכשיר.

תיקון

אתם יכולים להציג את תיבת הדו-שיח CLOSE_UNKNOWN_ACCESS_RISK כדי להציג למשתמש הנחיה לסגור את כל האפליקציות הלא מוכרות שעשויות לצלם את המסך או לשלוט במכשיר. אם המשתמש מקיש על הלחצן Close all, כל האפליקציות האלה נסגרות.

דוגמה לחוויית משתמש

איור 2. תיבת דו-שיח לסגירת סיכון גישה לא ידוע.

CLOSE_ALL_ACCESS_RISK (קוד סוג 3)

בעיה בתוצאה

אם environmentDetails.appAccessRiskVerdict.appsDetected מכיל את אחד מהערכים הבאים: "KNOWN_CAPTURING", "KNOWN_CONTROLLING","UNKNOWN_CAPTURING" או "UNKNOWN_CONTROLLING", המשמעות היא שיש אפליקציות שפועלות במכשיר ויכולות לצלם את המסך או לשלוט במכשיר.

תיקון

אתם יכולים להציג את תיבת הדו-שיח CLOSE_ALL_ACCESS_RISK כדי להציג למשתמש הנחיה לסגור את כל האפליקציות שיכולות לצלם את המסך או לשלוט במכשיר. אם המשתמש מקיש על הלחצן Close all, כל האפליקציות האלה נסגרות במכשיר.

דוגמה לחוויית משתמש

איור 3. תיבת דו-שיח לסגירת כל הסיכונים לגישה.