简体   繁体   中英

(Ed)Xposed Ressource override failing

I try to override two XML string[] things from https://github.com/LineageOS/android_packages_apps_Jelly/blob/lineage-16.0/app/src/main/res/values/search_engines.xml from:

<?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: (look after 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>

My code:

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 {
    }
}

The error:

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)

I tried to override the values from the search_engines.xml to add Ecosia to the Jelly Browser.

But always the error above throws and the Jelly Browser works but has no idea about Ecosia.

What do I wrong?

The resource type in the XML resource files is shown as <string-array> and also the Xposed API documentation knowns the type String Array . However the documentation is not clear what concrete values are acceptable for type :

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

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

Tracing back the path through the AOSP sources what values can be returned by Resources.getResourceTypeName(int) and therefore are a valid resource type name you end up in the file Resource.cpp and it's StringPiece to_string(ResourceType type) method. It contains all possible resource type names. At the moment therefore the following values are allowed:

"^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"

In your case you used "string-array" which would be consistent with the xml tag the resource was defined it. However as you can see this type is not a valid resource type name. The correct resource type therefore in your case is "array" .

Therefore you should change the type to "array" for the following two lines:

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}"});            

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM