1

我尝试从https://github.com/LineageOS/android_packages_apps_Jelly/blob/lineage-16.0/app/src/main/res/values/search_engines.xml覆盖两个 XML 字符串 [] 内容:

<?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>

to:(照顾鸭鸭)

<?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$000(XposedInit.java:61)
09-27 21:00:45.304 23339 23339 E EdXposed-Bridge:   at de.robv.android.xposed.XposedInit$2.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.access$1100(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 浏览器。

但是上面的错误总是抛出,果冻浏览器可以工作,但不知道 Ecosia。

我错了什么?

4

1 回答 1

1

XML 资源文件中的资源类型显示为<string-array>,并且 Xposed API 文档也知道该类型String Array。但是,文档不清楚哪些具体值可以接受type

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

type 类型名称,例如字符串。请参阅 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}"});            
于 2019-09-28T13:33:09.633 回答