@@ -58,12 +58,13 @@ public final class RobolectricBinderSecurityTest {
5858 private static final String SERVICE_NAME = "fake_service" ;
5959 private static final String FULL_METHOD_NAME = "fake_service/fake_method" ;
6060 private final Application context = ApplicationProvider .getApplicationContext ();
61+ private AndroidComponentAddress listenAddress ;
6162 private ManagedChannel channel ;
6263
6364 @ Before
6465 public void setUp () {
65- AndroidComponentAddress listenAddress = AndroidComponentAddress
66- .forRemoteComponent (context .getPackageName (), "HostService" );
66+ listenAddress =
67+ AndroidComponentAddress .forRemoteComponent (context .getPackageName (), "HostService" );
6768 channel =
6869 BinderChannelBuilder .forAddress (listenAddress , context )
6970 .build ();
@@ -99,8 +100,7 @@ public void testAsyncServerSecurityPolicy_allowed_returnsOkStatus() throws Excep
99100 }
100101
101102 private ListenableFuture <Status > makeCall () {
102- ClientCall <Empty , Empty > call =
103- channel .newCall (getMethodDescriptor (), CallOptions .DEFAULT );
103+ ClientCall <Empty , Empty > call = channel .newCall (getMethodDescriptor (), CallOptions .DEFAULT );
104104 ListenableFuture <Empty > responseFuture =
105105 ClientCalls .futureUnaryCall (call , Empty .getDefaultInstance ());
106106
@@ -141,31 +141,30 @@ public void setupServer() {
141141 ServerServiceDefinition def =
142142 ServerServiceDefinition .builder (SERVICE_NAME ).addMethod (methodDef ).build ();
143143
144- server =
145- BinderServerBuilder .forAddress (AndroidComponentAddress .forContext (context ), binderReceiver )
146- .addService (def )
147- .securityPolicy (
148- ServerSecurityPolicy .newBuilder ()
149- .servicePolicy (
150- SERVICE_NAME ,
151- new AsyncSecurityPolicy () {
152- @ Override
153- public ListenableFuture <Status > checkAuthorizationAsync (int uid ) {
154- SettableFuture <Status > status = SettableFuture .create ();
155- statusesToSet .add (status );
156- return status ;
157- }
158- }
159- )
160- .build ())
161- .build ();
144+ server =
145+ BinderServerBuilder .forAddress (listenAddress , binderReceiver )
146+ .addService (def )
147+ .securityPolicy (
148+ ServerSecurityPolicy .newBuilder ()
149+ .servicePolicy (
150+ SERVICE_NAME ,
151+ new AsyncSecurityPolicy () {
152+ @ Override
153+ public ListenableFuture <Status > checkAuthorizationAsync (int uid ) {
154+ SettableFuture <Status > status = SettableFuture .create ();
155+ statusesToSet .add (status );
156+ return status ;
157+ }
158+ })
159+ .build ())
160+ .build ();
162161 try {
163162 server .start ();
164163 } catch (IOException e ) {
165164 throw new IllegalStateException (e );
166165 }
167166
168- ComponentName componentName = new ComponentName (context , "SomeService" );
167+ ComponentName componentName = new ComponentName (context , "SomeService" );
169168 shadowOf (context )
170169 .setComponentNameAndServiceForBindService (
171170 componentName , checkNotNull (binderReceiver .get ()));
0 commit comments