Commit Graph

30 Commits

Author SHA1 Message Date
Ryan Mitchell
939df096be Add odm and oem policies
This change adds parsing, encoding, and validating of odm and oem
overlayable policies to aapt2, libandroidfw, and idmap2.

Bug: 121033532
Test: aapt2_tests, idmap2_tests
Change-Id: Ifc0d4b6c9f9c37e06b2988abade69dbb277c50c2
2019-04-17 16:07:57 -07:00
Ryan Mitchell
52e1f7a1ba Run idmap2 static-checks and fix formatting issues
Bug: 130324774
Test: builds
Change-Id: I2cf9d3aa268ffe38e525fadee9d81fc6aefe19b1
2019-04-15 08:48:10 -07:00
Ryan Mitchell
ac791e6557 Fix idmap2 policy concatenation
When printing warning messages while generating idmaps, put the vertical
bar chracater in between the policies.

Bug: none
Test: manual

Change-Id: I8efee753d9ed7ce99ccafd49b6c8744eea031839
2019-04-03 11:02:39 -07:00
TreeHugger Robot
1b41c4b364 Merge "idmap2: move Idmap.h to Result" 2019-03-21 16:38:10 +00:00
Mårten Kongstad
cf622490b3 idmap2: clang-format
Test: cmds/idmap2/static-checks.sh
Change-Id: I17a0268058156373e9af1e00a7bcca5a8cc8f100
2019-03-20 13:49:44 -07:00
Mårten Kongstad
ce42490bb5 idmap2: move Idmap.h to Result
Change the signatures of Idmap::FromApkAssets and
Idmap::FromBinaryStream from

  std::unique_ptr<const Idmap> func(..., std::ostream& out_error);

to

  Result<std::unique_ptr<const Idmap>> func(...);

The returned pointer is still a unique pointer to ensure the dynamically
allocated memory is automatically released when no longer used. This
means that using the returned value of either function requires one of
two patterns:

  const auto idmap = func(...);
  if (!idmap) {
    return Error(...);
  }
  (*idmap)->accept(...);

or

  auto result = func(...);
  if (!result) {
    return Error(...);
  }
  const auto idmap = std::move(*result);
  idmap->accept(...);

Note that in the second example, result must be non-const or
the call to std::move(*result) will not compile.

With this change, the entire idmap2 project has been converted to use
Result.

Test: make idmap2_tests
Change-Id: I533f4e03b99645523d94dd5f446ad76fb435f661
2019-03-20 13:45:14 -07:00
TreeHugger Robot
5942b376fd Merge "Fix idmap enforce overlayable bug" 2019-03-20 18:33:36 +00:00
Ryan Mitchell
2c19bd0bc0 Fix idmap enforce overlayable bug
Idmap2 is not enforcing overlayable on Q overlays and instead on P
overlays. This corrects this behavior.

Test: idmap2_tests
Bug: 128932015
Change-Id: I7e45a965d3b165dae7ed7377d0911afd62f63983
2019-03-19 15:23:15 -07:00
Mårten Kongstad
0c6ff1da4f idmap2: move commands to Result<Unit>
Change the signature of the idmap2 commands (Create, Dump, ...) to
return Result<Unit> instead of bool. This removes the need to pass in an
ostream for error messages: instead, those messages are part of the
returned Result.

Consolidate error messages: texts in Error objects should not be
prefixed with "error:", that is the responsibility of the outer-most
caller (i.e. main()).

Test: make idmap2_tests
Change-Id: I074881b3d1982ea8f4be5752161ac74b14fcba95
2019-03-19 14:26:38 -07:00
TreeHugger Robot
e11bfbe411 Merge changes from topic "idmap-default-policies"
* changes:
  Fix idmap scan to supply correct policies
  Revert "Revert "Enforce a default policy on packages without <overlayable>""
2019-03-11 15:38:09 +00:00
Ryan Mitchell
4c09a4a4f7 Fix idmap scan to supply correct policies
Overlayable policies were not being passed correctly to idmap2 create
from scan. This fixes that and adds better error messages for when
policy failures occur.

