2323
2424import android .content .Context ;
2525import android .content .Intent ;
26+ import android .net .Uri ;
2627import android .os .Parcel ;
2728import android .os .Parcelable ;
2829import androidx .test .core .app .ApplicationProvider ;
3940import io .grpc .ManagedChannel ;
4041import io .grpc .Metadata ;
4142import io .grpc .MethodDescriptor ;
42- import io .grpc .NameResolverRegistry ;
4343import io .grpc .ServerCall ;
4444import io .grpc .ServerCall .Listener ;
4545import io .grpc .ServerCallHandler ;
4949import io .grpc .Status .Code ;
5050import io .grpc .StatusRuntimeException ;
5151import io .grpc .internal .GrpcUtil ;
52- import io .grpc .internal .testing .FakeNameResolverProvider ;
5352import io .grpc .stub .ClientCalls ;
5453import io .grpc .stub .MetadataUtils ;
5554import io .grpc .stub .ServerCalls ;
5958import java .io .IOException ;
6059import java .io .InputStream ;
6160import java .util .ArrayList ;
61+ import java .util .concurrent .ExecutionException ;
6262import java .util .concurrent .Executors ;
6363import java .util .concurrent .atomic .AtomicReference ;
6464import org .junit .After ;
@@ -77,7 +77,6 @@ public final class BinderChannelSmokeTest {
7777
7878 private static final int SLIGHTLY_MORE_THAN_ONE_BLOCK = 16 * 1024 + 100 ;
7979 private static final String MSG = "Some text which will be repeated many many times" ;
80- private static final String SERVER_TARGET_URI = "fake://server" ;
8180 private static final Metadata .Key <PoisonParcelable > POISON_KEY =
8281 ParcelableUtils .metadataKey ("poison-bin" , PoisonParcelable .CREATOR );
8382
@@ -99,7 +98,6 @@ public final class BinderChannelSmokeTest {
9998 .setType (MethodDescriptor .MethodType .BIDI_STREAMING )
10099 .build ();
101100
102- FakeNameResolverProvider fakeNameResolverProvider ;
103101 ManagedChannel channel ;
104102 AtomicReference <Metadata > headersCapture = new AtomicReference <>();
105103 AtomicReference <PeerUid > clientUidCapture = new AtomicReference <>();
@@ -138,8 +136,6 @@ public void setUp() throws Exception {
138136 PeerUids .newPeerIdentifyingServerInterceptor ());
139137
140138 AndroidComponentAddress serverAddress = HostServices .allocateService (appContext );
141- fakeNameResolverProvider = new FakeNameResolverProvider (SERVER_TARGET_URI , serverAddress );
142- NameResolverRegistry .getDefaultRegistry ().register (fakeNameResolverProvider );
143139 HostServices .configureService (
144140 serverAddress ,
145141 HostServices .serviceParamsBuilder ()
@@ -163,10 +159,24 @@ public void setUp() throws Exception {
163159 .build ();
164160 }
165161
162+ @ Test
163+ public void testConnectViaIntentTargetUri () throws Exception {
164+ // TODO(jdcormie): Make this test good.
165+ channel = BinderChannelBuilder .forTarget ("intent://foo/bar" , appContext ).build ();
166+ // channel = BinderChannelBuilder.forTarget("android-app://com.foo.bar/authoritaaay",
167+ // appContext).build();
168+ ListenableFuture <String > resultFuture = doCall ("Hello" );
169+ try {
170+ resultFuture .get ();
171+ } catch (ExecutionException ee ) {
172+ StatusRuntimeException sre = (StatusRuntimeException ) ee .getCause ();
173+ assertThat (sre .getStatus ().getCode ()).isEqualTo (Code .UNIMPLEMENTED );
174+ }
175+ }
176+
166177 @ After
167178 public void tearDown () throws Exception {
168179 channel .shutdownNow ();
169- NameResolverRegistry .getDefaultRegistry ().deregister (fakeNameResolverProvider );
170180 HostServices .awaitServiceShutdown ();
171181 }
172182
@@ -235,7 +245,11 @@ public void testStreamingCallOptionHeaders() throws Exception {
235245
236246 @ Test
237247 public void testConnectViaTargetUri () throws Exception {
238- channel = BinderChannelBuilder .forTarget (SERVER_TARGET_URI , appContext ).build ();
248+ // Compare with the <intent-filter> mapping in AndroidManifest.xml.
249+ channel =
250+ BinderChannelBuilder .forTarget (
251+ "intent://authority/path#Intent;action=action1;scheme=scheme;end;" , appContext )
252+ .build ();
239253 assertThat (doCall ("Hello" ).get ()).isEqualTo ("Hello" );
240254 }
241255
@@ -245,7 +259,10 @@ public void testConnectViaIntentFilter() throws Exception {
245259 channel =
246260 BinderChannelBuilder .forAddress (
247261 AndroidComponentAddress .forBindIntent (
248- new Intent ().setAction ("action1" ).setPackage (appContext .getPackageName ())),
262+ new Intent ()
263+ .setAction ("action1" )
264+ .setData (Uri .parse ("scheme://authority/path" ))
265+ .setPackage (appContext .getPackageName ())),
249266 appContext )
250267 .build ();
251268 assertThat (doCall ("Hello" ).get ()).isEqualTo ("Hello" );
0 commit comments