Skip to content

Commit 1c6a741

Browse files
authored
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
1 parent d580bd3 commit 1c6a741

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

binder/src/main/java/io/grpc/binder/BindServiceFlags.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import static android.content.Context.BIND_WAIVE_PRIORITY;
2828
import static java.lang.Integer.toHexString;
2929

30+
import android.os.Build;
3031
import androidx.annotation.RequiresApi;
32+
import io.grpc.ExperimentalApi;
3133

3234
/**
3335
* An immutable set of flags affecting the behavior of {@link android.content.Context#bindService}.
@@ -101,6 +103,26 @@ public Builder setAdjustWithActivity(boolean newValue) {
101103
return setFlag(BIND_ADJUST_WITH_ACTIVITY, newValue);
102104
}
103105

106+
// TODO(b/274061424): Reference official constant and add RequiresApi declaration in place of
107+
// informal Javadoc warning when U is final.
108+
/**
109+
* Sets or clears the {@code android.content.Context#BIND_ALLOW_ACTIVITY_STARTS} flag.
110+
*
111+
* <p>This method allows for testing and development on Android U developer previews. Before
112+
* releasing production code which depends on this flag, verify that either the
113+
* {@code BIND_ALLOW_ACTIVITY_STARTS} flag has not changed from 0x200 during SDK development,
114+
* or wait for this method to be updated to point to the final flag and made non-experimental.
115+
*
116+
* <p>This flag has no additional meaning at the gRPC layer. See the Android docs for more.
117+
*
118+
* @return this, for fluent construction
119+
*/
120+
@ExperimentalApi("To be finalized after Android U SDK finalization")
121+
public Builder setAllowActivityStarts(boolean newValue) {
122+
// https://developer.android.com/reference/android/content/Context#BIND_ALLOW_ACTIVITY_STARTS
123+
return setFlag(0x200, newValue);
124+
}
125+
104126
/**
105127
* Sets or clears the {@link android.content.Context#BIND_ALLOW_OOM_MANAGEMENT} flag.
106128
*

binder/src/test/java/io/grpc/binder/BindServiceFlagsTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public void shouldReflectSetFlags() {
7373
.setAutoCreate(true)
7474
.setAdjustWithActivity(true)
7575
.setAboveClient(true)
76+
.setAllowActivityStarts(true)
7677
.setAllowOomManagement(true)
7778
.setImportant(true)
7879
.setIncludeCapabilities(true)
@@ -90,6 +91,8 @@ public void shouldReflectSetFlags() {
9091
| Context.BIND_INCLUDE_CAPABILITIES
9192
| Context.BIND_NOT_FOREGROUND
9293
| Context.BIND_NOT_PERCEPTIBLE
93-
| Context.BIND_WAIVE_PRIORITY);
94+
| Context.BIND_WAIVE_PRIORITY
95+
// TODO(b/274061424): Use Context.BIND_ALLOW_ACTIVITY_STARTS when U is final.
96+
| 0x200);
9497
}
9598
}

0 commit comments

Comments
 (0)