Disable app-link preferences for browser apps
Also make sure that the 'Clear defaults' action unsets the app's standing as the default browser, when applicable. Bug 23751034 Change-Id: I6131b763bfa76ba38d18cad2abbb35caffe789aa
This commit is contained in:
@@ -1146,9 +1146,9 @@ public final class Utils {
|
|||||||
boolean hasPreferred = hasPreferredActivities(pm, packageName)
|
boolean hasPreferred = hasPreferredActivities(pm, packageName)
|
||||||
|| hasUsbDefaults(usbManager, packageName);
|
|| hasUsbDefaults(usbManager, packageName);
|
||||||
int status = pm.getIntentVerificationStatus(packageName, UserHandle.myUserId());
|
int status = pm.getIntentVerificationStatus(packageName, UserHandle.myUserId());
|
||||||
|
// consider a visible current link-handling state to be any explicitly designated behavior
|
||||||
boolean hasDomainURLsPreference =
|
boolean hasDomainURLsPreference =
|
||||||
(status == PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS) ||
|
status != PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED;
|
||||||
(status == PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER);
|
|
||||||
return context.getString(hasPreferred || hasDomainURLsPreference
|
return context.getString(hasPreferred || hasDomainURLsPreference
|
||||||
? R.string.launch_defaults_some
|
? R.string.launch_defaults_some
|
||||||
: R.string.launch_defaults_none);
|
: R.string.launch_defaults_none);
|
||||||
|
@@ -17,14 +17,16 @@
|
|||||||
package com.android.settings.applications;
|
package com.android.settings.applications;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.IntentFilterVerificationInfo;
|
import android.content.pm.IntentFilterVerificationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.ResolveInfo;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.SwitchPreference;
|
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -52,8 +54,17 @@ public class AppLaunchSettings extends AppInfoWithHeader implements OnClickListe
|
|||||||
private static final String KEY_SUPPORTED_DOMAIN_URLS = "app_launch_supported_domain_urls";
|
private static final String KEY_SUPPORTED_DOMAIN_URLS = "app_launch_supported_domain_urls";
|
||||||
private static final String KEY_CLEAR_DEFAULTS = "app_launch_clear_defaults";
|
private static final String KEY_CLEAR_DEFAULTS = "app_launch_clear_defaults";
|
||||||
|
|
||||||
|
private static final Intent sBrowserIntent;
|
||||||
|
static {
|
||||||
|
sBrowserIntent = new Intent()
|
||||||
|
.setAction(Intent.ACTION_VIEW)
|
||||||
|
.addCategory(Intent.CATEGORY_BROWSABLE)
|
||||||
|
.setData(Uri.parse("http:"));
|
||||||
|
}
|
||||||
|
|
||||||
private PackageManager mPm;
|
private PackageManager mPm;
|
||||||
|
|
||||||
|
private boolean mIsBrowser;
|
||||||
private boolean mHasDomainUrls;
|
private boolean mHasDomainUrls;
|
||||||
private DropDownPreference mAppLinkState;
|
private DropDownPreference mAppLinkState;
|
||||||
private AppDomainsPreference mAppDomainUrls;
|
private AppDomainsPreference mAppDomainUrls;
|
||||||
@@ -64,28 +75,50 @@ public class AppLaunchSettings extends AppInfoWithHeader implements OnClickListe
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.installed_app_launch_settings);
|
addPreferencesFromResource(R.xml.installed_app_launch_settings);
|
||||||
|
mAppDomainUrls = (AppDomainsPreference) findPreference(KEY_SUPPORTED_DOMAIN_URLS);
|
||||||
|
mClearDefaultsPreference = (ClearDefaultsPreference) findPreference(KEY_CLEAR_DEFAULTS);
|
||||||
|
mAppLinkState = (DropDownPreference) findPreference(KEY_APP_LINK_STATE);
|
||||||
|
|
||||||
mPm = getActivity().getPackageManager();
|
mPm = getActivity().getPackageManager();
|
||||||
|
|
||||||
|
mIsBrowser = isBrowserApp(mPackageName);
|
||||||
mHasDomainUrls =
|
mHasDomainUrls =
|
||||||
(mAppEntry.info.privateFlags & ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS) != 0;
|
(mAppEntry.info.privateFlags & ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS) != 0;
|
||||||
|
|
||||||
|
if (!mIsBrowser) {
|
||||||
List<IntentFilterVerificationInfo> iviList = mPm.getIntentFilterVerifications(mPackageName);
|
List<IntentFilterVerificationInfo> iviList = mPm.getIntentFilterVerifications(mPackageName);
|
||||||
|
|
||||||
List<IntentFilter> filters = mPm.getAllIntentFilters(mPackageName);
|
List<IntentFilter> filters = mPm.getAllIntentFilters(mPackageName);
|
||||||
|
|
||||||
mAppDomainUrls = (AppDomainsPreference) findPreference(KEY_SUPPORTED_DOMAIN_URLS);
|
|
||||||
CharSequence[] entries = getEntries(mPackageName, iviList, filters);
|
CharSequence[] entries = getEntries(mPackageName, iviList, filters);
|
||||||
mAppDomainUrls.setTitles(entries);
|
mAppDomainUrls.setTitles(entries);
|
||||||
mAppDomainUrls.setValues(new int[entries.length]);
|
mAppDomainUrls.setValues(new int[entries.length]);
|
||||||
|
}
|
||||||
mClearDefaultsPreference = (ClearDefaultsPreference) findPreference(KEY_CLEAR_DEFAULTS);
|
|
||||||
|
|
||||||
buildStateDropDown();
|
buildStateDropDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildStateDropDown() {
|
// An app is a "browser" if it has an activity resolution that wound up
|
||||||
mAppLinkState = (DropDownPreference) findPreference(KEY_APP_LINK_STATE);
|
// marked with the 'handleAllWebDataURI' flag.
|
||||||
|
private boolean isBrowserApp(String packageName) {
|
||||||
|
sBrowserIntent.setPackage(packageName);
|
||||||
|
List<ResolveInfo> list = mPm.queryIntentActivitiesAsUser(sBrowserIntent,
|
||||||
|
PackageManager.MATCH_ALL, UserHandle.myUserId());
|
||||||
|
final int count = list.size();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
ResolveInfo info = list.get(i);
|
||||||
|
if (info.activityInfo != null && info.handleAllWebDataURI) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildStateDropDown() {
|
||||||
|
if (mIsBrowser) {
|
||||||
|
// Browsers don't show the app-link prefs
|
||||||
|
mAppLinkState.setShouldDisableView(true);
|
||||||
|
mAppLinkState.setEnabled(false);
|
||||||
|
mAppDomainUrls.setShouldDisableView(true);
|
||||||
|
mAppDomainUrls.setEnabled(false);
|
||||||
|
} else {
|
||||||
// Designed order of states in the dropdown:
|
// Designed order of states in the dropdown:
|
||||||
//
|
//
|
||||||
// * always
|
// * always
|
||||||
@@ -118,8 +151,15 @@ public class AppLaunchSettings extends AppInfoWithHeader implements OnClickListe
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean updateAppLinkState(final int newState) {
|
private boolean updateAppLinkState(final int newState) {
|
||||||
|
if (mIsBrowser) {
|
||||||
|
// We shouldn't get into this state, but if we do make sure
|
||||||
|
// not to cause any permanent mayhem.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
final int userId = UserHandle.myUserId();
|
final int userId = UserHandle.myUserId();
|
||||||
final int priorState = mPm.getIntentVerificationStatus(mPackageName, userId);
|
final int priorState = mPm.getIntentVerificationStatus(mPackageName, userId);
|
||||||
|
|
||||||
|
@@ -93,9 +93,13 @@ public class ClearDefaultsPreference extends Preference {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (mUsbManager != null) {
|
if (mUsbManager != null) {
|
||||||
|
final int userId = UserHandle.myUserId();
|
||||||
mPm.clearPackagePreferredActivities(mPackageName);
|
mPm.clearPackagePreferredActivities(mPackageName);
|
||||||
|
if (isDefaultBrowser(mPackageName)) {
|
||||||
|
mPm.setDefaultBrowserPackageName(null, userId);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
mUsbManager.clearDefaults(mPackageName, UserHandle.myUserId());
|
mUsbManager.clearDefaults(mPackageName, userId);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "mUsbManager.clearDefaults", e);
|
Log.e(TAG, "mUsbManager.clearDefaults", e);
|
||||||
}
|
}
|
||||||
@@ -122,6 +126,7 @@ public class ClearDefaultsPreference extends Preference {
|
|||||||
|
|
||||||
TextView autoLaunchView = (TextView) mRootView.findViewById(R.id.auto_launch);
|
TextView autoLaunchView = (TextView) mRootView.findViewById(R.id.auto_launch);
|
||||||
boolean autoLaunchEnabled = Utils.hasPreferredActivities(mPm, mPackageName)
|
boolean autoLaunchEnabled = Utils.hasPreferredActivities(mPm, mPackageName)
|
||||||
|
|| isDefaultBrowser(mPackageName)
|
||||||
|| Utils.hasUsbDefaults(mUsbManager, mPackageName);
|
|| Utils.hasUsbDefaults(mUsbManager, mPackageName);
|
||||||
if (!autoLaunchEnabled && !hasBindAppWidgetPermission) {
|
if (!autoLaunchEnabled && !hasBindAppWidgetPermission) {
|
||||||
resetLaunchDefaultsUi(autoLaunchView);
|
resetLaunchDefaultsUi(autoLaunchView);
|
||||||
@@ -165,6 +170,11 @@ public class ClearDefaultsPreference extends Preference {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isDefaultBrowser(String packageName) {
|
||||||
|
final String defaultBrowser = mPm.getDefaultBrowserPackageName(UserHandle.myUserId());
|
||||||
|
return packageName.equals(defaultBrowser);
|
||||||
|
}
|
||||||
|
|
||||||
private void resetLaunchDefaultsUi(TextView autoLaunchView) {
|
private void resetLaunchDefaultsUi(TextView autoLaunchView) {
|
||||||
autoLaunchView.setText(R.string.auto_launch_disable_text);
|
autoLaunchView.setText(R.string.auto_launch_disable_text);
|
||||||
// Disable clear activities button
|
// Disable clear activities button
|
||||||
|
Reference in New Issue
Block a user