Loading core/java/android/app/usage/IStorageStatsManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ interface IStorageStatsManager { boolean isQuotaSupported(String volumeUuid, String callingPackage); long getTotalBytes(String volumeUuid, String callingPackage); long getFreeBytes(String volumeUuid, String callingPackage); long getCacheQuotaBytes(String volumeUuid, int uid, String callingPackage); StorageStats queryStatsForPackage(String volumeUuid, String packageName, int userId, String callingPackage); StorageStats queryStatsForUid(String volumeUuid, int uid, String callingPackage); StorageStats queryStatsForUser(String volumeUuid, int userId, String callingPackage); Loading core/java/android/app/usage/StorageStatsManager.java +9 −0 Original line number Diff line number Diff line Loading @@ -195,4 +195,13 @@ public class StorageStatsManager { throw e.rethrowFromSystemServer(); } } /** {@hide} */ public long getCacheQuotaBytes(String volumeUuid, int uid) { try { return mService.getCacheQuotaBytes(volumeUuid, uid, mContext.getOpPackageName()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } } services/core/java/com/android/server/StorageManagerService.java +7 −2 Original line number Diff line number Diff line Loading @@ -3275,8 +3275,13 @@ class StorageManagerService extends IStorageManager.Stub if (uid != Binder.getCallingUid()) { mContext.enforceCallingPermission(android.Manifest.permission.STORAGE_INTERNAL, TAG); } // TODO: wire up to cache quota once merged return 64 * TrafficStats.MB_IN_BYTES; final long token = Binder.clearCallingIdentity(); final StorageStatsManager stats = mContext.getSystemService(StorageStatsManager.class); try { return stats.getCacheQuotaBytes(volumeUuid, uid); } finally { Binder.restoreCallingIdentity(token); } } @Override Loading services/core/java/com/android/server/storage/CacheQuotaStrategy.java +18 −1 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import android.os.RemoteException; import android.os.UserHandle; import android.os.UserManager; import android.text.format.DateUtils; import android.util.ArrayMap; import android.util.Pair; import android.util.Slog; import android.util.Xml; Loading @@ -64,6 +65,7 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * CacheQuotaStrategy is a strategy for determining cache quotas using usage stats and foreground Loading @@ -85,15 +87,18 @@ public class CacheQuotaStrategy implements RemoteCallback.OnResultListener { private final Context mContext; private final UsageStatsManagerInternal mUsageStats; private final Installer mInstaller; private final Map<String, Map<Integer, Long>> mQuotaMap; private ServiceConnection mServiceConnection; private ICacheQuotaService mRemoteService; private AtomicFile mPreviousValuesFile; public CacheQuotaStrategy( Context context, UsageStatsManagerInternal usageStatsManager, Installer installer) { Context context, UsageStatsManagerInternal usageStatsManager, Installer installer, Map<String, Map<Integer, Long>> quotaMap) { mContext = Preconditions.checkNotNull(context); mUsageStats = Preconditions.checkNotNull(usageStatsManager); mInstaller = Preconditions.checkNotNull(installer); mQuotaMap = Preconditions.checkNotNull(quotaMap); mPreviousValuesFile = new AtomicFile(new File( new File(Environment.getDataDirectory(), "system"), "cachequota.xml")); } Loading Loading @@ -221,6 +226,9 @@ public class CacheQuotaStrategy implements RemoteCallback.OnResultListener { mInstaller.setAppQuota(request.getVolumeUuid(), UserHandle.getUserId(uid), UserHandle.getAppId(uid), proposedQuota); insertIntoQuotaMap(request.getVolumeUuid(), UserHandle.getUserId(uid), UserHandle.getAppId(uid), proposedQuota); } catch (Installer.InstallerException ex) { Slog.w(TAG, "Failed to set cache quota for " + request.getUid(), Loading @@ -231,6 +239,15 @@ public class CacheQuotaStrategy implements RemoteCallback.OnResultListener { disconnectService(); } private void insertIntoQuotaMap(String volumeUuid, int userId, int appId, long quota) { Map<Integer, Long> volumeMap = mQuotaMap.get(volumeUuid); if (volumeMap == null) { volumeMap = new ArrayMap<>(); mQuotaMap.put(volumeUuid, volumeMap); } volumeMap.put(UserHandle.getUid(userId, appId), quota); } private void disconnectService() { if (mServiceConnection != null) { mContext.unbindService(mServiceConnection); Loading services/usage/java/com/android/server/usage/StorageStatsService.java +21 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageStats; import android.content.pm.UserInfo; import android.net.TrafficStats; import android.os.Binder; import android.os.Environment; import android.os.FileUtils; Loading @@ -43,6 +44,7 @@ import android.os.storage.StorageManager; import android.os.storage.VolumeInfo; import android.provider.Settings; import android.text.format.DateUtils; import android.util.ArrayMap; import android.util.Slog; import com.android.internal.annotations.VisibleForTesting; Loading @@ -56,6 +58,7 @@ import com.android.server.pm.Installer.InstallerException; import com.android.server.storage.CacheQuotaStrategy; import java.io.IOException; import java.util.Map; public class StorageStatsService extends IStorageStatsManager.Stub { private static final String TAG = "StorageStatsService"; Loading Loading @@ -84,6 +87,7 @@ public class StorageStatsService extends IStorageStatsManager.Stub { private final UserManager mUser; private final PackageManager mPackage; private final StorageManager mStorage; private final Map<String, Map<Integer, Long>> mCacheQuotas; private final Installer mInstaller; private final H mHandler; Loading @@ -94,6 +98,7 @@ public class StorageStatsService extends IStorageStatsManager.Stub { mUser = Preconditions.checkNotNull(context.getSystemService(UserManager.class)); mPackage = Preconditions.checkNotNull(context.getPackageManager()); mStorage = Preconditions.checkNotNull(context.getSystemService(StorageManager.class)); mCacheQuotas = new ArrayMap<>(); mInstaller = new Installer(context); mInstaller.onStart(); Loading Loading @@ -177,6 +182,21 @@ public class StorageStatsService extends IStorageStatsManager.Stub { } } @Override public long getCacheQuotaBytes(String volumeUuid, int uid, String callingPackage) { enforcePermission(Binder.getCallingUid(), callingPackage); if (mCacheQuotas.containsKey(volumeUuid)) { // TODO: Change to SparseLongArray. Map<Integer, Long> uidMap = mCacheQuotas.get(volumeUuid); if (uidMap.containsKey(uid)) { return uidMap.get(uid); } } return 64 * TrafficStats.MB_IN_BYTES; } @Override public StorageStats queryStatsForPackage(String volumeUuid, String packageName, int userId, String callingPackage) { Loading Loading @@ -433,7 +453,7 @@ public class StorageStatsService extends IStorageStatsManager.Stub { private CacheQuotaStrategy getInitializedStrategy() { UsageStatsManagerInternal usageStatsManager = LocalServices.getService(UsageStatsManagerInternal.class); return new CacheQuotaStrategy(mContext, usageStatsManager, mInstaller); return new CacheQuotaStrategy(mContext, usageStatsManager, mInstaller, mCacheQuotas); } } Loading Loading
core/java/android/app/usage/IStorageStatsManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ interface IStorageStatsManager { boolean isQuotaSupported(String volumeUuid, String callingPackage); long getTotalBytes(String volumeUuid, String callingPackage); long getFreeBytes(String volumeUuid, String callingPackage); long getCacheQuotaBytes(String volumeUuid, int uid, String callingPackage); StorageStats queryStatsForPackage(String volumeUuid, String packageName, int userId, String callingPackage); StorageStats queryStatsForUid(String volumeUuid, int uid, String callingPackage); StorageStats queryStatsForUser(String volumeUuid, int userId, String callingPackage); Loading
core/java/android/app/usage/StorageStatsManager.java +9 −0 Original line number Diff line number Diff line Loading @@ -195,4 +195,13 @@ public class StorageStatsManager { throw e.rethrowFromSystemServer(); } } /** {@hide} */ public long getCacheQuotaBytes(String volumeUuid, int uid) { try { return mService.getCacheQuotaBytes(volumeUuid, uid, mContext.getOpPackageName()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } }
services/core/java/com/android/server/StorageManagerService.java +7 −2 Original line number Diff line number Diff line Loading @@ -3275,8 +3275,13 @@ class StorageManagerService extends IStorageManager.Stub if (uid != Binder.getCallingUid()) { mContext.enforceCallingPermission(android.Manifest.permission.STORAGE_INTERNAL, TAG); } // TODO: wire up to cache quota once merged return 64 * TrafficStats.MB_IN_BYTES; final long token = Binder.clearCallingIdentity(); final StorageStatsManager stats = mContext.getSystemService(StorageStatsManager.class); try { return stats.getCacheQuotaBytes(volumeUuid, uid); } finally { Binder.restoreCallingIdentity(token); } } @Override Loading
services/core/java/com/android/server/storage/CacheQuotaStrategy.java +18 −1 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import android.os.RemoteException; import android.os.UserHandle; import android.os.UserManager; import android.text.format.DateUtils; import android.util.ArrayMap; import android.util.Pair; import android.util.Slog; import android.util.Xml; Loading @@ -64,6 +65,7 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * CacheQuotaStrategy is a strategy for determining cache quotas using usage stats and foreground Loading @@ -85,15 +87,18 @@ public class CacheQuotaStrategy implements RemoteCallback.OnResultListener { private final Context mContext; private final UsageStatsManagerInternal mUsageStats; private final Installer mInstaller; private final Map<String, Map<Integer, Long>> mQuotaMap; private ServiceConnection mServiceConnection; private ICacheQuotaService mRemoteService; private AtomicFile mPreviousValuesFile; public CacheQuotaStrategy( Context context, UsageStatsManagerInternal usageStatsManager, Installer installer) { Context context, UsageStatsManagerInternal usageStatsManager, Installer installer, Map<String, Map<Integer, Long>> quotaMap) { mContext = Preconditions.checkNotNull(context); mUsageStats = Preconditions.checkNotNull(usageStatsManager); mInstaller = Preconditions.checkNotNull(installer); mQuotaMap = Preconditions.checkNotNull(quotaMap); mPreviousValuesFile = new AtomicFile(new File( new File(Environment.getDataDirectory(), "system"), "cachequota.xml")); } Loading Loading @@ -221,6 +226,9 @@ public class CacheQuotaStrategy implements RemoteCallback.OnResultListener { mInstaller.setAppQuota(request.getVolumeUuid(), UserHandle.getUserId(uid), UserHandle.getAppId(uid), proposedQuota); insertIntoQuotaMap(request.getVolumeUuid(), UserHandle.getUserId(uid), UserHandle.getAppId(uid), proposedQuota); } catch (Installer.InstallerException ex) { Slog.w(TAG, "Failed to set cache quota for " + request.getUid(), Loading @@ -231,6 +239,15 @@ public class CacheQuotaStrategy implements RemoteCallback.OnResultListener { disconnectService(); } private void insertIntoQuotaMap(String volumeUuid, int userId, int appId, long quota) { Map<Integer, Long> volumeMap = mQuotaMap.get(volumeUuid); if (volumeMap == null) { volumeMap = new ArrayMap<>(); mQuotaMap.put(volumeUuid, volumeMap); } volumeMap.put(UserHandle.getUid(userId, appId), quota); } private void disconnectService() { if (mServiceConnection != null) { mContext.unbindService(mServiceConnection); Loading
services/usage/java/com/android/server/usage/StorageStatsService.java +21 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageStats; import android.content.pm.UserInfo; import android.net.TrafficStats; import android.os.Binder; import android.os.Environment; import android.os.FileUtils; Loading @@ -43,6 +44,7 @@ import android.os.storage.StorageManager; import android.os.storage.VolumeInfo; import android.provider.Settings; import android.text.format.DateUtils; import android.util.ArrayMap; import android.util.Slog; import com.android.internal.annotations.VisibleForTesting; Loading @@ -56,6 +58,7 @@ import com.android.server.pm.Installer.InstallerException; import com.android.server.storage.CacheQuotaStrategy; import java.io.IOException; import java.util.Map; public class StorageStatsService extends IStorageStatsManager.Stub { private static final String TAG = "StorageStatsService"; Loading Loading @@ -84,6 +87,7 @@ public class StorageStatsService extends IStorageStatsManager.Stub { private final UserManager mUser; private final PackageManager mPackage; private final StorageManager mStorage; private final Map<String, Map<Integer, Long>> mCacheQuotas; private final Installer mInstaller; private final H mHandler; Loading @@ -94,6 +98,7 @@ public class StorageStatsService extends IStorageStatsManager.Stub { mUser = Preconditions.checkNotNull(context.getSystemService(UserManager.class)); mPackage = Preconditions.checkNotNull(context.getPackageManager()); mStorage = Preconditions.checkNotNull(context.getSystemService(StorageManager.class)); mCacheQuotas = new ArrayMap<>(); mInstaller = new Installer(context); mInstaller.onStart(); Loading Loading @@ -177,6 +182,21 @@ public class StorageStatsService extends IStorageStatsManager.Stub { } } @Override public long getCacheQuotaBytes(String volumeUuid, int uid, String callingPackage) { enforcePermission(Binder.getCallingUid(), callingPackage); if (mCacheQuotas.containsKey(volumeUuid)) { // TODO: Change to SparseLongArray. Map<Integer, Long> uidMap = mCacheQuotas.get(volumeUuid); if (uidMap.containsKey(uid)) { return uidMap.get(uid); } } return 64 * TrafficStats.MB_IN_BYTES; } @Override public StorageStats queryStatsForPackage(String volumeUuid, String packageName, int userId, String callingPackage) { Loading Loading @@ -433,7 +453,7 @@ public class StorageStatsService extends IStorageStatsManager.Stub { private CacheQuotaStrategy getInitializedStrategy() { UsageStatsManagerInternal usageStatsManager = LocalServices.getService(UsageStatsManagerInternal.class); return new CacheQuotaStrategy(mContext, usageStatsManager, mInstaller); return new CacheQuotaStrategy(mContext, usageStatsManager, mInstaller, mCacheQuotas); } } Loading