Commit graph

474 commits

Author SHA1 Message Date
Tao Bao
2be9737cf4 Remove the FD parameter from FuseDataProvider ctor.
This leaves the FD implementation details to subclasses. In particular,
it allows minadbd to do additional works with the FD after sideloading.

Bug: 128415917
Test: atest recovery_component_test
Test: atest minadbd_test
Test: Sideload package on taimen.
Change-Id: I106bbaad05201227bbc5fe28890bbbb06fdcb67e
2019-04-15 16:53:31 -07:00
xunchang
2478885f3c Move install to separate module
Build libinstall as a shared library. Also drop the dependency on the
global variables in common.h.

Test: unit tests pass, sideload an OTA
Change-Id: I30a20047768ce00689fc0e7851c1c5d712a365a0
2019-03-29 10:27:51 -07:00
Tianjie Xu
3168ddf79d Merge "Allow RSA 4096 key in package verification" 2019-03-27 17:57:38 +00:00
xunchang
908ad77af8 Allow RSA 4096 key in package verification
The RSA_verify sitll works for 4096 bits keys. And we just
need to loose the check on modulus.

Sample commands to generate the key & package:
1. openssl genrsa -out keypair.pem 4096
2. openssl pkcs8 -topk8 -inform PEM -outform DER -nocrypt \
   -in keypair.pem -out private.pk8
3. openssl req -new -x509 -key keypair.pem -out public.x509.pem \
   -days 365
4. java -Djava.library.path=prebuilts/sdk/tools/linux/lib64 -jar \
   prebuilts/sdk/tools/lib/signapk.jar -w public.x509.pem private.pk8 \
   unsigned.zip signed.zip

Bug: 129163830
Test: unit tests pass
Change-Id: I5a5ff539c9ff1955c02ec2ce4b17563cb92808a4
2019-03-26 12:28:23 -07:00
xunchang
625c588c0f Move out the code to parse block map in MemMap
We will reuse them to implement the fuse provider from block maps.

Test: unit tests pass, sideload an OTA
Change-Id: Iaa409d19569c4ccc0bb24e12518044fcddb45c69
2019-03-26 11:47:27 -07:00
Tianjie Xu
8f397309b4 Move librecovery_ui to a sub-directory
This helps to expose librecovery_ui for device specific RecoveryUi.

Bug: 76436783
Test: mma, unit tests pass
Change-Id: Ic6c3d301d5833e4a592e6ea9d9d059bc4e4919be
(cherry picked from commit b5108c372c)
2019-03-21 10:46:11 -07:00
xunchang
5e6832a24d Remove the provider_vtab
It's no longer needed with the newly added FuseDataProvider class. Also
cleans up the parameters for run_fuse_sideload.

Bug: 127071893
Test: unit tests pass, run a sideload
Change-Id: I1ccd6798d187cfc6ac9f559ffb3f3edf08dad55c
2019-03-19 13:03:59 -07:00
xunchang
ea2912f187 Create a FuseDataProvider base class
The fuse data provider for adb/sdcard shares common code and structures.
This cl creates a FuseDataProvider base class and provides
implementations for adb and sdcard.

In the follow cls, we can kill the provider_vtab struct; and also add
another implementation to parse a block map file and provides data.

Test: unit tests pass, sideload a package, apply a package from sdcard
Change-Id: If8311666a52a2e3c0fbae0ee9688fa6d01e4ad09
2019-03-19 11:11:58 -07:00
xunchang
37304f3cc9 Implement FilePackage class
This is another implementation of the Package class. And we will later
need it when reading the package from FUSE.

Bug: 127071893
Test: unit tests pass, sideload a file package on sailfish
Change-Id: I3de5d5ef60b29c8b73517d6de3498459d7d95975
2019-03-14 15:35:09 -07:00
xunchang
aaa6103ae7 Update_verifier: Remove the support for legacy text format CareMap
We have already switched to the protobuf format for new builds, and
the downgrade packages will require a data wipe. So it should be safe
to drop the support for text format.

This also helps to save the issue when users sideload a package with a
pending OTA, because the new CareMap contains the fingerprint of the
intended build.

Bug: 128536706
Test: unit tests pass, run update_verifier with legacy CareMap
Change-Id: I1c4d0e54ec591f16cc0a65dac76767725ff9e7c4
2019-03-13 15:24:13 -07:00
xunchang
55e3d22223 Use the package class for wipe packages
The wipe package used to open the zip file directly from the content
string. Switch to use the interface from the new package class instead.

Bug: 127071893
Test: unit tests pass
Change-Id: I990e7f00c5148710722d17140bab2e343eea3b6b
2019-03-12 15:10:41 -07:00
xunchang
f07ed2efeb Create a wrapper class for update package
Creates a new class handle the package in memory and package read from fd.
Define the new interface functions, and make approximate changes to the
verify and install functions.

