blob: 64e4cfc70b408867a07eb41b6bface671f4eb1d5 [file] [log] [blame]
Jason Monkf9402322015-06-10 10:02:59 -04001/*
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
17package com.android.settings;
18
19import android.app.Activity;
20import android.content.Context;
21import android.content.Intent;
22import android.content.pm.ApplicationInfo;
23import android.content.pm.PackageManager;
24import android.content.pm.ResolveInfo;
25import android.os.Bundle;
Jason Monkf9402322015-06-10 10:02:59 -040026import android.provider.SearchIndexableResource;
Ben Line4ca92a2017-12-12 16:44:53 -080027import android.support.annotation.VisibleForTesting;
Jason Monk39b46742015-09-10 15:52:51 -040028import android.support.v7.preference.PreferenceGroup;
Jason Monkf9402322015-06-10 10:02:59 -040029
Tamas Berghammer265d3c22016-06-22 15:34:45 +010030import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Ben Line4ca92a2017-12-12 16:44:53 -080031import com.android.settings.R;
Jason Monkf9402322015-06-10 10:02:59 -040032import com.android.settings.search.BaseSearchIndexProvider;
33import com.android.settings.search.Indexable;
Tony Mantler0fcd6cb2018-03-26 15:17:25 -070034import com.android.settingslib.search.SearchIndexable;
Jason Monkf9402322015-06-10 10:02:59 -040035
Jason Monkf9402322015-06-10 10:02:59 -040036import java.util.Arrays;
37import java.util.List;
38
Tony Mantler0fcd6cb2018-03-26 15:17:25 -070039@SearchIndexable
Jason Monkf9402322015-06-10 10:02:59 -040040public class LegalSettings extends SettingsPreferenceFragment implements Indexable {
41
42 private static final String KEY_TERMS = "terms";
43 private static final String KEY_LICENSE = "license";
44 private static final String KEY_COPYRIGHT = "copyright";
45 private static final String KEY_WEBVIEW_LICENSE = "webview_license";
Ben Line4ca92a2017-12-12 16:44:53 -080046 @VisibleForTesting static final String KEY_WALLPAPER_ATTRIBUTIONS = "wallpaper_attributions";
Jason Monkf9402322015-06-10 10:02:59 -040047
48 public void onCreate(Bundle icicle) {
49 super.onCreate(icicle);
50 addPreferencesFromResource(R.xml.about_legal);
51
52 final Activity act = getActivity();
53 // These are contained in the "container" preference group
54 PreferenceGroup parentPreference = getPreferenceScreen();
55 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_TERMS,
56 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
57 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_LICENSE,
58 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
59 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_COPYRIGHT,
60 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
61 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_WEBVIEW_LICENSE,
62 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
Ben Line4ca92a2017-12-12 16:44:53 -080063
64 checkWallpaperAttributionAvailability(act);
Jason Monkf9402322015-06-10 10:02:59 -040065 }
66
67 @Override
Fan Zhang65076132016-08-08 10:25:13 -070068 public int getMetricsCategory() {
Chris Wren9d1bfd12016-01-26 18:04:01 -050069 return MetricsEvent.ABOUT_LEGAL_SETTINGS;
Jason Monkf9402322015-06-10 10:02:59 -040070 }
71
Ben Line4ca92a2017-12-12 16:44:53 -080072 @VisibleForTesting
73 void checkWallpaperAttributionAvailability(Context context) {
74 if (!context.getResources().getBoolean(
75 R.bool.config_show_wallpaper_attribution)) {
76 removePreference(KEY_WALLPAPER_ATTRIBUTIONS);
77 }
78 }
79
Jason Monkf9402322015-06-10 10:02:59 -040080 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
81 new BaseSearchIndexProvider() {
82
83 @Override
84 public List<SearchIndexableResource> getXmlResourcesToIndex(
85 Context context, boolean enabled) {
86 final SearchIndexableResource sir = new SearchIndexableResource(context);
87 sir.xmlResId = R.xml.about_legal;
88 return Arrays.asList(sir);
89 }
90
91 @Override
92 public List<String> getNonIndexableKeys(Context context) {
Matthew Fritze031af9f2017-05-11 13:32:37 -070093 final List<String> keys = super.getNonIndexableKeys(context);
Jason Monkf9402322015-06-10 10:02:59 -040094 if (!checkIntentAction(context, "android.settings.TERMS")) {
95 keys.add(KEY_TERMS);
96 }
97 if (!checkIntentAction(context, "android.settings.LICENSE")) {
98 keys.add(KEY_LICENSE);
99 }
100 if (!checkIntentAction(context, "android.settings.COPYRIGHT")) {
101 keys.add(KEY_COPYRIGHT);
102 }
103 if (!checkIntentAction(context, "android.settings.WEBVIEW_LICENSE")) {
104 keys.add(KEY_WEBVIEW_LICENSE);
105 }
Matthew Fritze031af9f2017-05-11 13:32:37 -0700106 keys.add(KEY_WALLPAPER_ATTRIBUTIONS);
Jason Monkf9402322015-06-10 10:02:59 -0400107 return keys;
108 }
109
110 private boolean checkIntentAction(Context context, String action) {
111 final Intent intent = new Intent(action);
112
113 // Find the activity that is in the system image
114 final PackageManager pm = context.getPackageManager();
115 final List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
116 final int listSize = list.size();
117
118 for (int i = 0; i < listSize; i++) {
119 ResolveInfo resolveInfo = list.get(i);
120 if ((resolveInfo.activityInfo.applicationInfo.flags &
121 ApplicationInfo.FLAG_SYSTEM) != 0) {
122 return true;
123 }
124 }
125
126 return false;
127 }
128 };
129
130}