Home | History | Annotate | Download | only in applications
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
      5  * except in compliance with the License. You may obtain a copy of the License at
      6  *
      7  *      http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software distributed under the
     10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     11  * KIND, either express or implied. See the License for the specific language governing
     12  * permissions and limitations under the License.
     13  */
     14 
     15 package com.android.settings.applications;
     16 
     17 import android.app.ActivityManager;
     18 import android.content.Context;
     19 import android.os.Bundle;
     20 import android.support.annotation.NonNull;
     21 import android.provider.SearchIndexableResource;
     22 import android.support.v7.preference.Preference;
     23 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
     24 import com.android.settings.R;
     25 import com.android.settings.dashboard.DashboardFragment;
     26 import com.android.settings.search.BaseSearchIndexProvider;
     27 import com.android.settings.search.Indexable;
     28 import com.android.settingslib.core.AbstractPreferenceController;
     29 import java.util.ArrayList;
     30 import java.util.List;
     31 
     32 public class SpecialAccessSettings extends DashboardFragment {
     33 
     34     private static final String TAG = "SpecialAccessSettings";
     35     private static final String[] DISABLED_FEATURES_LOW_RAM =
     36             new String[]{"notification_access", "zen_access", "enabled_vr_listeners",
     37                     "picture_in_picture"};
     38 
     39     @Override
     40     protected String getLogTag() {
     41         return TAG;
     42     }
     43 
     44     @Override
     45     protected int getPreferenceScreenResId() {
     46         return R.xml.special_access;
     47     }
     48 
     49     @Override
     50     public void onCreate(Bundle icicle) {
     51         super.onCreate(icicle);
     52 
     53         if (ActivityManager.isLowRamDeviceStatic()) {
     54             for (String disabledFeature : DISABLED_FEATURES_LOW_RAM) {
     55                 Preference pref = findPreference(disabledFeature);
     56                 if (pref != null) {
     57                     removePreference(disabledFeature);
     58                 }
     59             }
     60         }
     61     }
     62 
     63     @Override
     64     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
     65         return buildPreferenceControllers(context);
     66     }
     67 
     68     private static List<AbstractPreferenceController> buildPreferenceControllers(
     69             @NonNull Context context) {
     70         final List<AbstractPreferenceController> controllers = new ArrayList<>();
     71         controllers.add(new HighPowerAppsController(context));
     72         controllers.add(new DeviceAdministratorsController(context));
     73         controllers.add(new PremiumSmsController(context));
     74         controllers.add(new DataSaverController(context));
     75         controllers.add(new EnabledVrListenersController(context));
     76         return controllers;
     77     }
     78 
     79     @Override
     80     public int getMetricsCategory() {
     81         return MetricsEvent.SPECIAL_ACCESS;
     82     }
     83 
     84     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
     85             new BaseSearchIndexProvider() {
     86                 @Override
     87                 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
     88                         boolean enabled) {
     89                     final ArrayList<SearchIndexableResource> result = new ArrayList<>();
     90 
     91                     final SearchIndexableResource sir = new SearchIndexableResource(context);
     92                     sir.xmlResId = R.xml.special_access;
     93                     result.add(sir);
     94                     return result;
     95                 }
     96 
     97                 @Override
     98                 public List<AbstractPreferenceController> createPreferenceControllers(
     99                         Context context) {
    100                     return buildPreferenceControllers(context);
    101                 }
    102             };
    103 }
    104