210 Commits

Author SHA1 Message Date
Ryan Mitchell
2fedba9a32 Add <staging-public-group-final> to aapt2
To allow apps that compiled against a pre-release SDK to continue
working for a period of time after API finalization, a new tag,
<staging-public-group-final>, has been added to aapt2.

When finalizing the framework resource API, converting
<staging-public-group> tags to <staging-public-group-final> will
cause aapt2 to generate the resource table so that there is a resource
entry for the old non-finalized (staged) resource ID and another entry
for the finalized resource ID of newly finalized resources. This allows
an application that compiled against the pre-release SDK to continue
resolving resources using pre-release resource IDs.

All references to pre-release resource IDs will be rewritten to their
finalized resource IDs through the information stored in the new staged
alias chunk. This allows applications compiled against
<staging-public-group> resources to use the newly finalized
resource ID without re-compilation.

When an application is re-compiled against the SDK with
<staging-public-group-final> tags, the application will use the
finalized resource IDs.

This change limits the use of the alias chunk to the framework for S.

Bug: 183411356
Test: aapt2_test
Change-Id: Iba1c3033c3c2f32de8e4a19b58d3921c971092c4
2021-05-10 17:22:33 -07:00
Ryan Mitchell
326e35ffaf Add <macro> tag to aapt2
AAPT2 Macros are compile-time resources definitions that are expanded
when referenced during the link phase.

A macro must be defined in the res/values.xml directory. A macro
definition for a macro named "foo" looks like the following:
 <macro name="foo">contents</macro>

When "@macro/foo" is used in the res/values directory or in a compiled
XML file, the contents of the macro replace the macro reference and
then the substituted contents are compiled and linked. If the macro
contents reference xml namespaces from its original definition, the
namespaces of the original macro definition will be used to determine
which package is being referenced.

Macros can be used anywhere resources can be referenced using the
@package:type/entry syntax.

Macros are not included in the final resource table or the R.java since
they are not actual resources.

Bug: 175616308
Test: aapt2_tests
Change-Id: I48b29ab6564357b32b4b4e32bff7ef06036382bc
2021-04-28 14:58:23 -07:00
Ryan Mitchell
efcdb95fa7 Aapt2 ValueTransformer
For future macro support, aapt2 must be able to convert Reference
values into other Value types. Currently a DescendingValueVisitor is
used to visit all of the References in a ResourceTable or a compiled
XML file to set their resource ids during the link phase. This was fine
since we were only mutating the resource id of the visited Reference.

A macro may reference a String, BinaryPrimitive, or any other Item
type. During the link phase, we will need to transform references to
macros into the values of the macros.

The only parameter in the methods of the ValueVisitor interface is a
raw pointer to the type being visited. The visitor interface does not
support reassigning the visited type to a different type.

ValueTransformer is a new interface for consuming a Value type and
transforming it into a compatible Value type. This change refactors
Value::Clone to use this interface.

Bug: 175616308
Test: aapt2_tests
Change-Id: Ic1b9d718b932c208764114cd9c74d880e189ccb0
2021-04-21 08:32:30 -07:00
Ryan Mitchell
1d008d1d2a Refactor aapt2 tests ResourceTable changes
This changes refactors tests to use the NewResourceBuilder class
that makes it easier to construct resource entries.

Bug: 183102797
Test: aapt2_tests
Change-Id: I851f9fb99a003769f8df8c1876997eee0864822a
2021-03-29 10:22:10 -07:00
Ryan Mitchell
9634efb6f4 Prepare aapt2 for multiple ids per type
For the SDK finalization changes, aapt2 must be able to handle
resources of the same type having different type ids. The
ResourceTable data structure currently stores package ids and type ids
on ResourceTablePackage and ResourceTableType respectively. This
prevents resource entries of the same type from having different type
ids without having to create another ResourceTableType structure.

JavaClassGenerator assumes each type only appears once in the
ResourceTable and it would need to dedupe the types to ensure one class
containing all the resource types ids is generated. TableFlattener on
the other hand needs a separate ResourceTableType for each type/id
combination so that the types are flattened into separate
ResTable_types.

