Files
YukiHookAPI/assets/xposed-storage.html-DYzzLHun.js
github-actions[bot] aac9e42e84 Deploy to GitHub pages
2025-08-02 18:17:09 +00:00

39 lines
19 KiB
JavaScript

import{_ as s,o as e,c as a,a as n}from"./app-BpUB8-Q8.js";const o={},l=n(`<h1 id="xposed-module-data-storage" tabindex="-1"><a class="header-anchor" href="#xposed-module-data-storage" aria-hidden="true">#</a> Xposed Module Data Storage</h1><blockquote><p>This is an efficient Module App data storage solution that automatically connects <code>SharedPreferences</code> and <code>XSharedPreferences</code>.</p></blockquote><p>We need to store the data of the Module App for the Host App to call.</p><p>At this time, we will encounter the data exchange obstacle of the native <code>Sp</code> storage.</p><p>The native <code>Xposed</code> provides us with a <code>XSharedPreferences</code> for reading the <code>Sp</code> data of the Module App.</p><h2 id="use-in-activity" tabindex="-1"><a class="header-anchor" href="#use-in-activity" aria-hidden="true">#</a> Use in Activity</h2><blockquote><p>Loading <code>YukiHookPrefsBridge</code> in <code>Activity</code> is described here.</p></blockquote><p>Usually we can initialize it in Host App like this.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#DCBDFB;">XSharedPreferences</span><span style="color:#ADBAC7;">(BuildConfig.APPLICATION_ID)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Is there a convenient and quick solution?</p><p>At this point, you can use the extension capability of <code>YukiHookAPI</code> to quickly implement this function.</p><p>When you store data in a Module App, you can use the following methods if you are currently in an <code>Activity</code>.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#DCBDFB;">prefs</span><span style="color:#ADBAC7;">().</span><span style="color:#DCBDFB;">edit</span><span style="color:#ADBAC7;"> { </span><span style="color:#DCBDFB;">putString</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;test_name&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;saved_value&quot;</span><span style="color:#ADBAC7;">) }</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>When you read data in a Host App, you can use the following methods.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> testName </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> prefs.</span><span style="color:#DCBDFB;">getString</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;test_name&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;default_value&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>You don&#39;t need to consider the module package name and a series of complicated permission configurations, everything is handled by <code>YukiHookPrefsBridge</code>.</p><p>To achieve localization of storage, you can specify the name of each <code>prefs</code> file.</p><p>This is used in the <code>Activity</code> of the Module App.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Recommended usage</span></span>
<span class="line"><span style="color:#DCBDFB;">prefs</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;specify_file_name&quot;</span><span style="color:#ADBAC7;">).</span><span style="color:#DCBDFB;">edit</span><span style="color:#ADBAC7;"> { </span><span style="color:#DCBDFB;">putString</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;test_name&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;saved_value&quot;</span><span style="color:#ADBAC7;">) }</span></span>
<span class="line"><span style="color:#768390;">// Can also be used like this</span></span>
<span class="line"><span style="color:#DCBDFB;">prefs</span><span style="color:#ADBAC7;">().</span><span style="color:#DCBDFB;">name</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;specify_file_name&quot;</span><span style="color:#ADBAC7;">).</span><span style="color:#DCBDFB;">edit</span><span style="color:#ADBAC7;"> { </span><span style="color:#DCBDFB;">putString</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;test_name&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;saved_value&quot;</span><span style="color:#ADBAC7;">) }</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Read like this in Host App.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Recommended usage</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> testName </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">prefs</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;specify_file_name&quot;</span><span style="color:#ADBAC7;">).</span><span style="color:#DCBDFB;">getString</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;test_name&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;default_value&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#768390;">// Can also be used like this</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> testName </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> prefs.</span><span style="color:#DCBDFB;">name</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;specify_file_name&quot;</span><span style="color:#ADBAC7;">).</span><span style="color:#DCBDFB;">getString</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;test_name&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;default_value&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>If your project has a lot of fixed data that needs to be stored and read, it is recommended to use <code>PrefsData</code> to create templates.</p><p>Through the above example, you can call the <code>edit</code> method to store data in batches in the following two ways.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// &lt;Scenario 1&gt;</span></span>
<span class="line"><span style="color:#DCBDFB;">prefs</span><span style="color:#ADBAC7;">().</span><span style="color:#DCBDFB;">edit</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">putString</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;test_name_1&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;saved_value_1&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">putString</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;test_name_2&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;saved_value_2&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">putString</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;test_name_3&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;saved_value_3&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"><span style="color:#768390;">// &lt;Scenario 2&gt;</span></span>
<span class="line"><span style="color:#DCBDFB;">prefs</span><span style="color:#ADBAC7;">(). </span><span style="color:#DCBDFB;">edit</span><span style="color:#ADBAC7;">()</span></span>
<span class="line"><span style="color:#ADBAC7;"> .</span><span style="color:#DCBDFB;">putString</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;test_name_1&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;saved_value_1&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;"> .</span><span style="color:#DCBDFB;">putString</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;test_name_2&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;saved_value_2&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;"> .</span><span style="color:#DCBDFB;">putString</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;test_name_3&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#96D0FF;">&quot;saved_value_3&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;"> .</span><span style="color:#DCBDFB;">apply</span><span style="color:#ADBAC7;">()</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to <a href="../public/com/highcapable/yukihookapi/hook/xposed/prefs/YukiHookPrefsBridge">YukiHookPrefsBridge</a>, <a href="../public/com/highcapable/yukihookapi/hook/xposed/prefs/data/PrefsData">PrefsData</a>.</p></div><h2 id="use-in-preferencefragment" tabindex="-1"><a class="header-anchor" href="#use-in-preferencefragment" aria-hidden="true">#</a> Use in PreferenceFragment</h2><blockquote><p>Loading <code>YukiHookPrefsBridge</code> in <code>PreferenceFragment</code> is described here.</p></blockquote><p>If your Module App uses <code>PreferenceFragmentCompat</code>, you can now start migrating its extends <code>ModulePreferenceFragment</code>.</p><div class="custom-container danger"><p class="custom-container-title">Pay Attention</p><p>You must extends <strong>ModulePreferenceFragment</strong> to implement the module storage function of <strong>YukiHookPrefsBridge</strong>.</p></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to <a href="../public/com/highcapable/yukihookapi/hook/xposed/prefs/ui/ModulePreferenceFragment">ModulePreferenceFragment</a>.</p></div><h2 id="use-native-storage" tabindex="-1"><a class="header-anchor" href="#use-native-storage" aria-hidden="true">#</a> Use Native Storage</h2><p>In the Module environment, <code>YukiHookPrefsBridge</code> will store data in the Module App&#39;s own private directory (or the shared directory provided by Hook Framework) by default.</p><p>Using <code>YukiHookPrefsBridge</code> in the Host environment will read the data in the Module App&#39;s own private directory (or the shared directory provided by Hook Framework) by default.</p><p>If you want to store data directly into a Module App or Host App&#39;s own private directory, you can use the <code>native</code> method.</p><p>For example, the directory of the Module App is <code>.../com.demo.test.module/shared_prefs</code>, and the directory of the Host App is <code>.../com.demo.test.host/shared_prefs</code>.</p><p>The following is the usage in <code>Activity</code>.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Store private data</span></span>
<span class="line"><span style="color:#DCBDFB;">prefs</span><span style="color:#ADBAC7;">().</span><span style="color:#DCBDFB;">native</span><span style="color:#ADBAC7;">().</span><span style="color:#DCBDFB;">edit</span><span style="color:#ADBAC7;"> { </span><span style="color:#DCBDFB;">putBoolean</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;isolation_data&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#6CB6FF;">true</span><span style="color:#ADBAC7;">) }</span></span>
<span class="line"><span style="color:#768390;">// Read private data</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> privateData </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">prefs</span><span style="color:#ADBAC7;">().</span><span style="color:#DCBDFB;">native</span><span style="color:#ADBAC7;">().</span><span style="color:#DCBDFB;">getBoolean</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;isolation_data&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#768390;">// Store shared data</span></span>
<span class="line"><span style="color:#DCBDFB;">prefs</span><span style="color:#ADBAC7;">().</span><span style="color:#DCBDFB;">edit</span><span style="color:#ADBAC7;"> { </span><span style="color:#DCBDFB;">putBoolean</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;public_data&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#6CB6FF;">true</span><span style="color:#ADBAC7;">) }</span></span>
<span class="line"><span style="color:#768390;">// Read shared data</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> publicData </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">prefs</span><span style="color:#ADBAC7;">().</span><span style="color:#DCBDFB;">getBoolean</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;public_data&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>The following is the usage in <code>PackageParam</code>.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#768390;">// Store private data</span></span>
<span class="line"><span style="color:#ADBAC7;">prefs.</span><span style="color:#DCBDFB;">native</span><span style="color:#ADBAC7;">().</span><span style="color:#DCBDFB;">edit</span><span style="color:#ADBAC7;"> { </span><span style="color:#DCBDFB;">putBoolean</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;isolation_data&quot;</span><span style="color:#ADBAC7;">, </span><span style="color:#6CB6FF;">true</span><span style="color:#ADBAC7;">) }</span></span>
<span class="line"><span style="color:#768390;">// Read private data</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> privateData </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> prefs.</span><span style="color:#DCBDFB;">native</span><span style="color:#ADBAC7;">().</span><span style="color:#DCBDFB;">getBoolean</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;isolation_data&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#768390;">// Read shared data</span></span>
<span class="line"><span style="color:#F47067;">val</span><span style="color:#ADBAC7;"> publicData </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> prefs.</span><span style="color:#DCBDFB;">getBoolean</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;public_data&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>After using the <code>native</code> method, no matter in <code>Activity</code> or <code>PackageParam</code>, the data <u><strong>will be stored and read in the private directory of the corresponding environment</strong></u>, and the data will be isolated from each other.</p><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>For more functions, please refer to <a href="../public/com/highcapable/yukihookapi/hook/xposed/prefs/YukiHookPrefsBridge">YukiHookPrefsBridge</a>.</p></div>`,49),t=[l];function p(r,c){return e(),a("div",null,t)}const d=s(o,[["render",p],["__file","xposed-storage.html.vue"]]);export{d as default};