Merge "Resolve NPE when mini resolver is rotated" into tm-dev am: ad48cd89e0

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18188891

Change-Id: Ia6cb35676c75742576cc09ca9c38227665d65495
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Matt Casey
2022-05-11 20:51:35 +00:00
committed by Automerger Merge Worker
2 changed files with 37 additions and 9 deletions

View File

@@ -119,6 +119,11 @@ public class ResolverActivity extends Activity implements
@UnsupportedAppUsage @UnsupportedAppUsage
public ResolverActivity() { public ResolverActivity() {
mIsIntentPicker = getClass().equals(ResolverActivity.class);
}
protected ResolverActivity(boolean isIntentPicker) {
mIsIntentPicker = isIntentPicker;
} }
private boolean mSafeForwardingMode; private boolean mSafeForwardingMode;
@@ -135,6 +140,8 @@ public class ResolverActivity extends Activity implements
private String mReferrerPackage; private String mReferrerPackage;
private CharSequence mTitle; private CharSequence mTitle;
private int mDefaultTitleResId; private int mDefaultTitleResId;
// Expected to be true if this object is ResolverActivity or is ResolverWrapperActivity.
private final boolean mIsIntentPicker;
// Whether or not this activity supports choosing a default handler for the intent. // Whether or not this activity supports choosing a default handler for the intent.
@VisibleForTesting @VisibleForTesting
@@ -445,10 +452,6 @@ public class ResolverActivity extends Activity implements
+ (categories != null ? Arrays.toString(categories.toArray()) : "")); + (categories != null ? Arrays.toString(categories.toArray()) : ""));
} }
private boolean isIntentPicker() {
return getClass().equals(ResolverActivity.class);
}
protected AbstractMultiProfilePagerAdapter createMultiProfilePagerAdapter( protected AbstractMultiProfilePagerAdapter createMultiProfilePagerAdapter(
Intent[] initialIntents, Intent[] initialIntents,
List<ResolveInfo> rList, List<ResolveInfo> rList,
@@ -637,6 +640,11 @@ public class ResolverActivity extends Activity implements
resetButtonBar(); resetButtonBar();
if (shouldUseMiniResolver()) {
View buttonContainer = findViewById(R.id.button_bar_container);
buttonContainer.setPadding(0, 0, 0, mSystemWindowInsets.bottom);
}
// Need extra padding so the list can fully scroll up // Need extra padding so the list can fully scroll up
if (shouldAddFooterView()) { if (shouldAddFooterView()) {
applyFooterView(mSystemWindowInsets.bottom); applyFooterView(mSystemWindowInsets.bottom);
@@ -649,7 +657,8 @@ public class ResolverActivity extends Activity implements
public void onConfigurationChanged(Configuration newConfig) { public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
mMultiProfilePagerAdapter.getActiveListAdapter().handlePackagesChanged(); mMultiProfilePagerAdapter.getActiveListAdapter().handlePackagesChanged();
if (isIntentPicker() && shouldShowTabs() && !useLayoutWithDefault()) { if (mIsIntentPicker && shouldShowTabs() && !useLayoutWithDefault()
&& !shouldUseMiniResolver()) {
updateIntentPickerPaddings(); updateIntentPickerPaddings();
} }
@@ -1084,7 +1093,7 @@ public class ResolverActivity extends Activity implements
if (isAutolaunching()) { if (isAutolaunching()) {
return; return;
} }
if (isIntentPicker()) { if (mIsIntentPicker) {
((ResolverMultiProfilePagerAdapter) mMultiProfilePagerAdapter) ((ResolverMultiProfilePagerAdapter) mMultiProfilePagerAdapter)
.setUseLayoutWithDefault(useLayoutWithDefault()); .setUseLayoutWithDefault(useLayoutWithDefault());
} }
@@ -1108,7 +1117,7 @@ public class ResolverActivity extends Activity implements
protected void onListRebuilt(ResolverListAdapter listAdapter, boolean rebuildCompleted) { protected void onListRebuilt(ResolverListAdapter listAdapter, boolean rebuildCompleted) {
final ItemClickListener listener = new ItemClickListener(); final ItemClickListener listener = new ItemClickListener();
setupAdapterListView((ListView) mMultiProfilePagerAdapter.getActiveAdapterView(), listener); setupAdapterListView((ListView) mMultiProfilePagerAdapter.getActiveAdapterView(), listener);
if (shouldShowTabs() && isIntentPicker()) { if (shouldShowTabs() && mIsIntentPicker) {
final ResolverDrawerLayout rdl = findViewById(R.id.contentPanel); final ResolverDrawerLayout rdl = findViewById(R.id.contentPanel);
if (rdl != null) { if (rdl != null) {
rdl.setMaxCollapsedHeight(getResources() rdl.setMaxCollapsedHeight(getResources()
@@ -1448,6 +1457,12 @@ public class ResolverActivity extends Activity implements
return postRebuildList(rebuildCompleted); return postRebuildList(rebuildCompleted);
} }
/**
* Mini resolver is shown when the user is choosing between browser[s] in this profile and a
* single app in the other profile (see shouldUseMiniResolver()). It shows the single app icon
* and asks the user if they'd like to open that cross-profile app or use the in-profile
* browser.
*/
private void configureMiniResolverContent() { private void configureMiniResolverContent() {
mLayoutId = R.layout.miniresolver; mLayoutId = R.layout.miniresolver;
setContentView(mLayoutId); setContentView(mLayoutId);
@@ -1484,7 +1499,16 @@ public class ResolverActivity extends Activity implements
}); });
} }
/**
* Mini resolver should be used when all of the following are true:
* 1. This is the intent picker (ResolverActivity).
* 2. This profile only has web browser matches.
* 3. The other profile has a single non-browser match.
*/
private boolean shouldUseMiniResolver() { private boolean shouldUseMiniResolver() {
if (!mIsIntentPicker) {
return false;
}
if (mMultiProfilePagerAdapter.getActiveListAdapter() == null if (mMultiProfilePagerAdapter.getActiveListAdapter() == null
|| mMultiProfilePagerAdapter.getInactiveListAdapter() == null) { || mMultiProfilePagerAdapter.getInactiveListAdapter() == null) {
return false; return false;
@@ -1790,7 +1814,7 @@ public class ResolverActivity extends Activity implements
void onHorizontalSwipeStateChanged(int state) {} void onHorizontalSwipeStateChanged(int state) {}
private void maybeHideDivider() { private void maybeHideDivider() {
if (!isIntentPicker()) { if (!mIsIntentPicker) {
return; return;
} }
final View divider = findViewById(R.id.divider); final View divider = findViewById(R.id.divider);
@@ -1807,7 +1831,7 @@ public class ResolverActivity extends Activity implements
protected void onProfileTabSelected() { } protected void onProfileTabSelected() { }
private void resetCheckedItem() { private void resetCheckedItem() {
if (!isIntentPicker()) { if (!mIsIntentPicker) {
return; return;
} }
mLastSelected = ListView.INVALID_POSITION; mLastSelected = ListView.INVALID_POSITION;

View File

@@ -39,6 +39,10 @@ public class ResolverWrapperActivity extends ResolverActivity {
static final OverrideData sOverrides = new OverrideData(); static final OverrideData sOverrides = new OverrideData();
private UsageStatsManager mUsm; private UsageStatsManager mUsm;
public ResolverWrapperActivity() {
super(/* isIntentPicker= */ true);
}
@Override @Override
public ResolverListAdapter createResolverListAdapter(Context context, public ResolverListAdapter createResolverListAdapter(Context context,
List<Intent> payloadIntents, Intent[] initialIntents, List<ResolveInfo> rList, List<Intent> payloadIntents, Intent[] initialIntents, List<ResolveInfo> rList,