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 void updateState(Preference preference) {
55 preference.setSummary(isDefaultApp() ? R.string.yes : R.string.no);
59 public boolean handlePreferenceTreeClick(Preference preference) {
60 if (TextUtils.equals(mPreferenceKey, preference.getKey())) {
61 Bundle bundle = new Bundle();
62 bundle.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, mPreferenceKey);
63 Utils.startWithFragment(mContext, DefaultAppSettings.class.getName(), bundle, null, 0,
64 R.string.configure_apps, null, MetricsProto.MetricsEvent.VIEW_UNKNOWN);
71 * Check whether the app has the default app capability
72 * @return true if the app has the default app capability
74 protected abstract boolean hasAppCapability();
77 * Check whether the app is the default app
78 * @return true if the app is the default app
80 protected abstract boolean isDefaultApp();