Merge "Also skip calling ShortcutManager APIs if work user is locked" into rvc-dev

This commit is contained in:
Antoan Angelov
2020-06-29 16:32:25 +00:00
committed by Android (Google) Code Review
3 changed files with 88 additions and 2 deletions

View File

@@ -2040,6 +2040,9 @@ public class ChooserActivity extends ResolverActivity implements
if (!isUserRunning(userHandle)) {
return false;
}
if (!isUserUnlocked(userHandle)) {
return false;
}
if (isQuietModeEnabled(userHandle)) {
return false;
}
@@ -2891,6 +2894,12 @@ public class ChooserActivity extends ResolverActivity implements
return userManager.isUserRunning(userHandle);
}
@VisibleForTesting
protected boolean isUserUnlocked(UserHandle userHandle) {
UserManager userManager = getSystemService(UserManager.class);
return userManager.isUserUnlocked(userHandle);
}
@VisibleForTesting
protected boolean isQuietModeEnabled(UserHandle userHandle) {
UserManager userManager = getSystemService(UserManager.class);

View File

@@ -1996,7 +1996,7 @@ public class ChooserActivityTest {
}
@Test
public void testWorkTab_selectingWorkTabWithLockedWorkUser_directShareTargetsNotQueried() {
public void testWorkTab_selectingWorkTabWithNotRunningWorkUser_directShareTargetsNotQueried() {
// enable the work tab feature flag
ResolverActivity.ENABLE_TABBED_VIEW = true;
markWorkProfileUserAvailable();
@@ -2034,6 +2034,70 @@ public class ChooserActivityTest {
isQueryTargetServicesCalledOnWorkProfile[0]);
}
@Test
public void testWorkTab_workUserNotRunning_workTargetsShown() {
// enable the work tab feature flag
ResolverActivity.ENABLE_TABBED_VIEW = true;
markWorkProfileUserAvailable();
List<ResolvedComponentInfo> personalResolvedComponentInfos =
createResolvedComponentsForTestWithOtherProfile(3, /* userId */ 10);
List<ResolvedComponentInfo> workResolvedComponentInfos =
createResolvedComponentsForTest(3);
setupResolverControllers(personalResolvedComponentInfos, workResolvedComponentInfos);
Intent sendIntent = createSendTextIntent();
sendIntent.setType("TestType");
sOverrides.isWorkProfileUserRunning = false;
final ChooserWrapperActivity activity =
mActivityRule.launchActivity(Intent.createChooser(sendIntent, "work tab test"));
waitForIdle();
onView(withId(R.id.contentPanel))
.perform(swipeUp());
onView(withText(R.string.resolver_work_tab)).perform(click());
waitForIdle();
assertEquals(3, activity.getWorkListAdapter().getCount());
}
@Test
public void testWorkTab_selectingWorkTabWithLockedWorkUser_directShareTargetsNotQueried() {
// enable the work tab feature flag
ResolverActivity.ENABLE_TABBED_VIEW = true;
markWorkProfileUserAvailable();
List<ResolvedComponentInfo> personalResolvedComponentInfos =
createResolvedComponentsForTestWithOtherProfile(3, /* userId */ 10);
List<ResolvedComponentInfo> workResolvedComponentInfos =
createResolvedComponentsForTest(3);
setupResolverControllers(personalResolvedComponentInfos, workResolvedComponentInfos);
sOverrides.isWorkProfileUserUnlocked = false;
boolean[] isQueryDirectShareCalledOnWorkProfile = new boolean[] { false };
sOverrides.onQueryDirectShareTargets = chooserListAdapter -> {
isQueryDirectShareCalledOnWorkProfile[0] =
(chooserListAdapter.getUserHandle().getIdentifier() == 10);
return null;
};
boolean[] isQueryTargetServicesCalledOnWorkProfile = new boolean[] { false };
sOverrides.onQueryTargetServices = chooserListAdapter -> {
isQueryTargetServicesCalledOnWorkProfile[0] =
(chooserListAdapter.getUserHandle().getIdentifier() == 10);
return null;
};
Intent sendIntent = createSendTextIntent();
sendIntent.setType("TestType");
mActivityRule.launchActivity(Intent.createChooser(sendIntent, "work tab test"));
waitForIdle();
onView(withId(R.id.contentPanel))
.perform(swipeUp());
onView(withText(R.string.resolver_work_tab)).perform(click());
waitForIdle();
assertFalse("Direct share targets were queried on a locked work profile user",
isQueryDirectShareCalledOnWorkProfile[0]);
assertFalse("Target services were queried on a locked work profile user",
isQueryTargetServicesCalledOnWorkProfile[0]);
}
@Test
public void testWorkTab_workUserLocked_workTargetsShown() {
// enable the work tab feature flag
@@ -2046,7 +2110,7 @@ public class ChooserActivityTest {
setupResolverControllers(personalResolvedComponentInfos, workResolvedComponentInfos);
Intent sendIntent = createSendTextIntent();
sendIntent.setType("TestType");
sOverrides.isWorkProfileUserRunning = false;
sOverrides.isWorkProfileUserUnlocked = false;
final ChooserWrapperActivity activity =
mActivityRule.launchActivity(Intent.createChooser(sendIntent, "work tab test"));

View File

@@ -229,9 +229,20 @@ public class ChooserWrapperActivity extends ChooserActivity {
@Override
protected boolean isUserRunning(UserHandle userHandle) {
if (userHandle.equals(UserHandle.SYSTEM)) {
return super.isUserRunning(userHandle);
}
return sOverrides.isWorkProfileUserRunning;
}
@Override
protected boolean isUserUnlocked(UserHandle userHandle) {
if (userHandle.equals(UserHandle.SYSTEM)) {
return super.isUserUnlocked(userHandle);
}
return sOverrides.isWorkProfileUserUnlocked;
}
/**
* We cannot directly mock the activity created since instrumentation creates it.
* <p>
@@ -258,6 +269,7 @@ public class ChooserWrapperActivity extends ChooserActivity {
public boolean hasCrossProfileIntents;
public boolean isQuietModeEnabled;
public boolean isWorkProfileUserRunning;
public boolean isWorkProfileUserUnlocked;
public AbstractMultiProfilePagerAdapter.Injector multiPagerAdapterInjector;
public PackageManager packageManager;
@@ -281,6 +293,7 @@ public class ChooserWrapperActivity extends ChooserActivity {
hasCrossProfileIntents = true;
isQuietModeEnabled = false;
isWorkProfileUserRunning = true;
isWorkProfileUserUnlocked = true;
packageManager = null;
multiPagerAdapterInjector = new AbstractMultiProfilePagerAdapter.Injector() {
@Override