This change simplifies aapt2's ResourceTable data structure:
- Resource ids are stored exclusively on ResourceEntry structures
  meaning multiple entries can have different type ids while being
  stored in the same ResourceTableType. Classes like JavaClassGenerator
  can simply iterate over a type to see all the resources of the type
  regardless of what their type id is.

- ResourceTable::GetPartitionedView() retrieves a list of resources
  sorted and partitioned by package id, type id, and entry id. Classes
  like TableFlattener can use this view to get separate
  ResourceTavleTypes for each different type id that a type has.

These changes will also make it easy to have a resource span multiple
type ids if it exhausts all of the entry ids in one type id.

The new NewResourcesBuilder replaces the numerous setter methods on
ResourceTable.

Bug: 183102797
Test: aapt2_tests
Change-Id: I60dbcb24143bb958333899cafa7d41faa226d203
2021-03-29 10:22:08 -07:00
Rhed Jao
b9ccb8a49b aapt2: Add a new flag '--revision-code'
A new flag to inject revisionCode into the manifest for cts splits tests.

Bug: 174338944
Test: atest aapt2_tests
Change-Id: If5a089f37233f53af3012ca5eab17fab21eafd9c
2020-11-30 21:48:34 +08:00
Rhed Jao
61bcee0cd1 Merge "aapt2: Limit length of package name and shared user id" 2020-11-20 02:18:53 +00:00
Rhed Jao
2c4344223d aapt2: Limit length of package name and shared user id
Package name and shared user id could be used as part of filename
as prefix by other modules. Limits the length to 223 and reserves
32 for the OS.

Bug: 118768971
Test: atest aapt2_tests
Test: aapt2 link -I android.jar --manifest ManifestLongPackageName.xml
Test: aapt2 link -I android.jar --manifest ManifestLongSharedUserId.xml
Change-Id: Ic4b5b4647b9e253b79b663f4d7a9050f43bb8cf0
2020-11-19 15:34:14 +08:00
Todd Kennedy
ce3e129498 Handle new manifest tag <property>
Bug: 169258655
Test: aapt2_tests
Change-Id: Ia1c8e7c38fb882c3ce0aa2913b844cccdc5b8749
2020-11-17 11:59:07 -08:00
Sergey Nikolaienkov
65f9099ad5 Teach appt2 to handle <required-(not-)feature>
Introducing 'required-feature' and 'requred-not-feature' tags that could
be used "inside" 'uses-permission' elements.
Elements of both types should have non-empty 'android:name' attribute to
specify the name of the feature.

Bug: 168079571
Test: make aapt2
Test: make aapt2_tests
Test: out/host/linux-x86/nativetest64/aapt2_tests/aapt2_tests
Test: create AndroidManifest.xml with <required(-not)-feature>
Test: aapt2 link -o out.apk -I $ANDROID_SDK/platforms/android-30/android.jar --manifest AndroidManifest.xml
Test: aapt2 dump badging out.apk
Test: appt2 dump permissions out.apk
Change-Id: I67ba0731daa6d31cd976b922217853f159cf7c3a
2020-10-06 06:54:53 +00:00
Ryan Mitchell
4ea9075124 Make aapt2 terminology more inclusive
Update language to comply with Android's inclusive language guidance

See https://source.android.com/setup/contribute/respectful-code
for reference

Bug: 162364131
Bug: 162536543
Test: aapt2_tests
Change-Id: I4eef925d6319b40a395fc8d59a3f2912a02ca03b
2020-07-31 21:03:54 +00:00
Jiyong Park
6a5b8b1f6d Introduce uses-native-library tag
Since Android 7.0, partners were able to export some of their native
shared libraries to apps. So far, the native libraries were provided to
all apps regardless of whether they are actually needed or not. Even
worse, it was impossible to prevent the installation of an app to the
device where the some (or all) of the required native libs don't exist;
the apps had to manually handle the case, which sometimes impossible
when the dependency is so fundamental.

This change introduces a new tag <uses-native-library> to the app
manifest. Similary to the existing <uses-library> tag which is for
(java) shared libraries, the new tag is used to describe the depedencies
to the native shared libraries.

Apps targeting Android S or higher are required to use the tag to import
the native shared libraries. Libraries that are not depended on won't be
available to the app even if the libraries are listed in the
public.libraries*.txt files. Furthermore, when the dependency can't be
satisfied for an app, the package manager refejects installing the app.

