กล่องโต้ตอบการแก้ไข

หน้านี้จะอธิบายวิธีจัดการปัญหาเกี่ยวกับผลการตัดสินด้านความสมบูรณ์

เมื่อมีการขอโทเค็นความสมบูรณ์ คุณจะมีตัวเลือกในการแสดงกล่องโต้ตอบ Google Play ต่อผู้ใช้ คุณอาจแสดงกล่องโต้ตอบเมื่อมีปัญหาอย่างน้อย 1 รายการเกี่ยวกับผลการตัดสินความสมบูรณ์ กล่องโต้ตอบจะแสดงที่ด้านบนของแอป และแจ้งให้ผู้ใช้แก้ไขสาเหตุของปัญหา เมื่อปิดกล่องโต้ตอบแล้ว คุณจะยืนยันได้ว่าปัญหาได้รับการแก้ไขแล้วด้วยคำขออื่นไปยัง 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)

ปัญหาเกี่ยวกับคำตัดสิน

กล่องโต้ตอบนี้เหมาะสำหรับปัญหา 2 อย่างต่อไปนี้

  • การเข้าถึงที่ไม่ได้รับอนุญาต: appLicensingVerdict: "UNLICENSED" ซึ่งหมายความว่าบัญชีผู้ใช้ไม่มีสิทธิ์เข้าถึงแอปของคุณ ซึ่งอาจเกิดขึ้นได้หากผู้ใช้โหลดแอปจากแหล่งที่ไม่รู้จักหรือได้แอปจาก App Store อื่นที่ไม่ใช่ Google Play
  • แอปที่ถูกดัดแปลง: appRecognitionVerdict: "UNRECOGNIZED_VERSION" ซึ่งหมายความว่าไบนารีของแอปมีการแก้ไขหรือไม่ใช่เวอร์ชันที่ Google Play รู้จัก

การแก้ไข

คุณสามารถแสดงGET_LICENSEDกล่องโต้ตอบเพื่อแจ้งให้ผู้ใช้ดาวน์โหลด แอปของแท้จาก Google Play กล่องโต้ตอบนี้จะใช้ได้กับทั้ง 2 กรณี

  • สำหรับผู้ใช้ที่ไม่มีใบอนุญาต ระบบจะให้ใบอนุญาต Play แก่ผู้ใช้ ซึ่งจะช่วยให้ ผู้ใช้ได้รับการอัปเดตแอปจาก Google Play
  • สำหรับผู้ใช้ที่ใช้แอปเวอร์ชันที่ดัดแปลง ระบบจะแนะนำให้ติดตั้ง แอปที่ไม่มีการแก้ไขจาก Google Play

เมื่อผู้ใช้ดำเนินการในกล่องโต้ตอบเสร็จแล้ว การตรวจสอบความสมบูรณ์ครั้งต่อๆ ไปจะแสดงผลเป็น appLicensingVerdict: "LICENSED" และ appRecognitionVerdict: "PLAY_RECOGNIZED"

ตัวอย่าง UX

รูปที่ 1 กล่องโต้ตอบ GET_LICENSED ของ Play

CLOSE_UNKNOWN_ACCESS_RISK (รหัสประเภท 2)

ปัญหาเกี่ยวกับคำตัดสิน

เมื่อ environmentDetails.appAccessRiskVerdict.appsDetected มีค่าเป็น "UNKNOWN_CAPTURING" หรือ "UNKNOWN_CONTROLLING" แสดงว่ามีแอปที่ไม่รู้จัก ทำงานอยู่ในอุปกรณ์ซึ่งอาจจับภาพหน้าจอหรือควบคุม อุปกรณ์ได้

การแก้ไข

คุณสามารถแสดงกล่องโต้ตอบ CLOSE_UNKNOWN_ACCESS_RISK เพื่อแจ้งให้ผู้ใช้ปิด แอปที่ไม่รู้จักทั้งหมดซึ่งอาจบันทึกหน้าจอหรือควบคุมอุปกรณ์ได้ หากผู้ใช้แตะปุ่ม Close all ระบบจะปิดแอปดังกล่าวทั้งหมด

ตัวอย่าง UX

รูปที่ 2 กล่องโต้ตอบสำหรับปิดความเสี่ยงจากการเข้าถึงที่ไม่รู้จัก

CLOSE_ALL_ACCESS_RISK (รหัสประเภท 3)

ปัญหาเกี่ยวกับคำตัดสิน

เมื่อ environmentDetails.appAccessRiskVerdict.appsDetected มี "KNOWN_CAPTURING", "KNOWN_CONTROLLING","UNKNOWN_CAPTURING" หรือ "UNKNOWN_CONTROLLING" หมายความว่ามีแอปที่ทำงานบนอุปกรณ์ซึ่ง อาจจับภาพหน้าจอหรือควบคุมอุปกรณ์ได้

การแก้ไข

คุณสามารถแสดงCLOSE_ALL_ACCESS_RISKกล่องโต้ตอบเพื่อแจ้งให้ผู้ใช้ปิดแอปทั้งหมด ที่อาจบันทึกหน้าจอหรือควบคุมอุปกรณ์ได้ หาก ผู้ใช้แตะปุ่ม Close all ระบบจะปิดแอปดังกล่าวทั้งหมดในอุปกรณ์

ตัวอย่าง UX

รูปที่ 3 กล่องโต้ตอบเพื่อปิดความเสี่ยงในการเข้าถึงทั้งหมด