blob: e9b2694b82ac611693c998df59a3febc63e512bb [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;
34
Jason Monkf9402322015-06-10 10:02:59 -040035import java.util.Arrays;
36import java.util.List;
37
38public class LegalSettings extends SettingsPreferenceFragment implements Indexable {
39
40 private static final String KEY_TERMS = "terms";
41 private static final String KEY_LICENSE = "license";
42 private static final String KEY_COPYRIGHT = "copyright";
43 private static final String KEY_WEBVIEW_LICENSE = "webview_license";
Ben Line4ca92a2017-12-12 16:44:53 -080044 @VisibleForTesting static final String KEY_WALLPAPER_ATTRIBUTIONS = "wallpaper_attributions";
Jason Monkf9402322015-06-10 10:02:59 -040045
46 public void onCreate(Bundle icicle) {
47 super.onCreate(icicle);
48 addPreferencesFromResource(R.xml.about_legal);
49
50 final Activity act = getActivity();
51 // These are contained in the "container" preference group
52 PreferenceGroup parentPreference = getPreferenceScreen();
53 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_TERMS,
54 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
55 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_LICENSE,
56 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
57 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_COPYRIGHT,
58 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
59 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_WEBVIEW_LICENSE,
60 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
Ben Line4ca92a2017-12-12 16:44:53 -080061
62 checkWallpaperAttributionAvailability(act);
Jason Monkf9402322015-06-10 10:02:59 -040063 }
64
65 @Override
Fan Zhang65076132016-08-08 10:25:13 -070066 public int getMetricsCategory() {
Chris Wren9d1bfd12016-01-26 18:04:01 -050067 return MetricsEvent.ABOUT_LEGAL_SETTINGS;
Jason Monkf9402322015-06-10 10:02:59 -040068 }
69
Ben Line4ca92a2017-12-12 16:44:53 -080070 @VisibleForTesting
71 void checkWallpaperAttributionAvailability(Context context) {
72 if (!context.getResources().getBoolean(
73 R.bool.config_show_wallpaper_attribution)) {
74 removePreference(KEY_WALLPAPER_ATTRIBUTIONS);
75 }
76 }
77
Jason Monkf9402322015-06-10 10:02:59 -040078 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
79 new BaseSearchIndexProvider() {
80
81 @Override
82 public List<SearchIndexableResource> getXmlResourcesToIndex(
83 Context context, boolean enabled) {
84 final SearchIndexableResource sir = new SearchIndexableResource(context);
85 sir.xmlResId = R.xml.about_legal;
86 return Arrays.asList(sir);
87 }
88
89 @Override
90 public List<String> getNonIndexableKeys(Context context) {
Matthew Fritze031af9f2017-05-11 13:32:37 -070091 final List<String> keys = super.getNonIndexableKeys(context);
Jason Monkf9402322015-06-10 10:02:59 -040092 if (!checkIntentAction(context, "android.settings.TERMS")) {
93 keys.add(KEY_TERMS);
94 }
95 if (!checkIntentAction(context, "android.settings.LICENSE")) {
96 keys.add(KEY_LICENSE);
97 }
98 if (!checkIntentAction(context, "android.settings.COPYRIGHT")) {
99 keys.add(KEY_COPYRIGHT);
100 }
101 if (!checkIntentAction(context, "android.settings.WEBVIEW_LICENSE")) {
102 keys.add(KEY_WEBVIEW_LICENSE);
103 }
Matthew Fritze031af9f2017-05-11 13:32:37 -0700104 keys.add(KEY_WALLPAPER_ATTRIBUTIONS);
Jason Monkf9402322015-06-10 10:02:59 -0400105 return keys;
106 }
107
108 private boolean checkIntentAction(Context context, String action) {
109 final Intent intent = new Intent(action);
110
111 // Find the activity that is in the system image
112 final PackageManager pm = context.getPackageManager();
113 final List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
114 final int listSize = list.size();
115
116 for (int i = 0; i < listSize; i++) {
117 ResolveInfo resolveInfo = list.get(i);
118 if ((resolveInfo.activityInfo.applicationInfo.flags &
119 ApplicationInfo.FLAG_SYSTEM) != 0) {
120 return true;
121 }
122 }
123
124 return false;
125 }
126 };
127
128}