1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.support; 18 19 import android.app.Activity; 20 import android.content.Context; 21 import android.text.TextUtils; 22 23 import androidx.preference.Preference; 24 25 import com.android.settings.core.BasePreferenceController; 26 import com.android.settings.overlay.FeatureFactory; 27 import com.android.settings.overlay.SupportFeatureProvider; 28 29 public class SupportPreferenceController extends BasePreferenceController { 30 31 private final SupportFeatureProvider mSupportFeatureProvider; 32 33 private Activity mActivity; 34 SupportPreferenceController(Context context, String preferenceKey)35 public SupportPreferenceController(Context context, String preferenceKey) { 36 super(context, preferenceKey); 37 mSupportFeatureProvider = FeatureFactory.getFeatureFactory().getSupportFeatureProvider(); 38 } 39 setActivity(Activity activity)40 public void setActivity(Activity activity) { 41 mActivity = activity; 42 } 43 44 @Override getAvailabilityStatus()45 public int getAvailabilityStatus() { 46 return mSupportFeatureProvider == null ? UNSUPPORTED_ON_DEVICE : AVAILABLE; 47 } 48 49 @Override handlePreferenceTreeClick(Preference preference)50 public boolean handlePreferenceTreeClick(Preference preference) { 51 if (preference == null || mActivity == null || 52 !TextUtils.equals(preference.getKey(), getPreferenceKey())) { 53 return false; 54 } 55 mSupportFeatureProvider.startSupport(mActivity); 56 return true; 57 58 } 59 } 60