Expose role API for Settings on RoleManager.

Settings is a platform app so the role APIs for it wasn't system APIs,
but just @hide. Now that we are moving role into module, we need to
create system APIs for them.

RoleControllerManager is an implementation detail and may change in
soon when we move role logic into system server and leave only UI in
PermissionController, so we shouldn't expose it. Instead, we can
expose the new system APIs on RoleManager, and delegate to
RoleControllerManager internally.

Bug: 158736025
Test: presubmit
Test: atest DefaultSmsShortcutPreferenceControllerTest
Change-Id: Iafe1d24601a32799e04d9aa385ec2fbce833a02e
This commit is contained in:
Hai Zhang
2020-12-22 21:17:33 -08:00
parent af1fbb77e3
commit a8bd0d263f
7 changed files with 17 additions and 33 deletions

View File

@@ -25,7 +25,6 @@ import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
import android.app.Activity;
import android.app.role.RoleControllerManager;
import android.app.role.RoleManager;
import android.content.Context;
import android.content.Intent;
@@ -63,8 +62,6 @@ public class DefaultAppShortcutPreferenceControllerBaseTest {
@Mock
private RoleManager mRoleManager;
@Mock
private RoleControllerManager mRoleControllerManager;
@Mock
private Preference mPreference;
private Activity mActivity;
@@ -77,7 +74,6 @@ public class DefaultAppShortcutPreferenceControllerBaseTest {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
shadowApplication.setSystemService(Context.ROLE_SERVICE, mRoleManager);
shadowApplication.setSystemService(Context.ROLE_CONTROLLER_SERVICE, mRoleControllerManager);
mActivity = Robolectric.setupActivity(Activity.class);
mShadowUserManager = shadowOf(mActivity.getSystemService(UserManager.class));
mController = new TestRolePreferenceController(mActivity);
@@ -86,7 +82,7 @@ public class DefaultAppShortcutPreferenceControllerBaseTest {
@Test
public void constructor_callsIsApplicationVisibleForRole() {
verify(mRoleControllerManager).isApplicationVisibleForRole(eq(TEST_ROLE_NAME), eq(
verify(mRoleManager).isApplicationVisibleForRole(eq(TEST_ROLE_NAME), eq(
TEST_PACKAGE_NAME), any(Executor.class), any(Consumer.class));
}
@@ -153,7 +149,7 @@ public class DefaultAppShortcutPreferenceControllerBaseTest {
private void setRoleIsVisible(boolean visible) {
final ArgumentCaptor<Consumer<Boolean>> callbackCaptor = ArgumentCaptor.forClass(
Consumer.class);
verify(mRoleControllerManager).isRoleVisible(eq(TEST_ROLE_NAME), any(Executor.class),
verify(mRoleManager).isRoleVisible(eq(TEST_ROLE_NAME), any(Executor.class),
callbackCaptor.capture());
final Consumer<Boolean> callback = callbackCaptor.getValue();
callback.accept(visible);
@@ -162,7 +158,7 @@ public class DefaultAppShortcutPreferenceControllerBaseTest {
private void setApplicationIsVisibleForRole(boolean visible) {
final ArgumentCaptor<Consumer<Boolean>> callbackCaptor = ArgumentCaptor.forClass(
Consumer.class);
verify(mRoleControllerManager).isApplicationVisibleForRole(eq(TEST_ROLE_NAME), eq(
verify(mRoleManager).isApplicationVisibleForRole(eq(TEST_ROLE_NAME), eq(
TEST_PACKAGE_NAME), any(Executor.class), callbackCaptor.capture());
final Consumer<Boolean> callback = callbackCaptor.getValue();
callback.accept(visible);

View File

@@ -18,7 +18,7 @@ package com.android.settings.applications.appinfo;
import static com.google.common.truth.Truth.assertThat;
import android.app.role.RoleControllerManager;
import android.app.role.RoleManager;
import android.content.Context;
import org.junit.Before;
@@ -34,15 +34,14 @@ import org.robolectric.shadows.ShadowApplication;
public class DefaultBrowserShortcutPreferenceControllerTest {
@Mock
private RoleControllerManager mRoleControllerManager;
private RoleManager mRoleManager;
private DefaultBrowserShortcutPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowApplication.getInstance().setSystemService(Context.ROLE_CONTROLLER_SERVICE,
mRoleControllerManager);
ShadowApplication.getInstance().setSystemService(Context.ROLE_SERVICE, mRoleManager);
mController = new DefaultBrowserShortcutPreferenceController(RuntimeEnvironment.application,
"Package1");
}

View File

@@ -18,7 +18,7 @@ package com.android.settings.applications.appinfo;
import static com.google.common.truth.Truth.assertThat;
import android.app.role.RoleControllerManager;
import android.app.role.RoleManager;
import android.content.Context;
import org.junit.Before;
@@ -34,15 +34,14 @@ import org.robolectric.shadows.ShadowApplication;
public class DefaultEmergencyShortcutPreferenceControllerTest {
@Mock
private RoleControllerManager mRoleControllerManager;
private RoleManager mRoleManager;
private DefaultEmergencyShortcutPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowApplication.getInstance().setSystemService(Context.ROLE_CONTROLLER_SERVICE,
mRoleControllerManager);
ShadowApplication.getInstance().setSystemService(Context.ROLE_SERVICE, mRoleManager);
mController = new DefaultEmergencyShortcutPreferenceController(
RuntimeEnvironment.application, "Package1");
}

View File

@@ -18,7 +18,7 @@ package com.android.settings.applications.appinfo;
import static com.google.common.truth.Truth.assertThat;
import android.app.role.RoleControllerManager;
import android.app.role.RoleManager;
import android.content.Context;
import org.junit.Before;
@@ -34,15 +34,14 @@ import org.robolectric.shadows.ShadowApplication;
public class DefaultHomeShortcutPreferenceControllerTest {
@Mock
private RoleControllerManager mRoleControllerManager;
private RoleManager mRoleManager;
private DefaultHomeShortcutPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowApplication.getInstance().setSystemService(Context.ROLE_CONTROLLER_SERVICE,
mRoleControllerManager);
ShadowApplication.getInstance().setSystemService(Context.ROLE_SERVICE, mRoleManager);
mController = new DefaultHomeShortcutPreferenceController(RuntimeEnvironment.application,
"Package1");
}

View File

@@ -18,7 +18,7 @@ package com.android.settings.applications.appinfo;
import static com.google.common.truth.Truth.assertThat;
import android.app.role.RoleControllerManager;
import android.app.role.RoleManager;
import android.content.Context;
import org.junit.Before;
@@ -37,15 +37,14 @@ public class DefaultPhoneShortcutPreferenceControllerTest {
private static final String PREFERENCE_KEY = "default_phone_app";
@Mock
private RoleControllerManager mRoleControllerManager;
private RoleManager mRoleManager;
private DefaultPhoneShortcutPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowApplication.getInstance().setSystemService(Context.ROLE_CONTROLLER_SERVICE,
mRoleControllerManager);
ShadowApplication.getInstance().setSystemService(Context.ROLE_SERVICE, mRoleManager);
mController = new DefaultPhoneShortcutPreferenceController(RuntimeEnvironment.application,
TEST_PACKAGE_NAME);
}

View File

@@ -18,7 +18,6 @@ package com.android.settings.applications.appinfo;
import static com.google.common.truth.Truth.assertThat;
import android.app.role.RoleControllerManager;
import android.app.role.RoleManager;
import android.content.Context;
@@ -39,8 +38,6 @@ public class DefaultSmsShortcutPreferenceControllerTest {
@Mock
private RoleManager mRoleManager;
@Mock
private RoleControllerManager mRoleControllerManager;
private DefaultSmsShortcutPreferenceController mController;
@@ -49,7 +46,6 @@ public class DefaultSmsShortcutPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
final ShadowApplication shadowApplication = ShadowApplication.getInstance();
shadowApplication.setSystemService(Context.ROLE_SERVICE, mRoleManager);
shadowApplication.setSystemService(Context.ROLE_CONTROLLER_SERVICE, mRoleControllerManager);
mController = new DefaultSmsShortcutPreferenceController(RuntimeEnvironment.application,
TEST_PACKAGE_NAME);
}