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