自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
JSONFileKeyStoreClient
public
class
JSONFileKeyStoreClient
extends Object
implements
IKeyStoreClient
java.lang.Object
|
↳ |
com.android.tradefed.util.keystore.JSONFileKeyStoreClient
|
本機 JSON 檔案充當金鑰儲存庫的實作範例。JSON 文字檔案的鍵/值應採用字串格式。
摘要
受保護的方法 |
void
|
setKey(String key, String value)
將 key 對應至 value 。
|
欄位
mJsonKeyStore
protected JSONObject mJsonKeyStore
公用建構函式
JSONFileKeyStoreClient
public JSONFileKeyStoreClient ()
JSONFileKeyStoreClient
public JSONFileKeyStoreClient (File jsonFile)
公用方法
containsKey
public boolean containsKey (String key)
檢查金鑰庫是否包含特定金鑰的方法。
傳回 |
boolean |
如果指定的鍵存在,則傳回 true。 |
fetchKey
public String fetchKey (String key)
在金鑰庫中擷取指定金鑰的方法。
傳回 |
String |
鍵的 String 值。如果找不到鍵,則會傳回空值。 |
isAvailable
public boolean isAvailable ()
用於檢查是否有可用來通訊的有效金鑰庫。
傳回 |
boolean |
如果我們有有效的鍵值儲存庫,則傳回 true,否則傳回 false。 |
setKeyStore
public void setKeyStore (JSONObject keyStore)
用於設定 KeyStore 的輔助方法。用於測試。
受保護的方法
setKey
protected void setKey (String key,
String value)
將 key
對應至 value
。等同於 mJsonKeyStore.put(key, value)
。
參數 |
key |
String |
value |
String |
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# JSONFileKeyStoreClient\n======================\n\n\n`\npublic\n\n\nclass\nJSONFileKeyStoreClient\n`\n\n\n`\n\nextends Object\n\n\n`\n\n`\n\n\nimplements\n\n`[IKeyStoreClient](../../../../../../../reference/tradefed/com/android/tradefed/util/keystore/IKeyStoreClient.html)`\n\n\n`\n\n|---|-----------------------------------------------------------|\n| java.lang.Object ||\n| ↳ | com.android.tradefed.util.keystore.JSONFileKeyStoreClient |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nA sample implementation where a local JSON file acts a key store. The JSON\ntext file should have key to value in string format.\n\nSummary\n-------\n\n| ### Fields ||\n|-------------------------|---------------------------------------------------------------------------------------------------------------------------------------|\n| ` protected JSONObject` | [mJsonKeyStore](../../../../../../../reference/tradefed/com/android/tradefed/util/keystore/JSONFileKeyStoreClient.html#mJsonKeyStore) |\n\n| ### Public constructors ||\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| ` `[JSONFileKeyStoreClient](../../../../../../../reference/tradefed/com/android/tradefed/util/keystore/JSONFileKeyStoreClient.html#JSONFileKeyStoreClient())`() ` |\n| ` `[JSONFileKeyStoreClient](../../../../../../../reference/tradefed/com/android/tradefed/util/keystore/JSONFileKeyStoreClient.html#JSONFileKeyStoreClient(File))`(File jsonFile) ` |\n\n| ### Public methods ||\n|------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` boolean` | ` `[containsKey](../../../../../../../reference/tradefed/com/android/tradefed/util/keystore/JSONFileKeyStoreClient.html#containsKey(java.lang.String))`(String key) ` A method to check if the key store contains a given key. |\n| ` String` | ` `[fetchKey](../../../../../../../reference/tradefed/com/android/tradefed/util/keystore/JSONFileKeyStoreClient.html#fetchKey(java.lang.String))`(String key) ` A method to fetch a given key inside the key store. |\n| ` boolean` | ` `[isAvailable](../../../../../../../reference/tradefed/com/android/tradefed/util/keystore/JSONFileKeyStoreClient.html#isAvailable())`() ` A method to check whether or not we have a valid key store to talk to. |\n| ` void` | ` `[setKeyStore](../../../../../../../reference/tradefed/com/android/tradefed/util/keystore/JSONFileKeyStoreClient.html#setKeyStore(org.json.JSONObject))`(JSONObject keyStore) ` Helper method used to set key store. |\n\n| ### Protected methods ||\n|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` void` | ` `[setKey](../../../../../../../reference/tradefed/com/android/tradefed/util/keystore/JSONFileKeyStoreClient.html#setKey(java.lang.String,%20java.lang.String))`(String key, String value) ` Maps `key` to `value`. |\n\nFields\n------\n\n### mJsonKeyStore\n\n```\nprotected JSONObject mJsonKeyStore\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nPublic constructors\n-------------------\n\n### JSONFileKeyStoreClient\n\n```\npublic JSONFileKeyStoreClient ()\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### JSONFileKeyStoreClient\n\n```\npublic JSONFileKeyStoreClient (File jsonFile)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|------------|---------------|\n| `jsonFile` | `File` \u003cbr /\u003e |\n\n| Throws ||\n|------------------------------------------------------------------------------------------------------------------------|---|\n| [KeyStoreException](../../../../../../../reference/tradefed/com/android/tradefed/util/keystore/KeyStoreException.html) | |\n\nPublic methods\n--------------\n\n### containsKey\n\n```\npublic boolean containsKey (String key)\n```\n\nA method to check if the key store contains a given key.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-------|------------------------------------------|\n| `key` | `String`: to check existence for. \u003cbr /\u003e |\n\n| Returns ||\n|-----------|--------------------------------------|\n| `boolean` | true if the given key exists. \u003cbr /\u003e |\n\n### fetchKey\n\n```\npublic String fetchKey (String key)\n```\n\nA method to fetch a given key inside the key store.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-------|-------------------------------------------------|\n| `key` | `String`: to fetch inside the key store. \u003cbr /\u003e |\n\n| Returns ||\n|----------|-----------------------------------------------------------------------------------------------------------------------------------------------|\n| `String` | the [String](../../../../../../../reference/tradefed/java/lang/String.html) value of the key. It will return null if key is not found. \u003cbr /\u003e |\n\n### isAvailable\n\n```\npublic boolean isAvailable ()\n```\n\nA method to check whether or not we have a valid key store to talk to.\n\n\u003cbr /\u003e\n\n| Returns ||\n|-----------|------------------------------------------------------------|\n| `boolean` | true if we have a valid key store, false otherwise. \u003cbr /\u003e |\n\n### setKeyStore\n\n```\npublic void setKeyStore (JSONObject keyStore)\n```\n\nHelper method used to set key store. Used for testing.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|------------|--------------------------------------------------------------------------------------------------------------------------|\n| `keyStore` | `JSONObject`: [JSONObject](../../../../../../../reference/tradefed/org/json/JSONObject.html) to use as key store. \u003cbr /\u003e |\n\nProtected methods\n-----------------\n\n### setKey\n\n```\nprotected void setKey (String key, \n String value)\n```\n\nMaps `key` to `value`. Equivalent to `mJsonKeyStore.put(key, value)`.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|---------|-----------------|\n| `key` | `String` \u003cbr /\u003e |\n| `value` | `String` \u003cbr /\u003e |\n\n| Throws ||\n|-----------------|---|\n| `JSONException` | |"]]