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