blob: 5a9bf0bf5ed2e2496eba09bf93c4d90a6e8c7057 [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;
26import android.preference.PreferenceGroup;
27import android.provider.SearchIndexableResource;
28
29import com.android.settings.search.BaseSearchIndexProvider;
30import com.android.settings.search.Indexable;
31
32import java.util.ArrayList;
33import java.util.Arrays;
34import java.util.List;
35
36public class LegalSettings extends SettingsPreferenceFragment implements Indexable {
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
43 public void onCreate(Bundle icicle) {
44 super.onCreate(icicle);
45 addPreferencesFromResource(R.xml.about_legal);
46
47 final Activity act = getActivity();
48 // These are contained in the "container" preference group
49 PreferenceGroup parentPreference = getPreferenceScreen();
50 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_TERMS,
51 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
52 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_LICENSE,
53 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
54 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_COPYRIGHT,
55 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
56 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_WEBVIEW_LICENSE,
57 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
58 }
59
60 @Override
61 protected int getMetricsCategory() {
62 return InstrumentedFragment.ABOUT_LEGAL_SETTINGS;
63 }
64
65 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
66 new BaseSearchIndexProvider() {
67
68 @Override
69 public List<SearchIndexableResource> getXmlResourcesToIndex(
70 Context context, boolean enabled) {
71 final SearchIndexableResource sir = new SearchIndexableResource(context);
72 sir.xmlResId = R.xml.about_legal;
73 return Arrays.asList(sir);
74 }
75
76 @Override
77 public List<String> getNonIndexableKeys(Context context) {
78 final List<String> keys = new ArrayList<String>();
79 if (!checkIntentAction(context, "android.settings.TERMS")) {
80 keys.add(KEY_TERMS);
81 }
82 if (!checkIntentAction(context, "android.settings.LICENSE")) {
83 keys.add(KEY_LICENSE);
84 }
85 if (!checkIntentAction(context, "android.settings.COPYRIGHT")) {
86 keys.add(KEY_COPYRIGHT);
87 }
88 if (!checkIntentAction(context, "android.settings.WEBVIEW_LICENSE")) {
89 keys.add(KEY_WEBVIEW_LICENSE);
90 }
91 return keys;
92 }
93
94 private boolean checkIntentAction(Context context, String action) {
95 final Intent intent = new Intent(action);
96
97 // Find the activity that is in the system image
98 final PackageManager pm = context.getPackageManager();
99 final List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
100 final int listSize = list.size();
101
102 for (int i = 0; i < listSize; i++) {
103 ResolveInfo resolveInfo = list.get(i);
104 if ((resolveInfo.activityInfo.applicationInfo.flags &
105 ApplicationInfo.FLAG_SYSTEM) != 0) {
106 return true;
107 }
108 }
109
110 return false;
111 }
112 };
113
114}