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.datausage; 16 17 import android.app.settings.SettingsEnums; 18 import android.content.Context; 19 import android.os.Bundle; 20 import android.view.Menu; 21 import android.view.MenuInflater; 22 import android.view.MenuItem; 23 import android.view.View; 24 25 import com.android.settings.R; 26 import com.android.settings.dashboard.DashboardFragment; 27 import com.android.settings.search.BaseSearchIndexProvider; 28 import com.android.settingslib.applications.ApplicationsState; 29 import com.android.settingslib.applications.ApplicationsState.AppFilter; 30 import com.android.settingslib.search.SearchIndexable; 31 32 @SearchIndexable 33 public class UnrestrictedDataAccess extends DashboardFragment { 34 35 private static final String TAG = "UnrestrictedDataAccess"; 36 37 private static final int MENU_SHOW_SYSTEM = Menu.FIRST + 42; 38 private static final String EXTRA_SHOW_SYSTEM = "show_system"; 39 40 private boolean mShowSystem; 41 private AppFilter mFilter; 42 43 @Override onCreate(Bundle icicle)44 public void onCreate(Bundle icicle) { 45 super.onCreate(icicle); 46 mShowSystem = icicle != null && icicle.getBoolean(EXTRA_SHOW_SYSTEM); 47 48 use(UnrestrictedDataAccessPreferenceController.class).setParentFragment(this); 49 } 50 51 @Override onCreateOptionsMenu(Menu menu, MenuInflater inflater)52 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 53 menu.add(Menu.NONE, MENU_SHOW_SYSTEM, Menu.NONE, 54 mShowSystem ? R.string.menu_hide_system : R.string.menu_show_system); 55 super.onCreateOptionsMenu(menu, inflater); 56 } 57 58 @Override onOptionsItemSelected(MenuItem item)59 public boolean onOptionsItemSelected(MenuItem item) { 60 switch (item.getItemId()) { 61 case MENU_SHOW_SYSTEM: 62 mShowSystem = !mShowSystem; 63 item.setTitle(mShowSystem ? R.string.menu_hide_system : R.string.menu_show_system); 64 mFilter = mShowSystem ? ApplicationsState.FILTER_ALL_ENABLED 65 : ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER; 66 67 use(UnrestrictedDataAccessPreferenceController.class).setFilter(mFilter); 68 use(UnrestrictedDataAccessPreferenceController.class).rebuild(); 69 70 break; 71 } 72 return super.onOptionsItemSelected(item); 73 } 74 75 @Override onSaveInstanceState(Bundle outState)76 public void onSaveInstanceState(Bundle outState) { 77 super.onSaveInstanceState(outState); 78 outState.putBoolean(EXTRA_SHOW_SYSTEM, mShowSystem); 79 } 80 81 @Override onViewCreated(View view, Bundle savedInstanceState)82 public void onViewCreated(View view, Bundle savedInstanceState) { 83 super.onViewCreated(view, savedInstanceState); 84 } 85 86 @Override onAttach(Context context)87 public void onAttach(Context context) { 88 super.onAttach(context); 89 mFilter = mShowSystem ? ApplicationsState.FILTER_ALL_ENABLED 90 : ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER; 91 use(UnrestrictedDataAccessPreferenceController.class).setSession(getSettingsLifecycle()); 92 use(UnrestrictedDataAccessPreferenceController.class).setFilter(mFilter); 93 } 94 95 @Override getHelpResource()96 public int getHelpResource() { 97 return R.string.help_url_unrestricted_data_access; 98 } 99 100 @Override getLogTag()101 protected String getLogTag() { 102 return TAG; 103 } 104 105 @Override getMetricsCategory()106 public int getMetricsCategory() { 107 return SettingsEnums.DATA_USAGE_UNRESTRICTED_ACCESS; 108 } 109 110 @Override getPreferenceScreenResId()111 protected int getPreferenceScreenResId() { 112 return R.xml.unrestricted_data_access_settings; 113 } 114 115 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 116 new BaseSearchIndexProvider(R.xml.unrestricted_data_access_settings); 117 } 118