From f6986d4809e78012ccbfd1d36a423146508cd148 Mon Sep 17 00:00:00 2001 From: arangelov Date: Wed, 12 Feb 2020 15:03:22 +0000 Subject: [PATCH] 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 --- .../internal/app/ResolverActivity.java | 33 ++++++++++++++----- .../internal/app/ResolverListAdapter.java | 7 ++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index 022573c5203a6..c2c9fff401a30 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -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 diff --git a/core/java/com/android/internal/app/ResolverListAdapter.java b/core/java/com/android/internal/app/ResolverListAdapter.java index ea8409058264d..54453d0d0f465 100644 --- a/core/java/com/android/internal/app/ResolverListAdapter.java +++ b/core/java/com/android/internal/app/ResolverListAdapter.java @@ -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 payloadIntents, Intent[] initialIntents, List 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}.