storage
package com.android.settings.deviceinfo.storage;
import android.content.Context;
import android.content.SharedPreferences;
import android.provider.Settings.Global;
import android.support.annotation.VisibleForTesting;
import android.util.SparseArray;
import com.android.settings.deviceinfo.storage.StorageAsyncLoader.AppsStorageResult;
import com.android.settingslib.applications.StorageStatsSource.ExternalStorageStats;
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
import java.util.concurrent.TimeUnit;
public class CachedStorageValuesHelper {
@VisibleForTesting
public static final String SHARED_PREFERENCES_NAME = "CachedStorageValues";
private final Long mClobberThreshold;
protected Clock mClock = new Clock();
private final SharedPreferences mSharedPreferences;
private final int mUserId;
public CachedStorageValuesHelper(Context context, int i) {
this.mSharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, 0);
this.mUserId = i;
this.mClobberThreshold = Long.valueOf(Global.getLong(context.getContentResolver(), "storage_settings_clobber_threshold", TimeUnit.MINUTES.toMillis(5)));
}
private boolean isDataValid() {
if (this.mSharedPreferences.getInt("user_id", -1) != this.mUserId) {
return false;
}
return this.mClock.getCurrentTime() - this.mSharedPreferences.getLong("last_query_timestamp", Long.MAX_VALUE) < this.mClobberThreshold.longValue();
}
public void cacheResult(PrivateStorageInfo privateStorageInfo, AppsStorageResult appsStorageResult) {
this.mSharedPreferences.edit().putLong("free_bytes", privateStorageInfo.freeBytes).putLong("total_bytes", privateStorageInfo.totalBytes).putLong("game_apps_size", appsStorageResult.gamesSize).putLong("music_apps_size", appsStorageResult.musicAppsSize).putLong("video_apps_size", appsStorageResult.videoAppsSize).putLong("photo_apps_size", appsStorageResult.photosAppsSize).putLong("other_apps_size", appsStorageResult.otherAppsSize).putLong("cache_apps_size", appsStorageResult.cacheSize).putLong("external_total_bytes", appsStorageResult.externalStats.totalBytes).putLong("external_audio_bytes", appsStorageResult.externalStats.audioBytes).putLong("external_video_bytes", appsStorageResult.externalStats.videoBytes).putLong("external_image_bytes", appsStorageResult.externalStats.imageBytes).putLong("external_apps_bytes", appsStorageResult.externalStats.appBytes).putInt("user_id", this.mUserId).putLong("last_query_timestamp", this.mClock.getCurrentTime()).apply();
}
public SparseArray