(Edxposed 资源覆盖失败

(Ed)Xposed Ressource override failing

我尝试覆盖来自 https://github.com/LineageOS/android_packages_apps_Jelly/blob/lineage-16.0/app/src/main/res/values/search_engines.xml 的两个 XML string[] 东西​​,来自:

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2017 The LineageOS Project
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
     http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 -->
 <resources>

    <string-array name="pref_search_engine_entries" translatable="false">
        <item>Baidu</item>
        <item>Bing</item>
        <item>DuckDuckGo</item>
        <item>Google</item>
        <item>Google encrypted</item>
        <item>Yahoo</item>
        <item>Yandex</item>
    </string-array>

    <string-array name="pref_search_engine_entryvalues" translatable="false">
        <item>https://www.baidu.com/s?wd={searchTerms}</item>
        <item>https://www.bing.com/search?q={searchTerms}</item>
        <item>https://duckduckgo.com/?q={searchTerms}</item>
        <item>https://google.com/search?ie=UTF-8&amp;source=android-browser&amp;q={searchTerms}</item>
        <item>https://encrypted.google.com/search?q={searchTerms}</item>
        <item>https://search.yahoo.com/p={searchTerms}</item>
        <item>https://yandex.com/?q={searchTerms}</item>
    </string-array>
</resources>

致:(照顾duckduckgo)

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2017 The LineageOS Project
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
     http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 -->
 <resources>

    <string-array name="pref_search_engine_entries" translatable="false">
        <item>Baidu</item>
        <item>Bing</item>
        <item>DuckDuckGo</item>
        <item>Ecosia</item>
        <item>Google</item>
        <item>Google encrypted</item>
        <item>Yahoo</item>
        <item>Yandex</item>
    </string-array>

    <string-array name="pref_search_engine_entryvalues" translatable="false">
        <item>https://www.baidu.com/s?wd={searchTerms}</item>
        <item>https://www.bing.com/search?q={searchTerms}</item>
        <item>https://duckduckgo.com/?q={searchTerms}</item>
        <item>https://www.ecosia.org/search?q={searchTerms}
        <item>https://google.com/search?ie=UTF-8&amp;source=android-browser&amp;q={searchTerms}</item>
        <item>https://encrypted.google.com/search?q={searchTerms}</item>
        <item>https://search.yahoo.com/p={searchTerms}</item>
        <item>https://yandex.com/?q={searchTerms}</item>
    </string-array>
</resources>

我的代码:

package org.nift4.xposed.misc;

import de.robv.android.xposed.IXposedHookInitPackageResources;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.callbacks.XC_InitPackageResources.InitPackageResourcesParam;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;

import static de.robv.android.xposed.XposedHelpers.*;
import de.robv.android.xposed.XposedBridge;

public class Main implements IXposedHookLoadPackage, IXposedHookInitPackageResources
{

    @Override
    public void handleInitPackageResources(InitPackageResourcesParam resparam) throws Throwable
    {
        if (resparam.packageName.equals("org.lineageos.jelly")) {
            XposedBridge.log("found jelly '" + resparam.packageName + "'");
            resparam.res.setReplacement("org.lineageos.jelly", "string-array", "pref_search_engine_entries", new String[]{"Baidu", "Bing", "DuckDuckGo", "Ecosia", "Google", "Google encrypted", "Yahoo", "Yandex"});
            resparam.res.setReplacement("org.lineageos.jelly", "string-array", "pref_search_engine_entryvalues", new String[]{"https://www.baidu.com/s?wd={searchTerms}", "https://www.bing.com/search?q={searchTerms}", "https://duckduckgo.com/?q={searchTerms}", "https://www.ecosia.org/search?q={searchTerms}", "https://google.com/search?ie=UTF-8&amp;source=android-browser&amp;q={searchTerms}", "https://encrypted.google.com/search?q={searchTerms}", "https://search.yahoo.com/p={searchTerms}", "https://yandex.com/?q={searchTerms}"});
        }
        }

    @Override
    public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
    }
}

错误:

