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.tv.settings.device.apps; 18 19 import static com.android.tv.settings.util.InstrumentationUtils.logEntrySelected; 20 21 import android.app.Activity; 22 import android.app.Application; 23 import android.app.tvsettings.TvSettingsEnums; 24 import android.content.Context; 25 import android.os.Bundle; 26 import android.text.TextUtils; 27 28 import androidx.annotation.Keep; 29 import androidx.preference.Preference; 30 31 import com.android.internal.logging.nano.MetricsProto; 32 import com.android.settingslib.core.AbstractPreferenceController; 33 import com.android.tv.settings.PreferenceControllerFragment; 34 import com.android.tv.settings.R; 35 36 import java.util.ArrayList; 37 import java.util.List; 38 39 /** 40 * Fragment for managing recent apps, and apps permissions. 41 */ 42 @Keep 43 public class AppsFragment extends PreferenceControllerFragment { 44 45 private static final String KEY_PERMISSIONS = "Permissions"; 46 prepareArgs(Bundle b, String volumeUuid, String volumeName)47 public static void prepareArgs(Bundle b, String volumeUuid, String volumeName) { 48 b.putString(AppsActivity.EXTRA_VOLUME_UUID, volumeUuid); 49 b.putString(AppsActivity.EXTRA_VOLUME_NAME, volumeName); 50 } 51 newInstance(String volumeUuid, String volumeName)52 public static AppsFragment newInstance(String volumeUuid, String volumeName) { 53 final Bundle b = new Bundle(2); 54 prepareArgs(b, volumeUuid, volumeName); 55 final AppsFragment f = new AppsFragment(); 56 f.setArguments(b); 57 return f; 58 } 59 60 @Override onCreatePreferences(Bundle savedInstanceState, String rootKey)61 public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { 62 super.onCreatePreferences(savedInstanceState, rootKey); 63 64 final Preference permissionPreference = findPreference(KEY_PERMISSIONS); 65 final String volumeUuid = getArguments().getString(AppsActivity.EXTRA_VOLUME_UUID); 66 permissionPreference.setVisible(TextUtils.isEmpty(volumeUuid)); 67 permissionPreference.setOnPreferenceClickListener( 68 preference -> { 69 logEntrySelected(TvSettingsEnums.APPS_APP_PERMISSIONS); 70 return false; 71 } 72 ); 73 } 74 75 @Override getPreferenceScreenResId()76 protected int getPreferenceScreenResId() { 77 return R.xml.apps; 78 } 79 80 @Override onCreatePreferenceControllers(Context context)81 protected List<AbstractPreferenceController> onCreatePreferenceControllers(Context context) { 82 final Activity activity = getActivity(); 83 final Application app = activity != null ? activity.getApplication() : null; 84 List<AbstractPreferenceController> controllers = new ArrayList<>(); 85 controllers.add(new RecentAppsPreferenceController(getContext(), app)); 86 return controllers; 87 } 88 89 @Override getMetricsCategory()90 public int getMetricsCategory() { 91 return MetricsProto.MetricsEvent.SETTINGS_APP_NOTIF_CATEGORY; 92 } 93 94 @Override getPageId()95 protected int getPageId() { 96 return TvSettingsEnums.APPS; 97 } 98 } 99