36 Commits

Author SHA1 Message Date
Jeff Sharkey
c206d63edc Merge "Emit "usesPermissionFlags" in "dump badging"." into sc-dev 2021-06-04 22:06:55 +00:00
Ryan Mitchell
6ea9ed3d5f Do not call pop_back when app has no uses-sdk
Calling pop_back on an empty container results in undefined behavior.
aapt2 dump badging seg faults when used on an APK with no uses-sdk.

Bug: 188461703
Test: aapt2 dump badging HelloAppTest.apk
Change-Id: I8d8308a06d542f003ae399629bdbfb5b845674fc
2021-05-20 13:55:12 -07:00
Kelvin Zhang
3965584d3a Fix segmentation fault in aapt2
When passing a single iterator to std::vector::eraase, only element at
that iterator is removed. If no elements are filtered, std::remove_if()
returns the end iterator, attempting to erase() the end iterator can
cause segmentation fault. This bug causes signing test to fail.
https://atp.googleplex.com/tests/asit/ota/signing?tabId=test_run

Test: aapt2
PRODUCT/app/CalculatorGooglePrebuilt/CalculatorGooglePrebuilt.apk

Bug: 175789289
Bug: 178554651

Change-Id: I813055238bef2dcbdf76172a00b3f44ae940b759
(cherry picked from commit b88ccf80aa884df039cd13c5a31f3e08065d487e)
2021-05-11 17:18:45 +00:00
Ryan Mitchell
1966e1f236 AAPT2: Only print last uses-sdk tag
When an APK defines multiple "uses-sdk" tags, the Android runtime only
uses the minSdkVersion and targetSdkVersion values from the last
occurrence of the "uses-sdk" tag.

For example an application with the following tags:
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29"/>
<uses-sdk android:maxSdkVersion="28"/>

Will have the following version codes at runtime:
minSdk=1 targetSdk=1

Another example:
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="28"/>
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="19"/>

Will have the following version codes at runtime:
minSdk=5 targetSdk=19

AAPT2 must print the version data from only the last tag, skipping other
occurrences of the tag.

Bug: 175789289
Test: manual
Change-Id: If0fece7de1d96046221c89d1b12515bc5c15c301
2021-05-03 13:54:55 -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
Jeff Sharkey
abcddfd12b Emit "usesPermissionFlags" in "dump badging".
Since developers can declare the "neverForLocation" flag in their
manifest as public API, we should also offer a way to inspect the
value that we parsed from the manifest.

Bug: 183816684
Test: aapt2 dump badging \
        CtsAppThatRequestsBluetoothPermissionNeverForLocation31.apk
Change-Id: I93c0371d6fb1a0ca928aa26265074acee2bee879
2021-03-29 10:05:23 -06: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
Sergey Nikolaienkov
91331e5b55 Fix mismatch in the REQUIRED_(NOT_)FEATURE_ATTR ids
Fix the values of REQUIRED_FEATURE_ATTR and REQUIRED_NOT_FEATURE_ATTR to
match 'requiredFeature' (0x01010554) and 'requiredNotFeature'
(0x01010555) from frameworks/base/core/res/res/values/public.xml
correspondingly.

Bug: 169812610
Test: make aapt2
Test: make aapt2_tests
Test: out/host/linux-x86/nativetest64/aapt2_tests/aapt2_tests
Test: Create manifest with 'required(Not)Permission' in <uses-permission/>
Test: aapt2 link -o out.apk -I $ANDROID_SDK/platforms/android-30/android.jar --manifest AndroidManifest.xml -v
Test: aapt2 dump badging out.apk
Change-Id: Ia1c785cde80bc8394231248119418d5bc5bf456d
2020-10-01 07:41:01 +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
Ryan Mitchell
95f024289b Treat non-integer target SDK as version 10000
Currently aapt2 treats non-integer target SDK values as SDK level 0.
This resulted in incorrect implied permission dumps. This change
causes aapt2 to treat non-integer SDK values as version 10000.

