• 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.applications;
18 
19 import android.annotation.NonNull;
20 import android.content.Context;
21 import android.content.pm.ApplicationInfo;
22 import android.content.pm.PackageManager.NameNotFoundException;
23 import android.os.UserHandle;
24 import android.util.Log;
25 
26 import com.android.internal.util.Preconditions;
27 import com.android.settingslib.applications.StorageStatsSource;
28 import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
29 import com.android.settingslib.utils.AsyncLoaderCompat;
30 
31 import java.io.IOException;
32 
33 /**
34  * Fetches the storage stats using the StorageStatsManager for a given package and user tuple.
35  */
36 public class FetchPackageStorageAsyncLoader extends AsyncLoaderCompat<AppStorageStats> {
37     private static final String TAG = "FetchPackageStorage";
38     private final StorageStatsSource mSource;
39     private final ApplicationInfo mInfo;
40     private final UserHandle mUser;
41 
FetchPackageStorageAsyncLoader(Context context, @NonNull StorageStatsSource source, @NonNull ApplicationInfo info, @NonNull UserHandle user)42     public FetchPackageStorageAsyncLoader(Context context, @NonNull StorageStatsSource source,
43             @NonNull ApplicationInfo info, @NonNull UserHandle user) {
44         super(context);
45         mSource = Preconditions.checkNotNull(source);
46         mInfo = info;
47         mUser = user;
48     }
49 
50     @Override
loadInBackground()51     public AppStorageStats loadInBackground() {
52         AppStorageStats result = null;
53         try {
54             result = mSource.getStatsForPackage(mInfo.volumeUuid, mInfo.packageName, mUser);
55         } catch (NameNotFoundException | IOException e) {
56             Log.w(TAG, "Package may have been removed during query, failing gracefully", e);
57         }
58         return result;
59     }
60 
61     @Override
onDiscardResult(AppStorageStats result)62     protected void onDiscardResult(AppStorageStats result) {
63     }
64 }
65