Fix the summary format problem of the installed apps

- The summary of each installed apps in Opening links page is differnt
  with the summary of the Open by default in App info page.
- Let the format of the installed apps' summary is same as the Open
  by default.

Fixes: 193455965
Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.applications.managedomainurls
Change-Id: Ifef4b27795300dc81c83ac1cc5063e8e22f54497
This commit is contained in:
Sunny Shao
2021-09-06 16:53:24 +08:00
parent e893a890ca
commit 256a65c467
2 changed files with 41 additions and 25 deletions

View File

@@ -17,27 +17,26 @@
package com.android.settings.applications.managedomainurls;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.UserHandle;
import android.util.ArraySet;
import android.content.pm.verify.domain.DomainVerificationManager;
import android.content.pm.verify.domain.DomainVerificationUserState;
import android.util.IconDrawableFactory;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.applications.intentpicker.IntentPickerUtils;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
import com.android.settingslib.widget.AppPreference;
public class DomainAppPreference extends AppPreference {
private final AppEntry mEntry;
private final PackageManager mPm;
private final DomainVerificationManager mDomainVerificationManager;
private final IconDrawableFactory mIconDrawableFactory;
public DomainAppPreference(final Context context, IconDrawableFactory iconFactory,
AppEntry entry) {
super(context);
mIconDrawableFactory = iconFactory;
mPm = context.getPackageManager();
mDomainVerificationManager = context.getSystemService(DomainVerificationManager.class);
mEntry = entry;
mEntry.ensureLabel(getContext());
@@ -60,22 +59,14 @@ public class DomainAppPreference extends AppPreference {
}
private CharSequence getDomainsSummary(String packageName) {
// If the user has explicitly said "no" for this package, that's the
// string we should show.
int domainStatus =
mPm.getIntentVerificationStatusAsUser(packageName, UserHandle.myUserId());
if (domainStatus == PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER) {
return getContext().getText(R.string.domain_urls_summary_none);
}
// Otherwise, ask package manager for the domains for this package,
// and show the first one (or none if there aren't any).
final ArraySet<String> result = Utils.getHandledDomains(mPm, packageName);
if (result.isEmpty()) {
return getContext().getText(R.string.domain_urls_summary_none);
} else if (result.size() == 1) {
return getContext().getString(R.string.domain_urls_summary_one, result.valueAt(0));
} else {
return getContext().getString(R.string.domain_urls_summary_some, result.valueAt(0));
}
return getContext().getText(isLinkHandlingAllowed(packageName)
? R.string.app_link_open_always : R.string.app_link_open_never);
}
private boolean isLinkHandlingAllowed(String packageName) {
final DomainVerificationUserState userState =
IntentPickerUtils.getDomainVerificationUserState(mDomainVerificationManager,
packageName);
return userState == null ? false : userState.isLinkHandlingAllowed();
}
}