Skip to content

Commit 637fc04

Browse files
committed
Android : Worked on review comments (Binder)
1 parent 02998c9 commit 637fc04

7 files changed

Lines changed: 58 additions & 7 deletions

File tree

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ android {
1414
}
1515
compileSdkVersion 34
1616
defaultConfig {
17-
minSdkVersion 21
17+
minSdkVersion 22
1818
targetSdkVersion 33
1919
versionCode 1
2020
versionName "1.0"

binder/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ android {
1313
targetCompatibility 1.8
1414
}
1515
defaultConfig {
16-
minSdkVersion 21
16+
minSdkVersion 22
1717
targetSdkVersion 33
1818
versionCode 1
1919
versionName "1.0"

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ public String asAndroidAppUri() {
176176
intentForUri = intentForUri.cloneFilter().setPackage(getComponent().getPackageName());
177177
}
178178
return intentForUri.toUri(
179-
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1
180-
? URI_ANDROID_APP_SCHEME
181-
: URI_INTENT_SCHEME);
179+
URI_ANDROID_APP_SCHEME);
182180
}
183181

184182
@Override

binder/src/main/java/io/grpc/binder/internal/ServiceBinding.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,18 +195,24 @@ private static Status bindInternal(
195195
case BIND_SERVICE_AS_USER:
196196
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
197197
bindResult = context.bindServiceAsUser(bindIntent, conn, flags, targetUserHandle);
198+
} else {
199+
return Status.INTERNAL.
200+
withDescription("Cross user Channel requires Android R+");
198201
}
199202
break;
200203
case DEVICE_POLICY_BIND_SEVICE_ADMIN:
201204
DevicePolicyManager devicePolicyManager =
202205
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
203-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
206+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
204207
bindResult = devicePolicyManager.bindDeviceAdminServiceAsUser(
205208
channelCredentials.getDevicePolicyAdminComponentName(),
206209
bindIntent,
207210
conn,
208211
flags,
209212
targetUserHandle);
213+
} else {
214+
return Status.INTERNAL.
215+
withDescription("Device policy admin binding requires Android R+");
210216
}
211217
break;
212218
}

binder/src/test/java/io/grpc/binder/internal/ServiceBindingTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static com.google.common.truth.Truth.assertThat;
2222
import static org.junit.Assert.assertThrows;
2323
import static org.junit.Assert.fail;
24+
import static org.mockito.Mockito.mock;
2425
import static org.robolectric.Shadows.shadowOf;
2526

2627
import android.app.Application;
@@ -29,6 +30,7 @@
2930
import android.content.Context;
3031
import android.content.Intent;
3132
import android.content.pm.ServiceInfo;
33+
import android.os.Build;
3234
import android.os.IBinder;
3335
import android.os.Parcel;
3436
import android.os.UserHandle;
@@ -327,6 +329,47 @@ public void testResolveNonExistentServiceWithTargetUserThrows() throws Exception
327329
assertThat(statusException.getStatus().getDescription()).contains("12345");
328330
}
329331

332+
@Test
333+
@Config(sdk = 30)
334+
public void testBindService_doesNotThrowInternalErrorWhenSDkAtLeastR() {
335+
UserHandle userHandle = mock(UserHandle.class);
336+
binding = newBuilder().setTargetUserHandle(userHandle).build();
337+
binding.bind();
338+
shadowOf(getMainLooper()).idle();
339+
340+
assertThat(Build.VERSION.SDK_INT).isEqualTo(Build.VERSION_CODES.R);
341+
assertThat(observer.unboundReason).isNull();
342+
}
343+
344+
@Test
345+
@Config(sdk = 28)
346+
public void testBindServiceAsUser_returnsErrorWhenSDkBelowR() {
347+
UserHandle userHandle = mock(UserHandle.class);
348+
binding = newBuilder().setTargetUserHandle(userHandle).build();
349+
binding.bind();
350+
shadowOf(getMainLooper()).idle();
351+
352+
assertThat(observer.unboundReason.getCode()).isEqualTo(Code.INTERNAL);
353+
assertThat(observer.unboundReason.getDescription()).isEqualTo("Cross user Channel requires Android R+");
354+
}
355+
356+
@Test
357+
@Config(sdk = 28)
358+
public void testDevicePolicyBlind_returnsErrorWhenSDkBelowR() {
359+
String deviceAdminClassName = "DevicePolicyAdmin";
360+
ComponentName adminComponent = new ComponentName(appContext, deviceAdminClassName);
361+
allowBindDeviceAdminForUser(appContext, adminComponent,10);
362+
binding = newBuilder()
363+
.setTargetUserHandle(UserHandle.getUserHandleForUid(10))
364+
.setChannelCredentials(BinderChannelCredentials.forDevicePolicyAdmin(adminComponent))
365+
.build();
366+
binding.bind();
367+
shadowOf(getMainLooper()).idle();
368+
369+
assertThat(observer.unboundReason.getCode()).isEqualTo(Code.INTERNAL);
370+
assertThat(observer.unboundReason.getDescription()).isEqualTo("Device policy admin binding requires Android R+");
371+
}
372+
330373
@Test
331374
@Config(sdk = 30)
332375
public void testBindWithDeviceAdmin() throws Exception {

cronet/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ android {
1414
namespace = 'io.grpc.cronet'
1515
compileSdkVersion 33
1616
defaultConfig {
17-
minSdkVersion 21
17+
minSdkVersion 22
1818
targetSdkVersion 33
1919
versionCode 1
2020
versionName "1.0"

lint.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<lint>
3+
<!--
4+
Suppress temporarily due to AAPT2 failures with SDK 35/36 on AGP 7.x.
5+
Remove after AGP upgrade.
6+
-->
37
<issue id="OldTargetApi" severity="ignore" />
48
</lint>

0 commit comments

Comments
 (0)