import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
+import android.content.pm.IntentFilterVerificationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.service.persistentdata.PersistentDataBlockManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
+import android.util.ArraySet;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
return prefActList.size() > 0;
}
+ public static ArraySet<String> getHandledDomains(PackageManager pm, String packageName) {
+ List<IntentFilterVerificationInfo> iviList = pm.getIntentFilterVerifications(packageName);
+ List<IntentFilter> filters = pm.getAllIntentFilters(packageName);
+
+ ArraySet<String> result = new ArraySet<>();
+ if (iviList.size() > 0) {
+ for (IntentFilterVerificationInfo ivi : iviList) {
+ for (String host : ivi.getDomains()) {
+ result.add(host);
+ }
+ }
+ }
+ if (filters != null && filters.size() > 0) {
+ for (IntentFilter filter : filters) {
+ if (filter.hasDataScheme(IntentFilter.SCHEME_HTTP) ||
+ filter.hasDataScheme(IntentFilter.SCHEME_HTTPS)) {
+ result.addAll(filter.getHostsList());
+ }
+ }
+ }
+ return result;
+ }
+
public static CharSequence getLaunchByDeafaultSummary(ApplicationsState.AppEntry appEntry,
IUsbManager usbManager, PackageManager pm, Context context) {
String packageName = appEntry.info.packageName;
package com.android.settings.applications;
import android.app.AlertDialog;
-import android.content.ComponentName;
-import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.IntentFilterVerificationInfo;
import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.UserHandle;
import android.preference.Preference;
import android.preference.SwitchPreference;
import android.util.ArraySet;
+import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import com.android.internal.logging.MetricsLogger;
import com.android.settings.R;
+import com.android.settings.Utils;
-import java.util.List;
+import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS;
+import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER;
-import static android.content.pm.PackageManager.GET_ACTIVITIES;
-import static android.content.pm.PackageManager.GET_META_DATA;
-import static android.content.pm.PackageManager.GET_RESOLVED_FILTER;
+import java.util.List;
public class AppLaunchSettings extends AppInfoWithHeader implements OnClickListener,
Preference.OnPreferenceChangeListener {
+ private static final String TAG = "AppLaunchSettings";
private static final String KEY_OPEN_DOMAIN_URLS = "app_launch_open_domain_urls";
private static final String KEY_SUPPORTED_DOMAIN_URLS = "app_launch_supported_domain_urls";
private PackageManager mPm;
+ private boolean mHasDomainUrls;
private SwitchPreference mOpenDomainUrls;
private AppDomainsPreference mAppDomainUrls;
private ClearDefaultsPreference mClearDefaultsPreference;
addPreferencesFromResource(R.xml.installed_app_launch_settings);
mPm = getActivity().getPackageManager();
- final int myUserId = UserHandle.myUserId();
mOpenDomainUrls = (SwitchPreference) findPreference(KEY_OPEN_DOMAIN_URLS);
mOpenDomainUrls.setOnPreferenceChangeListener(this);
- boolean hasDomainUrls =
+ mHasDomainUrls =
(mAppEntry.info.privateFlags & ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS) != 0;
List<IntentFilterVerificationInfo> iviList = mPm.getIntentFilterVerifications(mPackageName);
- boolean enabled = hasDomainUrls && (iviList.size() != 0);
-
- mOpenDomainUrls.setEnabled(enabled);
- if (enabled) {
- final int status = mPm.getIntentVerificationStatus(mPackageName, myUserId);
- boolean checked =
- (status == PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS);
- mOpenDomainUrls.setChecked(checked);
- }
-
List<IntentFilter> filters = mPm.getAllIntentFilters(mPackageName);
mAppDomainUrls = (AppDomainsPreference) findPreference(KEY_SUPPORTED_DOMAIN_URLS);
- CharSequence[] entries = getEntries(iviList, filters);
+ CharSequence[] entries = getEntries(mPackageName, iviList, filters);
mAppDomainUrls.setTitles(entries);
mAppDomainUrls.setValues(new int[entries.length]);
mClearDefaultsPreference = (ClearDefaultsPreference) findPreference(KEY_CLEAR_DEFAULTS);
+
+ updateDomainUrlPrefState();
}
- private CharSequence[] getEntries(List<IntentFilterVerificationInfo> iviList,
- List<IntentFilter> filters) {
- ArraySet<String> result = new ArraySet<>();
- if (iviList.size() > 0) {
- for (IntentFilterVerificationInfo ivi : iviList) {
- for (String host : ivi.getDomains()) {
- result.add(host);
- }
- }
- }
- if (filters != null && filters.size() > 0) {
- for (IntentFilter filter : filters) {
- if (filter.hasDataScheme(IntentFilter.SCHEME_HTTP) ||
- filter.hasDataScheme(IntentFilter.SCHEME_HTTPS)) {
- result.addAll(filter.getHostsList());
- }
+ private void updateDomainUrlPrefState() {
+ mOpenDomainUrls.setEnabled(mHasDomainUrls);
+
+ boolean checked = false;
+ if (mHasDomainUrls) {
+ final int status = mPm.getIntentVerificationStatus(mPackageName, UserHandle.myUserId());
+ if (status == INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS) {
+ checked = true;
}
}
- return result.toArray(new CharSequence[0]);
+ mOpenDomainUrls.setChecked(checked);
+ }
+
+ private CharSequence[] getEntries(String packageName, List<IntentFilterVerificationInfo> iviList,
+ List<IntentFilter> filters) {
+ ArraySet<String> result = Utils.getHandledDomains(mPm, packageName);
+ return result.toArray(new CharSequence[result.size()]);
}
@Override
protected boolean refreshUi() {
mClearDefaultsPreference.setPackageName(mPackageName);
mClearDefaultsPreference.setAppEntry(mAppEntry);
-
+ updateDomainUrlPrefState();
return true;
}
return null;
}
-
@Override
public void onClick(View v) {
// Nothing to do
boolean ret = false;
final String key = preference.getKey();
if (KEY_OPEN_DOMAIN_URLS.equals(key)) {
- SwitchPreference pref = (SwitchPreference) preference;
- int status = !pref.isChecked() ?
- PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS :
- PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER;
- ret = mPm.updateIntentVerificationStatus(mPackageName, status, UserHandle.myUserId());
+ final SwitchPreference pref = (SwitchPreference) preference;
+ final Boolean switchedOn = (Boolean) newValue;
+ int newState = switchedOn ?
+ INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS :
+ INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER;
+ final int userId = UserHandle.myUserId();
+ boolean success = mPm.updateIntentVerificationStatus(mPackageName, newState, userId);
+ if (success) {
+ // read back the state to ensure canonicality
+ newState = mPm.getIntentVerificationStatus(mPackageName, userId);
+ ret = (newState == INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS);
+ pref.setChecked(ret);
+ } else {
+ Log.e(TAG, "Couldn't update intent verification status!");
+ }
}
return ret;
}