31 Commits

Author SHA1 Message Date
Todd Kennedy
0b103de238 Merge "idmap2: fix static checks" 2019-02-07 22:12:04 +00:00
TreeHugger Robot
f5ce5eddae Merge "idmap2: introduce improved Result class" 2019-02-07 19:01:38 +00: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
Mårten Kongstad
aabca6c00f idmap2: fix static checks
Fix two errors detected by static-checks.sh:

  - bpfmt: remove -s flag (sort arrays) since it makes no sense to order
    clang-tidy flags alphabetically: flags must be passed to clang-tidy
    in the order specified to make sense

  - cpplint: allow NOLINT(cert-dcl50-cpp)

Test: cmds/idmap2/static-checks.sh
Change-Id: I6677f8e7504551746edae458acd523e643044c7e
2019-02-07 09:27:16 -08:00
Mårten Kongstad
1e99b1783d idmap2: introduce improved Result class
Add a new version of the Result class that functions like the old
Result, but in case of an error, also encodes a string detailing the
error. This will allow us to write the following type of code:

Result<Foo> CreateFoo() {
    if (...) {
        return Error("errno=%d", errno());
    }
    return Foo(...);
}

auto foo = CreateFoo();
if (!foo) {
    std::cerr << "error: " << foo.GetErrorMessage() << std::endl;
    abort();
}
std::cout << "foo=" << *foo << std::endl;

This commit only adds the new Result class. A later change will replace
uses of the old version.

Test: make idmap2_tests
Change-Id: I674d8a06866402adedf85f8514400f25840d5eda
2019-02-06 16:54:25 -08: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
TreeHugger Robot
6302322fe9 Merge "idmap2: lock down write access to /data/resouce-cache" 2019-01-24 17:49:20 +00: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
1da49dc9b4 idmap2: lock down write access to /data/resouce-cache
Deny write access to /data/resource-cache for UIDs other than root and
system. While this is already handled by SELinux rules, add an
additional layer of security to explicitly prevent malicious apps from
messing with the system's idmap files.

Test: make idmap2_tests
Change-Id: Id986633558d5d02452276f05f64337a8700f148a
2019-01-18 10:05:48 -08:00
Ryan Mitchell
9853845074 Merge "Add enforcement of idmap policies" 2019-01-18 00:41:11 +00:00
Pirama Arumuga Nainar
4b2d55b082 Disable modernize-avoid-c-arrays clang-tidy check
Bug: http://b/122481018

Upcoming clang update has a clang-tidy warning about using c arrays and
instead use std::array:
    warning: do not declare C-style arrays, use std::array<> instead

Disable this warning for now (even before the new clang update lands)
since clang-tidy doesn't complain about flags it doesn't know.

Test: Build with new clang.
Change-Id: I971b84301e6cd1180326bc54711d0be193f09ccb
2019-01-17 12:17:31 -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
Chih-Hung Hsieh
55773ba766 Suppress cert-dcl50-cpp tidy warnings.
Bug: 122832439
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,cert-dcl50-cpp
Change-Id: I7268617658632140e9d78faa9ad7b112ff3f6408
2019-01-14 11:09:03 -08:00
Ryan Mitchell
ebc0b6a68e Sort static overlays by priority
Since static overlays are still managed by the native layer, we must
order the overlays during the initial scan so the are put into the
AssetManager in the correct order.

Bug: 121002654
Test: build_success and manual verification of ordering
Change-Id: Id46baed8f836c3b4b86d19d58aee5fd06ff0b762
2019-01-10 16:59:36 -08:00
Todd Kennedy
044803f44d Turn all warnings into errors
Bug: 121388682
Test: idmap2 builds
Change-Id: I6992c4d9b123a5e3d6cea91b1c83a90e57266837
2018-12-21 15:28:45 -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
TreeHugger Robot
b9c1e748e2 Merge "idmap2: move static functions to anonymous namespaces" 2018-12-21 04:39:47 +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
3c9bc617ca idmap2: improve Android.bp
Improve Android.bp in a few ways:

  - add cc_defaults
  - remove the tidy_flag "-warnings-as-errors=*"

