หน้านี้จะอธิบายวิธีจัดการปัญหาเกี่ยวกับผลการตัดสินด้านความสมบูรณ์
หลังจากขอโทเค็นความสมบูรณ์แล้ว คุณจะมีตัวเลือกในการแสดงกล่องโต้ตอบ Google Play ต่อผู้ใช้ คุณอาจแสดงกล่องโต้ตอบเมื่อมีปัญหาอย่างน้อย 1 รายการเกี่ยวกับผลการตัดสินความสมบูรณ์ หรือหากเกิดข้อยกเว้นระหว่างคำขอ Integrity API เมื่อปิดกล่องโต้ตอบแล้ว คุณจะยืนยันได้ว่าปัญหา ได้รับการแก้ไขแล้วด้วยคำขอโทเค็นความสมบูรณ์อีกรายการ หากส่งคำขอมาตรฐาน คุณจะต้องวอร์มอัพผู้ให้บริการโทเค็นอีกครั้ง เพื่อรับผลการตัดสินใหม่
ขอรับกล่องโต้ตอบความสมบูรณ์เพื่อแก้ไขปัญหาการตัดสิน
เมื่อไคลเอ็นต์ขอโทเค็นความสมบูรณ์ คุณจะใช้วิธีที่ระบุไว้ใน
StandardIntegrityToken
(Standard API) และ
IntegrityTokenResponse
(Classic API) ได้
showDialog(Activity activity, int integrityDialogTypeCode)
ขั้นตอนต่อไปนี้จะอธิบายวิธีใช้ Play Integrity API เพื่อแสดง
กล่องโต้ตอบการแก้ไขโดยใช้โค้ดกล่องโต้ตอบ GET_LICENSED
รหัสกล่องโต้ตอบอื่นๆ ที่แอปขอได้จะแสดงหลังจากส่วนนี้
ขอโทเค็นความสมบูรณ์จากแอป แล้วส่งโทเค็นไปยังเซิร์ฟเวอร์ คุณใช้คำขอมาตรฐานหรือคำขอแบบคลาสสิกได้
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));
ในเซิร์ฟเวอร์ ให้ถอดรหัสโทเค็นความสมบูรณ์และตรวจสอบฟิลด์
appLicensingVerdict
ซึ่งอาจมีลักษณะดังนี้// Licensing issue { ... "accountDetails": { "appLicensingVerdict": "UNLICENSED" } }
หากโทเค็นมี
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; }
ในแอป ให้เรียกใช้
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. }
กล่องโต้ตอบจะแสดงที่ด้านบนของกิจกรรมที่ระบุ เมื่อผู้ใช้ปิดกล่องโต้ตอบแล้ว งานจะเสร็จสมบูรณ์พร้อมรหัสการตอบกลับ
(ไม่บังคับ) ขอโทเค็นอีกรายการเพื่อแสดงกล่องโต้ตอบเพิ่มเติม หากส่งคำขอมาตรฐาน คุณจะต้องอุ่นเครื่อง ผู้ให้บริการโทเค็นอีกครั้งเพื่อรับผลการตัดสินใหม่
ขอให้แสดงกล่องโต้ตอบความสมบูรณ์เพื่อแก้ไขข้อยกเว้นฝั่งไคลเอ็นต์
หากคำขอ Integrity API ไม่สำเร็จโดยมีข้อผิดพลาด StandardIntegrityException
(Standard API) หรือ IntegrityServiceException
(Classic API) และ
ข้อยกเว้นสามารถแก้ไขได้ คุณสามารถใช้กล่องโต้ตอบ GET_INTEGRITY
หรือ
GET_STRONG_INTEGRITY
เพื่อแก้ไขข้อผิดพลาดได้
ขั้นตอนต่อไปนี้จะอธิบายวิธีใช้กล่องโต้ตอบ GET_INTEGRITY
เพื่อแก้ไขข้อผิดพลาดที่แก้ไขได้ฝั่งไคลเอ็นต์ซึ่ง Integrity API รายงาน
ตรวจสอบว่าข้อยกเว้นที่ส่งคืนจากคำขอ Integrity API สามารถแก้ไขได้
Kotlin
private fun isExceptionRemediable(exception: ExecutionException): Boolean { val cause = exception.cause if (cause is StandardIntegrityException && cause.isRemediable) { return true } return false }
Java
private boolean isExceptionRemediable(ExecutionException exception) { Throwable cause = exception.getCause(); if (cause instanceof StandardIntegrityException integrityException && integrityException.isRemediable()) { return true; } return false; }
หากข้อยกเว้นสามารถแก้ไขได้ ให้ขอ
GET_INTEGRITY
กล่องโต้ตอบโดยใช้ข้อยกเว้นที่ส่งคืน กล่องโต้ตอบจะแสดงเหนือกิจกรรมที่ระบุ และ Task ที่ส่งคืนจะเสร็จสมบูรณ์พร้อมรหัสการตอบกลับหลังจากที่ผู้ใช้ปิดกล่องโต้ตอบKotlin
private fun showDialog(exception: StandardIntegrityException) { // Create a dialog request val standardIntegrityDialogRequest = StandardIntegrityDialogRequest.builder() .setActivity(activity) .setType(IntegrityDialogTypeCode.GET_INTEGRITY) .setStandardIntegrityResponse(ExceptionDetails(exception)) .build() // Request dialog val responseCode: Task<Int> = standardIntegrityManager.showDialog(standardIntegrityDialogRequest) }
Java
private void showDialog(StandardIntegrityException exception) { // Create a dialog request StandardIntegrityDialogRequest standardIntegrityDialogRequest = StandardIntegrityDialogRequest.builder() .setActivity(this.activity) .setType(IntegrityDialogTypeCode.GET_INTEGRITY) .setStandardIntegrityResponse(new ExceptionDetails(exception)) .build(); // Request dialog Task<Integer> responseCode = standardIntegrityManager.showDialog(standardIntegrityDialogRequest); }
หากรหัสการตอบกลับที่ส่งคืนระบุว่าสำเร็จ คำขอโทเค็นความสมบูรณ์ครั้งถัดไปควรสำเร็จโดยไม่มีข้อยกเว้น หากส่งคำขอมาตรฐาน คุณจะต้องวอร์มอัพผู้ให้บริการโทเค็นอีกครั้งเพื่อรับผลการตัดสินใหม่
รหัสกล่องโต้ตอบความสมบูรณ์
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

CLOSE_UNKNOWN_ACCESS_RISK (รหัสประเภท 2)
ปัญหาเกี่ยวกับคำตัดสิน
เมื่อ environmentDetails.appAccessRiskVerdict.appsDetected
มี
"UNKNOWN_CAPTURING"
หรือ "UNKNOWN_CONTROLLING"
แสดงว่ามีแอปอื่นๆ
(ไม่ได้ติดตั้งโดย Google Play หรือโหลดไว้ล่วงหน้าในพาร์ติชันระบบโดยผู้ผลิตอุปกรณ์)
กำลังทำงานในอุปกรณ์ซึ่งอาจจับภาพหน้าจอหรือ
ควบคุมอุปกรณ์
การแก้ไข
คุณสามารถแสดงกล่องโต้ตอบ CLOSE_UNKNOWN_ACCESS_RISK
เพื่อแจ้งให้ผู้ใช้ปิด
แอปที่ไม่รู้จักทั้งหมดซึ่งอาจบันทึกหน้าจอหรือควบคุมอุปกรณ์ได้
หากผู้ใช้แตะปุ่ม Close all
ระบบจะปิดแอปดังกล่าวทั้งหมด
ตัวอย่าง UX

CLOSE_ALL_ACCESS_RISK (รหัสประเภท 3)
ปัญหาเกี่ยวกับคำตัดสิน
เมื่อ environmentDetails.appAccessRiskVerdict.appsDetected
มี
"KNOWN_CAPTURING"
, "KNOWN_CONTROLLING"
,"UNKNOWN_CAPTURING"
หรือ
"UNKNOWN_CONTROLLING"
หมายความว่ามีแอปที่ทำงานบนอุปกรณ์ซึ่ง
อาจจับภาพหน้าจอหรือควบคุมอุปกรณ์ได้
การแก้ไข
คุณสามารถแสดงCLOSE_ALL_ACCESS_RISK
กล่องโต้ตอบเพื่อแจ้งให้ผู้ใช้ปิดแอปทั้งหมด
ที่อาจบันทึกหน้าจอหรือควบคุมอุปกรณ์ หาก
ผู้ใช้แตะปุ่ม Close all
ระบบจะปิดแอปดังกล่าวทั้งหมดในอุปกรณ์
ตัวอย่าง UX

GET_INTEGRITY (รหัสประเภท 4)
ปัญหาเกี่ยวกับคำตัดสิน
กล่องโต้ตอบนี้เหมาะสำหรับปัญหาต่อไปนี้
ความสมบูรณ์ของอุปกรณ์ต่ำ: เมื่อ
deviceRecognitionVerdict
ไม่มีMEETS_DEVICE_INTEGRITY
อุปกรณ์อาจไม่ใช่ อุปกรณ์ที่ใช้ Android แท้ซึ่งได้รับการรับรองจาก Play Protect เช่น กรณีนี้อาจเกิดขึ้นหาก Bootloader ของอุปกรณ์ถูกปลดล็อกหรือระบบปฏิบัติการ Android ที่โหลดไว้ไม่ใช่รูปภาพของผู้ผลิตที่ได้รับการรับรองการเข้าถึงที่ไม่ได้รับอนุญาต:
appLicensingVerdict: "UNLICENSED"
ซึ่งหมายความว่าบัญชีผู้ใช้ไม่มีสิทธิ์เข้าถึงแอปของคุณ ซึ่งอาจเกิดขึ้นได้หากผู้ใช้ โหลดแอปจากแหล่งที่ไม่รู้จักหรือได้แอปมาจาก App Store อื่นที่ไม่ใช่ Google Playแอปที่ถูกดัดแปลง:
appRecognitionVerdict: "UNRECOGNIZED_VERSION"
ซึ่งหมายความว่าไบนารีของแอปมีการแก้ไขหรือไม่ใช่เวอร์ชันที่ Google Play รู้จักข้อยกเว้นฝั่งไคลเอ็นต์: เมื่อเกิดข้อยกเว้นที่แก้ไขได้ระหว่างคำขอ Integrity API ข้อยกเว้นที่แก้ไขได้คือข้อยกเว้นของ Integrity API ที่มี รหัสข้อผิดพลาด เช่น
PLAY_SERVICES_VERSION_OUTDATED
,NETWORK_ERROR
,PLAY_SERVICES_NOT_FOUND
เป็นต้น คุณสามารถใช้วิธีexception.isRemediable()
เพื่อตรวจสอบว่า ข้อยกเว้นแก้ไขได้โดยใช้กล่องโต้ตอบหรือไม่
การแก้ไข
GET_INTEGRITY
กล่องโต้ตอบได้รับการออกแบบมาเพื่อปรับปรุงประสบการณ์ของผู้ใช้โดย
จัดการขั้นตอนการแก้ไขหลายขั้นตอนภายในโฟลว์เดียวที่ต่อเนื่อง ซึ่งจะช่วยให้ผู้ใช้ไม่ต้องโต้ตอบกับกล่องโต้ตอบแยกกันหลายกล่องเพื่อแก้ไขปัญหาต่างๆ
เมื่อคุณขอใช้กล่องโต้ตอบ ระบบจะตรวจหาปัญหาเกี่ยวกับผลการตัดสินที่กำหนดเป้าหมายโดยอัตโนมัติ และแสดงขั้นตอนการแก้ไขที่เหมาะสม ซึ่งหมายความว่าคำขอในกล่องโต้ตอบเดียวสามารถแก้ไขปัญหาหลายอย่างได้พร้อมกัน รวมถึง
- ความสมบูรณ์ของอุปกรณ์: หากตรวจพบปัญหาเกี่ยวกับความสมบูรณ์ของอุปกรณ์ กล่องโต้ตอบจะ
แนะนําให้ผู้ใช้ปรับปรุงสถานะความปลอดภัยของอุปกรณ์ให้เป็นไปตาม
ข้อกําหนดสําหรับผลการตรวจสอบ
MEETS_DEVICE_INTEGRITY
- ความสมบูรณ์ของแอป: หากตรวจพบปัญหาต่างๆ เช่น การเข้าถึงที่ไม่ได้รับอนุญาตหรือการดัดแปลงแอป กล่องโต้ตอบจะนำผู้ใช้ไปดาวน์โหลดแอปจาก Play Store เพื่อแก้ไขปัญหา
- ข้อยกเว้นฝั่งไคลเอ็นต์: กล่องโต้ตอบจะตรวจสอบและพยายามแก้ไขปัญหาพื้นฐานที่ทำให้เกิดข้อยกเว้น Integrity API เช่น อาจ แจ้งให้ผู้ใช้อัปเดตบริการ Google Play เวอร์ชันที่ล้าสมัย
ตัวอย่าง UX

GET_STRONG_INTEGRITY (รหัสประเภท 5)
ปัญหาเกี่ยวกับคำตัดสิน
กล่องโต้ตอบนี้ออกแบบมาเพื่อแก้ไขปัญหาเดียวกันทั้งหมดที่
GET_INTEGRITY
จัดการ พร้อมความสามารถเพิ่มเติมในการแก้ไขปัญหาที่ทำให้อุปกรณ์ไม่ได้รับผลการตรวจสอบ MEETS_STRONG_INTEGRITY
และแก้ไขปัญหาผลการตรวจสอบของ Play Protect
การแก้ไข
GET_STRONG_INTEGRITY
ออกแบบมาเพื่อปรับปรุงประสบการณ์ของผู้ใช้โดย
จัดการขั้นตอนการแก้ไขหลายขั้นตอนภายในโฟลว์เดียวอย่างต่อเนื่อง กล่องโต้ตอบ
จะตรวจสอบปัญหาความสมบูรณ์ของที่อยู่ที่เกี่ยวข้องโดยอัตโนมัติ ซึ่งรวมถึง
- ความสมบูรณ์ของอุปกรณ์: หากตรวจพบปัญหาเกี่ยวกับความสมบูรณ์ของอุปกรณ์ กล่องโต้ตอบจะ
แนะนําให้ผู้ใช้ปรับปรุงสถานะความปลอดภัยของอุปกรณ์ให้เป็นไปตาม
ข้อกําหนดสําหรับผลการตรวจสอบ
MEETS_STRONG_INTEGRITY
สถานะ Play Protect: หาก
playProtectVerdict
ระบุว่ามีปัญหา กล่องโต้ตอบจะแนะนำให้ผู้ใช้แก้ไขปัญหา- หากปิดใช้ Play Protect (
playProtectVerdict == POSSIBLE_RISK
) ไว้ กล่องโต้ตอบจะแจ้งให้ผู้ใช้เปิดใช้และสแกนแอปทั้งหมด ในอุปกรณ์ - หากตรวจพบแอปที่เป็นอันตราย (
playProtectVerdict == MEDIUM_RISK
หรือHIGH_RISK
) กล่องโต้ตอบจะนำผู้ใช้ไปถอนการติดตั้งแอปเหล่านั้นโดยใช้ Google Play Protect
- หากปิดใช้ Play Protect (
ความสมบูรณ์ของแอป: หากตรวจพบปัญหาต่างๆ เช่น การเข้าถึงที่ไม่ได้รับอนุญาตหรือการดัดแปลงแอป กล่องโต้ตอบจะแจ้งให้ผู้ใช้ดาวน์โหลดแอปจาก Play Store เพื่อแก้ไขปัญหา
ข้อยกเว้นฝั่งไคลเอ็นต์: กล่องโต้ตอบจะพยายามแก้ไขปัญหาพื้นฐานที่ทำให้เกิดข้อยกเว้นของ Integrity API ด้วย เช่น อาจแจ้งให้ผู้ใช้เปิดใช้บริการ Google Play หากพบว่าปิดใช้อยู่ ข้อยกเว้นที่แก้ไขได้คือข้อยกเว้นของ Integrity API ที่มีรหัสข้อผิดพลาด เช่น
PLAY_SERVICES_VERSION_OUTDATED
,NETWORK_ERROR
หรือPLAY_SERVICES_NOT_FOUND
คุณสามารถใช้วิธีexception.isRemediable()
เพื่อตรวจสอบว่าข้อผิดพลาดแก้ไขได้โดยใช้กล่องโต้ตอบหรือไม่
ตัวอย่าง UX
