Commit Graph

119 Commits

Author SHA1 Message Date
John Cormie 21dec30924
Establish a default connect timeout. (#11359)
Enables the timer added in #11137
2024-07-09 12:46:21 -07:00
John Cormie 5770114d08
google-java-format binder/src/*/*.java (#11297)
https://github.com/grpc/grpc-java/blob/master/CONTRIBUTING.md#code-style

We've been talking about an incremental approach in https://github.com/grpc/grpc-java/issues/1664 but https://github.com/google/google-java-format/issues/1114 causes a bunch of manual formatting toil every time I run ~/google-java-format-diff.py because we have a LOT of lines >100 characters. Establishing a gjf-clean baseline will make things a lot easier for me.
2024-06-24 09:42:31 -07:00
John Cormie 15ad9f546c
binder: Simplify ownership of ServerAuthInterceptor's executor. (#11293)
Allocating this executor before BinderServer even exists is convoluted and actually leaks if the built server is never actually start()ed. Instead, have BinderServer own this executor directly, with a lifetime from start() until termination. Pass it to the ServerAuthInterceptor via TransportAuthorizationState Attribute instead of at construction time.
2024-06-18 18:56:33 -07:00
Kannan J 14fd81f59b
Adding missing synchronization in the runnable that is causing access guard violation error. (#11277) 2024-06-12 11:09:59 +05:30
John Cormie 7fee6a3fea
Don't block an offload thread when the client's SecurityPolicy is async (#11272)
https://github.com/grpc/grpc-java/issues/10566
2024-06-09 22:38:41 -07:00
Mateus Azis 34ee600dce
Wait for all BinderServerTransports to terminate before ... (#11240)
... returning security policy executor to the object pool.

Fixes #10897.
2024-06-06 14:52:11 -07:00
John Cormie 1670e97f74
Reject further SETUP_TRANSPORT requests post-BinderServer shutdown (#11260)
Fixes https://github.com/grpc/grpc-java/issues/8931
2024-06-06 14:18:45 -07:00
Eric Anderson 0a4df9f93c binder: Make transport notification methods package-private
These are overrides of BinderTransport itself, so not used elsewhere.
They are essentially private. It was scary seeing `@GuardedBy` for a
public method. I copied the annotation to the base class to make sure
ErrorProne could verify the calls.
2024-06-06 08:59:32 -07:00
John Cormie 791f894e25
binder: Add a connection timeout (#11255)
Timeout is initially infinite so that we can release/import the supporting code and the behavior change independently.

Fixes #11137
2024-06-05 15:11:30 -07:00
John Cormie df01271687
Use a builder to eliminate BinderServer's long list of ctor params (#11235) 2024-05-28 19:34:55 -07:00
Eric Anderson 960012d76e api: Add ClientStreamTracer.inboundHeaders(Metadata)
This will be used by the metadata exchange of CSM. When recording
per-attempt metrics, we really need per-attempt data and can't leverage
ClientInterceptors.
2024-05-24 11:28:40 -07:00
John Cormie 0b5f38d942
Use the builder pattern to replace BinderClientTransport's long ctor arg list (#11220) 2024-05-23 11:50:37 -07:00
hakusai22 6ec744f2a0
Fix various typos (#11144) 2024-05-06 20:29:44 -07:00
abtom 537dbe826a
binder: Helper class to allow in process servers to use peer uids in test (#11014) 2024-03-22 15:57:29 -07:00
James Duong 2c83ef0632
Allow configuration of the queued byte threshold at which a Stream is considered not ready (#10977)
* Allow the queued byte threshold for a Stream to be ready to be configurable

- on clients this is exposed by setting a CallOption
- on servers this is configured by calling a method on ServerCall or ServerStreamListener
2024-03-21 15:37:26 -07:00
John Cormie 8f45a97be6
binder: remove existing warnings and allow failOnWarnings (#10989) 2024-03-07 09:56:37 -08:00
John Cormie d894c8385d
Use a realistic Executor in BinderServerTransportTest (#10979) 2024-03-05 15:24:43 -08:00
Eric Anderson 9947a25765 binder: Fix unused imports and parameter name mismatch 2024-03-05 10:04:30 -08:00
Prashanth Swaminathan e697eccc51
roboelectric: Remove references to kitkat (#10953)
In addition to removing a test that only applies to KitKat, switch tests
that require 19 to not specifying the SDK version as we only support min
sdk version 21, which has the required API.

Also removes the SDK version check from isProfileOwner, to trigger a
runtime exception when too low of an SDK version is used.
2024-02-28 09:55:03 -08:00
Terry Wilson ce2adcca93
binder: Add missing Android API annotations (#10841) 2024-02-28 08:02:58 -08:00
John Cormie a654d2ebb3
binder: Add fault injection hooksunit tests for BinderClientTransport (#10928) 2024-02-27 14:28:50 -08:00
John Cormie f20c853c40
Factor out MainThreadScheduledExecutorService. (#10916)
So it can be used by other robolectric tests.
2024-02-15 11:11:43 -08:00
Larry Safran 7ba0718bb9
Change log level from WARNING to FINER for expected exception (#10899)
* Change log level from WARNING to FINER.  Fixes #10816
2024-02-07 17:31:27 -08:00
Mateus Azis c2a3792a04
binder: Create a new RobolectricBinderSecurityTest (#10835)
Exercises async security policies codepaths.
2024-01-30 11:36:53 -08:00
Mateus Azis 3e8e56feea
Make AsyncSecurityPolicy.checkAuthorizationAsync public. (#10836)
I initially omitted the visibility modifier because this class began as an interface. Since it moved to an abstract class, we must make it public so it can be overriden by subclasses in the integrator's packages.

Part of #10566.
2024-01-22 15:54:48 -08:00
Mateus Azis 9b9e53359f
Add unit test coverage for PendingAuthListener. (#10806)
Part of #10566.
2024-01-22 15:06:16 -08:00
John Cormie fdd6f5001f
binder: fix up BinderClientTransportTest (#10822)
- Multiple test cases assumed all messages would arrive on a single MessageProducer but this isn't guaranteed by the API contract.
- testBadTransactionStreamThroughput_b163053382 was writing `serverCallsCompleted` on one thread and reading it on another without synchronization. A deeper problem was that waiting for the call to complete on the server doesn't mean messages are  immediately available on the client.
- Replaced 100ms polling loops with wait()/notifyAll()
- Close() InputStreams that we read as required by the MessageProducer#next contract.

Passes with --runs_per_test=1000
2024-01-19 17:47:08 -08:00
John Cormie 4352099c7f
binder: BinderTransportTest uses a realistic Executor. (#10803) 2024-01-11 10:49:03 -08:00
John Cormie 5e07310d06
binder: oneway txns cannot arrive out of order (#10754)
See https://developer.android.com/reference/android/os/IBinder#FLAG_ONEWAY
2024-01-03 22:31:51 -08:00
joybestourous 91d15ce4e6
Add ClientTransportFilter (#10646)
* Add ClientTransportFilter
2024-01-03 10:45:22 -08:00
Mateus Azis 5b082ca640
Do not cache failed futures for async security policies indefinitely. (#10743)
Currently, if caching is enabled (as is often the case) and AsyncSecurityPolicy returns a failed future, then this future is cached forever, without giving the SecurityPolicy implementation a chance to be retried. Going forward, new invocations will trigger new security checks if the last one could not be completed successfuly.
2024-01-03 15:17:30 +01:00
Eric Anderson d6830d7f99
Change many api deps to implementation deps
These look pretty fair now, mostly only exposing grpc-api and
annotations as api dependencies.
2023-12-15 15:14:29 -08:00
Mateus Azis a053889869
Handle slow security policies without blocking gRPC threads. (#10633)
* Handle slow security policies without blocking gRPC threads.

- Introduce PendingAuthListener to handle a ListenableFuture<Status>, progressing the gRPC through each stage in sequence once the future completes and is OK.
- Move unit tests away from `checkAuthorizationForService` and into `checkAuthorizationForServiceAsync` since that should be the only method called in production now.
- Some tests in `ServerSecurityPolicyTest` had their expectations updated; they previously called synchornous APIs that transformed failed `ListenableFuture<Status>` into one or another status. Now, we call the sync API, so those transformations do not happen anymore, thus the test needs to deal with failed futures directly.
- I couldn't figure out if this PR needs extra tests. AFAICT `BinderSecurityTest` should already cover the new codepaths, but please let me know otherwise.
2023-12-06 11:13:28 +01:00
John Cormie bdb0c72d45
binder: Beef up hasPermissions security policy Javadoc (#10650)
Try to manage the fact that runtime permissions could be granted externally by the user after a hasPermissions() SecurityPolicy check has already been made on a transport.
2023-11-15 10:05:31 -08:00
Jeff Davidson 45ffb06f00 Bump compileSdkVersion and finalize setAllowActivityStarts API.
Per https://developer.android.com/about/versions/14#beta-3, Android U has reached the platform stability milestone which means that all external APIs are finalized.

We can thus bump the compileSdkVersion to 34 (U) and begin using APIs added there. We leave targetSdkVersion unchanged for now to avoid the broader evaluation of whether deeper changes may be necessary as part of the upgrade; this simply allows compile-time access to newer APIs without changing runtime behavior.

See b/274061424
2023-11-07 08:01:44 -08:00
sanjaypujare 15fc70be2a
core, netty, okhttp: implement new logic for nameResolverFactory API in channelBuilder (#10590)
* core, netty, okhttp: implement new logic for nameResolverFactory API in channelBuilder
fix ManagedChannelImpl to use NameResolverRegistry instead of NameResolverFactory
fix the ManagedChannelImplBuilder and remove nameResolverFactory

* Integrate target parsing and NameResolverProvider searching

Actually creating the name resolver is now delayed to the end of
ManagedChannelImpl.getNameResolver; we don't want to call into the name
resolver to determine if we should use the name resolver.

Added getDefaultScheme() to NameResolverRegistry to avoid needing
NameResolver.Factory.
---------

Co-authored-by: Eric Anderson <ejona@google.com>
2023-11-03 09:57:59 -07:00
Sergii Tkachenko a294b27d52
core: Deprecate ForwardingChannelBuilder (#10587)
Deprecate `ForwardingChannelBuilder` in favor of `ForwardingChannelBuilder2`.
2023-11-02 10:58:20 -07:00
Mateus Azis b6947de95a
Introduce the AsyncSecurityPolicy class. (#10622)
This is the async variant of SecurityPolicy, allowing callers to implement security checks based on slow calls that aren't meant to block the gRPC thread.

BinderTransportSecurity.checkAuthorization **STILL** blocks while attempting to resolve the ListenableFuture<Status> it gets from the policy object. That will still be adressed in a follow-up.

Relate issue: #10566
2023-10-26 19:14:39 +02:00
Mateus Azis 8966680015
binder: Allow async/slow implementations of authorization checks (#10596)
Allow a security policy to returns a `ListenableFuture<Status>` that
callers can implement to perform slower auth checks (like network
calls, disk I/O etc.) without necessarily blocking the gRPC calling
thread.

Partially addresses: https://github.com/grpc/grpc-java/issues/10566
2023-10-20 13:53:12 -07:00
amirhadadi 8c0545564f
Avoid flushing headers when the server returns a single response (#9314)
* core,netty: avoid flushing the headers on the server side when the server has a single response.
2023-10-09 09:43:10 -07:00
John Cormie 134b0490d5
Enable indirect addressing using <intent-filter>s. (#10550)
AndroidComponentAddress now accepts an Intent with merely a package
restriction, not a full ComponentName. This lets clients avoid hard
coding Service class names that they don't control.

Fixes #9062
2023-09-12 17:27:35 -07:00
Terry Wilson 2b4f649b0a
android: Min SDK level to 21 (#10505)
Google Play has dropped support for SDK levels 19 and 20 and so can we.
2023-08-22 10:47:31 -07:00
Kun Zhang c5c37ac51c
binder/test: Stop running Robolectric tests on APIs < 19 (#10385)
This is a port of internal cl/547560711, but with a change to call
isDeviceOwner that requires sdk 18 unconditioally
2023-07-26 10:44:56 -07:00
wwtbuaa01 5799febde0
Add UserHandle and BinderChannelCredentials to BinderChannelBuilder to support cross-user communication through OnDeviceServer. (#10197)
Add UserHandle and BinderChannelCredentials to BinderChannelBuilder to support cross-user ondevice server.
2023-06-29 13:01:13 +02:00
Eric Anderson d654707838
buildscripts: Build Android with main build in linux_artifacts
Note that this changes the JDK used to compile releases to Java 11. That
should only impact the appearance of the Javadoc.

This adds the Android SDK to the build container, removing the
dependency on the Android SDK being available on the CI host. This
allows running on newer Kokoro images. 'Android' and 'Android interop'
CIs still depend on the Android SDK being available on the host, but
since they aren't used as part of the release process, they can more
easily migrate off Kokoro as part of future work.

This also causes Android components to now be built with -Werror, as we
use -PfailOnWarnings=true in unix.sh but were missing it from the
Android build invocations.

Gradle will auto-download the necessary version of build-tools. We don't
want to download it ourselves because the version we specify might not
even be used. Looking at logs, we were previously downloading a version
that was unused.

We now fork javac to avoid OOM. The build fails 2/3 times before the
forking, and 0/3 after.
2023-06-28 16:24:21 -07:00
Eric Anderson f46793e82d Remove unneeded dependency excludes
Since 44847bf4e, when we upgraded our JUnit version, the JUnit
exclusions have probably not been necessary. e0ac97c4f upgraded
Robolectric to a version that had the auto.service problem fixed.
2023-06-23 11:18:10 -07:00
Eric Anderson e0ac97c4fd
Upgrade dependencies (#10178)
Required bumping android compile/targetSdkVersion to 33
2023-05-17 08:32:49 -07:00
Eric Anderson 29b8483fd6
Use test fixtures instead of sourceSets.test.output
This avoids the (often missing) evaluationDependsOn and fixes using
results from other projects without propagating those through
Configuration. It also reduces the number of useless classes pulled in
by down-stream tests, reducing the probability of rebuilds.

The expectation of fixtures is they help testing down-stream code that
use the classes in main. That applies to all the classes here except for
FakeClock and StaticTestingClassLoader. It would also apply to many
internal classes in grpc-testing, but let's consider cleaning that up
future work.
2023-05-16 12:10:13 -07:00
Eric Anderson 22366891de
binder: Use Channel-based blockingUnaryCall()
The Channel-based overload can change the CallOptions to use
ThreadlessExecutor, so avoids using extra threads.
2023-05-05 15:22:54 -07:00
Terry Wilson 0005029328
android,binder,cronet: .aar file when publishing (#10138) 2023-05-05 15:21:26 -07:00