1 /* 2 * Copyright (C) 2018 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.specialaccess; 18 19 import android.app.ActivityManager; 20 import android.content.Context; 21 import android.os.Bundle; 22 23 import androidx.annotation.Keep; 24 import androidx.annotation.VisibleForTesting; 25 import androidx.preference.Preference; 26 27 import com.android.internal.logging.nano.MetricsProto; 28 import com.android.tv.settings.R; 29 import com.android.tv.settings.SettingsPreferenceFragment; 30 31 /** 32 * Screen for Special App Access items 33 */ 34 @Keep 35 public class SpecialAppAccess extends SettingsPreferenceFragment { 36 37 @VisibleForTesting 38 static final String KEY_FEATURE_PIP = "picture_in_picture"; 39 static final String KEY_FEATURE_NOTIFICATION_ACCESS = "notification_access"; 40 private static final String[] DISABLED_FEATURES_LOW_RAM_TV = 41 new String[]{KEY_FEATURE_PIP, KEY_FEATURE_NOTIFICATION_ACCESS}; 42 43 @Override onCreatePreferences(Bundle savedInstanceState, String rootKey)44 public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { 45 setPreferencesFromResource(R.xml.special_app_access, null); 46 47 updatePreferenceStates(); 48 } 49 50 @Override getMetricsCategory()51 public int getMetricsCategory() { 52 return MetricsProto.MetricsEvent.SPECIAL_ACCESS; 53 } 54 55 @VisibleForTesting updatePreferenceStates()56 void updatePreferenceStates() { 57 ActivityManager activityManager = (ActivityManager) getContext() 58 .getSystemService(Context.ACTIVITY_SERVICE); 59 if (activityManager.isLowRamDevice()) { 60 for (String disabledFeature : DISABLED_FEATURES_LOW_RAM_TV) { 61 removePreference(disabledFeature); 62 } 63 } 64 } 65 66 @VisibleForTesting removePreference(String key)67 void removePreference(String key) { 68 final Preference preference = findPreference(key); 69 if (preference != null) { 70 getPreferenceScreen().removePreference(preference); 71 } 72 } 73 } 74