Skip to content

Commit 5517904

Browse files
committed
undo some merging mistakes
1 parent b88c8e9 commit 5517904

4 files changed

Lines changed: 10 additions & 61 deletions

File tree

binder/src/main/java/io/grpc/binder/ApiConstants.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import android.content.Intent;
2020
import android.content.pm.ServiceInfo;
2121
import android.os.UserHandle;
22+
import io.grpc.Attributes;
23+
import io.grpc.EquivalentAddressGroup;
2224
import io.grpc.ExperimentalApi;
2325
import io.grpc.NameResolver;
2426

@@ -46,15 +48,15 @@ private ApiConstants() {}
4648
NameResolver.Args.Key.create("target-android-user");
4749

4850
/**
49-
* Marks an {@link io.grpc.EquivalentAddressGroup} as needing pre-authorization.
51+
* Lets you override a Channel's pre-auth configuration (see {@link
52+
* BinderChannelBuilder#preAuthorizeServers(boolean)} for a given {@link EquivalentAddressGroup}.
5053
*
51-
* <p>Clients should authorize servers before connecting to them, but older versions of the binder
52-
* transport didn't do so. While this important extra security check is now possible (see {@link
53-
* BinderChannelBuilder#preAuthorizeServers(boolean)}, it remains optional, because it's a slight
54-
* behavior change and has a small performance cost and we don't want to break existing apps.
54+
* <p>A {@link NameResolver} that discovers servers from an untrusted source like PackageManager
55+
* can use this to force server pre-auth and prevent abuse.
5556
*/
56-
public static final Attributes.Key<Void> PRE_AUTH_REQUIRED =
57-
Attributes.Key.create("pre-auth-required");
57+
@EquivalentAddressGroup.Attr
58+
public static final Attributes.Key<Boolean> PRE_AUTH_SERVER_OVERRIDE =
59+
Attributes.Key.create("pre-auth-server-override");
5860

5961
/**
6062
* The authentic ServiceInfo for an {@link io.grpc.EquivalentAddressGroup} of {@link

binder/src/main/java/io/grpc/binder/internal/Bindable.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,10 @@ interface Observer {
4747
void onUnbound(Status reason);
4848
}
4949

50-
/** Fetches details about the remote service from PackageManager *before* binding to it. */
51-
@AnyThread
52-
ServiceInfo resolve();
53-
5450
/**
5551
* Fetches details about the remote Service from PackageManager without binding to it.
5652
*
57-
* <p>Resolving an untrusted address before binding to it lets you screen out problematic servers
53+
* <p>Resolving an untrusted address before binding to it lets you screen out unauthorized servers
5854
* before giving them a chance to run. However, note that the identity/existence of the resolved
5955
* Service can change between the time this method returns and the time you actually bind/connect
6056
* to it. For example, suppose the target package gets uninstalled right after this method

binder/src/main/java/io/grpc/binder/internal/ServiceBinding.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -257,42 +257,6 @@ private static int getIdentifier(UserHandle userHandle) throws ReflectiveOperati
257257
return (int) userHandle.getClass().getDeclaredMethod("getIdentifier").invoke(userHandle);
258258
}
259259

260-
private static ResolveInfo resolveServiceAsUser(
261-
PackageManager packageManager, Intent bindIntent, int flags, UserHandle targetUserHandle)
262-
throws ReflectiveOperationException {
263-
Method resolveService;
264-
Object[] args;
265-
if (targetUserHandle == null) {
266-
resolveService =
267-
packageManager.getClass().getMethod("resolveService", Intent.class, int.class);
268-
args = new Object[] {bindIntent, flags};
269-
} else {
270-
resolveService =
271-
packageManager
272-
.getClass()
273-
.getMethod("resolveServiceAsUser", Intent.class, int.class, int.class);
274-
args = new Object[] {bindIntent, flags, getIdentifier(targetUserHandle)};
275-
}
276-
return (ResolveInfo) resolveService.invoke(packageManager, args);
277-
}
278-
279-
@AnyThread
280-
public ServiceInfo resolve() {
281-
checkState(sourceContext != null);
282-
try {
283-
ResolveInfo resolveInfo =
284-
resolveServiceAsUser(sourceContext.getPackageManager(), bindIntent, 0, targetUserHandle);
285-
return resolveInfo != null ? resolveInfo.serviceInfo : null;
286-
} catch (ReflectiveOperationException e) {
287-
throw Status.fromThrowable(e).asRuntimeException();
288-
}
289-
}
290-
291-
// Sadly we must call this system API reflectively since it isn't part of the Android SDK.
292-
private static int getIdentifier(UserHandle userHandle) throws ReflectiveOperationException {
293-
return (int) userHandle.getClass().getMethod("getIdentifier").invoke(userHandle);
294-
}
295-
296260
// Sadly we must call this system API reflectively since it isn't part of the Android SDK.
297261
private static ResolveInfo resolveServiceAsUser(
298262
PackageManager packageManager, Intent intent, int flags, UserHandle targetUserHandle) {

binder/src/test/java/io/grpc/binder/BinderChannelBuilderTest.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,4 @@ public void strictLifecycleManagementForbidsIdleTimers() {
4242
// Expected.
4343
}
4444
}
45-
46-
@Test
47-
public void preAuthorizeTargetUris() {
48-
BinderChannelBuilder builder = BinderChannelBuilder.forTarget("foo://bar", appContext);
49-
assertThat(builder.transportFactoryBuilder.getPreAuthorizeServers()).isTrue();
50-
}
51-
52-
@Test
53-
public void noPreAuthorizeDirectAddresses() {
54-
// TODO(jdcormie): Turn this on by default in a future release.
55-
BinderChannelBuilder builder = BinderChannelBuilder.forAddress(addr, appContext);
56-
assertThat(builder.transportFactoryBuilder.getPreAuthorizeServers()).isFalse();
57-
}
5845
}

0 commit comments

Comments
 (0)