Merge "Also skip calling ShortcutManager APIs if work user is locked" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
625ada924d
@@ -2040,6 +2040,9 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
if (!isUserRunning(userHandle)) {
|
if (!isUserRunning(userHandle)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!isUserUnlocked(userHandle)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (isQuietModeEnabled(userHandle)) {
|
if (isQuietModeEnabled(userHandle)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2891,6 +2894,12 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
return userManager.isUserRunning(userHandle);
|
return userManager.isUserRunning(userHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
protected boolean isUserUnlocked(UserHandle userHandle) {
|
||||||
|
UserManager userManager = getSystemService(UserManager.class);
|
||||||
|
return userManager.isUserUnlocked(userHandle);
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected boolean isQuietModeEnabled(UserHandle userHandle) {
|
protected boolean isQuietModeEnabled(UserHandle userHandle) {
|
||||||
UserManager userManager = getSystemService(UserManager.class);
|
UserManager userManager = getSystemService(UserManager.class);
|
||||||
|
|||||||
@@ -1996,7 +1996,7 @@ public class ChooserActivityTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWorkTab_selectingWorkTabWithLockedWorkUser_directShareTargetsNotQueried() {
|
public void testWorkTab_selectingWorkTabWithNotRunningWorkUser_directShareTargetsNotQueried() {
|
||||||
// enable the work tab feature flag
|
// enable the work tab feature flag
|
||||||
ResolverActivity.ENABLE_TABBED_VIEW = true;
|
ResolverActivity.ENABLE_TABBED_VIEW = true;
|
||||||
markWorkProfileUserAvailable();
|
markWorkProfileUserAvailable();
|
||||||
@@ -2034,6 +2034,70 @@ public class ChooserActivityTest {
|
|||||||
isQueryTargetServicesCalledOnWorkProfile[0]);
|
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
|
@Test
|
||||||
public void testWorkTab_workUserLocked_workTargetsShown() {
|
public void testWorkTab_workUserLocked_workTargetsShown() {
|
||||||
// enable the work tab feature flag
|
// enable the work tab feature flag
|
||||||
@@ -2046,7 +2110,7 @@ public class ChooserActivityTest {
|
|||||||
setupResolverControllers(personalResolvedComponentInfos, workResolvedComponentInfos);
|
setupResolverControllers(personalResolvedComponentInfos, workResolvedComponentInfos);
|
||||||
Intent sendIntent = createSendTextIntent();
|
Intent sendIntent = createSendTextIntent();
|
||||||
sendIntent.setType("TestType");
|
sendIntent.setType("TestType");
|
||||||
sOverrides.isWorkProfileUserRunning = false;
|
sOverrides.isWorkProfileUserUnlocked = false;
|
||||||
|
|
||||||
final ChooserWrapperActivity activity =
|
final ChooserWrapperActivity activity =
|
||||||
mActivityRule.launchActivity(Intent.createChooser(sendIntent, "work tab test"));
|
mActivityRule.launchActivity(Intent.createChooser(sendIntent, "work tab test"));
|
||||||
|
|||||||
@@ -229,9 +229,20 @@ public class ChooserWrapperActivity extends ChooserActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isUserRunning(UserHandle userHandle) {
|
protected boolean isUserRunning(UserHandle userHandle) {
|
||||||
|
if (userHandle.equals(UserHandle.SYSTEM)) {
|
||||||
|
return super.isUserRunning(userHandle);
|
||||||
|
}
|
||||||
return sOverrides.isWorkProfileUserRunning;
|
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.
|
* We cannot directly mock the activity created since instrumentation creates it.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -258,6 +269,7 @@ public class ChooserWrapperActivity extends ChooserActivity {
|
|||||||
public boolean hasCrossProfileIntents;
|
public boolean hasCrossProfileIntents;
|
||||||
public boolean isQuietModeEnabled;
|
public boolean isQuietModeEnabled;
|
||||||
public boolean isWorkProfileUserRunning;
|
public boolean isWorkProfileUserRunning;
|
||||||
|
public boolean isWorkProfileUserUnlocked;
|
||||||
public AbstractMultiProfilePagerAdapter.Injector multiPagerAdapterInjector;
|
public AbstractMultiProfilePagerAdapter.Injector multiPagerAdapterInjector;
|
||||||
public PackageManager packageManager;
|
public PackageManager packageManager;
|
||||||
|
|
||||||
@@ -281,6 +293,7 @@ public class ChooserWrapperActivity extends ChooserActivity {
|
|||||||
hasCrossProfileIntents = true;
|
hasCrossProfileIntents = true;
|
||||||
isQuietModeEnabled = false;
|
isQuietModeEnabled = false;
|
||||||
isWorkProfileUserRunning = true;
|
isWorkProfileUserRunning = true;
|
||||||
|
isWorkProfileUserUnlocked = true;
|
||||||
packageManager = null;
|
packageManager = null;
|
||||||
multiPagerAdapterInjector = new AbstractMultiProfilePagerAdapter.Injector() {
|
multiPagerAdapterInjector = new AbstractMultiProfilePagerAdapter.Injector() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user