mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 01:35:17 +08:00
Modify change YukiHookModulePrefs name to YukiHookPrefsBridge and make it support native storage usage in YukiHookPrefsBridge
This commit is contained in:
@@ -29,7 +29,7 @@ const navigationLinks = {
|
||||
baseApiPath + 'hook/param/HookParam',
|
||||
baseApiPath + 'annotation/xposed/InjectYukiHookWithXposed',
|
||||
baseApiPath + 'hook/xposed/proxy/IYukiHookXposedInit',
|
||||
baseApiPath + 'hook/xposed/prefs/YukiHookModulePrefs',
|
||||
baseApiPath + 'hook/xposed/prefs/YukiHookPrefsBridge',
|
||||
baseApiPath + 'hook/xposed/prefs/ui/ModulePreferenceFragment',
|
||||
baseApiPath + 'hook/xposed/prefs/data/PrefsData',
|
||||
baseApiPath + 'hook/xposed/channel/YukiHookDataChannel',
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
> Here are the unresolved issues with `YukiHookAPI`.
|
||||
|
||||
### YukiHookModulePrefs
|
||||
### YukiHookPrefsBridge
|
||||
|
||||
Currently only supports LSPosed perfectly, other Xposed Framework need to downgrade the module target api.
|
||||
|
||||
|
@@ -404,23 +404,33 @@ var isDebug: Boolean
|
||||
|
||||
请转移到 `YukiHookLogger.Configs.isEnable`
|
||||
|
||||
### isEnableModulePrefsCache <span class="symbol">- field</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
var isEnableModulePrefsCache: Boolean
|
||||
```
|
||||
<h3 class="deprecated">isEnableModulePrefsCache - field</h3>
|
||||
|
||||
**Change Records**
|
||||
|
||||
`v1.0.5` `added`
|
||||
|
||||
`v1.1.9` `deprecated`
|
||||
|
||||
请转移到 `isEnablePrefsBridgeCache`
|
||||
|
||||
### isEnablePrefsBridgeCache <span class="symbol">- field</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
var isEnablePrefsBridgeCache: Boolean
|
||||
```
|
||||
|
||||
**Change Records**
|
||||
|
||||
`v1.1.9` `added`
|
||||
|
||||
**Function Illustrate**
|
||||
|
||||
> 是否启用 `YukiHookModulePrefs` 的键值缓存功能。
|
||||
> 是否启用 `YukiHookPrefsBridge` 的键值缓存功能。
|
||||
|
||||
为防止内存复用过高问题,此功能默认启用。
|
||||
|
||||
你可以手动在 `YukiHookModulePrefs` 中自由开启和关闭缓存功能以及清除缓存。
|
||||
你可以手动在 `YukiHookPrefsBridge` 中自由开启和关闭缓存功能以及清除缓存。
|
||||
|
||||
### isEnableModuleAppResourcesCache <span class="symbol">- field</span>
|
||||
|
||||
@@ -488,7 +498,7 @@ var isEnableHookSharedPreferences: Boolean
|
||||
|
||||
这是一个可选的实验性功能,此功能默认不启用。
|
||||
|
||||
仅用于修复某些系统可能会出现在启用了 **New XSharedPreferences** 后依然出现文件权限错误问题,若你能正常使用 **YukiHookModulePrefs** 就不建议启用此功能。
|
||||
仅用于修复某些系统可能会出现在启用了 **New XSharedPreferences** 后依然出现文件权限错误问题,若你能正常使用 **YukiHookPrefsBridge** 就不建议启用此功能。
|
||||
|
||||
:::
|
||||
|
||||
@@ -572,7 +582,7 @@ object HookEntry : IYukiHookXposedInit {
|
||||
elements(TAG, PRIORITY, PACKAGE_NAME, USER_ID)
|
||||
}
|
||||
isDebug = BuildConfig.DEBUG
|
||||
isEnableModulePrefsCache = true
|
||||
isEnablePrefsBridgeCache = true
|
||||
isEnableModuleAppResourcesCache = true
|
||||
isEnableHookModuleStatus = true
|
||||
isEnableHookSharedPreferences = false
|
||||
@@ -602,7 +612,7 @@ object HookEntry : IYukiHookXposedInit {
|
||||
elements(TAG, PRIORITY, PACKAGE_NAME, USER_ID)
|
||||
}
|
||||
isDebug = BuildConfig.DEBUG
|
||||
isEnableModulePrefsCache = true
|
||||
isEnablePrefsBridgeCache = true
|
||||
isEnableModuleAppResourcesCache = true
|
||||
isEnableHookModuleStatus = true
|
||||
isEnableHookSharedPreferences = false
|
||||
@@ -634,7 +644,7 @@ object HookEntry : IYukiHookXposedInit {
|
||||
YukiHookLogger.Configs.USER_ID
|
||||
)
|
||||
YukiHookAPI.Configs.isDebug = BuildConfig.DEBUG
|
||||
YukiHookAPI.Configs.isEnableModulePrefsCache = true
|
||||
YukiHookAPI.Configs.isEnablePrefsBridgeCache = true
|
||||
YukiHookAPI.Configs.isEnableModuleAppResourcesCache = true
|
||||
YukiHookAPI.Configs.isEnableHookModuleStatus = true
|
||||
YukiHookAPI.Configs.isEnableHookSharedPreferences = false
|
||||
|
@@ -64,33 +64,45 @@ fun IYukiHookXposedInit.encase(vararg hooker: YukiBaseHooker)
|
||||
|
||||
> 在 `IYukiHookXposedInit` 中调用 `YukiHookAPI`。
|
||||
|
||||
## Context.modulePrefs <span class="symbol">- ext-field</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
val Context.modulePrefs: YukiHookModulePrefs
|
||||
```
|
||||
<h2 class="deprecated">Context.modulePrefs - ext-field</h2>
|
||||
|
||||
**Change Records**
|
||||
|
||||
`v1.0` `first`
|
||||
|
||||
**Function Illustrate**
|
||||
`v1.1.9` `deprecated`
|
||||
|
||||
> 获取模块的存取对象。
|
||||
请转移到 `prefs` 方法
|
||||
|
||||
## Context.modulePrefs <span class="symbol">- ext-method</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
fun Context.modulePrefs(name: String): YukiHookModulePrefs
|
||||
```
|
||||
<h2 class="deprecated">Context.modulePrefs - ext-method</h2>
|
||||
|
||||
**Change Records**
|
||||
|
||||
`v1.0` `first`
|
||||
|
||||
`v1.1.9` `deprecated`
|
||||
|
||||
请转移到 `prefs` 方法
|
||||
|
||||
## Context.prefs <span class="symbol">- ext-method</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
fun Context.prefs(name: String): YukiHookPrefsBridge
|
||||
```
|
||||
|
||||
**Change Records**
|
||||
|
||||
`v1.1.9` `added`
|
||||
|
||||
**Function Illustrate**
|
||||
|
||||
> 获取模块的存取对象,可设置 `name` 为自定义 Sp 存储名称。
|
||||
> 获取 `YukiHookPrefsBridge` 对象。
|
||||
|
||||
可以同时在模块与 (Xposed) 宿主环境中使用。
|
||||
|
||||
如果你想在 (Xposed) 宿主环境将数据存入当前宿主的私有空间,请使用 `YukiHookPrefsBridge.native` 方法。
|
||||
|
||||
在未声明任何条件的情况下 (Xposed) 宿主环境默认读取模块中的数据。
|
||||
|
||||
## Context.dataChannel <span class="symbol">- ext-method</span>
|
||||
|
||||
|
@@ -243,7 +243,7 @@ val moduleAppResources: YukiModuleResources
|
||||
## prefs <span class="symbol">- field</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
val prefs: YukiHookModulePrefs
|
||||
val prefs: YukiHookPrefsBridge
|
||||
```
|
||||
|
||||
**Change Records**
|
||||
@@ -263,7 +263,7 @@ val prefs: YukiHookModulePrefs
|
||||
## prefs <span class="symbol">- method</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
fun prefs(name: String): YukiHookModulePrefs
|
||||
fun prefs(name: String): YukiHookPrefsBridge
|
||||
```
|
||||
|
||||
**Change Records**
|
||||
|
@@ -10,25 +10,29 @@ You can use the **Chrome Translation Plugin** to translate entire pages for refe
|
||||
|
||||
:::
|
||||
|
||||
# YukiHookModulePrefs <span class="symbol">- class</span>
|
||||
# YukiHookPrefsBridge <span class="symbol">- class</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
class YukiHookModulePrefs private constructor(private var context: Context?)
|
||||
class YukiHookPrefsBridge private constructor(private var context: Context?)
|
||||
```
|
||||
|
||||
**Change Records**
|
||||
|
||||
`v1.0` `first`
|
||||
|
||||
`v1.1.9` `modified`
|
||||
|
||||
~~`YukiHookModulePrefs`~~ 更名为 `YukiHookPrefsBridge`
|
||||
|
||||
**Function Illustrate**
|
||||
|
||||
> 实现 Xposed 模块的数据存取,对接 `SharedPreferences` 和 `XSharedPreferences`。
|
||||
> `YukiHookAPI` 对 `SharedPreferences`、`XSharedPreferences` 的扩展存储桥实现。
|
||||
|
||||
在不同环境智能选择存取使用的对象。
|
||||
|
||||
::: danger
|
||||
|
||||
此功能为实验性功能,仅在 LSPosed 环境测试通过,EdXposed 理论也可以使用但不再推荐。
|
||||
模块与宿主之前共享数据存储为实验性功能,仅在 LSPosed 环境测试通过,EdXposed 理论也可以使用但不再推荐。
|
||||
|
||||
:::
|
||||
|
||||
@@ -42,13 +46,7 @@ class YukiHookModulePrefs private constructor(private var context: Context?)
|
||||
|
||||
太极请参阅 [文件权限/配置/XSharedPreference](https://taichi.cool/zh/doc/for-xposed-dev.html#文件权限-配置-xsharedpreference)。
|
||||
|
||||
::: danger
|
||||
|
||||
当你在 Xposed 模块中存取数据的时候 **context** 必须不能是空的。
|
||||
|
||||
:::
|
||||
|
||||
若你正在使用 `PreferenceFragmentCompat`,请迁移到 `ModulePreferenceFragment` 以适配上述功能特性。
|
||||
对于在模块环境中使用 `PreferenceFragmentCompat`,`YukiHookAPI` 提供了 `ModulePreferenceFragment` 来实现同样的功能。
|
||||
|
||||
**Optional Configuration**
|
||||
|
||||
@@ -96,7 +94,7 @@ val isPreferencesAvailable: Boolean
|
||||
|
||||
**Function Illustrate**
|
||||
|
||||
> 获取当前 `YukiHookModulePrefs` 的可用状态。
|
||||
> 获取当前 `YukiHookPrefsBridge` 的可用状态。
|
||||
|
||||
在 (Xposed) 宿主环境中返回 `XSharedPreferences` 可用状态 (可读)。
|
||||
|
||||
@@ -105,7 +103,7 @@ val isPreferencesAvailable: Boolean
|
||||
## name <span class="symbol">- method</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
fun name(name: String): YukiHookModulePrefs
|
||||
fun name(name: String): YukiHookPrefsBridge
|
||||
```
|
||||
|
||||
**Change Records**
|
||||
@@ -123,7 +121,7 @@ fun name(name: String): YukiHookModulePrefs
|
||||
> The following example
|
||||
|
||||
```kotlin
|
||||
modulePrefs("custom_name").getString("custom_key")
|
||||
prefs("custom_name").getString("custom_key")
|
||||
```
|
||||
|
||||
在 (Xposed) 宿主环境 `PackageParam` 中的使用方法。
|
||||
@@ -137,7 +135,7 @@ prefs("custom_name").getString("custom_key")
|
||||
## direct <span class="symbol">- method</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
fun direct(): YukiHookModulePrefs
|
||||
fun direct(): YukiHookPrefsBridge
|
||||
```
|
||||
|
||||
**Change Records**
|
||||
@@ -148,10 +146,24 @@ fun direct(): YukiHookModulePrefs
|
||||
|
||||
> 忽略缓存直接读取键值。
|
||||
|
||||
无论是否开启 `YukiHookAPI.Configs.isEnableModulePrefsCache`。
|
||||
无论是否开启 `YukiHookAPI.Configs.isEnablePrefsBridgeCache`。
|
||||
|
||||
仅在 `XSharedPreferences` 下生效。
|
||||
|
||||
## native <span class="symbol">- method</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
fun native(): YukiHookPrefsBridge
|
||||
```
|
||||
|
||||
**Change Records**
|
||||
|
||||
`v1.1.9` `added`
|
||||
|
||||
**Function Illustrate**
|
||||
|
||||
> 忽略当前环境直接使用 `Context.getSharedPreferences` 存取数据。
|
||||
|
||||
## getString <span class="symbol">- method</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
@@ -434,7 +446,7 @@ fun clearCache()
|
||||
|
||||
> 清除 `XSharedPreferences` 中缓存的键值数据。
|
||||
|
||||
无论是否开启 `YukiHookAPI.Configs.isEnableModulePrefsCache`。
|
||||
无论是否开启 `YukiHookAPI.Configs.isEnablePrefsBridgeCache`。
|
||||
|
||||
调用此方法将清除当前存储的全部键值缓存。
|
||||
|
||||
@@ -454,7 +466,7 @@ inner class Editor internal constructor()
|
||||
|
||||
**Function Illustrate**
|
||||
|
||||
> `YukiHookModulePrefs` 的存储代理类。
|
||||
> `YukiHookPrefsBridge` 的存储代理类。
|
||||
|
||||
请使用 `edit` 方法来获取 `Editor`。
|
||||
|
@@ -28,7 +28,7 @@ data class PrefsData<T>(var key: String, var value: T) : Serializable
|
||||
|
||||
> 键值对存储构造类。
|
||||
|
||||
这个类是对 `YukiHookModulePrefs` 的一个扩展用法。
|
||||
这个类是对 `YukiHookPrefsBridge` 的一个扩展用法。
|
||||
|
||||
**Function Example**
|
||||
|
||||
@@ -51,9 +51,9 @@ object DataConst {
|
||||
|
||||
```kotlin
|
||||
// 读取
|
||||
val data = modulePrefs.get(DataConst.TEST_KV_DATA_1)
|
||||
val data = prefs().get(DataConst.TEST_KV_DATA_1)
|
||||
// 写入
|
||||
modulePrefs.put(DataConst.TEST_KV_DATA_1, "written value")
|
||||
prefs().edit { put(DataConst.TEST_KV_DATA_1, "written value") }
|
||||
```
|
||||
|
||||
> 宿主示例如下
|
||||
|
@@ -10,7 +10,7 @@ The native `Xposed` provides us with a `XSharedPreferences` for reading the `Sp`
|
||||
|
||||
## Use in Activity
|
||||
|
||||
> Loading `YukiHookModulePrefs` in `Activity` is described here.
|
||||
> Loading `YukiHookPrefsBridge` in `Activity` is described here.
|
||||
|
||||
Usually we can initialize it in Host App like this.
|
||||
|
||||
@@ -29,7 +29,7 @@ When you store data in a Module App, you can use the following methods if you ar
|
||||
> The following example
|
||||
|
||||
```kotlin
|
||||
modulePrefs.putString("test_name", "saved_value")
|
||||
prefs().edit { putString("test_name", "saved_value") }
|
||||
```
|
||||
|
||||
When you read data in a Host App, you can use the following methods.
|
||||
@@ -40,7 +40,7 @@ When you read data in a Host App, you can use the following methods.
|
||||
val testName = prefs.getString("test_name", "default_value")
|
||||
```
|
||||
|
||||
You don't need to consider the module package name and a series of complicated permission configurations, everything is handled by `YukiHookModulePrefs`.
|
||||
You don't need to consider the module package name and a series of complicated permission configurations, everything is handled by `YukiHookPrefsBridge`.
|
||||
|
||||
To achieve localization of storage, you can specify the name of each `prefs` file.
|
||||
|
||||
@@ -50,9 +50,9 @@ This is used in the `Activity` of the Module App.
|
||||
|
||||
```kotlin
|
||||
// Recommended usage
|
||||
modulePrefs("specify_file_name").putString("test_name", "saved_value")
|
||||
prefs("specify_file_name").edit { putString("test_name", "saved_value") }
|
||||
// Can also be used like this
|
||||
modulePrefs.name("specify_file_name").putString("test_name", "saved_value")
|
||||
prefs().name("specify_file_name").edit { putString("test_name", "saved_value") }
|
||||
```
|
||||
|
||||
Read like this in Host App.
|
||||
@@ -68,21 +68,40 @@ val testName = prefs.name("specify_file_name").getString("test_name", "default_v
|
||||
|
||||
If your project has a lot of fixed data that needs to be stored and read, it is recommended to use `PrefsData` to create templates.
|
||||
|
||||
Through the above example, you can call the `edit` method to store data in batches in the following two ways.
|
||||
|
||||
> The following example
|
||||
|
||||
```kotlin
|
||||
// <Scenario 1>
|
||||
prefs().edit {
|
||||
putString("test_name_1", "saved_value_1")
|
||||
putString("test_name_2", "saved_value_2")
|
||||
putString("test_name_3", "saved_value_3")
|
||||
}
|
||||
// <Scenario 2>
|
||||
prefs(). edit()
|
||||
.putString("test_name_1", "saved_value_1")
|
||||
.putString("test_name_2", "saved_value_2")
|
||||
.putString("test_name_3", "saved_value_3")
|
||||
.apply()
|
||||
```
|
||||
|
||||
::: tip
|
||||
|
||||
For more functions, please refer to [YukiHookModulePrefs](../public/com/highcapable/yukihookapi/hook/xposed/prefs/YukiHookModulePrefs), [PrefsData](../public/com/highcapable/yukihookapi/hook/xposed/prefs/data/PrefsData).
|
||||
For more functions, please refer to [YukiHookPrefsBridge](../public/com/highcapable/yukihookapi/hook/xposed/prefs/YukiHookPrefsBridge), [PrefsData](../public/com/highcapable/yukihookapi/hook/xposed/prefs/data/PrefsData).
|
||||
|
||||
:::
|
||||
|
||||
## Use in PreferenceFragment
|
||||
|
||||
> Loading `YukiHookModulePrefs` in `PreferenceFragment` is described here.
|
||||
> Loading `YukiHookPrefsBridge` in `PreferenceFragment` is described here.
|
||||
|
||||
If your Module App uses `PreferenceFragmentCompat`, you can now start migrating its extends `ModulePreferenceFragment`.
|
||||
|
||||
::: danger
|
||||
|
||||
You must extends **ModulePreferenceFragment** to implement the module storage function of **YukiHookModulePrefs**.
|
||||
You must extends **ModulePreferenceFragment** to implement the module storage function of **YukiHookPrefsBridge**.
|
||||
|
||||
:::
|
||||
|
||||
@@ -90,4 +109,50 @@ You must extends **ModulePreferenceFragment** to implement the module storage fu
|
||||
|
||||
For more functions, please refer to [ModulePreferenceFragment](../public/com/highcapable/yukihookapi/hook/xposed/prefs/ui/ModulePreferenceFragment).
|
||||
|
||||
:::
|
||||
|
||||
## Use Native Storage
|
||||
|
||||
In the Module environment, `YukiHookPrefsBridge` will store data in the Module App's own private directory (or the shared directory provided by Hook Framework) by default.
|
||||
|
||||
Using `YukiHookPrefsBridge` in the Host environment will read the data in the Module App's own private directory (or the shared directory provided by Hook Framework) by default.
|
||||
|
||||
If you want to store data directly into a Module App or Host App's own private directory, you can use the `native` method.
|
||||
|
||||
For example, the directory of the Module App is `.../com.demo.test.module/shared_prefs`, and the directory of the Host App is `.../com.demo.test.host/shared_prefs`.
|
||||
|
||||
The following is the usage in `Activity`.
|
||||
|
||||
> The following example
|
||||
|
||||
```kotlin
|
||||
// Store private data
|
||||
prefs().native().edit { putBoolean("isolation_data", true) }
|
||||
// Read private data
|
||||
val privateData = prefs().native().getBoolean("isolation_data")
|
||||
// Store shared data
|
||||
prefs().edit { putBoolean("public_data", true) }
|
||||
// Read shared data
|
||||
val publicData = prefs().getBoolean("public_data")
|
||||
```
|
||||
|
||||
The following is the usage in `PackageParam`.
|
||||
|
||||
> The following example
|
||||
|
||||
```kotlin
|
||||
// Store private data
|
||||
prefs.native().edit { putBoolean("isolation_data", true) }
|
||||
// Read private data
|
||||
val privateData = prefs.native().getBoolean("isolation_data")
|
||||
// Read shared data
|
||||
val publicData = prefs.getBoolean("public_data")
|
||||
```
|
||||
|
||||
After using the `native` method, no matter in `Activity` or `PackageParam`, the data <u>**will be stored and read in the private directory of the corresponding environment**</u>, and the data will be isolated from each other.
|
||||
|
||||
::: tip
|
||||
|
||||
For more functions, please refer to [YukiHookPrefsBridge](../public/com/highcapable/yukihookapi/hook/xposed/prefs/YukiHookPrefsBridge).
|
||||
|
||||
:::
|
@@ -218,6 +218,6 @@ For configuration details related to use as a Hook API, you can [click here](../
|
||||
|
||||
::: warning
|
||||
|
||||
**YukiHookModulePrefs**, **YukiHookDataChannel** and Resources Hook functionality will not work when using a custom Hook Framework instead of the full Xposed Module.
|
||||
**YukiHookPrefsBridge**, **YukiHookDataChannel** and Resources Hook functionality will not work when using a custom Hook Framework instead of the full Xposed Module.
|
||||
|
||||
:::
|
@@ -6,7 +6,7 @@
|
||||
|
||||
> 这里收录了 `YukiHookAPI` 尚未解决的问题。
|
||||
|
||||
### YukiHookModulePrefs
|
||||
### YukiHookPrefsBridge
|
||||
|
||||
目前仅限完美支持 LSPosed,其它 Xposed 框架需要降级模块 API。
|
||||
|
||||
|
@@ -396,23 +396,33 @@ var isDebug: Boolean
|
||||
|
||||
请转移到 `YukiHookLogger.Configs.isEnable`
|
||||
|
||||
### isEnableModulePrefsCache <span class="symbol">- field</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
var isEnableModulePrefsCache: Boolean
|
||||
```
|
||||
<h3 class="deprecated">isEnableModulePrefsCache - field</h3>
|
||||
|
||||
**变更记录**
|
||||
|
||||
`v1.0.5` `新增`
|
||||
|
||||
`v1.1.9` `作废`
|
||||
|
||||
请转移到 `isEnablePrefsBridgeCache`
|
||||
|
||||
### isEnablePrefsBridgeCache <span class="symbol">- field</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
var isEnablePrefsBridgeCache: Boolean
|
||||
```
|
||||
|
||||
**变更记录**
|
||||
|
||||
`v1.1.9` `新增`
|
||||
|
||||
**功能描述**
|
||||
|
||||
> 是否启用 `YukiHookModulePrefs` 的键值缓存功能。
|
||||
> 是否启用 `YukiHookPrefsBridge` 的键值缓存功能。
|
||||
|
||||
为防止内存复用过高问题,此功能默认启用。
|
||||
|
||||
你可以手动在 `YukiHookModulePrefs` 中自由开启和关闭缓存功能以及清除缓存。
|
||||
你可以手动在 `YukiHookPrefsBridge` 中自由开启和关闭缓存功能以及清除缓存。
|
||||
|
||||
### isEnableModuleAppResourcesCache <span class="symbol">- field</span>
|
||||
|
||||
@@ -480,7 +490,7 @@ var isEnableHookSharedPreferences: Boolean
|
||||
|
||||
这是一个可选的实验性功能,此功能默认不启用。
|
||||
|
||||
仅用于修复某些系统可能会出现在启用了 **New XSharedPreferences** 后依然出现文件权限错误问题,若你能正常使用 **YukiHookModulePrefs** 就不建议启用此功能。
|
||||
仅用于修复某些系统可能会出现在启用了 **New XSharedPreferences** 后依然出现文件权限错误问题,若你能正常使用 **YYukiHookPrefsBridge** 就不建议启用此功能。
|
||||
|
||||
:::
|
||||
|
||||
@@ -564,7 +574,7 @@ object HookEntry : IYukiHookXposedInit {
|
||||
elements(TAG, PRIORITY, PACKAGE_NAME, USER_ID)
|
||||
}
|
||||
isDebug = BuildConfig.DEBUG
|
||||
isEnableModulePrefsCache = true
|
||||
isEnablePrefsBridgeCache = true
|
||||
isEnableModuleAppResourcesCache = true
|
||||
isEnableHookModuleStatus = true
|
||||
isEnableHookSharedPreferences = false
|
||||
@@ -594,7 +604,7 @@ object HookEntry : IYukiHookXposedInit {
|
||||
elements(TAG, PRIORITY, PACKAGE_NAME, USER_ID)
|
||||
}
|
||||
isDebug = BuildConfig.DEBUG
|
||||
isEnableModulePrefsCache = true
|
||||
isEnablePrefsBridgeCache = true
|
||||
isEnableModuleAppResourcesCache = true
|
||||
isEnableHookModuleStatus = true
|
||||
isEnableHookSharedPreferences = false
|
||||
@@ -626,7 +636,7 @@ object HookEntry : IYukiHookXposedInit {
|
||||
YukiHookLogger.Configs.USER_ID
|
||||
)
|
||||
YukiHookAPI.Configs.isDebug = BuildConfig.DEBUG
|
||||
YukiHookAPI.Configs.isEnableModulePrefsCache = true
|
||||
YukiHookAPI.Configs.isEnablePrefsBridgeCache = true
|
||||
YukiHookAPI.Configs.isEnableModuleAppResourcesCache = true
|
||||
YukiHookAPI.Configs.isEnableHookModuleStatus = true
|
||||
YukiHookAPI.Configs.isEnableHookSharedPreferences = false
|
||||
|
@@ -56,33 +56,45 @@ fun IYukiHookXposedInit.encase(vararg hooker: YukiBaseHooker)
|
||||
|
||||
> 在 `IYukiHookXposedInit` 中调用 `YukiHookAPI`。
|
||||
|
||||
## Context.modulePrefs <span class="symbol">- ext-field</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
val Context.modulePrefs: YukiHookModulePrefs
|
||||
```
|
||||
<h2 class="deprecated">Context.modulePrefs - ext-field</h2>
|
||||
|
||||
**变更记录**
|
||||
|
||||
`v1.0` `添加`
|
||||
|
||||
**功能描述**
|
||||
`v1.1.9` `作废`
|
||||
|
||||
> 获取模块的存取对象。
|
||||
请转移到 `prefs` 方法
|
||||
|
||||
## Context.modulePrefs <span class="symbol">- ext-method</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
fun Context.modulePrefs(name: String): YukiHookModulePrefs
|
||||
```
|
||||
<h2 class="deprecated">Context.modulePrefs - ext-method</h2>
|
||||
|
||||
**变更记录**
|
||||
|
||||
`v1.0` `添加`
|
||||
|
||||
`v1.1.9` `作废`
|
||||
|
||||
请转移到 `prefs` 方法
|
||||
|
||||
## Context.prefs <span class="symbol">- ext-method</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
fun Context.prefs(name: String): YukiHookPrefsBridge
|
||||
```
|
||||
|
||||
**变更记录**
|
||||
|
||||
`v1.1.9` `新增`
|
||||
|
||||
**功能描述**
|
||||
|
||||
> 获取模块的存取对象,可设置 `name` 为自定义 Sp 存储名称。
|
||||
> 获取 `YukiHookPrefsBridge` 对象。
|
||||
|
||||
可以同时在模块与 (Xposed) 宿主环境中使用。
|
||||
|
||||
如果你想在 (Xposed) 宿主环境将数据存入当前宿主的私有空间,请使用 `YukiHookPrefsBridge.native` 方法。
|
||||
|
||||
在未声明任何条件的情况下 (Xposed) 宿主环境默认读取模块中的数据。
|
||||
|
||||
## Context.dataChannel <span class="symbol">- ext-method</span>
|
||||
|
||||
|
@@ -235,7 +235,7 @@ val moduleAppResources: YukiModuleResources
|
||||
## prefs <span class="symbol">- field</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
val prefs: YukiHookModulePrefs
|
||||
val prefs: YukiHookPrefsBridge
|
||||
```
|
||||
|
||||
**变更记录**
|
||||
@@ -255,7 +255,7 @@ val prefs: YukiHookModulePrefs
|
||||
## prefs <span class="symbol">- method</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
fun prefs(name: String): YukiHookModulePrefs
|
||||
fun prefs(name: String): YukiHookPrefsBridge
|
||||
```
|
||||
|
||||
**变更记录**
|
||||
|
@@ -2,25 +2,29 @@
|
||||
pageClass: code-page
|
||||
---
|
||||
|
||||
# YukiHookModulePrefs <span class="symbol">- class</span>
|
||||
# YukiHookPrefsBridge <span class="symbol">- class</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
class YukiHookModulePrefs private constructor(private var context: Context?)
|
||||
class YukiHookPrefsBridge private constructor(private var context: Context?)
|
||||
```
|
||||
|
||||
**变更记录**
|
||||
|
||||
`v1.0` `添加`
|
||||
|
||||
`v1.1.9` `修改`
|
||||
|
||||
~~`YukiHookModulePrefs`~~ 更名为 `YukiHookPrefsBridge`
|
||||
|
||||
**功能描述**
|
||||
|
||||
> 实现 Xposed 模块的数据存取,对接 `SharedPreferences` 和 `XSharedPreferences`。
|
||||
> `YukiHookAPI` 对 `SharedPreferences`、`XSharedPreferences` 的扩展存储桥实现。
|
||||
|
||||
在不同环境智能选择存取使用的对象。
|
||||
|
||||
::: danger
|
||||
|
||||
此功能为实验性功能,仅在 LSPosed 环境测试通过,EdXposed 理论也可以使用但不再推荐。
|
||||
模块与宿主之前共享数据存储为实验性功能,仅在 LSPosed 环境测试通过,EdXposed 理论也可以使用但不再推荐。
|
||||
|
||||
:::
|
||||
|
||||
@@ -34,13 +38,7 @@ class YukiHookModulePrefs private constructor(private var context: Context?)
|
||||
|
||||
太极请参阅 [文件权限/配置/XSharedPreference](https://taichi.cool/zh/doc/for-xposed-dev.html#文件权限-配置-xsharedpreference)。
|
||||
|
||||
::: danger
|
||||
|
||||
当你在 Xposed 模块中存取数据的时候 **context** 必须不能是空的。
|
||||
|
||||
:::
|
||||
|
||||
若你正在使用 `PreferenceFragmentCompat`,请迁移到 `ModulePreferenceFragment` 以适配上述功能特性。
|
||||
对于在模块环境中使用 `PreferenceFragmentCompat`,`YukiHookAPI` 提供了 `ModulePreferenceFragment` 来实现同样的功能。
|
||||
|
||||
**可选配置**
|
||||
|
||||
@@ -88,7 +86,7 @@ val isPreferencesAvailable: Boolean
|
||||
|
||||
**功能描述**
|
||||
|
||||
> 获取当前 `YukiHookModulePrefs` 的可用状态。
|
||||
> 获取当前 `YukiHookPrefsBridge` 的可用状态。
|
||||
|
||||
在 (Xposed) 宿主环境中返回 `XSharedPreferences` 可用状态 (可读)。
|
||||
|
||||
@@ -97,7 +95,7 @@ val isPreferencesAvailable: Boolean
|
||||
## name <span class="symbol">- method</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
fun name(name: String): YukiHookModulePrefs
|
||||
fun name(name: String): YukiHookPrefsBridge
|
||||
```
|
||||
|
||||
**变更记录**
|
||||
@@ -115,7 +113,7 @@ fun name(name: String): YukiHookModulePrefs
|
||||
> 示例如下
|
||||
|
||||
```kotlin
|
||||
modulePrefs("custom_name").getString("custom_key")
|
||||
prefs("custom_name").getString("custom_key")
|
||||
```
|
||||
|
||||
在 (Xposed) 宿主环境 `PackageParam` 中的使用方法。
|
||||
@@ -129,7 +127,7 @@ prefs("custom_name").getString("custom_key")
|
||||
## direct <span class="symbol">- method</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
fun direct(): YukiHookModulePrefs
|
||||
fun direct(): YukiHookPrefsBridge
|
||||
```
|
||||
|
||||
**变更记录**
|
||||
@@ -140,10 +138,24 @@ fun direct(): YukiHookModulePrefs
|
||||
|
||||
> 忽略缓存直接读取键值。
|
||||
|
||||
无论是否开启 `YukiHookAPI.Configs.isEnableModulePrefsCache`。
|
||||
无论是否开启 `YukiHookAPI.Configs.isEnablePrefsBridgeCache`。
|
||||
|
||||
仅在 `XSharedPreferences` 下生效。
|
||||
|
||||
## native <span class="symbol">- method</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
fun native(): YukiHookPrefsBridge
|
||||
```
|
||||
|
||||
**变更记录**
|
||||
|
||||
`v1.1.9` `新增`
|
||||
|
||||
**功能描述**
|
||||
|
||||
> 忽略当前环境直接使用 `Context.getSharedPreferences` 存取数据。
|
||||
|
||||
## getString <span class="symbol">- method</span>
|
||||
|
||||
```kotlin:no-line-numbers
|
||||
@@ -426,7 +438,7 @@ fun clearCache()
|
||||
|
||||
> 清除 `XSharedPreferences` 中缓存的键值数据。
|
||||
|
||||
无论是否开启 `YukiHookAPI.Configs.isEnableModulePrefsCache`。
|
||||
无论是否开启 `YukiHookAPI.Configs.isEnablePrefsBridgeCache`。
|
||||
|
||||
调用此方法将清除当前存储的全部键值缓存。
|
||||
|
||||
@@ -446,7 +458,7 @@ inner class Editor internal constructor()
|
||||
|
||||
**功能描述**
|
||||
|
||||
> `YukiHookModulePrefs` 的存储代理类。
|
||||
> `YukiHookPrefsBridge` 的存储代理类。
|
||||
|
||||
请使用 `edit` 方法来获取 `Editor`。
|
||||
|
@@ -20,7 +20,7 @@ data class PrefsData<T>(var key: String, var value: T) : Serializable
|
||||
|
||||
> 键值对存储构造类。
|
||||
|
||||
这个类是对 `YukiHookModulePrefs` 的一个扩展用法。
|
||||
这个类是对 `YukiHookPrefsBridge` 的一个扩展用法。
|
||||
|
||||
**功能示例**
|
||||
|
||||
@@ -43,9 +43,9 @@ object DataConst {
|
||||
|
||||
```kotlin
|
||||
// 读取
|
||||
val data = modulePrefs.get(DataConst.TEST_KV_DATA_1)
|
||||
val data = prefs().get(DataConst.TEST_KV_DATA_1)
|
||||
// 写入
|
||||
modulePrefs.put(DataConst.TEST_KV_DATA_1, "written value")
|
||||
prefs().edit { put(DataConst.TEST_KV_DATA_1, "written value") }
|
||||
```
|
||||
|
||||
> 宿主示例如下
|
||||
|
@@ -8,7 +8,7 @@
|
||||
|
||||
## 在 Activity 中使用
|
||||
|
||||
> 这里描述了在 `Activity` 中装载 `YukiHookModulePrefs` 的场景。
|
||||
> 这里描述了在 `Activity` 中装载 `YukiHookPrefsBridge` 的场景。
|
||||
|
||||
通常情况下我们可以这样在 Hook APP (宿主) 内对其进行初始化。
|
||||
|
||||
@@ -25,7 +25,7 @@ XSharedPreferences(BuildConfig.APPLICATION_ID)
|
||||
> 示例如下
|
||||
|
||||
```kotlin
|
||||
modulePrefs.putString("test_name", "saved_value")
|
||||
prefs().edit { putString("test_name", "saved_value") }
|
||||
```
|
||||
|
||||
当你在 Hook APP (宿主) 中读取数据时,可以使用如下方法。
|
||||
@@ -36,7 +36,7 @@ modulePrefs.putString("test_name", "saved_value")
|
||||
val testName = prefs.getString("test_name", "default_value")
|
||||
```
|
||||
|
||||
你不需要考虑传入模块的包名以及一系列复杂的权限配置,一切都交给 `YukiHookModulePrefs` 来处理。
|
||||
你不需要考虑传入模块的包名以及一系列复杂的权限配置,一切都交给 `YukiHookPrefsBridge` 来处理。
|
||||
|
||||
若要实现存储的区域划分,你可以指定每个 `prefs` 文件的名称。
|
||||
|
||||
@@ -46,9 +46,9 @@ val testName = prefs.getString("test_name", "default_value")
|
||||
|
||||
```kotlin
|
||||
// 推荐用法
|
||||
modulePrefs("specify_file_name").putString("test_name", "saved_value")
|
||||
prefs("specify_file_name").edit { putString("test_name", "saved_value") }
|
||||
// 也可以这样用
|
||||
modulePrefs.name("specify_file_name").putString("test_name", "saved_value")
|
||||
prefs().name("specify_file_name").edit { putString("test_name", "saved_value") }
|
||||
```
|
||||
|
||||
在 Hook APP (宿主) 中这样读取。
|
||||
@@ -64,21 +64,40 @@ val testName = prefs.name("specify_file_name").getString("test_name", "default_v
|
||||
|
||||
若你的项目中有大量的固定数据需要存储和读取,推荐使用 `PrefsData` 来创建模板。
|
||||
|
||||
通过上面的示例,你可以调用 `edit` 方法使用以下两种方式来批量存储数据。
|
||||
|
||||
> 示例如下
|
||||
|
||||
```kotlin
|
||||
// <方案 1>
|
||||
prefs().edit {
|
||||
putString("test_name_1", "saved_value_1")
|
||||
putString("test_name_2", "saved_value_2")
|
||||
putString("test_name_3", "saved_value_3")
|
||||
}
|
||||
// <方案 2>
|
||||
prefs().edit()
|
||||
.putString("test_name_1", "saved_value_1")
|
||||
.putString("test_name_2", "saved_value_2")
|
||||
.putString("test_name_3", "saved_value_3")
|
||||
.apply()
|
||||
```
|
||||
|
||||
::: tip
|
||||
|
||||
更多功能请参考 [YukiHookModulePrefs](../public/com/highcapable/yukihookapi/hook/xposed/prefs/YukiHookModulePrefs)、[PrefsData](../public/com/highcapable/yukihookapi/hook/xposed/prefs/data/PrefsData)。
|
||||
更多功能请参考 [YukiHookPrefsBridge](../public/com/highcapable/yukihookapi/hook/xposed/prefs/YukiHookPrefsBridge)、[PrefsData](../public/com/highcapable/yukihookapi/hook/xposed/prefs/data/PrefsData)。
|
||||
|
||||
:::
|
||||
|
||||
## 在 PreferenceFragment 中使用
|
||||
|
||||
> 这里描述了在 `PreferenceFragment` 中装载 `YukiHookModulePrefs` 的场景。
|
||||
> 这里描述了在 `PreferenceFragment` 中装载 `YukiHookPrefsBridge` 的场景。
|
||||
|
||||
若你的模块使用了 `PreferenceFragmentCompat`,你现在可以将其继承类开始迁移到 `ModulePreferenceFragment`。
|
||||
|
||||
::: danger
|
||||
|
||||
你必须继承 **ModulePreferenceFragment** 才能实现 **YukiHookModulePrefs** 的模块存储功能。
|
||||
你必须继承 **ModulePreferenceFragment** 才能实现 **YukiHookPrefsBridge** 的模块存储功能。
|
||||
|
||||
:::
|
||||
|
||||
@@ -86,4 +105,50 @@ val testName = prefs.name("specify_file_name").getString("test_name", "default_v
|
||||
|
||||
更多功能请参考 [ModulePreferenceFragment](../public/com/highcapable/yukihookapi/hook/xposed/prefs/ui/ModulePreferenceFragment)。
|
||||
|
||||
:::
|
||||
|
||||
## 使用原生方式存储
|
||||
|
||||
在模块环境中 `YukiHookPrefsBridge` 默认会将数据存储到模块自己的私有目录 (或 Hook Framework 提供的共享目录) 中。
|
||||
|
||||
在宿主环境中使用 `YukiHookPrefsBridge` 默认会读取模块自己的私有目录 (或 Hook Framework 提供的共享目录) 中的数据。
|
||||
|
||||
如果你想直接将数据存储到模块或宿主当前环境自身的私有目录,你可以使用 `native` 方法。
|
||||
|
||||
例如模块的目录是 `.../com.demo.test.module/shared_prefs`,宿主的目录是 `.../com.demo.test.host/shared_prefs`。
|
||||
|
||||
以下是在 `Activity` 中的用法。
|
||||
|
||||
> 示例如下
|
||||
|
||||
```kotlin
|
||||
// 存储私有数据
|
||||
prefs().native().edit { putBoolean("isolation_data", true) }
|
||||
// 读取私有数据
|
||||
val privateData = prefs().native().getBoolean("isolation_data")
|
||||
// 存储共享数据
|
||||
prefs().edit { putBoolean("public_data", true) }
|
||||
// 读取共享数据
|
||||
val publicData = prefs().getBoolean("public_data")
|
||||
```
|
||||
|
||||
以下是在 `PackageParam` 中的用法。
|
||||
|
||||
> 示例如下
|
||||
|
||||
```kotlin
|
||||
// 存储私有数据
|
||||
prefs.native().edit { putBoolean("isolation_data", true) }
|
||||
// 读取私有数据
|
||||
val privateData = prefs.native().getBoolean("isolation_data")
|
||||
// 读取共享数据
|
||||
val publicData = prefs.getBoolean("public_data")
|
||||
```
|
||||
|
||||
使用 `native` 方法后,无论在 `Activity` 还是 `PackageParam` 中都会将数据<u>**在对应环境的私有目录中**</u>存储、读取,数据相互隔离。
|
||||
|
||||
::: tip
|
||||
|
||||
更多功能请参考 [YukiHookPrefsBridge](../public/com/highcapable/yukihookapi/hook/xposed/prefs/YukiHookPrefsBridge)。
|
||||
|
||||
:::
|
@@ -215,6 +215,6 @@ override fun attachBaseContext(base: Context?) {
|
||||
|
||||
::: warning
|
||||
|
||||
使用自定义的 Hook Framework 而并非完整的 Xposed 模块时,**YukiHookModulePrefs**、**YukiHookDataChannel** 以及 Resources Hook 功能将失效。
|
||||
使用自定义的 Hook Framework 而并非完整的 Xposed 模块时,**YukiHookPrefsBridge**、**YukiHookDataChannel** 以及 Resources Hook 功能将失效。
|
||||
|
||||
:::
|
Reference in New Issue
Block a user