1 /*
2  * Copyright (C) 2024 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.privatespace;
18 
19 import android.content.Context;
20 import android.text.TextUtils;
21 
22 import androidx.annotation.NonNull;
23 import androidx.annotation.VisibleForTesting;
24 import androidx.preference.PreferenceScreen;
25 
26 import com.android.settings.R;
27 import com.android.settings.core.BasePreferenceController;
28 import com.android.settingslib.HelpUtils;
29 import com.android.settingslib.widget.FooterPreference;
30 
31 /** Preference controller for private space settings footer. */
32 public class PrivateSpaceFooterPreferenceController extends BasePreferenceController {
PrivateSpaceFooterPreferenceController( @onNull Context context, @NonNull String preferenceKey)33     public PrivateSpaceFooterPreferenceController(
34             @NonNull Context context, @NonNull String preferenceKey) {
35         super(context, preferenceKey);
36     }
37 
38     @Override
displayPreference(@onNull PreferenceScreen screen)39     public void displayPreference(@NonNull PreferenceScreen screen) {
40         super.displayPreference(screen);
41         FooterPreference preference = screen.findPreference(getPreferenceKey());
42         setupFooter(preference);
43     }
44 
45     @Override
getAvailabilityStatus()46     public int getAvailabilityStatus() {
47         return android.multiuser.Flags.enablePrivateSpaceFeatures()
48                 ? AVAILABLE
49                 : UNSUPPORTED_ON_DEVICE;
50     }
51 
52     @VisibleForTesting
setupFooter(FooterPreference preference)53     void setupFooter(FooterPreference preference) {
54         final String helpUri = mContext.getString(R.string.private_space_learn_more_url);
55         if (!TextUtils.isEmpty(helpUri) && preference != null) {
56             preference.setLearnMoreAction(
57                     v -> {
58                         mContext.startActivity(
59                                 HelpUtils.getHelpIntent(
60                                         mContext, helpUri, /* backupContext= */ ""));
61                     });
62             preference.setLearnMoreText(mContext.getString(R.string.private_space_learn_more_text));
63         }
64     }
65 }
66