Commit graph

303 commits

Author SHA1 Message Date
Tao Bao
189c8f9aeb Merge "Consolidate the codes that handle reboot/shutdown." 2019-04-29 21:53:41 +00:00
Tao Bao
782dcc1996 Consolidate the codes that handle reboot/shutdown.
Test: Choose `Reboot system now`, `Power off`, `Reboot to bootloader`
      from recovery UI respectively.
Test: `adb reboot recovery` while under sideload mode.
Change-Id: I0f3d55b80b472178ea4f6970b29cd9df0778b639
2019-04-29 12:12:25 -07:00
Tao Bao
40ccbe3324 Merge "Add install/wipe_device.cpp." 2019-04-29 18:46:53 +00:00
Tao Bao
7f19d100b5 Add install/wipe_device.cpp.
Prior to this CL, GetWipePartitionList was declared in install.h
(libinstall) but defined in recovery.cpp (librecovery). This CL
addresses the issue by refactoring wipe-device related functions into
install/wipe_device.cpp.

Test: atest recovery_component_test
Change-Id: I7ebe04ccfda3d793e085403560a0a202752d9ee3
2019-04-26 23:23:19 -07:00
xunchang
fedeef6f6d Support wipe command in rescue mode
Bug: 131037235
Test: unit tests pass, run `adb rescue wipe`
Change-Id: I22668f2c98fe2d9195d2561f961c28a7c08e712c
2019-04-26 10:36:48 -07:00
Tao Bao
d9cb014d43 Parse BCB command to enter rescue mode.
bootloader will set `boot-rescue` in BCB command field to indicate
booting into rescue mode. This CL adds the matching parsing code.

This CL changes the on-screen UI to display the default image while
waiting for each sideload / rescue command.

It also changes the minadbd reboot handlers to use REBOOT_ instead of
the previous ENTER_ actions. This ensures a reboot going through
bootloader, which may load a newly installed bootloader/recovery.

Bug: 128505466
Test: Boot into rescue mode. Run `adb rescue getprop` and `adb rescue
      install`. Check the UI. Then run `adb reboot rescue`.
Change-Id: I5b7de9dfd898ed8e14bea0d4ad7385a9bae26e94
2019-04-25 14:02:41 -07:00
Tao Bao
10f441a9db minadbd: Support adb reboot under sideload/rescue modes.
Bug: 128415917
Test: Run the following commands under sideload and rescue modes
      respectively.
$ adb reboot
$ adb reboot bootloader
$ adb reboot recovery
$ adb reboot rescue
$ adb reboot invalid
Change-Id: I84daf63e3360b7b4a0af5e055149a4f54e10ba90
2019-04-23 23:50:12 -07:00
Tao Bao
c6dc325e88 Allow entering rescue mode via recovery UI.
Only enabled on debuggable builds.

Bug: 128415917
Test: Sideload package on taimen.
Test: Choose "Enter rescue" from recovery UI.
Change-Id: I913dbdbcffd3179e6fa72ca862f74ca8f1364b02
2019-04-17 14:07:23 -07:00
xunchang
316e971746 Move wipe cache|data to libinstall
Therefore, libinstall becomes the sole owner to handle the request
from minadbd service.

The change also includes
1. move logging.cpp out of librecovery
2. drop the dependency on common.h
3. now it's more sensible to move the wipe_cache as part of
install_package. move the wipe_cache to the end of the function.

Bug: 130166585
Test: wipe data and cache from menu
Change-Id: I6f356dccdb38015c50acf756bac246f87c30fc1f
2019-04-15 12:22:11 -07:00
Tao Bao
e0cfab3de9 recovery: Remove SetUsbConfig() out of common.h.
libinstall now has its own copy.

Test: mmma -j bootable/recovery
Change-Id: Ibbe7084e15baeb7e744f2175d5944477092acc9e
2019-03-29 15:54:02 -07:00
Tao Bao
bc982a4f88 Remove ui_print().
This used to be a helper function that allows printing message to UI.
We no longer have any active user in bootable/recovery. Device-specific
code can achieve the same functionality by calling GetUI()->Print()
instead.

