Merge "Don't call ShortcutManager APIs if the work profile is paused or locked" into rvc-dev am: 054a8e32c1
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12000922 Change-Id: I3ce4706ced411401886e457b85652fb73db5bf70
This commit is contained in:
@@ -819,7 +819,8 @@ public class ChooserActivity extends ResolverActivity implements
|
||||
if (chooserListAdapter.getCount() == 0) {
|
||||
return;
|
||||
}
|
||||
if (resultList.isEmpty()) {
|
||||
if (resultList.isEmpty()
|
||||
&& shouldQueryShortcutManager(chooserListAdapter.getUserHandle())) {
|
||||
// APS may be disabled, so try querying targets ourselves.
|
||||
queryDirectShareTargets(chooserListAdapter, true);
|
||||
return;
|
||||
@@ -2025,6 +2026,26 @@ public class ChooserActivity extends ResolverActivity implements
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code false} if {@code userHandle} is the work profile and it's either
|
||||
* in quiet mode or not running.
|
||||
*/
|
||||
private boolean shouldQueryShortcutManager(UserHandle userHandle) {
|
||||
if (!shouldShowTabs()) {
|
||||
return true;
|
||||
}
|
||||
if (!getWorkProfileUserHandle().equals(userHandle)) {
|
||||
return true;
|
||||
}
|
||||
if (!isUserRunning(userHandle)) {
|
||||
return false;
|
||||
}
|
||||
if (isQuietModeEnabled(userHandle)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sendChooserTargetRankingScore(List<AppTarget> chooserTargetScores,
|
||||
UserHandle userHandle) {
|
||||
final Message msg = Message.obtain();
|
||||
@@ -2839,8 +2860,8 @@ public class ChooserActivity extends ResolverActivity implements
|
||||
return;
|
||||
}
|
||||
|
||||
// no need to query direct share for work profile when its turned off
|
||||
if (isQuietModeEnabled(chooserListAdapter.getUserHandle())) {
|
||||
// no need to query direct share for work profile when its locked or disabled
|
||||
if (!shouldQueryShortcutManager(chooserListAdapter.getUserHandle())) {
|
||||
getChooserActivityLogger().logSharesheetAppLoadComplete();
|
||||
return;
|
||||
}
|
||||
@@ -2864,6 +2885,12 @@ public class ChooserActivity extends ResolverActivity implements
|
||||
getChooserActivityLogger().logSharesheetAppLoadComplete();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected boolean isUserRunning(UserHandle userHandle) {
|
||||
UserManager userManager = getSystemService(UserManager.class);
|
||||
return userManager.isUserRunning(userHandle);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected boolean isQuietModeEnabled(UserHandle userHandle) {
|
||||
UserManager userManager = getSystemService(UserManager.class);
|
||||
|
||||
@@ -1995,6 +1995,70 @@ public class ChooserActivityTest {
|
||||
isQueryTargetServicesCalledOnWorkProfile[0]);
|
||||
}
|
||||
|
||||
@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.isWorkProfileUserRunning = 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
|
||||
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());
|
||||
}
|
||||
|
||||
private Intent createChooserIntent(Intent intent, Intent[] initialIntents) {
|
||||
Intent chooserIntent = new Intent();
|
||||
chooserIntent.setAction(Intent.ACTION_CHOOSER);
|
||||
|
||||
@@ -227,6 +227,11 @@ public class ChooserWrapperActivity extends ChooserActivity {
|
||||
return sOverrides.isQuietModeEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isUserRunning(UserHandle userHandle) {
|
||||
return sOverrides.isWorkProfileUserRunning;
|
||||
}
|
||||
|
||||
/**
|
||||
* We cannot directly mock the activity created since instrumentation creates it.
|
||||
* <p>
|
||||
@@ -252,6 +257,7 @@ public class ChooserWrapperActivity extends ChooserActivity {
|
||||
public UserHandle workProfileUserHandle;
|
||||
public boolean hasCrossProfileIntents;
|
||||
public boolean isQuietModeEnabled;
|
||||
public boolean isWorkProfileUserRunning;
|
||||
public AbstractMultiProfilePagerAdapter.Injector multiPagerAdapterInjector;
|
||||
public PackageManager packageManager;
|
||||
|
||||
@@ -274,6 +280,7 @@ public class ChooserWrapperActivity extends ChooserActivity {
|
||||
workProfileUserHandle = null;
|
||||
hasCrossProfileIntents = true;
|
||||
isQuietModeEnabled = false;
|
||||
isWorkProfileUserRunning = true;
|
||||
packageManager = null;
|
||||
multiPagerAdapterInjector = new AbstractMultiProfilePagerAdapter.Injector() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user