[core] Fix write settings (#1156)

This commit is contained in:
LoveSy 2021-09-22 00:26:00 +08:00 committed by GitHub
parent 9afa34932e
commit 41755d4464
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 47 additions and 44 deletions

View File

@ -25,6 +25,7 @@ import android.app.IActivityManager;
import android.app.IApplicationThread; import android.app.IApplicationThread;
import android.app.IServiceConnection; import android.app.IServiceConnection;
import android.app.ProfilerInfo; import android.app.ProfilerInfo;
import android.content.IContentProvider;
import android.content.IIntentReceiver; import android.content.IIntentReceiver;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
@ -163,4 +164,14 @@ public class ActivityManagerService {
return am.getCurrentUser(); return am.getCurrentUser();
} }
public static IContentProvider getContentProvider(String auth, int userId) throws RemoteException {
IActivityManager am = getActivityManager();
if (am == null) return null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
return am.getContentProviderExternal(auth, userId, token, null).provider;
} else {
return am.getContentProviderExternal(auth, userId, token).provider;
}
}
} }

View File

@ -598,13 +598,13 @@ public class LSPManagerService extends ILSPManagerService.Stub {
@Override @Override
public void setHiddenIcon(boolean hide) { public void setHiddenIcon(boolean hide) {
var settings = new ServiceShellCommand("settings"); Bundle args = new Bundle();
var enable = hide ? "0" : "1"; args.putString("value", hide ? "0" : "1");
var args = new String[]{"put", "global", "show_hidden_icon_apps_enabled", enable}; args.putString("_user", "0");
try { try {
settings.shellCommand(FileDescriptor.in, FileDescriptor.out, FileDescriptor.err, ActivityManagerService.getContentProvider("settings", 0)
args, new ResultReceiver(null)); .call("android", null, "settings", "PUT_global", "show_hidden_icon_apps_enabled", args);
} catch (RemoteException e) { } catch (RemoteException | NullPointerException e) {
Log.w(TAG, "setHiddenIcon: ", e); Log.w(TAG, "setHiddenIcon: ", e);
} }
} }

View File

@ -1,36 +0,0 @@
package org.lsposed.lspd.service;
import android.os.IBinder;
import android.os.Parcel;
import android.os.RemoteException;
import android.os.ResultReceiver;
import java.io.FileDescriptor;
class ServiceShellCommand {
private static final int SHELL_COMMAND_TRANSACTION = ('_' << 24) | ('C' << 16) | ('M' << 8) | 'D';
private final IBinder binder;
ServiceShellCommand(String name) {
binder = android.os.ServiceManager.getService(name);
}
void shellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
String[] args, ResultReceiver resultReceiver) throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeFileDescriptor(in);
data.writeFileDescriptor(out);
data.writeFileDescriptor(err);
data.writeStringArray(args);
data.writeStrongBinder(null);
resultReceiver.writeToParcel(data, 0);
try {
binder.transact(SHELL_COMMAND_TRANSACTION, data, reply, 0);
reply.readException();
} finally {
data.recycle();
reply.recycle();
}
}
}

View File

@ -95,7 +95,9 @@ public class ParasiticManagerHooker {
"android.app.ActivityThread$AppBindData", "android.app.ActivityThread$AppBindData",
managerApkHooker); managerApkHooker);
XposedBridge.hookAllConstructors(ActivityThread.ActivityClientRecord.class, activityHooker);
var activityClientRecordClass = XposedHelpers.findClass("android.app.ActivityThread$ActivityClientRecord", ActivityThread.class.getClassLoader());
XposedBridge.hookAllConstructors(activityClientRecordClass, activityHooker);
var unhooks = new XC_MethodHook.Unhook[]{null}; var unhooks = new XC_MethodHook.Unhook[]{null};
unhooks[0] = XposedHelpers.findAndHookMethod( unhooks[0] = XposedHelpers.findAndHookMethod(
@ -124,6 +126,7 @@ public class ParasiticManagerHooker {
}); });
XposedBridge.hookAllMethods(ActivityThread.class, "installProvider", new XC_MethodHook() { XposedBridge.hookAllMethods(ActivityThread.class, "installProvider", new XC_MethodHook() {
private Context originalContext = null; private Context originalContext = null;
@Override @Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable { protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Hookers.logD("before install provider"); Hookers.logD("before install provider");
@ -152,7 +155,7 @@ public class ParasiticManagerHooker {
} }
}); });
XposedHelpers.findAndHookMethod(ActivityThread.class, "deliverNewIntents", ActivityThread.ActivityClientRecord.class, List.class, new XC_MethodHook() { XposedHelpers.findAndHookMethod(ActivityThread.class, "deliverNewIntents", activityClientRecordClass, List.class, new XC_MethodHook() {
@Override @Override
protected void beforeHookedMethod(MethodHookParam param) { protected void beforeHookedMethod(MethodHookParam param) {
if (param.args[1] == null) return; if (param.args[1] == null) return;

View File

@ -0,0 +1,7 @@
package android.app;
import android.content.IContentProvider;
public class ContentProviderHolder {
public IContentProvider provider;
}

View File

@ -97,6 +97,13 @@ public interface IActivityManager extends IInterface {
void setActivityController(IActivityController watcher, boolean imAMonkey) throws RemoteException; void setActivityController(IActivityController watcher, boolean imAMonkey) throws RemoteException;
@RequiresApi(29)
ContentProviderHolder getContentProviderExternal(String name, int userId,
IBinder token, String tag);
ContentProviderHolder getContentProviderExternal(String name, int userId,
IBinder token);
abstract class Stub extends Binder implements IActivityManager { abstract class Stub extends Binder implements IActivityManager {
public static int TRANSACTION_setActivityController; public static int TRANSACTION_setActivityController;

View File

@ -0,0 +1,11 @@
package android.content;
import android.os.Bundle;
import android.os.IInterface;
import android.os.RemoteException;
public interface IContentProvider extends IInterface {
Bundle call(String callingPkg, String attributionTag, String authority,
String method, String arg, Bundle extras) throws RemoteException;
}