The dependency can be optional using the `android:required` attribute.
When it is set to true, the absence of the lib on the device doesn't
prevent the app from being installed. However, the app has to gracefully
deal with the absence.

The changed behavior only affects apps targeting S or higher. Existing
apps are unaffected; they still get all the public native libraries
regardless of whether they have <uses-native-library> tags or not; the
tags are simply ignored.

This is the first version of the implementation and therefore needs
further refinements. The followings are two major TODOs.

1) The native shared lib dependencies of the java shared libraries
are not enforced. For example, if an app depends on a java shared
library foo and foo depends on some native shared libraries, the
classloader where code from foo is loaded still gets all native shared
libraries. This should be fixed.

2) New APIs should be added. SharedLibraryInfo should be extended to
represent native shared libraries. The meaning of
ApplicationInfo.sharedLibraryFiles should be revised. Finally, the new
tag should be made public.

Bug: 142191088
Test: atest CtsUsesNativeLibraryTest
Change-Id: Iceb038aa86872d23e9faf582ae91b1fdcaf5c64c
2020-07-21 08:42:00 +09:00
Philip P. Moltmann
3a69660910 Remove legacy support for "featureId".
"featureId" was the old name of "attributionTag". This was never shipped
in any public build and is hence just dead code.

Bug: 151105954
Test: atest CtsAppOpsTestCases
Change-Id: I7570e7f84cc3f6cabaa769c700c3ceaf7eed0ae9
2020-06-19 19:57:27 -07:00
Roshan Pius
ae12ce4119 aapt2: Add command to rename overlay "targetPackage" attribute
Bug: 154960712
Test: atest ManifestFixerTest
Change-Id: I556fc11e271337de40c70d4ed56a0381a2f79712
2020-04-27 21:49:23 +00:00
Philip P. Moltmann
12ac3f406f Rename featureId -> attributionTag
In the core functionality this changes everything including aidl's and
field names:
- Context
- ContentProvider
- AppOps*
- Package parsing

For the rest, this is a shallow change to only change to the changed
APIs. This keeps the change small-ish

Exempt-From-Owner-Approval: Rename
Fixes: 148792795
Test: TH
Change-Id: I2a2245fe76e09e62cb13d5785d2efb4a304ba54a
Merged-In: I2a2245fe76e09e62cb13d5785d2efb4a304ba54a
2020-03-12 19:26:10 +00:00
Winson
62ac8b56a9 Refactor overlayable policy
To make it easier to add the actor policy in a follow up CL,
move most of the policy handling to a central location.

The strings and transformation between strings and flags is
now handled in libidmap2policies, with libandroidfw
containing the single source of policy flags.

This also extracts all the test resource IDs into an R.h
so they can be swapped without having to edit a dozen files
each time.

Bug: 130563563

Test: m aapt2_tests idmapt2_tests and run from host test output
Test: atest libandroidfw_tests

Change-Id: Ie533c9cebf938215df7586f00c38763ae467e606
2020-02-26 15:59:43 -08:00
Patrick Baumann
9918123bac Adds queries->provider tag
This change adds support for the <provider> tag inside of the <queries>
tag to support more succinct declaration that an app would like to see
the provider of a given authority.

Test: atest AppEnumerationTests AppsFilterTest
Bug: 136675067
Change-Id: Ie0f73213fae7a3a0619238e44063d4e5be157201
2020-02-07 17:08:30 -08:00
Dianne Hackborn
fc0839ae30 Work on issue #143085640: Per-process network access control
Fix some issues when apps start declaring processes, add validation
that apps don't use processes they haven't declared (if they
declared some).  Also add package dump output for the processes it
has declared.

Bug: 143085640
Test: atest CtsAppSecurityHostTestCases:UseProcessTest
Change-Id: If1d13bf402d2b0aea06f0c2c02d5e392c774c812
2020-02-02 13:39:32 -08:00
Anton Hansson
b2f709db1d Add <extension-sdk> manifest tag inside <uses-sdk>
This allows apps to specify the minimum versions they need
of extension sdks, and fails install if they aren't met.

There is additional work required to prevent local rollbacks
from triggering a downgrade of SDK versions after an install.

