• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.settings.datausage;
18 
19 import android.content.Context;
20 import android.content.pm.ApplicationInfo;
21 import android.content.pm.PackageManager;
22 import android.support.v7.preference.Preference;
23 import android.util.ArraySet;
24 import com.android.settingslib.utils.AsyncLoader;
25 
26 public class AppPrefLoader extends AsyncLoader<ArraySet<Preference>> {
27     private ArraySet<String> mPackages;
28     private PackageManager mPackageManager;
29     private Context mPrefContext;
30 
AppPrefLoader(Context prefContext, ArraySet<String> pkgs, PackageManager pm)31     public AppPrefLoader(Context prefContext, ArraySet<String> pkgs, PackageManager pm) {
32         super(prefContext);
33         mPackages = pkgs;
34         mPackageManager = pm;
35         mPrefContext = prefContext;
36     }
37 
38     @Override
loadInBackground()39     public ArraySet<Preference> loadInBackground() {
40         ArraySet<Preference> results = new ArraySet<>();
41         for (int i = 1, size = mPackages.size(); i < size; i++) {
42             try {
43                 ApplicationInfo info = mPackageManager.getApplicationInfo(mPackages.valueAt(i), 0);
44                 Preference preference = new Preference(mPrefContext);
45                 preference.setIcon(info.loadIcon(mPackageManager));
46                 preference.setTitle(info.loadLabel(mPackageManager));
47                 preference.setSelectable(false);
48                 results.add(preference);
49             } catch (PackageManager.NameNotFoundException e) {
50             }
51         }
52         return results;
53     }
54 
55     @Override
onDiscardResult(ArraySet<Preference> result)56     protected void onDiscardResult(ArraySet<Preference> result) {
57     }
58 }
59