Bug: 155391001
Test: aapt2 dump badging CtsSkQPTestCases.apk
Change-Id: Ie4312a827974a7a10b40b12f8f23d264d1b1999a
2020-04-30 10:31:14 -07:00
Automerger Merge Worker
0b49886dca Merge "Fix clang-tidy performance-faster-string-find warnings" am: 57fb318ca3 am: 7c0f0d3cec am: 40ef6319ca
Change-Id: Id9d31a0c5cf41a0bb4a58326faa79511a1d8cc4a
2020-02-12 00:53:37 +00:00
Chih-Hung Hsieh
f2ef6579f2 Fix clang-tidy performance-faster-string-find warnings
Bug: 30411878
Test: build with WITH_TIDY=1
Change-Id: I7fd815aa401fbcaff97b772f3ba5d6f1d2034011
2020-02-11 14:27:11 -08:00
Dave Ingram
7e0e4c11f2 Badging should print package attributes at most once
Following up to change 7938786; if an APK had platformBuildVersionCode
compiled as *both* integer and string, it would be output twice. This
then confuses anything that tries to parse the output.

With this change, the value will be printed at most once, with the
string version taking priority.

Bug: 138666693
Test: manually built SDK28 APK and ran aapt2 dump badging
Change-Id: Icf6eb656ac0cb263969bb2f0c5ca03139985f6ca
2019-08-01 16:10:33 -07:00
Ryan Mitchell
a36cc98af5 Badging should print compiled platform version
aapt2 saves space by compiling all raw xml strings to the Res_value
structure. This causes the platformBuildVersionCode and
platformBuildVersionCodename attributes on the <manifest> tag to be
compilled as integers. aapt2 and aapt dump badging assumed these values
would be strings and is failing to print the value for these attributes.

With this change, the value will be printed regardless if it is encoded
as an integer or string.

Bug: 130830770
Test: manualy build APK and run aapt2 dump badging
Change-Id: I89487db36c6bc4d0fde3a410b7a64debfec5021e
2019-06-05 10:13:41 -07:00
Ryan Mitchell
28c88801e7 Fix aapt2 badging return codes
aapt2 was returning the inverse return code when duumping badging.

Bug: 129476626
Test: aapt2 dump badging [APK] && echo $?
Change-Id: Icd236e5fad3284c8bc4a0e2d7e9fb7cfb3262b6c
2019-03-28 11:28:54 -07:00
Anton Hansson
cd2d8e2021 Make aapt2 dump badging print overlay info
This adds the contents of the manifest <overlay> tag to the
output of aapt2 dump badging.

Sample output:
  overlay: targetPackage='android' priority='1' isStatic='false'

Bug: 119938467
Test: aapt2 dump badging \
  $ANDROID_PRODUCT_OUT/vendor/overlay/framework-res__auto_generated_rro.apk
Change-Id: Ie9d904e6206ff8cf092744e630ee6f496672673c
2018-12-12 13:17:26 +00:00
Ryan Mitchell
214846df59 Created resuable DumpApkCommand and added "badger"
This change refactors the dump commands to inherit from a base
DumpApkCommand and adds a command that prints out an ASCII
image of a badger if the user wrote "badger" instead of
"badging". The command is hidden from the help menu.

Bug: 73535002
Test: manual
Change-Id: I9bdd8a7bbf6a4282c4933e5c478f6d1d8e32d99e
2018-10-09 10:51:25 -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
TreeHugger Robot
b61b0e5731 Merge "Implement issue #112113117: Ad library dependency declaration in manifest" 2018-10-05 00:45:06 +00: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
Ryan Mitchell
2250c93f14 Fix badging meta-data value
Integer meta data values were not printing correctly and instead were
printing as empty strings. Attempt to retrieve the integer value of the
attribute if the value is not a string.

Bug: 117260085
Test: manual
Change-Id: I1cef672e03d07728819ca584b484dc372984c823
2018-10-04 13:15:23 -07:00
Ryan Mitchell
fc225b21c1 AAPT2: Added badging and permission
Added the remaining dump commands to aapt2.
aapt2 dump badging [apk]
aapt2 dump permissions [apk]

Bug: 73351292
Test: Diffing aapt and aapt2 output across apps from the Android tree
Change-Id: Idee820db410ad8d777d0d250c2657e7b83112a00
2018-09-18 13:17:01 -07:00
Adam Lesinski
d0f492db03 AAPT2: Share split functionality between link and optimize
Generating splits should be possible to do from the optimize command.
This means that a lot of infrastructure around split APKs can be
shared by both the optimize and link phase.

