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

Commit ff3dd808 authored by Niamh Walsh's avatar Niamh Walsh Committed by Android (Google) Code Review
Browse files

Merge "Do not require the backupAgent manifest property to set some other backup flags" into main

parents bb0c44c9 f823de97
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -2072,16 +2072,17 @@ public class ParsingPackageUtils {
                    }

                    pkg.setBackupAgentName(backupAgentName)
                            .setKillAfterRestoreAllowed(bool(true,
                                    R.styleable.AndroidManifestApplication_killAfterRestore, sa))
                            .setRestoreAnyVersion(bool(false,
                                    R.styleable.AndroidManifestApplication_restoreAnyVersion, sa))
                            .setFullBackupOnly(bool(false,
                                    R.styleable.AndroidManifestApplication_fullBackupOnly, sa))
                            .setBackupInForeground(bool(false,
                                    R.styleable.AndroidManifestApplication_backupInForeground, sa));
                }

                pkg.setKillAfterRestoreAllowed(bool(true,
                                R.styleable.AndroidManifestApplication_killAfterRestore, sa))
                        .setRestoreAnyVersion(bool(false,
                                R.styleable.AndroidManifestApplication_restoreAnyVersion, sa));

                TypedValue v = sa.peekValue(
                        R.styleable.AndroidManifestApplication_fullBackupContent);
                int fullBackupContent = 0;
+2 −0
Original line number Diff line number Diff line
@@ -107,6 +107,8 @@ android_test {
        ":PackageParserTestApp6",
        ":PackageParserTestApp7",
        ":PackageParserTestApp8",
        ":PackageParserTestApp9",
        ":PackageParserTestApp10",
    ],
    resource_zips: [":PackageManagerServiceServerTests_apks_as_resources"],

+35 −0
Original line number Diff line number Diff line
@@ -166,6 +166,8 @@ public class PackageParserTest {
    private static final String TEST_APP6_APK = "PackageParserTestApp6.apk";
    private static final String TEST_APP7_APK = "PackageParserTestApp7.apk";
    private static final String TEST_APP8_APK = "PackageParserTestApp8.apk";
    private static final String TEST_APP9_APK = "PackageParserTestApp9.apk";
    private static final String TEST_APP10_APK = "PackageParserTestApp10.apk";
    private static final String PACKAGE_NAME = "com.android.servicestests.apps.packageparserapp";

    @Before
@@ -918,6 +920,39 @@ public class PackageParserTest {
        }
    }

    @Test
    public void testParseBackupProperties_noBackupAgent() throws Exception {
        final File testFile = extractFile(TEST_APP9_APK);
        try {
            final ParsedPackage pkg = new TestPackageParser2().parsePackage(testFile, 0, false);
            // Supported without backupAgent - checks they are the non-default
            assertTrue("restoreAnyVersion", pkg.isRestoreAnyVersion());
            assertFalse("killAfterRestore", pkg.isKillAfterRestoreAllowed());

            // Not supported without backupAgent - checks they are the default
            // (opposite of what is in the manifest)
            assertFalse("fullBackupOnly", pkg.isFullBackupOnly());
            assertFalse("backupInForeground", pkg.isBackupInForeground());
        } finally {
            testFile.delete();
        }
    }

    @Test
    public void testParseBackupProperties_withBackupAgent() throws Exception {
        final File testFile = extractFile(TEST_APP10_APK);
        try {
            final ParsedPackage pkg = new TestPackageParser2().parsePackage(testFile, 0, false);
            // Non-default values
            assertTrue("restoreAnyVersion", pkg.isRestoreAnyVersion());
            assertFalse("killAfterRestore", pkg.isKillAfterRestoreAllowed());
            assertTrue("fullBackupOnly", pkg.isFullBackupOnly());
            assertTrue("backupInForeground", pkg.isBackupInForeground());
        } finally {
            testFile.delete();
        }
    }

    /**
     * A subclass of package parser that adds a "cache_" prefix to the package name for the cached
     * results. This is used by tests to tell if a ParsedPackage is generated from the cache or not.
+26 −0
Original line number Diff line number Diff line
@@ -133,3 +133,29 @@ android_test_helper_app {
    ],
    manifest: "AndroidManifestApp8.xml",
}

android_test_helper_app {
    name: "PackageParserTestApp9",
    sdk_version: "current",
    srcs: ["**/*.java"],
    dex_preopt: {
        enabled: false,
    },
    optimize: {
        enabled: false,
    },
    manifest: "AndroidManifestApp9.xml",
}

android_test_helper_app {
    name: "PackageParserTestApp10",
    sdk_version: "current",
    srcs: ["**/*.java"],
    dex_preopt: {
        enabled: false,
    },
    optimize: {
        enabled: false,
    },
    manifest: "AndroidManifestApp10.xml",
}
+32 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2025 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.servicestests.apps.packageparserapp" >

    <!-- All backup flags set to non-default -->
    <application
        android:allowBackup="true"
        android:backupAgent="com.android.app.backup.BackupAgent"
        android:restoreAnyVersion="true"
        android:killAfterRestore="false"
        android:backupInForeground="true"
        android:fullBackupOnly="true">

        <activity android:name=".TestActivity"
            android:exported="true" />
    </application>
</manifest>
 No newline at end of file
Loading