Test: mmma -j bootable/recovery
Change-Id: If584fc8a51d1af466f1d94d8ea5faa262603a784
2019-03-29 15:50:02 -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
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
3cc23d5eac Move apply_from_sdcard to fuse_sdcard_install
Move the sdcard installation function and all helper functions to a
separate file, and drop the dependency on common.h.

In the future, we want to move these functions into the install class.

Bug: 127071893
Test: unit tests pass
Change-Id: I0b7f7cbf0b68918e638e13878ca28bfca367088a
2019-03-19 23:05:13 -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
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
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
d81b8e3d77 roots.cpp: convert to C++ Fstab
Convert code to use C++ Fstab struct and C++ std::strings.

Bug: 62292478
Bug: 118634720
Test: boots
Change-Id: Ibdc1df5831bc885d7c1574419f41af026e49a137
2018-12-18 15:57:29 -08:00
Tianjie Xu
1a0a30a16a Show wipe data confirmation text in recovery mode
After we generate the localized confirmation text images for certain dpi,
we can now load these images and display them under recovery. Devices that
cannot load the images will use the backup text strings as before.

Bug: 74397117
Test: check the menu with multiple locales, and check all the images locally
with locale test, check the fall back strings.
Change-Id: Ic31a55670026c909ec7a05cb0bb4a0fc1d5d15c7
2018-12-11 23:23:41 +00:00
Yifan Hong
4932780606 SYSTEM_ROOT -> get_system_root
Add a get_system_root() function in roots.cpp
which returns / or /system based on fstab.
This factors out the 'if' check from recovery.cpp
and fsck_unshare_blocks.cpp.

Test: boot recovery, mount system
Bug: 118634720
Change-Id: If4947cba3a3f08dbe695fd2b50a9354cd302ee03
2018-11-27 15:57:47 -08: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
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
Mark Salyzyn
fdea242a91 recovery: deprecate check for ro.build.system_root_image
If there is a "/system" in the fstab, then can not be a
system as root image.

Test: compile
Bug: 109821005
Change-Id: I2c852dcbdcf6de437d39039937799feeef949516
2018-10-11 09:04:56 -07:00
Tao Bao
a5bbcb9596 Trigger the logging when prompting for wipe.
This allows recording the reason string that prompts user for a data
wipe, even if user selects 'Try again'.

Test: Inject an error into framework to trigger RescueParty. Select
      'Try again' and check the recovery log post-boot.
Change-Id: I0d7d5afcf38cae5019e2ce0a46d3cd1ac3e83a03
2018-09-17 14:37:27 -07:00
Treehugger Robot
16147d1bd6 Merge "Allow switch to fastbootd when userdata wipe is required" 2018-09-13 00:48:42 +00:00
Hridya Valsaraju
eb6f13aeb6 Allow switch to fastbootd when userdata wipe is required
Bug: 114065789
Test: Able to use 'adb reboot fastboot' to switch to fastboot
from recovery when a userdata wipe is required to boot.

Change-Id: Ice6950444656f8d8857808531af030078f544b88
2018-09-12 14:16:07 -07:00
Hridya Valsaraju
e4ef453914 Fix sideload for user devices by adding a new sideload config
Bug: 113563995
Test: Tested the 'adb sideload' command on marlin user/userdebug builds
and walleye user/userdebug builds

Change-Id: I00d565547b85f2db87012e4a08316609e03395ac
2018-09-07 15:02:43 -07:00
Treehugger Robot
19a5316412 Merge "Add fastboot mode to recovery" 2018-08-14 21:25:50 +00:00
Hridya Valsaraju
20c81b308d Add fastboot mode to recovery
Add a fastboot mode to recovery that can be
entered with command line args or with the ui.

Add usb property triggers to switch between
fastboot and adb configurations.

Allow switching between fastboot and adb through
usb commands by opening a unix socket. adbd/fastbootd
writes to this socket, which interrupts the ui and
switches to the new mode.

Test: Use fastboot mode
Bug: 78793464
Change-Id: I7891bb84427ec734a21a872036629b95ab3fb13c
2018-08-13 21:18:18 -07:00
Yifan Hong
056538c0a9 recovery uses IHealth::getService
recovery is_battery_ok function uses get_health_service(),
which calls IHealth::getService("default") then
IHealth::getService("backup").

