Skip to content

Commit 5d34fe9

Browse files
committed
Add UserHandle and BinderChannelCredentials to BinderChannelBuilder to support cross-user ondevice server.
1 parent e6945df commit 5d34fe9

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2022 The gRPC Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.grpc.binder;
18+
19+
import static com.google.common.base.Preconditions.checkNotNull;
20+
21+
import android.content.ComponentName;
22+
import io.grpc.ChannelCredentials;
23+
import io.grpc.ExperimentalApi;
24+
import javax.annotation.Nullable;
25+
26+
/** Additional arbitrary arguments to establish a Android binder connection channel. */
27+
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/10173")
28+
public final class BinderChannelCredentials extends ChannelCredentials {
29+
30+
/**
31+
* Creates the default BinderChannelCredentials.
32+
*
33+
* @return a BinderChannelCredentials
34+
*/
35+
public static BinderChannelCredentials forDefault() {
36+
return new BinderChannelCredentials(null);
37+
}
38+
39+
/**
40+
* Creates a BinderChannelCredentials to be used with DevicePolicyManager API.
41+
*
42+
* @param devicePolicyAdminComponentName the admin component to be specified with
43+
* DevicePolicyManager.bindDeviceAdminServiceAsUser API.
44+
* @return a BinderChannelCredentials
45+
*/
46+
public static BinderChannelCredentials forDevicePolicyAdmin(
47+
ComponentName devicePolicyAdminComponentName) {
48+
return new BinderChannelCredentials(devicePolicyAdminComponentName);
49+
}
50+
51+
@Nullable private final ComponentName devicePolicyAdminComponentName;
52+
53+
private BinderChannelCredentials(@Nullable ComponentName devicePolicyAdminComponentName) {
54+
this.devicePolicyAdminComponentName = devicePolicyAdminComponentName;
55+
}
56+
57+
@Override
58+
public ChannelCredentials withoutBearerTokens() {
59+
return this;
60+
}
61+
62+
@Nullable
63+
public ComponentName getDevicePolicyAdminComponentName() {
64+
return devicePolicyAdminComponentName;
65+
}
66+
}

0 commit comments

Comments
 (0)