09-27 21:00:45.302 23339 23339 I EdXposed-Bridge: found jelly 'org.lineageos.jelly'
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge: android.content.res.Resources$NotFoundException: org.lineageos.jelly:string-array/pref_search_engine_entries
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at android.content.res.XResources.setReplacement(XResources.java:503)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at org.nift4.xposed.misc.Main.handleInitPackageResources(Main.java:19)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at de.robv.android.xposed.IXposedHookInitPackageResources$Wrapper.handleInitPackageResources(IXposedHookInitPackageResources.java:37)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at de.robv.android.xposed.callbacks.XC_InitPackageResources.call(XC_InitPackageResources.java:55)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at de.robv.android.xposed.callbacks.XCallback.callAll(XCallback.java:117)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at de.robv.android.xposed.XposedInit.cloneToXResources(XposedInit.java:288)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at de.robv.android.xposed.XposedInit.access[=13=]0(XposedInit.java:61)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at de.robv.android.xposed.XposedInit.afterHookedMethod(XposedInit.java:146)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at de.robv.android.xposed.XC_MethodHook.callAfterHookedMethod(XC_MethodHook.java:68)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at com.swift.sandhook.xposedcompat.hookstub.HookStubManager.hookBridge(HookStubManager.java:313)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at com.swift.sandhook.xposedcompat.hookstub.MethodHookerStubs64.stub_hook_0(MethodHookerStubs64.java:558)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at android.app.ResourcesManager.getResources(ResourcesManager.java:870)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at android.app.LoadedApk.getResources(LoadedApk.java:1029)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5798)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at java.lang.reflect.Method.invoke(Native Method)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at com.swift.sandhook.SandHook.callOriginMethod(SandHook.java:176)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at com.swift.sandhook.SandHook.callOriginMethod(SandHook.java:154)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at com.swift.sandhook.xposedcompat.hookstub.HookStubManager.hookBridge(HookStubManager.java:299)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at com.swift.sandhook.xposedcompat.hookstub.MethodHookerStubs64.stub_hook_0(MethodHookerStubs64.java:198)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at android.app.ActivityThread.access00(ActivityThread.java:200)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at android.os.Handler.dispatchMessage(Handler.java:106)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at android.os.Looper.loop(Looper.java:193)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at android.app.ActivityThread.main(ActivityThread.java:6718)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at java.lang.reflect.Method.invoke(Native Method)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

我试图覆盖 search_engines.xml 中的值以将 Ecosia 添加到 Jelly 浏览器。

但总是会抛出上述错误,Jelly 浏览器可以正常工作,但不知道 Ecosia。

我做错了什么?

XML 资源文件中的资源类型显示为 <string-array>,Xposed API 文档也知道类型 String Array。但是文档并不清楚 type:

可以接受哪些具体值

public void setReplacement (String pkg, String type, String name, Object replacement)

type The type name, e.g. string. See Resources.getResourceTypeName(int).

追溯通过 AOSP 源的路径,Resources.getResourceTypeName(int) 可以返回哪些值,因此是您最终在文件 Resource.cpp 中得到的有效资源类型名称,它是 StringPiece to_string(ResourceType type)方法。它包含所有可能的资源类型名称。因此,目前允许使用以下值:

"^attr-private"
"anim"
"animator"
"array"
"attr"
"bool"
"color"
"configVarying"
"dimen"
"drawable"
"font"
"fraction"
"id"
"integer"
"interpolator"
"layout"
"menu"
"mipmap"
"navigation"
"plurals"
"raw"
"string"
"style"
"styleable"
"transition"
"xml"

在您的情况下,您使用了 "string-array",这与定义资源的 xml 标签一致。但是,如您所见,此类型不是有效的资源类型名称。因此,在您的情况下,正确的资源类型是 "array".

因此您应该将以下两行的类型更改为 "array"

resparam.res.setReplacement("org.lineageos.jelly", "array", "pref_search_engine_entries", new String[]{"Baidu", "Bing", "DuckDuckGo", "Ecosia", "Google", "Google encrypted", "Yahoo", "Yandex"});
resparam.res.setReplacement("org.lineageos.jelly", "array", "pref_search_engine_entryvalues", new String[]{"https://www.baidu.com/s?wd={searchTerms}", "https://www.bing.com/search?q={searchTerms}", "https://duckduckgo.com/?q={searchTerms}", "https://www.ecosia.org/search?q={searchTerms}", "https://google.com/search?ie=UTF-8&amp;source=android-browser&amp;q={searchTerms}", "https://encrypted.google.com/search?q={searchTerms}", "https://search.yahoo.com/p={searchTerms}", "https://yandex.com/?q={searchTerms}"});