- An OEM can provide the default instance by installing
  android.hardware.health@2.0-impl-<device>.so to recovery
  partition.

- If that's not found, the "backup" instance is provided
  to the recovery partition by default.

Test: call is_battery_ok() in recovery, successfully
  get battery information.

Bug: 80132328

Change-Id: Ibfee80636325a07bc20b24d044d007a60b3dd7c2
2018-08-13 16:16:18 -07:00
Jerry Zhang
3528139409 Merge "recovery: Add ability to interrupt UI"
am: 561ee9362c

Change-Id: Ic33767a7ebaac6c066c0552b502a361b5c498b9e
2018-07-30 16:16:26 -07:00
Jerry Zhang
b76af93ab5 recovery: Add ability to interrupt UI
Normally calling a UI method will block
indefinitely until the UI is actually
used. This creates a method to interrupt
the UI, causing waitKey to return -2. This
in turn, will cause ShowMenu to return -2.
This allows switching between recovery and
fastbootd via usb commands.

Test: adb shell /data/nativetest64/recovery_unit_test/recovery_unit_test
Bug: 78793464
Change-Id: I4c6c9aa18d79070877841a5c9818acf723fa6096
2018-07-30 20:17:27 +00:00
Tao Bao
2f9d61ad25 Merge "Fix the arguments passed to getopt_long(3)."
am: 29932e7bcc

Change-Id: I985c5598ad9d9e4222849aff6177fa7e4f0e8820
2018-07-17 14:57:38 -07:00
Tao Bao
1700cc46b5 Fix the arguments passed to getopt_long(3).
The getopt_long(3) implementation in Android (upstream freebsd) expects
a null-terminated array while parsing long options with required args.

  if (long_options[match].has_arg == required_argument) {
    optarg = nargv[optind++];
  }
  ...
  if (long_options[match].has_arg == required_argument && optarg == NULL) {
    return (BADARG);
  }

This seems to make sense in practice, as getopt(3) takes the first two
arguments of argc and argv that are "as passed to the main() function on
program invocation", and both of C and C++ spec say "the value of
argv[argc] shall be 0".

Prior to the CL, we may run into undefined behavior on malformed input
command line (e.g. missing arg for an option that requires one). This CL
fixes the issue by always appending a nullptr to the argument list (but
without counting that into argc).

Test: Build and boot into recovery with commands.
Change-Id: Ic6c37548f4db2f30aeabd40f387ca916eeca5392
2018-07-17 12:16:53 -07:00
Jiyong Park
93ea306913 Merge "Recovery image is self-contained"
am: 397e8f2279

Change-Id: Ieb43e946cb694635b3b4aad91e7874f87ae39b47
2018-06-13 16:40:33 -07:00
Jiyong Park
8b7af4c0ee Recovery image is self-contained
Now recovery mode is self-contained, which means we don't need to mount
system.img to run shell, etc. What is needed in recovery mode is all in
the recovery ramdisk image.

Since we no longer use /system as the mount point for the system.img,
this allows us to have identical filesystem layout as the system.img.
Executables and libs are installed to /system/bin and /system/lib.
Right now, we only have adbd, sh, toybox in /system/bin but will move
static executables from /sbin to /system/bin as soon as they are
converted to dynamic executables.

system.img is mounted to /mnt/system instead.

Bug: 63673171
Test: `adb reboot recovery; adb devices` shows the device ID
Test: `adb root && adb shell` and then
$ lsof -p `pidof adbd` shows that libm.so, libc.so, etc. are loaded from
the /lib directory.

Change-Id: I801ebd18f3e0a112db3d9a11e4fbb4e49181652a
2018-06-07 23:24:33 +09:00
David Anderson
5a78f3984f Merge "recovery: add --fsck_unshare_blocks option for adb remount" am: bda4495176
am: b0d9b3594b

Change-Id: I86d3af476e87184e653de38cdb4faa1c9975ccba
2018-05-31 18:11:40 -07:00
David Anderson
edee8361d7 recovery: add --fsck_unshare_blocks option for adb remount
Allow "adb remount" on deduplicated filesystems to reboot into recovery
and run e2fsck to undo deduplication. The e2fsck binary is copied from
the system partition into tmpfs, and the system partition is unmounted
so e2fsck can run safely.

