blob: 9df741abd5d325c5927ac5a2cad35689978cc293 [file] [log] [blame]
Doris Ling2f022182017-04-28 15:17:30 -07001/*
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
17package com.android.settings.datausage;
18
19import android.content.Context;
20import android.content.pm.ApplicationInfo;
21import android.content.pm.PackageManager;
Doris Ling2f022182017-04-28 15:17:30 -070022import android.util.ArraySet;
Fan Zhangde117042018-09-04 13:52:15 -070023
24import androidx.preference.Preference;
25
Jaekyun Seok47f6e542017-11-30 18:10:34 +090026import com.android.settingslib.utils.AsyncLoader;
Doris Ling2f022182017-04-28 15:17:30 -070027
28public class AppPrefLoader extends AsyncLoader<ArraySet<Preference>> {
29 private ArraySet<String> mPackages;
30 private PackageManager mPackageManager;
31 private Context mPrefContext;
32
33 public AppPrefLoader(Context prefContext, ArraySet<String> pkgs, PackageManager pm) {
34 super(prefContext);
35 mPackages = pkgs;
36 mPackageManager = pm;
37 mPrefContext = prefContext;
38 }
39
40 @Override
41 public ArraySet<Preference> loadInBackground() {
42 ArraySet<Preference> results = new ArraySet<>();
43 for (int i = 1, size = mPackages.size(); i < size; i++) {
44 try {
45 ApplicationInfo info = mPackageManager.getApplicationInfo(mPackages.valueAt(i), 0);
46 Preference preference = new Preference(mPrefContext);
47 preference.setIcon(info.loadIcon(mPackageManager));
48 preference.setTitle(info.loadLabel(mPackageManager));
49 preference.setSelectable(false);
50 results.add(preference);
51 } catch (PackageManager.NameNotFoundException e) {
52 }
53 }
54 return results;
55 }
56
57 @Override
58 protected void onDiscardResult(ArraySet<Preference> result) {
59 }
60}