Bug: 137191822
Test: atest PackageParserTest
Exempt-From-Owner-Approval: PS4 was approved
Change-Id: If61ae6c67ceb752bec6876006a29e52b996901e7
2020-01-16 11:59:52 +00:00
Philip P. Moltmann
9046d82b8f Allow apps to define featureIds in the manifest
Test: CtsAppOpsTestCases (with newly added test for featureIds declared
      in manifest)
Bug: 144997947
Change-Id: I5563ae6861318e4cc1d196e3f6aea378a4dcf748
2020-01-03 10:08:03 -08:00
Ryan Mitchell
4d5833ecc8 Add android:angle on <gradient> for min sdk <= Q
The default orientation of gradients in android Q is different than
previous android versions. Set the android:angle attribute to "0"
to ensure that the default gradient orientation will remain
left-to-right in android Q.

Bug: 139883313
Test: aapt2_tests
Change-Id: I82e222f635858ed3ecf4a3f3761503d857adb93b
2019-09-04 09:18:55 -07:00
Patrick Baumann
a4ffb4567e Adds queries tag to manifest
This change adds support for a new <queries> tag as a child of the
<manifest> tag, allowing a package to declare the intents it intends to
use to query for other apps on device.

Bug: 136675067
Test: build and boot
Change-Id: Ic8b40cabddee4b6404c220901efeaae680661c0c
2019-07-24 15:24:03 -07:00
Udam Saini
b228df32d9 Allows features to link to other feature splits without namespacing.
Add uses-split dependencies to AppInfo. At link time, this is used
and allows features to reference other features, before
resource namespacing is implemented in Android Studio.

bug:135681292
Test: Link_test, ReferenceLinker_test, and integration tests.
Change-Id: Ifdf0067e7370552b6b9d4d6d4713d4484b6ea154
2019-06-26 13:30:35 -07:00
Donald Chai
121c6e8aa0 [aapt2] Add "link" option to override styles instead of overlaying.
For normal app development, the desired linking semantics are:
* styleables - take union of all definitions
* all other resources - take last non-weak definition

This differs from the semantics needed in other scenarios, where
merging/overlaying styles is desired.

Bug: 134525082
Change-Id: Iac0c43ca2ecf1f3fddc9c3367f8914c12c9258e1
Tested: aapt2_tests
2019-06-12 16:58:45 -07:00
Donald Chai
6e49735aa8 [aapt2] Ensure that attributes have declared namespaces when fixing manifest
aapt::ManifestFixer might add attributes from
http://schemas.android.com/apk/res/android when none existed previously.
When that happens, something needs to ensure that the schema has a
declared xmlns prefix, otherwise this:

bdb3e97c47/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceLinker.java (L560)

will crash.  It's a bit odd that Bazel converts back and forth between
protobuf and XML, but as long as the fields exist in Resources.proto,
they should be set.

Bug: 133004752
Change-Id: I73fb3f713be34c9f81753fde2fd24c4524656b7d
Tested: aapt2_tests
2019-06-05 19:42:42 -07:00
TreeHugger Robot
636f9ae0c2 Merge "Allow merging of resources with the same overlayable" into qt-dev 2019-04-08 21:06:32 +00:00
Ryan Mitchell
ced9a5c108 Allow merging of resources with the same overlayable
If a resource is redefined with the same overlayable name, actor, and
policies, do not error.

Bug: 128843658
Test: m -j Launcher3 && aapt2_tests
Change-Id: I2c79f7d9fa7ff16b38ec41cec7e9804d39b372d5
2019-04-05 10:44:16 -07:00
Chris Craik
335b565eb6 Support profileable application action
Fixes: 129358330
Test: make -j16 aapt2_run_host_unit_tests && cat out/target/product/walleye/obj/PACKAGING/aapt2_run_host_unit_tests_intermediates/result.xml | grep "failure message"
Change-Id: Id9ec59447a99a5f6e0bfe47c0b8ce3553bf751c7
2019-04-04 13:25:55 -07:00
TreeHugger Robot
ade947448e Merge "AAPT2: Delete unused method parameter" 2019-03-20 18:33:06 +00:00
Fabien Sanglard
2369f5407a AAPT2: Delete unused method parameter
Bug: None
Test: None
Change-Id: Ib5d78df9c8e341d9d6559f90f33b1fbd5f711e99
2019-03-19 08:32:46 -07:00
Fabien Sanglard
2d34e76dac Add --trace_folder to aapt2
Add a tracing API and instrument key functions in order to profile
aapt2 bottleneck. The API allows to generate systrace fragment files.

