| Doris Ling | 2f02218 | 2017-04-28 15:17:30 -0700 | [diff] [blame] | 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; |
| Doris Ling | 2f02218 | 2017-04-28 15:17:30 -0700 | [diff] [blame] | 22 | import android.util.ArraySet; |
| Fan Zhang | de11704 | 2018-09-04 13:52:15 -0700 | [diff] [blame^] | 23 | |
| 24 | import androidx.preference.Preference; |
| 25 | |
| Jaekyun Seok | 47f6e54 | 2017-11-30 18:10:34 +0900 | [diff] [blame] | 26 | import com.android.settingslib.utils.AsyncLoader; |
| Doris Ling | 2f02218 | 2017-04-28 15:17:30 -0700 | [diff] [blame] | 27 | |
| 28 | public 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 | } |