Expose AndroidPackage#getStorageUuid
The system internally passes around a String, but to mirror the
public ApplicationInfo API, PackageState and related
infrastructure will act on real UUIDs.
These can be converted with StorageManager#convert, although it's
expected that any exposed @SystemApi methods will just take the
UUID as a paramter.
Bug: 254029038
Test: atest AndroidPackageTest
Change-Id: I93e0f04b4d5c93cd534d393057f2c0d7f61418df
diff --git a/services/api/current.txt b/services/api/current.txt
index 35a4dcb..834ed2f 100644
--- a/services/api/current.txt
+++ b/services/api/current.txt
@@ -76,6 +76,7 @@
method @Nullable public String getSdkLibraryName();
method @NonNull public java.util.List<com.android.server.pm.pkg.AndroidPackageSplit> getSplits();
method @Nullable public String getStaticSharedLibraryName();
+ method @NonNull public java.util.UUID getStorageUuid();
method public int getTargetSdkVersion();
method public boolean isDebuggable();
method public boolean isIsolatedSplitLoading();
diff --git a/services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java b/services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java
index b1e9141..ba36ab7 100644
--- a/services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java
+++ b/services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java
@@ -1335,6 +1335,11 @@
}
@Override
+ public UUID getStorageUuid() {
+ return mStorageUuid;
+ }
+
+ @Override
public int getTargetSandboxVersion() {
return targetSandboxVersion;
}
diff --git a/services/core/java/com/android/server/pm/pkg/AndroidPackage.java b/services/core/java/com/android/server/pm/pkg/AndroidPackage.java
index e3dad45..84907a5 100644
--- a/services/core/java/com/android/server/pm/pkg/AndroidPackage.java
+++ b/services/core/java/com/android/server/pm/pkg/AndroidPackage.java
@@ -34,6 +34,7 @@
import android.content.pm.ServiceInfo;
import android.content.pm.SigningDetails;
import android.os.Bundle;
+import android.os.storage.StorageManager;
import android.processor.immutability.Immutable;
import android.util.ArraySet;
import android.util.Pair;
@@ -58,6 +59,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
/**
* The representation of an application on disk, as parsed from its split APKs' manifests.
@@ -111,6 +113,13 @@
String getStaticSharedLibraryName();
/**
+ * @return The {@link UUID} for use with {@link StorageManager} APIs identifying where this
+ * package was installed.
+ */
+ @NonNull
+ UUID getStorageUuid();
+
+ /**
* @see ApplicationInfo#targetSdkVersion
* @see R.styleable#AndroidManifestUsesSdk_targetSdkVersion
*/
diff --git a/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/parsing/parcelling/AndroidPackageTest.kt b/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/parsing/parcelling/AndroidPackageTest.kt
index ee6196d..7bf9a9e 100644
--- a/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/parsing/parcelling/AndroidPackageTest.kt
+++ b/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/parsing/parcelling/AndroidPackageTest.kt
@@ -48,11 +48,16 @@
import com.android.server.testutils.whenever
import java.security.KeyPairGenerator
import java.security.PublicKey
+import java.util.UUID
import kotlin.contracts.ExperimentalContracts
@ExperimentalContracts
class AndroidPackageTest : ParcelableComponentTest(AndroidPackage::class, PackageImpl::class) {
+ companion object {
+ private val TEST_UUID = UUID.fromString("57554103-df3e-4475-ae7a-8feba49353ac")
+ }
+
override val defaultImpl = PackageImpl.forTesting("com.example.test")
override val creator = PackageImpl.CREATOR
@@ -88,8 +93,6 @@
"getLongVersionCode",
// Tested through constructor
"getManifestPackageName",
- // Utility methods
- "getStorageUuid",
// Removal not tested, irrelevant for parcelling concerns
"removeUsesOptionalLibrary",
"clearAdoptPermissions",
@@ -101,6 +104,7 @@
// Tested manually
"getMimeGroups",
"getRequestedPermissions",
+ "getStorageUuid",
// Tested through asSplit
"asSplit",
"getSplits",
@@ -256,7 +260,7 @@
)
override fun extraParams() = listOf(
- getter(AndroidPackage::getVolumeUuid, "57554103-df3e-4475-ae7a-8feba49353ac"),
+ getter(AndroidPackage::getVolumeUuid, TEST_UUID.toString()),
getter(AndroidPackage::isProfileable, true),
getter(PackageImpl::getVersionCode, 3),
getter(PackageImpl::getVersionCodeMajor, 9),
@@ -617,6 +621,8 @@
expect.that(after.usesStaticLibrariesCertDigests!!.size).isEqualTo(1)
expect.that(after.usesStaticLibrariesCertDigests!![0]).asList()
.containsExactly("testCertDigest2")
+
+ expect.that(after.storageUuid).isEqualTo(TEST_UUID)
}
private fun testKey() = KeyPairGenerator.getInstance("RSA")
diff --git a/tools/processors/immutability/src/android/processor/immutability/ImmutabilityProcessor.kt b/tools/processors/immutability/src/android/processor/immutability/ImmutabilityProcessor.kt
index f29d9b2..c6f6d45 100644
--- a/tools/processors/immutability/src/android/processor/immutability/ImmutabilityProcessor.kt
+++ b/tools/processors/immutability/src/android/processor/immutability/ImmutabilityProcessor.kt
@@ -54,6 +54,7 @@
"java.lang.Short",
"java.lang.String",
"java.lang.Void",
+ "java.util.UUID",
"android.os.Parcelable.Creator",
)