Impact on performance is neglibible with each Trace requiring less
than 1us and the final Flush operation at the end of a command
requiring around 40us.

Bug: None
Test: None
Change-Id: I51b564d3694e9384679f43b878b32295527dddf6
2019-03-05 15:09:27 -08:00
Ryan Mitchell
aada89ce19 Correctly insert platformBuildVersionCode/Name
AAPT(1) encodes platformBuildVersionCode and
platformBuildVersionName into the manifest along with
compileSdkVersion and compileSdkVersionCodename. AAPT2 was extracting
the platform attributes from the app being created rather than the
framework.

This change inserts the correct platform attributes.

Bug: 124227171
Test: aapt2_tests
Change-Id: I4bc7986d25f065cecf01b9e988de4d37283ef7de
2019-02-12 08:16:03 -08:00
TreeHugger Robot
275c3ec658 Merge "Option to exclude configs from AAPT2 Link" 2019-02-01 02:13:08 +00:00
TreeHugger Robot
1ebc40339a Merge "Revert "Add android.hardware.fingerprint for pre-Q"" 2019-01-29 22:23:21 +00:00
Winson
3c918b8cee Option to exclude configs from AAPT2 Link
Adds --exclude-configs to remove matching configs from resulting APK. This matches on explicitness, so if the resource contains all the flags set by the option exactly, it will be removed, but not the other way around.

"--exclude-configs fr" with fr-land resource will remove.
"--exclude-configs fr-land" with fr resource will not remove.

Bug: 119678846

Test: aapt2_tests ResourceExcluder_test
Test: manually ran link on a test set of res

Change-Id: Ieccdecde4aea1fa0502abfd092dffa7da8f929ea
2019-01-28 11:06:33 -08:00
Kevin Chyn
06f2c9fc73 Revert "Add android.hardware.fingerprint for pre-Q"
This reverts commit e1de284ae9e163b90c8bac9f428026f3213ef358.

Reason for revert: b/115639644 comment #27

Change-Id: Icf1f067b4d8f6b83be86128f07a89608112cebeb
2019-01-22 18:19:26 +00:00
Ryan Mitchell
a117526b4a Merge "Remove RRO policy product_services" 2019-01-18 00:41:31 +00:00
Ryan Mitchell
02d9c1e931 Remove RRO policy product_services
Since Q will no longer have a product_services partition, remove instances of
the product_services policy across aapt2, androidfw, and idmap2.

Bug:122745343
Test: aapt2_tests and libandroidfw_tests
Change-Id: I97c223a0bf5a2eab95811e5f738b44af6335e0ea
2019-01-16 11:47:33 -08:00
Ryan Mitchell
e1de284ae9 Add android.hardware.fingerprint for pre-Q
Add "android.hardware.fingerprint" when
"android.hardware.biometric.fingerprint" is found, since the former is
deprecated in Q and the latter is not present pre-Q.

Bug: 115639644
Test: aapt2_tests
Change-Id: Id2b30e9fcc208759ee2e14a05d17c43db1e63db8
2019-01-11 14:36:20 -08:00
Chih-Hung Hsieh
3b3be3f10f Merge "Fix/suppress aapt/aapt2 google-explicit-constructor warnings" am: cdf6be573f am: d42fe48c93
am: 0bf62f1309

Change-Id: Iffb7e4a145b172a35dd58b9450d4a5184d8b07f7
2019-01-04 12:20:01 -08:00
Chih-Hung Hsieh
1fc78e1814 Fix/suppress aapt/aapt2 google-explicit-constructor warnings
* Add explicit to conversion constructors/operators
* Use NOLINT or NOLINTNEXTLINE to suppress warnings on intended converters

Bug: 28341362
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,google-explicit-constructor
Change-Id: Ie02101ea7c422e8add535c111a30a2f21ead0ace
2019-01-04 17:38:13 +00:00
Ryan Mitchell
54237ffed4 Add actor and name parsing for overlayable
Add parsing of two overlayable attributes:
 name : The unnique identifying name of the overlayable set of resources
 actor: The component responsible for enabling and disabling overlays
        targeting the specified set of resources