Bug: 127071893
Test: unit tests pass, sideload a package
Change-Id: I66ab00654df92471184536fd147b237a86e9c5b5
2019-03-11 10:43:52 -07:00
xunchang
e0d991ceca Add a new entry in wipe package to list all wipe partitions
This gives us finer control over the partitions to wipe on the host
side.

Bug: 127492427
Test: unit tests pass, install a wipe package on sailfish
Change-Id: I612f8bac743a310f28e365b490ef388b278cfccb
2019-03-06 15:37:28 -08:00
xunchang
7b08a5a6eb Recovery test: Fix an parameter issue in string construction
The intended string constructor is supposed be
basic_string(size_type count, CharT ch). But the parameter is
accidentally reversed when calling the constructor in install_test.

Test: A failed unit test pass
Change-Id: Id9765bfa7d2368ff0d7fbeea45c9c8357864e060
2019-02-05 12:44:53 -08:00
Suren Baghdasaryan
0ca607c4cd DO NOT MERGE: Revert "Revert "Add libprocessgroup dependency""
This reverts commit 9ce1d14ef6.

Reason for revert: AOSP is fixed with new vendor image

Change-Id: Ie5a9748acdae22a2b9862cb2ecedda7031f77264
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-25 05:43:59 +00:00
Suren Baghdasaryan
9ce1d14ef6 DO NOT MERGE: Revert "Add libprocessgroup dependency"
This reverts commit 62d0c7873c.

Reason for revert: Broke AOSP

Change-Id: I88ef00ebce797f7fdca3678ab93fcae364453a8c
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-23 20:46:46 -08:00
Suren Baghdasaryan
62d0c7873c Add libprocessgroup dependency
Because set_sched_policy is moved into libprocessgroup an additional
dependency is requred for recovery_component_test to build.

Exempt-From-Owner-Approval: janitorial

Bug: 111307099
Test: builds, boots

Merged-In: I7cf75e473ee1e2837940606c71d15be26db0c3f2
Change-Id: I7cf75e473ee1e2837940606c71d15be26db0c3f2
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-20 22:04:43 +00:00
Yifan Hong
82fc6ae5b8 Merge changes from topic "vintf_object_recovery_mount"
* changes:
  roots.cpp: convert to C++ Fstab
  Move parts of roots.cpp to libfs_mgr
2018-12-19 22:19:52 +00:00
Yifan Hong
0f339e27bb Move parts of roots.cpp to libfs_mgr
Move some mounting functionalities to libfs_mgr.

Test: run recovery tests

Bug: 118634720
Bug: 113182233

Change-Id: Ie59376664a744992429f0262ec96d13a1aed30f9
2018-12-18 15:57:29 -08:00
Tao Bao
f242a7ec2c tests: Temporarily disable ScreenRecoveryUITest tests.
Seems they're racing with SurfaceFlinger in acquiring the display, which
occasionally takes down the device and leads to test failures.

Bug: 120601844
Test: Run recovery_unit_test on marlin. ScreenRecoveryUITest not
      triggered.
Change-Id: I80b21595247a87fc1f2f95aa68df59f58bdf0257
2018-12-06 13:05:05 -08:00
Tao Bao
dd78982d58 minui: GRSurface::Create() computes data_size on its own.
GRSurface::Create() doesn't need to rely on caller specifying the buffer
size, as it can compute that info based on the given args.

This CL also uses `size_t` for all the parameters in
GRSurface::Create().

Test: Run recovery_unit_test on marlin.
Test: Build and boot into blueline recovery. `Run graphics test`.
Test: Build and boot into blueline charger mode.
Change-Id: Idec9381079196abf13553a475006fefcfca10950
2018-11-26 22:46:19 -08:00
Tao Bao
2201d08f8d minui: Fix a wrong arg in calling GRSurface::Create().
This is a bug introduced while refactoring init_display_surface(), in
[1]. As a result, user of res_create_multi_display_surface(), which is
effectively `charger` right now, crashes due to buffer overrun.

This CL fixes the wrong arg and adds a sanity test for
res_create_multi_display_surface(). The testdata (battery_scale.png) is
copied from system/core/healthd/images/battery_scale.png.

[1] commit 44820ac1e3.

Bug: 119122296
Test: Run recovery_unit_test on marlin.
Test: Build and boot into charger mode on blueline. Verify that
      `charger` no longer crashes.
Change-Id: Ib6d083e1512a9c3c6eb63874d26d22658921d693
2018-11-26 17:06:53 -08:00
Treehugger Robot
814c306106 Merge "switch to using android-base/file.h instead of android-base/test_utils.h" 2018-11-15 15:59:45 +00:00
Tianjie Xu
b8564e1093 Adjust the background text image width to reduce its size
We can adjust the image width with respect to the maximum width of the
wrapped text. This will remove some black margins and reduce the final
size of the images, especially for those with short strings, e.g.
"recovery_error".

