(Ed) Xposed Ressource не удалось переопределить - PullRequest
1 голос
/ 27 сентября 2019

Я пытаюсь переопределить две XML-строки [] с https://github.com/LineageOS/android_packages_apps_Jelly/blob/lineage-16.0/app/src/main/res/values/search_engines.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>

на: (присмотреть за 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$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 Browser.

Но всегда ошибкавыше бросает и Jelly Browser работает, но не имеет представления об Ecosia.

Что я не так делаю?

1 Ответ

0 голосов
/ 28 сентября 2019

Тип ресурса в файлах ресурсов XML отображается как <string-array>, а также в документации Xposed API известен тип String Array.Однако в документации неясно, какие конкретные значения приемлемы для type:

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

Тип Имя типа, например, строка.См. 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}"});            
...