Bug: 35925830
Change-Id: Ia88b9e4bff300a56353b2f7a4a2547c8eb43a299
Test: manual
2017-04-10 11:59:18 -07:00
Adam Lesinski
d5083f6f6b Move StringPiece to libandroidfw
libandroidfw needs to make use of StringPiece, so
move it to libandroidfw and update all code referencing
StringPiece in aapt2.

Test: make libandroidfw_tests libaapt2_tests
Change-Id: I68d7f0fc7c651b048d9d1f5e7971f10ef5349fa1
2017-01-17 18:55:51 -08:00
Adam Lesinski
ce5e56e243 AAPT2: Rename to match new style
Use Google3 naming style to match new
projects' and open source google projects' style.

Preferred to do this in a massive CL so as to avoid
style inconsistencies that plague legacy code bases.
This is a relatively NEW code base, may as well keep
it up to date.

Test: name/style refactor - existing tests pass
Change-Id: Ie80ecb78d46ec53efdfca2336bb57d96cbb7fb87
2016-10-26 19:30:23 -07:00
Adam Lesinski
cacb28f2d6 Use Google3 style guide with .clang-format
Test: style change only, builds ok
Change-Id: I885180e24cb2e7b58cfb4967c3bcb40058ce4078
2016-10-19 12:18:14 -07:00
Adam Lesinski
5eeaaddffd AAPT2: Add Inline Complex XML support
See: https://developer.android.com/guide/topics/resources/complex-xml-resources.html

Change-Id: I8274c85e25cabf90423141c228697e873167d136
2016-08-31 18:32:34 -07:00
Adam Lesinski
d0f116b619 AAPT2: Remove usage of u16string
For legacy reasons, we kept around the use of UTF-16 internally
in AAPT2. We don't need this and this CL removes all instances of
std::u16string and StringPiece16. The only places still needed
are when interacting with the ResTable APIs that only operate in
UTF16.

Change-Id: I492475b84bb9014fa13bf992cff447ee7a5fe588
2016-07-13 17:45:28 -07:00
Adam Lesinski
5e8fa3a248 AAPT2: Improve diff command
Change-Id: Ia1e2f8482c7192ef50126b61bed7975297332767
2016-06-29 21:56:58 -07:00
Adam Lesinski
fb6312fe93 AAPT2: Add version collapsing
When an app specifies (or imports) resources with various
configurations for different SDK versions, specifying
a minSdk will make many of those resources unreachable.

Version collapsing will prune out the resources specified
for SDK versions less than the minSdk.

If, however, there is no exact matching resource for the
minSdk version, the next smallest SDK version is kept.

Change-Id: Ic7bcab6c59d65c97c67c8767358abb57cdec60a4
2016-06-29 17:02:19 -07:00
Adam Lesinski
64587af817 AAPT2: Support building, linking, and merging static libraries
Android static libraries are like APKs but they contain much more debugging
and source information. We need to treat them differently in 3 ways:

1) When building a static library, we skip things like ID assignment and
   product/config stripping. Source information is emitted as well.
2) When building a static library and linking against another
   static library, we don't want to merge, we want to simply reference.
3) When building an app that uses static libraries, we want to merge
   the static library under the same package with or without mangling.

Bug:25958912
Change-Id: I425e032857936a3e83173c1edc2a6cdc6020b842
2016-03-04 14:39:01 -08:00
Adam Lesinski
355f285ffd AAPT2: Implement density stripping and initial Split support
When a preferred density is supplied, the closest matching densities
will be selected, the rest stripped from the APK.

Split support will be enabled in a later CL. Command line support is still
needed, but the foundation is ready.

Bug:25958912
Change-Id: I56d599806b4ec4ffa24e17aad48d47130ca05c08
2016-02-17 18:17:25 -08:00
Adam Lesinski
59e04c6f92 AAPT2: Switch to protobuf for intermediate format
Without needing to conform to the runtime data format,
it is much easier to add new features such as debugging symbols
and carrying over product data to link time.

This also simplifies the runtime format parser and serializer,
which will change much less frequently than the protobuf intermediate
format.

Change-Id: I209787bbf087db0a58a534cb8511c51d21133e00
2016-02-09 19:59:17 +00:00