1 /*
2  * Copyright (C) 2015 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.tv.settings.about;
18 
19 import static com.android.tv.settings.util.InstrumentationUtils.logEntrySelected;
20 
21 import android.app.AlertDialog;
22 import android.app.tvsettings.TvSettingsEnums;
23 import android.content.Context;
24 import android.os.Bundle;
25 
26 import androidx.annotation.Keep;
27 import androidx.preference.Preference;
28 import androidx.preference.PreferenceScreen;
29 
30 import com.android.tv.settings.PreferenceUtils;
31 import com.android.tv.settings.R;
32 import com.android.tv.settings.SettingsPreferenceFragment;
33 import com.android.tv.settings.overlay.FlavorUtils;
34 
35 @Keep
36 public class LegalFragment extends SettingsPreferenceFragment {
37 
38     private static final String KEY_TERMS = "terms";
39     private static final String KEY_LICENSE = "license";
40     private static final String KEY_COPYRIGHT = "copyright";
41     private static final String KEY_WEBVIEW_LICENSE = "webview_license";
42     private static final String KEY_ADS = "ads";
43 
44     @Override
onCreatePreferences(Bundle savedInstanceState, String rootKey)45     public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
46         setPreferencesFromResource(R.xml.about_legal, null);
47         final PreferenceScreen screen = getPreferenceScreen();
48 
49         final Context context = getActivity();
50         PreferenceUtils.resolveSystemActivityOrRemove(context, screen,
51                 findPreference(KEY_TERMS), PreferenceUtils.FLAG_SET_TITLE);
52         PreferenceUtils.resolveSystemActivityOrRemove(context, screen,
53                 findPreference(KEY_LICENSE), PreferenceUtils.FLAG_SET_TITLE);
54         PreferenceUtils.resolveSystemActivityOrRemove(context, screen,
55                 findPreference(KEY_COPYRIGHT), PreferenceUtils.FLAG_SET_TITLE);
56         PreferenceUtils.resolveSystemActivityOrRemove(context, screen,
57                 findPreference(KEY_WEBVIEW_LICENSE), PreferenceUtils.FLAG_SET_TITLE);
58         if (FlavorUtils.isTwoPanel(getContext())) {
59             Preference adsPref = findPreference(KEY_ADS);
60             if (adsPref != null) {
61                 adsPref.setVisible(false);
62             }
63         } else {
64             PreferenceUtils.resolveSystemActivityOrRemove(context, screen,
65                     findPreference(KEY_ADS), PreferenceUtils.FLAG_SET_TITLE);
66         }
67     }
68 
69     @Override
onPreferenceTreeClick(Preference preference)70     public boolean onPreferenceTreeClick(Preference preference) {
71         switch (preference.getKey()) {
72             case KEY_LICENSE:
73                 logEntrySelected(TvSettingsEnums.SYSTEM_ABOUT_LEGAL_INFO_OPEN_SOURCE);
74                 break;
75             case KEY_TERMS:
76                 logEntrySelected(TvSettingsEnums.SYSTEM_ABOUT_LEGAL_INFO_GOOGLE_LEGAL);
77                 break;
78             case KEY_WEBVIEW_LICENSE:
79                 logEntrySelected(TvSettingsEnums.SYSTEM_ABOUT_LEGAL_INFO_SYSTEM_WEBVIEW);
80                 break;
81         }
82         return super.onPreferenceTreeClick(preference);
83     }
84 
85     @Override
getPageId()86     protected int getPageId() {
87         return TvSettingsEnums.SYSTEM_ABOUT_LEGAL_INFO;
88     }
89 
90     @Override
onDisplayPreferenceDialog(Preference preference)91     public void onDisplayPreferenceDialog(Preference preference) {
92         if (preference instanceof ConsumerInformationDialogPreference) {
93             new AlertDialog.Builder(getContext())
94                     .setMessage(((ConsumerInformationDialogPreference) preference)
95                             .getDialogMessage())
96                     .setPositiveButton(((ConsumerInformationDialogPreference) preference)
97                             .getPositiveButtonText(), (dialog, which) -> {})
98                     .show();
99         } else {
100             super.onDisplayPreferenceDialog(preference);
101         }
102     }
103 }
104