自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
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 值。如果未找到键,则返回 null。 |
isAvailable
public boolean isAvailable ()
用于检查是否有有效的密钥库可供通信的方法。
返回 |
boolean |
如果我们有有效的密钥库,则为 true;否则为 false。 |
setKeyStore
public void setKeyStore (JSONObject keyStore)
用于设置密钥库的辅助方法。用于测试。
受保护的方法
setKey
protected void setKey (String key,
String value)
将 key
映射到 value
。等同于 mJsonKeyStore.put(key, value)
。
参数 |
key |
String |
value |
String |
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):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"]],["最后更新时间 (UTC):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` | |"]]