Commit Graph

106 Commits

Author SHA1 Message Date
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
yifeizhuang 5a121ebb83
binder: fix test error prone (#10132) 2023-05-05 10:55:58 -07:00
John Cormie 87fe41046a
Handle unexpected exceptions on binder threads (#10092)
All BinderTransport transactions are oneway which means uncaught
Exceptions during processing are merely logged locally and not
propagated to the peer. Instead, we add a top level catch block
that handles the unexpected by shutting down the whole transport. This
makes our peer aware of the problem immediately (instead of relying on a
deadline) and gives clients a fresh transport instance to handle any
retries.
2023-04-25 09:11:06 -07:00
Jeff Davidson 1c6a7412bb
Add BIND_ALLOW_ACTIVITY_STARTS to BindServiceFlags. (#10008)
This flag is added in the U SDK, which is still under development. Since it's just a numeric constant, we copy the value until it is stable and mark the API is experimental, with appropriate warnings about depending on it from production code.

A follow-up change will be made after SDK finalization to point to the official constant (or otherwise update to match any SDK changes), at which point we can remove the `@ExternalApi` annotation.

See b/274061424
2023-04-11 22:04:55 +02:00
Jeff Davidson b8444d563d
binder: Expose client identity via a new abstract 'PeerUid' type (#9952)
The actual remote uid was kept private to prevent misuse.
2023-03-16 17:34:13 -07:00
Terry Wilson b5b7cacba9
Upgrade Android Gradle plugin to 7.4.0 (#9933)
This is the latest version of the plugin supported by the Gradle version
in use at the moment (7.6).

Note that this also upgrades the R8 optimizer to a version (4.0.48) that
now uses "full mode" optimization by default.

This also splits off Android projects to run under Java 11 (Gradle
plugin requirement) while the other projects continue to run under Java
8.
2023-03-08 11:18:27 -08:00
Terry Wilson 2351e37dd7
binder: Do not fail binder build on javadoc errors (#9941)
We will be running this with Java 11, which has elevated some earlier
warnings to errors that fail the build. We don't want the build to fail
because of this.
2023-03-08 10:02:02 -08:00
Benjamin Peterson 4b6853b6dd
errorprone: enable UnnecessaryAnonymousClass (#9927)
The Java 7 compatibility rationale no longer holds.
2023-03-03 15:16:17 -08:00
yifeizhuang 2a0b86f7cd
binder: BinderInternal.setIBinder() is public static (#9743) 2022-12-09 15:21:47 -08:00
cbianchi-7 e36275e951 Additional changes that were added post-submission of PR 9669 for promoting out of experimental status. 2022-12-01 12:39:55 -08:00
Eric Anderson df974455ae binder: Remove unused imports 2022-12-01 11:41:57 -08:00
cbianchi-7 d6aa0ea370
binder: Promote out of experimental status (#9669) 2022-11-30 10:37:32 -08:00
markb74 241097c6e0
binder: Set default idle timeout to 60 seconds, and enable "strict lifecycle management". (#9486) 2022-11-29 09:57:25 +01:00
markb74 f082151fb5
binder: Ensure the security interceptor is always closest to the actual transport. (#9716) 2022-11-28 17:38:00 -08:00