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