Coerce component metadata Bundle to null if empty
Maintains backwards compatibilty where if no meta-data tags were declared, null is returned. Bug: 231270984 Test: atest PackageParserTest#testNoComponentMetadataIsCoercedToNullForInfoObject Change-Id: I732fa3a16c80d02577dfb62887ae44c4ae7b4094
This commit is contained in:
@@ -546,7 +546,9 @@ public class PackageInfoWithoutStateUtils {
|
||||
ai.windowLayout = a.getWindowLayout();
|
||||
ai.attributionTags = a.getAttributionTags();
|
||||
if ((flags & PackageManager.GET_META_DATA) != 0) {
|
||||
ai.metaData = a.getMetaData();
|
||||
var metaData = a.getMetaData();
|
||||
// Backwards compatibility, coerce to null if empty
|
||||
ai.metaData = metaData.isEmpty() ? null : metaData;
|
||||
}
|
||||
ai.applicationInfo = applicationInfo;
|
||||
ai.setKnownActivityEmbeddingCerts(a.getKnownActivityEmbeddingCerts());
|
||||
@@ -599,7 +601,9 @@ public class PackageInfoWithoutStateUtils {
|
||||
si.mForegroundServiceType = s.getForegroundServiceType();
|
||||
si.applicationInfo = applicationInfo;
|
||||
if ((flags & PackageManager.GET_META_DATA) != 0) {
|
||||
si.metaData = s.getMetaData();
|
||||
var metaData = s.getMetaData();
|
||||
// Backwards compatibility, coerce to null if empty
|
||||
si.metaData = metaData.isEmpty() ? null : metaData;
|
||||
}
|
||||
return si;
|
||||
}
|
||||
@@ -660,7 +664,9 @@ public class PackageInfoWithoutStateUtils {
|
||||
pi.uriPermissionPatterns = null;
|
||||
}
|
||||
if ((flags & PackageManager.GET_META_DATA) != 0) {
|
||||
pi.metaData = p.getMetaData();
|
||||
var metaData = p.getMetaData();
|
||||
// Backwards compatibility, coerce to null if empty
|
||||
pi.metaData = metaData.isEmpty() ? null : metaData;
|
||||
}
|
||||
pi.applicationInfo = applicationInfo;
|
||||
return pi;
|
||||
@@ -706,7 +712,9 @@ public class PackageInfoWithoutStateUtils {
|
||||
if ((flags & PackageManager.GET_META_DATA) == 0) {
|
||||
return ii;
|
||||
}
|
||||
ii.metaData = i.getMetaData();
|
||||
var metaData = i.getMetaData();
|
||||
// Backwards compatibility, coerce to null if empty
|
||||
ii.metaData = metaData.isEmpty() ? null : metaData;
|
||||
return ii;
|
||||
}
|
||||
|
||||
@@ -729,7 +737,9 @@ public class PackageInfoWithoutStateUtils {
|
||||
if ((flags & PackageManager.GET_META_DATA) == 0) {
|
||||
return pi;
|
||||
}
|
||||
pi.metaData = p.getMetaData();
|
||||
var metaData = p.getMetaData();
|
||||
// Backwards compatibility, coerce to null if empty
|
||||
pi.metaData = metaData.isEmpty() ? null : metaData;
|
||||
return pi;
|
||||
}
|
||||
|
||||
@@ -753,7 +763,9 @@ public class PackageInfoWithoutStateUtils {
|
||||
if ((flags & PackageManager.GET_META_DATA) == 0) {
|
||||
return pgi;
|
||||
}
|
||||
pgi.metaData = pg.getMetaData();
|
||||
var metaData = pg.getMetaData();
|
||||
// Backwards compatibility, coerce to null if empty
|
||||
pgi.metaData = metaData.isEmpty() ? null : metaData;
|
||||
return pgi;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
@@ -65,6 +66,7 @@ import com.android.server.pm.parsing.pkg.AndroidPackageUtils;
|
||||
import com.android.server.pm.parsing.pkg.PackageImpl;
|
||||
import com.android.server.pm.parsing.pkg.ParsedPackage;
|
||||
import com.android.server.pm.permission.CompatibilityPermissionInfo;
|
||||
import com.android.server.pm.pkg.PackageUserState;
|
||||
import com.android.server.pm.pkg.PackageUserStateInternal;
|
||||
import com.android.server.pm.pkg.component.ParsedActivity;
|
||||
import com.android.server.pm.pkg.component.ParsedActivityImpl;
|
||||
@@ -85,6 +87,7 @@ import com.android.server.pm.pkg.component.ParsedService;
|
||||
import com.android.server.pm.pkg.component.ParsedServiceImpl;
|
||||
import com.android.server.pm.pkg.component.ParsedUsesPermission;
|
||||
import com.android.server.pm.pkg.component.ParsedUsesPermissionImpl;
|
||||
import com.android.server.pm.pkg.parsing.PackageInfoWithoutStateUtils;
|
||||
import com.android.server.pm.pkg.parsing.ParsingPackage;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -596,6 +599,38 @@ public class PackageParserTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoComponentMetadataIsCoercedToNullForInfoObject() throws Exception {
|
||||
final File testFile = extractFile(TEST_APP4_APK);
|
||||
try {
|
||||
final ParsedPackage pkg = new TestPackageParser2().parsePackage(testFile, 0, false);
|
||||
ApplicationInfo appInfo = PackageInfoWithoutStateUtils.generateApplicationInfo(pkg, 0,
|
||||
PackageUserState.DEFAULT, 0);
|
||||
for (ParsedActivity activity : pkg.getActivities()) {
|
||||
assertNotNull(activity.getMetaData());
|
||||
assertNull(PackageInfoWithoutStateUtils.generateActivityInfoUnchecked(activity, 0,
|
||||
appInfo).metaData);
|
||||
}
|
||||
for (ParsedProvider provider : pkg.getProviders()) {
|
||||
assertNotNull(provider.getMetaData());
|
||||
assertNull(PackageInfoWithoutStateUtils.generateProviderInfoUnchecked(provider, 0,
|
||||
appInfo).metaData);
|
||||
}
|
||||
for (ParsedActivity receiver : pkg.getReceivers()) {
|
||||
assertNotNull(receiver.getMetaData());
|
||||
assertNull(PackageInfoWithoutStateUtils.generateActivityInfoUnchecked(receiver, 0,
|
||||
appInfo).metaData);
|
||||
}
|
||||
for (ParsedService service : pkg.getServices()) {
|
||||
assertNotNull(service.getMetaData());
|
||||
assertNull(PackageInfoWithoutStateUtils.generateServiceInfoUnchecked(service, 0,
|
||||
appInfo).metaData);
|
||||
}
|
||||
} finally {
|
||||
testFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A trivial subclass of package parser that only caches the package name, and throws away
|
||||
* all other information.
|
||||
|
||||
Reference in New Issue
Block a user