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.provider.SearchIndexableResource; 27 import android.support.annotation.VisibleForTesting; 28 import android.support.v7.preference.PreferenceGroup; 29 30 import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 31 import com.android.settings.R; 32 import com.android.settings.search.BaseSearchIndexProvider; 33 import com.android.settings.search.Indexable; 34 35 import java.util.Arrays; 36 import java.util.List; 37 38 public 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"; 44 @VisibleForTesting static final String KEY_WALLPAPER_ATTRIBUTIONS = "wallpaper_attributions"; 45 onCreate(Bundle icicle)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); 61 62 checkWallpaperAttributionAvailability(act); 63 } 64 65 @Override getMetricsCategory()66 public int getMetricsCategory() { 67 return MetricsEvent.ABOUT_LEGAL_SETTINGS; 68 } 69 70 @VisibleForTesting checkWallpaperAttributionAvailability(Context context)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 78 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) { 91 final List<String> keys = super.getNonIndexableKeys(context); 92 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 } 104 keys.add(KEY_WALLPAPER_ATTRIBUTIONS); 105 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 } 129