Skip to content

Commit dece3ca

Browse files
committed
Android : Addressed review comments and reformat code (issue 6868)
1 parent b0188f0 commit dece3ca

File tree

3 files changed

+27
-29
lines changed

3 files changed

+27
-29
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717
package io.grpc.binder;
1818

1919
import static android.content.Intent.URI_ANDROID_APP_SCHEME;
20-
import static android.content.Intent.URI_INTENT_SCHEME;
2120
import static com.google.common.base.Preconditions.checkArgument;
2221
import static com.google.common.base.Preconditions.checkState;
2322

24-
import android.annotation.SuppressLint;
2523
import android.content.ComponentName;
2624
import android.content.Context;
2725
import android.content.Intent;
28-
import android.os.Build;
2926
import android.os.UserHandle;
3027
import com.google.common.base.Objects;
3128
import io.grpc.ExperimentalApi;
@@ -175,8 +172,7 @@ public String asAndroidAppUri() {
175172
// factory methods. Oddly, a ComponentName is not enough.
176173
intentForUri = intentForUri.cloneFilter().setPackage(getComponent().getPackageName());
177174
}
178-
return intentForUri.toUri(
179-
URI_ANDROID_APP_SCHEME);
175+
return intentForUri.toUri(URI_ANDROID_APP_SCHEME);
180176
}
181177

182178
@Override

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,23 +196,23 @@ private static Status bindInternal(
196196
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
197197
bindResult = context.bindServiceAsUser(bindIntent, conn, flags, targetUserHandle);
198198
} else {
199-
return Status.INTERNAL.
200-
withDescription("Cross user Channel requires Android R+");
199+
return Status.INTERNAL.withDescription("Cross user Channel requires Android R+");
201200
}
202201
break;
203202
case DEVICE_POLICY_BIND_SEVICE_ADMIN:
204203
DevicePolicyManager devicePolicyManager =
205-
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
204+
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
206205
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
207-
bindResult = devicePolicyManager.bindDeviceAdminServiceAsUser(
208-
channelCredentials.getDevicePolicyAdminComponentName(),
209-
bindIntent,
210-
conn,
211-
flags,
212-
targetUserHandle);
206+
bindResult =
207+
devicePolicyManager.bindDeviceAdminServiceAsUser(
208+
channelCredentials.getDevicePolicyAdminComponentName(),
209+
bindIntent,
210+
conn,
211+
flags,
212+
targetUserHandle);
213213
} else {
214-
return Status.INTERNAL.
215-
withDescription("Device policy admin binding requires Android R+");
214+
return Status.INTERNAL.withDescription(
215+
"Device policy admin binding requires Android R+");
216216
}
217217
break;
218218
}

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
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;
2524
import static org.robolectric.Shadows.shadowOf;
2625

2726
import android.app.Application;
@@ -331,8 +330,8 @@ public void testResolveNonExistentServiceWithTargetUserThrows() throws Exception
331330

332331
@Test
333332
@Config(sdk = 30)
334-
public void testBindService_doesNotThrowInternalErrorWhenSDkAtLeastR() {
335-
UserHandle userHandle = mock(UserHandle.class);
333+
public void testBindService_doesNotThrowInternalErrorWhenSdkAtLeastR() {
334+
UserHandle userHandle = generateUserHandle(/* userId= */ 12345);
336335
binding = newBuilder().setTargetUserHandle(userHandle).build();
337336
binding.bind();
338337
shadowOf(getMainLooper()).idle();
@@ -343,31 +342,34 @@ public void testBindService_doesNotThrowInternalErrorWhenSDkAtLeastR() {
343342

344343
@Test
345344
@Config(sdk = 28)
346-
public void testBindServiceAsUser_returnsErrorWhenSDkBelowR() {
347-
UserHandle userHandle = mock(UserHandle.class);
345+
public void testBindServiceAsUser_returnsErrorWhenSdkBelowR() {
346+
UserHandle userHandle = generateUserHandle(/* userId= */ 12345);
348347
binding = newBuilder().setTargetUserHandle(userHandle).build();
349348
binding.bind();
350349
shadowOf(getMainLooper()).idle();
351350

352351
assertThat(observer.unboundReason.getCode()).isEqualTo(Code.INTERNAL);
353-
assertThat(observer.unboundReason.getDescription()).isEqualTo("Cross user Channel requires Android R+");
352+
assertThat(observer.unboundReason.getDescription())
353+
.isEqualTo("Cross user Channel requires Android R+");
354354
}
355355

356356
@Test
357357
@Config(sdk = 28)
358-
public void testDevicePolicyBlind_returnsErrorWhenSDkBelowR() {
358+
public void testDevicePolicyBlind_returnsErrorWhenSdkBelowR() {
359359
String deviceAdminClassName = "DevicePolicyAdmin";
360360
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();
361+
allowBindDeviceAdminForUser(appContext, adminComponent, 10);
362+
binding =
363+
newBuilder()
364+
.setTargetUserHandle(UserHandle.getUserHandleForUid(10))
365+
.setChannelCredentials(BinderChannelCredentials.forDevicePolicyAdmin(adminComponent))
366+
.build();
366367
binding.bind();
367368
shadowOf(getMainLooper()).idle();
368369

369370
assertThat(observer.unboundReason.getCode()).isEqualTo(Code.INTERNAL);
370-
assertThat(observer.unboundReason.getDescription()).isEqualTo("Device policy admin binding requires Android R+");
371+
assertThat(observer.unboundReason.getDescription())
372+
.isEqualTo("Device policy admin binding requires Android R+");
371373
}
372374

373375
@Test

0 commit comments

Comments
 (0)