Also, add an option to centrally align the text; and fix a boundary
check in the recovery resource test.

Bug: 74397117
Test: Generate and check the image
Change-Id: Ib6cf61a9c99c4aeede16751dc0adfa23ce3f5424
2018-11-15 00:33:14 +00:00
Mark Salyzyn
8b54bc5e04 switch to using android-base/file.h instead of android-base/test_utils.h
Test: compile
Bug: 119313545
Change-Id: I664fb32522d01909c603d7b903475c4e9aea9223
2018-11-14 15:49:19 -08:00
Pirama Arumuga Nainar
b3339ddc6b Use the non-LTO/PGO hwbinder in recovery_component_test
Bug: http://b/119560349
Bug: http://b/112277682

Currently, any binary links in a PGO-enabled static library also needs
to opt into PGO.  With b/119560349, this should be done automatically by
the build system.  Until then, use the non-PGO version of libhwbinder in
recovery_component_test.

Test: m ANDROID_PGO_INSTRUMENT=all
Change-Id: Ic6e44c1cb6d6f13e60e11a46fd7e5ef54238942b
2018-11-14 11:42:23 -08:00
Tao Bao
3cb3c524f6 tests: Add a testcase for updater overrun while patching.
For any patching command, the resulting data should always exactly fill
up the given target range.