Bug: 127860892
Test: manual
Change-Id: I8fae20884a75f4c57a0eb4aafdb4e09da3ebaf93
2019-03-08 09:31:44 -08:00
Ryan Mitchell
b863ca3348 Revert "Revert "Enforce a default policy on packages without <overlayable>""
This reverts commit 6ce5b00f2a.

Bug: 127835630
Test: manual and idmap2_tests
2019-03-07 14:31:54 -08:00
Ryan Mitchell
6ce5b00f2a Revert "Enforce a default policy on packages without <overlayable>"
This reverts commit 48945224bd.

Reason for revert: <b/127835630>

Change-Id: I0bc90c26e5b7d6b4d94704a2a1f92bbc889c025c
2019-03-07 21:58:14 +00:00
Ryan Mitchell
48945224bd Enforce a default policy on packages without <overlayable>
In order to lift the signature/preinstalled install restrictions on overlays,
we must protect packages that have not migrated to <overlayable> from
being overlaid. If a resources is not specified as overlayable and the
overlay does not define an <overlayable>, require the overlay to be
preinstalled or signed with the same signature as the target.

Bug: 121016681
Bug: 125933494
Test: idmap2_tests
Change-Id: I38f520929031b743e4bbe0366a9be55aac5795c5
2019-03-07 16:37:10 +00:00
Yi Kong
974d516e5f Add missing WARN_UNUSED attribute
The upcoming compiler update warns against missing WARN_UNUSED
attribute:

  frameworks/base/cmds/idmap2/libidmap2/Idmap.cpp:58:3: error: function 'Map' should be marked [[nodiscard]] [modernize-use-nodiscard,-warnings-as-errors]
    inline const std::map<TypeId, std::set<std::pair<ResourceId, ResourceId>>>& Map() const {
    ^
    [[nodiscard]]

Test: m checkbuild
Bug: 126457671
Change-Id: Ib006dacbc17446377b2886c73190548f53429a44
2019-03-06 16:22:42 -08:00
Mårten Kongstad
49d835d84e idmap2: switch to improved Result class
Remove the old std::optional based Result class, replace uses with the
new std::variant based Result class.

Test: make idmap2_tests
Change-Id: I401cb36e5af06133a2872d835cf29bfb0b106597
2019-02-27 20:31:51 +00:00
Winson
b410020881 idmap2: add signature policy
Handles the new signature policy for overlayable resources.

Bug: 119402606

Test: idmap2_tests target

Change-Id: I7961e04a879c40c240ed9097bb510addb8b56680
2019-02-15 17:29:48 -08:00
Mårten Kongstad
4cbb00752b idmap2: add systrace logs
Thanks to the ART team for art/libartbase/base/systrace.h which served
as inspiration for the SYSTRACE macro.

Bug: 119761810
Test: run idmap2_tests on device while capturing systrace
Change-Id: I81112ae8e58daf20ebed33ef8b0f5a0caa4dbc73
2019-02-08 07:28:41 -08:00
Mårten Kongstad
9371dc17e4 idmap2: include AndroidManifest.xml in CRCs
The CRCs stored in the idmap file header are copies of the zip file CRC for the
resources.arsc entry in the target and overlay package apks, and are used to
quickly check if either package's contents has changed, which in turn means the
idmap file must be recreated.

With the introduction of named targets, just checking the resources.arsc file is no
longer sufficient: an overlay package could be installed with targetName="a" and
updated to targetName="b". This change is not reflected in the resources.arsc file,
only in the AndroidManifest.xml.

To account for this, update the CRC in the idmap file header from

    CRC(resources.arsc)

to

    CRC(resources.arsc) ^ CRC(AndroidManifest.xml)

Test: make idmap2_tests
Bug: 119761809
Change-Id: Ieb0c6b466ac23eb81a2670a32309fa46ade5c5c8
2019-02-07 17:33:19 +00:00
Ryan Mitchell
198234502b Enforce overlayable API when defined
If a package defines overlayable resources, then do not allow resources
that are not defined as overlayable to be overlaid.

Bug:123600120
Test: idmap2_tests and cts-tradefed run cts -m CtsRROTestCases
Change-Id: I35120a97ccf4650e67c7ba65a60f4f3c51b0e627
2019-02-05 07:56:50 -08:00
Ryan Mitchell
a362846d4d Add enforcement of overlayable targetName
Adds android:targetName to the overlay manifest attributes and
PackageParser reads the name into PackageInfo. Specifying
android:targetName on an overlay allows the overlay to be associated
with a particular set of overlayable resources. The overlay can only
override the values of the resources defined within the target
overlayable element.

Test: idmap2_tests
Bug: 119390855
Bug: 110869880

Change-Id: I1128274af4cae983f61ae15cdfcbface63233ff2
2019-01-18 11:47:20 -08:00
Mårten Kongstad
d10d06d0b0 Add enforcement of idmap policies
Teaches idmap2 to recognize policy restrictions put on overlayable
resources. If overlayable enforcement is turned on for an overlay, then
any resources defined within the overlayable api of the target will have
policy restrictions imposed on them. All resources without overlayable
definitions will continue to be overlayable without policy restrictions.

Bug: 119390857
Test: atest idmap2 and booting

Co-authored-by: Ryan Mitchell <rtmitchell@google.com>
Change-Id: I7e435648eb6e4a87b0b90a7b2a0c3f33c1516ea6
2019-01-16 11:47:24 -08:00
Mårten Kongstad
0eba72a4dd idmap2: fix clang-tidy warnings [modernize-*]
Bug: 120024673
Test: mmm frameworks/base/cmds/idmap2; check output
Change-Id: I8768169fb7b541eb6b1aa3311c46a710eb71aac9
2018-12-21 08:16:09 -08:00
TreeHugger Robot
0b83fbf20e Merge "idmap2: fix clang-tidy warnings [readability-*]" 2018-12-21 05:34:52 +00:00
TreeHugger Robot
d76666276a Merge "idmap2: fix clang-tidy warnings [misc-*]" 2018-12-21 05:22:32 +00:00
Mårten Kongstad
cf28136041 idmap2: fix clang-tidy warnings [misc-*]
Bug: 120024673
Test: mmm frameworks/base/cmds/idmap2; check output
Change-Id: I48c1cf25d2f1cf243dca67ec9d7e8fd50e6f9f32
2018-12-20 15:30:49 -08:00
Mårten Kongstad
b877902199 idmap2: fix clang-tidy warnings [readability-*]
Bug: 120024673
Test: mmm frameworks/base/cmds/idmap2; check output
Change-Id: I1565afac8d34e4347d8c946228d1134211e8b435
2018-12-20 15:29:06 -08:00
Mårten Kongstad
744ccfe9d4 idmap2: move static functions to anonymous namespaces
Move static functions to anonymous namespaces: this is the contemporary
way to express the same thing.

Test: make idmap2_tests
Change-Id: I41ed387455996db1ac515d04eb560d179b5b5169
2018-12-20 15:01:09 -08:00
Mårten Kongstad
0f76311c1d idmap2: replace std::pair<bool, T> with Result<T>
Introduce a new type Result<T> to indicate if an operation succeeded or
not, and if it did, to hold the return value of the operation. This is
the same as how std::pair<bool, T> is already used in the codebase, so
replace all instances with Result<T> to improve clarity.

Result<T> is simply an alias for std::optional<T>. The difference is
semantic: use Result<T> as the return value for functions that can fail,
use std::optional<T> when values are truly optional. This is modelled
after Rust's std::result and std::option.

A future change may graduate Result<T> to a proper class which can hold
additional details on why an operation failed, such as a string or an
error code. As a special case, continue to use std::unique_ptr<T>
instead of Result<std::unique_ptr<T>> for now: the latter would increase
code complexity without added benefit.

Test: make idmap2_tests
Change-Id: I2a8355107ed2b6485409e5e655a84cf1e20b9911
2018-12-17 15:45:20 -08:00
Mårten Kongstad
0275123eef idmap2: initial code drop
idmap2 is a reboot of the idmap project. The project aims to

  - use modern C++
  - greatly improve test and debug support
  - interface towards AssetManager2 (instead of AssetManager)
  - provide a solid foundation to add support for new features

To make it easier to verify correctness, this first version of idmap2 is
feature equivalent to idmap. Later versions will add support for new
features such as <overlayable>.

Bug: 78815803
Test: make idmap2_tests
Change-Id: I1d806dc875a493e730ab55d2fdb027618e586d16
2018-10-30 04:37:41 -07:00