blob: d5b998891b54ea5d3324808b754dbf8b277ee807 [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;
Jason Monk39b46742015-09-10 15:52:51 -040027import android.support.v7.preference.PreferenceGroup;
Jason Monkf9402322015-06-10 10:02:59 -040028
Tamas Berghammer265d3c22016-06-22 15:34:45 +010029import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Jason Monkf9402322015-06-10 10:02:59 -040030import com.android.settings.search.BaseSearchIndexProvider;
31import com.android.settings.search.Indexable;
32
33import java.util.ArrayList;
34import java.util.Arrays;
35import java.util.List;
36
37public class LegalSettings extends SettingsPreferenceFragment implements Indexable {
38
39 private static final String KEY_TERMS = "terms";
40 private static final String KEY_LICENSE = "license";
41 private static final String KEY_COPYRIGHT = "copyright";
42 private static final String KEY_WEBVIEW_LICENSE = "webview_license";
Matthew Fritze031af9f2017-05-11 13:32:37 -070043 private static final String KEY_WALLPAPER_ATTRIBUTIONS = "wallpaper_attributions";
Jason Monkf9402322015-06-10 10:02:59 -040044
45 public void onCreate(Bundle icicle) {
46 super.onCreate(icicle);
47 addPreferencesFromResource(R.xml.about_legal);
48
49 final Activity act = getActivity();
50 // These are contained in the "container" preference group
51 PreferenceGroup parentPreference = getPreferenceScreen();
52 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_TERMS,
53 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
54 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_LICENSE,
55 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
56 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_COPYRIGHT,
57 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
58 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_WEBVIEW_LICENSE,
59 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
60 }
61
62 @Override
Fan Zhang65076132016-08-08 10:25:13 -070063 public int getMetricsCategory() {
Chris Wren9d1bfd12016-01-26 18:04:01 -050064 return MetricsEvent.ABOUT_LEGAL_SETTINGS;
Jason Monkf9402322015-06-10 10:02:59 -040065 }
66
67 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
68 new BaseSearchIndexProvider() {
69
70 @Override
71 public List<SearchIndexableResource> getXmlResourcesToIndex(
72 Context context, boolean enabled) {
73 final SearchIndexableResource sir = new SearchIndexableResource(context);
74 sir.xmlResId = R.xml.about_legal;
75 return Arrays.asList(sir);
76 }
77
78 @Override
79 public List<String> getNonIndexableKeys(Context context) {
Matthew Fritze031af9f2017-05-11 13:32:37 -070080 final List<String> keys = super.getNonIndexableKeys(context);
Jason Monkf9402322015-06-10 10:02:59 -040081 if (!checkIntentAction(context, "android.settings.TERMS")) {
82 keys.add(KEY_TERMS);
83 }
84 if (!checkIntentAction(context, "android.settings.LICENSE")) {
85 keys.add(KEY_LICENSE);
86 }
87 if (!checkIntentAction(context, "android.settings.COPYRIGHT")) {
88 keys.add(KEY_COPYRIGHT);
89 }
90 if (!checkIntentAction(context, "android.settings.WEBVIEW_LICENSE")) {
91 keys.add(KEY_WEBVIEW_LICENSE);
92 }
Matthew Fritze031af9f2017-05-11 13:32:37 -070093 keys.add(KEY_WALLPAPER_ATTRIBUTIONS);
Jason Monkf9402322015-06-10 10:02:59 -040094 return keys;
95 }
96
97 private boolean checkIntentAction(Context context, String action) {
98 final Intent intent = new Intent(action);
99
100 // Find the activity that is in the system image
101 final PackageManager pm = context.getPackageManager();
102 final List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
103 final int listSize = list.size();
104
105 for (int i = 0; i < listSize; i++) {
106 ResolveInfo resolveInfo = list.get(i);
107 if ((resolveInfo.activityInfo.applicationInfo.flags &
108 ApplicationInfo.FLAG_SYSTEM) != 0) {
109 return true;
110 }
111 }
112
113 return false;
114 }
115 };
116
117}