Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit efe45ee4 authored by William Loh's avatar William Loh
Browse files

Signal ASL in APK with manifest property

When bundling ASL in the APK by including a app.metadata file in assets,
the manifest must include an application property tag defining the path
of the file in the APK:

    <property android:name="android.content.SAFETY_LABEL_PATH"
    		android:value="some/path/filename" />

If this file is not found then the app metadata source will be set to
APP_METADATA_SOURCE_UNKNOWN and no ASL will be available for the app.

Bug: 329022140
Test: atest InstallAppMetadataTest
Test: atest AndroidPackageTest
Change-Id: I7646ea3fcc92d30f5b4f6f072e558e04a097978f
parent dc5c05a0
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -266,6 +266,15 @@ public abstract class PackageManager {
    public static final String PROPERTY_LEGACY_UPDATE_OWNERSHIP_DENYLIST =
            "android.app.PROPERTY_LEGACY_UPDATE_OWNERSHIP_DENYLIST";

    /**
     * Application level {@link android.content.pm.PackageManager.Property PackageManager
     * .Property} for a app to inform the installer that a file containing the app's android
     * safety label data is bundled into the APK at the given path.
     * @hide
     */
    public static final String PROPERTY_ANDROID_SAFETY_LABEL_PATH =
            "android.content.SAFETY_LABEL_PATH";

    /**
     * A property value set within the manifest.
     * <p>
+0 −15
Original line number Diff line number Diff line
@@ -421,8 +421,6 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal,
    @NonNull
    private String[] mUsesStaticLibrariesSorted;

    private boolean mAppMetadataFileInApk = false;

    @NonNull
    public static PackageImpl forParsing(@NonNull String packageName, @NonNull String baseCodePath,
            @NonNull String codePath, @NonNull TypedArray manifestArray, boolean isCoreApp,
@@ -1065,11 +1063,6 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal,
        return memtagMode;
    }

    @Override
    public boolean isAppMetadataFileInApk() {
        return mAppMetadataFileInApk;
    }

    @Nullable
    @Override
    public Bundle getMetaData() {
@@ -2157,12 +2150,6 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal,
        return this;
    }

    @Override
    public PackageImpl setAppMetadataFileInApk(boolean fileInApk) {
        mAppMetadataFileInApk = fileInApk;
        return this;
    }

    @Override
    public PackageImpl setMetaData(@Nullable Bundle value) {
        metaData = value;
@@ -3277,7 +3264,6 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal,
        dest.writeLong(this.mBooleans);
        dest.writeLong(this.mBooleans2);
        dest.writeBoolean(this.mAllowCrossUidActivitySwitchFromBelow);
        dest.writeBoolean(this.mAppMetadataFileInApk);
    }

    public PackageImpl(Parcel in) {
@@ -3445,7 +3431,6 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal,
        this.mBooleans = in.readLong();
        this.mBooleans2 = in.readLong();
        this.mAllowCrossUidActivitySwitchFromBelow = in.readBoolean();
        this.mAppMetadataFileInApk = in.readBoolean();

        assignDerivedFields();
        assignDerivedFields2();
+0 −3
Original line number Diff line number Diff line
@@ -127,7 +127,4 @@ public interface ParsedPackage extends AndroidPackage {
    ParsedPackage setDirectBootAware(boolean directBootAware);

    ParsedPackage setPersistent(boolean persistent);

    /** Retrieves whether the apk contains a app metadata file. */
    boolean isAppMetadataFileInApk();
}
+0 −3
Original line number Diff line number Diff line
@@ -133,9 +133,6 @@ public interface ParsingPackage {
            @Nullable SparseArray<int[]> splitDependencies
    );

    /** Sets whether the apk contains a app metadata file. */
    ParsingPackage setAppMetadataFileInApk(boolean fileInApk);

    ParsingPackage setMetaData(Bundle metaData);

    ParsingPackage setForceQueryable(boolean forceQueryable);
+0 −10
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.ConfigurationInfo;
import android.content.pm.FeatureGroupInfo;
import android.content.pm.FeatureInfo;
import android.content.pm.Flags;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.Property;
@@ -134,7 +133,6 @@ import org.xmlpull.v1.XmlPullParserException;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.security.PublicKey;
@@ -165,8 +163,6 @@ public class ParsingPackageUtils {
     */
    public static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml";

    public static final String APP_METADATA_FILE_NAME = "app.metadata";

    /**
     * Path prefix for apps on expanded storage
     */
@@ -640,12 +636,6 @@ public class ParsingPackageUtils {
                pkg.setSigningDetails(SigningDetails.UNKNOWN);
            }

            if (Flags.aslInApkAppMetadataSource()) {
                try (InputStream in = assets.open(APP_METADATA_FILE_NAME)) {
                    pkg.setAppMetadataFileInApk(true);
                } catch (Exception e) { }
            }

            return input.success(pkg);
        } catch (Exception e) {
            return input.error(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION,
Loading