Test: Run recovery_component_test on marlin.
Change-Id: Ib3cc1fc5c11094e2eab3fe370753db51c7c4135c
2018-11-05 20:47:53 -08:00
Treehugger Robot
06aea3a894 Merge "ui: Manage loaded resources with smart pointers." 2018-11-06 01:37:37 +00:00
Tao Bao
a0404ecd16 Merge "updater: Error out on underrun during patching." 2018-11-05 21:17:25 +00:00
Tao Bao
da409fb8d6 ui: Manage loaded resources with smart pointers.
Test: Run recovery_unit_test on marlin.
Test: `Run graphics test` on marlin.
Change-Id: I8239c3d9fb288f80ee11f615402768ff8ef8ecd0
2018-11-05 10:15:59 -08:00
Tao Bao
81ef508bd8 tests: Remove obsolete testdata files.
testdata/jarsigned.zip and testdata/unsigned.zip became dead since
commit 432918603f ("Refactor existing
tests to use gtest").

testdata/patch.bsdiff became dead when applypatch/applypatch.sh was
deleted (commit c3ef089dfa).

Test: Run recovery_unit_test and recovery_component_test.
Change-Id: Ie1a7f8850878593fcb7d4554759a539271ffb207
2018-11-05 09:10:11 -08:00
Tao Bao
a2cff952cf updater: Error out on underrun during patching.
Test: Run recovery_component_test on marlin.
Change-Id: If23baf42aeacb48500edabc2eadd2e7119a848da
2018-11-05 08:55:11 -08:00
Tao Bao
63b59dcead minui: Add GRSurface::Clone().
Clone() allows duplicating the image that's stored in the GRSurface.

Test: Run recovery_unit_test.
Change-Id: Ia50d507c6200f2de5f17143775de805247a60e1f
2018-11-01 12:14:46 -07:00
Tianjie Xu
cbdcfc0038 Merge "Refactor the code to check the metadata" 2018-11-01 17:38:18 +00:00
Tao Bao
929e481e71 tests: Use FRIEND_TEST in ScreenRecoveryUITest.
Test: Run recovery_unit_test on marlin.
Change-Id: I93ec6df8c056b2c485200822f18db0b852595242
2018-10-31 23:09:49 -07:00
Tao Bao
44820ac1e3 minui: Add a protected GRSurface ctor.
This prepares for the removal of the default and copy ctors, by making
GRSurface::Create() as the only way to get GRSurface instances.

Test: mmma -j bootable/recovery
Test: Run recovery_unit_test on marlin.
Change-Id: I0c34c3f3967e252deb020907c83acbac8a8f36b9
2018-10-31 11:19:28 -07:00
Tianjie Xu
93b5bf261c Refactor the code to check the metadata
The two functions check_wipe_package() and check_newer_ab_build() were
using the same flow; and checked the same device properties against the
metadata file in the package. These properties include: ota_type,
pre-device, and serial number.

Therefore, we can consolidate the checks to a single function; and
continue to check the fingerprint and timestamp only for AB updates.

This change also addresses the need to accept multiple serial number in
the wipe package.

Bug: 118401208
Test: unit tests pass
Change-Id: Ia6bc48fb6effcae059a2ff2cf71764b4136b4c00
2018-10-31 11:03:58 -07:00
Tianjie Xu
f2fb49a3c4 Clean up the zipfile creation in InstallTest
Consolidate them into a static function.

Test: unit tests pass
Change-Id: If05b62215940b221fc499d779eedc5079f68a060
2018-10-29 12:04:13 -07:00
Tianjie Xu
64ceace44f Merge "Remove the load_keys function" 2018-10-25 17:25:49 +00:00
Tianjie Xu
6793f61795 Merge "Add sanity check when loading public keys for OTA package" 2018-10-25 04:03:23 +00:00
Tianjie Xu
cbe93e6506 Remove the load_keys function
This function is used to parse the result of dumpKeys. It's no longer
needed as we are now parsing the public keys from the zipfile.

Bug: 116655889
Test: unit tests pass
Change-Id: I817906e451664058c644f4329ff499bbe4587ebb
2018-10-24 23:26:59 +00:00
Tianjie Xu
b5110de1b3 Add sanity check when loading public keys for OTA package
For RSA keys, check if it has a 2048 bits modulus, and its public
exponent is 3 or 65537. For EC keys, check if the field size is 256
bits for its curve.

Bug: 116655889
Test: unit tests pass
Change-Id: I5c00f4d2b61c98c434f0b49db232155d5d0770ec
2018-10-24 16:25:09 -07:00
Treehugger Robot
47b650b588 Merge "ui: Add constness to Draw- functions." 2018-10-24 00:28:21 +00:00
Tianjie Xu
1e10cc4297 Add a function to construct the GRSurface in test
This fixes the build error as the initializer list no longer work
without the proper constructor for c++ class.

Bug: 74397117
Test: unit tests pass
Change-Id: If3ff508a1a01ad5326413dab8e05bacae8a946c8
2018-10-23 12:10:46 -07:00
Tianjie Xu
06ccd00ef5 Merge "Add function to show localized rescue party menu" 2018-10-23 18:16:23 +00:00
Tao Bao
65815b6d3a ui: Add constness to Draw- functions.
These functions take the given GRSurface instances as inputs, which
shouldn't be altered.

Test: mmma -j bootable/recovery
Test: Run recovery_unit_test.
Test: `Run graphics test` on marlin.
Change-Id: I51bf408e85faae2b497d4f148ab1dec22dd16c93
2018-10-23 10:56:54 -07:00
Tao Bao
92bdb5a389 minui: Move GRSurface into a class.
This CL adds GRSurface::Create() and dtor for managing the allocated
memory in GRSurface class. It also adds GRSurface::data() that hides the
underlying implementation, with both of const and non-const overloads.
This allows `const GRSurface&` to be more useful - previously it only
ensured a const member variable of `data`, instead of a read-only buffer
it points to.

It also marks the parameters in gr_texticon() and gr_blit() as const, as
they're incoming source that shouldn't be altered. It corrects the type
of gr_draw, which is the sink to be painted on (an earlier attempt was
made in [1], but didn't get the full picture correctly).

[1] https://android-review.googlesource.com/c/platform/bootable/recovery/+/704757/

Test: mmma -j bootable/recovery
Test: recovery_unit_test on marlin
Test: Run graphics test on marlin (fbdev).
Test: Run graphics test on blueline (drm).
Change-Id: I7904df084cd6c08fa04a9da97d01b4b1a6e3a20c
2018-10-22 18:18:02 -07:00
Tianjie Xu
b99e6069c1 Add function to show localized rescue party menu
Add a function in screenUI to display the pre-generated graphs for
rescue party. If these graphs are not valid, falls back to display
the old text strings.

Right now we haven't generated the localized graphs yet, so the UI
always shows the TextMenu.

Bug: 116655889
Test: check rescue party under recovery
Change-Id: I0558cb536b659cdc25c8b7946d3a39820935b003
2018-10-22 15:27:33 -07:00
Tianjie Xu
0dd9685311 Load X509 keys from ziparchive
Add a function to parse the zip archive and load the certificate from
all the zip entries with the suffix "x509.pem".

Bug: 116655889
Test: unittests pass
Change-Id: I93bf7aef7462c0623e89fc2d466d7af2d3a758bc
2018-10-18 11:42:01 -07:00
Tianjie Xu
66dbf63080 Implement the graphic menus
As we plan to show localized rescue party dialogs under recovery mode
with pre-generated images, it becomes necessary to show the menu headers
and items with images.

This cl converts the menu class to a interface and derived TextMenu &
GraphicMenu classes. And the GraphicMenu uses GRSurfaces* as the menu header
and a list of GRSurfaces* as menu items.

Moreover, factor out the Draw* functions in the ScreenUI into a separate
DrawInterface. Therefore, the Menu class can access these draw functions and
use them to implement the DrawHeaders & DrawItems neatly.

Bug: 74397117
Test: unittests pass, boot into recovery and check menu
Change-Id: I95cee30f3e5eb666eb6fbcdfc873a7260fc177c1
2018-10-12 17:18:50 -07:00