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.AppIconCacheManager;
29 import com.android.settingslib.applications.ApplicationsState;
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 
42     @Override
onCreate(Bundle icicle)43     public void onCreate(Bundle icicle) {
44         super.onCreate(icicle);
45         mShowSystem = icicle != null && icicle.getBoolean(EXTRA_SHOW_SYSTEM);
46         use(UnrestrictedDataAccessPreferenceController.class).setFilter(
47                 mShowSystem ? ApplicationsState.FILTER_ENABLED_NOT_QUIET
48                         : ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_NOT_QUIET);
49         use(UnrestrictedDataAccessPreferenceController.class).setSession(getSettingsLifecycle());
50     }
51 
52     @Override
onCreateOptionsMenu(Menu menu, MenuInflater inflater)53     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
54         menu.add(Menu.NONE, MENU_SHOW_SYSTEM, Menu.NONE,
55                 mShowSystem ? R.string.menu_hide_system : R.string.menu_show_system);
56         super.onCreateOptionsMenu(menu, inflater);
57     }
58 
59     @Override
onOptionsItemSelected(MenuItem item)60     public boolean onOptionsItemSelected(MenuItem item) {
61         if (item.getItemId() == MENU_SHOW_SYSTEM) {
62             mShowSystem = !mShowSystem;
63             item.setTitle(mShowSystem ? R.string.menu_hide_system : R.string.menu_show_system);
64             use(UnrestrictedDataAccessPreferenceController.class).setFilter(
65                     mShowSystem ? ApplicationsState.FILTER_ENABLED_NOT_QUIET
66                             : ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_NOT_QUIET);
67             use(UnrestrictedDataAccessPreferenceController.class).rebuild();
68             return true;
69         }
70         return super.onOptionsItemSelected(item);
71     }
72 
73     @Override
onSaveInstanceState(Bundle outState)74     public void onSaveInstanceState(Bundle outState) {
75         super.onSaveInstanceState(outState);
76         outState.putBoolean(EXTRA_SHOW_SYSTEM, mShowSystem);
77     }
78 
79     @Override
onAttach(Context context)80     public void onAttach(Context context) {
81         super.onAttach(context);
82         use(UnrestrictedDataAccessPreferenceController.class).setParentFragment(this);
83     }
84 
85     @Override
getHelpResource()86     public int getHelpResource() {
87         return R.string.help_url_unrestricted_data_access;
88     }
89 
90     @Override
getLogTag()91     protected String getLogTag() {
92         return TAG;
93     }
94 
95     @Override
getMetricsCategory()96     public int getMetricsCategory() {
97         return SettingsEnums.DATA_USAGE_UNRESTRICTED_ACCESS;
98     }
99 
100     @Override
getPreferenceScreenResId()101     protected int getPreferenceScreenResId() {
102         return R.xml.unrestricted_data_access_settings;
103     }
104 
105     @Override
onDestroyView()106     public void onDestroyView() {
107         super.onDestroyView();
108         AppIconCacheManager.getInstance().release();
109     }
110 
111     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
112             new BaseSearchIndexProvider(R.xml.unrestricted_data_access_settings);
113 }
114