mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 09:45:19 +08:00
63 lines
21 KiB
JavaScript
63 lines
21 KiB
JavaScript
import{_ as s,o as e,c as n,a}from"./app.99fcdd51.js";const l={},o=a(`<h1 id="xposed-module-and-host-channel" tabindex="-1"><a class="header-anchor" href="#xposed-module-and-host-channel" aria-hidden="true">#</a> Xposed Module and Host Channel</h1><blockquote><p>This is a solution that uses system out-of-order broadcasting to send and receive data between the Module App and the Host App.</p></blockquote><div class="custom-container danger"><p class="custom-container-title">Condition that needs to be met</p><p>The Module App and the Host App need to remain alive, otherwise communication cannot be established.</p></div><h2 id="basic-usage" tabindex="-1"><a class="header-anchor" href="#basic-usage" aria-hidden="true">#</a> Basic Usage</h2><blockquote><p>The basic usage of the <code>wait</code> and <code>put</code> methods is described here.</p></blockquote><p>By using <code>dataChannel</code> to realize the communication bridge between the Module App and the Host App, the principle is to send and receive system out-of-order broadcasts.</p><blockquote><p>The Module App example is as follows</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#768390;">// Get from the Host App of the specified package name</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">dataChannel(packageName </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"com.example.demo"</span><span style="color:#ADBAC7;">).wait</span><span style="color:#F47067;"><</span><span style="color:#6CB6FF;">String</span><span style="color:#F47067;">></span><span style="color:#ADBAC7;">(key </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"key_from_host"</span><span style="color:#ADBAC7;">) { value </span><span style="color:#F47067;">-></span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Your code here.</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">}</span></span>
|
|
<span class="line"><span style="color:#768390;">// Send to the Host App with the specified package name</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">dataChannel(packageName </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"com.example.demo"</span><span style="color:#ADBAC7;">).put(key </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"key_from_module"</span><span style="color:#ADBAC7;">, value </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"I am module"</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><blockquote><p>The Host App example is as follows</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#768390;">// Get from the Module App</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">dataChannel.wait</span><span style="color:#F47067;"><</span><span style="color:#6CB6FF;">String</span><span style="color:#F47067;">></span><span style="color:#ADBAC7;">(key </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"key_from_module"</span><span style="color:#ADBAC7;">) { value </span><span style="color:#F47067;">-></span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Your code here.</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">}</span></span>
|
|
<span class="line"><span style="color:#768390;">// Send to the Module App</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">dataChannel.put(key </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"key_from_host"</span><span style="color:#ADBAC7;">, value </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"I am host"</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>You can leave the <code>value</code> of <code>dataChannel</code> unset to only notify the Module App or Host App to call back the <code>wait</code> method.</p><blockquote><p>The Module App example is as follows</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#768390;">// Get from the Host App of the specified package name</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">dataChannel(packageName </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"com.example.demo"</span><span style="color:#ADBAC7;">).wait(key </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"listener_from_host"</span><span style="color:#ADBAC7;">) {</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Your code here.</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">}</span></span>
|
|
<span class="line"><span style="color:#768390;">// Send to the Host App with the specified package name</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">dataChannel(packageName </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"com.example.demo"</span><span style="color:#ADBAC7;">).put(key </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"listener_from_module"</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><blockquote><p>The Host App example is as follows</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#768390;">// Get from the Module App</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">dataChannel.wait(key </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"listener_from_module"</span><span style="color:#ADBAC7;">) {</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Your code here.</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">}</span></span>
|
|
<span class="line"><span style="color:#768390;">// Send to the Module App</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">dataChannel.put(key </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"listener_from_host"</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><div class="custom-container danger"><p class="custom-container-title">Pay Attention</p><p>The receiver needs to stay alive to receive the communication data.</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/channel/YukiHookDataChannel">YukiHookDataChannel</a>.</p></div><h2 id="determine-module-app-and-host-app-version-match" tabindex="-1"><a class="header-anchor" href="#determine-module-app-and-host-app-version-match" aria-hidden="true">#</a> Determine Module App and Host App Version Match</h2><blockquote><p>Through the communication bridge function, <code>YukiHookAPI</code> also provides a solution for you to determine whether the Module App matches the Host App version after the user updates the Module App.</p></blockquote><p>We only need to call the <code>checkingVersionEquals</code> method to achieve this function.</p><p>Bidirectional judgment can be performed between the Module App and the Host App.</p><p>You can check in the Module App whether the Host App of the specified package name matches the version of the current Module App.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#768390;">// Get from the Host App of the specified package name</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">dataChannel(packageName </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"com.example.demo"</span><span style="color:#ADBAC7;">).checkingVersionEquals { isEquals </span><span style="color:#F47067;">-></span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Your code here.</span></span>
|
|
<span class="line"><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>You can also determine in the Host App whether it matches the current Module App version.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#768390;">// Get from the Module App</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">dataChannel.checkingVersionEquals { isEquals </span><span style="color:#F47067;">-></span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Your code here.</span></span>
|
|
<span class="line"><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><div class="custom-container warning"><p class="custom-container-title">Condition of method callback</p><p>The Host App and Module App must be stay alive, and after activating the Module App restart the Hook target Host App object in scope.</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/channel/YukiHookDataChannel">YukiHookDataChannel</a>.</p></div><h2 id="rules-for-callback-event-response" tabindex="-1"><a class="header-anchor" href="#rules-for-callback-event-response" aria-hidden="true">#</a> Rules for Callback Event Response</h2><p>Only examples used in Module App are listed here, the same <code>key</code> in the Host App is always not allowed to be created repeatedly.</p><div class="custom-container danger"><p class="custom-container-title">Pay Attention</p><p>In the Module App and Host App, each <strong>key</strong> callback event corresponding to <strong>dataChannel</strong> is not allowed to be repeatedly created, if repeated, the previous callback event will be replaced by the newly added callback event.</p><p>When used in the Module App, it cannot be repeated in the same <strong>Activity</strong>, and the same <strong>key</strong> in different <strong>Activity</strong> is allowed to be repeated.</p></div><blockquote><p>The following example</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#F47067;">class</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">MainActivity</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">AppCompatActivity</span><span style="color:#ADBAC7;">() {</span></span>
|
|
<span class="line"></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">override</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">fun</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">onCreate</span><span style="color:#ADBAC7;">(savedInstanceState</span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">Bundle?</span><span style="color:#ADBAC7;">) {</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">super</span><span style="color:#ADBAC7;">.onCreate(savedInstanceState)</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Callback event A</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> dataChannel(packageName </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"com.example.demo"</span><span style="color:#ADBAC7;">).wait(key </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"test_key"</span><span style="color:#ADBAC7;">) {</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Your code here.</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> }</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Callback event B</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> dataChannel(packageName </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"com.example.demo"</span><span style="color:#ADBAC7;">).wait(key </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"test_key"</span><span style="color:#ADBAC7;">) {</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Your code here.</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> }</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Callback event C</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> dataChannel(packageName </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"com.example.demo"</span><span style="color:#ADBAC7;">).wait(key </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"other_test_key"</span><span style="color:#ADBAC7;">) {</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Your code here.</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> }</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> }</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;">}</span></span>
|
|
<span class="line"></span>
|
|
<span class="line"><span style="color:#F47067;">class</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">OtherActivity</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">AppCompatActivity</span><span style="color:#ADBAC7;">() {</span></span>
|
|
<span class="line"></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">override</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">fun</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">onCreate</span><span style="color:#ADBAC7;">(savedInstanceState</span><span style="color:#F47067;">:</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">Bundle?</span><span style="color:#ADBAC7;">) {</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">super</span><span style="color:#ADBAC7;">.onCreate(savedInstanceState)</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Callback event D</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> dataChannel(packageName </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"com.example.demo"</span><span style="color:#ADBAC7;">).wait(key </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"test_key"</span><span style="color:#ADBAC7;">) {</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#768390;">// Your code here.</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> }</span></span>
|
|
<span class="line"><span style="color:#ADBAC7;"> }</span></span>
|
|
<span class="line"><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 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 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>In the above example, the callback event A will be replaced by the callback event B, the <code>key</code> of the callback event C is not repeated with others, and the callback event D is in another Activity, So the final callback events B, C, and D can all be created successfully.</p><div class="custom-container danger"><p class="custom-container-title">Pay Attention</p><p>A callback event with the same <strong>key</strong> will only call back the callback event registered in the <strong>Activity</strong> that the current Module App is displaying, such as <strong>test_key</strong> in the above, if <strong>OtherActivity</strong> is being displayed, then <strong>test_key</strong> in <strong>MainActivity</strong> will not be called back.</p><p>The same <strong>key</strong> registers <strong>dataChannel</strong> in the same <strong>Activity</strong> but different <strong>Fragment</strong>, they will still be called back in the current <strong>Activity</strong> at the same time.</p><p>In a Module App, you can only use <strong>Context</strong> of <strong>Activity</strong> to register <strong>dataChannel</strong>, you cannot use <strong>dataChannel</strong> in <strong>Application</strong> and <strong>Service</strong>.</p><p>If you want to use <strong>dataChannel</strong> in <strong>Fragment</strong>, use <strong>activity?.dataChannel(...)</strong>.</p></div><h2 id="security-instructions" tabindex="-1"><a class="header-anchor" href="#security-instructions" aria-hidden="true">#</a> Security Instructions</h2><p>In the Module environment, you can only receive communication data sent by <u><strong>the Host App with the specified package name</strong></u> and only send it to <u><strong>the Host App with the specified package name</strong></u>.</p><div class="custom-container danger"><p class="custom-container-title">Pay Attention</p><p>In order to further prevent broadcast abuse, the API in the communication data will automatically specify the package name of the Host App and Module App to prevent other apps from monitoring and using broadcast to make overrun behaviors.</p></div>`,39),t=[o];function p(c,i){return e(),n("div",null,t)}const d=s(l,[["render",p],["__file","xposed-channel.html.vue"]]);export{d as default};
|