Revert ResolverActivity changes associated with browseables.

Reverts changes 69df963, 0c7c5d59, 6cbef19 and others. These changes
don't revert cleanly because of several refactorings layered on top
of the original changes.

The main objective of these change is to get rid of mUseLayoutForBrowseable
and associated codepaths as we treat choosing between browseables the
same as other choices.

Bug: 157460946
Test: manual
Test: atest ResolverActivityTest
Test: atest ChooserActivityTest

Change-Id: Ibe9f2289289f7f5da3986e6892a2ee4ff65765a0
This commit is contained in:
Narayan Kamath
2020-05-07 13:42:05 +01:00
parent 393133b01c
commit 754186806d
10 changed files with 21 additions and 149 deletions

View File

@@ -54,8 +54,6 @@ public abstract class AbstractResolverComparator implements Comparator<ResolvedC
// True if the current share is a link.
private final boolean mHttp;
// can be null if mHttp == false or current user has no default browser package
private final String mDefaultBrowserPackageName;
// message types
static final int RANKER_SERVICE_RESULT = 0;
@@ -102,9 +100,6 @@ public abstract class AbstractResolverComparator implements Comparator<ResolvedC
getContentAnnotations(intent);
mPm = context.getPackageManager();
mUsm = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
mDefaultBrowserPackageName = mHttp
? mPm.getDefaultBrowserPackageNameAsUser(UserHandle.myUserId())
: null;
mAzComparator = new AzInfoComparator(context);
}
@@ -157,17 +152,6 @@ public abstract class AbstractResolverComparator implements Comparator<ResolvedC
}
if (mHttp) {
// Special case: we want filters that match URI paths/schemes to be
// ordered before others. This is for the case when opening URIs,
// to make native apps go above browsers - except for 1 even more special case
// which is the default browser, as we want that to go above them all.
if (isDefaultBrowser(lhs)) {
return -1;
}
if (isDefaultBrowser(rhs)) {
return 1;
}
final boolean lhsSpecific = ResolverActivity.isSpecificUriMatch(lhs.match);
final boolean rhsSpecific = ResolverActivity.isSpecificUriMatch(rhs.match);
if (lhsSpecific != rhsSpecific) {
@@ -272,21 +256,6 @@ public abstract class AbstractResolverComparator implements Comparator<ResolvedC
mAfterCompute = null;
}
private boolean isDefaultBrowser(ResolveInfo ri) {
// It makes sense to prefer the default browser
// only if the targeted user is the current user
if (ri.targetUserId != UserHandle.USER_CURRENT) {
return false;
}
if (ri.activityInfo.packageName != null
&& ri.activityInfo.packageName.equals(mDefaultBrowserPackageName)) {
return true;
}
return false;
}
/**
* Sort intents alphabetically based on package name.
*/

View File

@@ -885,7 +885,6 @@ public class ChooserActivity extends ResolverActivity implements
initialIntents,
rList,
filterLastUsed,
mUseLayoutForBrowsables,
/* userHandle */ UserHandle.of(UserHandle.myUserId()));
return new ChooserMultiProfilePagerAdapter(
/* context */ this,
@@ -906,7 +905,6 @@ public class ChooserActivity extends ResolverActivity implements
selectedProfile == PROFILE_PERSONAL ? initialIntents : null,
rList,
filterLastUsed,
mUseLayoutForBrowsables,
/* userHandle */ getPersonalProfileUserHandle());
ChooserGridAdapter workAdapter = createChooserGridAdapter(
/* context */ this,
@@ -914,7 +912,6 @@ public class ChooserActivity extends ResolverActivity implements
selectedProfile == PROFILE_WORK ? initialIntents : null,
rList,
filterLastUsed,
mUseLayoutForBrowsables,
/* userHandle */ getWorkProfileUserHandle());
return new ChooserMultiProfilePagerAdapter(
/* context */ this,
@@ -2504,10 +2501,10 @@ public class ChooserActivity extends ResolverActivity implements
@VisibleForTesting
public ChooserGridAdapter createChooserGridAdapter(Context context,
List<Intent> payloadIntents, Intent[] initialIntents, List<ResolveInfo> rList,
boolean filterLastUsed, boolean useLayoutForBrowsables, UserHandle userHandle) {
boolean filterLastUsed, UserHandle userHandle) {
ChooserListAdapter chooserListAdapter = createChooserListAdapter(context, payloadIntents,
initialIntents, rList, filterLastUsed,
useLayoutForBrowsables, createListController(userHandle));
createListController(userHandle));
AppPredictor.Callback appPredictorCallback = createAppPredictorCallback(chooserListAdapter);
AppPredictor appPredictor = setupAppPredictorForUser(userHandle, appPredictorCallback);
chooserListAdapter.setAppPredictor(appPredictor);
@@ -2518,11 +2515,10 @@ public class ChooserActivity extends ResolverActivity implements
@VisibleForTesting
public ChooserListAdapter createChooserListAdapter(Context context,
List<Intent> payloadIntents, Intent[] initialIntents, List<ResolveInfo> rList,
boolean filterLastUsed, boolean useLayoutForBrowsables,
ResolverListController resolverListController) {
boolean filterLastUsed, ResolverListController resolverListController) {
return new ChooserListAdapter(context, payloadIntents, initialIntents, rList,
filterLastUsed, resolverListController, useLayoutForBrowsables,
this, this, context.getPackageManager());
filterLastUsed, resolverListController, this,
this, context.getPackageManager());
}
@VisibleForTesting

