diff options
| author | 2019-03-28 16:02:21 +0000 | |
|---|---|---|
| committer | 2019-03-28 16:02:21 +0000 | |
| commit | 8502e24cd30e08267c0e529cb655195fbc619fbe (patch) | |
| tree | 95c123f9420c6b34afb81ad4cab171d1223f108e | |
| parent | 67542eec78d318d60cbbe98f8870b7debe665793 (diff) | |
| parent | 6dcc503b0dccb4ef7609025d9c95d464efc17652 (diff) | |
Merge "Add a new atom to log when an app is moved from internal to external storage and vice versa."
| -rw-r--r-- | cmds/statsd/src/atoms.proto | 25 | ||||
| -rw-r--r-- | services/core/java/com/android/server/pm/PackageManagerService.java | 59 |
2 files changed, 74 insertions, 10 deletions
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto index aeac546de830..1ffde972566f 100644 --- a/cmds/statsd/src/atoms.proto +++ b/cmds/statsd/src/atoms.proto @@ -254,6 +254,7 @@ message Atom { PrivacyIndicatorsInteracted privacy_indicators_interacted = 180; AppInstallOnExternalStorageReported app_install_on_external_storage_reported = 181; NetworkStackReported network_stack_reported = 182; + AppMovedStorageReported app_moved_storage_reported = 183; } // Pulled events will start at field 10000. @@ -3446,6 +3447,30 @@ message PrivacyIndicatorsInteracted { optional string package_name = 2; } +/** + * Logs information about a package that is moved from the internal to external storage and vice + * versa. + * It logs the package name, the type of the external storage where the package is installed + * (if moved to external storage, or UNKNOWN if moved to internal storage), + * and the move type: if it's from internal to external or the other way around. + * + * Logged from: + frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java + */ +message AppMovedStorageReported { + enum MoveType { + UNKNOWN = 0; + TO_EXTERNAL = 1; + TO_INTERNAL = 2; + } + // The type of the external storage. + optional android.stats.storage.ExternalStorageType external_storage_type = 1; + // The type of move. + optional MoveType move_type = 2; + // The name of the package that was moved. + optional string package_name = 3; +} + ////////////////////////////////////////////////////////////////////// // Pulled atoms below this line // ////////////////////////////////////////////////////////////////////// diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index eec1e539b2d7..6c1472c2372c 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -1941,8 +1941,13 @@ public class PackageManagerService extends IPackageManager.Stub // Send broadcast package appeared if external for all users if (isExternal(res.pkg)) { if (!update) { + final StorageManager storage = + mContext.getSystemService(StorageManager.class); + VolumeInfo volume = + storage.findVolumeByUuid( + res.pkg.applicationInfo.storageUuid.toString()); int packageExternalStorageType = - getPackageExternalStorageType(res.pkg); + getPackageExternalStorageType(volume, isExternal(res.pkg)); // If the package was installed externally, log it. if (packageExternalStorageType != StorageEnums.UNKNOWN) { StatsLog.write(StatsLog.APP_INSTALL_ON_EXTERNAL_STORAGE_REPORTED, @@ -2039,15 +2044,16 @@ public class PackageManagerService extends IPackageManager.Stub /** * Gets the type of the external storage a package is installed on. - * @param pkg The package for which to get the external storage type. - * @return {@link StorageEnum#TYPE_UNKNOWN} if it is not stored externally or the corresponding - * {@link StorageEnum} storage type value if it is. + * @param packageVolume The storage volume of the package. + * @param packageIsExternal true if the package is currently installed on + * external/removable/unprotected storage. + * @return {@link StorageEnum#TYPE_UNKNOWN} if the package is not stored externally or the + * corresponding {@link StorageEnum} storage type value if it is. */ - private int getPackageExternalStorageType(PackageParser.Package pkg) { - final StorageManager storage = mContext.getSystemService(StorageManager.class); - VolumeInfo volume = storage.findVolumeByUuid(pkg.applicationInfo.storageUuid.toString()); - if (volume != null) { - DiskInfo disk = volume.getDisk(); + private static int getPackageExternalStorageType(VolumeInfo packageVolume, + boolean packageIsExternal) { + if (packageVolume != null) { + DiskInfo disk = packageVolume.getDisk(); if (disk != null) { if (disk.isSd()) { return StorageEnums.SD_CARD; @@ -2055,7 +2061,7 @@ public class PackageManagerService extends IPackageManager.Stub if (disk.isUsb()) { return StorageEnums.USB; } - if (isExternal(pkg)) { + if (packageIsExternal) { return StorageEnums.OTHER; } } @@ -22494,6 +22500,7 @@ public class PackageManagerService extends IPackageManager.Stub final int targetSdkVersion; final PackageFreezer freezer; final int[] installedUserIds; + final boolean isCurrentLocationExternal; // reader synchronized (mPackages) { @@ -22540,6 +22547,7 @@ public class PackageManagerService extends IPackageManager.Stub "Failed to move already frozen package"); } + isCurrentLocationExternal = isExternal(pkg); codeFile = new File(pkg.codePath); installerPackageName = ps.installerPackageName; packageAbiOverride = ps.cpuAbiOverrideString; @@ -22642,6 +22650,7 @@ public class PackageManagerService extends IPackageManager.Stub case PackageInstaller.STATUS_SUCCESS: mMoveCallbacks.notifyStatusChanged(moveId, PackageManager.MOVE_SUCCEEDED); + logAppMovedStorage(packageName, isCurrentLocationExternal); break; case PackageInstaller.STATUS_FAILURE_STORAGE: mMoveCallbacks.notifyStatusChanged(moveId, @@ -22700,6 +22709,36 @@ public class PackageManagerService extends IPackageManager.Stub mHandler.sendMessage(msg); } + /** + * Logs that an app has been moved from internal to external storage and vice versa. + * @param packageName The package that was moved. + */ + private void logAppMovedStorage(String packageName, boolean isPreviousLocationExternal) { + final PackageParser.Package pkg; + synchronized (mPackages) { + pkg = mPackages.get(packageName); + } + if (pkg == null) { + return; + } + + final StorageManager storage = mContext.getSystemService(StorageManager.class); + VolumeInfo volume = storage.findVolumeByUuid(pkg.applicationInfo.storageUuid.toString()); + int packageExternalStorageType = getPackageExternalStorageType(volume, isExternal(pkg)); + + if (!isPreviousLocationExternal && isExternal(pkg)) { + // Move from internal to external storage. + StatsLog.write(StatsLog.APP_MOVED_STORAGE_REPORTED, packageExternalStorageType, + StatsLog.APP_MOVED_STORAGE_REPORTED__MOVE_TYPE__TO_EXTERNAL, + packageName); + } else if (isPreviousLocationExternal && !isExternal(pkg)) { + // Move from external to internal storage. + StatsLog.write(StatsLog.APP_MOVED_STORAGE_REPORTED, packageExternalStorageType, + StatsLog.APP_MOVED_STORAGE_REPORTED__MOVE_TYPE__TO_INTERNAL, + packageName); + } + } + @Override public int movePrimaryStorage(String volumeUuid) throws RemoteException { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MOVE_PACKAGE, null); |