Remove old default apps code and use roles instead.
Default apps are moved into PermissionController. Bug: 124452117 Bug: 124457823 Test: presubmit & manual Change-Id: I5f68e5b77cd6163d093590185314270706d75391
This commit is contained in:
@@ -136,7 +136,6 @@ public class Settings extends SettingsActivity {
|
||||
public static class ChangeWifiStateActivity extends SettingsActivity { /* empty */ }
|
||||
public static class AppDrawOverlaySettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class AppWriteSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class AdvancedAppsActivity extends SettingsActivity { /* empty */ }
|
||||
|
||||
public static class ManageExternalSourcesActivity extends SettingsActivity {/* empty */ }
|
||||
public static class ManageAppExternalSourcesActivity extends SettingsActivity { /* empty */ }
|
||||
|
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.applications;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.icu.text.ListFormatter;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.assist.DefaultAssistPreferenceController;
|
||||
import com.android.settings.applications.defaultapps.DefaultBrowserPreferenceController;
|
||||
import com.android.settings.applications.defaultapps.DefaultEmergencyPreferenceController;
|
||||
import com.android.settings.applications.defaultapps.DefaultHomePreferenceController;
|
||||
import com.android.settings.applications.defaultapps.DefaultPhonePreferenceController;
|
||||
import com.android.settings.applications.defaultapps.DefaultSmsPreferenceController;
|
||||
import com.android.settings.applications.defaultapps.DefaultWorkBrowserPreferenceController;
|
||||
import com.android.settings.applications.defaultapps.DefaultWorkPhonePreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.widget.PreferenceCategoryController;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable
|
||||
public class DefaultAppSettings extends DashboardFragment {
|
||||
|
||||
static final String TAG = "DefaultAppSettings";
|
||||
|
||||
private static final String KEY_DEFAULT_WORK_CATEGORY = "work_app_defaults";
|
||||
private static final String KEY_ASSIST_VOICE_INPUT = "assist_and_voice_input";
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.app_default_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
return buildPreferenceControllers(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.APPLICATIONS_ADVANCED;
|
||||
}
|
||||
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
final List<AbstractPreferenceController> workControllers = new ArrayList<>();
|
||||
workControllers.add(new DefaultWorkPhonePreferenceController(context));
|
||||
workControllers.add(new DefaultWorkBrowserPreferenceController(context));
|
||||
controllers.addAll(workControllers);
|
||||
controllers.add(new PreferenceCategoryController(
|
||||
context, KEY_DEFAULT_WORK_CATEGORY).setChildren(workControllers));
|
||||
controllers.add(new DefaultAssistPreferenceController(context, KEY_ASSIST_VOICE_INPUT,
|
||||
false /* showSetting */));
|
||||
controllers.add(new DefaultBrowserPreferenceController(context));
|
||||
controllers.add(new DefaultPhonePreferenceController(context));
|
||||
controllers.add(new DefaultSmsPreferenceController(context));
|
||||
controllers.add(new DefaultEmergencyPreferenceController(context));
|
||||
controllers.add(new DefaultHomePreferenceController(context));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.app_default_settings;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractPreferenceController> createPreferenceControllers(
|
||||
Context context) {
|
||||
return buildPreferenceControllers(context);
|
||||
}
|
||||
};
|
||||
|
||||
static class SummaryProvider implements SummaryLoader.SummaryProvider {
|
||||
|
||||
private final Context mContext;
|
||||
private final SummaryLoader mSummaryLoader;
|
||||
private final DefaultSmsPreferenceController mDefaultSmsPreferenceController;
|
||||
private final DefaultBrowserPreferenceController mDefaultBrowserPreferenceController;
|
||||
private final DefaultPhonePreferenceController mDefaultPhonePreferenceController;
|
||||
|
||||
public SummaryProvider(Context context, SummaryLoader summaryLoader) {
|
||||
mContext = context;
|
||||
mSummaryLoader = summaryLoader;
|
||||
mDefaultSmsPreferenceController = new DefaultSmsPreferenceController(mContext);
|
||||
mDefaultBrowserPreferenceController = new DefaultBrowserPreferenceController(mContext);
|
||||
mDefaultPhonePreferenceController = new DefaultPhonePreferenceController(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setListening(boolean listening) {
|
||||
if (!listening) {
|
||||
return;
|
||||
}
|
||||
final List<CharSequence> summaries = new ArrayList<>();
|
||||
if(!TextUtils.isEmpty(mDefaultBrowserPreferenceController.getDefaultAppLabel())) {
|
||||
summaries.add(mDefaultBrowserPreferenceController.getDefaultAppLabel());
|
||||
}
|
||||
if(!TextUtils.isEmpty(mDefaultPhonePreferenceController.getDefaultAppLabel())) {
|
||||
summaries.add(mDefaultPhonePreferenceController.getDefaultAppLabel());
|
||||
}
|
||||
if(!TextUtils.isEmpty(mDefaultSmsPreferenceController.getDefaultAppLabel())) {
|
||||
summaries.add(mDefaultSmsPreferenceController.getDefaultAppLabel());
|
||||
}
|
||||
|
||||
CharSequence summary = ListFormatter.getInstance().format(summaries);
|
||||
if (!TextUtils.isEmpty(summary)) {
|
||||
mSummaryLoader.setSummary(this, summary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY =
|
||||
new SummaryLoader.SummaryProviderFactory() {
|
||||
@Override
|
||||
public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
|
||||
SummaryLoader summaryLoader) {
|
||||
return new DefaultAppSettings.SummaryProvider(activity, summaryLoader);
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -11,66 +11,38 @@
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package com.android.settings.applications.defaultapps;
|
||||
package com.android.settings.applications;
|
||||
|
||||
import android.app.role.RoleManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.icu.text.ListFormatter;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* STOPSHIP(b/110557011): Remove once the new UI is ready.
|
||||
*/
|
||||
public class RolesPreferenceController extends BasePreferenceController {
|
||||
public class DefaultAppsPreferenceController extends BasePreferenceController {
|
||||
|
||||
private final PackageManager mPackageManager;
|
||||
private final RoleManager mRoleManager;
|
||||
|
||||
private final Intent mIntent;
|
||||
|
||||
public RolesPreferenceController(Context context, String preferenceKey) {
|
||||
public DefaultAppsPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
|
||||
mPackageManager = context.getPackageManager();
|
||||
mRoleManager = context.getSystemService(RoleManager.class);
|
||||
|
||||
final String packageName = mPackageManager.getPermissionControllerPackageName();
|
||||
if (packageName != null) {
|
||||
mIntent = new Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS)
|
||||
.setPackage(packageName);
|
||||
} else {
|
||||
mIntent = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mIntent != null ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (TextUtils.equals(preference.getKey(), mPreferenceKey)) {
|
||||
if (mIntent != null) {
|
||||
mContext.startActivity(mIntent);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.applications.DefaultAppInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Fragment for choosing default browser.
|
||||
*/
|
||||
public class DefaultBrowserPicker extends DefaultAppPickerFragment {
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.default_browser_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.DEFAULT_BROWSER_PICKER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultKey() {
|
||||
return mPm.getDefaultBrowserPackageNameAsUser(mUserId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultKey(String packageName) {
|
||||
return mPm.setDefaultBrowserPackageNameAsUser(packageName, mUserId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DefaultAppInfo> getCandidates() {
|
||||
final List<DefaultAppInfo> candidates = new ArrayList<>();
|
||||
final Context context = getContext();
|
||||
// Resolve that intent and check that the handleAllWebDataURI boolean is set
|
||||
final List<ResolveInfo> list =
|
||||
DefaultBrowserPreferenceController.getCandidates(mPm, mUserId);
|
||||
|
||||
for (ResolveInfo info : list) {
|
||||
try {
|
||||
candidates.add(new DefaultAppInfo(context, mPm, mUserId,
|
||||
mPm.getApplicationInfoAsUser(info.activityInfo.packageName, 0, mUserId)));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
// Skip unknown packages.
|
||||
}
|
||||
}
|
||||
|
||||
return candidates;
|
||||
}
|
||||
}
|
@@ -1,198 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.ComponentInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArraySet;
|
||||
import android.util.IconDrawableFactory;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settingslib.applications.DefaultAppInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class DefaultBrowserPreferenceController extends DefaultAppPreferenceController {
|
||||
|
||||
private static final String TAG = "BrowserPrefCtrl";
|
||||
|
||||
static final Intent BROWSE_PROBE = new Intent()
|
||||
.setAction(Intent.ACTION_VIEW)
|
||||
.addCategory(Intent.CATEGORY_BROWSABLE)
|
||||
.setData(Uri.parse("http:"))
|
||||
.addFlags(Intent.FLAG_IGNORE_EPHEMERAL);
|
||||
|
||||
public DefaultBrowserPreferenceController(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
final List<ResolveInfo> candidates = getCandidates(mPackageManager, mUserId);
|
||||
return candidates != null && !candidates.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return "default_browser";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
final CharSequence defaultAppLabel = getDefaultAppLabel();
|
||||
if (!TextUtils.isEmpty(defaultAppLabel)) {
|
||||
preference.setSummary(defaultAppLabel);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DefaultAppInfo getDefaultAppInfo() {
|
||||
try {
|
||||
final String packageName = mPackageManager.getDefaultBrowserPackageNameAsUser(mUserId);
|
||||
Log.d(TAG, "Get default browser package: " + packageName);
|
||||
return new DefaultAppInfo(mContext, mPackageManager, mUserId,
|
||||
mPackageManager.getApplicationInfoAsUser(packageName, 0, mUserId));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getDefaultAppLabel() {
|
||||
if (!isAvailable()) {
|
||||
return null;
|
||||
}
|
||||
final DefaultAppInfo defaultApp = getDefaultAppInfo();
|
||||
final CharSequence defaultAppLabel = defaultApp != null ? defaultApp.loadLabel() : null;
|
||||
if (!TextUtils.isEmpty(defaultAppLabel)) {
|
||||
return defaultAppLabel;
|
||||
}
|
||||
return getOnlyAppLabel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getDefaultAppIcon() {
|
||||
if (!isAvailable()) {
|
||||
return null;
|
||||
}
|
||||
final DefaultAppInfo defaultApp = getDefaultAppInfo();
|
||||
if (defaultApp != null) {
|
||||
return defaultApp.loadIcon();
|
||||
}
|
||||
return getOnlyAppIcon();
|
||||
}
|
||||
|
||||
static List<ResolveInfo> getCandidates(PackageManager packageManager, int userId) {
|
||||
final List<ResolveInfo> candidates = new ArrayList<>();
|
||||
// Resolve that intent and check that the handleAllWebDataURI boolean is set
|
||||
final List<ResolveInfo> list = packageManager.queryIntentActivitiesAsUser(
|
||||
BROWSE_PROBE, PackageManager.MATCH_ALL, userId);
|
||||
if (list != null) {
|
||||
final Set<String> addedPackages = new ArraySet<>();
|
||||
for (ResolveInfo info : list) {
|
||||
if (!info.handleAllWebDataURI || info.activityInfo == null
|
||||
|| !info.activityInfo.enabled
|
||||
|| !info.activityInfo.applicationInfo.enabled) {
|
||||
continue;
|
||||
}
|
||||
final String packageName = info.activityInfo.packageName;
|
||||
if (addedPackages.contains(packageName)) {
|
||||
continue;
|
||||
}
|
||||
candidates.add(info);
|
||||
addedPackages.add(packageName);
|
||||
}
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
private String getOnlyAppLabel() {
|
||||
// Resolve that intent and check that the handleAllWebDataURI boolean is set
|
||||
final List<ResolveInfo> list = getCandidates(mPackageManager, mUserId);
|
||||
if (list != null && list.size() == 1) {
|
||||
final ResolveInfo info = list.get(0);
|
||||
final String label = info.loadLabel(mPackageManager).toString();
|
||||
final ComponentInfo cn = info.getComponentInfo();
|
||||
final String packageName = cn == null ? null : cn.packageName;
|
||||
Log.d(TAG, "Getting label for the only browser app: " + packageName + label);
|
||||
return label;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
Drawable getOnlyAppIcon() {
|
||||
final List<ResolveInfo> list = getCandidates(mPackageManager, mUserId);
|
||||
if (list != null && list.size() == 1) {
|
||||
final ResolveInfo info = list.get(0);
|
||||
final ComponentInfo cn = info.getComponentInfo();
|
||||
final String packageName = cn == null ? null : cn.packageName;
|
||||
if (TextUtils.isEmpty(packageName)) {
|
||||
return null;
|
||||
}
|
||||
final ApplicationInfo appInfo;
|
||||
try {
|
||||
appInfo = mPackageManager.getApplicationInfoAsUser(packageName, 0, mUserId);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log.w(TAG, "Error getting app info for " + packageName);
|
||||
return null;
|
||||
}
|
||||
Log.d(TAG, "Getting icon for the only browser app: " + packageName);
|
||||
final IconDrawableFactory iconFactory = IconDrawableFactory.newInstance(mContext);
|
||||
return iconFactory.getBadgedIcon(cn, appInfo, mUserId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the pkg contains browser capability
|
||||
*/
|
||||
public static boolean hasBrowserPreference(String pkg, Context context, int userId) {
|
||||
final Intent intent = new Intent(BROWSE_PROBE);
|
||||
intent.setPackage(pkg);
|
||||
final List<ResolveInfo> resolveInfos = context.getPackageManager()
|
||||
.queryIntentActivitiesAsUser(intent, 0 /* flags */, userId);
|
||||
return resolveInfos != null && resolveInfos.size() != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the pkg is the default browser
|
||||
*/
|
||||
public boolean isBrowserDefault(String pkg, int userId) {
|
||||
final String defaultPackage = mPackageManager.getDefaultBrowserPackageNameAsUser(userId);
|
||||
if (defaultPackage != null) {
|
||||
return defaultPackage.equals(pkg);
|
||||
}
|
||||
|
||||
final List<ResolveInfo> list = getCandidates(mPackageManager, userId);
|
||||
// There is only 1 app, it must be the default browser.
|
||||
return list != null && list.size() == 1;
|
||||
}
|
||||
}
|
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
import android.app.role.RoleManager;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Process;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.util.CollectionUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settingslib.applications.DefaultAppInfo;
|
||||
import com.android.settingslib.widget.CandidateInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultEmergencyPicker extends DefaultAppPickerFragment {
|
||||
private static final String TAG = "DefaultEmergencyPicker";
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.DEFAULT_EMERGENCY_APP_PICKER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.default_emergency_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DefaultAppInfo> getCandidates() {
|
||||
final List<DefaultAppInfo> candidates = new ArrayList<>();
|
||||
final List<ResolveInfo> infos = mPm.queryIntentActivities(
|
||||
DefaultEmergencyPreferenceController.QUERY_INTENT, 0);
|
||||
PackageInfo bestMatch = null;
|
||||
final Context context = getContext();
|
||||
for (ResolveInfo info : infos) {
|
||||
try {
|
||||
final PackageInfo packageInfo =
|
||||
mPm.getPackageInfo(info.activityInfo.packageName, 0);
|
||||
final ApplicationInfo appInfo = packageInfo.applicationInfo;
|
||||
candidates.add(new DefaultAppInfo(context, mPm, mUserId, appInfo));
|
||||
// Get earliest installed system app.
|
||||
if (isSystemApp(appInfo) && (bestMatch == null ||
|
||||
bestMatch.firstInstallTime > packageInfo.firstInstallTime)) {
|
||||
bestMatch = packageInfo;
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
// Skip unknown packages.
|
||||
}
|
||||
if (bestMatch != null) {
|
||||
final String defaultKey = getDefaultKey();
|
||||
if (TextUtils.isEmpty(defaultKey)) {
|
||||
setDefaultKey(bestMatch.packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getConfirmationMessage(CandidateInfo info) {
|
||||
return Utils.isPackageDirectBootAware(getContext(), info.getKey()) ? null
|
||||
: getContext().getString(R.string.direct_boot_unaware_dialog_message);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultKey() {
|
||||
RoleManager roleManager = getContext().getSystemService(RoleManager.class);
|
||||
return CollectionUtils.firstOrNull(roleManager.getRoleHolders(RoleManager.ROLE_EMERGENCY));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultKey(String key) {
|
||||
final String previousValue = getDefaultKey();
|
||||
|
||||
if (!TextUtils.isEmpty(key) && !TextUtils.equals(key, previousValue)) {
|
||||
getContext().getSystemService(RoleManager.class).addRoleHolderAsUser(
|
||||
RoleManager.ROLE_EMERGENCY, key, 0, Process.myUserHandle(),
|
||||
AsyncTask.THREAD_POOL_EXECUTOR, successful -> {
|
||||
if (!successful) {
|
||||
Log.e(TAG, "Failed to set emergency default app.");
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isSystemApp(ApplicationInfo info) {
|
||||
return info != null && (info.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
|
||||
}
|
||||
}
|
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
import android.app.role.RoleManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.internal.util.CollectionUtils;
|
||||
import com.android.settingslib.applications.DefaultAppInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultEmergencyPreferenceController extends DefaultAppPreferenceController {
|
||||
|
||||
private static final boolean DEFAULT_EMERGENCY_APP_IS_CONFIGURABLE = false;
|
||||
|
||||
public static final Intent QUERY_INTENT = new Intent(
|
||||
TelephonyManager.ACTION_EMERGENCY_ASSISTANCE);
|
||||
|
||||
public DefaultEmergencyPreferenceController(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return DEFAULT_EMERGENCY_APP_IS_CONFIGURABLE
|
||||
&& isCapable()
|
||||
&& mPackageManager.resolveActivity(QUERY_INTENT, 0) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return "default_emergency_app";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DefaultAppInfo getDefaultAppInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isCapable() {
|
||||
return TelephonyManager.EMERGENCY_ASSISTANCE_ENABLED
|
||||
&& mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_voice_capable);
|
||||
}
|
||||
|
||||
public static boolean hasEmergencyPreference(String pkg, Context context) {
|
||||
Intent i = new Intent(QUERY_INTENT);
|
||||
i.setPackage(pkg);
|
||||
final List<ResolveInfo> resolveInfos =
|
||||
context.getPackageManager().queryIntentActivities(i, 0);
|
||||
return resolveInfos != null && resolveInfos.size() != 0;
|
||||
}
|
||||
|
||||
public static boolean isEmergencyDefault(String pkg, Context context) {
|
||||
String defaultPackage = CollectionUtils.firstOrNull(
|
||||
context.getSystemService(RoleManager.class)
|
||||
.getRoleHolders(RoleManager.ROLE_EMERGENCY));
|
||||
return defaultPackage != null && defaultPackage.equals(pkg);
|
||||
}
|
||||
}
|
@@ -1,152 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.applications.DefaultAppInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultHomePicker extends DefaultAppPickerFragment {
|
||||
|
||||
private String mPackageName;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
mPackageName = context.getPackageName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.default_home_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.DEFAULT_HOME_PICKER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DefaultAppInfo> getCandidates() {
|
||||
final boolean mustSupportManagedProfile = hasManagedProfile();
|
||||
final List<DefaultAppInfo> candidates = new ArrayList<>();
|
||||
final List<ResolveInfo> homeActivities = new ArrayList<>();
|
||||
final Context context = getContext();
|
||||
mPm.getHomeActivities(homeActivities);
|
||||
|
||||
for (ResolveInfo resolveInfo : homeActivities) {
|
||||
final ActivityInfo info = resolveInfo.activityInfo;
|
||||
final ComponentName activityName = new ComponentName(info.packageName, info.name);
|
||||
if (info.packageName.equals(mPackageName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final String summary;
|
||||
boolean enabled = true;
|
||||
if (mustSupportManagedProfile && !launcherHasManagedProfilesFeature(resolveInfo)) {
|
||||
summary = getContext().getString(R.string.home_work_profile_not_supported);
|
||||
enabled = false;
|
||||
} else {
|
||||
summary = null;
|
||||
}
|
||||
final DefaultAppInfo candidate =
|
||||
new DefaultAppInfo(context, mPm, mUserId, activityName, summary, enabled);
|
||||
candidates.add(candidate);
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultKey() {
|
||||
final ArrayList<ResolveInfo> homeActivities = new ArrayList<>();
|
||||
final ComponentName currentDefaultHome = mPm.getHomeActivities(homeActivities);
|
||||
if (currentDefaultHome != null) {
|
||||
return currentDefaultHome.flattenToString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultKey(String key) {
|
||||
if (!TextUtils.isEmpty(key)) {
|
||||
final ComponentName component = ComponentName.unflattenFromString(key);
|
||||
final List<ResolveInfo> homeActivities = new ArrayList<>();
|
||||
mPm.getHomeActivities(homeActivities);
|
||||
final List<ComponentName> allComponents = new ArrayList<>();
|
||||
for (ResolveInfo info : homeActivities) {
|
||||
final ActivityInfo appInfo = info.activityInfo;
|
||||
ComponentName activityName = new ComponentName(appInfo.packageName, appInfo.name);
|
||||
allComponents.add(activityName);
|
||||
}
|
||||
mPm.replacePreferredActivity(
|
||||
DefaultHomePreferenceController.HOME_FILTER,
|
||||
IntentFilter.MATCH_CATEGORY_EMPTY,
|
||||
allComponents.toArray(new ComponentName[0]),
|
||||
component);
|
||||
|
||||
// Launch the new Home app so the change is immediately visible even if
|
||||
// the Home button is not pressed.
|
||||
final Context context = getContext();
|
||||
Intent i = new Intent(Intent.ACTION_MAIN);
|
||||
i.addCategory(Intent.CATEGORY_HOME);
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(i);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean hasManagedProfile() {
|
||||
final Context context = getContext();
|
||||
List<UserInfo> profiles = mUserManager.getProfiles(context.getUserId());
|
||||
for (UserInfo userInfo : profiles) {
|
||||
if (userInfo.isManagedProfile()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean launcherHasManagedProfilesFeature(ResolveInfo resolveInfo) {
|
||||
try {
|
||||
ApplicationInfo appInfo = mPm.getApplicationInfo(resolveInfo.activityInfo.packageName,
|
||||
0 /* default flags */);
|
||||
return versionNumberAtLeastL(appInfo.targetSdkVersion);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean versionNumberAtLeastL(int versionNumber) {
|
||||
return versionNumber >= Build.VERSION_CODES.LOLLIPOP;
|
||||
}
|
||||
}
|
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.applications.DefaultAppInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultHomePreferenceController extends DefaultAppPreferenceController {
|
||||
|
||||
static final IntentFilter HOME_FILTER;
|
||||
|
||||
private final String mPackageName;
|
||||
|
||||
static {
|
||||
HOME_FILTER = new IntentFilter(Intent.ACTION_MAIN);
|
||||
HOME_FILTER.addCategory(Intent.CATEGORY_HOME);
|
||||
HOME_FILTER.addCategory(Intent.CATEGORY_DEFAULT);
|
||||
}
|
||||
|
||||
public DefaultHomePreferenceController(Context context) {
|
||||
super(context);
|
||||
mPackageName = mContext.getPackageName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return "default_home";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mContext.getResources().getBoolean(R.bool.config_show_default_home);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DefaultAppInfo getDefaultAppInfo() {
|
||||
final ArrayList<ResolveInfo> homeActivities = new ArrayList<>();
|
||||
final ComponentName currentDefaultHome = mPackageManager.getHomeActivities(homeActivities);
|
||||
if (currentDefaultHome != null) {
|
||||
return new DefaultAppInfo(mContext, mPackageManager, mUserId, currentDefaultHome);
|
||||
}
|
||||
final ActivityInfo onlyAppInfo = getOnlyAppInfo(homeActivities);
|
||||
if (onlyAppInfo != null) {
|
||||
return new DefaultAppInfo(mContext, mPackageManager, mUserId,
|
||||
onlyAppInfo.getComponentName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ActivityInfo getOnlyAppInfo(List<ResolveInfo> homeActivities) {
|
||||
final List<ActivityInfo> appLabels = new ArrayList<>();
|
||||
|
||||
mPackageManager.getHomeActivities(homeActivities);
|
||||
for (ResolveInfo candidate : homeActivities) {
|
||||
final ActivityInfo info = candidate.activityInfo;
|
||||
if (info.packageName.equals(mPackageName)) {
|
||||
continue;
|
||||
}
|
||||
appLabels.add(info);
|
||||
}
|
||||
return appLabels.size() == 1
|
||||
? appLabels.get(0)
|
||||
: null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Intent getSettingIntent(DefaultAppInfo info) {
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
final String packageName;
|
||||
if (info.componentName != null) {
|
||||
packageName = info.componentName.getPackageName();
|
||||
} else if (info.packageItemInfo != null) {
|
||||
packageName = info.packageItemInfo.packageName;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_APPLICATION_PREFERENCES)
|
||||
.setPackage(packageName)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
return intent.resolveActivity(mPackageManager) != null ? intent : null;
|
||||
}
|
||||
|
||||
public static boolean hasHomePreference(String pkg, Context context) {
|
||||
ArrayList<ResolveInfo> homeActivities = new ArrayList<>();
|
||||
PackageManager pm = context.getPackageManager();
|
||||
pm.getHomeActivities(homeActivities);
|
||||
for (int i = 0; i < homeActivities.size(); i++) {
|
||||
if (homeActivities.get(i).activityInfo.packageName.equals(pkg)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isHomeDefault(String pkg, PackageManager pm) {
|
||||
final ArrayList<ResolveInfo> homeActivities = new ArrayList<>();
|
||||
ComponentName def = pm.getHomeActivities(homeActivities);
|
||||
|
||||
return def == null || def.getPackageName().equals(pkg);
|
||||
}
|
||||
}
|
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.telecom.DefaultDialerManager;
|
||||
import android.telecom.TelecomManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.applications.DefaultAppInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultPhonePicker extends DefaultAppPickerFragment {
|
||||
|
||||
private DefaultKeyUpdater mDefaultKeyUpdater;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.DEFAULT_PHONE_PICKER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
mDefaultKeyUpdater = new DefaultKeyUpdater(
|
||||
(TelecomManager) context.getSystemService(Context.TELECOM_SERVICE));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.default_phone_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DefaultAppInfo> getCandidates() {
|
||||
final List<DefaultAppInfo> candidates = new ArrayList<>();
|
||||
final List<String> dialerPackages =
|
||||
DefaultDialerManager.getInstalledDialerApplications(getContext(), mUserId);
|
||||
final Context context = getContext();
|
||||
for (String packageName : dialerPackages) {
|
||||
try {
|
||||
candidates.add(new DefaultAppInfo(context, mPm, mUserId,
|
||||
mPm.getApplicationInfoAsUser(packageName, 0, mUserId)));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
// Skip unknown packages.
|
||||
}
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultKey() {
|
||||
return mDefaultKeyUpdater.getDefaultDialerApplication(getContext(), mUserId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSystemDefaultKey() {
|
||||
return mDefaultKeyUpdater.getSystemDialerPackage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultKey(String key) {
|
||||
if (!TextUtils.isEmpty(key) && !TextUtils.equals(key, getDefaultKey())) {
|
||||
mBatteryUtils.clearForceAppStandby(key);
|
||||
return mDefaultKeyUpdater.setDefaultDialerApplication(getContext(), key, mUserId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper class to handle default phone app update.
|
||||
*/
|
||||
static class DefaultKeyUpdater {
|
||||
private final TelecomManager mTelecomManager;
|
||||
|
||||
public DefaultKeyUpdater(TelecomManager telecomManager) {
|
||||
mTelecomManager = telecomManager;
|
||||
}
|
||||
|
||||
public String getSystemDialerPackage() {
|
||||
return mTelecomManager.getSystemDialerPackage();
|
||||
}
|
||||
|
||||
public String getDefaultDialerApplication(Context context, int uid) {
|
||||
return DefaultDialerManager.getDefaultDialerApplication(context, uid);
|
||||
}
|
||||
|
||||
public boolean setDefaultDialerApplication(Context context, String key, int uid) {
|
||||
return DefaultDialerManager.setDefaultDialerApplication(context, key, uid);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.telecom.DefaultDialerManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.settingslib.applications.DefaultAppInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultPhonePreferenceController extends DefaultAppPreferenceController {
|
||||
|
||||
public DefaultPhonePreferenceController(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
final TelephonyManager tm =
|
||||
(TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (!tm.isVoiceCapable()) {
|
||||
return false;
|
||||
}
|
||||
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
final boolean hasUserRestriction =
|
||||
um.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS);
|
||||
|
||||
if (hasUserRestriction) {
|
||||
return false;
|
||||
}
|
||||
final List<String> candidates = getCandidates();
|
||||
return candidates != null && !candidates.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return "default_phone_app";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DefaultAppInfo getDefaultAppInfo() {
|
||||
try {
|
||||
return new DefaultAppInfo(mContext, mPackageManager, mUserId,
|
||||
mPackageManager.getApplicationInfo(
|
||||
DefaultDialerManager.getDefaultDialerApplication(mContext, mUserId), 0));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getCandidates() {
|
||||
return DefaultDialerManager.getInstalledDialerApplications(mContext, mUserId);
|
||||
}
|
||||
|
||||
public static boolean hasPhonePreference(String pkg, Context context) {
|
||||
List<String> dialerPackages =
|
||||
DefaultDialerManager.getInstalledDialerApplications(context, UserHandle.myUserId());
|
||||
return dialerPackages.contains(pkg);
|
||||
}
|
||||
|
||||
public static boolean isPhoneDefault(String pkg, Context context) {
|
||||
String def = DefaultDialerManager.getDefaultDialerApplication(context,
|
||||
UserHandle.myUserId());
|
||||
return def != null && def.equals(pkg);
|
||||
}
|
||||
}
|
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.internal.telephony.SmsApplication;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settingslib.applications.DefaultAppInfo;
|
||||
import com.android.settingslib.widget.CandidateInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultSmsPicker extends DefaultAppPickerFragment {
|
||||
|
||||
private DefaultKeyUpdater mDefaultKeyUpdater = new DefaultKeyUpdater();
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.DEFAULT_SMS_PICKER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.default_sms_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DefaultAppInfo> getCandidates() {
|
||||
final Context context = getContext();
|
||||
final Collection<SmsApplication.SmsApplicationData> smsApplications =
|
||||
SmsApplication.getApplicationCollection(context);
|
||||
final List<DefaultAppInfo> candidates = new ArrayList<>(smsApplications.size());
|
||||
|
||||
for (SmsApplication.SmsApplicationData smsApplicationData : smsApplications) {
|
||||
try {
|
||||
candidates.add(new DefaultAppInfo(context, mPm, mUserId,
|
||||
mPm.getApplicationInfoAsUser(smsApplicationData.mPackageName, 0, mUserId)));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
// Skip unknown packages.
|
||||
}
|
||||
}
|
||||
|
||||
return candidates;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultKey() {
|
||||
return mDefaultKeyUpdater.getDefaultApplication(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultKey(String key) {
|
||||
if (!TextUtils.isEmpty(key) && !TextUtils.equals(key, getDefaultKey())) {
|
||||
mDefaultKeyUpdater.setDefaultApplication(getContext(), key);
|
||||
mBatteryUtils.clearForceAppStandby(key);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getConfirmationMessage(CandidateInfo info) {
|
||||
return Utils.isPackageDirectBootAware(getContext(), info.getKey()) ? null
|
||||
: getContext().getString(R.string.direct_boot_unaware_dialog_message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper class to handle default phone app update.
|
||||
*/
|
||||
static class DefaultKeyUpdater {
|
||||
|
||||
public String getDefaultApplication(Context context) {
|
||||
final ComponentName appName = SmsApplication.getDefaultSmsApplication(context, true);
|
||||
if (appName != null) {
|
||||
return appName.getPackageName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setDefaultApplication(Context context, String key) {
|
||||
SmsApplication.setDefaultApplication(key, context);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.internal.telephony.SmsApplication;
|
||||
import com.android.settingslib.applications.DefaultAppInfo;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class DefaultSmsPreferenceController extends DefaultAppPreferenceController {
|
||||
|
||||
public DefaultSmsPreferenceController(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
boolean isRestrictedUser = mUserManager.getUserInfo(mUserId).isRestricted();
|
||||
TelephonyManager tm =
|
||||
(TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
return !isRestrictedUser && tm.isSmsCapable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return "default_sms_app";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DefaultAppInfo getDefaultAppInfo() {
|
||||
final ComponentName app = SmsApplication.getDefaultSmsApplication(mContext, true);
|
||||
if (app != null) {
|
||||
return new DefaultAppInfo(mContext, mPackageManager, mUserId, app);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasSmsPreference(String pkg, Context context) {
|
||||
Collection<SmsApplication.SmsApplicationData> smsApplications =
|
||||
SmsApplication.getApplicationCollection(context);
|
||||
for (SmsApplication.SmsApplicationData data : smsApplications) {
|
||||
if (data.mPackageName.equals(pkg)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isSmsDefault(String pkg, Context context) {
|
||||
ComponentName appName = SmsApplication.getDefaultSmsApplication(context, true);
|
||||
return appName != null && appName.getPackageName().equals(pkg);
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
|
||||
|
||||
public class DefaultWorkBrowserPreferenceController extends DefaultBrowserPreferenceController {
|
||||
|
||||
public static final String KEY = "work_default_browser";
|
||||
private final UserHandle mUserHandle;
|
||||
|
||||
public DefaultWorkBrowserPreferenceController(Context context) {
|
||||
super(context);
|
||||
mUserHandle = Utils.getManagedProfile(mUserManager);
|
||||
if (mUserHandle != null) {
|
||||
mUserId = mUserHandle.getIdentifier();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
if (mUserHandle == null) {
|
||||
return false;
|
||||
}
|
||||
return super.isAvailable();
|
||||
}
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
|
||||
public class DefaultWorkPhonePreferenceController extends DefaultPhonePreferenceController {
|
||||
|
||||
public static final String KEY = "work_default_phone_app";
|
||||
private final UserHandle mUserHandle;
|
||||
|
||||
public DefaultWorkPhonePreferenceController(Context context) {
|
||||
super(context);
|
||||
mUserHandle = Utils.getManagedProfile(mUserManager);
|
||||
if (mUserHandle != null) {
|
||||
mUserId = mUserHandle.getIdentifier();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
if (mUserHandle == null) {
|
||||
return false;
|
||||
}
|
||||
return super.isAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY;
|
||||
}
|
||||
}
|
@@ -92,7 +92,6 @@ import com.android.settings.applications.AppStateUsageBridge;
|
||||
import com.android.settings.applications.AppStateUsageBridge.UsageState;
|
||||
import com.android.settings.applications.AppStateWriteSettingsBridge;
|
||||
import com.android.settings.applications.AppStorageSettings;
|
||||
import com.android.settings.applications.DefaultAppSettings;
|
||||
import com.android.settings.applications.InstalledAppCounter;
|
||||
import com.android.settings.applications.UsageAccessDetails;
|
||||
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
|
||||
@@ -704,12 +703,9 @@ public class ManageApplications extends InstrumentedFragment
|
||||
.setResultListener(this, ADVANCED_SETTINGS)
|
||||
.launch();
|
||||
} else {
|
||||
new SubSettingLauncher(getContext())
|
||||
.setDestination(DefaultAppSettings.class.getName())
|
||||
.setTitleRes(R.string.configure_apps)
|
||||
.setSourceMetricsCategory(getMetricsCategory())
|
||||
.setResultListener(this, ADVANCED_SETTINGS)
|
||||
.launch();
|
||||
Intent intent = new Intent(
|
||||
android.provider.Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS);
|
||||
startActivityForResult(intent, ADVANCED_SETTINGS);
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
|
@@ -34,7 +34,6 @@ import com.android.settings.accounts.AccountSyncSettings;
|
||||
import com.android.settings.accounts.ChooseAccountFragment;
|
||||
import com.android.settings.accounts.ManagedProfileSettings;
|
||||
import com.android.settings.applications.AppAndNotificationDashboardFragment;
|
||||
import com.android.settings.applications.DefaultAppSettings;
|
||||
import com.android.settings.applications.ProcessStatsSummary;
|
||||
import com.android.settings.applications.ProcessStatsUi;
|
||||
import com.android.settings.applications.UsageAccessDetails;
|
||||
@@ -247,7 +246,6 @@ public class SettingsGateway {
|
||||
DrawOverlayDetails.class.getName(),
|
||||
WriteSettingsDetails.class.getName(),
|
||||
ExternalSourcesDetails.class.getName(),
|
||||
DefaultAppSettings.class.getName(),
|
||||
WallpaperTypeSettings.class.getName(),
|
||||
VrListenerSettings.class.getName(),
|
||||
PictureInPictureSettings.class.getName(),
|
||||
@@ -308,7 +306,6 @@ public class SettingsGateway {
|
||||
// Home page > Apps & Notifications
|
||||
Settings.UserSettingsActivity.class.getName(),
|
||||
Settings.ConfigureNotificationSettingsActivity.class.getName(),
|
||||
Settings.AdvancedAppsActivity.class.getName(),
|
||||
Settings.ManageApplicationsActivity.class.getName(),
|
||||
Settings.PaymentSettingsActivity.class.getName(),
|
||||
// Home page > Security & screen lock
|
||||
|
@@ -23,7 +23,6 @@ import com.android.settings.LegalSettings;
|
||||
import com.android.settings.accounts.AccountDashboardFragment;
|
||||
import com.android.settings.accounts.AccountDetailDashboardFragment;
|
||||
import com.android.settings.applications.AppAndNotificationDashboardFragment;
|
||||
import com.android.settings.applications.DefaultAppSettings;
|
||||
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
|
||||
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
|
||||
import com.android.settings.development.DevelopmentSettingsDashboardFragment;
|
||||
@@ -79,8 +78,6 @@ public class DashboardFragmentRegistry {
|
||||
CategoryKey.CATEGORY_APPS);
|
||||
PARENT_TO_CATEGORY_KEY_MAP.put(PowerUsageSummary.class.getName(),
|
||||
CategoryKey.CATEGORY_BATTERY);
|
||||
PARENT_TO_CATEGORY_KEY_MAP.put(DefaultAppSettings.class.getName(),
|
||||
CategoryKey.CATEGORY_APPS_DEFAULT);
|
||||
PARENT_TO_CATEGORY_KEY_MAP.put(DisplaySettings.class.getName(),
|
||||
CategoryKey.CATEGORY_DISPLAY);
|
||||
PARENT_TO_CATEGORY_KEY_MAP.put(SoundSettings.class.getName(),
|
||||
|
Reference in New Issue
Block a user