1 /*
2  * Copyright (C) 2019 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.car.settings.applications;
18 
19 import android.content.Context;
20 import android.os.Bundle;
21 import android.provider.Settings;
22 
23 import androidx.annotation.XmlRes;
24 
25 import com.android.car.settings.R;
26 import com.android.car.settings.applications.performance.PerfImpactingAppsItemManager;
27 import com.android.car.settings.common.SettingsFragment;
28 import com.android.car.settings.search.CarBaseSearchIndexProvider;
29 import com.android.settingslib.search.SearchIndexable;
30 
31 /** Shows subsettings related to apps. */
32 @SearchIndexable
33 public class AppsFragment extends SettingsFragment {
34 
35     private RecentAppsItemManager mRecentAppsItemManager;
36     private InstalledAppCountItemManager mInstalledAppCountItemManager;
37     private HibernatedAppsItemManager mHibernatedAppsItemManager;
38     private PerfImpactingAppsItemManager mPerfImpactingAppsItemManager;
39 
40     @Override
41     @XmlRes
getPreferenceScreenResId()42     protected int getPreferenceScreenResId() {
43         return R.xml.apps_fragment;
44     }
45 
46     @Override
onAttach(Context context)47     public void onAttach(Context context) {
48         super.onAttach(context);
49         mRecentAppsItemManager = new RecentAppsItemManager(context,
50                 context.getResources().getInteger(R.integer.recent_apps_max_count));
51         mRecentAppsItemManager.addListener(use(AllAppsPreferenceController.class,
52                 R.string.pk_applications_settings_screen_entry));
53         mRecentAppsItemManager.addListener(use(RecentAppsGroupPreferenceController.class,
54                 R.string.pk_recent_apps_group));
55         mRecentAppsItemManager.addListener(use(RecentAppsListPreferenceController.class,
56                 R.string.pk_recent_apps_list));
57 
58         mInstalledAppCountItemManager = new InstalledAppCountItemManager(context);
59         mInstalledAppCountItemManager.addListener(use(AllAppsPreferenceController.class,
60                 R.string.pk_applications_settings_screen_entry));
61         mInstalledAppCountItemManager.addListener(use(RecentAppsViewAllPreferenceController.class,
62                 R.string.pk_recent_apps_view_all));
63 
64         mHibernatedAppsItemManager = new HibernatedAppsItemManager(context);
65         mHibernatedAppsItemManager.setListener(use(HibernatedAppsPreferenceController.class,
66                 R.string.pk_hibernated_apps));
67 
68         mPerfImpactingAppsItemManager = new PerfImpactingAppsItemManager(context);
69         mPerfImpactingAppsItemManager.addListener(
70                 use(PerfImpactingAppsEntryPreferenceController.class,
71                         R.string.pk_performance_impacting_apps_entry));
72     }
73 
74     @Override
onCreate(Bundle savedInstanceState)75     public void onCreate(Bundle savedInstanceState) {
76         super.onCreate(savedInstanceState);
77         mRecentAppsItemManager.startLoading();
78         mInstalledAppCountItemManager.startLoading();
79         mHibernatedAppsItemManager.startLoading();
80     }
81 
82     @Override
onResume()83     public void onResume() {
84         super.onResume();
85         mPerfImpactingAppsItemManager.startLoading();
86     }
87 
88     /**
89      * Data provider for Settings Search.
90      */
91     public static final CarBaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
92             new CarBaseSearchIndexProvider(R.xml.apps_fragment,
93                     Settings.ACTION_APPLICATION_SETTINGS);
94 }
95