• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.car.settings.applications;
18 
19 import static com.android.car.settings.storage.StorageUtils.maybeInitializeVolume;
20 
21 import android.app.Application;
22 import android.content.Context;
23 import android.os.Bundle;
24 import android.os.UserManager;
25 import android.os.storage.StorageManager;
26 import android.os.storage.VolumeInfo;
27 
28 import com.android.car.settings.R;
29 import com.android.settingslib.applications.ApplicationsState;
30 
31 /**
32  * Lists all installed applications and their summary.
33  */
34 public class ApplicationsSettingsFragment extends AppListFragment {
35 
36     private ApplicationListItemManager mAppListItemManager;
37 
38     @Override
getPreferenceScreenResId()39     protected int getPreferenceScreenResId() {
40         return R.xml.applications_settings_fragment;
41     }
42 
43     @Override
onAttach(Context context)44     public void onAttach(Context context) {
45         super.onAttach(context);
46 
47         Application application = requireActivity().getApplication();
48         StorageManager sm = context.getSystemService(StorageManager.class);
49         UserManager um = context.getSystemService(UserManager.class);
50         VolumeInfo volume = maybeInitializeVolume(sm, getArguments());
51         mAppListItemManager = new ApplicationListItemManager(volume, getLifecycle(),
52                 ApplicationsState.getInstance(application),
53                 getContext().getResources().getInteger(
54                         R.integer.millisecond_app_data_update_interval),
55                 getContext().getResources().getInteger(
56                         R.integer.millisecond_max_app_load_wait_interval),
57                 getContext().getPackageManager(), um);
58         mAppListItemManager.registerListener(
59                 use(ApplicationsSettingsPreferenceController.class,
60                         R.string.pk_all_applications_settings_list));
61     }
62 
63     @Override
onCreate(Bundle savedInstanceState)64     public void onCreate(Bundle savedInstanceState) {
65         super.onCreate(savedInstanceState);
66         mAppListItemManager.startLoading(getAppFilter(), ApplicationsState.ALPHA_COMPARATOR);
67     }
68 
69     @Override
onStart()70     public void onStart() {
71         super.onStart();
72         mAppListItemManager.onFragmentStart();
73     }
74 
75     @Override
onStop()76     public void onStop() {
77         super.onStop();
78         mAppListItemManager.onFragmentStop();
79     }
80 
81     @Override
onToggleShowSystemApps(boolean showSystem)82     protected void onToggleShowSystemApps(boolean showSystem) {
83         mAppListItemManager.rebuildWithFilter(getAppFilter());
84     }
85 
getAppFilter()86     private ApplicationsState.AppFilter getAppFilter() {
87         return shouldShowSystemApps() ? null
88                 : ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_AND_INSTANT;
89     }
90 }
91