Autolaunch when active tab has 1 target and inactive tab has 0 targets.

Also fixes bug where we autolaunch without waiting for the inactive
tab list to load. If the inactive tab's targets are 0 since they
are not loaded, if the active tab's targets are 1, it would
incorrectly autolaunch.

Test: manually tried attaching a file in gmail with no cross-profile
intents
Fixes: 149383054
Change-Id: I1a2455088762dce7265ae4b7ad2c6bc8b217f99e
This commit is contained in:
arangelov
2020-02-12 15:03:22 +00:00
parent 590fba384a
commit f6986d4809
2 changed files with 32 additions and 8 deletions

View File

@@ -1278,10 +1278,9 @@ public class ResolverActivity extends Activity implements
throw new IllegalStateException("mMultiProfilePagerAdapter.getCurrentListAdapter() "
+ "cannot be null.");
}
boolean rebuildCompleted = mMultiProfilePagerAdapter.rebuildActiveTab(true);
// We partially rebuild the inactive adapter to determine if we should auto launch
mMultiProfilePagerAdapter.rebuildInactiveTab(false);
boolean rebuildActiveCompleted = mMultiProfilePagerAdapter.rebuildActiveTab(true);
boolean rebuildInactiveCompleted = mMultiProfilePagerAdapter.rebuildInactiveTab(false);
if (useLayoutWithDefault()) {
mLayoutId = R.layout.resolver_list_with_default;
@@ -1290,7 +1289,7 @@ public class ResolverActivity extends Activity implements
}
setContentView(mLayoutId);
mMultiProfilePagerAdapter.setupViewPager(findViewById(R.id.profile_pager));
return postRebuildList(rebuildCompleted);
return postRebuildList(rebuildActiveCompleted && rebuildInactiveCompleted);
}
/**
@@ -1338,10 +1337,11 @@ public class ResolverActivity extends Activity implements
int numberOfProfiles = mMultiProfilePagerAdapter.getItemCount();
if (numberOfProfiles == 1 && maybeAutolaunchIfSingleTarget()) {
return true;
} else if (numberOfProfiles == 2 && maybeAutolaunchIfCrossProfileSupported()) {
// note that autolaunching when we have 2 profiles, 1 resolved target on the active
// tab and 0 resolved targets on the inactive tab, is already handled before launching
// ResolverActivity
} else if (numberOfProfiles == 2
&& mMultiProfilePagerAdapter.getActiveListAdapter().isListLoaded()
&& mMultiProfilePagerAdapter.getInactiveListAdapter().isListLoaded()
&& (maybeAutolaunchIfNoAppsOnInactiveTab()
|| maybeAutolaunchIfCrossProfileSupported())) {
return true;
}
return false;
@@ -1364,6 +1364,23 @@ public class ResolverActivity extends Activity implements
return false;
}
private boolean maybeAutolaunchIfNoAppsOnInactiveTab() {
int count = mMultiProfilePagerAdapter.getActiveListAdapter().getUnfilteredCount();
if (count != 1) {
return false;
}
ResolverListAdapter inactiveListAdapter =
mMultiProfilePagerAdapter.getInactiveListAdapter();
if (inactiveListAdapter.getUnfilteredCount() != 0) {
return false;
}
TargetInfo target = mMultiProfilePagerAdapter.getActiveListAdapter()
.targetInfoForPosition(0, false);
safelyStartActivity(target);
finish();
return true;
}
/**
* When we have a personal and a work profile, we auto launch in the following scenario:
* - There is 1 resolved target on each profile

View File

@@ -87,6 +87,7 @@ public class ResolverListAdapter extends BaseAdapter {
private final ResolverListCommunicator mResolverListCommunicator;
private Runnable mPostListReadyRunnable;
private final boolean mIsAudioCaptureDevice;
private boolean mIsListLoaded;
public ResolverListAdapter(Context context, List<Intent> payloadIntents,
Intent[] initialIntents, List<ResolveInfo> rList,
@@ -191,6 +192,7 @@ public class ResolverListAdapter extends BaseAdapter {
mLastChosenPosition = -1;
mAllTargetsAreBrowsers = false;
mDisplayList.clear();
mIsListLoaded = false;
if (mBaseResolveList != null) {
currentResolveList = mUnfilteredResolveList = new ArrayList<>();
@@ -352,6 +354,7 @@ public class ResolverListAdapter extends BaseAdapter {
mResolverListCommunicator.sendVoiceChoicesIfNeeded();
postListReadyRunnable(doPostProcessing);
mIsListLoaded = true;
}
/**
@@ -611,6 +614,10 @@ public class ResolverListAdapter extends BaseAdapter {
return mIntents;
}
protected boolean isListLoaded() {
return mIsListLoaded;
}
/**
* Necessary methods to communicate between {@link ResolverListAdapter}
* and {@link ResolverActivity}.