Bug: 110869880
Bug: 119390855
Test: m -j aapt2_tests
Change-Id: Id42463e2b92b69034fb39cd29bc8606affb61ba7
2018-12-13 16:05:10 -08:00
Ryan Mitchell
1bb1fe068a Refactor policy parsing
This change removes the ability for an overlayable resource to be
defined in multiple policy blocks within the same overlayable. This
change also changes aapt2 to use a bit mask to keep track of the parsed
policies.

Bug: 110869880
Bug: 120298168
Test: aapt2_tests
Change-Id: Ie26cd913f94a16c0b312f222bccfa48f62feceaa
2018-12-11 13:48:45 -08:00
Ryan Mitchell
75e20dda2b Encoding of <overlayable> and <policy>
This change defines two new chunks for encoding overlayable information.
RES_TABLE_OVERLAYABLE_POLICY_TYPE contains flags that represent
restrictions enforced on overlays that try to overlay a specific set of
resource ids. The chunk header is followed by ResTable_ref for each id
that belongs to the policy type. A policy chunk will be created for
every unique combination of policies that are defined in overlayable
declarations.

RES_TABLE_OVERLAYABLE_TYPE holds policy blocks. Since <overlayable>
does not currently have any attributes, only one overlayable block is
encoded in an APK.

This change also removes the SPEC_OVERLAYABLE flag because the runtime
does not use the flag, and the overlayable chunk encoding renders it
obsolete.

Bug: 110869880
Bug: 117545186
Test: libandroidfw_tests and aapt2_tests
Change-Id: I45ae9bf4176699f14c85e2b7a2e8560185d8a0b8
2018-12-04 16:45:26 -08:00
Ryan Mitchell
e4e989ccba RRO: Added partition policies for overlays
<overlayable> tags can now have policy elements that indicate which
partition the overlay apk must reside on in order to be allowed to
overlay a resource. This change only adds parsing of <policy> and
encoding of policy in the proto ResourceTable. A later change will add
the encoding of policy and overlayable in the binary APK.

<overlayable>
  <policy type="system|vendor|product|product_services|public" >
    <item type="string" name="oof" />
  </policy>
</overlayable>

Bug: 110869880
Test: make aapt2_tests
Change-Id: I8d4ed7b0e01f981149c6e3190af1681073b79b03
2018-11-06 00:10:26 +00:00
Treehugger Robot
e75f2f504e Merge changes from topic "aapt2-manifest-elements"
* changes:
  Remove workarounds for b/79755007
  AAPT2: Add the rest of supported manifest elements
  AAPT2: Add supported manifest elements
2018-10-10 22:29:57 +00:00
Mårten Kongstad
5c541f6e36 libandroidfw: move ConfigDescription from aapt2 to libandroidfw
This is to allow idmap2 to access ConfigDescription.

Test: libandroidfw_tests
Test: aapt2_tests
Change-Id: I54210bbbd8dad5903cb7100807df977efa394ad5
Merged-In: I54210bbbd8dad5903cb7100807df977efa394ad5
2018-10-08 09:56:09 -07:00
TreeHugger Robot
6d659e8ceb Merge "libandroidfw: move ConfigDescription from aapt2 to libandroidfw" 2018-10-08 15:41:13 +00:00
Mårten Kongstad
24c9aa6541 libandroidfw: move ConfigDescription from aapt2 to libandroidfw
This is to allow idmap2 to access ConfigDescription.

Test: libandroidfw_tests
Test: aapt2_tests
Change-Id: I54210bbbd8dad5903cb7100807df977efa394ad5
2018-10-08 06:50:22 -07:00
Dianne Hackborn
813d7503c8 Implement issue #112113117: Ad library dependency declaration in manifest
You can now do a new form of <uses-package> that allows you to
specify a type of package along with required cert digests (like
uses-static-library).

This defines the new attribute needed for this and XML tag, and
updates aapt2 to actually allow uses-library in the manifest and
output this data with "dump badging".

While doing this I realized that "dump badging" was not printing
the data for uses-static-library or uses-library, so do those too.

Bug: 112113117
Test: manual
Change-Id: I5d02010aad9cb44675504a317df9cced421be8a1
2018-10-04 15:27:15 -07:00