本頁面說明如何處理完整性判定結果的問題。
在要求提供完整性權杖時,您可以選擇向使用者顯示 Google Play 對話方塊。如果完整性判定結果出現一或多個問題,您就可以顯示這個對話方塊。對話方塊會顯示在應用程式頂端,並提示使用者解決問題。對話方塊關閉後,您可以向 Integrity API 提出另一項要求,驗證問題是否已修正。
完整性對話方塊
GET_LICENSED (類型代碼 1)
判定結果問題
發生 appLicensingVerdict == "UNLICENSED"
的情形。這表示使用者帳戶未經授權。也就是說,他們不是從 Google Play 安裝或購買應用程式。
修復
您可以顯示 GET_LICENSED
對話方塊,提示使用者利用 Google Play 取得應用程式。如果使用者接受,使用者帳戶就會獲得授權 (appLicensingVerdict == "LICENSED"
)。系統會將應用程式新增至使用者的 Google Play 程式庫,而 Google Play 可代您提供應用程式更新。
使用者體驗範例
CLOSE_UNKNOWN_ACCESS_RISK (類型代碼 2)
判定結果問題
如果 environmentDetails.appAccessRiskVerdict.appsDetected
包含 "UNKNOWN_CAPTURING"
或 "UNKNOWN_CONTROLLING"
,表示裝置上有不明應用程式正在執行,可能會擷取螢幕畫面或控制裝置。
修復
您可以顯示 CLOSE_UNKNOWN_ACCESS_RISK
對話方塊,提示使用者關閉所有可能擷取螢幕或控制裝置的不明應用程式。如果使用者輕觸 Close all
按鈕,系統會關閉所有這類應用程式。
使用者體驗範例
CLOSE_ALL_ACCESS_RISK (類型代碼 3)
判定結果問題
如果 environmentDetails.appAccessRiskVerdict.appsDetected
包含 "KNOWN_CAPTURING"
、"KNOWN_CONTROLLING"
、"UNKNOWN_CAPTURING"
或 "UNKNOWN_CONTROLLING"
中的任何項目,表示裝置上有執行中的應用程式,可能會擷取螢幕畫面或控制裝置。
修復
您可以顯示 CLOSE_ALL_ACCESS_RISK
對話方塊,提示使用者關閉所有可能擷取螢幕畫面或控制裝置的應用程式。如果使用者輕觸 Close all
按鈕,裝置上的所有這類應用程式都會關閉。
使用者體驗範例
要求完整性對話方塊
當用戶端要求完整性權杖時,您可以使用 StandardIntegrityToken (標準 API) 和 IntegrityTokenResponse (傳統 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);
原生
/// 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; }
原生
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. }
原生
// 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. }
對話方塊會顯示在系統提供的活動頂端。使用者關閉對話方塊後,工作就會完成,並顯示回應代碼。
(選用) 要求其他權杖,以便顯示任何後續對話方塊。如果您提出標準要求,需再次替權杖供應工具暖機,才能取得最新判定結果。