A note on warnings-as-errors: the default set of tidy checks are
inherited from the lists in build/soong/cc/config/tidy.go. This set is
modified by the local Android.bp's tidy_checks. If a new check is
enabled as default, and idmap2 specifies warnings-as-errors, idmap2 will
potentially break the build. In light of this, keep warnings as
warnings.

Also add a few non-default tidy checks. This version of idmap2 doesn't
compile cleanly: fixes will come in future CLs.

Also exempt the auto-generated code from IIdmap2.aidl from clang-tidy by
containing it in a separate cc_library_static block.

Bug: 120024673
Test: mmm frameworks/base/cmds/idmap2
Change-Id: I589fce792075a44a77b79117aa16b63ef0bec142
2018-12-20 14:55:49 -08:00
Todd Kennedy
f912d7ac48 Merge "OMS: extract verifyIdmap from createIdmap" 2018-12-18 14:38:52 +00: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
ef0695d78f OMS: extract verifyIdmap from createIdmap
For clarity, split IIdmap2::createIdmap into two separate functions:

  - IIdmap2::verifyIdmap [check if an existing idmap file is OK to use]
  - IIdmap2::createIdmap [unconditionally (re)create an idmap file]

Teach the IdmapManager to call verifyIdmap and to proceed with
createIdmap only if actually needed.

Test: atest OverlayDeviceTests OverlayHostTests
Change-Id: I9f6f1192011fcb094adffeca1eb3f709520bbd24
2018-12-17 15:20:48 -08:00
Mårten Kongstad
b87b507248 Switch to idmap2
Switch from idmap to idmap2.

This CL is the safety pin for idmap2. If idmap2 causes issues during
dogfooding it is easy go back to idmap by reverting this CL.

Once idmap2 has proven itself during a suitable period of time, the
FEATURE_FLAG_IDMAP2 flag and the obsolete idmap code will be removed.

Also add an .rc file to tell init to launch idmap2d.

Bug: 78815803
Test: atest OverlayDeviceTests OverlayHostTests
Change-Id: I5ca1388ac2f8a9379fed0c257247d351a5c7a3c4
2018-11-27 13:37:34 -08:00
Andreas Gampe
d3196be41a Idmap2: Disable tidy errors
Temporarily only emit warnings.

Exempt-From-Owner-Approval: Build fix
Bug: 120024673
Test: N/A
Change-Id: Ia85fca04cc4fe7c4fd7a5d551abb8e00bbec820b
2018-11-26 09:47:04 -08:00
Andreas Gampe
32ad3efd41 Frameworks: Fix tidy build
Some tidy warnings are now errors.

Exempt-From-Owner-Approval: Build fix
Test: WITH_TIDY=1 m
Change-Id: Id0f951e0650bbf5d10afedefe39c8326408fc1a7
2018-11-21 22:24:42 +00:00
Mårten Kongstad
e63a4a28ab idmap2: silence irrelevant warning during 'idmap2 scan'
Even if an idmap file fails the is-up-to-date check during 'idmap2
scan', there is no need to print a warning: this is an expected scenario
and just means that the idmap file needs to be re-created. Remove the
print.

Useful commands for testing:

  1. adb shell rm -f /data/resource-cache/*
  2. adb shell idmap2 scan                                         \
             --recursive                                           \
             --target-package-name android                         \
             --target-apk-path /system/framework/framework-res.apk \
             --output-directory /data/resource-cache               \
             --input-directory /vendor/overlay

Test: manual: put an overlay package with isStatic="true" and       \
              targetPackage="android" in /vendor/overlay/<dir>, run \
              the commands above, verify that nothing is printed    \
              on stderr
Change-Id: I9a458a805936d0c1f6d64b0c3983365e0f0c4696
2018-11-12 13:37:01 -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