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
This commit is contained in:
@@ -76,6 +76,7 @@ package com.android.server.pm.pkg {
|
||||
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();
|
||||
|
||||
@@ -1334,6 +1334,11 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal,
|
||||
return staticSharedLibVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getStorageUuid() {
|
||||
return mStorageUuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTargetSandboxVersion() {
|
||||
return targetSandboxVersion;
|
||||
|
||||
@@ -34,6 +34,7 @@ import android.content.pm.ProviderInfo;
|
||||
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.security.PublicKey;
|
||||
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.
|
||||
@@ -110,6 +112,13 @@ public interface AndroidPackage {
|
||||
@Nullable
|
||||
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
|
||||
|
||||
@@ -48,11 +48,16 @@ import com.android.server.testutils.mockThrowOnUnmocked
|
||||
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 @@ class AndroidPackageTest : ParcelableComponentTest(AndroidPackage::class, Packag
|
||||
"getLongVersionCode",
|
||||
// Tested through constructor
|
||||
"getManifestPackageName",
|
||||
// Utility methods
|
||||
"getStorageUuid",
|
||||
// Removal not tested, irrelevant for parcelling concerns
|
||||
"removeUsesOptionalLibrary",
|
||||
"clearAdoptPermissions",
|
||||
@@ -101,6 +104,7 @@ class AndroidPackageTest : ParcelableComponentTest(AndroidPackage::class, Packag
|
||||
// Tested manually
|
||||
"getMimeGroups",
|
||||
"getRequestedPermissions",
|
||||
"getStorageUuid",
|
||||
// Tested through asSplit
|
||||
"asSplit",
|
||||
"getSplits",
|
||||
@@ -256,7 +260,7 @@ class AndroidPackageTest : ParcelableComponentTest(AndroidPackage::class, Packag
|
||||
)
|
||||
|
||||
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 @@ class AndroidPackageTest : ParcelableComponentTest(AndroidPackage::class, Packag
|
||||
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")
|
||||
|
||||
@@ -54,6 +54,7 @@ class ImmutabilityProcessor : AbstractProcessor() {
|
||||
"java.lang.Short",
|
||||
"java.lang.String",
|
||||
"java.lang.Void",
|
||||
"java.util.UUID",
|
||||
"android.os.Parcelable.Creator",
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user