Skip to content

Commit f06a63b

Browse files
muhomorrthestinger
authored andcommitted
gmscompat: add hooks for overriding BinderProxy transactions
1 parent dcb914c commit f06a63b

3 files changed

Lines changed: 44 additions & 6 deletions

File tree

core/java/android/os/BinderProxy.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import android.util.SparseIntArray;
2525

2626
import com.android.internal.annotations.GuardedBy;
27+
import com.android.internal.gmscompat.GmsCompatLib;
28+
import com.android.internal.gmscompat.IGmsCompatLib;
2729
import com.android.internal.os.BinderInternal;
2830

2931
import libcore.util.NativeAllocationRegistry;
@@ -503,10 +505,23 @@ private static class NoImagePreloadHolder {
503505
*/
504506
public native boolean isBinderAlive();
505507

506-
/**
507-
* Retrieve a local interface - always null in case of a proxy
508-
*/
508+
private IInterface mLocalInterface;
509+
private static final IInterface NO_LOCAL_INTERFACE = () -> null;
510+
509511
public IInterface queryLocalInterface(String descriptor) {
512+
IGmsCompatLib gmcLib = GmsCompatLib.get();
513+
if (gmcLib != null) {
514+
synchronized (this) {
515+
IInterface cache = mLocalInterface;
516+
if (cache != null) {
517+
return cache == NO_LOCAL_INTERFACE ? null : cache;
518+
}
519+
IInterface res = gmcLib.maybeProvideBinderProxyInterface(this, descriptor);
520+
mLocalInterface = res != null ? res : NO_LOCAL_INTERFACE;
521+
return res;
522+
}
523+
524+
}
510525
return null;
511526
}
512527

@@ -719,6 +734,12 @@ private native boolean removeFrozenStateChangeCallbackNative(
719734
* @throws RemoteException
720735
*/
721736
public void dump(FileDescriptor fd, String[] args) throws RemoteException {
737+
IGmsCompatLib gmcLib = GmsCompatLib.get();
738+
if (gmcLib != null) {
739+
if (gmcLib.maybeInterceptBinderProxyDump(this, fd, args, false)) {
740+
return;
741+
}
742+
}
722743
Parcel data = Parcel.obtain();
723744
Parcel reply = Parcel.obtain();
724745
data.writeFileDescriptor(fd);
@@ -740,6 +761,12 @@ public void dump(FileDescriptor fd, String[] args) throws RemoteException {
740761
* @throws RemoteException
741762
*/
742763
public void dumpAsync(FileDescriptor fd, String[] args) throws RemoteException {
764+
IGmsCompatLib gmcLib = GmsCompatLib.get();
765+
if (gmcLib != null) {
766+
if (gmcLib.maybeInterceptBinderProxyDump(this, fd, args, true)) {
767+
return;
768+
}
769+
}
743770
Parcel data = Parcel.obtain();
744771
Parcel reply = Parcel.obtain();
745772
data.writeFileDescriptor(fd);

core/java/com/android/internal/gmscompat/GmsCompatLib.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ public static void init(Context appContext, String processName) {
3333
throw new IllegalStateException(e);
3434
}
3535
instance = lib;
36-
lib.init(appContext, processName);
36+
lib.init(appContext, libCtx, processName);
3737
}
3838
}

core/java/com/android/internal/gmscompat/IGmsCompatLib.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,25 @@
55
import android.content.Context.BindServiceFlags;
66
import android.content.Intent;
77
import android.content.ServiceConnection;
8+
import android.os.BinderProxy;
9+
import android.os.IInterface;
810
import android.os.UserHandle;
911

12+
import java.io.FileDescriptor;
1013
import java.util.concurrent.Executor;
1114

1215
public interface IGmsCompatLib {
13-
void init(Context appContext, String processName);
16+
void init(Context appContext, Context libContext, String processName);
1417

15-
/** @see android.content.Context#bindService(Intent, BindServiceFlags, Executor, ServiceConnection) */
18+
/** @see Context#bindService(Intent, BindServiceFlags, Executor, ServiceConnection) */
1619
@Nullable
1720
ServiceConnection maybeReplaceServiceConnection(Intent service, long flags, UserHandle user, ServiceConnection orig);
21+
22+
/** @see BinderProxy#queryLocalInterface(String) */
23+
@Nullable
24+
IInterface maybeProvideBinderProxyInterface(BinderProxy binderProxy, String ifaceDescriptor);
25+
26+
/** @see BinderProxy#dump(FileDescriptor, String[])
27+
* @see BinderProxy#dumpAsync(FileDescriptor, String[]) */
28+
boolean maybeInterceptBinderProxyDump(BinderProxy binderProxy, FileDescriptor fd, String[] args, boolean async);
1829
}

0 commit comments

Comments
 (0)