View File

@@ -120,15 +120,13 @@ public class ChooserListAdapter extends ResolverListAdapter {
public ChooserListAdapter(Context context, List<Intent> payloadIntents,
Intent[] initialIntents, List<ResolveInfo> rList,
boolean filterLastUsed, ResolverListController resolverListController,
boolean useLayoutForBrowsables,
ChooserListCommunicator chooserListCommunicator,
SelectableTargetInfo.SelectableTargetInfoCommunicator selectableTargetInfoCommunicator,
PackageManager packageManager) {
// Don't send the initial intents through the shared ResolverActivity path,
// we want to separate them into a different section.
super(context, payloadIntents, null, rList, filterLastUsed,
resolverListController, useLayoutForBrowsables,
chooserListCommunicator, false);
resolverListController, chooserListCommunicator, false);
createPlaceHolders();
mMaxShortcutTargetsPerApp =

View File

@@ -133,9 +133,6 @@ public class ResolverActivity extends Activity implements
private CharSequence mTitle;
private int mDefaultTitleResId;
@VisibleForTesting
protected boolean mUseLayoutForBrowsables;
// Whether or not this activity supports choosing a default handler for the intent.
@VisibleForTesting
protected boolean mSupportsAlwaysUseOption;
@@ -353,10 +350,6 @@ public class ResolverActivity extends Activity implements
mTitle = title;
mDefaultTitleResId = defaultTitleRes;
mUseLayoutForBrowsables = getTargetIntent() == null
? false
: isHttpSchemeAndViewAction(getTargetIntent());
mSupportsAlwaysUseOption = supportsAlwaysUseOption;
mWorkProfileUserHandle = fetchWorkProfileUserProfile();
@@ -450,7 +443,6 @@ public class ResolverActivity extends Activity implements
initialIntents,
rList,
filterLastUsed,
mUseLayoutForBrowsables,
/* userHandle */ UserHandle.of(UserHandle.myUserId()));
return new ResolverMultiProfilePagerAdapter(
/* context */ this,
@@ -485,7 +477,6 @@ public class ResolverActivity extends Activity implements
rList,
(filterLastUsed && UserHandle.myUserId()
== getPersonalProfileUserHandle().getIdentifier()),
mUseLayoutForBrowsables,
/* userHandle */ getPersonalProfileUserHandle());
UserHandle workProfileUserHandle = getWorkProfileUserHandle();
ResolverListAdapter workAdapter = createResolverListAdapter(
@@ -495,7 +486,6 @@ public class ResolverActivity extends Activity implements
rList,
(filterLastUsed && UserHandle.myUserId()
== workProfileUserHandle.getIdentifier()),
mUseLayoutForBrowsables,
/* userHandle */ workProfileUserHandle);
return new ResolverMultiProfilePagerAdapter(
/* context */ this,
@@ -741,26 +731,6 @@ public class ResolverActivity extends Activity implements
mMultiProfilePagerAdapter.getActiveListAdapter().getFilteredPosition() >= 0;
if (title == ActionTitle.DEFAULT && defaultTitleRes != 0) {
return getString(defaultTitleRes);
} else if (isHttpSchemeAndViewAction(intent)) {
// If the Intent's scheme is http(s) then we need to warn the user that
// they're giving access for the activity to open URLs from this specific host
String dialogTitle = null;
if (named && !mUseLayoutForBrowsables) {
dialogTitle = getString(ActionTitle.BROWSABLE_APP_TITLE_RES,
mMultiProfilePagerAdapter.getActiveListAdapter().getFilteredItem()
.getDisplayLabel());
} else if (named && mUseLayoutForBrowsables) {
dialogTitle = getString(ActionTitle.BROWSABLE_HOST_APP_TITLE_RES,
intent.getData().getHost(),
mMultiProfilePagerAdapter.getActiveListAdapter().getFilteredItem()
.getDisplayLabel());
} else if (mMultiProfilePagerAdapter.getActiveListAdapter().areAllTargetsBrowsers()) {
dialogTitle = getString(ActionTitle.BROWSABLE_TITLE_RES);
} else {
dialogTitle = getString(ActionTitle.BROWSABLE_HOST_TITLE_RES,
intent.getData().getHost());
}
return dialogTitle;
} else {
return named
? getString(title.namedTitleRes, mMultiProfilePagerAdapter
@@ -873,12 +843,6 @@ public class ResolverActivity extends Activity implements
mMultiProfilePagerAdapter.clearInactiveProfileCache();
}
private boolean isHttpSchemeAndViewAction(Intent intent) {
return (IntentFilter.SCHEME_HTTP.equals(intent.getScheme())
|| IntentFilter.SCHEME_HTTPS.equals(intent.getScheme()))
&& Intent.ACTION_VIEW.equals(intent.getAction());
}
private boolean hasManagedProfile() {
UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
if (userManager == null) {
@@ -929,13 +893,9 @@ public class ResolverActivity extends Activity implements
} else {
enabled = true;
}
if (mUseLayoutForBrowsables && !ri.handleAllWebDataURI) {
mAlwaysButton.setText(getResources()
.getString(R.string.activity_resolver_set_always));
} else {
mAlwaysButton.setText(getResources()
.getString(R.string.activity_resolver_use_always));
}
mAlwaysButton.setText(getResources()
.getString(R.string.activity_resolver_use_always));
}
if (ri != null) {
@@ -965,31 +925,7 @@ public class ResolverActivity extends Activity implements
? currentListAdapter.getFilteredPosition()
: listView.getCheckedItemPosition();
boolean hasIndexBeenFiltered = !currentListAdapter.hasFilteredItem();
ResolveInfo ri = currentListAdapter.resolveInfoForPosition(which, hasIndexBeenFiltered);
if (mUseLayoutForBrowsables
&& !ri.handleAllWebDataURI && id == R.id.button_always) {
showSettingsForSelected(ri);
} else {
startSelected(which, id == R.id.button_always, hasIndexBeenFiltered);
}
}
private void showSettingsForSelected(ResolveInfo ri) {
Intent intent = new Intent();
final String packageName = ri.activityInfo.packageName;
Bundle showFragmentArgs = new Bundle();
showFragmentArgs.putString(EXTRA_FRAGMENT_ARG_KEY, OPEN_LINKS_COMPONENT_KEY);
showFragmentArgs.putString("package", packageName);
// For regular apps, we open the Open by Default page
intent.setAction(Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS)
.setData(Uri.fromParts("package", packageName, null))
.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT)
.putExtra(EXTRA_FRAGMENT_ARG_KEY, OPEN_LINKS_COMPONENT_KEY)
.putExtra(EXTRA_SHOW_FRAGMENT_ARGS, showFragmentArgs);
startActivity(intent);
startSelected(which, id == R.id.button_always, hasIndexBeenFiltered);
}
public void startSelected(int which, boolean always, boolean hasIndexBeenFiltered) {
@@ -1381,12 +1317,12 @@ public class ResolverActivity extends Activity implements
@VisibleForTesting
protected ResolverListAdapter createResolverListAdapter(Context context,
List<Intent> payloadIntents, Intent[] initialIntents, List<ResolveInfo> rList,
boolean filterLastUsed, boolean useLayoutForBrowsables, UserHandle userHandle) {
boolean filterLastUsed, UserHandle userHandle) {
Intent startIntent = getIntent();
boolean isAudioCaptureDevice =
startIntent.getBooleanExtra(EXTRA_IS_AUDIO_CAPTURE_DEVICE, false);
return new ResolverListAdapter(context, payloadIntents, initialIntents, rList,
filterLastUsed, createListController(userHandle), useLayoutForBrowsables, this,
filterLastUsed, createListController(userHandle), this,
isAudioCaptureDevice);
}
@@ -1760,7 +1696,7 @@ public class ResolverActivity extends Activity implements
listView.setOnItemClickListener(listener);
listView.setOnItemLongClickListener(listener);
if (mSupportsAlwaysUseOption || mUseLayoutForBrowsables) {
if (mSupportsAlwaysUseOption) {
listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
}
}
@@ -1801,7 +1737,7 @@ public class ResolverActivity extends Activity implements
}
protected void resetButtonBar() {
if (!mSupportsAlwaysUseOption && !mUseLayoutForBrowsables) {
if (!mSupportsAlwaysUseOption) {
return;
}
final ViewGroup buttonLayout = findViewById(R.id.button_bar);

View File

@@ -69,13 +69,11 @@ public class ResolverListAdapter extends BaseAdapter {
private final PackageManager mPm;
protected final Context mContext;
private final ColorMatrixColorFilter mSuspendedMatrixColorFilter;
private final boolean mUseLayoutForBrowsables;
private final int mIconDpi;
protected ResolveInfo mLastChosen;
private DisplayResolveInfo mOtherProfile;
ResolverListController mResolverListController;
private int mPlaceholderCount;
private boolean mAllTargetsAreBrowsers = false;
protected final LayoutInflater mInflater;
@@ -94,7 +92,6 @@ public class ResolverListAdapter extends BaseAdapter {
Intent[] initialIntents, List<ResolveInfo> rList,
boolean filterLastUsed,
ResolverListController resolverListController,
boolean useLayoutForBrowsables,
ResolverListCommunicator resolverListCommunicator,
boolean isAudioCaptureDevice) {
mContext = context;
@@ -107,7 +104,6 @@ public class ResolverListAdapter extends BaseAdapter {
mFilterLastUsed = filterLastUsed;
mResolverListController = resolverListController;
mSuspendedMatrixColorFilter = createSuspendedColorMatrix();
mUseLayoutForBrowsables = useLayoutForBrowsables;
mResolverListCommunicator = resolverListCommunicator;
mIsAudioCaptureDevice = isAudioCaptureDevice;
final ActivityManager am = (ActivityManager) mContext.getSystemService(ACTIVITY_SERVICE);
@@ -182,14 +178,6 @@ public class ResolverListAdapter extends BaseAdapter {
return mUnfilteredResolveList;
}
/**
* @return true if all items in the display list are defined as browsers by
* ResolveInfo.handleAllWebDataURI
*/
public boolean areAllTargetsBrowsers() {
return mAllTargetsAreBrowsers;
}
/**
* Rebuild the list of resolvers. In some cases some parts will need some asynchronous work
* to complete.
@@ -207,7 +195,6 @@ public class ResolverListAdapter extends BaseAdapter {
mOtherProfile = null;
mLastChosen = null;
mLastChosenPosition = -1;
mAllTargetsAreBrowsers = false;
mDisplayList.clear();
mIsTabLoaded = false;
@@ -322,8 +309,6 @@ public class ResolverListAdapter extends BaseAdapter {
boolean doPostProcessing) {
int n;
if (sortedComponents != null && (n = sortedComponents.size()) != 0) {
mAllTargetsAreBrowsers = mUseLayoutForBrowsables;
// First put the initial items at the top.
if (mInitialIntents != null) {
for (int i = 0; i < mInitialIntents.length; i++) {
@@ -353,7 +338,6 @@ public class ResolverListAdapter extends BaseAdapter {
ri.noResourceId = true;
ri.icon = 0;
}
mAllTargetsAreBrowsers &= ri.handleAllWebDataURI;
addResolveInfo(new DisplayResolveInfo(ii, ri,
ri.loadLabel(mPm), null, ii, makePresentationGetter(ri)));
@@ -364,7 +348,6 @@ public class ResolverListAdapter extends BaseAdapter {
for (ResolvedComponentInfo rci : sortedComponents) {
final ResolveInfo ri = rci.getResolveInfoAt(0);
if (ri != null) {
mAllTargetsAreBrowsers &= ri.handleAllWebDataURI;
addResolveInfoWithAlternates(rci);
}
}

View File

@@ -4137,18 +4137,10 @@
as the default in the activity resolver. [CHAR LIMIT=25] -->
<string name="activity_resolver_use_always">Always</string>
<!-- Title for a button to choose the currently selected activity
as the default in the activity resolver. [CHAR LIMIT=50] -->
<string name="activity_resolver_set_always">Set to always open</string>
<!-- Title for a button to choose the currently selected activity
from the activity resolver to use just this once. [CHAR LIMIT=25] -->
<string name="activity_resolver_use_once">Just once</string>
<!-- Title for a button to choose to go to
'Open by Default' app settings. [CHAR LIMIT=25] -->
<string name="activity_resolver_app_settings">Settings</string>
<!-- Text for the toast that is shown when the user clicks on a launcher that
doesn't support the work profile. [CHAR LIMIT=100] -->
<string name="activity_resolver_work_profiles_support">%1$s doesn\'t support work profile</string>

View File

@@ -2552,7 +2552,6 @@
<java-symbol type="bool" name="config_allow_ussd_over_ims" />
<java-symbol type="attr" name="touchscreenBlocksFocus" />
<java-symbol type="layout" name="resolver_list_with_default" />
<java-symbol type="string" name="activity_resolver_set_always" />
<java-symbol type="string" name="activity_resolver_use_always" />
<java-symbol type="string" name="whichApplicationNamed" />
<java-symbol type="string" name="whichApplicationLabel" />

View File

@@ -61,12 +61,12 @@ public class ChooserWrapperActivity extends ChooserActivity {
@Override
public ChooserListAdapter createChooserListAdapter(Context context, List<Intent> payloadIntents,
Intent[] initialIntents, List<ResolveInfo> rList, boolean filterLastUsed,
boolean useLayoutForBrowsables, ResolverListController resolverListController) {
ResolverListController resolverListController) {
PackageManager packageManager =
sOverrides.packageManager == null ? context.getPackageManager()
: sOverrides.packageManager;
return new ChooserListAdapter(context, payloadIntents, initialIntents, rList,
filterLastUsed, resolverListController, useLayoutForBrowsables,
filterLastUsed, resolverListController,
this, this, packageManager);
}

View File

@@ -42,9 +42,9 @@ public class ResolverWrapperActivity extends ResolverActivity {
@Override
public ResolverListAdapter createResolverListAdapter(Context context,
List<Intent> payloadIntents, Intent[] initialIntents, List<ResolveInfo> rList,
boolean filterLastUsed, boolean useLayoutForBrowsables, UserHandle userHandle) {
boolean filterLastUsed, UserHandle userHandle) {
return new ResolverWrapperAdapter(context, payloadIntents, initialIntents, rList,
filterLastUsed, createListController(userHandle), useLayoutForBrowsables, this);
filterLastUsed, createListController(userHandle), this);
}
@Override
@@ -166,4 +166,4 @@ public class ResolverWrapperActivity extends ResolverActivity {
};
}
}
}
}

View File

@@ -35,11 +35,10 @@ public class ResolverWrapperAdapter extends ResolverListAdapter {
List<Intent> payloadIntents,
Intent[] initialIntents,
List<ResolveInfo> rList, boolean filterLastUsed,
ResolverListController resolverListController, boolean useLayoutForBrowsables,
ResolverListController resolverListController,
ResolverListCommunicator resolverListCommunicator) {
super(context, payloadIntents, initialIntents, rList, filterLastUsed,
resolverListController,
useLayoutForBrowsables, resolverListCommunicator, false);
resolverListController, resolverListCommunicator, false);
}
public CountingIdlingResource getLabelIdlingResource() {