2 * Copyright (C) 2017 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
15 package com.android.settings.applications.appinfo;
17 import android.app.slice.Slice;
18 import android.content.Context;
19 import android.os.Bundle;
20 import android.os.UserManager;
21 import android.support.v7.preference.Preference;
22 import android.text.TextUtils;
24 import com.android.internal.logging.nano.MetricsProto;
25 import com.android.settings.R;
26 import com.android.settings.SettingsActivity;
27 import com.android.settings.Utils;
28 import com.android.settings.applications.DefaultAppSettings;
29 import com.android.settings.core.BasePreferenceController;
32 * Abstract base controller for the default app shortcut preferences that launches the default app
33 * settings with the corresponding default app highlighted.
35 public abstract class DefaultAppShortcutPreferenceControllerBase extends BasePreferenceController {
37 protected final String mPackageName;
39 public DefaultAppShortcutPreferenceControllerBase(Context context, String preferenceKey,
41 super(context, preferenceKey);
42 mPackageName = packageName;
46 public int getAvailabilityStatus() {
47 if (UserManager.get(mContext).isManagedProfile()) {
48 return DISABLED_FOR_USER;
50 return hasAppCapability() ? AVAILABLE : DISABLED_UNSUPPORTED;
54 public Slice getSettingSlice() {
59 public void updateState(Preference preference) {
60 preference.setSummary(isDefaultApp() ? R.string.yes : R.string.no);
64 public boolean handlePreferenceTreeClick(Preference preference) {
65 if (TextUtils.equals(mPreferenceKey, preference.getKey())) {
66 Bundle bundle = new Bundle();
67 bundle.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, mPreferenceKey);
68 Utils.startWithFragment(mContext, DefaultAppSettings.class.getName(), bundle, null, 0,
69 R.string.configure_apps, null, MetricsProto.MetricsEvent.VIEW_UNKNOWN);
76 * Check whether the app has the default app capability
77 * @return true if the app has the default app capability
79 protected abstract boolean hasAppCapability();
82 * Check whether the app is the default app
83 * @return true if the app is the default app
85 protected abstract boolean isDefaultApp();