mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-07 19:14:08 +08:00
Modify change YukiHookModulePrefs name to YukiHookPrefsBridge and make it support native storage usage in YukiHookPrefsBridge
This commit is contained in:
@@ -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.
|
||||
|
||||
:::
|
Reference in New Issue
Block a user