Bug: 64109868
Test: recovery with --fsck_unshare_blocks; adb remount
Change-Id: I7558749b018b58f3c4339e51a95831dbd5be1ae3
2018-05-30 13:24:30 -07:00
Jerry Zhang
ebc910901c Merge "recovery: Add ability to set title lines" am: cba047f944
am: 6283f64568

Change-Id: I9c40c26a28de5d45b4651bd5cd5d36d57ff9d9fb
2018-05-21 17:05:28 -07:00
Jerry Zhang
0e577ee424 recovery: Add ability to set title lines
Add the ability to change the contents of
the title lines, displayed at the top of
the screen. Once set, the same lines are
displayed for all menus until changed again.

Test: Recovery works
Bug: 78793464
Change-Id: I7ef5594b0d76dbbd2e01ad7508863af1270b2a2a
2018-05-21 16:37:07 -07:00
Jerry Zhang
901fb2c811 Merge "recovery: Reset optind to 1 after getopt" am: 38d90316b2
am: 25d31c9f9c

Change-Id: Id2d80584075c3482748e5946d39fe8ef572aea45
2018-05-17 14:48:15 -07:00
Jerry Zhang
49fd5d262c recovery: Reset optind to 1 after getopt
The getopt library exposes optind which is the
next index to be processed. When scanning is
restarted, optind has to be reset to 1.

Test: Recovery works
Bug: 78793464
Change-Id: I1efca3fb985ffbdfe91e43767469733cda6e7d5b
2018-05-17 19:56:42 +00:00
Jerry Zhang
f5e319ac96 recovery: Refactor common setup into main()
Move more common setup into the main function.
Main() handles all 1 time setup, such as ui,
logging, and secontext. Recovery_main()
takes in command line arguments, does any
necessary recovery work, and can be called
multiple times from main().

Test: Recovery works
Bug: 78793464
Change-Id: I2d2595fc342b4ddfa80f4e06b30e44263132acd9
Merged-In: I2d2595fc342b4ddfa80f4e06b30e44263132acd9
2018-05-16 19:32:06 +00:00
Jerry Zhang
6a64804965 recovery: Refactor common setup into main()
Move more common setup into the main function.
Main() handles all 1 time setup, such as ui,
logging, and secontext. Recovery_main()
takes in command line arguments, does any
necessary recovery work, and can be called
multiple times from main().

Test: Recovery works
Bug: 78793464
Change-Id: I2d2595fc342b4ddfa80f4e06b30e44263132acd9
2018-05-16 00:20:45 +00:00
Tao Bao
20976a0913 Merge "recovery: Configure device menu based on runtime info." am: e498ef2f03
am: bd32e1b50b

Change-Id: Id611c10a6f84afdec38ca01d6932f4c964f9c2ac
2018-05-11 10:57:40 -07:00
Tao Bao
e5d2c25ecf recovery: Configure device menu based on runtime info.
Drop the dependency on build time flag of AB_OTA_UPDATER when compiling
device.cpp. Note that AB_OTA_UPDATER still guards the package install
behavior (install.cpp).

This can be extended to cover the entry of "Apply update from SD card".

Test: Build and boot into recovery on angler and walleye respectively.
      Check the recovery menu.
Change-Id: I36a6a6b4101ba61d4d374e32353c36cc5716f9ce
2018-05-10 20:46:46 -07:00
Tao Bao
4fd58ca28a Merge "Device owns the RecoveryUI instance." am: 6df846e337
am: 8d593973d6

Change-Id: I006ae17453913b7e9cd23bafc30862f1532e1f60
2018-05-10 17:20:02 -07:00
Tao Bao
551d2c3181 Device owns the RecoveryUI instance.
Test: mmma -j bootable/recovery
Test: Build and boot into recovery, w/ and w/o enabling quiescent mode
      respectively.
Change-Id: I5d9bb945a6c3c9a3b96199fa0c8071a2f91339a0
2018-05-09 21:22:26 -07:00