From 4eb482cce681f11438c63b6d53635a26ecd8acc8 Mon Sep 17 00:00:00 2001 From: Georgeto Date: Mon, 6 Nov 2017 00:44:25 +0100 Subject: [PATCH] Allow location providers also outside of /system --- app/src/main/assets/xposed_init | 3 +- .../fakegapps/NonSystemLocationProviders.java | 65 +++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/thermatk/android/xf/fakegapps/NonSystemLocationProviders.java diff --git a/app/src/main/assets/xposed_init b/app/src/main/assets/xposed_init index 079c87d..2e49046 100644 --- a/app/src/main/assets/xposed_init +++ b/app/src/main/assets/xposed_init @@ -1,2 +1,3 @@ com.thermatk.android.xf.fakegapps.FakeSignatures -com.thermatk.android.xf.fakegapps.PackageNameServiceHook \ No newline at end of file +com.thermatk.android.xf.fakegapps.PackageNameServiceHook +com.thermatk.android.xf.fakegapps.NonSystemLocationProviders \ No newline at end of file diff --git a/app/src/main/java/com/thermatk/android/xf/fakegapps/NonSystemLocationProviders.java b/app/src/main/java/com/thermatk/android/xf/fakegapps/NonSystemLocationProviders.java new file mode 100644 index 0000000..f040b6b --- /dev/null +++ b/app/src/main/java/com/thermatk/android/xf/fakegapps/NonSystemLocationProviders.java @@ -0,0 +1,65 @@ +package com.thermatk.android.xf.fakegapps; + +import android.content.Context; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.content.pm.Signature; +import android.os.Binder; +import android.os.Build; +import android.os.PackageNameServiceManager; +import android.util.Log; + +import com.android.server.PackageNameService; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; + +import de.robv.android.xposed.IXposedHookZygoteInit; +import de.robv.android.xposed.XC_MethodHook; +import de.robv.android.xposed.XposedBridge; +import de.robv.android.xposed.XposedHelpers; + +public final class NonSystemLocationProviders implements IXposedHookZygoteInit { + @Override + public void initZygote(StartupParam startupParam) throws Throwable { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + XposedBridge.hookAllMethods(XposedHelpers.findClass("android.app.ActivityThread", null), + "systemMain", + new XC_MethodHook() { + @Override + protected void afterHookedMethod(MethodHookParam param) { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + register(loader); + } + } + ); + } + } + + private static void register(ClassLoader loader) { + final Class serviceWatcher = XposedHelpers.findClass("com.android.server.ServiceWatcher", loader); + XposedBridge.hookAllMethods(serviceWatcher, "getSignatureSets", new XC_MethodHook() { + @Override + protected void beforeHookedMethod(MethodHookParam param) throws Throwable { + Context context = (Context) param.args[0]; + List initialPackageNames = (List) param.args[1]; + PackageManager pm = context.getPackageManager(); + ArrayList> sigSets = new ArrayList<>(); + for (int i = 0, size = initialPackageNames.size(); i < size; i++) { + String pkg = initialPackageNames.get(i); + try { + HashSet set = new HashSet<>(); + Signature[] sigs = pm.getPackageInfo(pkg, PackageManager.GET_SIGNATURES).signatures; + set.addAll(Arrays.asList(sigs)); + sigSets.add(set); + } catch (PackageManager.NameNotFoundException e) { + Log.w("ServiceWatcher", pkg + " not found"); + } + } + param.setResult(sigSets); + } + }); + } +}