AOSP10 TWRP Merge: fix conflicts and update libraries needed
This allows flame to boot TWRP. Still will need to work on
super partition for vendor and system access.
The plan will be to cherry-pick any updates to android-9.0
through gerrit.twrp.me to this branch as a WIP.
diff --git a/.gitignore b/.gitignore
index e03babb..480f547 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
.*.swp
*~
tags
+.vscode
diff --git a/Android.bp b/Android.bp
old mode 100644
new mode 100755
index c98d194..c9f92b6
--- a/Android.bp
+++ b/Android.bp
@@ -1,4 +1,3 @@
-<<<<<<< HEAD
subdirs = [
// "applypatch",
"bootloader_message",
@@ -7,199 +6,15 @@
// "otautil",
// "uncrypt",
]
-=======
-// Copyright (C) 2018 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
cc_defaults {
name: "recovery_defaults",
-
cflags: [
"-D_FILE_OFFSET_BITS=64",
-
// Must be the same as RECOVERY_API_VERSION.
"-DRECOVERY_API_VERSION=3",
-
"-Wall",
"-Werror",
],
+ cpp_std: "c++17",
}
-
-cc_library_static {
- name: "librecovery_fastboot",
- recovery_available: true,
- defaults: [
- "recovery_defaults",
- ],
-
- srcs: [
- "fastboot/fastboot.cpp",
- ],
-
- shared_libs: [
- "libbase",
- "libbootloader_message",
- "libcutils",
- "liblog",
- "librecovery_ui",
- ],
-
- static_libs: [
- "librecovery_ui_default",
- ],
-}
-
-cc_defaults {
- name: "librecovery_defaults",
-
- defaults: [
- "recovery_defaults",
- ],
-
- shared_libs: [
- "android.hardware.health@2.0",
- "libbase",
- "libbootloader_message",
- "libcrypto",
- "libcutils",
- "libfs_mgr",
- "liblog",
- "libziparchive",
- ],
-
- static_libs: [
- "libinstall",
- "librecovery_fastboot",
- "libminui",
- "libotautil",
-
- // external dependencies
- "libhealthhalutils",
- "libfstab",
- ],
-}
-
-cc_library_static {
- name: "librecovery",
- recovery_available: true,
-
- defaults: [
- "librecovery_defaults",
- ],
-
- srcs: [
- "fsck_unshare_blocks.cpp",
- "recovery.cpp",
- ],
-
- shared_libs: [
- "librecovery_ui",
- ],
-}
-
-cc_binary {
- name: "recovery",
- recovery: true,
-
- defaults: [
- "libinstall_defaults",
- "librecovery_defaults",
- ],
-
- srcs: [
- "recovery_main.cpp",
- ],
-
- shared_libs: [
- "librecovery_ui",
- ],
-
- static_libs: [
- "librecovery",
- "librecovery_ui_default",
- ],
-
- required: [
- "e2fsdroid.recovery",
- "librecovery_ui_ext",
- "minadbd",
- "mke2fs.conf.recovery",
- "mke2fs.recovery",
- "recovery_deps",
- ],
-}
-
-// The dynamic executable that runs after /data mounts.
-cc_binary {
- name: "recovery-persist",
-
- defaults: [
- "recovery_defaults",
- ],
-
- srcs: [
- "recovery-persist.cpp",
- ],
-
- shared_libs: [
- "libbase",
- "liblog",
- "libmetricslogger",
- ],
-
- static_libs: [
- "libotautil",
- "libfstab",
- ],
-
- init_rc: [
- "recovery-persist.rc",
- ],
-}
-
-// The dynamic executable that runs at init.
-cc_binary {
- name: "recovery-refresh",
-
- defaults: [
- "recovery_defaults",
- ],
-
- srcs: [
- "recovery-refresh.cpp",
- ],
-
- shared_libs: [
- "libbase",
- "liblog",
- ],
-
- static_libs: [
- "libotautil",
- "libfstab",
- ],
-
- init_rc: [
- "recovery-refresh.rc",
- ],
-}
-
-filegroup {
- name: "res-testdata",
-
- srcs: [
- "res-*/images/*_text.png",
- ],
-}
->>>>>>> android-10.0.0_r25
diff --git a/Android.mk b/Android.mk
index 4e7d7cc..30d5981 100755
--- a/Android.mk
+++ b/Android.mk
@@ -15,7 +15,6 @@
LOCAL_PATH := $(call my-dir)
commands_TWRP_local_path := $(LOCAL_PATH)
-<<<<<<< HEAD
ifneq ($(project-path-for),)
ifeq ($(LOCAL_PATH),$(call project-path-for,recovery))
PROJECT_PATH_AGREES := true
@@ -123,13 +122,25 @@
system/core/adb \
system/core/libsparse \
external/zlib \
- $(LOCAL_PATH)/bootloader_message_twrp/include
+ system/core/libpixelflinger/include \
+ external/freetype/include \
+ $(LOCAL_PATH)/bootloader_message_twrp/include \
+ $(LOCAL_PATH)/recovery_ui/include \
+ $(LOCAL_PATH)/otautil/include \
+ $(LOCAL_PATH)/install/include
LOCAL_C_INCLUDES += bionic
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
LOCAL_C_INCLUDES += external/stlport/stlport external/openssl/include
LOCAL_CFLAGS += -DUSE_FUSE_SIDELOAD22
else
+ ifeq ($shell test $(PLATFORM_SDK_VERSION) -lt 29; echo $$?),0)
+ LOCAL_C_INCLUDES += $(LOCAL_PATH)/fuse_sideload28/
+ else
+ LOCAL_C_FLAGS += -DUSE_OLD_LOAD_KEYS
+ LOCAL_C_INCLUDES += $(LOCAL_PATH)/fuse_sideload/include \
+ $(LOCAL_PATH)/install/include
+ endif
LOCAL_C_INCLUDES += external/boringssl/include external/libcxx/include
endif
@@ -137,8 +148,8 @@
LOCAL_SHARED_LIBRARIES :=
LOCAL_STATIC_LIBRARIES += libguitwrp
-LOCAL_SHARED_LIBRARIES += libaosprecovery libz libc libcutils libstdc++ libtar libblkid libminuitwrp libminadbd libmtdutils libtwadbbu libbootloader_message_twrp
-LOCAL_SHARED_LIBRARIES += libcrecovery libtwadbbu libtwrpdigest libc++
+LOCAL_SHARED_LIBRARIES += libz libc libcutils libstdc++ libtar libblkid libminuitwrp libminadbd libmtdutils libtwadbbu libbootloader_message_twrp
+LOCAL_SHARED_LIBRARIES += libcrecovery libtwadbbu libtwrpdigest libc++ libaosprecovery
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
LOCAL_SHARED_LIBRARIES += libstlport
@@ -149,6 +160,12 @@
LOCAL_C_INCLUDES += $(LOCAL_PATH)/libmincrypt/includes
LOCAL_CFLAGS += -DUSE_OLD_VERIFIER
else
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -le 29; echo $$?),0)
+ LOCAL_C_INCLUDES += $(LOCAL_PATH)/verifier28/
+ LOCAL_CFLAGS += -DUSE_28_VERIFIER
+ else
+ LOCAL_C_INCLUDES += $(LOCAL_PATH)/install/include
+ endif
LOCAL_SHARED_LIBRARIES += libcrypto
endif
@@ -157,8 +174,14 @@
endif
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 26; echo $$?),0)
- LOCAL_SHARED_LIBRARIES += libziparchive
- LOCAL_C_INCLUDES += $(LOCAL_PATH)/otautil/include
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 29; echo $$?),0)
+ LOCAL_SHARED_LIBRARIES += libziparchive
+ LOCAL_C_INCLUDES += $(LOCAL_PATH)/otautil/include system/core/libziparchive/include
+ else
+ LOCAL_SHARED_LIBRARIES += libziparchive
+ LOCAL_C_INCLUDES += system/core/libziparchive/include
+ LOCAL_C_FLAGS += -DUSE_
+ endif
else
LOCAL_SHARED_LIBRARIES += libminzip
LOCAL_CFLAGS += -DUSE_MINZIP
@@ -212,34 +235,9 @@
tw_git_revision := $(shell git -C $(LOCAL_PATH) rev-parse --short=8 HEAD 2>/dev/null)
ifeq ($(shell git -C $(LOCAL_PATH) diff --quiet; echo $$?),1)
tw_git_revision := $(tw_git_revision)-dirty
-=======
-# Needed by build/make/core/Makefile. Must be consistent with the value in Android.bp.
-RECOVERY_API_VERSION := 3
-RECOVERY_FSTAB_VERSION := 2
-
-# TARGET_RECOVERY_UI_LIB should be one of librecovery_ui_{default,wear,vr} or a device-specific
-# module that defines make_device() and the exact RecoveryUI class for the target. It defaults to
-# librecovery_ui_default, which uses ScreenRecoveryUI.
-TARGET_RECOVERY_UI_LIB ?= librecovery_ui_default
-
-# librecovery_ui_ext (shared library)
-# ===================================
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := librecovery_ui_ext
-
-# LOCAL_MODULE_PATH for shared libraries is unsupported in multiarch builds.
-LOCAL_MULTILIB := first
-
-ifeq ($(TARGET_IS_64_BIT),true)
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/lib64
-else
-LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/lib
->>>>>>> android-10.0.0_r25
endif
LOCAL_CFLAGS += -DTW_GIT_REVISION='"$(tw_git_revision)"'
-<<<<<<< HEAD
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 28; echo $$?),0)
ifeq ($(TW_EXCLUDE_MTP),)
LOCAL_SHARED_LIBRARIES += libtwrpmtp-ffs
@@ -425,13 +423,14 @@
LOCAL_CFLAGS += -DTW_CLOCK_OFFSET=$(TW_CLOCK_OFFSET)
endif
TWRP_REQUIRED_MODULES += \
+ relink \
+ relink_init \
dump_image \
erase_image \
flash_image \
mke2fs.conf \
pigz \
teamwin \
- toolbox_symlinks \
twrp \
fsck.fat \
fatlabel \
@@ -537,16 +536,30 @@
mkfs.f2fs
endif
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 28; echo $$?),0)
- TWRP_REQUIRED_MODULES += sload.f2fs
+ TWRP_REQUIRED_MODULES += sload.f2fs \
+ libfs_mgr \
+ fs_mgr \
+ libinit
endif
endif
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 26; echo $$?),0)
TWRP_REQUIRED_MODULES += ld.config.txt
- TWRP_REQUIRED_MODULES += init.recovery.ldconfig.rc
- LOCAL_POST_INSTALL_CMD += \
- sed 's/\(namespace.default.search.paths\)\s\{1,\}=/namespace.default.search.paths = \/sbin\n\1 +=/' \
- $(TARGET_OUT_ETC)/ld.config*.txt > $(TARGET_RECOVERY_ROOT_OUT)/sbin/ld.config.txt;
+ ifeq ($(BOARD_VNDK_RUNTIME_DISABLE),true)
+ LOCAL_POST_INSTALL_CMD += \
+ sed 's/\(namespace.default.search.paths\)\s\{1,\}=/namespace.default.search.paths = \/sbin\n\1 +=/' \
+ $(TARGET_OUT_ETC)/ld.config.vndk_lite.txt > $(TARGET_RECOVERY_ROOT_OUT)/sbin/ld.config.txt;
+ else
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 28; echo $$?),0)
+ LOCAL_POST_INSTALL_CMD += \
+ sed 's/\(namespace.default.search.paths\)\s\{1,\}=/namespace.default.search.paths = \/sbin\n\1 +=/' \
+ $(TARGET_RECOVERY_ROOT_OUT)/system/etc/ld.config.txt > $(TARGET_RECOVERY_ROOT_OUT)/sbin/ld.config.txt;
+ else
+ LOCAL_POST_INSTALL_CMD += \
+ sed 's/\(namespace.default.search.paths\)\s\{1,\}=/namespace.default.search.paths = \/sbin\n\1 +=/' \
+ $(TARGET_OUT_ETC)/ld.config.txt > $(TARGET_RECOVERY_ROOT_OUT)/sbin/ld.config.txt;
+ endif
+ endif
endif
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 25; echo $$?),0)
@@ -580,7 +593,7 @@
LOCAL_POST_INSTALL_CMD := \
$(hide) cp -f $(PRODUCT_OUT)/obj/ETC/file_contexts.bin_intermediates/file_contexts.concat.tmp $(TARGET_RECOVERY_ROOT_OUT)/file_contexts
-include $(BUILD_PHONY_PACKAGE)
+#include $(BUILD_PHONY_PACKAGE)
ifneq ($(TW_USE_TOOLBOX), true)
include $(CLEAR_VARS)
@@ -620,7 +633,7 @@
ifneq (,$(filter $(PLATFORM_SDK_VERSION),16 17 18))
ALL_DEFAULT_INSTALLED_MODULES += $(RECOVERY_BUSYBOX_SYMLINKS)
endif
-include $(BUILD_PHONY_PACKAGE)
+#include $(BUILD_PHONY_PACKAGE)
RECOVERY_BUSYBOX_SYMLINKS :=
endif # !TW_USE_TOOLBOX
@@ -629,10 +642,15 @@
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 24; echo $$?),0)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
- recovery-persist.cpp \
- rotate_logs.cpp
+ recovery-persist.cpp
LOCAL_MODULE := recovery-persist
- LOCAL_SHARED_LIBRARIES := liblog libbase
+ LOCAL_SHARED_LIBRARIES := liblog libbase libmetricslogger
+ LOCAL_STATIC_LIBRARIES := libotautil
+ LOCAL_C_INCLUDES += $(LOCAL_PATH)/otautil/include
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 29; echo $$?),0)
+ LOCAL_C_INCLUDES += system/core/libmetricslogger/include \
+ system/core/libstats/include
+ endif
LOCAL_CFLAGS := -Werror
LOCAL_INIT_RC := recovery-persist.rc
include $(BUILD_EXECUTABLE)
@@ -643,10 +661,11 @@
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 24; echo $$?),0)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
- recovery-refresh.cpp \
- rotate_logs.cpp
+ recovery-refresh.cpp
LOCAL_MODULE := recovery-refresh
LOCAL_SHARED_LIBRARIES := liblog libbase
+ LOCAL_STATIC_LIBRARIES := libotautil
+ LOCAL_C_INCLUDES += $(LOCAL_PATH)/otautil/include
LOCAL_CFLAGS := -Werror
LOCAL_INIT_RC := recovery-refresh.rc
include $(BUILD_EXECUTABLE)
@@ -654,90 +673,61 @@
# shared libfusesideload
# ===============================
-include $(CLEAR_VARS)
-LOCAL_CLANG := true
-LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
-LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 29; echo $$?),0)
+ include $(CLEAR_VARS)
+ LOCAL_CLANG := true
+ LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
+ LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE := libfusesideload
-LOCAL_SHARED_LIBRARIES := libcutils libc
-ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0)
- LOCAL_C_INCLUDES := $(LOCAL_PATH)/libmincrypt/includes
- LOCAL_SHARED_LIBRARIES += libmincrypttwrp
- LOCAL_CFLAGS += -DUSE_MINCRYPT
-else
- LOCAL_SHARED_LIBRARIES += libcrypto
+ LOCAL_MODULE_TAGS := optional
+ LOCAL_MODULE := libfusesideload
+ LOCAL_SHARED_LIBRARIES := libcutils libc
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0)
+ LOCAL_C_INCLUDES := $(LOCAL_PATH)/libmincrypt/includes
+ LOCAL_SHARED_LIBRARIES += libmincrypttwrp
+ LOCAL_CFLAGS += -DUSE_MINCRYPT
+ else
+ LOCAL_SHARED_LIBRARIES += libcrypto libbase
+ endif
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
+ LOCAL_SRC_FILES := fuse_sideload22.cpp
+ LOCAL_CFLAGS += -DUSE_FUSE_SIDELOAD22
+ else
+ # ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 29; echo $$?),0)
+ LOCAL_SRC_FILES := fuse_sideload28/fuse_sideload.cpp
+ # else
+ # LOCAL_SRC_FILES := fuse_sideload/fuse_sideload.cpp \
+ fuse_sideload/fuse_provider.cpp
+ # endif
+ endif
+ include $(BUILD_SHARED_LIBRARY)
endif
-ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
- LOCAL_SRC_FILES := fuse_sideload22.cpp
- LOCAL_CFLAGS += -DUSE_FUSE_SIDELOAD22
-else
- LOCAL_SRC_FILES := fuse_sideload.cpp
-=======
-LOCAL_WHOLE_STATIC_LIBRARIES := \
- $(TARGET_RECOVERY_UI_LIB)
-LOCAL_SHARED_LIBRARIES := \
- libbase \
- liblog \
- librecovery_ui.recovery
+# # static libfusesideload
+# # =============================== (required to fix build errors in 8.1 due to use by tests)
+# include $(CLEAR_VARS)
+# LOCAL_CLANG := true
+# LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
+# LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE
-include $(BUILD_SHARED_LIBRARY)
+# LOCAL_MODULE_TAGS := optional
+# LOCAL_MODULE := libfusesideload
+# LOCAL_SHARED_LIBRARIES := libcutils libc
+# ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0)
+# LOCAL_C_INCLUDES := $(LOCAL_PATH)/libmincrypt/includes
+# LOCAL_STATIC_LIBRARIES += libmincrypttwrp
+# LOCAL_CFLAGS += -DUSE_MINCRYPT
+# else
+# LOCAL_STATIC_LIBRARIES += libcrypto_static
+# endif
+# ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
+# LOCAL_SRC_FILES := fuse_sideload22.cpp
+# LOCAL_CFLAGS += -DUSE_FUSE_SIDELOAD22
+# else
+# LOCAL_SRC_FILES := fuse_sideload.cpp
+# endif
+# include $(BUILD_STATIC_LIBRARY)
-# recovery_deps: A phony target that's depended on by `recovery`, which
-# builds additional modules conditionally based on Makefile variables.
-# ======================================================================
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := recovery_deps
-
-ifeq ($(TARGET_USERIMAGES_USE_F2FS),true)
-ifeq ($(HOST_OS),linux)
-LOCAL_REQUIRED_MODULES += \
- make_f2fs.recovery \
- sload_f2fs.recovery
-endif
->>>>>>> android-10.0.0_r25
-endif
-include $(BUILD_SHARED_LIBRARY)
-
-# static libfusesideload
-# =============================== (required to fix build errors in 8.1 due to use by tests)
-include $(CLEAR_VARS)
-LOCAL_CLANG := true
-LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
-LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE
-
-<<<<<<< HEAD
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE := libfusesideload
-LOCAL_SHARED_LIBRARIES := libcutils libc
-ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0)
- LOCAL_C_INCLUDES := $(LOCAL_PATH)/libmincrypt/includes
- LOCAL_STATIC_LIBRARIES += libmincrypttwrp
- LOCAL_CFLAGS += -DUSE_MINCRYPT
-else
- LOCAL_STATIC_LIBRARIES += libcrypto_static
-=======
-# On A/B devices recovery-persist reads the recovery related file from the persist storage and
-# copies them into /data/misc/recovery. Then, for both A/B and non-A/B devices, recovery-persist
-# parses the last_install file and reports the embedded update metrics. Also, the last_install file
-# will be deteleted after the report.
-LOCAL_REQUIRED_MODULES += recovery-persist
-ifeq ($(BOARD_CACHEIMAGE_PARTITION_SIZE),)
-LOCAL_REQUIRED_MODULES += recovery-refresh
->>>>>>> android-10.0.0_r25
-endif
-ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
- LOCAL_SRC_FILES := fuse_sideload22.cpp
- LOCAL_CFLAGS += -DUSE_FUSE_SIDELOAD22
-else
- LOCAL_SRC_FILES := fuse_sideload.cpp
-endif
-include $(BUILD_STATIC_LIBRARY)
-
-<<<<<<< HEAD
# libmounts (static library)
# ===============================
include $(CLEAR_VARS)
@@ -779,10 +769,19 @@
LOCAL_MODULE := libaosprecovery
-LOCAL_MODULE_TAGS := eng optional
-LOCAL_CFLAGS := -std=gnu++0x
-LOCAL_SRC_FILES := adb_install.cpp legacy_property_service.cpp set_metadata.cpp tw_atomic.cpp installcommand.cpp zipwrap.cpp
-LOCAL_SHARED_LIBRARIES += libc liblog libcutils libmtdutils libfusesideload libselinux libminzip
+LOCAL_MODULE_TAGS := optional
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 29; echo $$?),0)
+ LOCAL_SRC_FILES := install28/adb_install.cpp legacy_property_service.cpp set_metadata.cpp tw_atomic.cpp \
+ installcommand.cpp zipwrap.cpp
+else
+ LOCAL_SRC_FILES := install/adb_install.cpp install/asn1_decoder.cpp install/fuse_sdcard_install.cpp\
+ install/install.cpp install/installcommand.cpp install/legacy_property_service.cpp \
+ install/package.cpp install/verifier.cpp install/wipe_data.cpp install/tw_atomic.cpp \
+ install/set_metadata.cpp verifier28/verifier.cpp install/zipwrap.cpp install/ZipUtil.cpp
+endif
+LOCAL_SHARED_LIBRARIES += libbase libbootloader_message libcrypto libext4_utils \
+ libfs_mgr libfusesideload libhidl-gen-utils libhidlbase libhidltransport \
+ liblog libselinux libtinyxml2 libutils libz libziparchive libcutils
LOCAL_CFLAGS += -DRECOVERY_API_VERSION=$(RECOVERY_API_VERSION)
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
LOCAL_SHARED_LIBRARIES += libstdc++ libstlport
@@ -797,30 +796,51 @@
LOCAL_SRC_FILES += verifier24/verifier.cpp verifier24/asn1_decoder.cpp
LOCAL_CFLAGS += -DUSE_OLD_VERIFIER
else
- LOCAL_SHARED_LIBRARIES += libcrypto libbase
- LOCAL_SRC_FILES += verifier.cpp asn1_decoder.cpp
- LOCAL_C_INCLUDES += $(LOCAL_PATH)/otautil/include
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 24; echo $$?),0)
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 28; echo $$?),0)
+ LOCAL_CFLAGS := -std=gnu++2a
+ LOCAL_C_INCLUDES += $(commands_TWRP_local_path)/install/include \
+ $(commands_TWRP_local_path)/recovery_ui/include \
+ $(commands_TWRP_local_path)/otautil/include \
+ $(commands_TWRP_local_path)/minadbd \
+ $(commands_TWRP_local_path)/minzip \
+ system/libvintf/include
+ LOCAL_STATIC_LIBRARIES += libotautil libvintf_recovery libvintf
+ else
+ LOCAL_C_INCLUDES += $(commands_TWRP_local_path)/install28/
+ LOCAL_CFLAGS += -DUSE_28_INSTALL
+ endif
+ LOCAL_CFLAGS += -DRECOVERY_API_VERSION=$(RECOVERY_API_VERSION)
+ else
+ LOCAL_SHARED_LIBRARIES += libcrypto libbase
+ LOCAL_SRC_FILES += verifier28/verifier.cpp verifier28/asn1_decoder.cpp
+ LOCAL_C_INCLUDES += $(LOCAL_PATH)/otautil/include $(LOCAL_PATH)/verifier28 \
+ system/libvintf/include
+ LOCAL_CFLAGS += -DUSE_28_VERIFIER
+ endif
endif
ifeq ($(AB_OTA_UPDATER),true)
LOCAL_CFLAGS += -DAB_OTA_UPDATER=1
endif
+
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 26; echo $$?),0)
- LOCAL_SRC_FILES += otautil/ZipUtil.cpp otautil/SysUtil.cpp otautil/DirUtil.cpp
- LOCAL_SHARED_LIBRARIES += libziparchive libext4_utils libcrypto libcrypto_utils
- LOCAL_STATIC_LIBRARIES += libvintf_recovery libfs_mgr liblogwrap libavb libvintf libtinyxml2 libz
- LOCAL_C_INCLUDES += $(LOCAL_PATH)/otautil/include
- ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 27; echo $$?),0)
- # Android 9.0 needs c++17 for libvintf
- LOCAL_CPPFLAGS += -std=c++17
- # Android 9.0's libvintf also needs this library
- LOCAL_STATIC_LIBRARIES += libhidl-gen-utils
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 29; echo $$?),0)
+ # LOCAL_SRC_FILES += otautil/ZipUtil.cpp otautil/SysUtil.cpp otautil/DirUtil.cpp
+ LOCAL_SHARED_LIBRARIES += libziparchive libext4_utils libcrypto libcrypto_utils libfs_mgr
+ LOCAL_STATIC_LIBRARIES += libvintf_recovery liblogwrap libavb libvintf libtinyxml2 libz
+ LOCAL_C_INCLUDES += $(LOCAL_PATH)/otautil/include
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 27; echo $$?),0)
+ # Android 9.0's libvintf also needs this library
+ LOCAL_STATIC_LIBRARIES += libhidl-gen-utils
+ endif
endif
else
LOCAL_CFLAGS += -DUSE_MINZIP
endif
include $(BUILD_SHARED_LIBRARY)
+
# libverifier (static library)
# ===============================
include $(CLEAR_VARS)
@@ -837,44 +857,41 @@
LOCAL_CFLAGS := -Wall -Werror
include $(BUILD_STATIC_LIBRARY)
-# Wear default device
-# ===============================
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := wear_device.cpp
-LOCAL_CFLAGS := -Wall -Werror
+# # Wear default device
+# # ===============================
+# include $(CLEAR_VARS)
+# LOCAL_SRC_FILES := wear_device.cpp
+# LOCAL_CFLAGS := -Wall -Werror
-# Should match TARGET_RECOVERY_UI_LIB in BoardConfig.mk.
-LOCAL_MODULE := librecovery_ui_wear
+# # Should match TARGET_RECOVERY_UI_LIB in BoardConfig.mk.
+# LOCAL_MODULE := librecovery_ui_wear
-include $(BUILD_STATIC_LIBRARY)
+# include $(BUILD_STATIC_LIBRARY)
-# vr headset default device
-# ===============================
-include $(CLEAR_VARS)
+# # vr headset default device
+# # ===============================
+# include $(CLEAR_VARS)
-LOCAL_SRC_FILES := vr_device.cpp
-LOCAL_CFLAGS := -Wall -Werror
+# LOCAL_SRC_FILES := vr_device.cpp
+# LOCAL_CFLAGS := -Wall -Werror
-# should match TARGET_RECOVERY_UI_LIB set in BoardConfig.mk
-LOCAL_MODULE := librecovery_ui_vr
+# # should match TARGET_RECOVERY_UI_LIB set in BoardConfig.mk
+# LOCAL_MODULE := librecovery_ui_vr
-include $(BUILD_STATIC_LIBRARY)
-=======
-include $(BUILD_PHONY_PACKAGE)
->>>>>>> android-10.0.0_r25
+# include $(BUILD_STATIC_LIBRARY)
commands_recovery_local_path := $(LOCAL_PATH)
# $(LOCAL_PATH)/edify/Android.mk
# $(LOCAL_PATH)/otafault/Android.mk
# $(LOCAL_PATH)/bootloader_message/Android.mk
+
+ # $(commands_TWRP_local_path)/boot_control/Android.bp
+ # $(commands_TWRP_local_path)/tests/Android.mk
+ # $(commands_TWRP_local_path)/tools/Android.mk
+ # $(commands_TWRP_local_path)/update_verifier/Android.mk
include \
-<<<<<<< HEAD
- $(commands_TWRP_local_path)/boot_control/Android.mk \
- $(commands_TWRP_local_path)/tests/Android.mk \
- $(commands_TWRP_local_path)/tools/Android.mk \
$(commands_TWRP_local_path)/updater/Android.mk \
- $(commands_TWRP_local_path)/update_verifier/Android.mk \
$(commands_TWRP_local_path)/bootloader_message_twrp/Android.mk
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -le 25; echo $$?),0)
@@ -904,7 +921,8 @@
$(commands_TWRP_local_path)/minui21/Android.mk
endif
-#$(commands_TWRP_local_path)/otautil/Android.mk
+ # $(commands_TWRP_local_path)/otautil/Android.mk \
+
#includes for TWRP
include $(commands_TWRP_local_path)/injecttwrp/Android.mk \
$(commands_TWRP_local_path)/htcdumlock/Android.mk \
@@ -920,7 +938,6 @@
$(commands_TWRP_local_path)/libblkid/Android.mk \
$(commands_TWRP_local_path)/minuitwrp/Android.mk \
$(commands_TWRP_local_path)/openaes/Android.mk \
- $(commands_TWRP_local_path)/toolbox/Android.mk \
$(commands_TWRP_local_path)/twrpTarMain/Android.mk \
$(commands_TWRP_local_path)/minzip/Android.mk \
$(commands_TWRP_local_path)/dosfstools/Android.mk \
@@ -973,6 +990,3 @@
endif
commands_TWRP_local_path :=
-=======
- $(LOCAL_PATH)/updater/Android.mk \
->>>>>>> android-10.0.0_r25
diff --git a/README.md b/README.md
old mode 100644
new mode 100755
index 2bdff2b..820a8b7
--- a/README.md
+++ b/README.md
@@ -1,136 +1,3 @@
**Team Win Recovery Project (TWRP)**
-<<<<<<< HEAD
You can find a compiling guide [here](http://forum.xda-developers.com/showthread.php?t=1943625 "Guide").
-=======
-Quick turn-around testing
--------------------------
-
- mm -j && m ramdisk-nodeps && m recoveryimage-nodeps
-
- # To boot into the new recovery image
- # without flashing the recovery partition:
- adb reboot bootloader
- fastboot boot $ANDROID_PRODUCT_OUT/recovery.img
-
-Running the tests
------------------
- # After setting up environment and lunch.
- mmma -j bootable/recovery
-
- # Running the tests on device.
- adb root
- adb sync data
-
- # 32-bit device
- adb shell /data/nativetest/recovery_unit_test/recovery_unit_test
- adb shell /data/nativetest/recovery_component_test/recovery_component_test
-
- # Or 64-bit device
- adb shell /data/nativetest64/recovery_unit_test/recovery_unit_test
- adb shell /data/nativetest64/recovery_component_test/recovery_component_test
-
-Running the manual tests
-------------------------
-
-`recovery-refresh` and `recovery-persist` executables exist only on systems without
-/cache partition. And we need to follow special steps to run tests for them.
-
-- Execute the test on an A/B device first. The test should fail but it will log
- some contents to pmsg.
-
-- Reboot the device immediately and run the test again. The test should save the
- contents of pmsg buffer into /data/misc/recovery/inject.txt. Test will pass if
- this file has expected contents.
-
-Using `adb` under recovery
---------------------------
-
-When running recovery image from debuggable builds (i.e. `-eng` or `-userdebug` build variants, or
-`ro.debuggable=1` in `/prop.default`), `adbd` service is enabled and started by default, which
-allows `adb` communication. A device should be listed under `adb devices`, either in `recovery` or
-`sideload` state.
-
- $ adb devices
- List of devices attached
- 1234567890abcdef recovery
-
-Although `/system/bin/adbd` is built from the same code base as the one in the normal boot, only a
-subset of `adb` commands are meaningful under recovery, such as `adb root`, `adb shell`, `adb push`,
-`adb pull` etc. Since Android Q, `adb shell` no longer requires manually mounting `/system` from
-recovery menu.
-
-## Troubleshooting
-
-### `adb devices` doesn't show the device.
-
- $ adb devices
- List of devices attached
-
- * Ensure `adbd` is built and running.
-
-By default, `adbd` is always included into recovery image, as `/system/bin/adbd`. `init` starts
-`adbd` service automatically only in debuggable builds. This behavior is controlled by the recovery
-specific `/init.rc`, whose source code is at `bootable/recovery/etc/init.rc`.
-
-The best way to confirm a running `adbd` is by checking the serial output, which shows a service
-start log as below.
-
- [ 18.961986] c1 1 init: starting service 'adbd'...
-
- * Ensure USB gadget has been enabled.
-
-If `adbd` service has been started but device not shown under `adb devices`, use `lsusb(8)` (on
-host) to check if the device is visible to the host.
-
-`bootable/recovery/etc/init.rc` disables Android USB gadget (via sysfs) as part of the `fs` action
-trigger, and will only re-enable it in debuggable builds (the `on property` rule will always run
-_after_ `on fs`).
-
- on fs
- write /sys/class/android_usb/android0/enable 0
-
- # Always start adbd on userdebug and eng builds
- on property:ro.debuggable=1
- write /sys/class/android_usb/android0/enable 1
- start adbd
-
-If device is using [configfs](https://www.kernel.org/doc/Documentation/usb/gadget_configfs.txt),
-check if configfs has been properly set up in init rc scripts. See the [example
-configuration](https://android.googlesource.com/device/google/wahoo/+/master/init.recovery.hardware.rc)
-for Pixel 2 devices. Note that the flag set via sysfs (i.e. the one above) is no-op when using
-configfs.
-
-### `adb devices` shows the device, but in `unauthorized` state.
-
- $ adb devices
- List of devices attached
- 1234567890abcdef unauthorized
-
-recovery image doesn't honor the USB debugging toggle and the authorizations added under normal boot
-(because such authorization data stays in /data, which recovery doesn't mount), nor does it support
-authorizing a host device under recovery. We can use one of the following options instead.
-
- * **Option 1 (Recommended):** Authorize a host device with adb vendor keys.
-
-For debuggable builds, an RSA keypair can be used to authorize a host device that has the private
-key. The public key, defined via `PRODUCT_ADB_KEYS`, will be copied to `/adb_keys`. When starting
-the host-side `adbd`, make sure the filename (or the directory) of the matching private key has been
-added to `$ADB_VENDOR_KEYS`.
-
- $ export ADB_VENDOR_KEYS=/path/to/adb/private/key
- $ adb kill-server
- $ adb devices
-
-`-user` builds filter out `PRODUCT_ADB_KEYS`, so no `/adb_keys` will be included there.
-
-Note that this mechanism applies to both of normal boot and recovery modes.
-
- * **Option 2:** Allow `adbd` to connect without authentication.
- * `adbd` is compiled with `ALLOW_ADBD_NO_AUTH` (only on debuggable builds).
- * `ro.adb.secure` has a value of `0`.
-
-Both of the two conditions need to be satisfied. Although `ro.adb.secure` is a runtime property, its
-value is set at build time (written into `/prop.default`). It defaults to `1` on `-user` builds, and
-`0` for other build variants. The value is overridable via `PRODUCT_DEFAULT_PROPERTY_OVERRIDES`.
->>>>>>> android-10.0.0_r25
diff --git a/adbbu/Android.mk b/adbbu/Android.mk
index 8f8dbd0..e271938 100644
--- a/adbbu/Android.mk
+++ b/adbbu/Android.mk
@@ -41,7 +41,7 @@
LOCAL_CFLAGS:= -c -W
LOCAL_MODULE:= twrpbu
LOCAL_MODULE_STEM := bu
-LOCAL_MODULE_TAGS:= eng
+LOCAL_MODULE_TAGS:= optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
include $(BUILD_EXECUTABLE)
diff --git a/applypatch/Android.mk b/applypatch/Android.mk
index 1f71c44..44112fd 100644
--- a/applypatch/Android.mk
+++ b/applypatch/Android.mk
@@ -23,7 +23,7 @@
freecache.cpp \
imgpatch.cpp
LOCAL_MODULE := libapplypatch
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/include \
$(commands_recovery_local_path)
diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp
old mode 100644
new mode 100755
index a2d38f1..0106582
--- a/applypatch/applypatch.cpp
+++ b/applypatch/applypatch.cpp
@@ -49,23 +49,8 @@
using namespace std::string_literals;
-<<<<<<< HEAD
-static bool mtd_partitions_scanned = false;
-
-// Read a file into memory; store the file contents and associated metadata in *file.
-// Return 0 on success.
-int LoadFileContents(const char* filename, FileContents* file) {
- // A special 'filename' beginning with "MTD:" or "EMMC:" means to
- // load the contents of a partition.
- if (strncmp(filename, "MTD:", 4) == 0 ||
- strncmp(filename, "EMMC:", 5) == 0 ||
- strncmp(filename, "BML:", 4) == 0) {
- return LoadPartitionContents(filename, file);
- }
-=======
static bool GenerateTarget(const Partition& target, const FileContents& source_file,
const Value& patch, const Value* bonus_data);
->>>>>>> android-10.0.0_r25
bool LoadFileContents(const std::string& filename, FileContents* file) {
// No longer allow loading contents from eMMC partitions.
@@ -84,62 +69,6 @@
return true;
}
-<<<<<<< HEAD
-// Load the contents of an EMMC partition into the provided
-// FileContents. filename should be a string of the form
-// "EMMC:<partition_device>:...". The smallest size_n bytes for
-// which that prefix of the partition contents has the corresponding
-// sha1 hash will be loaded. It is acceptable for a size value to be
-// repeated with different sha1s. Will return 0 on success.
-//
-// This complexity is needed because if an OTA installation is
-// interrupted, the partition might contain either the source or the
-// target data, which might be of different lengths. We need to know
-// the length in order to read from a partition (there is no
-// "end-of-file" marker), so the caller must specify the possible
-// lengths and the hash of the data, and we'll do the load expecting
-// to find one of those hashes.
-enum PartitionType { MTD, EMMC };
-
-static int LoadPartitionContents(const std::string& filename, FileContents* file) {
- std::vector<std::string> pieces = android::base::Split(filename, ":");
- if (pieces.size() < 4 || pieces.size() % 2 != 0) {
- printf("LoadPartitionContents called with bad filename \"%s\"\n", filename.c_str());
- return -1;
- }
-
- enum PartitionType type;
- if (pieces[0] == "MTD") {
- type = MTD;
- } else if (pieces[0] == "EMMC") {
- type = EMMC;
- } else if (pieces[0] == "BML") {
- type = EMMC;
- } else {
- printf("LoadPartitionContents called with bad filename (%s)\n", filename.c_str());
- return -1;
- }
-
- size_t pair_count = (pieces.size() - 2) / 2; // # of (size, sha1) pairs in filename
- std::vector<std::pair<size_t, std::string>> pairs;
- for (size_t i = 0; i < pair_count; ++i) {
- size_t size;
- if (!android::base::ParseUint(pieces[i * 2 + 2], &size) || size == 0) {
- printf("LoadPartitionContents called with bad size \"%s\"\n", pieces[i * 2 + 2].c_str());
- return -1;
- }
- pairs.push_back({ size, pieces[i * 2 + 3] });
- }
-
- // Sort the pairs array so that they are in order of increasing size.
- std::sort(pairs.begin(), pairs.end());
-
- const char* partition = pieces[1].c_str();
- unique_file dev(ota_fopen(partition, "rb"));
- if (!dev) {
- printf("failed to open emmc partition \"%s\": %s\n", partition, strerror(errno));
- return -1;
-=======
// Reads the contents of a Partition to the given FileContents buffer.
static bool ReadPartitionToBuffer(const Partition& partition, FileContents* out,
bool check_backup) {
@@ -147,7 +76,6 @@
if (ParseSha1(partition.hash, expected_sha1) != 0) {
LOG(ERROR) << "Failed to parse target hash \"" << partition.hash << "\"";
return false;
->>>>>>> android-10.0.0_r25
}
android::base::unique_fd dev(open(partition.name.c_str(), O_RDONLY));
@@ -164,40 +92,6 @@
out->data = std::move(buffer);
return true;
}
-<<<<<<< HEAD
- SHA1_Update(&sha_ctx, buffer_ptr, read);
- buffer_size += read;
- buffer_ptr += read;
- }
-
- if (pieces[0] == "BML") {
- if (strcmp(partition, "boot") == 0) {
- partition = BOARD_BML_BOOT;
- } else if (strcmp(partition, "recovery") == 0) {
- partition = BOARD_BML_RECOVERY;
- }
- }
-
- // Duplicate the SHA context and finalize the duplicate so we can
- // check it against this pair's expected hash.
- SHA_CTX temp_ctx;
- memcpy(&temp_ctx, &sha_ctx, sizeof(SHA_CTX));
- uint8_t sha_so_far[SHA_DIGEST_LENGTH];
- SHA1_Final(sha_so_far, &temp_ctx);
-
- uint8_t parsed_sha[SHA_DIGEST_LENGTH];
- if (ParseSha1(current_sha1.c_str(), parsed_sha) != 0) {
- printf("failed to parse SHA-1 %s in %s\n", current_sha1.c_str(), filename.c_str());
- return -1;
- }
-
- if (memcmp(sha_so_far, parsed_sha, SHA_DIGEST_LENGTH) == 0) {
- // We have a match. Stop reading the partition; we'll return the data we've read so far.
- printf("partition read matched size %zu SHA-1 %s\n", current_size, current_sha1.c_str());
- found = true;
- break;
-=======
->>>>>>> android-10.0.0_r25
}
}
@@ -228,34 +122,6 @@
return false;
}
-<<<<<<< HEAD
- return 0;
-}
-
-// Write a memory buffer to 'target' partition, a string of the form
-// "EMMC:<partition_device>[:...]". The target name
-// might contain multiple colons, but WriteToPartition() only uses the first
-// two and ignores the rest. Return 0 on success.
-int WriteToPartition(const unsigned char* data, size_t len, const std::string& target) {
- std::string copy(target);
- std::vector<std::string> pieces = android::base::Split(copy, ":");
-
- if (pieces.size() < 2) {
- printf("WriteToPartition called with bad target (%s)\n", target.c_str());
- return -1;
- }
-
- enum PartitionType type;
- if (pieces[0] == "MTD") {
- type = MTD;
- } else if (pieces[0] == "EMMC") {
- type = EMMC;
- } else if (pieces[0] == "BML") {
- type = EMMC;
- } else {
- printf("WriteToPartition called with bad target (%s)\n", target.c_str());
- return -1;
-=======
if (fsync(fd) != 0) {
PLOG(ERROR) << "Failed to fsync \"" << filename << "\"";
return false;
@@ -321,228 +187,10 @@
if (TEMP_FAILURE_RETRY(lseek(fd, 0, SEEK_SET)) == -1) {
PLOG(ERROR) << "Failed to seek to 0 on " << partition;
return false;
->>>>>>> android-10.0.0_r25
}
const char* partition = pieces[1].c_str();
-<<<<<<< HEAD
- if (pieces[0] == "BML") {
- if (strcmp(partition, "boot") == 0) {
- partition = BOARD_BML_BOOT;
- } else if (strcmp(partition, "recovery") == 0) {
- partition = BOARD_BML_RECOVERY;
- }
-
- int bmlpartition = open(partition, O_RDWR | O_LARGEFILE);
- if (bmlpartition < 0)
- return -1;
- if (ioctl(bmlpartition, BML_UNLOCK_ALL, 0)) {
- printf("failed to unlock BML partition: (%s)\n", partition);
- return -1;
- }
- close(bmlpartition);
- }
-
- if (partition == NULL) {
- printf("bad partition target name \"%s\"\n", target.c_str());
- return -1;
- }
-
- switch (type) {
- case MTD: {
- if (!mtd_partitions_scanned) {
- mtd_scan_partitions();
- mtd_partitions_scanned = true;
- }
-
- const MtdPartition* mtd = mtd_find_partition_by_name(partition);
- if (mtd == NULL) {
- printf("mtd partition \"%s\" not found for writing\n", partition);
- return -1;
- }
-
- MtdWriteContext* ctx = mtd_write_partition(mtd);
- if (ctx == NULL) {
- printf("failed to init mtd partition \"%s\" for writing\n", partition);
- return -1;
- }
-
- size_t written = mtd_write_data(ctx, reinterpret_cast<const char*>(data), len);
- if (written != len) {
- printf("only wrote %zu of %zu bytes to MTD %s\n", written, len, partition);
- mtd_write_close(ctx);
- return -1;
- }
-
- if (mtd_erase_blocks(ctx, -1) < 0) {
- printf("error finishing mtd write of %s\n", partition);
- mtd_write_close(ctx);
- return -1;
- }
-
- if (mtd_write_close(ctx)) {
- printf("error closing mtd write of %s\n", partition);
- return -1;
- }
- break;
- }
-
- case EMMC: {
- size_t start = 0;
- bool success = false;
- unique_fd fd(ota_open(partition, O_RDWR | O_SYNC));
- if (fd < 0) {
- printf("failed to open %s: %s\n", partition, strerror(errno));
- return -1;
- }
-
- for (size_t attempt = 0; attempt < 2; ++attempt) {
- if (TEMP_FAILURE_RETRY(lseek(fd, start, SEEK_SET)) == -1) {
- printf("failed seek on %s: %s\n", partition, strerror(errno));
- return -1;
- }
- while (start < len) {
- size_t to_write = len - start;
- if (to_write > 1<<20) to_write = 1<<20;
-
- ssize_t written = TEMP_FAILURE_RETRY(ota_write(fd, data+start, to_write));
- if (written == -1) {
- printf("failed write writing to %s: %s\n", partition, strerror(errno));
- return -1;
- }
- start += written;
- }
- if (ota_fsync(fd) != 0) {
- printf("failed to sync to %s (%s)\n", partition, strerror(errno));
- return -1;
- }
- if (ota_close(fd) != 0) {
- printf("failed to close %s (%s)\n", partition, strerror(errno));
- return -1;
- }
- unique_fd fd(ota_open(partition, O_RDONLY));
- if (fd < 0) {
- printf("failed to reopen %s for verify (%s)\n", partition, strerror(errno));
- return -1;
- }
-
- // Drop caches so our subsequent verification read
- // won't just be reading the cache.
- sync();
- unique_fd dc(ota_open("/proc/sys/vm/drop_caches", O_WRONLY));
- if (TEMP_FAILURE_RETRY(ota_write(dc, "3\n", 2)) == -1) {
- printf("write to /proc/sys/vm/drop_caches failed: %s\n", strerror(errno));
- } else {
- printf(" caches dropped\n");
- }
- ota_close(dc);
- sleep(1);
-
- // verify
- if (TEMP_FAILURE_RETRY(lseek(fd, 0, SEEK_SET)) == -1) {
- printf("failed to seek back to beginning of %s: %s\n",
- partition, strerror(errno));
- return -1;
- }
- unsigned char buffer[4096];
- start = len;
- for (size_t p = 0; p < len; p += sizeof(buffer)) {
- size_t to_read = len - p;
- if (to_read > sizeof(buffer)) {
- to_read = sizeof(buffer);
- }
-
- size_t so_far = 0;
- while (so_far < to_read) {
- ssize_t read_count =
- TEMP_FAILURE_RETRY(ota_read(fd, buffer+so_far, to_read-so_far));
- if (read_count == -1) {
- printf("verify read error %s at %zu: %s\n",
- partition, p, strerror(errno));
- return -1;
- }
- if (static_cast<size_t>(read_count) < to_read) {
- printf("short verify read %s at %zu: %zd %zu %s\n",
- partition, p, read_count, to_read, strerror(errno));
- }
- so_far += read_count;
- }
-
- if (memcmp(buffer, data+p, to_read) != 0) {
- printf("verification failed starting at %zu\n", p);
- start = p;
- break;
- }
- }
-
- if (start == len) {
- printf("verification read succeeded (attempt %zu)\n", attempt+1);
- success = true;
- break;
- }
- }
-
- if (!success) {
- printf("failed to verify after all attempts\n");
- return -1;
- }
-
- if (ota_close(fd) != 0) {
- printf("error closing %s (%s)\n", partition, strerror(errno));
- return -1;
- }
- sync();
- break;
- }
- }
-
- return 0;
-}
-
-// Take a string 'str' of 40 hex digits and parse it into the 20
-// byte array 'digest'. 'str' may contain only the digest or be of
-// the form "<digest>:<anything>". Return 0 on success, -1 on any
-// error.
-int ParseSha1(const char* str, uint8_t* digest) {
- const char* ps = str;
- uint8_t* pd = digest;
- for (int i = 0; i < SHA_DIGEST_LENGTH * 2; ++i, ++ps) {
- int digit;
- if (*ps >= '0' && *ps <= '9') {
- digit = *ps - '0';
- } else if (*ps >= 'a' && *ps <= 'f') {
- digit = *ps - 'a' + 10;
- } else if (*ps >= 'A' && *ps <= 'F') {
- digit = *ps - 'A' + 10;
- } else {
- return -1;
- }
- if (i % 2 == 0) {
- *pd = digit << 4;
- } else {
- *pd |= digit;
- ++pd;
- }
- }
- if (*ps != '\0') return -1;
- return 0;
-}
-
-// Search an array of sha1 strings for one matching the given sha1.
-// Return the index of the match on success, or -1 if no match is
-// found.
-static int FindMatchingPatch(uint8_t* sha1, const std::vector<std::string>& patch_sha1_str) {
- for (size_t i = 0; i < patch_sha1_str.size(); ++i) {
- uint8_t patch_sha1[SHA_DIGEST_LENGTH];
- if (ParseSha1(patch_sha1_str[i].c_str(), patch_sha1) == 0 &&
- memcmp(patch_sha1, sha1, SHA_DIGEST_LENGTH) == 0) {
- return i;
- }
- }
- return -1;
-=======
- if (!android::base::ReadFully(fd, buffer, to_read)) {
PLOG(ERROR) << "Failed to verify-read " << partition << " at " << p;
return false;
}
@@ -574,7 +222,6 @@
sync();
return true;
->>>>>>> android-10.0.0_r25
}
int ParseSha1(const std::string& str, uint8_t* digest) {
@@ -758,40 +405,6 @@
LOG(INFO) << " now " << short_sha1(expected_sha1);
// Write back the temp file to the partition.
- if (!WriteBufferToPartition(patched, target)) {
- LOG(ERROR) << "Failed to write patched data to " << target.name;
- return false;
- }
-
- // Delete the backup copy of the source.
- unlink(Paths::Get().cache_temp_source().c_str());
-
- // Success!
- return true;
-}
-
-bool CheckPartition(const Partition& partition) {
- FileContents target_file;
- return ReadPartitionToBuffer(partition, &target_file, false);
-}
-
-Partition Partition::Parse(const std::string& input_str, std::string* err) {
- std::vector<std::string> pieces = android::base::Split(input_str, ":");
- if (pieces.size() != 4 || pieces[0] != "EMMC") {
- *err = "Invalid number of tokens or non-eMMC target";
- return {};
- }
-
- size_t size;
- if (!android::base::ParseUint(pieces[2], &size) || size == 0) {
- *err = "Failed to parse \"" + pieces[2] + "\" as byte count";
- return {};
- }
-
- return Partition(pieces[1], size, pieces[3]);
-}
-
-std::string Partition::ToString() const {
if (*this) {
return "EMMC:"s + name + ":" + std::to_string(size) + ":" + hash;
}
diff --git a/attr/Android.mk b/attr/Android.mk
index 2986ab5..ab1d892 100644
--- a/attr/Android.mk
+++ b/attr/Android.mk
@@ -4,7 +4,7 @@
LOCAL_SRC_FILES := listxattr.c
LOCAL_CFLAGS := -c -W
LOCAL_MODULE := listxattr
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_PACK_MODULE_RELOCATIONS := false
diff --git a/bmlutils/Android.mk b/bmlutils/Android.mk
index 7216775..9cbada0 100644
--- a/bmlutils/Android.mk
+++ b/bmlutils/Android.mk
@@ -13,7 +13,7 @@
LOCAL_SRC_FILES := bmlutils.c
LOCAL_MODULE := libbmlutils
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
include $(BUILD_STATIC_LIBRARY)
#Added for building TWRP dynamic:
@@ -30,5 +30,5 @@
LOCAL_SRC_FILES := bmlutils.c
LOCAL_MODULE := libbmlutils
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY)
diff --git a/bootloader_message/Android.mk b/bootloader_message/Android.mk
deleted file mode 100644
index 0d84713..0000000
--- a/bootloader_message/Android.mk
+++ /dev/null
@@ -1,29 +0,0 @@
-# Copyright (C) 2016 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-LOCAL_CLANG := true
-LOCAL_SRC_FILES := bootloader_message.cpp
-LOCAL_MODULE := libbootloader_message
-LOCAL_STATIC_LIBRARIES := libbase libfs_mgr
-LOCAL_CFLAGS := -Werror
-ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 26; echo $$?),0)
- TARGET_GLOBAL_CFLAGS += -DUSE_OLD_BOOTLOADER_MESSAGE
- CLANG_TARGET_GLOBAL_CFLAGS += -DUSE_OLD_BOOTLOADER_MESSAGE
-endif
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
-include $(BUILD_STATIC_LIBRARY)
diff --git a/bootloader_message/bootloader_message.cpp b/bootloader_message/bootloader_message.cpp
index 9fad7ff..c1ebeaa 100644
--- a/bootloader_message/bootloader_message.cpp
+++ b/bootloader_message/bootloader_message.cpp
@@ -25,6 +25,7 @@
#include <vector>
#include <android-base/file.h>
+#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/unique_fd.h>
#include <fstab/fstab.h>
@@ -39,47 +40,7 @@
g_misc_device_for_test = misc_device;
}
-#ifdef USE_OLD_BOOTLOADER_MESSAGE
-#include <sys/system_properties.h>
-
-static struct fstab* read_fstab(std::string* err) {
- // The fstab path is always "/fstab.${ro.hardware}".
- std::string fstab_path = "/fstab.";
- char value[PROP_VALUE_MAX];
- if (__system_property_get("ro.hardware", value) == 0) {
- *err = "failed to get ro.hardware";
- return nullptr;
- }
- fstab_path += value;
- struct fstab* fstab = fs_mgr_read_fstab(fstab_path.c_str());
- if (fstab == nullptr) {
- *err = "failed to read " + fstab_path;
- }
- return fstab;
-}
-#endif
-
static std::string get_misc_blk_device(std::string* err) {
-<<<<<<< HEAD
-#ifdef USE_OLD_BOOTLOADER_MESSAGE
- struct fstab* fstab = read_fstab(err);
-#else
- std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(),
- fs_mgr_free_fstab);
-#endif
- if (!fstab) {
- *err = "failed to read default fstab";
- return "";
- }
-#ifdef USE_OLD_BOOTLOADER_MESSAGE
- fstab_rec* record = fs_mgr_get_entry_for_mount_point(fstab, "/misc");
-#else
- fstab_rec* record = fs_mgr_get_entry_for_mount_point(fstab.get(), "/misc");
-#endif
- if (record == nullptr) {
- *err = "failed to find /misc partition";
- return "";
-=======
if (!g_misc_device_for_test.empty()) {
return g_misc_device_for_test;
}
@@ -92,7 +53,6 @@
if (entry.mount_point == "/misc") {
return entry.blk_device;
}
->>>>>>> android-10.0.0_r25
}
*err = "failed to find /misc partition";
diff --git a/bootloader_message/include/bootloader_message/bootloader_message.h b/bootloader_message/include/bootloader_message/bootloader_message.h
index d03d297..95dd8f4 100644
--- a/bootloader_message/include/bootloader_message/bootloader_message.h
+++ b/bootloader_message/include/bootloader_message/bootloader_message.h
@@ -66,16 +66,6 @@
char status[32];
char recovery[768];
-#ifdef USE_OLD_BOOTLOADER_MESSAGE
- // The 'recovery' field used to be 1024 bytes. It has only ever
- // been used to store the recovery command line, so 768 bytes
- // should be plenty. We carve off the last 256 bytes to store the
- // stage string (for multistage packages) and possible future
- // expansion.
- char stage[32];
- char slot_suffix[32];
- char reserved[192];
-#else
// The 'recovery' field used to be 1024 bytes. It has only ever
// been used to store the recovery command line, so 768 bytes
// should be plenty. We carve off the last 256 bytes to store the
@@ -88,14 +78,13 @@
// 1184-byte so that the entire bootloader_message struct rounds up
// to 2048-byte.
char reserved[1184];
-#endif
};
/**
* We must be cautious when changing the bootloader_message struct size,
* because A/B-specific fields may end up with different offsets.
*/
-#if !defined(USE_OLD_BOOTLOADER_MESSAGE) && ((__STDC_VERSION__ >= 201112L) || defined(__cplusplus))
+#if (__STDC_VERSION__ >= 201112L) || defined(__cplusplus)
static_assert(sizeof(struct bootloader_message) == 2048,
"struct bootloader_message size changes, which may break A/B devices");
#endif
@@ -132,7 +121,7 @@
* Be cautious about the struct size change, in case we put anything post
* bootloader_message_ab struct (b/29159185).
*/
-#if !defined(USE_OLD_BOOTLOADER_MESSAGE) && ((__STDC_VERSION__ >= 201112L) || defined(__cplusplus))
+#if (__STDC_VERSION__ >= 201112L) || defined(__cplusplus)
static_assert(sizeof(struct bootloader_message_ab) == 4096,
"struct bootloader_message_ab size changes");
#endif
diff --git a/common.h b/common.h
old mode 100644
new mode 100755
index 6215b1d..e82bec3
--- a/common.h
+++ b/common.h
@@ -14,19 +14,11 @@
* limitations under the License.
*/
-<<<<<<< HEAD
-#ifndef RECOVERY_COMMON_H
-#define RECOVERY_COMMON_H
-
-#include <stdio.h>
-#include <stdarg.h>
-=======
#pragma once
->>>>>>> android-10.0.0_r25
#include <string>
-#ifdef __cplusplus
+#ifndef __cplusplus
extern "C" {
#endif
@@ -54,12 +46,7 @@
extern struct selabel_handle* sehandle;
extern RecoveryUI* ui;
-<<<<<<< HEAD
-extern bool modified_flash;
-//typedef struct fstab_rec Volume;
-=======
extern bool has_cache;
->>>>>>> android-10.0.0_r25
// The current stage, e.g. "1/2".
extern std::string stage;
@@ -67,21 +54,4 @@
// The reason argument provided in "--reason=".
extern const char* reason;
-<<<<<<< HEAD
-// fopen a file, mounting volumes and making parent dirs as necessary.
-FILE* fopen_path(const char *path, const char *mode);
-
-void ui_print(const char* format, ...);
-
-//static bool is_ro_debuggable();
-
-#ifdef __cplusplus
-}
-#endif
-
-bool reboot(const std::string& command);
-
-#endif // RECOVERY_COMMON_H
-=======
-bool is_ro_debuggable();
->>>>>>> android-10.0.0_r25
+// static bool is_ro_debuggable();
diff --git a/crypto/ext4crypt/Android.mk b/crypto/ext4crypt/Android.mk
old mode 100644
new mode 100755
index 0c6ef5b..c8283dd
--- a/crypto/ext4crypt/Android.mk
+++ b/crypto/ext4crypt/Android.mk
@@ -3,12 +3,18 @@
include $(CLEAR_VARS)
LOCAL_MODULE := libe4crypt
-LOCAL_MODULE_TAGS := eng optional
+LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS :=
LOCAL_SRC_FILES := Decrypt.cpp ScryptParameters.cpp Utils.cpp HashPassword.cpp ext4_crypt.cpp
LOCAL_SHARED_LIBRARIES := libselinux libc libc++ libext4_utils libbase libcrypto libcutils libkeymaster_messages libhardware libprotobuf-cpp-lite
LOCAL_STATIC_LIBRARIES := libscrypt_static
-LOCAL_C_INCLUDES := system/extras/ext4_utils system/extras/ext4_utils/include/ext4_utils external/scrypt/lib/crypto system/security/keystore hardware/libhardware/include/hardware system/security/softkeymaster/include/keymaster system/keymaster/include
+LOCAL_C_INCLUDES := system/extras/ext4_utils \
+ system/extras/ext4_utils/include/ext4_utils \
+ external/scrypt/lib/crypto \
+ system/security/keystore/include \
+ hardware/libhardware/include/hardware \
+ system/security/softkeymaster/include/keymaster \
+ system/keymaster/include
ifneq ($(wildcard hardware/libhardware/include/hardware/keymaster0.h),)
LOCAL_CFLAGS += -DTW_CRYPTO_HAVE_KEYMASTERX
@@ -17,6 +23,10 @@
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 26; echo $$?),0)
#8.0 or higher
LOCAL_CFLAGS += -DHAVE_GATEKEEPER1
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 29; echo $$?),0)
+ LOCAL_SHARED_LIBRARIES += android.hardware.confirmationui@1.0
+ # LOCAL_CFLAGS += -DUSE_
+ endif
LOCAL_SHARED_LIBRARIES += android.hardware.keymaster@3.0 libkeystore_binder libhidlbase libutils libbinder android.hardware.gatekeeper@1.0
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 28; echo $$?),0)
#9.0 rules
diff --git a/crypto/ext4crypt/Decrypt.cpp b/crypto/ext4crypt/Decrypt.cpp
old mode 100644
new mode 100755
index d8542dc..dcd390f
--- a/crypto/ext4crypt/Decrypt.cpp
+++ b/crypto/ext4crypt/Decrypt.cpp
@@ -52,10 +52,12 @@
#include <sys/types.h>
#include <fstream>
-#include <ext4_utils/ext4_crypt.h>
+#include "ext4_crypt.h"
#ifdef USE_KEYSTORAGE_4
-#include <android/security/IKeystoreService.h>
+#include <android/hardware/confirmationui/1.0/types.h>
+#include <android/security/BnConfirmationPromptCallback.h>
+#include <android/security/keystore/IKeystoreService.h>
#else
#include <keystore/IKeystoreService.h>
#include <keystore/authorization_set.h>
@@ -82,6 +84,10 @@
#include <android-base/file.h>
+#ifdef USE_KEYSTORAGE_4
+using android::security::keystore::IKeystoreService;
+#endif
+
// Store main DE raw ref / policy
extern std::string de_raw_ref;
extern std::map<userid_t, std::string> s_de_key_raw_refs;
@@ -551,7 +557,7 @@
// First get the keystore service
sp<IBinder> binder = getKeystoreBinderRetry();
#ifdef USE_KEYSTORAGE_4
- sp<security::IKeystoreService> service = interface_cast<security::IKeystoreService>(binder);
+ sp<IKeystoreService> service = interface_cast<IKeystoreService>(binder);
#else
sp<IKeystoreService> service = interface_cast<IKeystoreService>(binder);
#endif
diff --git a/crypto/ext4crypt/Keymaster.cpp b/crypto/ext4crypt/Keymaster.cpp
index ec80ab5..3c21aa2 100644
--- a/crypto/ext4crypt/Keymaster.cpp
+++ b/crypto/ext4crypt/Keymaster.cpp
@@ -130,14 +130,14 @@
auto error =
mDevice->update(mOpHandle, nullptr, &inputBlob, &inputConsumed, nullptr, &outputBlob);
if (error != KM_ERROR_OK) {
- LOG(ERROR) << "update failed, code " << error << "\n";
+ LOG(ERROR) << "update failed, code " << error;
mDevice = nullptr;
return false;
}
output->append(reinterpret_cast<const char*>(outputBlob.data), outputBlob.data_length);
free(const_cast<uint8_t*>(outputBlob.data));
if (inputConsumed > toRead) {
- LOG(ERROR) << "update reported too much input consumed\n";
+ LOG(ERROR) << "update reported too much input consumed";
mDevice = nullptr;
return false;
}
@@ -150,7 +150,7 @@
auto error = mDevice->finish(mOpHandle, nullptr, nullptr, nullptr, nullptr);
mDevice = nullptr;
if (error != KM_ERROR_OK) {
- LOG(ERROR) << "finish failed, code " << error << "\n";
+ LOG(ERROR) << "finish failed, code " << error;
return false;
}
return true;
@@ -161,7 +161,7 @@
auto error = mDevice->finish(mOpHandle, nullptr, nullptr, nullptr, &outputBlob);
mDevice = nullptr;
if (error != KM_ERROR_OK) {
- LOG(ERROR) << "finish failed, code " << error << "\n";
+ LOG(ERROR) << "finish failed, code " << error;
return false;
}
output->assign(reinterpret_cast<const char*>(outputBlob.data), outputBlob.data_length);
@@ -174,14 +174,14 @@
const hw_module_t* module;
int ret = hw_get_module_by_class(KEYSTORE_HARDWARE_MODULE_ID, NULL, &module);
if (ret != 0) {
- LOG(ERROR) << "hw_get_module_by_class returned " << ret << "\n";
+ LOG(ERROR) << "hw_get_module_by_class returned " << ret;
return;
}
if (module->module_api_version == KEYMASTER_MODULE_API_VERSION_1_0) {
keymaster1_device_t* device;
ret = keymaster1_open(module, &device);
if (ret != 0) {
- LOG(ERROR) << "keymaster1_open returned " << ret << "\n";
+ LOG(ERROR) << "keymaster1_open returned " << ret;
return;
}
mDevice = std::make_shared<Keymaster1Device>(device);
@@ -189,12 +189,12 @@
keymaster2_device_t* device;
ret = keymaster2_open(module, &device);
if (ret != 0) {
- LOG(ERROR) << "keymaster2_open returned " << ret << "\n";
+ LOG(ERROR) << "keymaster2_open returned " << ret;
return;
}
mDevice = std::make_shared<Keymaster2Device>(device);
} else {
- LOG(ERROR) << "module_api_version is " << module->module_api_version << "\n";
+ LOG(ERROR) << "module_api_version is " << module->module_api_version;
return;
}
}
@@ -203,7 +203,7 @@
keymaster_key_blob_t keyBlob;
auto error = mDevice->generate_key(&inParams, &keyBlob);
if (error != KM_ERROR_OK) {
- LOG(ERROR) << "generate_key failed, code " << error << "\n";
+ LOG(ERROR) << "generate_key failed, code " << error;
return false;
}
key->assign(reinterpret_cast<const char*>(keyBlob.key_material), keyBlob.key_material_size);
@@ -215,7 +215,7 @@
keymaster_key_blob_t keyBlob{reinterpret_cast<const uint8_t*>(key.data()), key.size()};
auto error = mDevice->delete_key(&keyBlob);
if (error != KM_ERROR_OK) {
- LOG(ERROR) << "delete_key failed, code " << error << "\n";
+ LOG(ERROR) << "delete_key failed, code " << error;
return false;
}
return true;
@@ -229,7 +229,7 @@
keymaster_key_param_set_t outParams_set;
auto error = mDevice->begin(purpose, &keyBlob, &inParams, &outParams_set, &mOpHandle);
if (error != KM_ERROR_OK) {
- LOG(ERROR) << "begin failed, code " << error << "\n";
+ LOG(ERROR) << "begin failed, code " << error;
return KeymasterOperation(nullptr, mOpHandle);
}
outParams->Clear();
@@ -244,7 +244,7 @@
keymaster_operation_handle_t mOpHandle;
auto error = mDevice->begin(purpose, &keyBlob, &inParams, nullptr, &mOpHandle);
if (error != KM_ERROR_OK) {
- LOG(ERROR) << "begin failed, code " << error << "\n";
+ LOG(ERROR) << "begin failed, code " << error;
return KeymasterOperation(nullptr, mOpHandle);
}
return KeymasterOperation(mDevice, mOpHandle);
diff --git a/crypto/ext4crypt/Keymaster3.cpp b/crypto/ext4crypt/Keymaster3.cpp
index f8774f2..7862044 100644
--- a/crypto/ext4crypt/Keymaster3.cpp
+++ b/crypto/ext4crypt/Keymaster3.cpp
@@ -56,17 +56,17 @@
auto inputBlob = blob2hidlVec(reinterpret_cast<const uint8_t*>(&*it), toRead);
auto error = mDevice->update(mOpHandle, hidl_vec<KeyParameter>(), inputBlob, hidlCB);
if (!error.isOk()) {
- LOG(ERROR) << "update failed: " << error.description() << "\n";
+ LOG(ERROR) << "update failed: " << error.description();
mDevice = nullptr;
return false;
}
if (km_error != ErrorCode::OK) {
- LOG(ERROR) << "update failed, code " << int32_t(km_error) << "\n";
+ LOG(ERROR) << "update failed, code " << int32_t(km_error);
mDevice = nullptr;
return false;
}
if (inputConsumed > toRead) {
- LOG(ERROR) << "update reported too much input consumed\n";
+ LOG(ERROR) << "update reported too much input consumed";
mDevice = nullptr;
return false;
}
@@ -88,11 +88,11 @@
hidl_vec<uint8_t>(), hidlCb);
mDevice = nullptr;
if (!error.isOk()) {
- LOG(ERROR) << "finish failed: " << error.description() << "\n";
+ LOG(ERROR) << "finish failed: " << error.description();
return false;
}
if (km_error != ErrorCode::OK) {
- LOG(ERROR) << "finish failed, code " << int32_t(km_error) << "\n";
+ LOG(ERROR) << "finish failed, code " << int32_t(km_error);
return false;
}
return true;
@@ -114,27 +114,27 @@
auto error = mDevice->generateKey(inParams.hidl_data(), hidlCb);
if (!error.isOk()) {
- LOG(ERROR) << "generate_key failed: " << error.description() << "\n";
+ LOG(ERROR) << "generate_key failed: " << error.description();
return false;
}
if (km_error != ErrorCode::OK) {
- LOG(ERROR) << "generate_key failed, code " << int32_t(km_error) << "\n";
+ LOG(ERROR) << "generate_key failed, code " << int32_t(km_error);
return false;
}
return true;
}*/
bool Keymaster::deleteKey(const std::string& key) {
- LOG(ERROR) << "NOT deleting key in TWRP\n";
+ LOG(ERROR) << "NOT deleting key in TWRP";
return false;
/*auto keyBlob = blob2hidlVec(key);
auto error = mDevice->deleteKey(keyBlob);
if (!error.isOk()) {
- LOG(ERROR) << "delete_key failed: " << error.description() << "\n";
+ LOG(ERROR) << "delete_key failed: " << error.description();
return false;
}
if (ErrorCode(error) != ErrorCode::OK) {
- LOG(ERROR) << "delete_key failed, code " << uint32_t(ErrorCode(error)) << "\n";
+ LOG(ERROR) << "delete_key failed, code " << uint32_t(ErrorCode(error));
return false;
}
return true;*/
@@ -153,11 +153,11 @@
};
auto error = mDevice->upgradeKey(oldKeyBlob, inParams.hidl_data(), hidlCb);
if (!error.isOk()) {
- LOG(ERROR) << "upgrade_key failed: " << error.description() << "\n";
+ LOG(ERROR) << "upgrade_key failed: " << error.description();
return false;
}
if (km_error != ErrorCode::OK) {
- LOG(ERROR) << "upgrade_key failed, code " << int32_t(km_error) << "\n";
+ LOG(ERROR) << "upgrade_key failed, code " << int32_t(km_error);
return false;
}
return true;
@@ -181,11 +181,11 @@
auto error = mDevice->begin(purpose, keyBlob, inParams.hidl_data(), hidlCb);
if (!error.isOk()) {
- LOG(ERROR) << "begin failed: " << error.description() << "\n";
+ LOG(ERROR) << "begin failed: " << error.description();
return KeymasterOperation(ErrorCode::UNKNOWN_ERROR);
}
if (km_error != ErrorCode::OK) {
- LOG(ERROR) << "begin failed, code " << int32_t(km_error) << "\n";
+ LOG(ERROR) << "begin failed, code " << int32_t(km_error);
return KeymasterOperation(km_error);
}
return KeymasterOperation(mDevice, mOpHandle);
@@ -207,7 +207,7 @@
int keymaster_compatibility_cryptfs_scrypt() {
Keymaster dev;
if (!dev) {
- LOG(ERROR) << "Failed to initiate keymaster session\n";
+ LOG(ERROR) << "Failed to initiate keymaster session";
return -1;
}
return dev.isSecure();
@@ -224,11 +224,11 @@
Keymaster dev;
std::string key;
if (!dev) {
- LOG(ERROR) << "Failed to initiate keymaster session\n";
+ LOG(ERROR) << "Failed to initiate keymaster session";
return -1;
}
if (!key_buffer || !key_out_size) {
- LOG(ERROR) << __FILE__ << ":" << __LINE__ << ":Invalid argument\n";
+ LOG(ERROR) << __FILE__ << ":" << __LINE__ << ":Invalid argument";
return -1;
}
if (key_out_size) {
@@ -276,11 +276,11 @@
{
Keymaster dev;
if (!dev) {
- LOG(ERROR) << "Failed to initiate keymaster session\n";
+ LOG(ERROR) << "Failed to initiate keymaster session";
return -1;
}
if (!key_blob || !object || !signature_buffer || !signature_buffer_size) {
- LOG(ERROR) << __FILE__ << ":" << __LINE__ << ":Invalid argument\n";
+ LOG(ERROR) << __FILE__ << ":" << __LINE__ << ":Invalid argument";
return -1;
}
@@ -303,7 +303,7 @@
std::string newKey;
bool ret = dev.upgradeKey(key, paramBuilder, &newKey);
if(ret == false) {
- LOG(ERROR) << "Error upgradeKey: \n";
+ LOG(ERROR) << "Error upgradeKey: ";
return -1;
}
@@ -312,7 +312,7 @@
}
if (key_buffer_size < newKey.size()) {
- LOG(ERROR) << "key buffer size is too small\n";
+ LOG(ERROR) << "key buffer size is too small";
return -1;
}
@@ -322,24 +322,24 @@
}
if (op.errorCode() != ErrorCode::OK) {
- LOG(ERROR) << "Error starting keymaster signature transaction: " << int32_t(op.errorCode()) << "\n";
+ LOG(ERROR) << "Error starting keymaster signature transaction: " << int32_t(op.errorCode());
return -1;
}
if (!op.updateCompletely(input, &output)) {
LOG(ERROR) << "Error sending data to keymaster signature transaction: "
- << uint32_t(op.errorCode()) << "\n";
+ << uint32_t(op.errorCode());
return -1;
}
if (!op.finish(&output)) {
- LOG(ERROR) << "Error finalizing keymaster signature transaction: " << int32_t(op.errorCode()) << "\n";
+ LOG(ERROR) << "Error finalizing keymaster signature transaction: " << int32_t(op.errorCode());
return -1;
}
*signature_buffer = reinterpret_cast<uint8_t*>(malloc(output.size()));
if (*signature_buffer == nullptr) {
- LOG(ERROR) << "Error allocation buffer for keymaster signature\n";
+ LOG(ERROR) << "Error allocation buffer for keymaster signature";
return -1;
}
*signature_buffer_size = output.size();
diff --git a/crypto/ext4crypt/ext4_crypt.h b/crypto/ext4crypt/ext4_crypt.h
new file mode 100644
index 0000000..d410ccf
--- /dev/null
+++ b/crypto/ext4crypt/ext4_crypt.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _EXT4_CRYPT_H_
+#define _EXT4_CRYPT_H_
+
+#include <sys/cdefs.h>
+#include <stdbool.h>
+#include <cutils/multiuser.h>
+
+__BEGIN_DECLS
+
+bool e4crypt_is_native();
+
+int e4crypt_policy_ensure(const char *directory, const char *policy,
+ size_t policy_length,
+ const char *contents_encryption_mode,
+ const char *filenames_encryption_mode);
+
+static const char* e4crypt_unencrypted_folder = "/unencrypted";
+static const char* e4crypt_key_ref = "/unencrypted/ref";
+static const char* e4crypt_key_mode = "/unencrypted/mode";
+
+__END_DECLS
+
+#endif // _EXT4_CRYPT_H_
diff --git a/crypto/fde/Android.mk b/crypto/fde/Android.mk
index aafd7a0..fcdd564 100644
--- a/crypto/fde/Android.mk
+++ b/crypto/fde/Android.mk
@@ -3,7 +3,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := libcryptfsfde
-LOCAL_MODULE_TAGS := eng optional
+LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := cryptfs.cpp
LOCAL_SHARED_LIBRARIES := libcrypto libhardware libcutils libstdc++
LOCAL_STATIC_LIBRARIES := libscrypttwrp_static
diff --git a/crypto/fde/cryptfs.cpp b/crypto/fde/cryptfs.cpp
index 5b8757c..8352296 100644
--- a/crypto/fde/cryptfs.cpp
+++ b/crypto/fde/cryptfs.cpp
@@ -256,7 +256,7 @@
if (should_use_keymaster()) {
if (scrypt_keymaster(passwd, salt, newpw, (void*)ftr)) {
- SLOGE("scrypt failed\n");
+ SLOGE("scrypt failed");
} else {
rc = 0;
}
@@ -293,7 +293,7 @@
++crypt_ftr->failed_decrypt_count;
if (ascii_passwd_updated) {
- SLOGI("Ascii password was updated\n");
+ SLOGI("Ascii password was updated");
} else {
/* Code in else part would execute only once:
* When device is upgraded from L->M release.
@@ -305,14 +305,14 @@
if (crypt_ftr->crypt_type == CRYPT_TYPE_DEFAULT) {
new_passwd = (char*)malloc(strlen(DEFAULT_HEX_PASSWORD) + 1);
if (new_passwd == NULL) {
- SLOGE("System out of memory. Password verification incomplete\n");
+ SLOGE("System out of memory. Password verification incomplete");
goto out;
}
strlcpy(new_passwd, DEFAULT_HEX_PASSWORD, strlen(DEFAULT_HEX_PASSWORD) + 1);
} else {
new_passwd = (char*)malloc(strlen(passwd) * 2 + 1);
if (new_passwd == NULL) {
- SLOGE("System out of memory. Password verification incomplete\n");
+ SLOGE("System out of memory. Password verification incomplete");
goto out;
}
convert_key_to_hex_ascii_for_upgrade((const unsigned char*)passwd,
@@ -322,7 +322,7 @@
(char*) crypt_ftr->crypto_type_name);
if (key_index >=0) {
crypt_ftr->failed_decrypt_count = 0;
- SLOGI("Hex password verified...will try to update with Ascii value\n");
+ SLOGI("Hex password verified...will try to update with Ascii value");
/* Before updating password, tie that with keymaster to tie with ROT */
if (get_keymaster_hw_fde_passwd(passwd, newpw,
@@ -336,9 +336,9 @@
if (passwd_updated >= 0) {
crypt_ftr->flags |= CRYPT_ASCII_PASSWORD_UPDATED;
- SLOGI("Ascii password recorded and updated\n");
+ SLOGI("Ascii password recorded and updated");
} else {
- SLOGI("Passwd verified, could not update...Will try next time\n");
+ SLOGI("Passwd verified, could not update...Will try next time");
}
} else {
++crypt_ftr->failed_decrypt_count;
@@ -412,10 +412,10 @@
// so) because we really should be using a proper deterministic
// RSA padding function, such as PKCS1.
memcpy(to_sign + 1, object, min((size_t)RSA_KEY_SIZE_BYTES - 1, object_size));
- SLOGI("Signing safely-padded object\n");
+ SLOGI("Signing safely-padded object");
break;
default:
- SLOGE("Unknown KDF type %d\n", ftr->kdf_type);
+ SLOGE("Unknown KDF type %d", ftr->kdf_type);
return -1;
}
@@ -549,7 +549,7 @@
return -1;
}
/*if (put_crypt_ftr_and_key(ftr) != 0) {
- SLOGE("Failed to write upgraded key to disk\n");
+ SLOGE("Failed to write upgraded key to disk");
}*/
SLOGD("Key upgraded successfully\n");
return 0;
@@ -930,8 +930,8 @@
crypt_ftr->crypto_type_name, master_key_ascii,
real_blk_name, extra_params);
- SLOGI("target_type = %s\n", tgt->target_type);
- SLOGI("real_blk_name = %s, extra_params = %s\n", real_blk_name, extra_params);
+ SLOGI("target_type = %s", tgt->target_type);
+ SLOGI("real_blk_name = %s, extra_params = %s", real_blk_name, extra_params);
#else
convert_key_to_hex_ascii(master_key, crypt_ftr->keysize, master_key_ascii);
strlcpy(tgt->target_type, "crypt", DM_MAX_TYPE_NAME);
@@ -1205,13 +1205,13 @@
INTERMEDIATE_BUF_SIZE);
if (rc) {
- SLOGE("scrypt failed\n");
+ SLOGE("scrypt failed");
return -1;
}
if (keymaster_sign_object(ftr, ikey, INTERMEDIATE_BUF_SIZE,
&signature, &signature_size)) {
- SLOGE("Keymaster signing failed\n");
+ SLOGE("Keymaster signing failed");
return -1;
}
@@ -1220,7 +1220,7 @@
free(signature);
if (rc) {
- SLOGE("scrypt failed\n");
+ SLOGE("scrypt failed");
return -1;
}
@@ -1242,7 +1242,7 @@
/* Turn the password into an intermediate key and IV that can decrypt the
master key */
if (kdf(passwd, salt, ikey, kdf_params)) {
- SLOGE("kdf failed\n");
+ SLOGE("kdf failed");
return -1;
}
@@ -1308,7 +1308,7 @@
decrypted_master_key, kdf, kdf_params,
intermediate_key, intermediate_key_size);
if (ret != 0) {
- SLOGW("failure decrypting master key\n");
+ SLOGW("failure decrypting master key");
}
return ret;
@@ -1332,13 +1332,6 @@
int key_index = 0;
if(is_hw_disk_encryption((char*)crypt_ftr->crypto_type_name)) {
- if (crypt_ftr->flags & CRYPT_FORCE_COMPLETE) {
- if (decrypt_master_key(passwd, decrypted_master_key, crypt_ftr, 0, 0)) {
- printf("Failed to decrypt master key\n");
- rc = -1;
- goto errout;
- }
- }
key_index = verify_and_update_hw_fde_passwd(passwd, crypt_ftr);
if (key_index < 0) {
rc = -1;
@@ -1349,7 +1342,7 @@
#ifndef CONFIG_HW_DISK_ENCRYPT_PERF
if (create_crypto_blk_dev(crypt_ftr, (unsigned char*)&key_index,
real_blkdev, crypto_blkdev, label, 0)) {
- SLOGE("Error creating decrypted block device\n");
+ SLOGE("Error creating decrypted block device");
rc = -1;
goto errout;
}
@@ -1357,7 +1350,7 @@
} else {
if (create_crypto_blk_dev(crypt_ftr, decrypted_master_key,
real_blkdev, crypto_blkdev, label, 0)) {
- SLOGE("Error creating decrypted block device\n");
+ SLOGE("Error creating decrypted block device");
rc = -1;
goto errout;
}
@@ -1403,7 +1396,7 @@
//char real_blkdev[MAXPATHLEN];
char tmp_mount_point[64];
unsigned int orig_failed_decrypt_count;
- int rc = 0;
+ int rc;
int use_keymaster = 0;
unsigned char* intermediate_key = 0;
size_t intermediate_key_size = 0;
@@ -1446,7 +1439,7 @@
if (rc == 0 && memcmp(scrypted_intermediate_key,
crypt_ftr->scrypted_intermediate_key,
sizeof(scrypted_intermediate_key)) == 0) {
- SLOGI("Password matches\n");
+ SLOGI("Password matches");
rc = 0;
} else {
/* Try mounting the file system anyway, just in case the problem's with
@@ -1461,7 +1454,7 @@
rc = -1;
} else {
/* Success! */
- SLOGI("Password did not match but decrypted drive mounted - continue\n");
+ SLOGI("Password did not match but decrypted drive mounted - continue");
umount(tmp_mount_point);
rc = 0;
}
@@ -1501,7 +1494,7 @@
const unsigned char* key, int keysize, char* out_crypto_blkdev) {
int fd = open(real_blkdev, O_RDONLY|O_CLOEXEC);
if (fd == -1) {
- SLOGE("Failed to open %s: %s\n", real_blkdev, strerror(errno));
+ SLOGE("Failed to open %s: %s", real_blkdev, strerror(errno));
return -1;
}
@@ -1510,7 +1503,7 @@
close(fd);
if (nr_sec == 0) {
- SLOGE("Failed to get size of %s: %s\n", real_blkdev, strerror(errno));
+ SLOGE("Failed to get size of %s: %s", real_blkdev, strerror(errno));
return -1;
}
@@ -1542,12 +1535,12 @@
property_get("ro.crypto.state", encrypted_state, "");
if ( master_key_saved || strcmp(encrypted_state, "encrypted") ) {
SLOGE("encrypted fs already validated or not running with encryption,"
- " aborting\n");
+ " aborting");
return -1;
}
if (get_crypt_ftr_and_key(crypt_ftr)) {
- SLOGE("Error getting crypt footer and key\n");
+ SLOGE("Error getting crypt footer and key");
return -1;
}
@@ -1558,11 +1551,11 @@
int cryptfs_check_passwd_hw(const char* passwd)
{
struct crypt_mnt_ftr crypt_ftr;
- int rc = 0;
+ int rc;
unsigned char master_key[KEY_LEN_BYTES];
/* get key */
if (get_crypt_ftr_and_key(&crypt_ftr)) {
- SLOGE("Error getting crypt footer and key\n");
+ SLOGE("Error getting crypt footer and key");
return -1;
}
@@ -1576,7 +1569,7 @@
*/
rc = cryptfs_get_master_key(&crypt_ftr, passwd, master_key);
if (rc) {
- SLOGE("password doesn't match\n");
+ SLOGE("password doesn't match");
return rc;
}
@@ -1584,7 +1577,7 @@
DATA_MNT_POINT, CRYPTO_BLOCK_DEVICE);
if (rc) {
- SLOGE("Default password did not match on reboot encryption\n");
+ SLOGE("Default password did not match on reboot encryption");
return rc;
}
} else {
@@ -1600,7 +1593,7 @@
int cryptfs_check_passwd(const char *passwd)
{
/*if (e4crypt_is_native()) {
- SLOGE("cryptfs_check_passwd not valid for file encryption\n");
+ SLOGE("cryptfs_check_passwd not valid for file encryption");
return -1;
}*/
@@ -1609,7 +1602,7 @@
rc = check_unmounted_and_get_ftr(&crypt_ftr);
if (rc) {
- SLOGE("Could not get footer\n");
+ SLOGE("Could not get footer");
return rc;
}
@@ -1622,7 +1615,7 @@
DATA_MNT_POINT, CRYPTO_BLOCK_DEVICE);
if (rc) {
- SLOGE("Password did not match\n");
+ SLOGE("Password did not match");
return rc;
}
@@ -1635,7 +1628,7 @@
rc = test_mount_encrypted_fs(&crypt_ftr, DEFAULT_PASSWORD,
DATA_MNT_POINT, CRYPTO_BLOCK_DEVICE);
if (rc) {
- SLOGE("Default password did not match on reboot encryption\n");
+ SLOGE("Default password did not match on reboot encryption");
return rc;
}
}
@@ -1652,17 +1645,17 @@
property_get("ro.crypto.state", encrypted_state, "");
if (strcmp(encrypted_state, "encrypted") ) {
- SLOGE("device not encrypted, aborting\n");
+ SLOGE("device not encrypted, aborting");
return -2;
}
if (!master_key_saved) {
- SLOGE("encrypted fs not yet mounted, aborting\n");
+ SLOGE("encrypted fs not yet mounted, aborting");
return -1;
}
if (!saved_mount_point) {
- SLOGE("encrypted fs failed to save mount point, aborting\n");
+ SLOGE("encrypted fs failed to save mount point, aborting");
return -1;
}
@@ -1742,7 +1735,7 @@
&intermediate_key_size);
if (rc) {
- SLOGE("Can't calculate intermediate key\n");
+ SLOGE("Can't calculate intermediate key");
return rc;
}
@@ -1760,7 +1753,7 @@
free(intermediate_key);
if (rc) {
- SLOGE("Can't scrypt intermediate key\n");
+ SLOGE("Can't scrypt intermediate key");
return rc;
}
diff --git a/crypto/vold_decrypt/Android.mk b/crypto/vold_decrypt/Android.mk
index 860e61f..8d60911 100644
--- a/crypto/vold_decrypt/Android.mk
+++ b/crypto/vold_decrypt/Android.mk
@@ -39,7 +39,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := init.recovery.vold_decrypt.rc
- LOCAL_MODULE_TAGS := eng
+ LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
# Cannot send to TARGET_RECOVERY_ROOT_OUT since build system wipes init*.rc
@@ -75,7 +75,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := libvolddecrypt
- LOCAL_MODULE_TAGS := eng optional
+ LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS := -Wall
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
LOCAL_C_INCLUDES += external/stlport/stlport bionic bionic/libstdc++/include
@@ -115,7 +115,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := vdc_pie
LOCAL_SRC_FILES := vdc_pie.cpp
- LOCAL_MODULE_TAGS := eng
+ LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_CLANG := true
diff --git a/etc/Android.mk b/etc/Android.mk
index ca549ea..a59a54c 100644
--- a/etc/Android.mk
+++ b/etc/Android.mk
@@ -18,7 +18,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := init.recovery.usb.rc
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
# Cannot send to TARGET_RECOVERY_ROOT_OUT since build system wipes init*.rc
@@ -34,7 +34,7 @@
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 22; echo $$?),0)
include $(CLEAR_VARS)
LOCAL_MODULE := init.recovery.service.rc
- LOCAL_MODULE_TAGS := eng
+ LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
@@ -43,7 +43,7 @@
else
include $(CLEAR_VARS)
LOCAL_MODULE := init.recovery.service.rc
- LOCAL_MODULE_TAGS := eng
+ LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
@@ -54,7 +54,7 @@
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 26; echo $$?),0)
include $(CLEAR_VARS)
LOCAL_MODULE := init.recovery.hlthchrg.rc
- LOCAL_MODULE_TAGS := eng
+ LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
@@ -72,7 +72,7 @@
else
include $(CLEAR_VARS)
LOCAL_MODULE := init.recovery.hlthchrg.rc
- LOCAL_MODULE_TAGS := eng
+ LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
@@ -85,7 +85,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := init.recovery.logd.rc
- LOCAL_MODULE_TAGS := eng
+ LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
# Cannot send to TARGET_RECOVERY_ROOT_OUT since build system wipes init*.rc
@@ -101,7 +101,7 @@
ifeq ($(TW_USE_TOOLBOX), true)
include $(CLEAR_VARS)
LOCAL_MODULE := init.recovery.mksh.rc
- LOCAL_MODULE_TAGS := eng
+ LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
# Cannot send to TARGET_RECOVERY_ROOT_OUT since build system wipes init*.rc
diff --git a/etc/init.rc b/etc/init.rc
old mode 100644
new mode 100755
index c5138aa..b96016c
--- a/etc/init.rc
+++ b/etc/init.rc
@@ -7,26 +7,11 @@
import /init.recovery.${ro.hardware}.rc
on early-init
- # Apply strict SELinux checking of PROT_EXEC on mmap/mprotect calls.
- write /sys/fs/selinux/checkreqprot 0
-
- # Set the security context for the init process.
- # This should occur before anything else (e.g. ueventd) is started.
- setcon u:r:init:s0
-
# Set the security context of /postinstall if present.
restorecon /postinstall
start ueventd
-<<<<<<< HEAD
-service set_permissive /sbin/permissive.sh
- oneshot
- seclabel u:r:recovery:s0
-=======
- setprop sys.usb.configfs 0
->>>>>>> android-10.0.0_r25
-
on init
export PATH /sbin:/system/bin
export LD_LIBRARY_PATH /sbin
@@ -35,8 +20,6 @@
export ANDROID_DATA /data
export EXTERNAL_STORAGE /sdcard
-<<<<<<< HEAD
-=======
symlink /proc/self/fd/0 /dev/stdin
symlink /proc/self/fd/1 /dev/stdout
symlink /proc/self/fd/2 /dev/stderr
@@ -44,7 +27,6 @@
symlink /system/bin /bin
symlink /system/etc /etc
->>>>>>> android-10.0.0_r25
mount cgroup none /acct cpuacct
mkdir /acct/uid
@@ -61,15 +43,12 @@
write /proc/sys/kernel/panic_on_oops 1
write /proc/sys/vm/max_map_count 1000000
-<<<<<<< HEAD
on fs
mount pstore pstore /sys/fs/pstore
mkdir /dev/usb-ffs 0770 shell shell
mkdir /dev/usb-ffs/adb 0770 shell shell
mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=2000
-=======
->>>>>>> android-10.0.0_r25
on boot
ifup lo
hostname localhost
@@ -116,7 +95,6 @@
trigger early-boot
trigger boot
-<<<<<<< HEAD
on property:sys.powerctl=*
powerctl ${sys.powerctl}
@@ -125,37 +103,20 @@
seclabel u:r:ueventd:s0
service adbd /sbin/adbd --root_seclabel=u:r:su:s0 --device_banner=recovery
-=======
-service ueventd /system/bin/ueventd
- critical
- seclabel u:r:ueventd:s0
-
-service charger /system/bin/charger
- critical
- seclabel u:r:charger:s0
-
-service recovery /system/bin/recovery
- socket recovery stream 422 system system
- seclabel u:r:recovery:s0
-
-service adbd /system/bin/adbd --root_seclabel=u:r:su:s0 --device_banner=recovery
->>>>>>> android-10.0.0_r25
disabled
socket adbd stream 660 system system
seclabel u:r:adbd:s0
-<<<<<<< HEAD
# Always start adbd on userdebug and eng builds
on property:ro.debuggable=1
#write /sys/class/android_usb/android0/enable 1
#start adbd
setprop service.adb.root 1
-=======
-service fastbootd /system/bin/fastbootd
+
+service fastbootd /sbin/fastbootd
disabled
group system
seclabel u:r:fastbootd:s0
->>>>>>> android-10.0.0_r25
# Restart adbd so it can run as root
on property:service.adb.root=1
diff --git a/etc/init.recovery.service22.rc b/etc/init.recovery.service22.rc
old mode 100644
new mode 100755
index bb2853c..438bb3b
--- a/etc/init.recovery.service22.rc
+++ b/etc/init.recovery.service22.rc
@@ -3,3 +3,6 @@
# For starting recovery on 5.0 and newer
service recovery /sbin/recovery
seclabel u:r:recovery:s0
+
+on early-init
+ write /sys/fs/selinux/enforce 0
diff --git a/etc/init28.rc b/etc/init28.rc
new file mode 100755
index 0000000..0b2a4ef
--- /dev/null
+++ b/etc/init28.rc
@@ -0,0 +1,225 @@
+import /init.recovery.logd.rc
+import /init.recovery.ldconfig.rc
+import /init.recovery.mksh.rc
+import /init.recovery.usb.rc
+import /init.recovery.service.rc
+import /init.recovery.vold_decrypt.rc
+import /init.recovery.${ro.hardware}.rc
+
+on early-init
+ # Apply strict SELinux checking of PROT_EXEC on mmap/mprotect calls.
+ write /sys/fs/selinux/checkreqprot 0
+
+ # Set the security context for the init process.
+ # This should occur before anything else (e.g. ueventd) is started.
+ setcon u:r:init:s0
+
+ # Set the security context of /postinstall if present.
+ restorecon /postinstall
+
+ start ueventd
+
+service set_permissive /sbin/permissive.sh
+ oneshot
+ seclabel u:r:recovery:s0
+
+on init
+ export PATH /sbin:/system/bin
+ export LD_LIBRARY_PATH /sbin
+
+ export ANDROID_ROOT /system
+ export ANDROID_DATA /data
+ export EXTERNAL_STORAGE /sdcard
+
+ symlink /proc/self/fd/0 /dev/stdin
+ symlink /proc/self/fd/1 /dev/stdout
+ symlink /proc/self/fd/2 /dev/stderr
+
+ symlink /system/bin /bin
+ symlink /system/etc /etc
+
+ mount cgroup none /acct cpuacct
+ mkdir /acct/uid
+
+ mkdir /system
+ mkdir /data
+ mkdir /cache
+ mkdir /sideload
+ mkdir /mnt/system
+ mount tmpfs tmpfs /tmp
+
+ chown root shell /tmp
+ chmod 0775 /tmp
+
+ write /proc/sys/kernel/panic_on_oops 1
+ write /proc/sys/vm/max_map_count 1000000
+
+on fs
+ mount pstore pstore /sys/fs/pstore
+ mkdir /dev/usb-ffs 0770 shell shell
+ mkdir /dev/usb-ffs/adb 0770 shell shell
+ mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=2000
+
+on boot
+ ifup lo
+ hostname localhost
+ domainname localdomain
+
+ class_start default
+
+# Load properties, pre-Android 6.0
+on load_all_props_action
+ load_all_props
+
+# Load properties, Android 6.0+
+on load_system_props_action
+ load_system_props
+
+# Load properties, Android 6.0+, vendor init lives here
+on load_persist_props_action
+ load_persist_props
+
+on firmware_mounts_complete
+ rm /dev/.booting
+
+# Mount filesystems and start core system services.
+on late-init
+ trigger early-fs
+ trigger fs
+ trigger post-fs
+ trigger post-fs-data
+
+ # Load properties, pre-Android 6.0
+ trigger load_all_props_action
+
+ # Load properties from /system/ + /factory after fs mount. Place
+ # this in another action so that the load will be scheduled after the prior
+ # issued fs triggers have completed.
+ trigger load_system_props_action
+
+ # Load properties, Android 6.0+, vendor init lives here
+ trigger load_persist_props_action
+
+ # Remove a file to wake up anything waiting for firmware
+ trigger firmware_mounts_complete
+
+ trigger early-boot
+ trigger boot
+
+on property:sys.powerctl=*
+ powerctl ${sys.powerctl}
+
+service ueventd /sbin/ueventd
+ critical
+ seclabel u:r:ueventd:s0
+
+service adbd /sbin/adbd --root_seclabel=u:r:su:s0 --device_banner=recovery
+ disabled
+ socket adbd stream 660 system system
+ seclabel u:r:adbd:s0
+
+# Always start adbd on userdebug and eng builds
+on property:ro.debuggable=1
+ #write /sys/class/android_usb/android0/enable 1
+ #start adbd
+ setprop service.adb.root 1
+
+service fastbootd /sbin/fastbootd
+ disabled
+ group system
+ seclabel u:r:fastbootd:s0
+
+# Restart adbd so it can run as root
+on property:service.adb.root=1
+ restart adbd
+
+# Always start adbd on userdebug and eng builds
+on fs && property:ro.debuggable=1
+ setprop sys.usb.config adb
+
+on fs && property:sys.usb.configfs=1
+ mount configfs none /config
+ mkdir /config/usb_gadget/g1 0770 shell shell
+ write /config/usb_gadget/g1/idVendor 0x18D1
+ mkdir /config/usb_gadget/g1/strings/0x409 0770
+ write /config/usb_gadget/g1/strings/0x409/serialnumber ${ro.serialno}
+ write /config/usb_gadget/g1/strings/0x409/manufacturer ${ro.product.manufacturer}
+ write /config/usb_gadget/g1/strings/0x409/product ${ro.product.model}
+ mkdir /config/usb_gadget/g1/functions/ffs.adb
+ mkdir /config/usb_gadget/g1/functions/ffs.fastboot
+ mkdir /config/usb_gadget/g1/configs/b.1 0777 shell shell
+ mkdir /config/usb_gadget/g1/configs/b.1/strings/0x409 0770 shell shell
+
+on fs && property:sys.usb.configfs=0
+ write /sys/class/android_usb/android0/f_ffs/aliases adb,fastboot
+ write /sys/class/android_usb/android0/idVendor 18D1
+ write /sys/class/android_usb/android0/iManufacturer ${ro.product.manufacturer}
+ write /sys/class/android_usb/android0/iProduct ${ro.product.model}
+ write /sys/class/android_usb/android0/iSerial ${ro.serialno}
+
+on fs
+ mkdir /dev/usb-ffs 0775 shell shell
+ mkdir /dev/usb-ffs/adb 0770 shell shell
+ mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=2000
+ mkdir /dev/usb-ffs/fastboot 0770 system system
+ mount functionfs fastboot /dev/usb-ffs/fastboot rmode=0770,fmode=0660,uid=1000,gid=1000
+
+on property:sys.usb.config=adb
+ start adbd
+
+on property:sys.usb.config=fastboot
+ start fastbootd
+
+on property:sys.usb.config=none && property:sys.usb.configfs=0
+ stop adbd
+ stop fastboot
+ write /sys/class/android_usb/android0/enable 0
+ setprop sys.usb.state ${sys.usb.config}
+
+on property:sys.usb.config=adb && property:sys.usb.configfs=0
+ write /sys/class/android_usb/android0/idProduct D001
+ write /sys/class/android_usb/android0/functions adb
+ write /sys/class/android_usb/android0/enable 1
+ setprop sys.usb.state ${sys.usb.config}
+
+on property:sys.usb.config=sideload && property:sys.usb.configfs=0
+ write /sys/class/android_usb/android0/idProduct D001
+ write /sys/class/android_usb/android0/functions adb
+ write /sys/class/android_usb/android0/enable 1
+ setprop sys.usb.state ${sys.usb.config}
+
+on property:sys.usb.config=fastboot && property:sys.usb.configfs=0
+ write /sys/class/android_usb/android0/idProduct 4EE0
+ write /sys/class/android_usb/android0/functions fastboot
+ write /sys/class/android_usb/android0/enable 1
+ setprop sys.usb.state ${sys.usb.config}
+
+# Configfs triggers
+on property:sys.usb.config=none && property:sys.usb.configfs=1
+ write /config/usb_gadget/g1/UDC "none"
+ stop adbd
+ stop fastbootd
+ setprop sys.usb.ffs.ready 0
+ rm /config/usb_gadget/g1/configs/b.1/f1
+ setprop sys.usb.state ${sys.usb.config}
+
+on property:sys.usb.config=sideload && property:sys.usb.ffs.ready=1 && property:sys.usb.configfs=1
+ write /config/usb_gadget/g1/idProduct 0xD001
+ write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "adb"
+ symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f1
+ write /config/usb_gadget/g1/UDC ${sys.usb.controller}
+ setprop sys.usb.state ${sys.usb.config}
+
+on property:sys.usb.config=adb && property:sys.usb.ffs.ready=1 && property:sys.usb.configfs=1
+ write /config/usb_gadget/g1/idProduct 0xD001
+ write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "adb"
+ symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f1
+ write /config/usb_gadget/g1/UDC ${sys.usb.controller}
+ setprop sys.usb.state ${sys.usb.config}
+
+on property:sys.usb.config=fastboot && property:sys.usb.ffs.ready=1 && property:sys.usb.configfs=1
+ write /config/usb_gadget/g1/idProduct 0x4EE0
+ write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "fastboot"
+ symlink /config/usb_gadget/g1/functions/ffs.fastboot /config/usb_gadget/g1/configs/b.1/f1
+ write /config/usb_gadget/g1/UDC ${sys.usb.controller}
+ setprop sys.usb.state ${sys.usb.config}
diff --git a/fb2png/Android.mk b/fb2png/Android.mk
index e82495d..8d19868 100644
--- a/fb2png/Android.mk
+++ b/fb2png/Android.mk
@@ -62,7 +62,7 @@
LOCAL_SRC_FILES := main.c
LOCAL_MODULE := fb2png
LOCAL_FORCE_STATIC_EXECUTABLE := true
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS += -DANDROID
LOCAL_STATIC_LIBRARIES := libfb2png libpng libz libc
diff --git a/flashutils/Android.mk b/flashutils/Android.mk
index ab552b1..1c5872e 100644
--- a/flashutils/Android.mk
+++ b/flashutils/Android.mk
@@ -81,7 +81,7 @@
include $(CLEAR_VARS)
LOCAL_SRC_FILES := flashutils.c
LOCAL_MODULE := libflashutils
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES += $(commands_recovery_local_path)
LOCAL_SHARED_LIBRARIES := libc libmtdutils libmmcutils libbmlutils libcrecovery
@@ -97,7 +97,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := flash_image
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_SRC_FILES := flash_image.c
@@ -106,7 +106,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := dump_image
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_SRC_FILES := dump_image.c
@@ -115,7 +115,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := erase_image
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_SRC_FILES := erase_image.c
diff --git a/fuse_sideload/fuse_sideload.cpp b/fuse_sideload/fuse_sideload.cpp
index 8fa8ad4..3d94803 100644
--- a/fuse_sideload/fuse_sideload.cpp
+++ b/fuse_sideload/fuse_sideload.cpp
@@ -45,9 +45,8 @@
#include <errno.h>
#include <fcntl.h>
-#include <limits.h>
-#include "fuse.h"
-#include <pthread.h>
+#include <limits.h> // PATH_MAX
+#include <linux/fuse.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -58,19 +57,13 @@
#include <sys/uio.h>
#include <unistd.h>
-#ifdef USE_MINCRYPT
-#include "mincrypt/sha256.h"
-#define SHA256_DIGEST_LENGTH SHA256_DIGEST_SIZE
-#else
-#include <openssl/sha.h>
-#endif
-
#include <array>
#include <string>
#include <vector>
-//#include <android-base/stringprintf.h>
-//#include <android-base/unique_fd.h>
+#include <android-base/stringprintf.h>
+#include <android-base/unique_fd.h>
+#include <openssl/sha.h>
static constexpr uint64_t PACKAGE_FILE_ID = FUSE_ROOT_ID + 1;
static constexpr uint64_t EXIT_FLAG_ID = FUSE_ROOT_ID + 2;
@@ -80,12 +73,8 @@
using SHA256Digest = std::array<uint8_t, SHA256_DIGEST_LENGTH>;
-#ifndef MIN
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#endif
-
struct fuse_data {
- int ffd; // file descriptor for the fuse socket
+ android::base::unique_fd ffd; // file descriptor for the fuse socket
FuseDataProvider* provider; // Provider of the source data.
@@ -102,8 +91,8 @@
uint8_t* extra_block; // another block of storage for reads that span two blocks
- uint8_t* hashes; // SHA-256 hash of each block (all zeros
- // if block hasn't been read yet)
+ std::vector<SHA256Digest>
+ hashes; // SHA-256 hash of each block (all zeros if block hasn't been read yet)
};
static void fuse_reply(const fuse_data* fd, uint64_t unique, const void* data, size_t len) {
@@ -162,7 +151,7 @@
static void fill_attr(fuse_attr* attr, const fuse_data* fd, uint64_t nodeid, uint64_t size,
uint32_t mode) {
- memset(attr, 0, sizeof(*attr));
+ *attr = {};
attr->nlink = 1;
attr->uid = fd->uid;
attr->gid = fd->gid;
@@ -175,8 +164,7 @@
}
static int handle_getattr(void* /* data */, const fuse_data* fd, const fuse_in_header* hdr) {
- struct fuse_attr_out out;
- memset(&out, 0, sizeof(out));
+ fuse_attr_out out = {};
out.attr_valid = 10;
if (hdr->nodeid == FUSE_ROOT_ID) {
@@ -196,8 +184,7 @@
static int handle_lookup(void* data, const fuse_data* fd, const fuse_in_header* hdr) {
if (data == nullptr) return -ENOENT;
- struct fuse_entry_out out;
- memset(&out, 0, sizeof(out));
+ fuse_entry_out out = {};
out.entry_valid = 10;
out.attr_valid = 10;
@@ -222,8 +209,7 @@
if (hdr->nodeid == EXIT_FLAG_ID) return -EPERM;
if (hdr->nodeid != PACKAGE_FILE_ID) return -ENOENT;
- struct fuse_open_out out;
- memset(&out, 0, sizeof(out));
+ fuse_open_out out = {};
out.fh = 10; // an arbitrary number; we always use the same handle
fuse_reply(fd, hdr->unique, &out, sizeof(out));
return NO_STATUS;
@@ -271,26 +257,22 @@
// time we've read this block).
// - Otherwise, return -EINVAL for the read.
- uint8_t hash[SHA256_DIGEST_LENGTH];
-#ifdef USE_MINCRYPT
- SHA256_hash(fd->block_data, fd->block_size, hash);
-#else
- SHA256(fd->block_data, fd->block_size, hash);
-#endif
- uint8_t* blockhash = fd->hashes + block * SHA256_DIGEST_LENGTH;
- if (memcmp(hash, blockhash, SHA256_DIGEST_LENGTH) == 0) {
+ SHA256Digest hash;
+ SHA256(fd->block_data, fd->block_size, hash.data());
+
+ const SHA256Digest& blockhash = fd->hashes[block];
+ if (hash == blockhash) {
return 0;
}
- int i;
- for (i = 0; i < SHA256_DIGEST_LENGTH; ++i) {
- if (blockhash[i] != 0) {
+ for (uint8_t i : blockhash) {
+ if (i != 0) {
fd->curr_block = -1;
return -EIO;
}
}
- memcpy(blockhash, hash, SHA256_DIGEST_LENGTH);
+ fd->hashes[block] = hash;
return 0;
}
@@ -377,14 +359,8 @@
return -1;
}
-<<<<<<< HEAD:fuse_sideload.cpp
- fuse_data fd;
- memset(&fd, 0, sizeof(fd));
- fd.vtab = vtab;
-=======
fuse_data fd = {};
fd.provider = provider.get();
->>>>>>> android-10.0.0_r25:fuse_sideload/fuse_sideload.cpp
fd.file_size = file_size;
fd.block_size = block_size;
fd.file_blocks = (file_size == 0) ? 0 : (((file_size - 1) / block_size) + 1);
@@ -396,14 +372,8 @@
goto done;
}
- fd.hashes = (uint8_t*)calloc(fd.file_blocks, SHA256_DIGEST_LENGTH);
- if (fd.hashes == NULL) {
- fprintf(stderr, "failed to allocate %d bites for hashes\n",
- fd.file_blocks * SHA256_DIGEST_LENGTH);
- result = -1;
- goto done;
- }
-
+ // All hashes will be zero-initialized.
+ fd.hashes.resize(fd.file_blocks);
fd.uid = getuid();
fd.gid = getgid();
@@ -421,28 +391,21 @@
goto done;
}
-<<<<<<< HEAD:fuse_sideload.cpp
- fd.ffd = open("/dev/fuse", O_RDWR);
- if (!fd.ffd) {
-=======
fd.ffd.reset(open("/dev/fuse", O_RDWR));
if (fd.ffd == -1) {
->>>>>>> android-10.0.0_r25:fuse_sideload/fuse_sideload.cpp
perror("open /dev/fuse");
result = -1;
goto done;
}
{
- char opts[256];
- snprintf(opts, sizeof(opts),
- ("fd=%d,user_id=%d,group_id=%d,max_read=%u,"
- "allow_other,rootmode=040000"),
- fd.ffd, fd.uid, fd.gid, block_size);
+ std::string opts = android::base::StringPrintf(
+ "fd=%d,user_id=%d,group_id=%d,max_read=%u,allow_other,rootmode=040000", fd.ffd.get(),
+ fd.uid, fd.gid, block_size);
- result = mount("/dev/fuse", FUSE_SIDELOAD_HOST_MOUNTPOINT, "fuse",
- MS_NOSUID | MS_NODEV | MS_RDONLY | MS_NOEXEC, opts);
- if (result < 0) {
+ result = mount("/dev/fuse", mount_point, "fuse", MS_NOSUID | MS_NODEV | MS_RDONLY | MS_NOEXEC,
+ opts.c_str());
+ if (result == -1) {
perror("mount");
goto done;
}
@@ -530,9 +493,3 @@
return result;
}
-
-extern "C" int run_old_fuse_sideload(const struct provider_vtab& vtab, void* cookie __unused,
- uint64_t file_size, uint32_t block_size)
-{
- return run_fuse_sideload(vtab, file_size, block_size, FUSE_SIDELOAD_HOST_MOUNTPOINT);
-}
diff --git a/fuse_sideload/include/fuse_sideload.h b/fuse_sideload/include/fuse_sideload.h
index 55bc8f2..1b7759a 100644
--- a/fuse_sideload/include/fuse_sideload.h
+++ b/fuse_sideload/include/fuse_sideload.h
@@ -17,17 +17,9 @@
#ifndef __FUSE_SIDELOAD_H
#define __FUSE_SIDELOAD_H
-<<<<<<< HEAD:fuse_sideload.h
-#ifdef USE_FUSE_SIDELOAD22
-#include "fuse_sideload22.h"
-#else
-
-#include <functional>
-=======
#include <memory>
#include "fuse_provider.h"
->>>>>>> android-10.0.0_r25:fuse_sideload/include/fuse_sideload.h
// Define the filenames created by the sideload FUSE filesystem.
static constexpr const char* FUSE_SIDELOAD_HOST_MOUNTPOINT = "/sideload";
@@ -39,15 +31,4 @@
int run_fuse_sideload(std::unique_ptr<FuseDataProvider>&& provider,
const char* mount_point = FUSE_SIDELOAD_HOST_MOUNTPOINT);
-#ifdef __cplusplus
-extern "C" {
-#endif
-int run_old_fuse_sideload(const struct provider_vtab& vtab, void* cookie,
- uint64_t file_size, uint32_t block_size);
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
#endif
diff --git a/fuse_sideload28/fuse_sideload.cpp b/fuse_sideload28/fuse_sideload.cpp
new file mode 100644
index 0000000..45c79f9
--- /dev/null
+++ b/fuse_sideload28/fuse_sideload.cpp
@@ -0,0 +1,525 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// This module creates a special filesystem containing two files.
+//
+// "/sideload/package.zip" appears to be a normal file, but reading
+// from it causes data to be fetched from the adb host. We can use
+// this to sideload packages over an adb connection without having to
+// store the entire package in RAM on the device.
+//
+// Because we may not trust the adb host, this filesystem maintains
+// the following invariant: each read of a given position returns the
+// same data as the first read at that position. That is, once a
+// section of the file is read, future reads of that section return
+// the same data. (Otherwise, a malicious adb host process could
+// return one set of bits when the package is read for signature
+// verification, and then different bits for when the package is
+// accessed by the installer.) If the adb host returns something
+// different than it did on the first read, the reader of the file
+// will see their read fail with EINVAL.
+//
+// The other file, "/sideload/exit", is used to control the subprocess
+// that creates this filesystem. Calling stat() on the exit file
+// causes the filesystem to be unmounted and the adb process on the
+// device shut down.
+//
+// Note that only the minimal set of file operations needed for these
+// two files is implemented. In particular, you can't opendir() or
+// readdir() on the "/sideload" directory; ls on it won't work.
+
+#include "fuse_sideload.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include "fuse.h"
+#include <pthread.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mount.h>
+#include <sys/param.h> // MIN
+#include <sys/stat.h>
+#include <sys/uio.h>
+#include <unistd.h>
+
+#ifdef USE_MINCRYPT
+#include "mincrypt/sha256.h"
+#define SHA256_DIGEST_LENGTH SHA256_DIGEST_SIZE
+#else
+#include <openssl/sha.h>
+#endif
+
+#include <array>
+#include <string>
+#include <vector>
+
+//#include <android-base/stringprintf.h>
+//#include <android-base/unique_fd.h>
+
+static constexpr uint64_t PACKAGE_FILE_ID = FUSE_ROOT_ID + 1;
+static constexpr uint64_t EXIT_FLAG_ID = FUSE_ROOT_ID + 2;
+
+static constexpr int NO_STATUS = 1;
+static constexpr int NO_STATUS_EXIT = 2;
+
+using SHA256Digest = std::array<uint8_t, SHA256_DIGEST_LENGTH>;
+
+#ifndef MIN
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
+struct fuse_data {
+ int ffd; // file descriptor for the fuse socket
+
+ provider_vtab vtab;
+
+ uint64_t file_size; // bytes
+
+ uint32_t block_size; // block size that the adb host is using to send the file to us
+ uint32_t file_blocks; // file size in block_size blocks
+
+ uid_t uid;
+ gid_t gid;
+
+ uint32_t curr_block; // cache the block most recently read from the host
+ uint8_t* block_data;
+
+ uint8_t* extra_block; // another block of storage for reads that span two blocks
+
+ uint8_t* hashes; // SHA-256 hash of each block (all zeros
+ // if block hasn't been read yet)
+};
+
+static void fuse_reply(const fuse_data* fd, uint64_t unique, const void* data, size_t len) {
+ fuse_out_header hdr;
+ hdr.len = len + sizeof(hdr);
+ hdr.error = 0;
+ hdr.unique = unique;
+
+ struct iovec vec[2];
+ vec[0].iov_base = &hdr;
+ vec[0].iov_len = sizeof(hdr);
+ vec[1].iov_base = const_cast<void*>(data);
+ vec[1].iov_len = len;
+
+ int res = writev(fd->ffd, vec, 2);
+ if (res == -1) {
+ printf("*** REPLY FAILED *** %s\n", strerror(errno));
+ }
+}
+
+static int handle_init(void* data, fuse_data* fd, const fuse_in_header* hdr) {
+ const fuse_init_in* req = static_cast<const fuse_init_in*>(data);
+
+ // Kernel 2.6.16 is the first stable kernel with struct fuse_init_out defined (fuse version 7.6).
+ // The structure is the same from 7.6 through 7.22. Beginning with 7.23, the structure increased
+ // in size and added new parameters.
+ if (req->major != FUSE_KERNEL_VERSION || req->minor < 6) {
+ printf("Fuse kernel version mismatch: Kernel version %d.%d, Expected at least %d.6", req->major,
+ req->minor, FUSE_KERNEL_VERSION);
+ return -1;
+ }
+
+ fuse_init_out out;
+ out.minor = MIN(req->minor, FUSE_KERNEL_MINOR_VERSION);
+ size_t fuse_struct_size = sizeof(out);
+#if defined(FUSE_COMPAT_22_INIT_OUT_SIZE)
+ /* FUSE_KERNEL_VERSION >= 23. */
+
+ // If the kernel only works on minor revs older than or equal to 22, then use the older structure
+ // size since this code only uses the 7.22 version of the structure.
+ if (req->minor <= 22) {
+ fuse_struct_size = FUSE_COMPAT_22_INIT_OUT_SIZE;
+ }
+#endif
+
+ out.major = FUSE_KERNEL_VERSION;
+ out.max_readahead = req->max_readahead;
+ out.flags = 0;
+ out.max_background = 32;
+ out.congestion_threshold = 32;
+ out.max_write = 4096;
+ fuse_reply(fd, hdr->unique, &out, fuse_struct_size);
+
+ return NO_STATUS;
+}
+
+static void fill_attr(fuse_attr* attr, const fuse_data* fd, uint64_t nodeid, uint64_t size,
+ uint32_t mode) {
+ memset(attr, 0, sizeof(*attr));
+ attr->nlink = 1;
+ attr->uid = fd->uid;
+ attr->gid = fd->gid;
+ attr->blksize = 4096;
+
+ attr->ino = nodeid;
+ attr->size = size;
+ attr->blocks = (size == 0) ? 0 : (((size - 1) / attr->blksize) + 1);
+ attr->mode = mode;
+}
+
+static int handle_getattr(void* /* data */, const fuse_data* fd, const fuse_in_header* hdr) {
+ struct fuse_attr_out out;
+ memset(&out, 0, sizeof(out));
+ out.attr_valid = 10;
+
+ if (hdr->nodeid == FUSE_ROOT_ID) {
+ fill_attr(&(out.attr), fd, hdr->nodeid, 4096, S_IFDIR | 0555);
+ } else if (hdr->nodeid == PACKAGE_FILE_ID) {
+ fill_attr(&(out.attr), fd, PACKAGE_FILE_ID, fd->file_size, S_IFREG | 0444);
+ } else if (hdr->nodeid == EXIT_FLAG_ID) {
+ fill_attr(&(out.attr), fd, EXIT_FLAG_ID, 0, S_IFREG | 0);
+ } else {
+ return -ENOENT;
+ }
+
+ fuse_reply(fd, hdr->unique, &out, sizeof(out));
+ return (hdr->nodeid == EXIT_FLAG_ID) ? NO_STATUS_EXIT : NO_STATUS;
+}
+
+static int handle_lookup(void* data, const fuse_data* fd, const fuse_in_header* hdr) {
+ if (data == nullptr) return -ENOENT;
+
+ struct fuse_entry_out out;
+ memset(&out, 0, sizeof(out));
+ out.entry_valid = 10;
+ out.attr_valid = 10;
+
+ std::string filename(static_cast<const char*>(data));
+ if (filename == FUSE_SIDELOAD_HOST_FILENAME) {
+ out.nodeid = PACKAGE_FILE_ID;
+ out.generation = PACKAGE_FILE_ID;
+ fill_attr(&(out.attr), fd, PACKAGE_FILE_ID, fd->file_size, S_IFREG | 0444);
+ } else if (filename == FUSE_SIDELOAD_HOST_EXIT_FLAG) {
+ out.nodeid = EXIT_FLAG_ID;
+ out.generation = EXIT_FLAG_ID;
+ fill_attr(&(out.attr), fd, EXIT_FLAG_ID, 0, S_IFREG | 0);
+ } else {
+ return -ENOENT;
+ }
+
+ fuse_reply(fd, hdr->unique, &out, sizeof(out));
+ return (out.nodeid == EXIT_FLAG_ID) ? NO_STATUS_EXIT : NO_STATUS;
+}
+
+static int handle_open(void* /* data */, const fuse_data* fd, const fuse_in_header* hdr) {
+ if (hdr->nodeid == EXIT_FLAG_ID) return -EPERM;
+ if (hdr->nodeid != PACKAGE_FILE_ID) return -ENOENT;
+
+ struct fuse_open_out out;
+ memset(&out, 0, sizeof(out));
+ out.fh = 10; // an arbitrary number; we always use the same handle
+ fuse_reply(fd, hdr->unique, &out, sizeof(out));
+ return NO_STATUS;
+}
+
+static int handle_flush(void* /* data */, fuse_data* /* fd */, const fuse_in_header* /* hdr */) {
+ return 0;
+}
+
+static int handle_release(void* /* data */, fuse_data* /* fd */, const fuse_in_header* /* hdr */) {
+ return 0;
+}
+
+// Fetch a block from the host into fd->curr_block and fd->block_data.
+// Returns 0 on successful fetch, negative otherwise.
+static int fetch_block(fuse_data* fd, uint32_t block) {
+ if (block == fd->curr_block) {
+ return 0;
+ }
+
+ if (block >= fd->file_blocks) {
+ memset(fd->block_data, 0, fd->block_size);
+ fd->curr_block = block;
+ return 0;
+ }
+
+ size_t fetch_size = fd->block_size;
+ if (block * fd->block_size + fetch_size > fd->file_size) {
+ // If we're reading the last (partial) block of the file, expect a shorter response from the
+ // host, and pad the rest of the block with zeroes.
+ fetch_size = fd->file_size - (block * fd->block_size);
+ memset(fd->block_data + fetch_size, 0, fd->block_size - fetch_size);
+ }
+
+ int result = fd->vtab.read_block(block, fd->block_data, fetch_size);
+ if (result < 0) return result;
+
+ fd->curr_block = block;
+
+ // Verify the hash of the block we just got from the host.
+ //
+ // - If the hash of the just-received data matches the stored hash for the block, accept it.
+ // - If the stored hash is all zeroes, store the new hash and accept the block (this is the first
+ // time we've read this block).
+ // - Otherwise, return -EINVAL for the read.
+
+ uint8_t hash[SHA256_DIGEST_LENGTH];
+#ifdef USE_MINCRYPT
+ SHA256_hash(fd->block_data, fd->block_size, hash);
+#else
+ SHA256(fd->block_data, fd->block_size, hash);
+#endif
+ uint8_t* blockhash = fd->hashes + block * SHA256_DIGEST_LENGTH;
+ if (memcmp(hash, blockhash, SHA256_DIGEST_LENGTH) == 0) {
+ return 0;
+ }
+
+ int i;
+ for (i = 0; i < SHA256_DIGEST_LENGTH; ++i) {
+ if (blockhash[i] != 0) {
+ fd->curr_block = -1;
+ return -EIO;
+ }
+ }
+
+ memcpy(blockhash, hash, SHA256_DIGEST_LENGTH);
+ return 0;
+}
+
+static int handle_read(void* data, fuse_data* fd, const fuse_in_header* hdr) {
+ if (hdr->nodeid != PACKAGE_FILE_ID) return -ENOENT;
+
+ const fuse_read_in* req = static_cast<const fuse_read_in*>(data);
+ uint64_t offset = req->offset;
+ uint32_t size = req->size;
+
+ // The docs on the fuse kernel interface are vague about what to do when a read request extends
+ // past the end of the file. We can return a short read -- the return structure does include a
+ // length field -- but in testing that caused the program using the file to segfault. (I
+ // speculate that this is due to the reading program accessing it via mmap; maybe mmap dislikes
+ // when you return something short of a whole page?) To fix this we zero-pad reads that extend
+ // past the end of the file so we're always returning exactly as many bytes as were requested.
+ // (Users of the mapped file have to know its real length anyway.)
+
+ fuse_out_header outhdr;
+ outhdr.len = sizeof(outhdr) + size;
+ outhdr.error = 0;
+ outhdr.unique = hdr->unique;
+
+ struct iovec vec[3];
+ vec[0].iov_base = &outhdr;
+ vec[0].iov_len = sizeof(outhdr);
+
+ uint32_t block = offset / fd->block_size;
+ int result = fetch_block(fd, block);
+ if (result != 0) return result;
+
+ // Two cases:
+ //
+ // - the read request is entirely within this block. In this case we can reply immediately.
+ //
+ // - the read request goes over into the next block. Note that since we mount the filesystem
+ // with max_read=block_size, a read can never span more than two blocks. In this case we copy
+ // the block to extra_block and issue a fetch for the following block.
+
+ uint32_t block_offset = offset - (block * fd->block_size);
+
+ int vec_used;
+ if (size + block_offset <= fd->block_size) {
+ // First case: the read fits entirely in the first block.
+
+ vec[1].iov_base = fd->block_data + block_offset;
+ vec[1].iov_len = size;
+ vec_used = 2;
+ } else {
+ // Second case: the read spills over into the next block.
+
+ memcpy(fd->extra_block, fd->block_data + block_offset, fd->block_size - block_offset);
+ vec[1].iov_base = fd->extra_block;
+ vec[1].iov_len = fd->block_size - block_offset;
+
+ result = fetch_block(fd, block + 1);
+ if (result != 0) return result;
+ vec[2].iov_base = fd->block_data;
+ vec[2].iov_len = size - vec[1].iov_len;
+ vec_used = 3;
+ }
+
+ if (writev(fd->ffd, vec, vec_used) == -1) {
+ printf("*** READ REPLY FAILED: %s ***\n", strerror(errno));
+ }
+ return NO_STATUS;
+}
+
+int run_fuse_sideload(const provider_vtab& vtab, uint64_t file_size, uint32_t block_size,
+ const char* mount_point) {
+ // If something's already mounted on our mountpoint, try to remove it. (Mostly in case of a
+ // previous abnormal exit.)
+ umount2(mount_point, MNT_FORCE);
+
+ // fs/fuse/inode.c in kernel code uses the greater of 4096 and the passed-in max_read.
+ if (block_size < 4096) {
+ fprintf(stderr, "block size (%u) is too small\n", block_size);
+ return -1;
+ }
+ if (block_size > (1 << 22)) { // 4 MiB
+ fprintf(stderr, "block size (%u) is too large\n", block_size);
+ return -1;
+ }
+
+ fuse_data fd;
+ memset(&fd, 0, sizeof(fd));
+ fd.vtab = vtab;
+ fd.file_size = file_size;
+ fd.block_size = block_size;
+ fd.file_blocks = (file_size == 0) ? 0 : (((file_size - 1) / block_size) + 1);
+
+ int result;
+ if (fd.file_blocks > (1 << 18)) {
+ fprintf(stderr, "file has too many blocks (%u)\n", fd.file_blocks);
+ result = -1;
+ goto done;
+ }
+
+ fd.hashes = (uint8_t*)calloc(fd.file_blocks, SHA256_DIGEST_LENGTH);
+ if (fd.hashes == NULL) {
+ fprintf(stderr, "failed to allocate %d bites for hashes\n",
+ fd.file_blocks * SHA256_DIGEST_LENGTH);
+ result = -1;
+ goto done;
+ }
+
+ fd.uid = getuid();
+ fd.gid = getgid();
+
+ fd.curr_block = -1;
+ fd.block_data = static_cast<uint8_t*>(malloc(block_size));
+ if (fd.block_data == nullptr) {
+ fprintf(stderr, "failed to allocate %d bites for block_data\n", block_size);
+ result = -1;
+ goto done;
+ }
+ fd.extra_block = static_cast<uint8_t*>(malloc(block_size));
+ if (fd.extra_block == nullptr) {
+ fprintf(stderr, "failed to allocate %d bites for extra_block\n", block_size);
+ result = -1;
+ goto done;
+ }
+
+ fd.ffd = open("/dev/fuse", O_RDWR);
+ if (!fd.ffd) {
+ perror("open /dev/fuse");
+ result = -1;
+ goto done;
+ }
+
+ {
+ char opts[256];
+ snprintf(opts, sizeof(opts),
+ ("fd=%d,user_id=%d,group_id=%d,max_read=%u,"
+ "allow_other,rootmode=040000"),
+ fd.ffd, fd.uid, fd.gid, block_size);
+
+ result = mount("/dev/fuse", FUSE_SIDELOAD_HOST_MOUNTPOINT, "fuse",
+ MS_NOSUID | MS_NODEV | MS_RDONLY | MS_NOEXEC, opts);
+ if (result < 0) {
+ perror("mount");
+ goto done;
+ }
+ }
+
+ uint8_t request_buffer[sizeof(fuse_in_header) + PATH_MAX * 8];
+ for (;;) {
+ ssize_t len = TEMP_FAILURE_RETRY(read(fd.ffd, request_buffer, sizeof(request_buffer)));
+ if (len == -1) {
+ perror("read request");
+ if (errno == ENODEV) {
+ result = -1;
+ break;
+ }
+ continue;
+ }
+
+ if (static_cast<size_t>(len) < sizeof(fuse_in_header)) {
+ fprintf(stderr, "request too short: len=%zd\n", len);
+ continue;
+ }
+
+ fuse_in_header* hdr = reinterpret_cast<fuse_in_header*>(request_buffer);
+ void* data = request_buffer + sizeof(fuse_in_header);
+
+ result = -ENOSYS;
+
+ switch (hdr->opcode) {
+ case FUSE_INIT:
+ result = handle_init(data, &fd, hdr);
+ break;
+
+ case FUSE_LOOKUP:
+ result = handle_lookup(data, &fd, hdr);
+ break;
+
+ case FUSE_GETATTR:
+ result = handle_getattr(data, &fd, hdr);
+ break;
+
+ case FUSE_OPEN:
+ result = handle_open(data, &fd, hdr);
+ break;
+
+ case FUSE_READ:
+ result = handle_read(data, &fd, hdr);
+ break;
+
+ case FUSE_FLUSH:
+ result = handle_flush(data, &fd, hdr);
+ break;
+
+ case FUSE_RELEASE:
+ result = handle_release(data, &fd, hdr);
+ break;
+
+ default:
+ fprintf(stderr, "unknown fuse request opcode %d\n", hdr->opcode);
+ break;
+ }
+
+ if (result == NO_STATUS_EXIT) {
+ result = 0;
+ break;
+ }
+
+ if (result != NO_STATUS) {
+ fuse_out_header outhdr;
+ outhdr.len = sizeof(outhdr);
+ outhdr.error = result;
+ outhdr.unique = hdr->unique;
+ TEMP_FAILURE_RETRY(write(fd.ffd, &outhdr, sizeof(outhdr)));
+ }
+ }
+
+done:
+ fd.vtab.close();
+
+ if (umount2(mount_point, MNT_DETACH) == -1) {
+ fprintf(stderr, "fuse_sideload umount failed: %s\n", strerror(errno));
+ }
+
+ free(fd.block_data);
+ free(fd.extra_block);
+
+ return result;
+}
+
+extern "C" int run_old_fuse_sideload(const struct provider_vtab& vtab, void* cookie __unused,
+ uint64_t file_size, uint32_t block_size)
+{
+ return run_fuse_sideload(vtab, file_size, block_size, FUSE_SIDELOAD_HOST_MOUNTPOINT);
+}
diff --git a/fuse_sideload28/fuse_sideload.h b/fuse_sideload28/fuse_sideload.h
new file mode 100644
index 0000000..1ea1eb8
--- /dev/null
+++ b/fuse_sideload28/fuse_sideload.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __FUSE_SIDELOAD_H
+#define __FUSE_SIDELOAD_H
+
+#ifdef USE_FUSE_SIDELOAD22
+#include "fuse_sideload22.h"
+#else
+
+#include <functional>
+
+// Define the filenames created by the sideload FUSE filesystem.
+static constexpr const char* FUSE_SIDELOAD_HOST_MOUNTPOINT = "/sideload";
+static constexpr const char* FUSE_SIDELOAD_HOST_FILENAME = "package.zip";
+static constexpr const char* FUSE_SIDELOAD_HOST_PATHNAME = "/sideload/package.zip";
+static constexpr const char* FUSE_SIDELOAD_HOST_EXIT_FLAG = "exit";
+static constexpr const char* FUSE_SIDELOAD_HOST_EXIT_PATHNAME = "/sideload/exit";
+
+struct provider_vtab {
+ // read a block
+ std::function<int(uint32_t block, uint8_t* buffer, uint32_t fetch_size)> read_block;
+
+ // close down
+ std::function<void(void)> close;
+};
+
+int run_fuse_sideload(const provider_vtab& vtab, uint64_t file_size, uint32_t block_size,
+ const char* mount_point = FUSE_SIDELOAD_HOST_MOUNTPOINT);
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+int run_old_fuse_sideload(const struct provider_vtab& vtab, void* cookie,
+ uint64_t file_size, uint32_t block_size);
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+#endif
diff --git a/gui/Android.mk b/gui/Android.mk
old mode 100644
new mode 100755
index 22b5347..9ee54d6
--- a/gui/Android.mk
+++ b/gui/Android.mk
@@ -1,7 +1,7 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_CFLAGS := -fno-strict-aliasing
+LOCAL_CFLAGS := -fno-strict-aliasing -Wno-implicit-fallthrough
LOCAL_SRC_FILES := \
gui.cpp \
@@ -39,9 +39,21 @@
endif
LOCAL_SHARED_LIBRARIES += libminuitwrp libc libstdc++ libaosprecovery libselinux
+LOCAL_C_INCLUDES += $(LOCAL_PATH)/../otautil/include
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 26; echo $$?),0)
- LOCAL_SHARED_LIBRARIES += libziparchive
- LOCAL_C_INCLUDES += $(LOCAL_PATH)/../otautil/include
+ LOCAL_SHARED_LIBRARIES += libziparchive
+ LOCAL_STATIC_LIBRARIES += libotautil
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 28; echo $$?),0)
+ LOCAL_C_INCLUDES += $(LOCAL_PATH)/../install/include \
+ system/core/libziparchive/include/ \
+ $(LOCAL_PATH)/../recovery_ui/include \
+ $(LOCAL_PATH)/../fuse_sideload/include
+ LOCAL_CFLAGS += -D_USE_SYSTEM_ZIPARCHIVE
+ else
+ LOCAL_C_INCLUDES += $(LOCAL_PATH)/../install28/ \
+ $(LOCAL_PATH)/../fuse_sideload28/
+ LOCAL_CFLAGS += -DUSE_28_INSTALL -DUSE_OTAUTIL_ZIPARCHIVE
+ endif
else
LOCAL_SHARED_LIBRARIES += libminzip
LOCAL_CFLAGS += -DUSE_MINZIP
@@ -84,7 +96,8 @@
LOCAL_C_INCLUDES += \
bionic \
system/core/include \
- system/core/libpixelflinger/include
+ system/core/libpixelflinger/include \
+ external/freetype/include
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
LOCAL_C_INCLUDES += external/stlport/stlport
@@ -98,7 +111,7 @@
# Transfer in the resources for the device
include $(CLEAR_VARS)
LOCAL_MODULE := twrp
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)$(TWRES_PATH)
diff --git a/gui/action.cpp b/gui/action.cpp
index 0216d84..52d924b 100755
--- a/gui/action.cpp
+++ b/gui/action.cpp
@@ -40,8 +40,9 @@
#include "../twrp-functions.hpp"
#include "../openrecoveryscript.hpp"
-#include "../adb_install.h"
-#include "../fuse_sideload.h"
+#include "install/adb_install.h"
+
+#include "fuse_sideload.h"
#include "blanktimer.hpp"
#include "../twinstall.h"
@@ -49,14 +50,14 @@
#include "../twcommon.h"
#include "../variables.h"
#include "cutils/properties.h"
-#include "../adb_install.h"
+#include "install/adb_install.h"
};
-#include "../set_metadata.h"
+#include "set_metadata.h"
#include "../minuitwrp/minui.h"
#include "rapidxml.hpp"
#include "objects.hpp"
-#include "../tw_atomic.hpp"
+#include "tw_atomic.hpp"
GUIAction::mapFunc GUIAction::mf;
std::set<string> GUIAction::setActionsRunningInCallerThread;
@@ -1533,7 +1534,9 @@
bool mtp_was_enabled = TWFunc::Toggle_MTP(false);
// wait for the adb connection
- int ret = apply_from_adb("/", &sideload_child_pid);
+ // int ret = apply_from_adb("/", &sideload_child_pid);
+ Device::BuiltinAction reboot_action = Device::REBOOT_BOOTLOADER;
+ int ret = ApplyFromAdb("/", &reboot_action);
DataManager::SetValue("tw_has_cancel", 0); // Remove cancel button from gui now that the zip install is going to start
if (ret != 0) {
diff --git a/gui/gui.cpp b/gui/gui.cpp
old mode 100644
new mode 100755
index ce8c3e2..bab7ed2
--- a/gui/gui.cpp
+++ b/gui/gui.cpp
@@ -50,7 +50,7 @@
#include "../openrecoveryscript.hpp"
#include "../orscmd/orscmd.h"
#include "blanktimer.hpp"
-#include "../tw_atomic.hpp"
+#include "tw_atomic.hpp"
// Enable to print render time of each frame to the log file
//#define PRINT_RENDER_TIME 1
diff --git a/gui/input.cpp b/gui/input.cpp
old mode 100644
new mode 100755
index 91a1c11..458eb55
--- a/gui/input.cpp
+++ b/gui/input.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2012 to 2016 bigbiff/Dees_Troy TeamWin
+ Copyright 2012 to 2020 TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
@@ -41,6 +41,7 @@
#include "../twcommon.h"
}
#include "../minuitwrp/minui.h"
+#include "../minuitwrp/truetype.hpp"
#include "rapidxml.hpp"
#include "objects.hpp"
@@ -215,7 +216,7 @@
displayValue = mValue;
}
- textWidth = gr_ttf_measureEx(displayValue.c_str(), fontResource);
+ textWidth = twrpTruetype::gr_ttf_measureEx(displayValue.c_str(), fontResource);
}
void GUIInput::HandleCursorByTouch(int x) {
@@ -239,7 +240,7 @@
for (index = 0; index <= displaySize; index++) {
cursorString = displayValue.substr(0, index);
- cursorX = gr_ttf_measureEx(cursorString.c_str(), fontResource) + mRenderX + scrollingX;
+ cursorX = twrpTruetype::gr_ttf_measureEx(cursorString.c_str(), fontResource) + mRenderX + scrollingX;
if (cursorX > x) {
if (index > 0 && x <= cursorX - ((x - prevX) / 2) && prevX >= mRenderX) {
// This helps make sure that we can place the cursor before the very first char if the first char is
@@ -280,7 +281,7 @@
if (mCursorLocation != -1) {
string cursorDisplay = displayValue;
cursorDisplay.resize(mCursorLocation);
- cursorTextWidth = gr_ttf_measureEx(cursorDisplay.c_str(), fontResource);
+ cursorTextWidth = twrpTruetype::gr_ttf_measureEx(cursorDisplay.c_str(), fontResource);
}
cursorX = mRenderX + cursorTextWidth + scrollingX;
if (cursorX >= mRenderX + mRenderW) {
diff --git a/gui/keyboard.cpp b/gui/keyboard.cpp
index b6a772b..026984c 100755
--- a/gui/keyboard.cpp
+++ b/gui/keyboard.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2012 bigbiff/Dees_Troy TeamWin
+ Copyright 2012 to 2020 TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
@@ -28,6 +28,7 @@
#include "gui.h"
}
#include "../minuitwrp/minui.h"
+#include "../minuitwrp/truetype.hpp"
#include "rapidxml.hpp"
#include "objects.hpp"
@@ -333,7 +334,7 @@
else if (!labelText.empty() && labelFont && labelFont->GetResource())
{
void* fontResource = labelFont->GetResource();
- int textW = gr_ttf_measureEx(labelText.c_str(), fontResource);
+ int textW = twrpTruetype::gr_ttf_measureEx(labelText.c_str(), fontResource);
int textH = labelFont->GetHeight();
int textX = keyX + (keyW - textW) / 2;
int textY = keyY + (keyH - textH) / 2;
@@ -346,7 +347,7 @@
void* fontResource = mLongpressFont->GetResource();
gr_color(mLongpressFontColor.red, mLongpressFontColor.green, mLongpressFontColor.blue, mLongpressFontColor.alpha);
string text(1, keychar);
- int textW = gr_ttf_measureEx(text.c_str(), fontResource);
+ int textW = twrpTruetype::gr_ttf_measureEx(text.c_str(), fontResource);
int textX = keyX + keyW - longpressOffsetX - textW;
int textY = keyY + longpressOffsetY;
gr_textEx_scaleW(textX, textY, text.c_str(), fontResource, keyW, TOP_LEFT, 0);
diff --git a/gui/pages.cpp b/gui/pages.cpp
old mode 100644
new mode 100755
index fd0ad9b..cc2f615
--- a/gui/pages.cpp
+++ b/gui/pages.cpp
@@ -42,14 +42,18 @@
#ifdef USE_MINZIP
#include "../minzip/SysUtil.h"
#else
+#ifdef USE_OTAUTIL_ZIPARCHIVE
#include <otautil/SysUtil.h>
+#else
+#include <ziparchive/zip_archive.h>
+#endif
#endif
extern "C" {
#include "../twcommon.h"
#include "gui.h"
}
-#include "../zipwrap.hpp"
+#include "zipwrap.hpp"
#include "../minuitwrp/minui.h"
#include "rapidxml.hpp"
diff --git a/gui/pages.hpp b/gui/pages.hpp
old mode 100644
new mode 100755
index 282b2d5..8c5edaf
--- a/gui/pages.hpp
+++ b/gui/pages.hpp
@@ -21,7 +21,7 @@
#ifndef _PAGES_HEADER_HPP
#define _PAGES_HEADER_HPP
-#include "../zipwrap.hpp"
+#include "zipwrap.hpp"
#include <vector>
#include <map>
#include <string>
diff --git a/gui/resources.cpp b/gui/resources.cpp
old mode 100644
new mode 100755
index bb2fd50..5efa093
--- a/gui/resources.cpp
+++ b/gui/resources.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2017 TeamWin
+ Copyright 2012 to 2020 TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
@@ -30,11 +30,13 @@
#include <iomanip>
#include <fcntl.h>
-#include "../zipwrap.hpp"
+#include "zipwrap.hpp"
extern "C" {
#include "../twcommon.h"
#include "gui.h"
}
+
+#include "../minuitwrp/truetype.hpp"
#include "../minuitwrp/minui.h"
#include "rapidxml.hpp"
@@ -155,12 +157,12 @@
std::string tmpname = "/tmp/" + file;
if (ExtractResource(pZip, "fonts", file, "", tmpname) == 0)
{
- mFont = gr_ttf_loadFont(tmpname.c_str(), font_size, dpi);
+ mFont = twrpTruetype::gr_ttf_loadFont(tmpname.c_str(), font_size, dpi);
}
else
{
file = std::string(TWRES "fonts/") + file;
- mFont = gr_ttf_loadFont(file.c_str(), font_size, dpi);
+ mFont = twrpTruetype::gr_ttf_loadFont(file.c_str(), font_size, dpi);
}
}
else
@@ -170,11 +172,13 @@
}
void FontResource::DeleteFont() {
- if (mFont)
- gr_ttf_freeFont(mFont);
+ if (mFont) {
+ twrpTruetype::gr_ttf_freeFont(mFont);
+ }
mFont = NULL;
- if (origFont)
- gr_ttf_freeFont(origFont);
+ if (origFont) {
+ twrpTruetype::gr_ttf_freeFont(origFont);
+ }
origFont = NULL;
}
@@ -182,7 +186,7 @@
if (!origFont) {
origFont = mFont;
} else if (mFont) {
- gr_ttf_freeFont(mFont);
+ twrpTruetype::gr_ttf_freeFont(mFont);
mFont = NULL;
}
LoadFont(node, pZip);
diff --git a/gui/resources.hpp b/gui/resources.hpp
old mode 100644
new mode 100755
index 69bebc7..e709e33
--- a/gui/resources.hpp
+++ b/gui/resources.hpp
@@ -1,5 +1,5 @@
/*
- Copyright 2017 TeamWin
+ Copyright 2012 to 2020 TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
@@ -25,7 +25,8 @@
#include <vector>
#include <map>
#include "rapidxml.hpp"
-#include "../zipwrap.hpp"
+#include "zipwrap.hpp"
+#include "../minuitwrp/truetype.hpp"
extern "C" {
#include "../minuitwrp/minui.h"
@@ -58,7 +59,7 @@
public:
void* GetResource() { return mFont; }
- int GetHeight() { return gr_ttf_getMaxFontHeight(mFont); }
+ int GetHeight() { return twrpTruetype::gr_ttf_getMaxFontHeight(mFont); }
void Override(xml_node<>* node, ZipWrap* pZip);
protected:
diff --git a/gui/scrolllist.cpp b/gui/scrolllist.cpp
index bf5a9b0..0a4eed8 100755
--- a/gui/scrolllist.cpp
+++ b/gui/scrolllist.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2013 bigbiff/Dees_Troy TeamWin
+ Copyright 2012 to 2020 TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
@@ -22,6 +22,7 @@
#include "../twcommon.h"
}
#include "../minuitwrp/minui.h"
+#include "../minuitwrp/truetype.hpp"
#include "rapidxml.hpp"
#include "objects.hpp"
@@ -633,7 +634,7 @@
if (origColor)
curr_color = origColor->at(i);
for (;;) {
- size_t line_char_width = gr_ttf_maxExW(curr_line.c_str(), mFont->GetResource(), mRenderW);
+ size_t line_char_width = twrpTruetype::gr_ttf_maxExW(curr_line.c_str(), mFont->GetResource(), mRenderW);
if (line_char_width < curr_line.size()) {
//string left = curr_line.substr(0, line_char_width);
size_t wrap_pos = curr_line.find_last_of(" ,./:-_;", line_char_width - 1);
diff --git a/gui/slidervalue.cpp b/gui/slidervalue.cpp
old mode 100644
new mode 100755
index 3aaffcc..5ed9c4f
--- a/gui/slidervalue.cpp
+++ b/gui/slidervalue.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2017 TeamWin
+ Copyright 2012 to 2020 TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
@@ -39,6 +39,7 @@
#include "../twcommon.h"
}
#include "../minuitwrp/minui.h"
+#include "../minuitwrp/truetype.hpp"
#include "rapidxml.hpp"
#include "objects.hpp"
@@ -270,7 +271,7 @@
void* fontResource = NULL;
if (mFont) fontResource = mFont->GetResource();
- return gr_ttf_measureEx(str.c_str(), fontResource);
+ return twrpTruetype::gr_ttf_measureEx(str.c_str(), fontResource);
}
int GUISliderValue::Render(void)
diff --git a/gui/terminal.cpp b/gui/terminal.cpp
index a4fed91..e12df5c 100755
--- a/gui/terminal.cpp
+++ b/gui/terminal.cpp
@@ -34,6 +34,8 @@
#include "../twcommon.h"
}
#include "../minuitwrp/minui.h"
+#include "../minuitwrp/truetype.hpp"
+
#include "gui.hpp"
#include "rapidxml.hpp"
@@ -883,10 +885,10 @@
// render cursor
int cursorX = engine->getCursorX();
std::string leftOfCursor = line.substr(0, cursorX);
- int x = gr_ttf_measureEx(leftOfCursor.c_str(), mFont->GetResource());
+ int x = twrpTruetype::gr_ttf_measureEx(leftOfCursor.c_str(), mFont->GetResource());
// note that this single character can be a UTF-8 sequence
std::string atCursor = (size_t)cursorX < line.length() ? line.substr(cursorX, 1) : " ";
- int w = gr_ttf_measureEx(atCursor.c_str(), mFont->GetResource());
+ int w = twrpTruetype::gr_ttf_measureEx(atCursor.c_str(), mFont->GetResource());
gr_color(mFontColor.red, mFontColor.green, mFontColor.blue, mFontColor.alpha);
gr_fill(mRenderX + x, yPos, w, actualItemHeight);
gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, mBackgroundColor.alpha);
@@ -905,7 +907,7 @@
engine->initPty();
// send window resize
if (mFont && mFont->GetResource()) {
- int charWidth = gr_ttf_measureEx("N", mFont->GetResource());
+ int charWidth = twrpTruetype::gr_ttf_measureEx("N", mFont->GetResource());
engine->setSize(mRenderW / charWidth, GetDisplayItemCount(), mRenderW, mRenderH);
}
}
diff --git a/gui/text.cpp b/gui/text.cpp
old mode 100644
new mode 100755
index 123b249..b72dd04
--- a/gui/text.cpp
+++ b/gui/text.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2012 to 2016 bigbiff/Dees_Troy TeamWin
+ Copyright 2012 to 2020 TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
@@ -39,6 +39,7 @@
#include "../twcommon.h"
}
#include "../minuitwrp/minui.h"
+#include "../minuitwrp/truetype.hpp"
#include "rapidxml.hpp"
#include "objects.hpp"
@@ -159,7 +160,7 @@
h = mFontHeight;
mLastValue = gui_parse_text(mText);
- w = gr_ttf_measureEx(mLastValue.c_str(), fontResource);
+ w = twrpTruetype::gr_ttf_measureEx(mLastValue.c_str(), fontResource);
return 0;
}
diff --git a/gui/theme/common/languages/tr.xml b/gui/theme/common/languages/tr.xml
index d86d494..8e924cb 100644
--- a/gui/theme/common/languages/tr.xml
+++ b/gui/theme/common/languages/tr.xml
@@ -98,19 +98,16 @@
<string name="successful">Başarılı</string>
<string name="install_failed">Yükleme BaÅŸarısız</string>
<string name="install_successful">Yükleme BaÅŸarılı</string>
- <string name="wipe_cache_dalvik_btn">Önbellek/Dalvik Temizle</string>
- <string name="wipe_dalvik_btn">Dalvik Temizle</string>
+ <string name="wipe_cache_dalvik_btn">Cache/dalvik temizle</string>
<string name="reboot_system_btn">Sistemi Yeniden BaÅŸlat</string>
<string name="install_sel_target">Hedef Bölümü Seç</string>
- <string name="flash_image_select">Ä°majı Flashlamak için Bölüm Seçin:</string>
+ <string name="flash_image_select">Ä°majı Flashlamak için Bölüm Seç:</string>
<string name="target_partition">Hedef Bölüm:</string>
<string name="flashing_image">İmaj Flashlanıyor...</string>
<string name="image_flashed">İmaj Flashlandı</string>
<string name="wipe_cache_dalvik_confirm">Önbellek ve Dalvik temizlensin mi?</string>
- <string name="wipe_dalvik_confirm">Dalvik temizlensin mi?</string>
<string name="wiping_cache_dalvik">Önbellek ve Dalvik temizleniyor...</string>
<string name="wipe_cache_dalvik_complete">Önbellek ve Dalvik temizliÄŸi tamamlandı</string>
- <string name="wipe_dalvik_complete">Dalvik Temizliği Tamamlandı</string>
<string name="swipe_wipe">Temizlemek için Kaydır</string>
<string name="swipe_wipe_s"> Temizle</string>
<string name="no_os1">Ä°ÅŸletim Sistemi yüklü deÄŸil!</string>
@@ -122,13 +119,9 @@
<string name="reboot_install_app_hdr">TWRP Uygulaması yüklensin mi?</string>
<string name="reboot_install_app1">Resmi TWRP Uygulamasını yüklemek ister misiniz?</string>
<string name="reboot_install_app2">Uygulama, yeni TWRP sürümlerini kontrol edebilir.</string>
- <string name="reboot_install_app_prompt_install">Yüklü deÄŸilse TWRP uygulamasını yüklemeyi sor</string>
+ <string name="reboot_install_app_prompt_install">Yüklü deÄŸilse, TWRP uygulamasını yüklemek için sor</string>
<string name="reboot_install_app_system">Sistem Uygulaması olarak yükle</string>
<string name="reboot_installing_app">Uygulama yükleniyor...</string>
- <string name="uninstall_twrp_system_app">TWRP Uygulamasını Sistemden kaldır</string>
- <string name="uninstall_twrp_system_app_confirm">TWRP Uygulaması Sistemden kaldırılsın mı?</string>
- <string name="uninstalling_twrp_system_app">TWRP Uygulaması Sistemden kaldırılıyor...</string>
- <string name="uninstall_twrp_system_app_complete">TWRP Uygulamasını Sistemden Kaldırma Tamamlandı</string>
<string name="swipe_to_install_app">TWRP Uygulamasını yüklemek için kaydır</string>
<string name="swipe_flash">Flashlamayı onaylamak için kaydır</string>
<string name="confirm_action">Eylemi Onayla</string>
@@ -137,7 +130,7 @@
<string name="wipe_hdr">Temizle</string>
<string name="factory_reset_hdr">Sıfırla</string>
<string name="factory_reset_btn">Sıfırla</string>
- <string name="factory_reset1">Veriyi, ÖnbelleÄŸi ve Dalvik'i temizler</string>
+ <string name="factory_reset1">Veriyi, ÖnbelleÄŸi, ve Dalvik'i temizler</string>
<string name="factory_reset2">(dahili depolama hariç)</string>
<string name="factory_reset3">ÇoÄŸu zaman ihtiyacınız olan</string>
<string name="factory_reset4">tek temizlik budur.</string>
@@ -158,10 +151,10 @@
<string name="format_data_hdr">Veriyi Biçimlendir</string>
<string name="format_data_btn">Veriyi Biçimlendir</string>
<string name="format_data_ptr1">Veriyi biçimlendirmek tüm uygulamalarınızı,</string>
- <string name="format_data_ptr2">yedeklerinizi, resimlerinizi, videolarınızı, medyanızı temizleyecek ve</string>
+ <string name="format_data_ptr2">yedeklerinizi, resimlerinizi, videolarınızı, medyanızı, temizleyecek ve</string>
<string name="format_data_ptr3">dahili depolama üzerindeki ÅŸifrelemeyi kaldıracak.</string>
<string name="format_data_adopted">Kabul Edilen Depolama Dahil</string>
- <string name="format_data_lcp1">Veriyi biçimlendirmek tüm uygulamalarınızı, yedeklerinizi, resimlerinizi, videolarınızı, medyanızı temizleyecek ve</string>
+ <string name="format_data_lcp1">Veriyi biçimlendirmek tüm uygulamalarınızı, yedeklerinizi, resimlerinizi, videolarınızı, medyanızı, temizleyecek ve</string>
<string name="format_data_lcp2">dahili depolama üzerindeki ÅŸifrelemeyi kaldıracak.</string>
<string name="format_data_wtc1">Veriyi biçimlendirmek tüm uygulamalarınızı,</string>
<string name="format_data_wtc2">yedeklerinizi ve medyanızı temizleyecek. Bu işlem geri alınamaz.</string>
@@ -218,13 +211,13 @@
<string name="encryption_tab">ŞİFRELEME</string>
<string name="encryption">Åžifreleme:</string>
<string name="name">Ad:</string>
- <string name="sel_part_backup">Yedeklenecek Bölümleri Seçin:</string>
+ <string name="sel_part_backup">Yedeklenecek Bölümleri Seç:</string>
<string name="storage">Depolama:</string>
<string name="enc_disabled">devre dışı - etkinleÅŸtirmek için bir ÅŸifre ayarlayın</string>
<string name="enc_enabled">etkin</string>
<string name="enable_backup_comp_chk">Sıkıştırmayı etkinleştir</string>
<string name="skip_digest_backup_chk" version="2">Yedekleme sırasında Digest oluÅŸturmayı geç</string>
- <string name="disable_backup_space_chk" version="2">Yedeklemeden önce boÅŸ alan kontrolünü devre dışı bırak</string>
+ <string name="disable_backup_space_chk" version="2">Yedeklemeden önce boÅŸ alan denetimini devre dışı bırak</string>
<string name="current_boot_slot">Geçerli Yuva: %tw_active_slot%</string>
<string name="boot_slot_a">A Yuvası</string>
<string name="boot_slot_b">B Yuvası</string>
@@ -235,7 +228,7 @@
<string name="append_date_btn">Tarih Ekle</string>
<string name="backup_name_exists">Bu adda bir yedek zaten var!</string>
<string name="encrypt_backup">Yedeklemeniz ÅŸifrelensin mi?</string>
- <string name="enter_pass">Åžifreyi Girin:</string>
+ <string name="enter_pass">Åžifre Gir:</string>
<string name="enter_pass2">Åžifreyi Tekrar Girin:</string>
<string name="pass_not_match">Åžifreler eÅŸleÅŸmiyor!</string>
<string name="partitions">Bölümler:</string>
@@ -260,7 +253,7 @@
<string name="restore_try_decrypt">Åžifreli Yedek - Çözülmeye Çalışılıyor</string>
<string name="restore_try_decrypt_s">Çözülmeye Çalışılıyor</string>
<string name="restore_backup_date">Yedek tarihi: %tw_restore_file_date%</string>
- <string name="restore_sel_part">Geri Yüklenecek Bölümleri Seçin:</string>
+ <string name="restore_sel_part">Geri Yüklenecek Bölümleri Seç:</string>
<string name="restore_enable_digest_chk" version="2">Yedek Dosyalarının Digest Doğrulamasını etkinleştir</string>
<string name="restore_complete">Geri Yükleme Tamamlandı</string>
<string name="swipe_restore">Geri Yüklemek için Kaydır</string>
@@ -274,7 +267,7 @@
<string name="swipe_rename"> Yeniden Adlandır</string>
<string name="confirm_hdr">Onayla</string>
<string name="mount_hdr">BaÄŸla</string>
- <string name="mount_sel_part">BaÄŸlanacak Bölümleri Seçin:</string>
+ <string name="mount_sel_part">BaÄŸlanacak Bölümleri Seç:</string>
<string name="mount_sys_ro_chk">Sistem bölümünü salt okunur baÄŸla</string>
<string name="mount_sys_ro_s_chk">Sistemi RO BaÄŸla</string>
<string name="decrypt_data_btn">Veri Åžifresini Çöz</string>
@@ -326,11 +319,10 @@
<string name="settings_tz_btn">Zaman Dilimi</string>
<string name="settings_screen_btn">Ekran</string>
<string name="settings_screen_bright_btn">Ekran Parlaklığı</string>
- <string name="vibration_disabled">Bu cihaz için titreÅŸim devre dışı</string>
<string name="settings_vibration_btn">TitreÅŸim</string>
<string name="settings_language_btn">Dil</string>
<string name="time_zone_hdr">Zaman Dilimi</string>
- <string name="sel_tz_list">Zaman Dilimi Seçin:</string>
+ <string name="sel_tz_list">Zaman Dilimi Seç:</string>
<!-- Translator note: if it does not make sense to translate the locations or if it makes more sense,
feel free to change the location listed or drop the location entirely and just call it UTC -6 -->
<string name="utcm11">(UTC -11) Samoa, Midway Adası</string>
@@ -382,7 +374,7 @@
<string name="button_vibration">DüÄŸme TitreÅŸimi:</string>
<string name="kb_vibration">Klavye TitreÅŸimi:</string>
<string name="act_vibration">Eylem TitreÅŸimi:</string>
- <string name="select_language">Dil Seçin:</string>
+ <string name="select_language">Dil Seç:</string>
<string name="sel_lang_btn">Dil Seç</string>
<string name="set_language_btn">Dili Ayarla</string>
<string name="advanced_hdr">GeliÅŸmiÅŸ</string>
@@ -432,10 +424,10 @@
<string name="swipe_to_unlock">Kilidi Açmak için Kaydır</string>
<string name="swipe_unlock"> Kilidi Aç</string>
<string name="fm_hdr">Dosya Yöneticisi</string>
- <string name="fm_sel_file">Bir Dosya veya Klasör Seç</string>
+ <string name="fm_sel_file">Bir Dosya veya Klasör Seçin</string>
<string name="fm_type_folder">Klasör</string>
<string name="fm_type_file">Dosya</string>
- <string name="fm_choose_act">Eylem Seç</string>
+ <string name="fm_choose_act">Eylem Seçin</string>
<string name="fm_selected">%tw_fm_type% seçili:</string>
<string name="fm_copy_btn">Kopyala</string>
<string name="fm_copy_file_btn">Dosyayı Kopyala</string>
@@ -452,7 +444,7 @@
<string name="fm_rename_file_btn">Dosyayı Yeniden Adlandır</string>
<string name="fm_rename_folder_btn">Klasörü Yeniden Adlandır</string>
<string name="fm_renaming">Yeniden Adlandır</string>
- <string name="fm_sel_dest">Hedef Klasörü Seç</string>
+ <string name="fm_sel_dest">Hedef Klasörü Seçin</string>
<string name="fm_sel_curr_folder">Geçerli Klasörü Seç</string>
<string name="fm_rename_hdr">Yeniden Adlandır</string>
<string name="fm_set_perms_hdr">Ä°zinleri Ayarla</string>
@@ -489,28 +481,6 @@
<string name="install_cancel">Yükleme</string>
<string name="sel_storage_list">Depolama Seç</string>
<string name="ok_btn">Tamam</string>
- <string name="install_twrp_ramdisk">Recovery Ramdisk Yükle</string>
- <string name="install_kernel">Kernel Yükle</string>
- <string name="repack_kernel_confirm_hdr">Kernel Yükle</string>
- <string name="repack_ramdisk_confirm_hdr">Recovery Yükle</string>
- <string name="repack_kernel_confirm">Kernel Yüklensin mi?</string>
- <string name="repack_ramdisk_confirm">Recovery Yüklensin mi?</string>
- <string name="repack_backup_first">Önce geçerli imajı yedekle</string>
- <string name="repack">Yeniden paketle</string>
- <string name="swipe_to_install">Yüklemek için Kaydır</string>
- <string name="installing">Yükleniyor...</string>
- <string name="install_complete">Yükleme Tamamlandı</string>
- <string name="unpack_error">Ä°maj açılırken hata oluÅŸtu.</string>
- <string name="repack_error">İmajı yeniden paketleme hatası.</string>
- <string name="unpacking_image">{1} açılıyor...</string>
- <string name="repacking_image">{1} yeniden paketleniyor...</string>
- <string name="repack_image_hdr">Ä°maj Seç</string>
- <string name="fix_recovery_loop">Recovery Bootloop'unu Onar</string>
- <string name="fix_recovery_loop_confirm">Recovery Bootloop'u Onarılsın mı?</string>
- <string name="fixing_recovery_loop">Recovery Bootloop'u Onarılıyor...</string>
- <string name="fix_recovery_loop_complete">Recovery Bootloop'unu Onarma Tamamlandı</string>
- <string name="fixing_recovery_loop_patch">Kernel yamalanıyor...</string>
- <string name="fix_recovery_loop_patch_error">Kernel yamalama hatası.</string>
<!-- Various console messages - these consist of user displayed messages, oftentimes errors -->
<string name="no_kernel_selinux">Kernel SELinux içeriklerini okuma desteÄŸine sahip deÄŸil.</string>
@@ -540,7 +510,7 @@
<string name="backup_folder"> * Yedekleme Klasörü: {1}</string>
<string name="fail_backup_folder">Yedekleme klasörü oluÅŸturulamadı.</string>
<string name="avg_backup_fs">Dosya sistemleri için ortalama yedekleme hızı: {1} MB/sn</string>
- <string name="avg_backup_img">Ä°majlı sürücüler için ortalama yedekleme hızı: {1} MB/sn</string>
+ <string name="avg_backup_img">Görüntülü sürücüler için ortalama yedekleme hızı: {1} MB/sn</string>
<string name="total_backed_size">[{1} MB YEDEKLENDÄ°]</string>
<string name="backup_completed">[YEDEKLEME {1} SANÄ°YEDE TAMAMLANDI]</string>
<string name="restore_started">[GERÄ° YÜKLEME BAÅžLATILDI]</string>
@@ -548,7 +518,7 @@
<!-- {1} is the partition display name and {2} is the number of seconds -->
<string name="restore_part_done">[{1} bitti ({2} saniye)]</string>
<string name="verifying_digest" version="2">Digest Doğrulanıyor</string>
- <string name="skip_digest" version="2">Kullanıcı ayarına göre Digest kontrolü geçiliyor.</string>
+ <string name="skip_digest" version="2">Kullanıcı ayarına göre Digest denetimi geçiliyor.</string>
<string name="calc_restore">Geri yükleme ayrıntıları hesaplanıyor...</string>
<string name="restore_read_only">{1} geri yüklenemiyor -- salt okunur baÄŸlanmış.</string>
<string name="restore_unable_locate">Geri yüklemek için \'{1}\' bölümü bulunamıyor.</string>
@@ -563,10 +533,9 @@
<string name="unable_find_part_path">\'{1}\' yolu için bölüm bulunamıyor</string>
<string name="update_part_details">Bölüm ayrıntıları güncelleniyor...</string>
<string name="update_part_details_done">...bitti</string>
- <string name="wiping_dalvik">Dalvik Dizinleri Temizleniyor...</string>
+ <string name="wiping_dalvik">Dalvik ÖnbelleÄŸi Dizinleri Temizleniyor...</string>
<string name="cleaned">Temizlendi: {1}...</string>
- <string name="cache_dalvik_done">-- Dalvik ÖnbelleÄŸi Dizinleri Temizleme Tamamlandı!</string>
- <string name="dalvik_done">-- Dalvik Dizinleri Temizleme Tamamlandı!</string>
+ <string name="dalvik_done">-- Dalvik ÖnbelleÄŸi Dizinleri Temizleme Tamamlandı!</string>
<string name="no_andsec">Android secure bölümü yok.</string>
<string name="unable_to_locate">{1} bulunamıyor.</string>
<string name="wiping_datamedia">Dahili depolama temizleniyor -- /data/media...</string>
@@ -634,7 +603,7 @@
<string name="backup_folder_set">Yedekleme klasörü '{1}' olarak ayarlandı</string>
<string name="locate_backup_err">'{1}' yedeği bulunamadı</string>
<string name="set_restore_opt">Geri yükleme seçeneklerini ayarlama: '{1}':</string>
- <string name="digest_check_skip" version="2">Digest kontrolünü atlama açık</string>
+ <string name="digest_check_skip" version="2">Digest denetimini atlama açık</string>
<string name="ors_encrypt_restore_err">ÅžifrelenmiÅŸ bir yedeklemeyi geri yüklemek için OpenRecoveryScript kullanılamıyor.</string>
<string name="mounting">Bağlanıyor</string>
<string name="unmounting">Kaldırılıyor</string>
@@ -669,7 +638,7 @@
<string name="verify_zip_fail">Zip imzası doğrulama başarısız oldu!</string>
<string name="verify_zip_done">Zip imzası başarıyla doğrulandı.</string>
<string name="zip_corrupt">Zip dosyası bozuk!</string>
- <string name="no_digest" version="2">Digest kontrolü geçiliyor: Digest dosyası bulunamadı</string>
+ <string name="no_digest" version="2">Digest denetimi geçiliyor: Digest dosyası bulunamadı</string>
<string name="digest_fail" version="2">Digest eÅŸleÅŸmiyor</string>
<string name="digest_match" version="2">Digest eÅŸleÅŸti</string>
<string name="pid_signal">{1} process ended with signal: {2}</string>
diff --git a/htcdumlock/Android.mk b/htcdumlock/Android.mk
index 242f124..27b3c34 100644
--- a/htcdumlock/Android.mk
+++ b/htcdumlock/Android.mk
@@ -6,8 +6,8 @@
htcdumlock.c
LOCAL_CFLAGS:= -g -c -W
LOCAL_MODULE:=htcdumlock
- LOCAL_MODULE_TAGS:= eng
+ LOCAL_MODULE_TAGS:= optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
include $(BUILD_EXECUTABLE)
-endif
\ No newline at end of file
+endif
diff --git a/injecttwrp/Android.mk b/injecttwrp/Android.mk
index 2557523..d7f7936 100644
--- a/injecttwrp/Android.mk
+++ b/injecttwrp/Android.mk
@@ -6,7 +6,7 @@
injecttwrp.c
LOCAL_CFLAGS:= -g -c -W
LOCAL_MODULE:=injecttwrp
- LOCAL_MODULE_TAGS:= eng
+ LOCAL_MODULE_TAGS:= optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
include $(BUILD_EXECUTABLE)
diff --git a/otautil/ZipUtil.cpp b/install/ZipUtil.cpp
old mode 100644
new mode 100755
similarity index 98%
rename from otautil/ZipUtil.cpp
rename to install/ZipUtil.cpp
index a2d0cba..f8134bc
--- a/otautil/ZipUtil.cpp
+++ b/install/ZipUtil.cpp
@@ -28,7 +28,7 @@
#include <selinux/selinux.h>
#include <ziparchive/zip_archive.h>
-#include "otautil/DirUtil.h"
+#include "otautil/dirutil.h"
static constexpr mode_t UNZIP_DIRMODE = 0755;
static constexpr mode_t UNZIP_FILEMODE = 0644;
diff --git a/otautil/ZipUtil.h b/install/ZipUtil.h
similarity index 100%
rename from otautil/ZipUtil.h
rename to install/ZipUtil.h
diff --git a/install/adb_install.cpp b/install/adb_install.cpp
old mode 100644
new mode 100755
index 9497df5..44a58a0
--- a/install/adb_install.cpp
+++ b/install/adb_install.cpp
@@ -90,7 +90,7 @@
// Installs the package from FUSE. Returns the installation result and whether it should continue
// waiting for new commands.
-static auto AdbInstallPackageHandler(RecoveryUI* ui, int* result) {
+static auto AdbInstallPackageHandler(int* result) {
// How long (in seconds) we wait for the package path to be ready. It doesn't need to be too long
// because the minadbd service has already issued an install command. FUSE_SIDELOAD_HOST_PATHNAME
// will start to exist once the host connects and starts serving a package. Poll for its
@@ -106,11 +106,11 @@
continue;
} else {
should_continue = false;
- ui->Print("\nTimed out waiting for fuse to be ready.\n\n");
+ // ui->Print("\nTimed out waiting for fuse to be ready.\n\n");
break;
}
}
- *result = install_package(FUSE_SIDELOAD_HOST_PATHNAME, false, false, 0, ui);
+ *result = install_package(FUSE_SIDELOAD_HOST_PATHNAME, false, false, 0);
break;
}
@@ -182,7 +182,7 @@
// TODO(xunchang) add a wrapper function and kill the minadbd service there.
static void ListenAndExecuteMinadbdCommands(
- RecoveryUI* ui, pid_t minadbd_pid, android::base::unique_fd&& socket_fd,
+ pid_t minadbd_pid, android::base::unique_fd&& socket_fd,
const std::map<MinadbdCommand, CommandFunction>& command_map) {
android::base::unique_fd epoll_fd(epoll_create1(O_CLOEXEC));
if (epoll_fd == -1) {
@@ -206,8 +206,8 @@
constexpr int TIMEOUT_MILLIS = 300 * 1000;
while (true) {
// Reset the progress bar and the background image before each command.
- ui->SetProgressType(RecoveryUI::EMPTY);
- ui->SetBackground(RecoveryUI::NO_COMMAND);
+ // ui->SetProgressType(RecoveryUI::EMPTY);
+ // ui->SetBackground(RecoveryUI::NO_COMMAND);
// Poll for the status change of the socket_fd, and handle the message if the fd is ready to
// read.
@@ -272,8 +272,8 @@
// b11. exit the listening loop
//
static void CreateMinadbdServiceAndExecuteCommands(
- RecoveryUI* ui, const std::map<MinadbdCommand, CommandFunction>& command_map,
- bool rescue_mode) {
+ const std::map<MinadbdCommand, CommandFunction>& command_map,
+ bool rescue_mode, std::string install_file) {
signal(SIGPIPE, SIG_IGN);
android::base::unique_fd recovery_socket;
@@ -291,8 +291,10 @@
if (child == 0) {
recovery_socket.reset();
std::vector<std::string> minadbd_commands = {
- "/system/bin/minadbd",
- "--socket_fd",
+ "/sbin/recovery",
+ "recovery",
+ "--adbd",
+ install_file,
std::to_string(minadbd_socket.release()),
};
if (rescue_mode) {
@@ -312,7 +314,7 @@
return;
}
- std::thread listener_thread(ListenAndExecuteMinadbdCommands, ui, child,
+ std::thread listener_thread(ListenAndExecuteMinadbdCommands, child,
std::move(recovery_socket), std::ref(command_map));
if (listener_thread.joinable()) {
listener_thread.join();
@@ -331,7 +333,9 @@
signal(SIGPIPE, SIG_DFL);
}
-int ApplyFromAdb(Device* device, bool rescue_mode, Device::BuiltinAction* reboot_action) {
+// int ApplyFromAdb(Device* device, bool rescue_mode, Device::BuiltinAction* reboot_action) {
+ int ApplyFromAdb(const char* install_file, Device::BuiltinAction* reboot_action) {
+
// Save the usb state to restore after the sideload operation.
std::string usb_state = android::base::GetProperty("sys.usb.state", "none");
// Clean up state and stop adbd.
@@ -340,24 +344,25 @@
return INSTALL_ERROR;
}
- RecoveryUI* ui = device->GetUI();
+ // RecoveryUI* ui = device->GetUI();
int install_result = INSTALL_ERROR;
std::map<MinadbdCommand, CommandFunction> command_map{
- { MinadbdCommand::kInstall, std::bind(&AdbInstallPackageHandler, ui, &install_result) },
- { MinadbdCommand::kRebootAndroid, std::bind(&AdbRebootHandler, MinadbdCommand::kRebootAndroid,
+ { MinadbdCommand::kInstall, std::bind(&AdbInstallPackageHandler, &install_result) },
+ { MinadbdCommand::kRebootAndroid, std::bind(&AdbRebootHandler, MinadbdCommand::kRebootAndroid,
+ &install_result, reboot_action) },
+ { MinadbdCommand::kRebootBootloader,
+ std::bind(&AdbRebootHandler, MinadbdCommand::kRebootBootloader, &install_result,
+ reboot_action) },
+ { MinadbdCommand::kRebootFastboot, std::bind(&AdbRebootHandler, MinadbdCommand::kRebootFastboot,
&install_result, reboot_action) },
- { MinadbdCommand::kRebootBootloader,
- std::bind(&AdbRebootHandler, MinadbdCommand::kRebootBootloader, &install_result,
- reboot_action) },
- { MinadbdCommand::kRebootFastboot, std::bind(&AdbRebootHandler, MinadbdCommand::kRebootFastboot,
- &install_result, reboot_action) },
- { MinadbdCommand::kRebootRecovery, std::bind(&AdbRebootHandler, MinadbdCommand::kRebootRecovery,
- &install_result, reboot_action) },
- { MinadbdCommand::kRebootRescue,
- std::bind(&AdbRebootHandler, MinadbdCommand::kRebootRescue, &install_result, reboot_action) },
- };
+ { MinadbdCommand::kRebootRecovery, std::bind(&AdbRebootHandler, MinadbdCommand::kRebootRecovery,
+ &install_result, reboot_action) },
+ { MinadbdCommand::kRebootRescue,
+ std::bind(&AdbRebootHandler, MinadbdCommand::kRebootRescue, &install_result, reboot_action) },
+};
+/*
if (!rescue_mode) {
ui->Print(
"\n\nNow send the package you want to apply\n"
@@ -371,8 +376,8 @@
ui->Print("\n\nWaiting for rescue commands...\n");
}
-
- CreateMinadbdServiceAndExecuteCommands(ui, command_map, rescue_mode);
+*/
+ CreateMinadbdServiceAndExecuteCommands(command_map, false, install_file);
// Clean up before switching to the older state, for example setting the state
// to none sets sys/class/android_usb/android0/enable to 0.
diff --git a/install/fuse_sdcard_install.cpp b/install/fuse_sdcard_install.cpp
old mode 100644
new mode 100755
index 1aa8768..011847b
--- a/install/fuse_sdcard_install.cpp
+++ b/install/fuse_sdcard_install.cpp
@@ -184,7 +184,7 @@
}
}
- result = install_package(FUSE_SIDELOAD_HOST_PATHNAME, false, false, 0 /*retry_count*/, ui);
+ result = install_package(FUSE_SIDELOAD_HOST_PATHNAME, false, false, 0 /*retry_count*/);
break;
}
diff --git a/install/include/install/adb_install.h b/install/include/install/adb_install.h
old mode 100644
new mode 100755
index 3a0a817..f7b15b2
--- a/install/include/install/adb_install.h
+++ b/install/include/install/adb_install.h
@@ -21,4 +21,4 @@
// Applies a package via `adb sideload` or `adb rescue`. Returns the install result (in `enum
// InstallResult`). When a reboot has been requested, INSTALL_REBOOT will be the return value, with
// the reboot target set in reboot_action.
-int ApplyFromAdb(Device* device, bool rescue_mode, Device::BuiltinAction* reboot_action);
+int ApplyFromAdb(const char* install_file, Device::BuiltinAction* reboot_action);
diff --git a/install/include/install/fuse_sdcard_install.h b/install/include/install/fuse_sdcard_install.h
old mode 100644
new mode 100755
index 43f2489..d9214ca
--- a/install/include/install/fuse_sdcard_install.h
+++ b/install/include/install/fuse_sdcard_install.h
@@ -16,17 +16,7 @@
#pragma once
-<<<<<<< HEAD:adb_install.h
-#include <sys/types.h>
-
-//class RecoveryUI;
-
-//static void set_usb_driver(bool enabled);
-//static void maybe_restart_adbd();
-int apply_from_adb(const char* install_file, pid_t* child_pid);
-=======
#include "recovery_ui/device.h"
#include "recovery_ui/ui.h"
->>>>>>> android-10.0.0_r25:install/include/install/fuse_sdcard_install.h
int ApplyFromSdcard(Device* device, RecoveryUI* ui);
diff --git a/install/include/install/install.h b/install/include/install/install.h
old mode 100644
new mode 100755
index c0a8f1f..9e6787f
--- a/install/include/install/install.h
+++ b/install/include/install/install.h
@@ -48,11 +48,11 @@
// successful installation if |should_wipe_cache| is true or an updater command asks to wipe the
// cache.
int install_package(const std::string& package, bool should_wipe_cache, bool needs_mount,
- int retry_count, RecoveryUI* ui);
+ int retry_count);
// Verifies the package by ota keys. Returns true if the package is verified successfully,
// otherwise returns false.
-bool verify_package(Package* package, RecoveryUI* ui);
+bool verify_package(Package* package);
// Reads meta data file of the package; parses each line in the format "key=value"; and writes the
// result to |metadata|. Return true if succeed, otherwise return false.
diff --git a/install/include/install/package.h b/install/include/install/package.h
old mode 100644
new mode 100755
index cd44d10..50a4ffa
--- a/install/include/install/package.h
+++ b/install/include/install/package.h
@@ -33,9 +33,9 @@
class Package : public VerifierInterface {
public:
static std::unique_ptr<Package> CreateMemoryPackage(
- const std::string& path, const std::function<void(float)>& set_progress);
+ const std::string& path);
static std::unique_ptr<Package> CreateMemoryPackage(
- std::vector<uint8_t> content, const std::function<void(float)>& set_progress);
+ std::vector<uint8_t> content);
static std::unique_ptr<Package> CreateFilePackage(const std::string& path,
const std::function<void(float)>& set_progress);
diff --git a/install/include/install/wipe_data.h b/install/include/install/wipe_data.h
old mode 100644
new mode 100755
index b34891f..76ebf05
--- a/install/include/install/wipe_data.h
+++ b/install/include/install/wipe_data.h
@@ -24,7 +24,7 @@
struct selabel_handle;
// Returns true on success.
-bool WipeCache(RecoveryUI* ui, const std::function<bool()>& confirm);
+bool WipeCache(const std::function<bool()>& confirm);
// Returns true on success.
bool WipeData(Device* device, bool convert_fbe);
diff --git a/installcommand.h b/install/include/installcommand.h
similarity index 100%
rename from installcommand.h
rename to install/include/installcommand.h
diff --git a/legacy_property_service.h b/install/include/legacy_property_service.h
similarity index 100%
rename from legacy_property_service.h
rename to install/include/legacy_property_service.h
diff --git a/set_metadata.h b/install/include/set_metadata.h
similarity index 100%
rename from set_metadata.h
rename to install/include/set_metadata.h
diff --git a/tw_atomic.hpp b/install/include/tw_atomic.hpp
similarity index 100%
rename from tw_atomic.hpp
rename to install/include/tw_atomic.hpp
diff --git a/zipwrap.hpp b/install/include/zipwrap.hpp
old mode 100644
new mode 100755
similarity index 94%
rename from zipwrap.hpp
rename to install/include/zipwrap.hpp
index f86e98e..7102116
--- a/zipwrap.hpp
+++ b/install/include/zipwrap.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 bigbiff/Dees_Troy TeamWin
+ * Copyright (C) TeamWin
* This file is part of TWRP/TeamWin Recovery Project.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +24,7 @@
#include "minzip/SysUtil.h"
#else
#include <ziparchive/zip_archive.h>
-#include "otautil/SysUtil.h"
+#include "otautil/sysutil.h"
#endif
using namespace std;
diff --git a/install/install.cpp b/install/install.cpp
old mode 100644
new mode 100755
index 0e3cccf..55d51fc
--- a/install/install.cpp
+++ b/install/install.cpp
@@ -64,8 +64,8 @@
static_assert(kRecoveryApiVersion == RECOVERY_API_VERSION, "Mismatching recovery API versions.");
// Default allocation of progress bar segments to operations
-static constexpr int VERIFICATION_PROGRESS_TIME = 60;
-static constexpr float VERIFICATION_PROGRESS_FRACTION = 0.25;
+// static constexpr int VERIFICATION_PROGRESS_TIME = 60;
+// static constexpr float VERIFICATION_PROGRESS_FRACTION = 0.25;
static std::condition_variable finish_log_temperature;
@@ -157,8 +157,6 @@
return INSTALL_ERROR;
}
-<<<<<<< HEAD:install.cpp
-=======
// Check for downgrade version.
int64_t build_timestamp =
android::base::GetIntProperty("ro.build.date.utc", std::numeric_limits<int64_t>::max());
@@ -182,7 +180,6 @@
}
}
->>>>>>> android-10.0.0_r25:install/install.cpp
return 0;
}
@@ -330,7 +327,7 @@
// If the package contains an update binary, extract it and run it.
static int try_update_binary(const std::string& package, ZipArchiveHandle zip, bool* wipe_cache,
std::vector<std::string>* log_buffer, int retry_count,
- int* max_temperature, RecoveryUI* ui) {
+ int* max_temperature) {
std::map<std::string, std::string> metadata;
if (!ReadMetadataFromPackage(zip, &metadata)) {
LOG(ERROR) << "Failed to parse metadata in the zip file";
@@ -442,7 +439,7 @@
int seconds;
if (tokens.size() == 2 && android::base::ParseDouble(tokens[0].c_str(), &fraction) &&
android::base::ParseInt(tokens[1], &seconds)) {
- ui->ShowProgress(fraction * (1 - VERIFICATION_PROGRESS_FRACTION), seconds);
+ // ui->ShowProgress(fraction * (1 - VERIFICATION_PROGRESS_FRACTION), seconds);
} else {
LOG(ERROR) << "invalid \"progress\" parameters: " << line;
}
@@ -450,22 +447,22 @@
std::vector<std::string> tokens = android::base::Split(args, " ");
double fraction;
if (tokens.size() == 1 && android::base::ParseDouble(tokens[0].c_str(), &fraction)) {
- ui->SetProgress(fraction);
+ // ui->SetProgress(fraction);
} else {
LOG(ERROR) << "invalid \"set_progress\" parameters: " << line;
}
} else if (command == "ui_print") {
- ui->PrintOnScreenOnly("%s\n", args.c_str());
+ // ui->PrintOnScreenOnly("%s\n", args.c_str());
fflush(stdout);
} else if (command == "wipe_cache") {
*wipe_cache = true;
} else if (command == "clear_display") {
- ui->SetBackground(RecoveryUI::NONE);
+ // ui->SetBackground(RecoveryUI::NONE);
} else if (command == "enable_reboot") {
// packages can explicitly request that they want the user
// to be able to reboot during installation (useful for
// debugging packages that don't exit).
- ui->SetEnableReboot(true);
+ // ui->SetEnableReboot(true);
} else if (command == "retry_update") {
retry_update = true;
} else if (command == "log") {
@@ -576,16 +573,16 @@
static int really_install_package(const std::string& path, bool* wipe_cache, bool needs_mount,
std::vector<std::string>* log_buffer, int retry_count,
- int* max_temperature, RecoveryUI* ui) {
- ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
- ui->Print("Finding update package...\n");
+ int* max_temperature) {
+ // ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
+ // ui->Print("Finding update package...\n");
// Give verification half the progress bar...
- ui->SetProgressType(RecoveryUI::DETERMINATE);
- ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME);
+ // ui->SetProgressType(RecoveryUI::DETERMINATE);
+ // ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME);
LOG(INFO) << "Update location: " << path;
// Map the update package into memory.
- ui->Print("Opening update package...\n");
+ // ui->Print("Opening update package...\n");
if (needs_mount) {
if (path[0] == '@') {
@@ -596,14 +593,14 @@
}
auto package = Package::CreateMemoryPackage(
- path, std::bind(&RecoveryUI::SetProgress, ui, std::placeholders::_1));
+ path);
if (!package) {
log_buffer->push_back(android::base::StringPrintf("error: %d", kMapFileFailure));
return INSTALL_CORRUPT;
}
// Verify package.
- if (!verify_package(package.get(), ui)) {
+ if (!verify_package(package.get())) {
log_buffer->push_back(android::base::StringPrintf("error: %d", kZipVerificationFailure));
return INSTALL_CORRUPT;
}
@@ -622,21 +619,21 @@
}
// Verify and install the contents of the package.
- ui->Print("Installing update...\n");
- if (retry_count > 0) {
- ui->Print("Retry attempt: %d\n", retry_count);
- }
- ui->SetEnableReboot(false);
+ // ui->Print("Installing update...\n");
+ // if (retry_count > 0) {
+ // ui->Print("Retry attempt: %d\n", retry_count);
+ // }
+ // ui->SetEnableReboot(false);
int result =
- try_update_binary(path, zip, wipe_cache, log_buffer, retry_count, max_temperature, ui);
- ui->SetEnableReboot(true);
- ui->Print("\n");
+ try_update_binary(path, zip, wipe_cache, log_buffer, retry_count, max_temperature);
+ // ui->SetEnableReboot(true);
+ // ui->Print("\n");
return result;
}
int install_package(const std::string& path, bool should_wipe_cache, bool needs_mount,
- int retry_count, RecoveryUI* ui) {
+ int retry_count) {
CHECK(!path.empty());
auto start = std::chrono::system_clock::now();
@@ -652,7 +649,7 @@
} else {
bool updater_wipe_cache = false;
result = really_install_package(path, &updater_wipe_cache, needs_mount, &log_buffer,
- retry_count, &max_temperature, ui);
+ retry_count, &max_temperature);
should_wipe_cache = should_wipe_cache || updater_wipe_cache;
}
@@ -709,7 +706,7 @@
LOG(INFO) << log_content;
if (result == INSTALL_SUCCESS && should_wipe_cache) {
- if (!WipeCache(ui, nullptr)) {
+ if (!WipeCache(nullptr)) {
result = INSTALL_ERROR;
}
}
@@ -717,7 +714,7 @@
return result;
}
-bool verify_package(Package* package, RecoveryUI* ui) {
+bool verify_package(Package* package) {
static constexpr const char* CERTIFICATE_ZIP_FILE = "/system/etc/security/otacerts.zip";
std::vector<Certificate> loaded_keys = LoadKeysFromZipfile(CERTIFICATE_ZIP_FILE);
if (loaded_keys.empty()) {
@@ -727,11 +724,11 @@
LOG(INFO) << loaded_keys.size() << " key(s) loaded from " << CERTIFICATE_ZIP_FILE;
// Verify package.
- ui->Print("Verifying update package...\n");
- auto t0 = std::chrono::system_clock::now();
+ // ui->Print("Verifying update package...\n");
+ // auto t0 = std::chrono::system_clock::now();
int err = verify_file(package, loaded_keys);
- std::chrono::duration<double> duration = std::chrono::system_clock::now() - t0;
- ui->Print("Update package verification took %.1f s (result %d).\n", duration.count(), err);
+ // std::chrono::duration<double> duration = std::chrono::system_clock::now() - t0;
+ // ui->Print("Update package verification took %.1f s (result %d).\n", duration.count(), err);
if (err != VERIFY_SUCCESS) {
LOG(ERROR) << "Signature verification failed";
LOG(ERROR) << "error: " << kZipVerificationFailure;
diff --git a/installcommand.cpp b/install/installcommand.cpp
old mode 100644
new mode 100755
similarity index 95%
rename from installcommand.cpp
rename to install/installcommand.cpp
index fa079ea..f421056
--- a/installcommand.cpp
+++ b/install/installcommand.cpp
@@ -37,7 +37,7 @@
#ifdef USE_OLD_VERIFIER
#include "verifier24/verifier.h"
#else
-#include "verifier.h"
+#include "install/install.h"
#endif
#ifdef AB_OTA_UPDATER
@@ -124,23 +124,9 @@
property_get("ro.product.device", value, "");
const std::string& pkg_device = metadata["pre-device"];
-
- std::vector<std::string> assertResults = android::base::Split(pkg_device, ",");
-
- bool deviceExists = false;
-
- for(const std::string& deviceAssert : assertResults)
- {
- std::string assertName = android::base::Trim(deviceAssert);
- if (assertName == value && !assertName.empty()) {
- deviceExists = true;
- break;
- }
- }
-
- if (!deviceExists) {
+ if (pkg_device != value || pkg_device.empty()) {
printf("Package is for product %s but expected %s\n",
- pkg_device.c_str(), value);
+ pkg_device.c_str(), value);
return INSTALL_ERROR;
}
diff --git a/legacy_property_service.cpp b/install/legacy_property_service.cpp
similarity index 100%
rename from legacy_property_service.cpp
rename to install/legacy_property_service.cpp
diff --git a/install/package.cpp b/install/package.cpp
old mode 100644
new mode 100755
index 4402f48..22673cf
--- a/install/package.cpp
+++ b/install/package.cpp
@@ -32,11 +32,10 @@
class MemoryPackage : public Package {
public:
// Constructs the class from a file. We will memory maps the file later.
- MemoryPackage(const std::string& path, std::unique_ptr<MemMapping> map,
- const std::function<void(float)>& set_progress);
+ MemoryPackage(const std::string& path, std::unique_ptr<MemMapping> map);
// Constructs the class from the package bytes in |content|.
- MemoryPackage(std::vector<uint8_t> content, const std::function<void(float)>& set_progress);
+ MemoryPackage(std::vector<uint8_t> content);
~MemoryPackage() override;
@@ -102,14 +101,14 @@
};
std::unique_ptr<Package> Package::CreateMemoryPackage(
- const std::string& path, const std::function<void(float)>& set_progress) {
+ const std::string& path) {
std::unique_ptr<MemMapping> mmap = std::make_unique<MemMapping>();
if (!mmap->MapFile(path)) {
LOG(ERROR) << "failed to map file";
return nullptr;
}
- return std::make_unique<MemoryPackage>(path, std::move(mmap), set_progress);
+ return std::make_unique<MemoryPackage>(path, std::move(mmap));
}
std::unique_ptr<Package> Package::CreateFilePackage(
@@ -130,25 +129,21 @@
}
std::unique_ptr<Package> Package::CreateMemoryPackage(
- std::vector<uint8_t> content, const std::function<void(float)>& set_progress) {
- return std::make_unique<MemoryPackage>(std::move(content), set_progress);
+ std::vector<uint8_t> content) {
+ return std::make_unique<MemoryPackage>(std::move(content));
}
-MemoryPackage::MemoryPackage(const std::string& path, std::unique_ptr<MemMapping> map,
- const std::function<void(float)>& set_progress)
+MemoryPackage::MemoryPackage(const std::string& path, std::unique_ptr<MemMapping> map)
: map_(std::move(map)), path_(path), zip_handle_(nullptr) {
addr_ = map_->addr;
package_size_ = map_->length;
- set_progress_ = set_progress;
}
-MemoryPackage::MemoryPackage(std::vector<uint8_t> content,
- const std::function<void(float)>& set_progress)
+MemoryPackage::MemoryPackage(std::vector<uint8_t> content)
: package_content_(std::move(content)), zip_handle_(nullptr) {
CHECK(!package_content_.empty());
addr_ = package_content_.data();
package_size_ = package_content_.size();
- set_progress_ = set_progress;
}
MemoryPackage::~MemoryPackage() {
diff --git a/set_metadata.cpp b/install/set_metadata.cpp
similarity index 100%
rename from set_metadata.cpp
rename to install/set_metadata.cpp
diff --git a/tw_atomic.cpp b/install/tw_atomic.cpp
similarity index 100%
rename from tw_atomic.cpp
rename to install/tw_atomic.cpp
diff --git a/install/wipe_data.cpp b/install/wipe_data.cpp
old mode 100644
new mode 100755
index 765a815..b0e44c7
--- a/install/wipe_data.cpp
+++ b/install/wipe_data.cpp
@@ -36,12 +36,12 @@
constexpr const char* DATA_ROOT = "/data";
constexpr const char* METADATA_ROOT = "/metadata";
-static bool EraseVolume(const char* volume, RecoveryUI* ui, bool convert_fbe) {
+static bool EraseVolume(const char* volume, bool convert_fbe) {
bool is_cache = (strcmp(volume, CACHE_ROOT) == 0);
bool is_data = (strcmp(volume, DATA_ROOT) == 0);
- ui->SetBackground(RecoveryUI::ERASING);
- ui->SetProgressType(RecoveryUI::INDETERMINATE);
+ // ui->SetBackground(RecoveryUI::ERASING);
+ // ui->SetProgressType(RecoveryUI::INDETERMINATE);
std::vector<saved_log_file> log_files;
if (is_cache) {
@@ -50,7 +50,7 @@
log_files = ReadLogFilesToMemory();
}
- ui->Print("Formatting %s...\n", volume);
+ // ui->Print("Formatting %s...\n", volume);
ensure_path_unmounted(volume);
@@ -84,10 +84,10 @@
return (result == 0);
}
-bool WipeCache(RecoveryUI* ui, const std::function<bool()>& confirm_func) {
+bool WipeCache(const std::function<bool()>& confirm_func) {
bool has_cache = volume_for_mount_point("/cache") != nullptr;
if (!has_cache) {
- ui->Print("No /cache partition found.\n");
+ // ui->Print("No /cache partition found.\n");
return false;
}
@@ -95,29 +95,29 @@
return false;
}
- ui->Print("\n-- Wiping cache...\n");
- bool success = EraseVolume("/cache", ui, false);
- ui->Print("Cache wipe %s.\n", success ? "complete" : "failed");
+ // ui->Print("\n-- Wiping cache...\n");
+ bool success = EraseVolume("/cache", false);
+ // ui->Print("Cache wipe %s.\n", success ? "complete" : "failed");
return success;
}
bool WipeData(Device* device, bool convert_fbe) {
- RecoveryUI* ui = device->GetUI();
- ui->Print("\n-- Wiping data...\n");
+ // RecoveryUI* ui = device->GetUI();
+ // ui->Print("\n-- Wiping data...\n");
bool success = device->PreWipeData();
if (success) {
- success &= EraseVolume(DATA_ROOT, ui, convert_fbe);
+ success &= EraseVolume(DATA_ROOT, convert_fbe);
bool has_cache = volume_for_mount_point("/cache") != nullptr;
if (has_cache) {
- success &= EraseVolume(CACHE_ROOT, ui, false);
+ success &= EraseVolume(CACHE_ROOT, false);
}
if (volume_for_mount_point(METADATA_ROOT) != nullptr) {
- success &= EraseVolume(METADATA_ROOT, ui, false);
+ success &= EraseVolume(METADATA_ROOT, false);
}
}
if (success) {
success &= device->PostWipeData();
}
- ui->Print("Data wipe %s.\n", success ? "complete" : "failed");
+ // ui->Print("Data wipe %s.\n", success ? "complete" : "failed");
return success;
}
\ No newline at end of file
diff --git a/zipwrap.cpp b/install/zipwrap.cpp
old mode 100644
new mode 100755
similarity index 97%
rename from zipwrap.cpp
rename to install/zipwrap.cpp
index 9619540..ddd13de
--- a/zipwrap.cpp
+++ b/install/zipwrap.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 bigbiff/Dees_Troy TeamWin
+ * Copyright (C) TeamWin
* This file is part of TWRP/TeamWin Recovery Project.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,8 +27,8 @@
#include "minzip/SysUtil.h"
#else
#include <ziparchive/zip_archive.h>
-#include "otautil/ZipUtil.h"
-#include "otautil/SysUtil.h"
+#include "ZipUtil.h"
+#include "otautil/sysutil.h"
#endif
ZipWrap::ZipWrap() {
diff --git a/adb_install.cpp b/install28/adb_install.cpp
old mode 100644
new mode 100755
similarity index 96%
rename from adb_install.cpp
rename to install28/adb_install.cpp
index 291708c..5b57641
--- a/adb_install.cpp
+++ b/install28/adb_install.cpp
@@ -14,8 +14,6 @@
* limitations under the License.
*/
-#include "adb_install.h"
-
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
@@ -31,15 +29,19 @@
#include <stdio.h>
#include <unistd.h>
-#include "ui.h"
#include "cutils/properties.h"
#include "common.h"
-#include "fuse_sideload.h"
#ifdef USE_OLD_VERIFIER
#include "verifier24/verifier.h"
+#include "ui.h"
+#elif USE_28_VERIFIER
+#include "verifier28/verifier.h"
+#include "verifier28/adb_install.h"
+#include "verifier28/ui.h"
+#include "verifier28/fuse_sideload.h"
#else
-#include "verifier.h"
+#include "install/install.h"
#endif
static void set_usb_driver(bool enabled) {
diff --git a/install28/adb_install.h b/install28/adb_install.h
new file mode 100644
index 0000000..97dc83d
--- /dev/null
+++ b/install28/adb_install.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ADB_INSTALL_H
+#define _ADB_INSTALL_H
+
+#include <sys/types.h>
+
+//class RecoveryUI;
+
+//static void set_usb_driver(bool enabled);
+//static void maybe_restart_adbd();
+int apply_from_adb(const char* install_file, pid_t* child_pid);
+
+#endif
diff --git a/libcrecovery/Android.mk b/libcrecovery/Android.mk
index 8434d51..734e7b1 100644
--- a/libcrecovery/Android.mk
+++ b/libcrecovery/Android.mk
@@ -5,13 +5,13 @@
include $(CLEAR_VARS)
LOCAL_SRC_FILES := system.c popen.c
LOCAL_MODULE := libcrecovery
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := system.c popen.c
LOCAL_MODULE := libcrecovery
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY)
endif
diff --git a/libpixelflinger/Android.mk b/libpixelflinger/Android.mk
index 026e8ad..439c835 100644
--- a/libpixelflinger/Android.mk
+++ b/libpixelflinger/Android.mk
@@ -34,11 +34,11 @@
codeflinger/load_store.cpp \
codeflinger/blending.cpp \
codeflinger/texturing.cpp \
- fixed.cpp.arm \
- picker.cpp.arm \
- pixelflinger.cpp.arm \
- trap.cpp.arm \
- scanline.cpp.arm
+ fixed.cpp \
+ picker.cpp \
+ pixelflinger.cpp \
+ trap.cpp \
+ scanline.cpp
else
PIXELFLINGER_SRC_FILES_x86 := \
codeflinger/x86/X86Assembler.cpp \
@@ -105,6 +105,7 @@
LOCAL_C_INCLUDES += $(LOCAL_EXPORT_C_INCLUDE_DIRS)
LOCAL_CFLAGS := $(PIXELFLINGER_CFLAGS)
LOCAL_CPPFLAGS := -Wno-unused-function
+LOCAL_STATIC_LIBRARIES += libbase libutils libcutils
LOCAL_C_INCLUDES_x86 := $(PIXELFLINGER_C_INCLUDES_x86)
ifeq ($(TW_HAVE_X86_ACCELERATED_PIXELFLINGER),true)
LOCAL_WHOLE_STATIC_LIBRARIES += libenc
diff --git a/libtar/Android.mk b/libtar/Android.mk
index 90a5006..6b464f3 100644
--- a/libtar/Android.mk
+++ b/libtar/Android.mk
@@ -4,7 +4,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := libtar
-LOCAL_MODULE_TAGS := eng optional
+LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := append.c block.c decode.c encode.c extract.c handle.c output.c util.c wrapper.c basename.c strmode.c libtar_hash.c libtar_list.c dirname.c android_utils.c
LOCAL_C_INCLUDES += $(LOCAL_PATH) \
external/zlib
@@ -25,7 +25,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := libtar_static
-LOCAL_MODULE_TAGS := eng optional
+LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := append.c block.c decode.c encode.c extract.c handle.c output.c util.c wrapper.c basename.c strmode.c libtar_hash.c libtar_list.c dirname.c android_utils.c
LOCAL_C_INCLUDES += $(LOCAL_PATH) \
external/zlib
diff --git a/minadbd/Android.mk b/minadbd/Android.mk
old mode 100644
new mode 100755
index a50d844..0d2a8b3
--- a/minadbd/Android.mk
+++ b/minadbd/Android.mk
@@ -22,19 +22,20 @@
# libminadbd (static library)
# ===============================
include $(CLEAR_VARS)
+ # ../fuse_sideload.cpp \
LOCAL_SRC_FILES := \
fuse_adb_provider.cpp \
- ../fuse_sideload.cpp \
minadbd.cpp \
minadbd_services.cpp \
LOCAL_MODULE := libminadbd
LOCAL_CFLAGS := $(minadbd_cflags) -Wno-unused-parameter
LOCAL_CONLY_FLAGS := -Wimplicit-function-declaration
+LOCAL_CFLAGS += -std=gnu++2a
LOCAL_C_INCLUDES := $(LOCAL_PATH)/.. system/core/adb
-LOCAL_WHOLE_STATIC_LIBRARIES := libadbd
-LOCAL_SHARED_LIBRARIES := libbase liblog libcutils libc
+#LOCAL_WHOLE_STATIC_LIBRARIES := libadbd
+LOCAL_SHARED_LIBRARIES := libadbd libbase liblog libcutils libc
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/libmincrypt/includes
@@ -49,6 +50,13 @@
endif
endif
+ifeq ($shell test $(PLATFORM_SDK_VERSION) -lt 29; echo $$?),0)
+ LOCAL_C_INCLUDES += $(LOCAL_PATH)/../fuse_sideload28/
+else
+ LOCAL_C_INCLUDES += $(LOCAL_PATH)/../fuse_sideload/include
+ LOCAL_SHARED_LIBRARIES += libfusesideload
+endif
+
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
@@ -63,9 +71,16 @@
LOCAL_MODULE := libminadbd
LOCAL_CFLAGS := $(minadbd_cflags) -Wno-unused-parameter
LOCAL_CONLY_FLAGS := -Wimplicit-function-declaration
+LOCAL_CFLAGS += -std=gnu++2a
LOCAL_C_INCLUDES := $(LOCAL_PATH)/.. system/core/adb
-LOCAL_WHOLE_STATIC_LIBRARIES := libadbd
-LOCAL_STATIC_LIBRARIES := libbase liblog libcutils libc
+LOCAL_SHARED_LIBRARIES := libadbd libbase liblog libcutils libc
+#LOCAL_STATIC_LIBRARIES := libbase liblog libcutils libc
+
+ifeq ($shell test $(PLATFORM_SDK_VERSION) -lt 29; echo $$?),0)
+ LOCAL_C_INCLUDES += $(LOCAL_PATH)/../fuse_sideload28/
+else
+ LOCAL_C_INCLUDES += $(LOCAL_PATH)/../fuse_sideload/include
+endif
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/libmincrypt/includes
@@ -84,19 +99,19 @@
# minadbd_test (native test)
# ===============================
-include $(CLEAR_VARS)
+# include $(CLEAR_VARS)
-LOCAL_MODULE := minadbd_test
-LOCAL_COMPATIBILITY_SUITE := device-tests
-LOCAL_SRC_FILES := fuse_adb_provider_test.cpp
-LOCAL_CFLAGS := $(minadbd_cflags)
-LOCAL_C_INCLUDES := $(LOCAL_PATH) system/core/adb
-LOCAL_STATIC_LIBRARIES := \
- libBionicGtestMain \
- libminadbd
-LOCAL_SHARED_LIBRARIES := \
- liblog \
- libbase \
- libcutils
+# LOCAL_MODULE := minadbd_test
+# LOCAL_COMPATIBILITY_SUITE := device-tests
+# LOCAL_SRC_FILES := fuse_adb_provider_test.cpp
+# LOCAL_CFLAGS := $(minadbd_cflags)
+# LOCAL_C_INCLUDES := $(LOCAL_PATH) system/core/adb
+# LOCAL_STATIC_LIBRARIES := \
+# libBionicGtestMain \
+# libminadbd
+# LOCAL_SHARED_LIBRARIES := \
+# liblog \
+# libbase \
+# libcutils
-include $(BUILD_NATIVE_TEST)
+# include $(BUILD_NATIVE_TEST)
diff --git a/minadbd/fuse_adb_provider.h b/minadbd/fuse_adb_provider.h
old mode 100644
new mode 100755
diff --git a/minadbd/minadbd.cpp b/minadbd/minadbd.cpp
old mode 100644
new mode 100755
index 388d414..216dc62
--- a/minadbd/minadbd.cpp
+++ b/minadbd/minadbd.cpp
@@ -68,13 +68,8 @@
init_transport_registration();
usb_init();
-<<<<<<< HEAD
//VLOG(ADB) << "Event loop starting";
fdevent_loop();
-=======
- VLOG(ADB) << "Event loop starting";
- fdevent_loop();
->>>>>>> android-10.0.0_r25
return 0;
}
diff --git a/minadbd/minadbd_services.cpp b/minadbd/minadbd_services.cpp
old mode 100644
new mode 100755
index c8eae52..5fe3052
--- a/minadbd/minadbd_services.cpp
+++ b/minadbd/minadbd_services.cpp
@@ -48,42 +48,6 @@
#include "services.h"
#include "sysdeps.h"
-<<<<<<< HEAD
-typedef struct stinfo stinfo;
-
-struct stinfo {
- void (*func)(int fd, void *cookie);
- int fd;
- void *cookie;
-};
-
-void service_bootstrap_func(void* x) {
- stinfo* sti = reinterpret_cast<stinfo*>(x);
- sti->func(sti->fd, sti->cookie);
- free(sti);
-}
-
-#if PLATFORM_SDK_VERSION < 26
-static void sideload_host_service(int sfd, void* data) {
- char* args = reinterpret_cast<char*>(data);
-#else
-static void sideload_host_service(int sfd, const std::string& args) {
-#endif
- int file_size;
- int block_size;
-#if PLATFORM_SDK_VERSION < 26
- if (sscanf(args, "%d:%d", &file_size, &block_size) != 2) {
- printf("bad sideload-host arguments: %s\n", args);
-#else
- if (sscanf(args.c_str(), "%d:%d", &file_size, &block_size) != 2) {
- printf("bad sideload-host arguments: %s\n", args.c_str());
-#endif
- exit(1);
- }
-#if PLATFORM_SDK_VERSION < 26
- free(args);
-#endif
-=======
static int minadbd_socket = -1;
static bool rescue_mode = false;
static std::string sideload_mount_point = FUSE_SIDELOAD_HOST_MOUNTPOINT;
@@ -174,7 +138,6 @@
return kMinadbdHostSocketIOError;
}
}
->>>>>>> android-10.0.0_r25
return kMinadbdSuccess;
}
@@ -193,44 +156,6 @@
}
}
-<<<<<<< HEAD
-#if PLATFORM_SDK_VERSION < 26
-static int create_service_thread(void (*func)(int, void *), void *cookie) {
- int s[2];
- if (adb_socketpair(s)) {
- printf("cannot create service socket pair\n");
- return -1;
- }
-
- stinfo* sti = static_cast<stinfo*>(malloc(sizeof(stinfo)));
- if(sti == 0) fatal("cannot allocate stinfo");
- sti->func = func;
- sti->cookie = cookie;
- sti->fd = s[1];
-
-#if PLATFORM_SDK_VERSION == 23
- adb_thread_t t;
- if (adb_thread_create( &t, (adb_thread_func_t)service_bootstrap_func, sti)){
-#else
- if (!adb_thread_create(service_bootstrap_func, sti)) {
-#endif
- free(sti);
- adb_close(s[0]);
- adb_close(s[1]);
- printf("cannot create service thread\n");
- return -1;
- }
-
- //VLOG(SERVICES) << "service thread started, " << s[0] << ":" << s[1];
- return s[0];
-}
-#else
-static int create_service_thread(void (*func)(int, const std::string&), const std::string& args) {
- int s[2];
- if (adb_socketpair(s)) {
- printf("cannot create service socket pair\n");
- return -1;
-=======
// Answers the query on a given property |prop|, by writing the result to the given |sfd|. The
// result will be newline-terminated, so nonexistent or nonallowed query will be answered with "\n".
// If given an empty string, dumps all the supported properties (analogous to `adb shell getprop`)
@@ -255,7 +180,6 @@
continue;
}
result += "[" + key + "]: [" + value + "]\n";
->>>>>>> android-10.0.0_r25
}
} else if (kGetpropAllowedProps.find(prop) != kGetpropAllowedProps.end()) {
result = android::base::GetProperty(prop, "") + "\n";
@@ -321,41 +245,14 @@
exit(kMinadbdMessageFormatError);
}
-<<<<<<< HEAD
- //VLOG(SERVICES) << "service thread started, " << s[0] << ":" << s[1];
- return s[0];
-=======
std::string response = (status == MinadbdCommandStatus::kSuccess) ? kMinadbdServicesExitSuccess
: kMinadbdServicesExitFailure;
response += std::string(message_size - response.size(), '\0');
if (!android::base::WriteFully(fd, response.c_str(), response.size())) {
exit(kMinadbdHostSocketIOError);
}
->>>>>>> android-10.0.0_r25
}
-#endif
-<<<<<<< HEAD
-#if PLATFORM_SDK_VERSION >= 28
-int service_to_fd(const char* name, atransport* /* transport */) {
-#else
-int service_to_fd(const char* name, const atransport* transport __unused) {
-#endif
- int ret = -1;
-
- if (!strncmp(name, "sideload:", 9)) {
- // this exit status causes recovery to print a special error
- // message saying to use a newer adb (that supports
- // sideload-host).
- exit(3);
- } else if (!strncmp(name, "sideload-host:", 14)) {
-#if PLATFORM_SDK_VERSION < 26
- char* arg = strdup(name + 14);
-#else
- std::string arg(name + 14);
-#endif
- ret = create_service_thread(sideload_host_service, arg);
-=======
unique_fd daemon_service_to_fd(std::string_view name, atransport* /* transport */) {
// Common services that are supported both in sideload and rescue modes.
if (ConsumePrefix(&name, "reboot:")) {
@@ -389,7 +286,6 @@
}
return unique_fd{};
->>>>>>> android-10.0.0_r25
}
// Sideload-specific services.
diff --git a/minadbd21/Android.mk b/minadbd21/Android.mk
index 201c795..40ed9f7 100644
--- a/minadbd21/Android.mk
+++ b/minadbd21/Android.mk
@@ -24,7 +24,7 @@
LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter
LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE
LOCAL_CFLAGS += -DUSE_FUSE_SIDELOAD22
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libminadbd
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../
LOCAL_SHARED_LIBRARIES := libfusesideload libcutils libc
diff --git a/minui/Android.mk b/minui/Android.mk
old mode 100644
new mode 100755
index 824eec6..5ccdf4f
--- a/minui/Android.mk
+++ b/minui/Android.mk
@@ -16,145 +16,145 @@
# libminui (static library)
# ===============================
-include $(CLEAR_VARS)
+# include $(CLEAR_VARS)
-LOCAL_SRC_FILES := \
- events.cpp \
- graphics.cpp \
- graphics_drm.cpp \
- graphics_fbdev.cpp \
- graphics_overlay.cpp \
- resources.cpp
+# LOCAL_SRC_FILES := \
+# events.cpp \
+# graphics.cpp \
+# graphics_drm.cpp \
+# graphics_fbdev.cpp \
+# graphics_overlay.cpp \
+# resources.cpp
-LOCAL_C_INCLUDES := external/libcxx/include external/libpng
+# LOCAL_C_INCLUDES := external/libcxx/include external/libpng
-ifeq ($(TW_TARGET_USES_QCOM_BSP), true)
- LOCAL_CFLAGS += -DMSM_BSP
- LOCAL_SRC_FILES += graphics_overlay.cpp
- ifeq ($(TARGET_PREBUILT_KERNEL),)
- ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 28; echo $$?),0)
- LOCAL_REQUIRED_MODULES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
- else
- LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
- endif
- LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
- else
- ifeq ($(TARGET_CUSTOM_KERNEL_HEADERS),)
- LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
- else
- LOCAL_C_INCLUDES += $(TARGET_CUSTOM_KERNEL_HEADERS)
- endif
- endif
-else
- LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
- # The header files required for adf graphics can cause compile errors
- # with adf graphics.
- LOCAL_SRC_FILES += graphics_adf.cpp
- LOCAL_WHOLE_STATIC_LIBRARIES += libadf
-endif
+# ifeq ($(TW_TARGET_USES_QCOM_BSP), true)
+# LOCAL_CFLAGS += -DMSM_BSP
+# LOCAL_SRC_FILES += graphics_overlay.cpp
+# ifeq ($(TARGET_PREBUILT_KERNEL),)
+# ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 28; echo $$?),0)
+# LOCAL_REQUIRED_MODULES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
+# else
+# LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
+# endif
+# LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
+# else
+# ifeq ($(TARGET_CUSTOM_KERNEL_HEADERS),)
+# LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
+# else
+# LOCAL_C_INCLUDES += $(TARGET_CUSTOM_KERNEL_HEADERS)
+# endif
+# endif
+# else
+# LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
+# # The header files required for adf graphics can cause compile errors
+# # with adf graphics.
+# LOCAL_SRC_FILES += graphics_adf.cpp
+# LOCAL_WHOLE_STATIC_LIBRARIES += libadf
+# endif
-ifeq ($(TW_NEW_ION_HEAP), true)
- LOCAL_CFLAGS += -DNEW_ION_HEAP
-endif
+# ifeq ($(TW_NEW_ION_HEAP), true)
+# LOCAL_CFLAGS += -DNEW_ION_HEAP
+# endif
-LOCAL_STATIC_LIBRARIES += libpng libbase
-ifneq ($(wildcard external/libdrm/Android.common.mk),)
-LOCAL_WHOLE_STATIC_LIBRARIES += libdrm_platform
-else
-LOCAL_WHOLE_STATIC_LIBRARIES += libdrm
-endif
-ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 26; echo $$?),0)
- LOCAL_CFLAGS += -DHAS_LIBSYNC
- LOCAL_WHOLE_STATIC_LIBRARIES += libsync_recovery
-endif
+# LOCAL_STATIC_LIBRARIES += libpng libbase
+# ifneq ($(wildcard external/libdrm/Android.common.mk),)
+# LOCAL_WHOLE_STATIC_LIBRARIES += libdrm_platform
+# else
+# LOCAL_WHOLE_STATIC_LIBRARIES += libdrm
+# endif
+# ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 26; echo $$?),0)
+# LOCAL_CFLAGS += -DHAS_LIBSYNC
+# LOCAL_WHOLE_STATIC_LIBRARIES += libsync_recovery
+# endif
-LOCAL_CFLAGS += -Wall -Werror -std=c++14 -Wno-unused-private-field
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
+# LOCAL_CFLAGS += -Wall -Werror -std=c++14 -Wno-unused-private-field
+# LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
+# LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
-LOCAL_MODULE := libminui
+# LOCAL_MODULE := libminui
-LOCAL_CLANG := true
+# LOCAL_CLANG := true
-# This used to compare against values in double-quotes (which are just
-# ordinary characters in this context). Strip double-quotes from the
-# value so that either will work.
+# # This used to compare against values in double-quotes (which are just
+# # ordinary characters in this context). Strip double-quotes from the
+# # value so that either will work.
-ifeq ($(subst ",,$(TARGET_RECOVERY_PIXEL_FORMAT)),ABGR_8888)
- LOCAL_CFLAGS += -DRECOVERY_ABGR
-endif
-ifeq ($(subst ",,$(TARGET_RECOVERY_PIXEL_FORMAT)),RGBA_8888)
- LOCAL_CFLAGS += -DRECOVERY_RGBA
-endif
-ifeq ($(subst ",,$(TARGET_RECOVERY_PIXEL_FORMAT)),RGBX_8888)
- LOCAL_CFLAGS += -DRECOVERY_RGBX
-endif
-ifeq ($(subst ",,$(TARGET_RECOVERY_PIXEL_FORMAT)),BGRA_8888)
- LOCAL_CFLAGS += -DRECOVERY_BGRA
-endif
+# ifeq ($(subst ",,$(TARGET_RECOVERY_PIXEL_FORMAT)),ABGR_8888)
+# LOCAL_CFLAGS += -DRECOVERY_ABGR
+# endif
+# ifeq ($(subst ",,$(TARGET_RECOVERY_PIXEL_FORMAT)),RGBA_8888)
+# LOCAL_CFLAGS += -DRECOVERY_RGBA
+# endif
+# ifeq ($(subst ",,$(TARGET_RECOVERY_PIXEL_FORMAT)),RGBX_8888)
+# LOCAL_CFLAGS += -DRECOVERY_RGBX
+# endif
+# ifeq ($(subst ",,$(TARGET_RECOVERY_PIXEL_FORMAT)),BGRA_8888)
+# LOCAL_CFLAGS += -DRECOVERY_BGRA
+# endif
-ifneq ($(TARGET_RECOVERY_OVERSCAN_PERCENT),)
- LOCAL_CFLAGS += -DOVERSCAN_PERCENT=$(TARGET_RECOVERY_OVERSCAN_PERCENT)
-else
- LOCAL_CFLAGS += -DOVERSCAN_PERCENT=0
-endif
+# ifneq ($(TARGET_RECOVERY_OVERSCAN_PERCENT),)
+# LOCAL_CFLAGS += -DOVERSCAN_PERCENT=$(TARGET_RECOVERY_OVERSCAN_PERCENT)
+# else
+# LOCAL_CFLAGS += -DOVERSCAN_PERCENT=0
+# endif
-ifneq ($(TW_BRIGHTNESS_PATH),)
- LOCAL_CFLAGS += -DTW_BRIGHTNESS_PATH=\"$(TW_BRIGHTNESS_PATH)\"
-endif
-ifneq ($(TW_MAX_BRIGHTNESS),)
- LOCAL_CFLAGS += -DTW_MAX_BRIGHTNESS=$(TW_MAX_BRIGHTNESS)
-else
- LOCAL_CFLAGS += -DTW_MAX_BRIGHTNESS=255
-endif
-ifneq ($(TW_NO_SCREEN_BLANK),)
- LOCAL_CFLAGS += -DTW_NO_SCREEN_BLANK
-endif
-ifneq ($(BOARD_USE_CUSTOM_RECOVERY_FONT),)
- LOCAL_CFLAGS += -DBOARD_USE_CUSTOM_RECOVERY_FONT=$(BOARD_USE_CUSTOM_RECOVERY_FONT)
-endif
-ifeq ($(wildcard system/core/healthd/animation.h),)
- TARGET_GLOBAL_CFLAGS += -DTW_NO_MINUI_CUSTOM_FONTS
- CLANG_TARGET_GLOBAL_CFLAGS += -DTW_NO_MINUI_CUSTOM_FONTS
-endif
-ifneq ($(TARGET_RECOVERY_DEFAULT_ROTATION),)
- LOCAL_CFLAGS += -DDEFAULT_ROTATION=$(TARGET_RECOVERY_DEFAULT_ROTATION)
-else
- LOCAL_CFLAGS += -DDEFAULT_ROTATION=ROTATION_NONE
-endif
+# ifneq ($(TW_BRIGHTNESS_PATH),)
+# LOCAL_CFLAGS += -DTW_BRIGHTNESS_PATH=\"$(TW_BRIGHTNESS_PATH)\"
+# endif
+# ifneq ($(TW_MAX_BRIGHTNESS),)
+# LOCAL_CFLAGS += -DTW_MAX_BRIGHTNESS=$(TW_MAX_BRIGHTNESS)
+# else
+# LOCAL_CFLAGS += -DTW_MAX_BRIGHTNESS=255
+# endif
+# ifneq ($(TW_NO_SCREEN_BLANK),)
+# LOCAL_CFLAGS += -DTW_NO_SCREEN_BLANK
+# endif
+# ifneq ($(BOARD_USE_CUSTOM_RECOVERY_FONT),)
+# LOCAL_CFLAGS += -DBOARD_USE_CUSTOM_RECOVERY_FONT=$(BOARD_USE_CUSTOM_RECOVERY_FONT)
+# endif
+# ifeq ($(wildcard system/core/healthd/animation.h),)
+# TARGET_GLOBAL_CFLAGS += -DTW_NO_MINUI_CUSTOM_FONTS
+# CLANG_TARGET_GLOBAL_CFLAGS += -DTW_NO_MINUI_CUSTOM_FONTS
+# endif
+# ifneq ($(TARGET_RECOVERY_DEFAULT_ROTATION),)
+# LOCAL_CFLAGS += -DDEFAULT_ROTATION=$(TARGET_RECOVERY_DEFAULT_ROTATION)
+# else
+# LOCAL_CFLAGS += -DDEFAULT_ROTATION=ROTATION_NONE
+# endif
-include $(BUILD_STATIC_LIBRARY)
+# include $(BUILD_STATIC_LIBRARY)
# libminui (shared library)
# ===============================
# Used by OEMs for factory test images.
-include $(CLEAR_VARS)
-LOCAL_CLANG := true
-LOCAL_MODULE := libminui
-LOCAL_WHOLE_STATIC_LIBRARIES += libminui
-LOCAL_SHARED_LIBRARIES := \
- libpng \
- libbase
+# include $(CLEAR_VARS)
+# LOCAL_CLANG := true
+# LOCAL_MODULE := libminui
+# LOCAL_WHOLE_STATIC_LIBRARIES += libminui
+# LOCAL_SHARED_LIBRARIES := \
+# libpng \
+# libbase
-LOCAL_CFLAGS := -Wall -Werror -std=c++14 -Wno-unused-private-field
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
-include $(BUILD_SHARED_LIBRARY)
+# LOCAL_CFLAGS := -Wall -Werror -std=c++14 -Wno-unused-private-field
+# LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
+# LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
+# include $(BUILD_SHARED_LIBRARY)
-include $(CLEAR_VARS)
-LOCAL_MODULE := minuitest
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT_SBIN)
-LOCAL_SRC_FILES := main.cpp
-LOCAL_SHARED_LIBRARIES := libbinder libminui libpng libz libutils libstdc++ libcutils liblog libm libc
-LOCAL_C_INCLUDES := external/libcxx/include external/libpng
-ifneq ($(TARGET_ARCH), arm64)
- ifneq ($(TARGET_ARCH), x86_64)
- LOCAL_LDFLAGS += -Wl,-dynamic-linker,/sbin/linker
- else
- LOCAL_LDFLAGS += -Wl,-dynamic-linker,/sbin/linker64
- endif
-else
- LOCAL_LDFLAGS += -Wl,-dynamic-linker,/sbin/linker64
-endif
-include $(BUILD_EXECUTABLE)
+# include $(CLEAR_VARS)
+# LOCAL_MODULE := minuitest
+# LOCAL_MODULE_TAGS := optional
+# LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT_SBIN)
+# LOCAL_SRC_FILES := main.cpp
+# LOCAL_SHARED_LIBRARIES := libbinder libminui libpng libz libutils libstdc++ libcutils liblog libm libc
+# LOCAL_C_INCLUDES := external/libcxx/include external/libpng
+# ifneq ($(TARGET_ARCH), arm64)
+# ifneq ($(TARGET_ARCH), x86_64)
+# LOCAL_LDFLAGS += -Wl,-dynamic-linker,/sbin/linker
+# else
+# LOCAL_LDFLAGS += -Wl,-dynamic-linker,/sbin/linker64
+# endif
+# else
+# LOCAL_LDFLAGS += -Wl,-dynamic-linker,/sbin/linker64
+# endif
+# include $(BUILD_EXECUTABLE)
diff --git a/minui/events.cpp b/minui/events.cpp
old mode 100644
new mode 100755
index 0b4540b..f3eaa1e
--- a/minui/events.cpp
+++ b/minui/events.cpp
@@ -65,24 +65,10 @@
#ifdef TW_USE_MINUI_WITH_OPTIONAL_TOUCH_EVENTS
int ev_init(ev_callback input_cb, bool allow_touch_inputs) {
-<<<<<<< HEAD
-#else
-#ifdef TW_USE_MINUI_WITH_DATA
-int ev_init(ev_callback input_cb, void* data) {
-#else
-int ev_init(ev_callback input_cb) {
-#endif
- bool allow_touch_inputs = false;
-#endif
-
- g_epoll_fd = epoll_create(MAX_DEVICES + MAX_MISC_FDS);
- if (g_epoll_fd == -1) {
-=======
g_epoll_fd.reset();
android::base::unique_fd epoll_fd(epoll_create1(EPOLL_CLOEXEC));
if (epoll_fd == -1) {
->>>>>>> android-10.0.0_r25
return -1;
}
@@ -114,23 +100,12 @@
}
}
-<<<<<<< HEAD
- ev_fdinfo[ev_count].fd = fd;
- ev_fdinfo[ev_count].cb = std::move(input_cb);
-#ifdef TW_USE_MINUI_WITH_DATA
- ev_fdinfo[ev_count].data = data;
-#endif
- ev_count++;
- ev_dev_count++;
- if (ev_dev_count == MAX_DEVICES) break;
-=======
epoll_event ev;
ev.events = EPOLLIN | EPOLLWAKEUP;
ev.data.ptr = &ev_fdinfo[g_ev_count];
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev) == -1) {
epoll_ctl_failed = true;
continue;
->>>>>>> android-10.0.0_r25
}
ev_fdinfo[g_ev_count].fd.reset(fd.release());
@@ -152,17 +127,8 @@
return g_epoll_fd.get();
}
-<<<<<<< HEAD
-#ifdef TW_USE_MINUI_WITH_DATA
-int ev_add_fd(int fd, ev_callback cb, void* data) {
-#else
-int ev_add_fd(int fd, ev_callback cb) {
-#endif
- if (ev_misc_count == MAX_MISC_FDS || cb == NULL) {
-=======
int ev_add_fd(android::base::unique_fd&& fd, ev_callback cb) {
if (g_ev_misc_count == MAX_MISC_FDS || cb == nullptr) {
->>>>>>> android-10.0.0_r25
return -1;
}
@@ -171,20 +137,10 @@
ev.data.ptr = static_cast<void*>(&ev_fdinfo[g_ev_count]);
int ret = epoll_ctl(g_epoll_fd, EPOLL_CTL_ADD, fd, &ev);
if (!ret) {
-<<<<<<< HEAD
- ev_fdinfo[ev_count].fd = fd;
- ev_fdinfo[ev_count].cb = std::move(cb);
-#ifdef TW_USE_MINUI_WITH_DATA
- ev_fdinfo[ev_count].data = data;
-#endif
- ev_count++;
- ev_misc_count++;
-=======
ev_fdinfo[g_ev_count].fd.reset(fd.release());
ev_fdinfo[g_ev_count].cb = std::move(cb);
g_ev_count++;
g_ev_misc_count++;
->>>>>>> android-10.0.0_r25
}
return ret;
@@ -212,15 +168,7 @@
FdInfo* fdi = static_cast<FdInfo*>(g_polled_events[n].data.ptr);
const ev_callback& cb = fdi->cb;
if (cb) {
-<<<<<<< HEAD
-#ifdef TW_USE_MINUI_WITH_DATA
- cb(fdi->fd, polledevents[n].events, fdi->data);
-#else
- cb(fdi->fd, polledevents[n].events);
-#endif
-=======
cb(fdi->fd, g_polled_events[n].events);
->>>>>>> android-10.0.0_r25
}
}
}
diff --git a/minui/graphics.cpp b/minui/graphics.cpp
old mode 100644
new mode 100755
index 744cceb..bb3c5f9
--- a/minui/graphics.cpp
+++ b/minui/graphics.cpp
@@ -23,18 +23,8 @@
#include <memory>
-<<<<<<< HEAD
-#ifdef BOARD_USE_CUSTOM_RECOVERY_FONT
-#include BOARD_USE_CUSTOM_RECOVERY_FONT
-#else
-#include "font_10x18.h"
-#endif
-
-#ifndef MSM_BSP
-=======
#include <android-base/properties.h>
->>>>>>> android-10.0.0_r25
#include "graphics_adf.h"
#endif
#include "graphics_drm.h"
@@ -222,29 +212,7 @@
return (out_r & 0xff) | (out_g & 0xff00) | (out_b & 0xff0000) | (gr_current & 0xff000000);
}
-<<<<<<< HEAD
-// increments pixel pointer right, with current rotation.
-static void incr_x16(uint16_t** p, int row_pixels) {
- if (rotation % 2) {
- *p = *p + (rotation == 1 ? 1 : -1) * row_pixels;
- } else {
- *p = *p + (rotation ? -1 : 1);
- }
-}
-
-// increments pixel pointer down, with current rotation.
-static void incr_y16(uint16_t** p, int row_pixels) {
- if (rotation % 2) {
- *p = *p + (rotation == 1 ? -1 : 1);
- } else {
- *p = *p + (rotation ? -1 : 1) * row_pixels;
- }
-}
-
-// increments pixel pointer right, with current rotation.
-=======
// Increments pixel pointer right, with current rotation.
->>>>>>> android-10.0.0_r25
static void incr_x(uint32_t** p, int row_pixels) {
if (rotation == GRRotation::LEFT) {
*p = *p - row_pixels;
@@ -270,31 +238,8 @@
}
}
-<<<<<<< HEAD
-// returns pixel pointer at given coordinates with rotation adjustment.
-static uint16_t* pixel_at16(GRSurface* surf, int x, int y, int row_pixels) {
- switch (rotation) {
- case ROTATION_NONE:
- return reinterpret_cast<uint16_t*>(surf->data) + y * row_pixels + x;
- case ROTATION_RIGHT:
- return reinterpret_cast<uint16_t*>(surf->data) + x * row_pixels + (surf->width - y);
- case ROTATION_DOWN:
- return reinterpret_cast<uint16_t*>(surf->data) + (surf->height - 1 - y) * row_pixels +
- (surf->width - 1 - x);
- case ROTATION_LEFT:
- return reinterpret_cast<uint16_t*>(surf->data) + (surf->height - 1 - x) * row_pixels + y;
- default:
- printf("invalid rotation %d", rotation);
- }
- return nullptr;
-}
-
-// returns pixel pointer at given coordinates with rotation adjustment.
-static uint32_t* pixel_at(GRSurface* surf, int x, int y, int row_pixels) {
-=======
// Returns pixel pointer at given coordinates with rotation adjustment.
static uint32_t* PixelAt(GRSurface* surface, int x, int y, int row_pixels) {
->>>>>>> android-10.0.0_r25
switch (rotation) {
case GRRotation::NONE:
return reinterpret_cast<uint32_t*>(surface->data()) + y * row_pixels + x;
@@ -312,29 +257,8 @@
return nullptr;
}
-<<<<<<< HEAD
-static void text_blend16(uint8_t* src_p, int src_row_bytes, uint16_t* dst_p, int dst_row_pixels,
- int width, int height) {
- uint8_t alpha_current = static_cast<uint8_t>((alpha_mask & gr_current) >> 24);
- for (int j = 0; j < height; ++j) {
- uint8_t* sx = src_p;
- uint16_t* px = dst_p;
- for (int i = 0; i < width; ++i, incr_x16(&px, dst_row_pixels)) {
- uint8_t a = *sx++;
- if (alpha_current < 255) a = (static_cast<uint32_t>(a) * alpha_current) / 255;
- *px = pixel_blend16(a, *px);
- }
- src_p += src_row_bytes;
- incr_y16(&dst_p, dst_row_pixels);
- }
-}
-
-static void text_blend(uint8_t* src_p, int src_row_bytes, uint32_t* dst_p, int dst_row_pixels,
- int width, int height) {
-=======
static void TextBlend(const uint8_t* src_p, int src_row_bytes, uint32_t* dst_p, int dst_row_pixels,
int width, int height) {
->>>>>>> android-10.0.0_r25
uint8_t alpha_current = static_cast<uint8_t>((alpha_mask & gr_current) >> 24);
for (int j = 0; j < height; ++j) {
const uint8_t* sx = src_p;
@@ -404,22 +328,6 @@
}
int row_pixels = gr_draw->row_bytes / gr_draw->pixel_bytes;
-<<<<<<< HEAD
-
- uint8_t* src_p = font->texture->data + ((ch - ' ') * font->char_width) +
- (bold ? font->char_height * font->texture->row_bytes : 0);
- if (gr_draw->pixel_bytes == 2) {
- uint16_t* dst_p = pixel_at16(gr_draw, x, y, row_pixels);
-
- text_blend16(src_p, font->texture->row_bytes, dst_p, row_pixels, font->char_width,
- font->char_height);
- } else { // not indenting AOSP original code
- uint32_t* dst_p = pixel_at(gr_draw, x, y, row_pixels);
-
- text_blend(src_p, font->texture->row_bytes, dst_p, row_pixels, font->char_width,
- font->char_height);
- }
-=======
const uint8_t* src_p = font->texture->data() + ((ch - ' ') * font->char_width) +
(bold ? font->char_height * font->texture->row_bytes : 0);
uint32_t* dst_p = PixelAt(gr_draw, x, y, row_pixels);
@@ -427,7 +335,6 @@
TextBlend(src_p, font->texture->row_bytes, dst_p, row_pixels, font->char_width,
font->char_height);
->>>>>>> android-10.0.0_r25
x += font->char_width;
}
}
@@ -447,22 +354,9 @@
if (outside(x, y) || outside(x + icon->width - 1, y + icon->height - 1)) return;
int row_pixels = gr_draw->row_bytes / gr_draw->pixel_bytes;
-<<<<<<< HEAD
- uint8_t* src_p = icon->data;
- if (gr_draw->pixel_bytes == 2) {
- uint16_t* dst_p = pixel_at16(gr_draw, x, y, row_pixels);
-
- text_blend16(src_p, icon->row_bytes, dst_p, row_pixels, icon->width, icon->height);
- return;
- }
- uint32_t* dst_p = pixel_at(gr_draw, x, y, row_pixels);
-
- text_blend(src_p, icon->row_bytes, dst_p, row_pixels, icon->width, icon->height);
-=======
const uint8_t* src_p = icon->data();
uint32_t* dst_p = PixelAt(gr_draw, x, y, row_pixels);
TextBlend(src_p, icon->row_bytes, dst_p, row_pixels, icon->width, icon->height);
->>>>>>> android-10.0.0_r25
}
void gr_convert_rgb_555(unsigned char r, unsigned char g, unsigned char b)
@@ -536,27 +430,7 @@
if (outside(x1, y1) || outside(x2 - 1, y2 - 1)) return;
int row_pixels = gr_draw->row_bytes / gr_draw->pixel_bytes;
-<<<<<<< HEAD
- if (gr_draw->pixel_bytes == 2) {
- uint16_t* p = pixel_at16(gr_draw, x1, y1, row_pixels);
- uint8_t alpha = static_cast<uint8_t>(((gr_current & alpha_mask) >> 24));
- if (alpha > 0) {
- for (int y = y1; y < y2; ++y) {
- uint16_t* px = p;
- for (int x = x1; x < x2; ++x) {
- *px = pixel_blend16(alpha, *px);
- incr_x16(&px, row_pixels);
- }
- incr_y16(&p, row_pixels);
- }
- }
- return;
- }
- { // open brace to maintain separation between uint16_t p and uint32_t p
- uint32_t* p = pixel_at(gr_draw, x1, y1, row_pixels);
-=======
uint32_t* p = PixelAt(gr_draw, x1, y1, row_pixels);
->>>>>>> android-10.0.0_r25
uint8_t alpha = static_cast<uint8_t>(((gr_current & alpha_mask) >> 24));
if (alpha > 0) {
for (int y = y1; y < y2; ++y) {
@@ -740,49 +614,10 @@
return 0;
}
-<<<<<<< HEAD
-static void gr_init_font(void) {
- int res = gr_init_font("font", &gr_font);
- if (res == 0) {
- return;
- }
-
- printf("failed to read font: res=%d\n", res);
-
- // fall back to the compiled-in font.
- gr_font = static_cast<GRFont*>(calloc(1, sizeof(*gr_font)));
- gr_font->texture = static_cast<GRSurface*>(malloc(sizeof(*gr_font->texture)));
- gr_font->texture->width = font.width;
- gr_font->texture->height = font.height;
- gr_font->texture->row_bytes = font.width;
- gr_font->texture->pixel_bytes = 1;
-
- unsigned char* bits = static_cast<unsigned char*>(malloc(font.width * font.height));
- gr_font->texture->data = bits;
-
- unsigned char data;
- unsigned char* in = font.rundata;
- while ((data = *in++)) {
- memset(bits, (data & 0x80) ? 255 : 0, data & 0x7f);
- bits += (data & 0x7f);
- }
-
- gr_font->char_width = font.char_width;
- gr_font->char_height = font.char_height;
-}
-#endif // TW_NO_MINUI_CUSTOM_FONTS
-
-=======
->>>>>>> android-10.0.0_r25
void gr_flip() {
gr_draw = gr_backend->Flip();
}
-<<<<<<< HEAD
-int gr_init(void)
-{
- gr_init_font();
-=======
int gr_init() {
// pixel_format needs to be set before loading any resources or initializing backends.
std::string format = android::base::GetProperty("ro.minui.pixel_format", "");
@@ -801,7 +636,6 @@
printf("Failed to init font: %d, continuing graphic backend initialization without font file\n",
ret);
}
->>>>>>> android-10.0.0_r25
auto backend = std::unique_ptr<MinuiBackend>{ std::make_unique<MinuiBackendOverlay>() };
gr_draw = backend->Init();
@@ -812,16 +646,6 @@
}
#endif
-#ifndef MSM_BSP
- if (!gr_draw) {
- backend = std::make_unique<MinuiBackendAdf>();
- gr_draw = backend->Init();
- if (gr_draw)
- printf("Using adf graphics.\n");
- }
-#else
- printf("Skipping adf graphics because TW_TARGET_USES_QCOM_BSP := true\n");
-#endif
if (!gr_draw) {
backend = std::make_unique<MinuiBackendDrm>();
@@ -835,13 +659,11 @@
gr_draw = backend->Init();
if (gr_draw)
printf("Using fbdev graphics.\n");
- }
if (!gr_draw) {
return -1;
}
- gr_backend = backend.release();
int overscan_percent = android::base::GetIntProperty("ro.minui.overscan_percent", 0);
overscan_offset_x = gr_draw->width * overscan_percent / 100;
diff --git a/minui/graphics_adf.cpp b/minui/graphics_adf.cpp
old mode 100644
new mode 100755
index df72e85..8f1f33a
--- a/minui/graphics_adf.cpp
+++ b/minui/graphics_adf.cpp
@@ -116,19 +116,6 @@
}
GRSurface* MinuiBackendAdf::Init() {
-<<<<<<< HEAD
-#if defined(RECOVERY_ABGR)
- format = DRM_FORMAT_ABGR8888;
-#elif defined(RECOVERY_BGRA)
- format = DRM_FORMAT_BGRA8888;
-#elif defined(RECOVERY_RGBA)
- format = DRM_FORMAT_RGBA8888;
-#elif defined(RECOVERY_RGBX)
- format = DRM_FORMAT_RGBX8888;
-#else
- format = DRM_FORMAT_RGB565;
-#endif
-=======
PixelFormat pixel_format = gr_pixel_format();
if (pixel_format == PixelFormat::ABGR) {
format = DRM_FORMAT_ABGR8888;
@@ -139,7 +126,6 @@
} else {
format = DRM_FORMAT_RGB565;
}
->>>>>>> android-10.0.0_r25
adf_id_t* dev_ids = nullptr;
ssize_t n_dev_ids = adf_devices(&dev_ids);
@@ -178,14 +164,8 @@
return ret;
}
-<<<<<<< HEAD
-void MinuiBackendAdf::Sync(__unused GRSurfaceAdf* surf) {
-#ifdef HAS_LIBSYNC
- static constexpr unsigned int warningTimeout = 3000;
-=======
void MinuiBackendAdf::Sync(GRSurfaceAdf* surf) {
static constexpr unsigned int kWarningTimeout = 3000;
->>>>>>> android-10.0.0_r25
if (surf == nullptr) return;
diff --git a/minui/graphics_drm.cpp b/minui/graphics_drm.cpp
old mode 100644
new mode 100755
index b8d813e..7b2eed1
--- a/minui/graphics_drm.cpp
+++ b/minui/graphics_drm.cpp
@@ -76,19 +76,6 @@
std::unique_ptr<GRSurfaceDrm> GRSurfaceDrm::Create(int drm_fd, int width, int height) {
uint32_t format;
-<<<<<<< HEAD
-#if defined(RECOVERY_ABGR)
- format = DRM_FORMAT_RGBA8888;
-#elif defined(RECOVERY_BGRA)
- format = DRM_FORMAT_ARGB8888;
-#elif defined(RECOVERY_RGBA)
- format = DRM_FORMAT_ARGB8888;
-#elif defined(RECOVERY_RGBX)
- format = DRM_FORMAT_XBGR8888;
-#else
- format = DRM_FORMAT_RGB565;
-#endif
-=======
PixelFormat pixel_format = gr_pixel_format();
// PixelFormat comes in byte order, whereas DRM_FORMAT_* uses little-endian
// (external/libdrm/include/drm/drm_fourcc.h). Note that although drm_fourcc.h also defines a
@@ -103,7 +90,6 @@
} else {
format = DRM_FORMAT_RGB565;
}
->>>>>>> android-10.0.0_r25
drm_mode_create_dumb create_dumb = {};
create_dumb.height = height;
diff --git a/minui/include/minui/minui.h b/minui/include/minui/minui.h
old mode 100644
new mode 100755
index 9c36636..071403e
--- a/minui/include/minui/minui.h
+++ b/minui/include/minui/minui.h
@@ -16,13 +16,10 @@
#pragma once
-<<<<<<< HEAD
#ifndef TW_USE_MINUI_21
-=======
#include <stdint.h>
#include <stdlib.h>
->>>>>>> android-10.0.0_r25
#include <sys/types.h>
#include <functional>
@@ -128,7 +125,6 @@
void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
void gr_fill(int x1, int y1, int x2, int y2);
-<<<<<<< HEAD
void gr_texticon(int x, int y, GRSurface* icon);
#ifdef TW_NO_MINUI_CUSTOM_FONTS
void gr_text(int x, int y, const char *s, bool bold);
@@ -136,22 +132,15 @@
void gr_font_size(int *x, int *y);
void gr_set_font(__attribute__ ((unused))const char* name);
#else
-=======
void gr_texticon(int x, int y, const GRSurface* icon);
->>>>>>> android-10.0.0_r25
const GRFont* gr_sys_font();
int gr_init_font(const char* name, GRFont** dest);
void gr_text(const GRFont* font, int x, int y, const char* s, bool bold);
// Returns -1 if font is nullptr.
int gr_measure(const GRFont* font, const char* s);
-<<<<<<< HEAD
-void gr_font_size(const GRFont* font, int* x, int* y);
-#endif
-=======
// Returns -1 if font is nullptr.
int gr_font_size(const GRFont* font, int* x, int* y);
->>>>>>> android-10.0.0_r25
void gr_blit(const GRSurface* source, int sx, int sy, int w, int h, int dx, int dy);
unsigned int gr_get_width(const GRSurface* surface);
@@ -182,12 +171,9 @@
#ifdef TW_USE_MINUI_WITH_OPTIONAL_TOUCH_EVENTS
int ev_init(ev_callback input_cb, bool allow_touch_inputs = false);
-<<<<<<< HEAD
-=======
void ev_exit();
int ev_add_fd(android::base::unique_fd&& fd, ev_callback cb);
void ev_iterate_available_keys(const std::function<void(int)>& f);
->>>>>>> android-10.0.0_r25
void ev_iterate_touch_inputs(const std::function<void(int)>& action);
#else
int ev_init(ev_callback input_cb);
@@ -254,8 +240,6 @@
// Free a surface allocated by any of the res_create_*_surface()
// functions.
void res_free_surface(GRSurface* surface);
-<<<<<<< HEAD
-
#else //ifndef TW_USE_MINUI_21
// This the old minui21/minui.h for compatibility with building TWRP
@@ -348,5 +332,3 @@
#endif // ifndef TW_USE_MINUI_21
#endif // ifndef _MINUI_H_
-=======
->>>>>>> android-10.0.0_r25
diff --git a/minui/resources.cpp b/minui/resources.cpp
old mode 100644
new mode 100755
index 8379885..abcffcc
--- a/minui/resources.cpp
+++ b/minui/resources.cpp
@@ -33,12 +33,7 @@
#include <string>
#include <vector>
-<<<<<<< HEAD
-//#include <android-base/stringprintf.h> // does not exist in 6.0
-//#include <android-base/strings.h> // does not exist in 6.0
-=======
#include <android-base/strings.h>
->>>>>>> android-10.0.0_r25
#include <png.h>
#include "minui/minui.h"
@@ -68,13 +63,6 @@
return result;
}
-<<<<<<< HEAD
-PngHandler::PngHandler(const std::string& name) : error_code_(0), png_fp_(nullptr, fclose) {
- char res_path[PATH_MAX];
- sprintf(res_path, "/res/images/%s.png", name.c_str());
- //std::string res_path = sprintf("/res/images/%s.png", name.c_str());
- png_fp_.reset(fopen(res_path, "rbe"));
-=======
PngHandler::PngHandler(const std::string& name) {
std::string res_path = g_resource_dir + "/" + name + ".png";
png_fp_.reset(fopen(res_path.c_str(), "rbe"));
@@ -82,7 +70,6 @@
if (!png_fp_) {
png_fp_.reset(fopen(name.c_str(), "rbe"));
}
->>>>>>> android-10.0.0_r25
if (!png_fp_) {
error_code_ = -1;
return;
diff --git a/minuitwrp/Android.mk b/minuitwrp/Android.mk
index 2ca2091..99f9a23 100644
--- a/minuitwrp/Android.mk
+++ b/minuitwrp/Android.mk
@@ -201,7 +201,7 @@
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 25; echo $$?),0)
LOCAL_SHARED_LIBRARIES += libcutils liblog libutils
endif
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libminuitwrp
include $(BUILD_SHARED_LIBRARY)
diff --git a/minuitwrp/graphics.cpp b/minuitwrp/graphics.cpp
old mode 100644
new mode 100755
index 47ff3b9..8abf8eb
--- a/minuitwrp/graphics.cpp
+++ b/minuitwrp/graphics.cpp
@@ -37,6 +37,7 @@
#include "graphics.h"
// For std::min and std::max
#include <algorithm>
+#include "truetype.hpp"
struct GRFont {
GRSurface* texture;
@@ -70,25 +71,25 @@
if (!s || strlen(s) == 0 || !font)
return 0;
- measured_height = gr_ttf_getMaxFontHeight(font);
+ measured_height = twrpTruetype::gr_ttf_getMaxFontHeight(font);
if (scale) {
- measured_width = gr_ttf_measureEx(s, vfont);
+ measured_width = twrpTruetype::gr_ttf_measureEx(s, vfont);
if (measured_width > max_width) {
// Adjust font size down until the text fits
- void *new_font = gr_ttf_scaleFont(vfont, max_width, measured_width);
+ void *new_font = twrpTruetype::gr_ttf_scaleFont(vfont, max_width, measured_width);
if (!new_font) {
printf("gr_textEx_scaleW new_font is NULL\n");
return 0;
}
- measured_width = gr_ttf_measureEx(s, new_font);
+ measured_width = twrpTruetype::gr_ttf_measureEx(s, new_font);
// These next 2 lines adjust the y point based on the new font's height
- new_height = gr_ttf_getMaxFontHeight(new_font);
+ new_height = twrpTruetype::gr_ttf_getMaxFontHeight(new_font);
y_scale = (measured_height - new_height) / 2;
vfont = new_font;
}
} else
- measured_width = gr_ttf_measureEx(s, vfont);
+ measured_width = twrpTruetype::gr_ttf_measureEx(s, vfont);
int x_adj = measured_width;
if (measured_width > max_width)
@@ -107,7 +108,7 @@
else if (placement == BOTTOM_LEFT || placement == BOTTOM_RIGHT)
y -= measured_height;
}
- return gr_ttf_textExWH(gl, x, y + y_scale, s, vfont, measured_width + x, -1, gr_draw);
+ return twrpTruetype::gr_ttf_textExWH(gl, x, y + y_scale, s, vfont, measured_width + x, -1, gr_draw);
}
void gr_clip(int x, int y, int w, int h)
diff --git a/minuitwrp/truetype.cpp b/minuitwrp/truetype.cpp
old mode 100644
new mode 100755
index 0416b0e..3dffbe4
--- a/minuitwrp/truetype.cpp
+++ b/minuitwrp/truetype.cpp
@@ -1,3 +1,21 @@
+/*
+ Copyright 2012 to 2020 TeamWin
+ This file is part of TWRP/TeamWin Recovery Project.
+
+ TWRP is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ TWRP is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with TWRP. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
@@ -5,856 +23,631 @@
#include <errno.h>
#include <stdio.h>
-#include "minui.h"
-
-#include <cutils/hashmap.h>
-#include <ft2build.h>
-#include FT_FREETYPE_H
-#include FT_GLYPH_H
-
-#include <pixelflinger/pixelflinger.h>
#include <pthread.h>
-// For std::min and std::max
#include <algorithm>
-
-#define STRING_CACHE_MAX_ENTRIES 400
-#define STRING_CACHE_TRUNCATE_ENTRIES 150
-
-typedef struct
-{
- int size;
- int dpi;
- char *path;
-} TrueTypeFontKey;
-
-typedef struct
-{
- int type;
- int refcount;
- int size;
- int dpi;
- int max_height;
- int base;
- FT_Face face;
- Hashmap *glyph_cache;
- Hashmap *string_cache;
- struct StringCacheEntry *string_cache_head;
- struct StringCacheEntry *string_cache_tail;
- pthread_mutex_t mutex;
- TrueTypeFontKey *key;
-} TrueTypeFont;
-
-typedef struct
-{
- FT_BBox bbox;
- FT_BitmapGlyph glyph;
-} TrueTypeCacheEntry;
-
-typedef struct
-{
- char *text;
- int max_width;
-} StringCacheKey;
-
-struct StringCacheEntry
-{
- GGLSurface surface;
- int rendered_bytes; // number of bytes from C string rendered, not number of UTF8 characters!
- StringCacheKey *key;
- struct StringCacheEntry *prev;
- struct StringCacheEntry *next;
-};
-
-typedef struct StringCacheEntry StringCacheEntry;
-
-typedef struct
-{
- FT_Library ft_library;
- Hashmap *fonts;
- pthread_mutex_t mutex;
-} FontData;
+#include <string>
+#include "truetype.hpp"
static FontData font_data = {
- .ft_library = NULL,
- .fonts = NULL,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
+ .ft_library = NULL,
+ .mutex = PTHREAD_MUTEX_INITIALIZER
};
-#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
-#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
+twrpTruetype::twrpTruetype(void) {
-// 32bit FNV-1a hash algorithm
-// http://isthe.com/chongo/tech/comp/fnv/#FNV-1a
-static const uint32_t FNV_prime = 16777619U;
-static const uint32_t offset_basis = 2166136261U;
-
-static uint32_t fnv_hash(void *data, uint32_t len)
-{
- uint8_t *d8 = (uint8_t *)data;
- uint32_t *d32 = (uint32_t *)data;
- uint32_t i, max;
- uint32_t hash = offset_basis;
-
- max = len/4;
-
- // 32 bit data
- for(i = 0; i < max; ++i)
- {
- hash ^= *d32++;
- hash *= FNV_prime;
- }
-
- // last bits
- for(i *= 4; i < len; ++i)
- {
- hash ^= (uint32_t) d8[i];
- hash *= FNV_prime;
- }
- return hash;
}
-static inline uint32_t fnv_hash_add(uint32_t cur_hash, uint32_t word)
-{
- cur_hash ^= word;
- cur_hash *= FNV_prime;
- return cur_hash;
+int twrpTruetype::utf8_to_unicode(const char* pIn, unsigned int *pOut) {
+ int utf_bytes = 1;
+ unsigned int unicode = 0;
+ unsigned char tmp;
+ tmp = (unsigned char)*pIn++;
+ if (tmp < 0x80)
+ {
+ *pOut = tmp;
+ }
+ else
+ {
+ unsigned int high_bit_mask = 0x3F;
+ unsigned int high_bit_shift = 0;
+ int total_bits = 0;
+ while((tmp & 0xC0) == 0xC0)
+ {
+ utf_bytes ++;
+ if(utf_bytes > 6)
+ {
+ *pOut = tmp;
+ return 1;
+ }
+ tmp = 0xFF & (tmp << 1);
+ total_bits += 6;
+ high_bit_mask >>= 1;
+ high_bit_shift++;
+ unicode <<= 6;
+ unicode |= (*pIn++) & 0x3F;
+ }
+ unicode |= ((tmp >> high_bit_shift) & high_bit_mask) << total_bits;
+ *pOut = unicode;
+ }
+
+ return utf_bytes;
}
-int utf8_to_unicode(const char* pIn, unsigned int *pOut)
-{
- int utf_bytes = 1;
- unsigned int unicode = 0;
- unsigned char tmp;
- tmp = (unsigned char)*pIn++;
- if (tmp < 0x80)
- {
- *pOut = tmp;
- }
- else
- {
- unsigned int high_bit_mask = 0x3F;
- unsigned int high_bit_shift = 0;
- int total_bits = 0;
- while((tmp & 0xC0) == 0xC0)
- {
- utf_bytes ++;
- if(utf_bytes > 6)
- {
- *pOut = tmp;
- return 1;
- }
- tmp = 0xFF & (tmp << 1);
- total_bits += 6;
- high_bit_mask >>= 1;
- high_bit_shift++;
- unicode <<= 6;
- unicode |= (*pIn++) & 0x3F;
- }
- unicode |= ((tmp >> high_bit_shift) & high_bit_mask) << total_bits;
- *pOut = unicode;
- }
+void* twrpTruetype::gr_ttf_loadFont(const char *filename, int size, int dpi) {
+ int error;
+ TrueTypeFont* res = nullptr;
+ TrueTypeFontKey* key;
- return utf_bytes;
-}
+ pthread_mutex_lock(&font_data.mutex);
-static bool gr_ttf_string_cache_equals(void *keyA, void *keyB)
-{
- StringCacheKey *a = (StringCacheKey *)keyA;
- StringCacheKey *b = (StringCacheKey *)keyB;
- return a->max_width == b->max_width && strcmp(a->text, b->text) == 0;
-}
+ TrueTypeFontKey k = {
+ .size = size,
+ .dpi = dpi,
+ .path = (char*)filename
+ };
-static int gr_ttf_string_cache_hash(void *key)
-{
- StringCacheKey *k = (StringCacheKey *)key;
- return fnv_hash(k->text, strlen(k->text));
-}
+ TrueTypeFontMap::iterator ttfIter = font_data.fonts.find(k);
-static bool gr_ttf_font_cache_equals(void *keyA, void *keyB)
-{
- TrueTypeFontKey *a = (TrueTypeFontKey *)keyA;
- TrueTypeFontKey *b = (TrueTypeFontKey *)keyB;
- return (a->size == b->size) && (a->dpi == b->dpi) && !strcmp(a->path, b->path);
-}
+ if (ttfIter != font_data.fonts.end())
+ {
+ res = ttfIter->second;
+ ++res->refcount;
+ goto exit;
+ }
-static int gr_ttf_font_cache_hash(void *key)
-{
- TrueTypeFontKey *k = (TrueTypeFontKey *)key;
+ if(!font_data.ft_library)
+ {
+ error = FT_Init_FreeType(&font_data.ft_library);
+ if(error)
+ {
+ fprintf(stderr, "Failed to init libfreetype! %d\n", error);
+ goto exit;
+ }
+ }
- uint32_t hash = fnv_hash(k->path, strlen(k->path));
- hash = fnv_hash_add(hash, k->size);
- hash = fnv_hash_add(hash, k->dpi);
- return hash;
-}
+ FT_Face face;
+ error = FT_New_Face(font_data.ft_library, filename, 0, &face);
+ if(error)
+ {
+ fprintf(stderr, "Failed to load truetype face %s: %d\n", filename, error);
+ goto exit;
+ }
-void *gr_ttf_loadFont(const char *filename, int size, int dpi)
-{
- int error;
- TrueTypeFont *res = NULL;
- TrueTypeFontKey *key = NULL;
+ error = FT_Set_Char_Size(face, 0, size*16, dpi, dpi);
+ if(error)
+ {
+ fprintf(stderr, "Failed to set truetype face size to %d, dpi %d: %d\n", size, dpi, error);
+ FT_Done_Face(face);
+ goto exit;
+ }
- pthread_mutex_lock(&font_data.mutex);
+ res = new TrueTypeFont;
+ res->type = FONT_TYPE_TTF;
+ res->size = size;
+ res->dpi = dpi;
+ res->face = face;
+ res->max_height = -1;
+ res->base = -1;
+ res->refcount = 1;
- if(font_data.fonts)
- {
- TrueTypeFontKey k = {
- .size = size,
- .dpi = dpi,
- .path = (char*)filename
- };
+ pthread_mutex_init(&res->mutex, 0);
- res = (TrueTypeFont *)hashmapGet(font_data.fonts, &k);
- if(res)
- {
- ++res->refcount;
- goto exit;
- }
- }
+ key = new TrueTypeFontKey;
+ key->path = strdup(filename);
+ key->size = size;
+ key->dpi = dpi;
- if(!font_data.ft_library)
- {
- error = FT_Init_FreeType(&font_data.ft_library);
- if(error)
- {
- fprintf(stderr, "Failed to init libfreetype! %d\n", error);
- goto exit;
- }
- }
-
- FT_Face face;
- error = FT_New_Face(font_data.ft_library, filename, 0, &face);
- if(error)
- {
- fprintf(stderr, "Failed to load truetype face %s: %d\n", filename, error);
- goto exit;
- }
-
- error = FT_Set_Char_Size(face, 0, size*16, dpi, dpi);
- if(error)
- {
- fprintf(stderr, "Failed to set truetype face size to %d, dpi %d: %d\n", size, dpi, error);
- FT_Done_Face(face);
- goto exit;
- }
-
- res = (TrueTypeFont *)malloc(sizeof(TrueTypeFont));
- memset(res, 0, sizeof(TrueTypeFont));
- res->type = FONT_TYPE_TTF;
- res->size = size;
- res->dpi = dpi;
- res->face = face;
- res->max_height = -1;
- res->base = -1;
- res->refcount = 1;
- res->glyph_cache = hashmapCreate(32, hashmapIntHash, hashmapIntEquals);
- res->string_cache = hashmapCreate(128, gr_ttf_string_cache_hash, gr_ttf_string_cache_equals);
- pthread_mutex_init(&res->mutex, 0);
-
- if(!font_data.fonts)
- font_data.fonts = hashmapCreate(4, gr_ttf_font_cache_hash, gr_ttf_font_cache_equals);
-
- key = (TrueTypeFontKey *)malloc(sizeof(TrueTypeFontKey));
- memset(key, 0, sizeof(TrueTypeFontKey));
- key->path = strdup(filename);
- key->size = size;
- key->dpi = dpi;
-
- res->key = key;
-
- hashmapPut(font_data.fonts, key, res);
+ res->key = key;
+ font_data.fonts[*key] = res;
exit:
- pthread_mutex_unlock(&font_data.mutex);
- return res;
+ pthread_mutex_unlock(&font_data.mutex);
+ return res;
}
-void *gr_ttf_scaleFont(void *font, int max_width, int measured_width)
-{
- if (!font)
- return NULL;
+void* twrpTruetype::gr_ttf_scaleFont(void *font, int max_width, int measured_width) {
+ if (!font)
+ return nullptr;
- TrueTypeFont *f = (TrueTypeFont *)font;
- float scale_value = (float)(max_width) / (float)(measured_width);
- int new_size = ((int)((float)f->size * scale_value)) - 1;
- if (new_size < 1)
- new_size = 1;
- const char* file = f->key->path;
- int dpi = f->dpi;
- return gr_ttf_loadFont(file, new_size, dpi);
+ TrueTypeFont *f = (TrueTypeFont *)font;
+ float scale_value = (float)(max_width) / (float)(measured_width);
+ int new_size = ((int)((float)f->size * scale_value)) - 1;
+ if (new_size < 1)
+ new_size = 1;
+ const char* file = f->key->path;
+ int dpi = f->dpi;
+ return gr_ttf_loadFont(file, new_size, dpi);
}
-static bool gr_ttf_freeFontCache(void *key, void *value, void *context __unused)
+static bool gr_ttf_freeFontCache(void *value, void *context __unused)
{
- TrueTypeCacheEntry *e = (TrueTypeCacheEntry *)value;
- FT_Done_Glyph((FT_Glyph)e->glyph);
- free(e);
- free(key);
- return true;
+ TrueTypeCacheEntry *e = (TrueTypeCacheEntry *)value;
+ FT_Done_Glyph((FT_Glyph)e->glyph);
+ free(e);
+ return true;
}
-static bool gr_ttf_freeStringCache(void *key, void *value, void *context __unused)
-{
- StringCacheKey *k = (StringCacheKey *)key;
- free(k->text);
- free(k);
+bool twrpTruetype::gr_ttf_freeStringCache(void *key, void *value, void *context __unused) {
+ StringCacheKey *k = (StringCacheKey *)key;
+ delete k->text;
+ delete k;
- StringCacheEntry *e = (StringCacheEntry *)value;
- free(e->surface.data);
- free(e);
- return true;
+ StringCacheEntry *e = (StringCacheEntry *)value;
+ delete e->surface.data;
+ delete e;
+ return true;
}
-void gr_ttf_freeFont(void *font)
-{
- pthread_mutex_lock(&font_data.mutex);
+void twrpTruetype::gr_ttf_freeFont(void *font) {
+ pthread_mutex_lock(&font_data.mutex);
- TrueTypeFont *d = (TrueTypeFont *)font;
+ TrueTypeFont *d = (TrueTypeFont *)font;
+ if(--d->refcount == 0)
+ {
+ delete d->key->path;
+ delete d->key;
- if(--d->refcount == 0)
- {
- hashmapRemove(font_data.fonts, d->key);
+ FT_Done_Face(d->face);
- if(hashmapSize(font_data.fonts) == 0)
- {
- hashmapFree(font_data.fonts);
- font_data.fonts = NULL;
- }
+ StringCacheMap::iterator stringCacheEntryIt = d->string_cache.begin();
+ while (stringCacheEntryIt != d->string_cache.end()) {
+ gr_ttf_freeStringCache(stringCacheEntryIt->second->key, stringCacheEntryIt->second, NULL);
+ stringCacheEntryIt = d->string_cache.erase(stringCacheEntryIt);
+ }
- free(d->key->path);
- free(d->key);
+ TrueTypeCacheEntryMap::iterator ttcIt = d->glyph_cache.begin();
+ while(ttcIt != d->glyph_cache.end()) {
+ gr_ttf_freeFontCache(ttcIt->second, NULL);
+ ttcIt = d->glyph_cache.erase(ttcIt);
+ }
- FT_Done_Face(d->face);
- hashmapForEach(d->string_cache, gr_ttf_freeStringCache, NULL);
- hashmapFree(d->string_cache);
- hashmapForEach(d->glyph_cache, gr_ttf_freeFontCache, NULL);
- hashmapFree(d->glyph_cache);
- pthread_mutex_destroy(&d->mutex);
- free(d);
- }
+ pthread_mutex_destroy(&d->mutex);
- pthread_mutex_unlock(&font_data.mutex);
+ TrueTypeFontMap::iterator trueTypeFontIt = font_data.fonts.find(*(d->key));
+ delete d;
+ font_data.fonts.erase(trueTypeFontIt);
+
+ }
+
+ pthread_mutex_unlock(&font_data.mutex);
}
-static TrueTypeCacheEntry *gr_ttf_glyph_cache_peek(TrueTypeFont *font, int char_index)
-{
- return (TrueTypeCacheEntry *)hashmapGet(font->glyph_cache, &char_index);
+TrueTypeCacheEntry* twrpTruetype::gr_ttf_glyph_cache_peek(TrueTypeFont *font, int char_index) {
+ TrueTypeCacheEntryMap::iterator glyphCacheItr = font->glyph_cache.find(char_index);
+
+ if(glyphCacheItr != font->glyph_cache.end()) {
+ return font->glyph_cache[char_index];
+ }
+ return nullptr;
}
-static TrueTypeCacheEntry *gr_ttf_glyph_cache_get(TrueTypeFont *font, int char_index)
-{
- TrueTypeCacheEntry *res = (TrueTypeCacheEntry *)hashmapGet(font->glyph_cache, &char_index);
- if(!res)
- {
- int error = FT_Load_Glyph(font->face, char_index, FT_LOAD_RENDER);
- if(error)
- {
- fprintf(stderr, "Failed to load glyph idx %d: %d\n", char_index, error);
- return NULL;
- }
+TrueTypeCacheEntry* twrpTruetype::gr_ttf_glyph_cache_get(TrueTypeFont *font, int char_index) {
+ TrueTypeCacheEntryMap::iterator glyphCacheItr = font->glyph_cache.find(char_index);
+ TrueTypeCacheEntry* res = nullptr;
+ if(glyphCacheItr == font->glyph_cache.end())
+ {
+ int error = FT_Load_Glyph(font->face, char_index, FT_LOAD_RENDER);
+ if(error)
+ {
+ fprintf(stderr, "Failed to load glyph idx %d: %d\n", char_index, error);
+ return NULL;
+ }
- FT_BitmapGlyph glyph;
- error = FT_Get_Glyph(font->face->glyph, (FT_Glyph*)&glyph);
- if(error)
- {
- fprintf(stderr, "Failed to copy glyph %d: %d\n", char_index, error);
- return NULL;
- }
+ FT_BitmapGlyph glyph;
+ error = FT_Get_Glyph(font->face->glyph, (FT_Glyph*)&glyph);
+ if(error)
+ {
+ fprintf(stderr, "Failed to copy glyph %d: %d\n", char_index, error);
+ return NULL;
+ }
- res = (TrueTypeCacheEntry *)malloc(sizeof(TrueTypeCacheEntry));
- memset(res, 0, sizeof(TrueTypeCacheEntry));
- res->glyph = glyph;
- FT_Glyph_Get_CBox((FT_Glyph)glyph, FT_GLYPH_BBOX_PIXELS, &res->bbox);
+ res = new TrueTypeCacheEntry;
+ res->glyph = glyph;
+ FT_Glyph_Get_CBox((FT_Glyph)glyph, FT_GLYPH_BBOX_PIXELS, &res->bbox);
+ font->glyph_cache[char_index] = res;
+ }
+ else {
+ res = glyphCacheItr->second;
+ }
- int *key = (int *)malloc(sizeof(int));
- *key = char_index;
-
- hashmapPut(font->glyph_cache, key, res);
- }
-
- return res;
+ return res;
}
-static int gr_ttf_copy_glyph_to_surface(GGLSurface *dest, FT_BitmapGlyph glyph, int offX, int offY, int base)
-{
- unsigned y;
- uint8_t *src_itr = glyph->bitmap.buffer;
- uint8_t *dest_itr = dest->data;
+int twrpTruetype::gr_ttf_copy_glyph_to_surface(GGLSurface *dest, FT_BitmapGlyph glyph, int offX, int offY, int base) {
+ unsigned y;
+ uint8_t *src_itr = glyph->bitmap.buffer;
+ uint8_t *dest_itr = dest->data;
- if(glyph->bitmap.pixel_mode != FT_PIXEL_MODE_GRAY)
- {
- fprintf(stderr, "Unsupported pixel mode in FT_BitmapGlyph %d\n", glyph->bitmap.pixel_mode);
- return -1;
- }
+ if(glyph->bitmap.pixel_mode != FT_PIXEL_MODE_GRAY)
+ {
+ fprintf(stderr, "Unsupported pixel mode in FT_BitmapGlyph %d\n", glyph->bitmap.pixel_mode);
+ return -1;
+ }
- dest_itr += (offY + base - glyph->top)*dest->stride + (offX + glyph->left);
+ dest_itr += (offY + base - glyph->top)*dest->stride + (offX + glyph->left);
- // FIXME: if glyph->left is negative and everything else is 0 (e.g. letter 'j' in Roboto-Regular),
- // the result might end up being before the buffer - I'm not sure how to properly handle this.
- if(dest_itr < dest->data)
- dest_itr = dest->data;
+ // FIXME: if glyph->left is negative and everything else is 0 (e.g. letter 'j' in Roboto-Regular),
+ // the result might end up being before the buffer - I'm not sure how to properly handle this.
+ if(dest_itr < dest->data)
+ dest_itr = dest->data;
- for(y = 0; y < glyph->bitmap.rows; ++y)
- {
- memcpy(dest_itr, src_itr, glyph->bitmap.width);
- src_itr += glyph->bitmap.pitch;
- dest_itr += dest->stride;
- }
- return 0;
+ for(y = 0; y < glyph->bitmap.rows; ++y)
+ {
+ memcpy(dest_itr, src_itr, glyph->bitmap.width);
+ src_itr += glyph->bitmap.pitch;
+ dest_itr += dest->stride;
+ }
+ return 0;
}
-static void gr_ttf_calcMaxFontHeight(TrueTypeFont *f)
-{
- char c;
- int char_idx;
- int error;
- FT_Glyph glyph;
- FT_BBox bbox;
- FT_BBox bbox_glyph;
- TrueTypeCacheEntry *ent;
+void twrpTruetype::gr_ttf_calcMaxFontHeight(TrueTypeFont *f) {
+ char c;
+ int char_idx;
+ int error;
+ FT_Glyph glyph;
+ FT_BBox bbox;
+ FT_BBox bbox_glyph;
+ TrueTypeCacheEntry *ent;
- bbox.yMin = bbox_glyph.yMin = LONG_MAX;
- bbox.yMax = bbox_glyph.yMax = LONG_MIN;
+ bbox.yMin = bbox_glyph.yMin = LONG_MAX;
+ bbox.yMax = bbox_glyph.yMax = LONG_MIN;
- for(c = '!'; c <= '~'; ++c)
- {
- char_idx = FT_Get_Char_Index(f->face, c);
- ent = gr_ttf_glyph_cache_peek(f, char_idx);
- if(ent)
- {
- bbox.yMin = MIN(bbox.yMin, ent->bbox.yMin);
- bbox.yMax = MAX(bbox.yMax, ent->bbox.yMax);
- }
- else
- {
- error = FT_Load_Glyph(f->face, char_idx, 0);
- if(error)
- continue;
+ for(c = '!'; c <= '~'; ++c)
+ {
+ char_idx = FT_Get_Char_Index(f->face, c);
+ ent = gr_ttf_glyph_cache_peek(f, char_idx);
+ if(ent)
+ {
+ bbox.yMin = MIN(bbox.yMin, ent->bbox.yMin);
+ bbox.yMax = MAX(bbox.yMax, ent->bbox.yMax);
+ }
+ else
+ {
+ error = FT_Load_Glyph(f->face, char_idx, 0);
+ if(error)
+ continue;
- error = FT_Get_Glyph(f->face->glyph, &glyph);
- if(error)
- continue;
+ error = FT_Get_Glyph(f->face->glyph, &glyph);
+ if(error)
+ continue;
- FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_PIXELS, &bbox_glyph);
- bbox.yMin = MIN(bbox.yMin, bbox_glyph.yMin);
- bbox.yMax = MAX(bbox.yMax, bbox_glyph.yMax);
+ FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_PIXELS, &bbox_glyph);
+ bbox.yMin = MIN(bbox.yMin, bbox_glyph.yMin);
+ bbox.yMax = MAX(bbox.yMax, bbox_glyph.yMax);
- FT_Done_Glyph(glyph);
- }
- }
+ FT_Done_Glyph(glyph);
+ }
+ }
- if(bbox.yMin > bbox.yMax)
- bbox.yMin = bbox.yMax = 0;
+ if(bbox.yMin > bbox.yMax)
+ bbox.yMin = bbox.yMax = 0;
- f->max_height = bbox.yMax - bbox.yMin;
- f->base = bbox.yMax;
+ f->max_height = bbox.yMax - bbox.yMin;
+ f->base = bbox.yMax;
- // FIXME: twrp fonts have some padding on top, I'll add it here
- // Should be fixed in the themes
- f->max_height += f->size / 4;
- f->base += f->size / 4;
+ // FIXME: twrp fonts have some padding on top, I'll add it here
+ // Should be fixed in the themes
+ f->max_height += f->size / 4;
+ f->base += f->size / 4;
}
// returns number of bytes from const char *text rendered to fit max_width, not number of UTF8 characters!
-static int gr_ttf_render_text(TrueTypeFont *font, GGLSurface *surface, const char *text, int max_width)
-{
- TrueTypeFont *f = font;
- TrueTypeCacheEntry *ent;
- int bytes_rendered = 0, total_w = 0;
- int utf_bytes = 0;
- unsigned int unicode = 0;
- int i, x, diff, char_idx, prev_idx = 0;
- int height;
- FT_Vector delta;
- uint8_t *data = NULL;
- const char *text_itr = text;
- int *char_idxs;
- int char_idxs_len = 0;
+int twrpTruetype::gr_ttf_render_text(TrueTypeFont *font, GGLSurface *surface, const char *text, int max_width) {
+ TrueTypeFont *f = font;
+ TrueTypeCacheEntry *ent;
+ int bytes_rendered = 0, total_w = 0;
+ int utf_bytes = 0;
+ unsigned int unicode = 0;
+ int i, x, diff, char_idx, prev_idx = 0;
+ int height;
+ FT_Vector delta;
+ uint8_t *data = NULL;
+ const char *text_itr = text;
+ int *char_idxs;
+ int char_idxs_len = 0;
- char_idxs = (int *)malloc(strlen(text) * sizeof(int));
+ char_idxs = new int[strlen(text)];
- while(*text_itr)
- {
- utf_bytes = utf8_to_unicode(text_itr, &unicode);
- text_itr += utf_bytes;
- bytes_rendered += utf_bytes;
+ while(*text_itr)
+ {
+ utf_bytes = utf8_to_unicode(text_itr, &unicode);
+ text_itr += utf_bytes;
+ bytes_rendered += utf_bytes;
- char_idx = FT_Get_Char_Index(f->face, unicode);
- char_idxs[char_idxs_len] = char_idx;
+ char_idx = FT_Get_Char_Index(f->face, unicode);
+ char_idxs[char_idxs_len] = char_idx;
+ ent = gr_ttf_glyph_cache_get(f, char_idx);
+ if(ent)
+ {
+ diff = ent->glyph->root.advance.x >> 16;
- ent = gr_ttf_glyph_cache_get(f, char_idx);
- if(ent)
- {
- diff = ent->glyph->root.advance.x >> 16;
+ if(FT_HAS_KERNING(f->face) && prev_idx && char_idx)
+ {
+ FT_Get_Kerning(f->face, prev_idx, char_idx, FT_KERNING_DEFAULT, &delta);
+ diff += delta.x >> 6;
+ }
- if(FT_HAS_KERNING(f->face) && prev_idx && char_idx)
- {
- FT_Get_Kerning(f->face, prev_idx, char_idx, FT_KERNING_DEFAULT, &delta);
- diff += delta.x >> 6;
- }
+ if(max_width != -1 && total_w + diff > max_width)
+ break;
- if(max_width != -1 && total_w + diff > max_width)
- break;
+ total_w += diff;
+ }
+ prev_idx = char_idx;
+ ++char_idxs_len;
+ }
- total_w += diff;
- }
- prev_idx = char_idx;
- ++char_idxs_len;
- }
+ if(font->max_height == -1)
+ gr_ttf_calcMaxFontHeight(font);
- if(font->max_height == -1)
- gr_ttf_calcMaxFontHeight(font);
+ if(font->max_height == -1)
+ {
+ delete [] char_idxs;
+ return -1;
+ }
- if(font->max_height == -1)
- {
- free(char_idxs);
- return -1;
- }
+ height = font->max_height;
- height = font->max_height;
+ data = new uint8_t[total_w * height];
+ x = 0;
+ prev_idx = 0;
- data = (uint8_t *)malloc(total_w*height);
- memset(data, 0, total_w*height);
- x = 0;
- prev_idx = 0;
+ surface->version = sizeof(*surface);
+ surface->width = total_w;
+ surface->height = height;
+ surface->stride = total_w;
+ surface->data = (GGLubyte*)data;
+ surface->format = GGL_PIXEL_FORMAT_A_8;
- surface->version = sizeof(*surface);
- surface->width = total_w;
- surface->height = height;
- surface->stride = total_w;
- surface->data = (GGLubyte*)data;
- surface->format = GGL_PIXEL_FORMAT_A_8;
+ for(i = 0; i < char_idxs_len; ++i)
+ {
+ char_idx = char_idxs[i];
+ if(FT_HAS_KERNING(f->face) && prev_idx && char_idx)
+ {
+ FT_Get_Kerning(f->face, prev_idx, char_idx, FT_KERNING_DEFAULT, &delta);
+ x += delta.x >> 6;
+ }
- for(i = 0; i < char_idxs_len; ++i)
- {
- char_idx = char_idxs[i];
- if(FT_HAS_KERNING(f->face) && prev_idx && char_idx)
- {
- FT_Get_Kerning(f->face, prev_idx, char_idx, FT_KERNING_DEFAULT, &delta);
- x += delta.x >> 6;
- }
+ ent = gr_ttf_glyph_cache_get(f, char_idx);
+ if(ent)
+ {
+ gr_ttf_copy_glyph_to_surface(surface, ent->glyph, x, 0, font->base);
+ x += ent->glyph->root.advance.x >> 16;
+ }
- ent = gr_ttf_glyph_cache_get(f, char_idx);
- if(ent)
- {
- gr_ttf_copy_glyph_to_surface(surface, ent->glyph, x, 0, font->base);
- x += ent->glyph->root.advance.x >> 16;
- }
+ prev_idx = char_idx;
+ }
- prev_idx = char_idx;
- }
-
- free(char_idxs);
- return bytes_rendered;
+ delete [] char_idxs;
+ return bytes_rendered;
}
-static StringCacheEntry *gr_ttf_string_cache_peek(TrueTypeFont *font, const char *text, int max_width)
-{
- StringCacheKey k = {
- .text = (char*)text,
- .max_width = max_width
- };
-
- return (StringCacheEntry *)hashmapGet(font->string_cache, &k);
+StringCacheEntry* twrpTruetype::gr_ttf_string_cache_peek(TrueTypeFont *font,
+ const char *text,
+ __attribute__((unused)) int max_width) {
+ StringCacheKey k = {
+ .text = (char*)text,
+ .max_width = max_width
+ };
+ StringCacheMap::iterator stringCacheItr = font->string_cache.find(k);
+ if (stringCacheItr != font->string_cache.end()) {
+ return stringCacheItr->second;
+ }
+ else {
+ return nullptr;
+ }
}
-static StringCacheEntry *gr_ttf_string_cache_get(TrueTypeFont *font, const char *text, int max_width)
-{
- StringCacheEntry *res;
- StringCacheKey k = {
- .text = (char*)text,
- .max_width = max_width
- };
+StringCacheEntry* twrpTruetype::gr_ttf_string_cache_get(TrueTypeFont *font, const char *text, int max_width) {
+ StringCacheEntry *res = nullptr;
- res = (StringCacheEntry *)hashmapGet(font->string_cache, &k);
- if(!res)
- {
- res = (StringCacheEntry *)malloc(sizeof(StringCacheEntry));
- memset(res, 0, sizeof(StringCacheEntry));
- res->rendered_bytes = gr_ttf_render_text(font, &res->surface, text, max_width);
- if(res->rendered_bytes < 0)
- {
- free(res);
- return NULL;
- }
+ StringCacheKey k = {
+ .text = (char*)text,
+ .max_width = max_width
+ };
- StringCacheKey *new_key = (StringCacheKey *)malloc(sizeof(StringCacheKey));
- memset(new_key, 0, sizeof(StringCacheKey));
- new_key->max_width = max_width;
- new_key->text = strdup(text);
+ StringCacheMap::iterator stringCacheItr = font->string_cache.find(k);
+ if (stringCacheItr == font->string_cache.end())
+ {
+ res = new StringCacheEntry;
+ res->rendered_bytes = gr_ttf_render_text(font, &res->surface, text, max_width);
+ if(res->rendered_bytes < 0)
+ {
+ delete res;
+ return nullptr;
+ }
- res->key = new_key;
+ StringCacheKey *new_key = new StringCacheKey;
+ new_key->max_width = max_width;
+ new_key->text = strdup(text);
+ res->key = new_key;
+ font->string_cache[k] = res;
+ }
+ else
+ {
+ res = stringCacheItr->second;
- if(font->string_cache_tail)
- {
- res->prev = font->string_cache_tail;
- res->prev->next = res;
- }
- else
- font->string_cache_head = res;
- font->string_cache_tail = res;
+ // truncate old entries
+ if (font->string_cache.size() >= STRING_CACHE_MAX_ENTRIES)
+ {
+ StringCacheEntry *ent;
+ for(int i = 0; i < STRING_CACHE_TRUNCATE_ENTRIES; ++i)
+ {
+ StringCacheMap::iterator stringTruncCacheItr = font->string_cache.find(k);
- hashmapPut(font->string_cache, new_key, res);
- }
- else if(res->next)
- {
- // move this entry to the tail of the linked list
- // if it isn't already there
- if(res->prev)
- res->prev->next = res->next;
-
- res->next->prev = res->prev;
-
- if(!res->prev)
- font->string_cache_head = res->next;
-
- res->next = NULL;
- res->prev = font->string_cache_tail;
- res->prev->next = res;
- font->string_cache_tail = res;
-
- // truncate old entries
- if(hashmapSize(font->string_cache) >= STRING_CACHE_MAX_ENTRIES)
- {
- printf("Truncating string cache entries.\n");
- int i;
- StringCacheEntry *ent;
- for(i = 0; i < STRING_CACHE_TRUNCATE_ENTRIES; ++i)
- {
- ent = font->string_cache_head;
- font->string_cache_head = ent->next;
- font->string_cache_head->prev = NULL;
-
- hashmapRemove(font->string_cache, ent->key);
-
- gr_ttf_freeStringCache(ent->key, ent, NULL);
- }
- }
- }
- return res;
+ if (stringTruncCacheItr != font->string_cache.end()) {
+ ent = stringTruncCacheItr->second;
+ gr_ttf_freeStringCache(ent->key, ent, nullptr);
+ font->string_cache.erase(stringTruncCacheItr);
+ }
+ }
+ }
+ }
+ return res;
}
-int gr_ttf_measureEx(const char *s, void *font)
-{
- TrueTypeFont *f = (TrueTypeFont *)font;
- int res = -1;
+int twrpTruetype::gr_ttf_measureEx(const char *s, void *font) {
+ TrueTypeFont *f = (TrueTypeFont *)font;
+ int res = -1;
- pthread_mutex_lock(&f->mutex);
- StringCacheEntry *e = gr_ttf_string_cache_get(f, s, -1);
- if(e)
- res = e->surface.width;
- pthread_mutex_unlock(&f->mutex);
+ pthread_mutex_lock(&f->mutex);
+ StringCacheEntry *e = gr_ttf_string_cache_get(f, s, -1);
+ if(e)
+ res = e->surface.width;
+ pthread_mutex_unlock(&f->mutex);
- return res;
+ return res;
}
-int gr_ttf_maxExW(const char *s, void *font, int max_width)
-{
- TrueTypeFont *f = (TrueTypeFont *)font;
- TrueTypeCacheEntry *ent;
- int max_bytes = 0, total_w = 0;
- int utf_bytes, prev_utf_bytes = 0;
- unsigned int unicode = 0;
- int char_idx, prev_idx = 0;
- FT_Vector delta;
- StringCacheEntry *e;
+int twrpTruetype::gr_ttf_maxExW(const char *s, void *font, int max_width) {
+ TrueTypeFont *f = (TrueTypeFont *)font;
+ TrueTypeCacheEntry *ent;
+ int max_bytes = 0, total_w = 0;
+ int utf_bytes, prev_utf_bytes = 0;
+ unsigned int unicode = 0;
+ int char_idx, prev_idx = 0;
+ FT_Vector delta;
+ StringCacheEntry *e;
- pthread_mutex_lock(&f->mutex);
+ pthread_mutex_lock(&f->mutex);
- e = gr_ttf_string_cache_peek(f, s, max_width);
- if(e)
- {
- max_bytes = e->rendered_bytes;
- pthread_mutex_unlock(&f->mutex);
- return max_bytes;
- }
+ e = gr_ttf_string_cache_peek(f, s, max_width);
+ if(e)
+ {
+ max_bytes = e->rendered_bytes;
+ pthread_mutex_unlock(&f->mutex);
+ return max_bytes;
+ }
- while(*s)
- {
- utf_bytes = utf8_to_unicode(s, &unicode);
- s += utf_bytes;
+ while(*s)
+ {
+ utf_bytes = utf8_to_unicode(s, &unicode);
+ s += utf_bytes;
- char_idx = FT_Get_Char_Index(f->face, unicode);
- if(FT_HAS_KERNING(f->face) && prev_idx && char_idx)
- {
- FT_Get_Kerning(f->face, prev_idx, char_idx, FT_KERNING_DEFAULT, &delta);
- total_w += delta.x >> 6;
- }
- prev_idx = char_idx;
+ char_idx = FT_Get_Char_Index(f->face, unicode);
+ if(FT_HAS_KERNING(f->face) && prev_idx && char_idx)
+ {
+ FT_Get_Kerning(f->face, prev_idx, char_idx, FT_KERNING_DEFAULT, &delta);
+ total_w += delta.x >> 6;
+ }
+ prev_idx = char_idx;
- if(total_w > max_width)
- {
- max_bytes -= prev_utf_bytes;
- break;
- }
- prev_utf_bytes = utf_bytes;
+ if(total_w > max_width)
+ {
+ max_bytes -= prev_utf_bytes;
+ break;
+ }
+ prev_utf_bytes = utf_bytes;
+ ent = gr_ttf_glyph_cache_get(f, char_idx);
+ if(!ent)
+ continue;
- ent = gr_ttf_glyph_cache_get(f, char_idx);
- if(!ent)
- continue;
-
- total_w += ent->glyph->root.advance.x >> 16;
- max_bytes += utf_bytes;
- }
- pthread_mutex_unlock(&f->mutex);
- return max_bytes;
+ total_w += ent->glyph->root.advance.x >> 16;
+ max_bytes += utf_bytes;
+ }
+ pthread_mutex_unlock(&f->mutex);
+ return max_bytes;
}
-int gr_ttf_textExWH(void *context, int x, int y,
- const char *s, void *pFont,
- int max_width, int max_height,
- const gr_surface gr_draw_surface)
-{
- GGLContext *gl = (GGLContext *)context;
- TrueTypeFont *font = (TrueTypeFont *)pFont;
- const GRSurface *gr_draw = (const GRSurface*) gr_draw_surface;
+int twrpTruetype::gr_ttf_textExWH(void *context, int x, int y,
+ const char *s, void *pFont,
+ int max_width, int max_height,
+ const gr_surface gr_draw_surface) {
+ GGLContext *gl = (GGLContext *)context;
+ TrueTypeFont *font = (TrueTypeFont *)pFont;
+ const GRSurface *gr_draw = (const GRSurface*) gr_draw_surface;
- // not actualy max width, but max_width + x
- if(max_width != -1)
- {
- max_width -= x;
- if(max_width <= 0)
- return 0;
- }
+ // not actualy max width, but max_width + x
+ if(max_width != -1)
+ {
+ max_width -= x;
+ if(max_width <= 0)
+ return 0;
+ }
- pthread_mutex_lock(&font->mutex);
+ pthread_mutex_lock(&font->mutex);
- StringCacheEntry *e = gr_ttf_string_cache_get(font, s, max_width);
- if(!e)
- {
- pthread_mutex_unlock(&font->mutex);
- return -1;
- }
+ StringCacheEntry *e = gr_ttf_string_cache_get(font, s, max_width);
+ if(!e)
+ {
+ pthread_mutex_unlock(&font->mutex);
+ return -1;
+ }
#if TW_ROTATION != 0
- // Do not perform relatively expensive operation if not needed
- GGLSurface string_surface_rotated;
- string_surface_rotated.version = sizeof(string_surface_rotated);
- // Skip the **(TW_ROTATION == 0)** || (TW_ROTATION == 180) check
- // because we are under a TW_ROTATION != 0 conditional compilation statement
- string_surface_rotated.width = (TW_ROTATION == 180) ? e->surface.width : e->surface.height;
- string_surface_rotated.height = (TW_ROTATION == 180) ? e->surface.height : e->surface.width;
- string_surface_rotated.stride = string_surface_rotated.width;
- string_surface_rotated.format = e->surface.format;
- // e->surface.format is GGL_PIXEL_FORMAT_A_8 (grayscale)
- string_surface_rotated.data = (GGLubyte*) malloc(string_surface_rotated.stride * string_surface_rotated.height * 1);
- surface_ROTATION_transform((gr_surface) &string_surface_rotated, (const gr_surface) &e->surface, 1);
+ // Do not perform relatively expensive operation if not needed
+ GGLSurface string_surface_rotated;
+ string_surface_rotated.version = sizeof(string_surface_rotated);
+ // Skip the **(TW_ROTATION == 0)** || (TW_ROTATION == 180) check
+ // because we are under a TW_ROTATION != 0 conditional compilation statement
+ string_surface_rotated.width = (TW_ROTATION == 180) ? e->surface.width : e->surface.height;
+ string_surface_rotated.height = (TW_ROTATION == 180) ? e->surface.height : e->surface.width;
+ string_surface_rotated.stride = string_surface_rotated.width;
+ string_surface_rotated.format = e->surface.format;
+ // e->surface.format is GGL_PIXEL_FORMAT_A_8 (grayscale)
+ string_surface_rotated.data = new GGLubyte[string_surface_rotated.stride * string_surface_rotated.height * 1];
+ surface_ROTATION_transform((gr_surface) &string_surface_rotated, (const gr_surface) &e->surface, 1);
#endif
- int y_bottom = y + e->surface.height;
- int res = e->rendered_bytes;
+ int y_bottom = y + e->surface.height;
+ int res = e->rendered_bytes;
- if(max_height != -1 && max_height < y_bottom)
- {
- y_bottom = max_height;
- if(y_bottom <= y)
- {
- pthread_mutex_unlock(&font->mutex);
- return 0;
- }
- }
+ if(max_height != -1 && max_height < y_bottom)
+ {
+ y_bottom = max_height;
+ if(y_bottom <= y)
+ {
+ pthread_mutex_unlock(&font->mutex);
+ return 0;
+ }
+ }
- // Figuring out display coordinates works for TW_ROTATION == 0 too,
- // and isn't as expensive as allocating and rotating another surface,
- // so we do this anyway.
- int x0_disp, y0_disp, x1_disp, y1_disp;
- int l_disp, r_disp, t_disp, b_disp;
+ // Figuring out display coordinates works for TW_ROTATION == 0 too,
+ // and isn't as expensive as allocating and rotating another surface,
+ // so we do this anyway.
+ int x0_disp, y0_disp, x1_disp, y1_disp;
+ int l_disp, r_disp, t_disp, b_disp;
- x0_disp = ROTATION_X_DISP(x, y, gr_draw);
- y0_disp = ROTATION_Y_DISP(x, y, gr_draw);
- x1_disp = ROTATION_X_DISP(x + e->surface.width, y_bottom, gr_draw);
- y1_disp = ROTATION_Y_DISP(x + e->surface.width, y_bottom, gr_draw);
- l_disp = std::min(x0_disp, x1_disp);
- r_disp = std::max(x0_disp, x1_disp);
- t_disp = std::min(y0_disp, y1_disp);
- b_disp = std::max(y0_disp, y1_disp);
+ x0_disp = ROTATION_X_DISP(x, y, gr_draw);
+ y0_disp = ROTATION_Y_DISP(x, y, gr_draw);
+ x1_disp = ROTATION_X_DISP(x + e->surface.width, y_bottom, gr_draw);
+ y1_disp = ROTATION_Y_DISP(x + e->surface.width, y_bottom, gr_draw);
+ l_disp = std::min(x0_disp, x1_disp);
+ r_disp = std::max(x0_disp, x1_disp);
+ t_disp = std::min(y0_disp, y1_disp);
+ b_disp = std::max(y0_disp, y1_disp);
#if TW_ROTATION != 0
- gl->bindTexture(gl, &string_surface_rotated);
+ gl->bindTexture(gl, &string_surface_rotated);
#else
- gl->bindTexture(gl, &e->surface);
+ gl->bindTexture(gl, &e->surface);
#endif
- gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE);
- gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
- gl->texGeni(gl, GGL_T, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
+ gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE);
+ gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
+ gl->texGeni(gl, GGL_T, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
- gl->enable(gl, GGL_TEXTURE_2D);
- gl->texCoord2i(gl, -l_disp, -t_disp);
- gl->recti(gl, l_disp, t_disp, r_disp, b_disp);
- gl->disable(gl, GGL_TEXTURE_2D);
+ gl->enable(gl, GGL_TEXTURE_2D);
+ gl->texCoord2i(gl, -l_disp, -t_disp);
+ gl->recti(gl, l_disp, t_disp, r_disp, b_disp);
+ gl->disable(gl, GGL_TEXTURE_2D);
#if TW_ROTATION != 0
- free(string_surface_rotated.data);
+ delete [] string_surface_rotated.data;
#endif
- pthread_mutex_unlock(&font->mutex);
- return res;
+ pthread_mutex_unlock(&font->mutex);
+ return res;
}
-int gr_ttf_getMaxFontHeight(void *font)
-{
- int res;
- TrueTypeFont *f = (TrueTypeFont *)font;
+int twrpTruetype::gr_ttf_getMaxFontHeight(void *font) {
+ int res;
+ TrueTypeFont *f = (TrueTypeFont *)font;
- pthread_mutex_lock(&f->mutex);
+ pthread_mutex_lock(&f->mutex);
- if(f->max_height == -1)
- gr_ttf_calcMaxFontHeight(f);
- res = f->max_height;
+ if(f->max_height == -1)
+ gr_ttf_calcMaxFontHeight(f);
+ res = f->max_height;
- pthread_mutex_unlock(&f->mutex);
- return res;
-}
-
-static bool gr_ttf_dump_stats_count_string_cache(void *key __unused, void *value, void *context)
-{
- int *string_cache_size = (int *)context;
- StringCacheEntry *e = (StringCacheEntry *)value;
- *string_cache_size += e->surface.height*e->surface.width + sizeof(StringCacheEntry);
- return true;
-}
-
-static bool gr_ttf_dump_stats_font(void *key, void *value, void *context)
-{
- TrueTypeFontKey *k = (TrueTypeFontKey *)key;
- TrueTypeFont *f = (TrueTypeFont *)value;
- int *total_string_cache_size = (int *)context;
- int string_cache_size = 0;
-
- pthread_mutex_lock(&f->mutex);
-
- hashmapForEach(f->string_cache, gr_ttf_dump_stats_count_string_cache, &string_cache_size);
-
- printf(" Font %s (size %d, dpi %d):\n"
- " refcount: %d\n"
- " max_height: %d\n"
- " base: %d\n"
- " glyph_cache: %zu entries\n"
- " string_cache: %zu entries (%.2f kB)\n",
- k->path, k->size, k->dpi,
- f->refcount, f->max_height, f->base,
- hashmapSize(f->glyph_cache),
- hashmapSize(f->string_cache), ((double)string_cache_size)/1024);
-
- pthread_mutex_unlock(&f->mutex);
-
- *total_string_cache_size += string_cache_size;
- return true;
-}
-
-void gr_ttf_dump_stats(void)
-{
- pthread_mutex_lock(&font_data.mutex);
-
- printf("TrueType fonts system stats: ");
- if(!font_data.fonts)
- printf("no truetype fonts loaded.\n");
- else
- {
- int total_string_cache_size = 0;
- printf("%zu fonts loaded.\n", hashmapSize(font_data.fonts));
- hashmapForEach(font_data.fonts, gr_ttf_dump_stats_font, &total_string_cache_size);
- printf(" Total string cache size: %.2f kB\n", ((double)total_string_cache_size)/1024);
- }
-
- pthread_mutex_unlock(&font_data.mutex);
+ pthread_mutex_unlock(&f->mutex);
+ return res;
}
diff --git a/minuitwrp/truetype.hpp b/minuitwrp/truetype.hpp
new file mode 100755
index 0000000..e0d7a2f
--- /dev/null
+++ b/minuitwrp/truetype.hpp
@@ -0,0 +1,121 @@
+/*
+ Copyright 2013 to 2020 TeamWin
+ TWRP is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ TWRP is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with TWRP. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _TWRP_TRUETYPE_HPP
+#define _TWRP_TRUETYPE_HPP
+
+#include <map>
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
+#include <pixelflinger/pixelflinger.h>
+#include "minui.h"
+
+struct TrueTypeFontKey {
+ int size;
+ int dpi;
+ char *path;
+
+ bool operator<(const TrueTypeFontKey &ttfk) const {
+ return size < ttfk.size || (size == ttfk.size && dpi < ttfk.dpi) || (size == ttfk.size && dpi == ttfk.dpi
+ && std::strcmp(path, ttfk.path) < 0) || (size == ttfk.size && std::strcmp(path, ttfk.path) > 0);
+ }
+};
+
+typedef struct TrueTypeFontKey TrueTypeFontKey;
+
+typedef struct {
+ FT_BBox bbox;
+ FT_BitmapGlyph glyph;
+} TrueTypeCacheEntry;
+
+struct StringCacheKey {
+ char *text;
+ int max_width;
+
+ bool operator<(const StringCacheKey &sck) const {
+ return max_width < sck.max_width || (max_width == sck.max_width
+ && std::strcmp(text, sck.text) < 0) || (max_width == sck.max_width && std::strcmp(text, sck.text) > 0);
+ }
+};
+
+typedef struct StringCacheKey StringCacheKey;
+
+typedef struct StringCacheEntry {
+ GGLSurface surface;
+ int rendered_bytes; // number of bytes from C string rendered, not number of UTF8 characters!
+ StringCacheKey *key;
+} StringCacheEntry;
+
+typedef struct {
+ int type;
+ int refcount;
+ int size;
+ int dpi;
+ int max_height;
+ int base;
+ FT_Face face;
+ std::map<int, TrueTypeCacheEntry*> glyph_cache;
+ std::map<StringCacheKey, StringCacheEntry*> string_cache;
+ pthread_mutex_t mutex;
+ TrueTypeFontKey *key;
+} TrueTypeFont;
+
+typedef struct {
+ FT_Library ft_library;
+ std::map<TrueTypeFontKey, TrueTypeFont*> fonts;
+ pthread_mutex_t mutex;
+} FontData;
+
+typedef std::map<StringCacheKey, StringCacheEntry*> StringCacheMap;
+typedef std::map<int, TrueTypeCacheEntry*> TrueTypeCacheEntryMap;
+typedef std::map<TrueTypeFontKey, TrueTypeFont*> TrueTypeFontMap;
+
+#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
+#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
+
+// 32bit FNV-1a hash algorithm
+// http://isthe.com/chongo/tech/comp/fnv/#FNV-1a
+static const uint32_t FNV_prime = 16777619U;
+static const uint32_t offset_basis = 2166136261U;
+
+#define STRING_CACHE_MAX_ENTRIES 400
+#define STRING_CACHE_TRUNCATE_ENTRIES 150
+
+class twrpTruetype {
+public:
+ twrpTruetype();
+ static int utf8_to_unicode(const char* pIn, unsigned int *pOut);
+ static void* gr_ttf_loadFont(const char *filename, int size, int dpi);
+ static void* gr_ttf_scaleFont(void *font, int max_width, int measured_width);
+ static bool gr_ttf_freeStringCache(void *key, void *value, void *context __unused);
+ static void gr_ttf_freeFont(void *font);
+ static TrueTypeCacheEntry* gr_ttf_glyph_cache_peek(TrueTypeFont *font, int char_index);
+ static TrueTypeCacheEntry* gr_ttf_glyph_cache_get(TrueTypeFont *font, int char_index);
+ static int gr_ttf_copy_glyph_to_surface(GGLSurface *dest, FT_BitmapGlyph glyph, int offX, int offY, int base);
+ static void gr_ttf_calcMaxFontHeight(TrueTypeFont *f);
+ static int gr_ttf_render_text(TrueTypeFont *font, GGLSurface *surface, const char *text, int max_width);
+ static StringCacheEntry* gr_ttf_string_cache_peek(TrueTypeFont *font, const char *text, __attribute__((unused)) int max_width);
+ static StringCacheEntry* gr_ttf_string_cache_get(TrueTypeFont *font, const char *text, int max_width);
+ static int gr_ttf_measureEx(const char *s, void *font);
+ static int gr_ttf_maxExW(const char *s, void *font, int max_width);
+ static int gr_ttf_textExWH(void *context, int x, int y,
+ const char *s, void *pFont,
+ int max_width, int max_height,
+ const gr_surface gr_draw_surface);
+ static int gr_ttf_getMaxFontHeight(void *font);
+};
+#endif // _TWRP_TRUETYPE_HPP
diff --git a/minzip/Zip.c b/minzip/Zip.c
old mode 100644
new mode 100755
diff --git a/mmcutils/Android.mk b/mmcutils/Android.mk
index 119b40f..40cda36 100644
--- a/mmcutils/Android.mk
+++ b/mmcutils/Android.mk
@@ -7,7 +7,7 @@
mmcutils.c
LOCAL_MODULE := libmmcutils
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
include $(BUILD_STATIC_LIBRARY)
@@ -18,7 +18,7 @@
mmcutils.c
LOCAL_MODULE := libmmcutils
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY)
diff --git a/mtdutils/Android.mk b/mtdutils/Android.mk
index 87ac081..b952e36 100644
--- a/mtdutils/Android.mk
+++ b/mtdutils/Android.mk
@@ -48,14 +48,14 @@
LOCAL_SRC_FILES := bml_over_mtd.c
LOCAL_C_INCLUDES += $(commands_recovery_local_path)/mtdutils
LOCAL_MODULE := libbml_over_mtd
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS += -Dmain=bml_over_mtd_main
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := bml_over_mtd.c
LOCAL_MODULE := bml_over_mtd
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := UTILITY_EXECUTABLES
LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities
LOCAL_UNSTRIPPED_PATH := $(PRODUCT_OUT)/symbols/utilities
diff --git a/mtp/ffs/Android.mk b/mtp/ffs/Android.mk
old mode 100644
new mode 100755
index 9e75e0d..740afcb
--- a/mtp/ffs/Android.mk
+++ b/mtp/ffs/Android.mk
@@ -5,14 +5,17 @@
include $(CLEAR_VARS)
LOCAL_MODULE := libtwrpmtp-ffs
LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS = -D_FILE_OFFSET_BITS=64 -DMTP_DEVICE -DMTP_HOST -fno-strict-aliasing -Wno-unused-variable -Wno-format -Wno-unused-parameter -Wno-unused-private-field
-LOCAL_C_INCLUDES += $(LOCAL_PATH) bionic frameworks/base/include system/core/include bionic/libc/private/ bootable/recovery/twrplibusbhost/include
-ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
- LOCAL_C_INCLUDES += external/stlport/stlport
- LOCAL_SHARED_LIBRARIES += libstlport
-else
- LOCAL_SHARED_LIBRARIES += libc++
-endif
+LOCAL_CFLAGS = -D_FILE_OFFSET_BITS=64 -DMTP_DEVICE -DMTP_HOST -fno-strict-aliasing \
+ -Wno-unused-variable -Wno-format -Wno-unused-parameter -Wno-unused-private-field \
+ -Wno-implicit-fallthrough
+LOCAL_C_INCLUDES += $(LOCAL_PATH) bionic \
+ frameworks/base/include \
+ system/core/include \
+ bionic/libc/private/ \
+ bootable/recovery/twrplibusbhost/include \
+ bootable/recovery/install/include
+
+LOCAL_SHARED_LIBRARIES += libc++ libaosprecovery
LOCAL_SRC_FILES = \
MtpDataPacket.cpp \
@@ -54,7 +57,6 @@
libdl \
libcutils \
libutils \
- libaosprecovery \
libselinux \
libbase
diff --git a/mtp/ffs/MtpStorage.h b/mtp/ffs/MtpStorage.h
index 9d6d291..8d12b07 100755
--- a/mtp/ffs/MtpStorage.h
+++ b/mtp/ffs/MtpStorage.h
@@ -23,7 +23,7 @@
#include "MtpTypes.h"
#include "mtp.h"
#include "btree.hpp"
-#include "../../tw_atomic.hpp"
+#include "tw_atomic.hpp"
class MtpDatabase;
diff --git a/openaes/Android.mk b/openaes/Android.mk
index ef6fcb0..a628784 100644
--- a/openaes/Android.mk
+++ b/openaes/Android.mk
@@ -9,7 +9,7 @@
$(commands_recovery_local_path)/openaes/inc
LOCAL_CFLAGS:= -g -c -W
LOCAL_MODULE:=openaes
- LOCAL_MODULE_TAGS:= eng
+ LOCAL_MODULE_TAGS:= optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_SHARED_LIBRARIES = libopenaes libc
@@ -18,7 +18,7 @@
# Build shared library
include $(CLEAR_VARS)
LOCAL_MODULE := libopenaes
- LOCAL_MODULE_TAGS := eng
+ LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES := \
$(commands_recovery_local_path)/openaes/src/isaac \
$(commands_recovery_local_path)/openaes/inc
@@ -29,7 +29,7 @@
# Build static library
include $(CLEAR_VARS)
LOCAL_MODULE := libopenaes_static
- LOCAL_MODULE_TAGS := eng
+ LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES := \
$(commands_recovery_local_path)/openaes/src/isaac \
$(commands_recovery_local_path)/openaes/inc
diff --git a/openrecoveryscript.cpp b/openrecoveryscript.cpp
index 1de0870..120dfca 100755
--- a/openrecoveryscript.cpp
+++ b/openrecoveryscript.cpp
@@ -44,14 +44,14 @@
#include "openrecoveryscript.hpp"
#include "progresstracking.hpp"
#include "variables.h"
-#include "adb_install.h"
+#include "install/adb_install.h"
#include "data.hpp"
-#include "adb_install.h"
#include "fuse_sideload.h"
#include "gui/gui.hpp"
#include "gui/pages.hpp"
#include "orscmd/orscmd.h"
#include "twinstall.h"
+#include "install/adb_install.h"
extern "C" {
#include "gui/gui.h"
#include "cutils/properties.h"
@@ -253,8 +253,8 @@
gui_msg(Msg("set_restore_opt=Setting restore options: '{1}':")(value2));
line_len = strlen(value2);
for (i=0; i<line_len; i++) {
- if ((value2[i] == 'S' || value2[i] == 's') && Partition_List.find(PartitionManager.Get_Android_Root_Path() + ';') != string::npos) {
- Restore_List += PartitionManager.Get_Android_Root_Path() + ';';
+ if ((value2[i] == 'S' || value2[i] == 's') && Partition_List.find("/system;") != string::npos) {
+ Restore_List += "/system;";
gui_msg("system=System");
} else if ((value2[i] == 'D' || value2[i] == 'd') && Partition_List.find("/data;") != string::npos) {
Restore_List += "/data;";
@@ -363,10 +363,13 @@
int wipe_cache = 0;
string result;
- pid_t sideload_child_pid;
+ // pid_t sideload_child_pid;
gui_msg("start_sideload=Starting ADB sideload feature...");
- ret_val = apply_from_adb("/", &sideload_child_pid);
+
+ // ret_val = apply_from_adb("/", &sideload_child_pid);
+ Device::BuiltinAction reboot_action = Device::REBOOT_BOOTLOADER;
+ ret_val = ApplyFromAdb("/", &reboot_action);
if (ret_val != 0) {
if (ret_val == -2)
gui_err("need_new_adb=You need adb 1.0.32 or newer to sideload to this device.");
@@ -378,6 +381,7 @@
ret_val = 1; // failure
}
sideload = 1; // Causes device to go to the home screen afterwards
+#ifdef USE_28_INSTALL
if (sideload_child_pid != 0) {
LOGINFO("Signaling child sideload process to exit.\n");
struct stat st;
@@ -388,6 +392,7 @@
LOGINFO("Waiting for child sideload process to exit.\n");
waitpid(sideload_child_pid, &status, 0);
}
+#endif
property_set("ctl.start", "adbd");
gui_msg("done=Done.");
} else if (strcmp(command, "fixperms") == 0 || strcmp(command, "fixpermissions") == 0 || strcmp(command, "fixcontexts") == 0) {
@@ -539,7 +544,7 @@
line_len = Options.size();
for (i=0; i<line_len; i++) {
if (Options.substr(i, 1) == "S" || Options.substr(i, 1) == "s") {
- Backup_List += PartitionManager.Get_Android_Root_Path() + ';';
+ Backup_List += "/system;";
gui_msg("system=System");
} else if (Options.substr(i, 1) == "D" || Options.substr(i, 1) == "d") {
Backup_List += "/data;";
diff --git a/orscmd/Android.mk b/orscmd/Android.mk
index 19837b4..ad7c67b 100644
--- a/orscmd/Android.mk
+++ b/orscmd/Android.mk
@@ -12,7 +12,7 @@
LOCAL_CFLAGS += -c -W
LOCAL_MODULE := orscmd
LOCAL_MODULE_STEM := twrp
-LOCAL_MODULE_TAGS:= eng
+LOCAL_MODULE_TAGS:= optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_PACK_MODULE_RELOCATIONS := false
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
diff --git a/otafault/Android.mk b/otafault/Android.mk
index c40fc06..13ab711 100644
--- a/otafault/Android.mk
+++ b/otafault/Android.mk
@@ -30,7 +30,7 @@
-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS
LOCAL_SRC_FILES := config.cpp ota_io.cpp
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libotafault
LOCAL_CLANG := true
LOCAL_C_INCLUDES := $(commands_recovery_local_path)
diff --git a/otautil/Android.bp b/otautil/Android.bp
old mode 100644
new mode 100755
index dd8f154..0bc7cf5
--- a/otautil/Android.bp
+++ b/otautil/Android.bp
@@ -24,15 +24,7 @@
// Minimal set of files to support host build.
srcs: [
-<<<<<<< HEAD
- "SysUtil.cpp",
- "DirUtil.cpp",
- "ZipUtil.cpp",
- "ThermalUtil.cpp",
- "cache_location.cpp",
-=======
"paths.cpp",
->>>>>>> android-10.0.0_r25
"rangeset.cpp",
],
@@ -69,6 +61,7 @@
"libext4_utils",
"libfs_mgr",
"libselinux",
+ "libziparchive",
],
},
},
diff --git a/otautil/Android.mk b/otautil/Android.mk
deleted file mode 100644
index feb468d..0000000
--- a/otautil/Android.mk
+++ /dev/null
@@ -1,41 +0,0 @@
-# Copyright (C) 2016 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
- SysUtil.cpp \
- DirUtil.cpp \
- ZipUtil.cpp \
- ThermalUtil.cpp
-
-LOCAL_STATIC_LIBRARIES := \
- libselinux \
- libbase
-
-ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 26; echo $$?),0)
-# Android 8.1 header
-LOCAL_C_INCLUDES += \
- system/core/libziparchive/include
-endif
-
-LOCAL_MODULE := libotautil
-LOCAL_CFLAGS := \
- -Werror \
- -Wall
-
-LOCAL_C_INCLUDES := include
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/otautil/include/otautil/logging.h b/otautil/include/otautil/logging.h
old mode 100644
new mode 100755
index 57125e4..6083497
--- a/otautil/include/otautil/logging.h
+++ b/otautil/include/otautil/logging.h
@@ -21,15 +21,10 @@
#include <sys/stat.h>
#include <sys/types.h>
-<<<<<<< HEAD:rotate_logs.h
-//#include <log/log_id.h>
-#include <private/android_logger.h> /* private pmsg functions */
-=======
#include <string>
#include <vector>
#include <log/log_id.h>
->>>>>>> android-10.0.0_r25:otautil/include/otautil/logging.h
static constexpr int KEEP_LOG_COUNT = 10;
diff --git a/otautil/include/otautil/roots.h b/otautil/include/otautil/roots.h
index a2c51e2..482f3d0 100644
--- a/otautil/include/otautil/roots.h
+++ b/otautil/include/otautil/roots.h
@@ -22,8 +22,6 @@
using Volume = android::fs_mgr::FstabEntry;
-typedef struct fstab_rec Volume;
-
// Load and parse volume data from /etc/recovery.fstab.
void load_volume_table();
diff --git a/partition.cpp b/partition.cpp
index beb4a81..581593c 100644
--- a/partition.cpp
+++ b/partition.cpp
@@ -667,7 +667,7 @@
LOGINFO("Trying wrapped key.\n");
property_set("fbe.data.wrappedkey", "true");
if (!Decrypt_FBE_DE()) {
- LOGINFO("Unable to decrypt device\n");
+ LOGERR("Unable to decrypt FBE device\n");
}
}
}
@@ -932,6 +932,7 @@
break;
case TWFLAG_KEYDIRECTORY:
Key_Directory = str;
+ break;
default:
// Should not get here
LOGINFO("Flag identified for processing, but later unmatched: %i\n", flag);
@@ -1128,7 +1129,6 @@
DataManager::SetValue("tw_has_internal", 1);
DataManager::SetValue("tw_has_data_media", 1);
backup_exclusions.add_absolute_dir("/data/data/com.google.android.music/files");
- backup_exclusions.add_absolute_dir("/data/per_boot"); // DJ9,14Jan2020 - exclude this dir to prevent "error 255" on AOSP ROMs that create and lock it
wipe_exclusions.add_absolute_dir(Mount_Point + "/misc/vold"); // adopted storage keys
ExcludeAll(Mount_Point + "/.layout_version");
ExcludeAll(Mount_Point + "/system/storage.xml");
diff --git a/partitionmanager.cpp b/partitionmanager.cpp
index b265469..19c527f 100755
--- a/partitionmanager.cpp
+++ b/partitionmanager.cpp
@@ -515,7 +515,7 @@
bool found = false;
string Local_Path = TWFunc::Get_Root_Path(Path);
- if (Local_Path == "/tmp" || Local_Path == "/" || Local_Path == "/etc")
+ if (Local_Path == "/tmp" || Local_Path == "/")
return true;
// Iterate through all partitions
@@ -799,7 +799,6 @@
string Backup_Name, Backup_List, backup_path;
unsigned long long total_bytes = 0, free_space = 0;
TWPartition* storage = NULL;
- std::vector<TWPartition*>::iterator subpart;
struct tm *t;
time_t seconds, total_start, total_stop;
size_t start_pos = 0, end_pos = 0;
@@ -2960,7 +2959,7 @@
int len = recv(uevent_pfd.fd, buf, sizeof(buf), MSG_DONTWAIT);
if (len == -1) {
- LOGINFO("recv error on uevent\n");
+ LOGERR("recv error on uevent\n");
return;
}
/*int i = 0; // Print all uevent output for test /debug
diff --git a/partitions.hpp b/partitions.hpp
old mode 100644
new mode 100755
diff --git a/pigz/Android.mk b/pigz/Android.mk
index 89f9635..ad7f39d 100644
--- a/pigz/Android.mk
+++ b/pigz/Android.mk
@@ -3,7 +3,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := pigz
-LOCAL_MODULE_TAGS := eng optional
+LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_CFLAGS :=
diff --git a/prebuilt/Android.mk b/prebuilt/Android.mk
old mode 100644
new mode 100755
index d330799..87496af
--- a/prebuilt/Android.mk
+++ b/prebuilt/Android.mk
@@ -18,17 +18,27 @@
ifneq ($(TW_USE_TOOLBOX), true)
RELINK_SOURCE_FILES += $(TARGET_OUT_OPTIONAL_EXECUTABLES)/busybox
else
- RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/sh
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 29; echo $$?),0)
+ RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/sh
+ else
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/bin/sh
+ endif
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libcrypto.so
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 23; echo $$?),0)
- RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/grep
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 29; echo $$?),0)
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/bin/grep
+ else
+ RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/grep
+ endif
LOCAL_POST_INSTALL_CMD += $(hide) if [ -e "$(TARGET_RECOVERY_ROOT_OUT)/sbin/egrep" ]; then \
- rm $(TARGET_RECOVERY_ROOT_OUT)/sbin/egrep; fi; ln -sr $(TARGET_RECOVERY_ROOT_OUT)/sbin/grep $(TARGET_RECOVERY_ROOT_OUT)/sbin/egrep; \
+ rm $(TARGET_RECOVERY_ROOT_OUT)/sbin/egrep; fi; ln -s $(TARGET_RECOVERY_ROOT_OUT)/sbin/grep $(TARGET_RECOVERY_ROOT_OUT)/sbin/egrep; \
if [ -e "$(TARGET_RECOVERY_ROOT_OUT)/sbin/fgrep" ]; then \
- rm $(TARGET_RECOVERY_ROOT_OUT)/sbin/fgrep; fi; ln -sr $(TARGET_RECOVERY_ROOT_OUT)/sbin/grep $(TARGET_RECOVERY_ROOT_OUT)/sbin/fgrep;
- RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/toybox
+ rm $(TARGET_RECOVERY_ROOT_OUT)/sbin/fgrep; fi; ln -s $(TARGET_RECOVERY_ROOT_OUT)/sbin/grep $(TARGET_RECOVERY_ROOT_OUT)/sbin/fgrep;
+ # RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/toybox
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23; echo $$?),0)
- RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/dd
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 29; echo $$?),0)
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/dd
+ endif
endif
ifneq ($(wildcard external/zip/Android.mk),)
RELINK_SOURCE_FILES += $(TARGET_OUT_OPTIONAL_EXECUTABLES)/zip
@@ -49,7 +59,11 @@
RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/fatlabel
RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/mkfs.fat
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 27; echo $$?),0)
- RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/adbd
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -le 29; echo $$?),0)
+ RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/adbd
+ else
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/bin/adbd
+ endif
endif
RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/e2fsck
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 28; echo $$?),0)
@@ -66,15 +80,42 @@
RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/linker64
endif
ifeq ($(TARGET_ARCH), arm64)
- RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/linker64
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 29; echo $$?),0)
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/bin/linker64
+ else
+ RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/linker64
+ endif
endif
#RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/twrpmtp
-RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libc.so
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 29; echo $$?),0)
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libc.so
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libdl.so
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libm.so
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libbacktrace.so
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libbootloader_message.so
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libfs_mgr.so
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libfscrypt.so
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libgsi.so
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libkeyutils.so
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/liblogwrap.so
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/liblp.so
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libprocessgroup.so
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libprocessgroup_setup.so
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libadbd.so
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libadbd_services.so
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libcap.so
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libminijail.so
+ # RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/libinit.so
+ RELINK_SOURCE_FILES += $(TARGET_ROOT_OUT)/../system/lib64/libdl_android.so
+else
+ RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libc.so
+ RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libdl.so
+ RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libm.so
+endif
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libcutils.so
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libcrecovery.so
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libusbhost.so
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libutils.so
-RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libdl.so
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libext2_com_err.so
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libext2_e2p.so
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libext2fs.so
@@ -94,12 +135,13 @@
endif
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libpng.so
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/liblog.so
-RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libm.so
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libstdc++.so
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libz.so
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libminuitwrp.so
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libminadbd.so
-RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libminzip.so
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 29; echo $$?),0)
+ RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libminzip.so
+endif
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libmtdutils.so
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libtar.so
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libtwadbbu.so
@@ -150,7 +192,11 @@
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0)
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libmincrypttwrp.so
endif
-RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/toolbox
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 28; echo $$?),0)
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/system/bin/toolbox
+else
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/toolbox
+endif
ifneq ($(TW_OEM_BUILD),true)
RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/twrp
@@ -290,9 +336,17 @@
RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/mkfs.f2fs
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libf2fs.so
else ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 26; echo $$?),0)
- RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/mkfs.f2fs
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 29; echo $$?),0)
+ RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/make_f2fs
+ else
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/mkfs.f2fs
+ endif
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 28; echo $$?),0)
- RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/sload.f2fs
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 29; echo $$?),0)
+ RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/sload_f2fs
+ else
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/sload.f2fs
+ endif
endif
else ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 24; echo $$?),0)
RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/mkfs.f2fs
@@ -405,24 +459,30 @@
TW_BB_SYMLINKS := busybox_symlinks
endif
-TWRP_AUTOGEN := $(intermediates)/teamwin
-GEN := $(intermediates)/teamwin
-$(GEN): $(RELINK) $(TW_BB_SYMLINKS) toolbox_symlinks
-$(GEN): $(RELINK_SOURCE_FILES) $(call intermediates-dir-for,EXECUTABLES,init)/init
- $(RELINK) $(TARGET_RECOVERY_ROOT_OUT)/sbin $(RELINK_SOURCE_FILES)
+# GEN := $(intermediates)/teamwin
+# $(GEN): $(RELINK) $(TW_BB_SYMLINKS) toolbox_symlinks
-LOCAL_GENERATED_SOURCES := $(GEN)
-LOCAL_SRC_FILES := teamwin $(GEN)
-include $(BUILD_PREBUILT)
-
-#permissive.sh
+#relink recovery executables linker to /sbin
include $(CLEAR_VARS)
-LOCAL_MODULE := permissive.sh
-LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE := relink
+LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
-LOCAL_SRC_FILES := $(LOCAL_MODULE)
-include $(BUILD_PREBUILT)
+LOCAL_POST_INSTALL_CMD += $(RELINK) $(TARGET_RECOVERY_ROOT_OUT)/sbin $(RELINK_SOURCE_FILES)
+LOCAL_REQUIRED_MODULES := linker toolbox_symlinks adbd libdl_android
+include $(BUILD_PHONY_PACKAGE)
+
+#relink init
+include $(CLEAR_VARS)
+LOCAL_MODULE := relink_init
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
+LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)
+RELINK_INIT := $(TARGET_RECOVERY_ROOT_OUT)/system/bin/init
+LOCAL_POST_INSTALL_CMD += $(RELINK) $(TARGET_RECOVERY_ROOT_OUT) $(RELINK_INIT) && \
+ ln -sf ../init $(TARGET_RECOVERY_ROOT_OUT)/sbin/ueventd
+LOCAL_REQUIRED_MODULES := init_second_stage.recovery
+include $(BUILD_PHONY_PACKAGE)
#mke2fs.conf
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 26; echo $$?),0)
@@ -542,16 +602,16 @@
include $(BUILD_PREBUILT)
endif
-ifeq ($(TW_USE_TOOLBOX), true)
- include $(CLEAR_VARS)
- LOCAL_MODULE := mkshrc_twrp
- LOCAL_MODULE_STEM := mkshrc
- LOCAL_MODULE_TAGS := eng
- LOCAL_MODULE_CLASS := ETC
- LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/etc
- LOCAL_SRC_FILES := $(LOCAL_MODULE)
- include $(BUILD_PREBUILT)
-endif
+#ifeq ($(TW_USE_TOOLBOX), true)
+# include $(CLEAR_VARS)
+# LOCAL_MODULE := mkshrc_twrp
+# LOCAL_MODULE_STEM := mkshrc
+# LOCAL_MODULE_TAGS := eng
+# LOCAL_MODULE_CLASS := ETC
+# LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/etc
+# LOCAL_SRC_FILES := $(LOCAL_MODULE)
+# include $(BUILD_PREBUILT)
+#endif
#TWRP App "placeholder"
include $(CLEAR_VARS)
diff --git a/prebuilt/permissive.sh b/prebuilt/permissive.sh
deleted file mode 100755
index f1046f9..0000000
--- a/prebuilt/permissive.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/sbin/sh
-
-# We use this shell script because the script will follow symlinks and
-# different trees will use different binaries to supply the setenforce
-# tool. Before M we use toolbox, M and beyond will use toybox. The init
-# binary and init.rc will not follow symlinks.
-
-setenforce 0
diff --git a/prebuilt/relink b/prebuilt/relink
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/prebuilt/relink
diff --git a/prebuilt/relink.sh b/prebuilt/relink.sh
index 2dd5614..3fa627f 100755
--- a/prebuilt/relink.sh
+++ b/prebuilt/relink.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/bash -x
process_file()
{
@@ -8,10 +8,10 @@
cp -f -p $src $src.tmp
src=$2.tmp
else
- cp -f -p $src $dst
+ cp -f -p --remove-destination $src $dst
fi
- sed "s|/system/bin/linker64\x0|/sbin/linker64\x0\x0\x0\x0\x0\x0\x0|g" $src | sed "s|/system/bin/linker\x0|/sbin/linker\x0\x0\x0\x0\x0\x0\x0|g" | sed "s|/system/bin/sh\x0|/sbin/sh\x0\x0\x0\x0\x0\x0\x0|g" | sed "s|/system/lib64\x0|/sbin\x0\x0\x0\x0\x0\x0\x0\x0\x0|g" | sed "s|/system/lib\x0|/sbin\x0\x0\x0\x0\x0\x0\x0|g" > $dst
+ sed "s|/system/bin/linker64\x0|/sbin/linker64\x0\x0\x0\x0\x0\x0\x0|g" $src | sed "s|/system/bin/linker\x0|/sbin/linker\x0\x0\x0\x0\x0\x0\x0|g" | sed "s|/system/bin/sh\x0|/sbin/sh\x0\x0\x0\x0\x0\x0\x0|g" > $dst
if [ $1 == $(dirname $2) ]; then
rm -f $src
diff --git a/prebuilt/relink_init b/prebuilt/relink_init
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/prebuilt/relink_init
diff --git a/recovery_ui/include/recovery_ui/device.h b/recovery_ui/include/recovery_ui/device.h
old mode 100644
new mode 100755
index 7c76cdb..c85da2a
--- a/recovery_ui/include/recovery_ui/device.h
+++ b/recovery_ui/include/recovery_ui/device.h
@@ -22,9 +22,9 @@
#include <memory>
#include <string>
#include <vector>
-
+#include "ui.h"
// Forward declaration to avoid including "ui.h".
-class RecoveryUI;
+// class RecoveryUI;
class Device {
public:
diff --git a/rotate_logs.cpp b/rotate_logs.cpp
deleted file mode 100644
index 76b7f4b..0000000
--- a/rotate_logs.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "rotate_logs.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-
-#include <string>
-
-#include <android-base/file.h>
-#include <android-base/logging.h>
-#include <android-base/parseint.h>
-#include <android-base/stringprintf.h>
-#include <private/android_logger.h> /* private pmsg functions */
-
-static const std::string LAST_KMSG_FILTER = "recovery/last_kmsg";
-static const std::string LAST_LOG_FILTER = "recovery/last_log";
-
-ssize_t logbasename(log_id_t /* id */, char /* prio */, const char* filename, const char* /* buf */,
- size_t len, void* arg) {
- bool* do_rotate = static_cast<bool*>(arg);
- if (LAST_KMSG_FILTER.find(filename) != std::string::npos ||
- LAST_LOG_FILTER.find(filename) != std::string::npos) {
- *do_rotate = true;
- }
- return len;
-}
-
-ssize_t logrotate(log_id_t id, char prio, const char* filename, const char* buf, size_t len,
- void* arg) {
- bool* do_rotate = static_cast<bool*>(arg);
- if (!*do_rotate) {
- return __android_log_pmsg_file_write(id, prio, filename, buf, len);
- }
-
- std::string name(filename);
- size_t dot = name.find_last_of('.');
- std::string sub = name.substr(0, dot);
-
- if (LAST_KMSG_FILTER.find(sub) == std::string::npos &&
- LAST_LOG_FILTER.find(sub) == std::string::npos) {
- return __android_log_pmsg_file_write(id, prio, filename, buf, len);
- }
-
- // filename rotation
- if (dot == std::string::npos) {
- name += ".1";
- } else {
- std::string number = name.substr(dot + 1);
- if (!isdigit(number[0])) {
- name += ".1";
- } else {
- size_t i;
- if (!android::base::ParseUint(number.c_str(), &i)) {
- LOG(ERROR) << "failed to parse uint in " << number;
- return -1;
- }
- name = sub + "." + std::to_string(i + 1);
- }
- }
-
- return __android_log_pmsg_file_write(id, prio, name.c_str(), buf, len);
-}
-
-// Rename last_log -> last_log.1 -> last_log.2 -> ... -> last_log.$max.
-// Similarly rename last_kmsg -> last_kmsg.1 -> ... -> last_kmsg.$max.
-// Overwrite any existing last_log.$max and last_kmsg.$max.
-void rotate_logs(const char* last_log_file, const char* last_kmsg_file) {
- // Logs should only be rotated once.
- static bool rotated = false;
- if (rotated) {
- return;
- }
- rotated = true;
-
- for (int i = KEEP_LOG_COUNT - 1; i >= 0; --i) {
- std::string old_log = android::base::StringPrintf("%s", last_log_file);
- if (i > 0) {
- old_log += "." + std::to_string(i);
- }
- std::string new_log = android::base::StringPrintf("%s.%d", last_log_file, i + 1);
- // Ignore errors if old_log doesn't exist.
- rename(old_log.c_str(), new_log.c_str());
-
- std::string old_kmsg = android::base::StringPrintf("%s", last_kmsg_file);
- if (i > 0) {
- old_kmsg += "." + std::to_string(i);
- }
- std::string new_kmsg = android::base::StringPrintf("%s.%d", last_kmsg_file, i + 1);
- rename(old_kmsg.c_str(), new_kmsg.c_str());
- }
-}
diff --git a/sepolicy/twrp.te b/sepolicy/twrp.te
old mode 100644
new mode 100755
index d81b9e1..44ceaf8
--- a/sepolicy/twrp.te
+++ b/sepolicy/twrp.te
@@ -1,4 +1,4 @@
recovery_only(`
- # Allow recovery to set permissive mode
permissive recovery;
+ permissive init;
')
diff --git a/simg2img/Android.mk b/simg2img/Android.mk
index 74755e7..b0bb4f1 100644
--- a/simg2img/Android.mk
+++ b/simg2img/Android.mk
@@ -1,8 +1,8 @@
LOCAL_PATH := system/core/libsparse
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := simg2img.c \
- sparse_crc32.c
+LOCAL_SRC_FILES := simg2img.cpp \
+ sparse_crc32.cpp
LOCAL_MODULE := simg2img_twrp
LOCAL_MODULE_STEM := simg2img
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
diff --git a/tests/Android.mk b/tests/Android.mk
old mode 100644
new mode 100755
index f19ca36..5cf00d3
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -14,211 +14,211 @@
# limitations under the License.
#
-LOCAL_PATH := $(call my-dir)
+# LOCAL_PATH := $(call my-dir)
# Unit tests
-include $(CLEAR_VARS)
-LOCAL_CFLAGS := -Wall -Werror
-LOCAL_MODULE := recovery_unit_test
-LOCAL_COMPATIBILITY_SUITE := device-tests
-LOCAL_STATIC_LIBRARIES := \
- libverifier \
- libminui \
- libotautil \
- libupdater \
- libziparchive \
- libutils \
- libz \
- libselinux \
- libbase \
- libBionicGtestMain
+# include $(CLEAR_VARS)
+# LOCAL_CFLAGS := -Wall -Werror
+# LOCAL_MODULE := recovery_unit_test
+# LOCAL_COMPATIBILITY_SUITE := device-tests
+# LOCAL_STATIC_LIBRARIES := \
+# libverifier \
+# libminui \
+# libotautil \
+# libupdater \
+# libziparchive \
+# libutils \
+# libz \
+# libselinux \
+# libbase \
+# libBionicGtestMain
-LOCAL_SRC_FILES := \
- unit/asn1_decoder_test.cpp \
- unit/dirutil_test.cpp \
- unit/locale_test.cpp \
- unit/rangeset_test.cpp \
- unit/sysutil_test.cpp \
- unit/zip_test.cpp \
- unit/ziputil_test.cpp
+# LOCAL_SRC_FILES := \
+# unit/asn1_decoder_test.cpp \
+# unit/dirutil_test.cpp \
+# unit/locale_test.cpp \
+# unit/rangeset_test.cpp \
+# unit/sysutil_test.cpp \
+# unit/zip_test.cpp \
+# unit/ziputil_test.cpp
-LOCAL_C_INCLUDES := $(commands_recovery_local_path)
-LOCAL_SHARED_LIBRARIES := liblog
-include $(BUILD_NATIVE_TEST)
+# LOCAL_C_INCLUDES := $(commands_recovery_local_path)
+# LOCAL_SHARED_LIBRARIES := liblog
+# include $(BUILD_NATIVE_TEST)
# Manual tests
-include $(CLEAR_VARS)
-LOCAL_CFLAGS := -Wall -Werror
-LOCAL_MODULE := recovery_manual_test
-LOCAL_STATIC_LIBRARIES := \
- libminui \
- libbase \
- libBionicGtestMain
+# include $(CLEAR_VARS)
+# LOCAL_CFLAGS := -Wall -Werror
+# LOCAL_MODULE := recovery_manual_test
+# LOCAL_STATIC_LIBRARIES := \
+# libminui \
+# libbase \
+# libBionicGtestMain
-LOCAL_SRC_FILES := manual/recovery_test.cpp
-LOCAL_SHARED_LIBRARIES := \
- liblog \
- libpng
+# LOCAL_SRC_FILES := manual/recovery_test.cpp
+# LOCAL_SHARED_LIBRARIES := \
+# liblog \
+# libpng
-resource_files := $(call find-files-in-subdirs, bootable/recovery, \
- "*_text.png", \
- res-mdpi/images \
- res-hdpi/images \
- res-xhdpi/images \
- res-xxhdpi/images \
- res-xxxhdpi/images \
- )
+# resource_files := $(call find-files-in-subdirs, bootable/recovery, \
+# "*_text.png", \
+# res-mdpi/images \
+# res-hdpi/images \
+# res-xhdpi/images \
+# res-xxhdpi/images \
+# res-xxxhdpi/images \
+# )
-# The resource image files that will go to $OUT/data/nativetest/recovery.
-testimage_out_path := $(TARGET_OUT_DATA)/nativetest/recovery
-GEN := $(addprefix $(testimage_out_path)/, $(resource_files))
+# # The resource image files that will go to $OUT/data/nativetest/recovery.
+# testimage_out_path := $(TARGET_OUT_DATA)/nativetest/recovery
+# GEN := $(addprefix $(testimage_out_path)/, $(resource_files))
-$(GEN): PRIVATE_PATH := $(LOCAL_PATH)
-$(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@
-$(GEN): $(testimage_out_path)/% : bootable/recovery/%
- $(transform-generated-source)
-LOCAL_GENERATED_SOURCES += $(GEN)
+# $(GEN): PRIVATE_PATH := $(LOCAL_PATH)
+# $(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@
+# $(GEN): $(testimage_out_path)/% : bootable/recovery/%
+# $(transform-generated-source)
+# LOCAL_GENERATED_SOURCES += $(GEN)
-include $(BUILD_NATIVE_TEST)
+# include $(BUILD_NATIVE_TEST)
# Component tests
-include $(CLEAR_VARS)
-LOCAL_CFLAGS := \
- -Wall \
- -Werror \
- -D_FILE_OFFSET_BITS=64
+# include $(CLEAR_VARS)
+# LOCAL_CFLAGS := \
+# -Wall \
+# -Werror \
+# -D_FILE_OFFSET_BITS=64
-ifeq ($(AB_OTA_UPDATER),true)
-LOCAL_CFLAGS += -DAB_OTA_UPDATER=1
-endif
+# ifeq ($(AB_OTA_UPDATER),true)
+# LOCAL_CFLAGS += -DAB_OTA_UPDATER=1
+# endif
-ifeq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),true)
-LOCAL_CFLAGS += -DPRODUCT_SUPPORTS_VERITY=1
-endif
+# ifeq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),true)
+# LOCAL_CFLAGS += -DPRODUCT_SUPPORTS_VERITY=1
+# endif
-ifeq ($(BOARD_AVB_ENABLE),true)
-LOCAL_CFLAGS += -DBOARD_AVB_ENABLE=1
-endif
+# ifeq ($(BOARD_AVB_ENABLE),true)
+# LOCAL_CFLAGS += -DBOARD_AVB_ENABLE=1
+# endif
-LOCAL_MODULE := recovery_component_test
-LOCAL_COMPATIBILITY_SUITE := device-tests
-LOCAL_C_INCLUDES := $(commands_recovery_local_path)
-LOCAL_SRC_FILES := \
- component/applypatch_test.cpp \
- component/bootloader_message_test.cpp \
- component/edify_test.cpp \
- component/imgdiff_test.cpp \
- component/install_test.cpp \
- component/sideload_test.cpp \
- component/uncrypt_test.cpp \
- component/updater_test.cpp \
- component/update_verifier_test.cpp \
- component/verifier_test.cpp
+# LOCAL_MODULE := recovery_component_test
+# LOCAL_COMPATIBILITY_SUITE := device-tests
+# LOCAL_C_INCLUDES := $(commands_recovery_local_path)
+# LOCAL_SRC_FILES := \
+# component/applypatch_test.cpp \
+# component/bootloader_message_test.cpp \
+# component/edify_test.cpp \
+# component/imgdiff_test.cpp \
+# component/install_test.cpp \
+# component/sideload_test.cpp \
+# component/uncrypt_test.cpp \
+# component/updater_test.cpp \
+# component/update_verifier_test.cpp \
+# component/verifier_test.cpp
-LOCAL_SHARED_LIBRARIES := \
- libhidlbase
+# LOCAL_SHARED_LIBRARIES := \
+# libhidlbase
-tune2fs_static_libraries := \
- libext2_com_err \
- libext2_blkid \
- libext2_quota \
- libext2_uuid \
- libext2_e2p \
- libext2fs
+# tune2fs_static_libraries := \
+# libext2_com_err \
+# libext2_blkid \
+# libext2_quota \
+# libext2_uuid \
+# libext2_e2p \
+# libext2fs
-LOCAL_STATIC_LIBRARIES := \
- libapplypatch_modes \
- libapplypatch \
- libedify \
- libimgdiff \
- libimgpatch \
- libbsdiff \
- libbspatch \
- libfusesideload \
- libotafault \
- librecovery \
- libupdater \
- libbootloader_message \
- libverifier \
- libotautil \
- libmounts \
- libupdate_verifier \
- libdivsufsort \
- libdivsufsort64 \
- libfs_mgr \
- libvintf_recovery \
- libvintf \
- libhidl-gen-utils \
- libtinyxml2 \
- libselinux \
- libext4_utils \
- libsparse \
- libcrypto_utils \
- libcrypto \
- libbz \
- libziparchive \
- liblog \
- libutils \
- libz \
- libbase \
- libtune2fs \
- libfec \
- libfec_rs \
- libsquashfs_utils \
- libcutils \
- libbrotli \
- libBionicGtestMain \
- $(tune2fs_static_libraries)
+# LOCAL_STATIC_LIBRARIES := \
+# libapplypatch_modes \
+# libapplypatch \
+# libedify \
+# libimgdiff \
+# libimgpatch \
+# libbsdiff \
+# libbspatch \
+# libfusesideload \
+# libotafault \
+# librecovery \
+# libupdater \
+# libbootloader_message \
+# libverifier \
+# libotautil \
+# libmounts \
+# libupdate_verifier \
+# libdivsufsort \
+# libdivsufsort64 \
+# libfs_mgr \
+# libvintf_recovery \
+# libvintf \
+# libhidl-gen-utils \
+# libtinyxml2 \
+# libselinux \
+# libext4_utils \
+# libsparse \
+# libcrypto_utils \
+# libcrypto \
+# libbz \
+# libziparchive \
+# liblog \
+# libutils \
+# libz \
+# libbase \
+# libtune2fs \
+# libfec \
+# libfec_rs \
+# libsquashfs_utils \
+# libcutils \
+# libbrotli \
+# libBionicGtestMain \
+# $(tune2fs_static_libraries)
-testdata_files := $(call find-subdir-files, testdata/*)
+# testdata_files := $(call find-subdir-files, testdata/*)
-# The testdata files that will go to $OUT/data/nativetest/recovery.
-testdata_out_path := $(TARGET_OUT_DATA)/nativetest/recovery
-GEN := $(addprefix $(testdata_out_path)/, $(testdata_files))
-$(GEN): PRIVATE_PATH := $(LOCAL_PATH)
-$(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@
-$(GEN): $(testdata_out_path)/% : $(LOCAL_PATH)/%
- $(transform-generated-source)
-LOCAL_GENERATED_SOURCES += $(GEN)
+# # The testdata files that will go to $OUT/data/nativetest/recovery.
+# testdata_out_path := $(TARGET_OUT_DATA)/nativetest/recovery
+# GEN := $(addprefix $(testdata_out_path)/, $(testdata_files))
+# $(GEN): PRIVATE_PATH := $(LOCAL_PATH)
+# $(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@
+# $(GEN): $(testdata_out_path)/% : $(LOCAL_PATH)/%
+# $(transform-generated-source)
+# LOCAL_GENERATED_SOURCES += $(GEN)
-# A copy of the testdata to be packed into continuous_native_tests.zip.
-testdata_continuous_zip_prefix := \
- $(call intermediates-dir-for,PACKAGING,recovery_component_test)/DATA
-testdata_continuous_zip_path := $(testdata_continuous_zip_prefix)/nativetest/recovery
-GEN := $(addprefix $(testdata_continuous_zip_path)/, $(testdata_files))
-$(GEN): PRIVATE_PATH := $(LOCAL_PATH)
-$(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@
-$(GEN): $(testdata_continuous_zip_path)/% : $(LOCAL_PATH)/%
- $(transform-generated-source)
-LOCAL_GENERATED_SOURCES += $(GEN)
-LOCAL_PICKUP_FILES := $(testdata_continuous_zip_prefix)
+# # A copy of the testdata to be packed into continuous_native_tests.zip.
+# testdata_continuous_zip_prefix := \
+# $(call intermediates-dir-for,PACKAGING,recovery_component_test)/DATA
+# testdata_continuous_zip_path := $(testdata_continuous_zip_prefix)/nativetest/recovery
+# GEN := $(addprefix $(testdata_continuous_zip_path)/, $(testdata_files))
+# $(GEN): PRIVATE_PATH := $(LOCAL_PATH)
+# $(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@
+# $(GEN): $(testdata_continuous_zip_path)/% : $(LOCAL_PATH)/%
+# $(transform-generated-source)
+# LOCAL_GENERATED_SOURCES += $(GEN)
+# LOCAL_PICKUP_FILES := $(testdata_continuous_zip_prefix)
-include $(BUILD_NATIVE_TEST)
+# include $(BUILD_NATIVE_TEST)
# Host tests
-include $(CLEAR_VARS)
-LOCAL_CFLAGS := -Wall -Werror
-LOCAL_MODULE := recovery_host_test
-LOCAL_MODULE_HOST_OS := linux
-LOCAL_C_INCLUDES := bootable/recovery
-LOCAL_SRC_FILES := \
- component/imgdiff_test.cpp
-LOCAL_STATIC_LIBRARIES := \
- libimgdiff \
- libimgpatch \
- libotautil \
- libbsdiff \
- libbspatch \
- libziparchive \
- libutils \
- libbase \
- libcrypto \
- libbrotli \
- libbz \
- libdivsufsort64 \
- libdivsufsort \
- libz \
- libBionicGtestMain
-LOCAL_SHARED_LIBRARIES := \
- liblog
-include $(BUILD_HOST_NATIVE_TEST)
+# include $(CLEAR_VARS)
+# LOCAL_CFLAGS := -Wall -Werror
+# LOCAL_MODULE := recovery_host_test
+# LOCAL_MODULE_HOST_OS := linux
+# LOCAL_C_INCLUDES := bootable/recovery
+# LOCAL_SRC_FILES := \
+# component/imgdiff_test.cpp
+# LOCAL_STATIC_LIBRARIES := \
+# libimgdiff \
+# libimgpatch \
+# libotautil \
+# libbsdiff \
+# libbspatch \
+# libziparchive \
+# libutils \
+# libbase \
+# libcrypto \
+# libbrotli \
+# libbz \
+# libdivsufsort64 \
+# libdivsufsort \
+# libz \
+# libBionicGtestMain
+# LOCAL_SHARED_LIBRARIES := \
+# liblog
+# include $(BUILD_HOST_NATIVE_TEST)
diff --git a/tests/unit/zip_test.cpp b/tests/unit/zip_test.cpp
old mode 100644
new mode 100755
index f41a405..1104978
--- a/tests/unit/zip_test.cpp
+++ b/tests/unit/zip_test.cpp
@@ -22,11 +22,6 @@
#include <android-base/file.h>
#include <gtest/gtest.h>
-<<<<<<< HEAD
-#include <otautil/SysUtil.h>
-#include <otautil/ZipUtil.h>
-=======
->>>>>>> android-10.0.0_r25
#include <ziparchive/zip_archive.h>
#include "common/test_constants.h"
diff --git a/toolbox/Android.mk b/toolbox/Android.mk
old mode 100644
new mode 100755
index 9267438..4a2546e
--- a/toolbox/Android.mk
+++ b/toolbox/Android.mk
@@ -164,7 +164,9 @@
# Special rules for 9.0
OUR_TOOLS += getevent
LOCAL_C_INCLUDES += $(TWRP_TOOLBOX_PATH)
- LOCAL_WHOLE_STATIC_LIBRARIES += libtoolbox_dd
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 29; echo $$?),0)
+ LOCAL_WHOLE_STATIC_LIBRARIES += libtoolbox_dd
+ endif
ifneq ($(TW_USE_TOOLBOX), true)
OUR_TOOLS += newfs_msdos
@@ -286,7 +288,7 @@
TOOLS_H := $(intermediates)/tools.h
$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
-$(TOOLS_H):
+$(TOOLS_H):
$(transform-generated-source)
# toolbox setenforce is used during init in non-symlink form, so it was
diff --git a/toybox/Android.mk b/toybox/Android.mk
old mode 100644
new mode 100755
index 5f6edec..0fb345d
--- a/toybox/Android.mk
+++ b/toybox/Android.mk
@@ -553,6 +553,10 @@
stop \
stty
endif
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 28; echo $$?),0)
+ALL_TOOLS += \
+ dd
+endif
endif
# Account for master branch changes pulld into CM14.1
ifneq ($(CM_BUILD),)
@@ -569,7 +573,9 @@
endif
# Install the symlinks.
-LOCAL_POST_INSTALL_CMD := $(hide) $(foreach t,$(ALL_TOOLS),ln -sf toybox $(TARGET_RECOVERY_ROOT_OUT)/sbin/$(t);)
+# LOCAL_POST_INSTALL_CMD := $(hide) $(foreach t,$(ALL_TOOLS),ln -sf toybox $(TARGET_RECOVERY_ROOT_OUT)/sbin/$(t);)
+LOCAL_POST_INSTALL_CMD := $(foreach t,$(ALL_TOOLS),ln -sf toybox $(TARGET_RECOVERY_ROOT_OUT)/sbin/$(t);)
+
include $(BUILD_EXECUTABLE)
diff --git a/twinstall.cpp b/twinstall.cpp
index d659b47..fb639a7 100755
--- a/twinstall.cpp
+++ b/twinstall.cpp
@@ -41,14 +41,16 @@
#ifdef USE_MINZIP
#include "minzip/SysUtil.h"
#else
-#include "otautil/SysUtil.h"
+#include "otautil/sysutil.h"
#include <ziparchive/zip_archive.h>
#endif
#include "zipwrap.hpp"
#ifdef USE_OLD_VERIFIER
#include "verifier24/verifier.h"
+#elif USE_28_VERIFIER
+#include "verifier28/verifier.h"
#else
-#include "verifier.h"
+#include "install/verifier.h"
#endif
#include "variables.h"
#include "data.hpp"
diff --git a/twinstall.h b/twinstall.h
old mode 100644
new mode 100755
diff --git a/twrp.cpp b/twrp.cpp
index dac0093..8c6dcf8 100755
--- a/twrp.cpp
+++ b/twrp.cpp
@@ -47,7 +47,7 @@
#include "variables.h"
#include "twrpAdbBuFifo.hpp"
#ifdef TW_USE_NEW_MINADBD
-#include "minadbd/minadbd.h"
+// #include "minadbd/minadbd.h"
#else
extern "C" {
#include "minadbd21/adb.h"
@@ -84,7 +84,7 @@
property_set("ctl.stop", "adbd");
#ifdef TW_USE_NEW_MINADBD
//adb_server_main(0, DEFAULT_ADB_PORT, -1); TODO fix this for android8
- minadbd_main();
+ // minadbd_main();
#else
adb_main(argv[2]);
#endif
@@ -127,6 +127,7 @@
gui_loadResources();
bool Shutdown = false;
+ bool SkipDecryption = false;
string Send_Intent = "";
{
TWPartition* misc = PartitionManager.Find_Partition_By_Path("/misc");
@@ -161,6 +162,9 @@
string ORSCommand = "install ";
ORSCommand.append(ptr);
+ // If we have a map of blocks we don't need to mount data.
+ SkipDecryption = *ptr == '@';
+
if (!OpenRecoveryScript::Insert_ORS_Command(ORSCommand))
break;
} else
@@ -228,13 +232,17 @@
// Offer to decrypt if the device is encrypted
if (DataManager::GetIntValue(TW_IS_ENCRYPTED) != 0) {
- LOGINFO("Is encrypted, do decrypt page first\n");
- if (gui_startPage("decrypt", 1, 1) != 0) {
- LOGERR("Failed to start decrypt GUI page.\n");
+ if (SkipDecryption) {
+ LOGINFO("Skipping decryption\n");
} else {
- // Check for and load custom theme if present
- TWFunc::check_selinux_support();
- gui_loadCustomResources();
+ LOGINFO("Is encrypted, do decrypt page first\n");
+ if (gui_startPage("decrypt", 1, 1) != 0) {
+ LOGERR("Failed to start decrypt GUI page.\n");
+ } else {
+ // Check for and load custom theme if present
+ TWFunc::check_selinux_support();
+ gui_loadCustomResources();
+ }
}
} else if (datamedia) {
TWFunc::check_selinux_support();
@@ -258,8 +266,7 @@
// Run any outstanding OpenRecoveryScript
std::string cacheDir = TWFunc::get_cache_dir();
std::string orsFile = cacheDir + "/recovery/openrecoveryscript";
-
- if (TWFunc::Path_Exists(SCRIPT_FILE_TMP) || (DataManager::GetIntValue(TW_IS_ENCRYPTED) == 0 && TWFunc::Path_Exists(orsFile))) {
+ if ((DataManager::GetIntValue(TW_IS_ENCRYPTED) == 0 || SkipDecryption) && (TWFunc::Path_Exists(SCRIPT_FILE_TMP) || TWFunc::Path_Exists(orsFile))) {
OpenRecoveryScript::Run_OpenRecoveryScript();
}
diff --git a/updater/Android.mk b/updater/Android.mk
old mode 100644
new mode 100755
index d77fdc2..23dc650
--- a/updater/Android.mk
+++ b/updater/Android.mk
@@ -57,40 +57,6 @@
libtune2fs \
$(tune2fs_static_libraries)
-<<<<<<< HEAD
-# libupdater (static library)
-# ===============================
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libupdater
-
-LOCAL_SRC_FILES := \
- install.cpp \
- blockimg.cpp
-
-LOCAL_C_INCLUDES := \
- $(LOCAL_PATH)/.. \
- $(LOCAL_PATH)/include \
- external/e2fsprogs/misc
-
-LOCAL_CFLAGS := \
- -Wall \
- -Werror
-
-ifeq ($(BOARD_SUPPRESS_EMMC_WIPE),true)
- LOCAL_CFLAGS += -DSUPPRESS_EMMC_WIPE
-endif
-
-LOCAL_EXPORT_C_INCLUDE_DIRS := \
- $(LOCAL_PATH)/include
-
-LOCAL_STATIC_LIBRARIES := \
- $(updater_common_static_libraries)
-
-include $(BUILD_STATIC_LIBRARY)
-
-=======
->>>>>>> android-10.0.0_r25
# updater (static executable)
# ===============================
include $(CLEAR_VARS)
diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp
old mode 100644
new mode 100755
index 9750a20..ef33ab2
--- a/updater/blockimg.cpp
+++ b/updater/blockimg.cpp
@@ -1540,11 +1540,6 @@
return -1;
}
-<<<<<<< HEAD
-#ifndef SUPPRESS_EMMC_WIPE
- if (ioctl(params.fd, BLKDISCARD, &blocks) == -1) {
- PLOG(ERROR) << "BLKDISCARD ioctl failed";
-=======
for (size_t i = begin; i < end; i++) {
if (!android::base::ReadFully(params.fd, buffer, BLOCKSIZE)) {
failure_type = errno == EIO ? kEioFailure : kFreadFailure;
@@ -1554,7 +1549,6 @@
if (!builder.Update(reinterpret_cast<unsigned char*>(buffer), BLOCKSIZE)) {
LOG(ERROR) << "Failed to update hash tree builder";
->>>>>>> android-10.0.0_r25
return -1;
}
#endif
diff --git a/updater/install.cpp b/updater/install.cpp
old mode 100644
new mode 100755
index 28bfee9..70092c5
--- a/updater/install.cpp
+++ b/updater/install.cpp
@@ -57,47 +57,6 @@
#include <ziparchive/zip_archive.h>
#include "edify/expr.h"
-<<<<<<< HEAD
-#include "mounts.h"
-
-#include "applypatch/applypatch.h"
-#include "flashutils/flashutils.h"
-#include "install.h"
-#ifdef HAVE_LIBTUNE2FS
-#include "tune2fs.h"
-#endif
-
-#ifdef USE_EXT4
-#include "make_ext4fs.h"
-#include "wipe.h"
-#endif
-
-#include "otautil/ZipUtil.h"
-#include "otafault/ota_io.h"
-#include "otautil/DirUtil.h"
-=======
-#include "otautil/dirutil.h"
->>>>>>> android-10.0.0_r25
-#include "otautil/error_code.h"
-#include "otautil/mounts.h"
-#include "otautil/print_sha1.h"
-#include "otautil/sysutil.h"
-#include "updater/updater.h"
-
-// Send over the buffer to recovery though the command pipe.
-static void uiPrint(State* state, const std::string& buffer) {
- UpdaterInfo* ui = static_cast<UpdaterInfo*>(state->cookie);
-
- // "line1\nline2\n" will be split into 3 tokens: "line1", "line2" and "".
- // So skip sending empty strings to UI.
- std::vector<std::string> lines = android::base::Split(buffer, "\n");
- for (auto& line : lines) {
- if (!line.empty()) {
- fprintf(ui->cmd_pipe, "ui_print %s\n", line.c_str());
- }
- }
-
- // On the updater side, we need to dump the contents to stderr (which has
// been redirected to the log file). Because the recovery will only print
// the contents to screen when processing pipe command ui_print.
LOG(INFO) << buffer;
@@ -1458,11 +1417,6 @@
RegisterFunction("wipe_block_device", WipeBlockDeviceFn);
RegisterFunction("read_file", ReadFileFn);
-<<<<<<< HEAD
- RegisterFunction("sha1_check", Sha1CheckFn);
- RegisterFunction("rename", RenameFn);
-=======
->>>>>>> android-10.0.0_r25
RegisterFunction("write_value", WriteValueFn);
RegisterFunction("wipe_cache", WipeCacheFn);
diff --git a/updater/updater.cpp b/updater/updater.cpp
old mode 100644
new mode 100755
index fd66e93..bbdf744
--- a/updater/updater.cpp
+++ b/updater/updater.cpp
@@ -48,14 +48,6 @@
// (Note it's "updateR-script", not the older "update-script".)
static constexpr const char* SCRIPT_NAME = "META-INF/com/google/android/updater-script";
-<<<<<<< HEAD
-#define SELINUX_CONTEXTS_ZIP "file_contexts"
-#define SELINUX_CONTEXTS_TMP "/tmp/file_contexts"
-
-extern bool have_eio_error;
-
-=======
->>>>>>> android-10.0.0_r25
struct selabel_handle *sehandle;
static void UpdaterLogger(android::base::LogId /* id */, android::base::LogSeverity /* severity */,
diff --git a/updater_sample/proguard.flags b/updater_sample/proguard.flags
old mode 100644
new mode 100755
index 6f52193..97ab534
--- a/updater_sample/proguard.flags
+++ b/updater_sample/proguard.flags
@@ -22,17 +22,3 @@
public <init>(java.lang.String, java.lang.String, int);
}
-<<<<<<< HEAD:tools/dumpkey/Android.mk
-# Pre Oreo trees have dumpkey defined elsewhere in the tree
-ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 26; echo $$?),0)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := dumpkey
-LOCAL_SRC_FILES := DumpPublicKey.java
-LOCAL_JAR_MANIFEST := DumpPublicKey.mf
-LOCAL_STATIC_JAVA_LIBRARIES := bouncycastle-host
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-endif
-=======
->>>>>>> android-10.0.0_r25:updater_sample/proguard.flags
diff --git a/verifier28/asn1_decoder.cpp b/verifier28/asn1_decoder.cpp
new file mode 100644
index 0000000..285214f
--- /dev/null
+++ b/verifier28/asn1_decoder.cpp
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "asn1_decoder.h"
+
+#include <stdint.h>
+
+int asn1_context::peek_byte() const {
+ if (length_ == 0) {
+ return -1;
+ }
+ return *p_;
+}
+
+int asn1_context::get_byte() {
+ if (length_ == 0) {
+ return -1;
+ }
+
+ int byte = *p_;
+ p_++;
+ length_--;
+ return byte;
+}
+
+bool asn1_context::skip_bytes(size_t num_skip) {
+ if (length_ < num_skip) {
+ return false;
+ }
+ p_ += num_skip;
+ length_ -= num_skip;
+ return true;
+}
+
+bool asn1_context::decode_length(size_t* out_len) {
+ int num_octets = get_byte();
+ if (num_octets == -1) {
+ return false;
+ }
+ if ((num_octets & 0x80) == 0x00) {
+ *out_len = num_octets;
+ return true;
+ }
+ num_octets &= kMaskTag;
+ if (static_cast<size_t>(num_octets) >= sizeof(size_t)) {
+ return false;
+ }
+ size_t length = 0;
+ for (int i = 0; i < num_octets; ++i) {
+ int byte = get_byte();
+ if (byte == -1) {
+ return false;
+ }
+ length <<= 8;
+ length += byte;
+ }
+ *out_len = length;
+ return true;
+}
+
+/**
+ * Returns the constructed type and advances the pointer. E.g. A0 -> 0
+ */
+asn1_context* asn1_context::asn1_constructed_get() {
+ int type = get_byte();
+ if (type == -1 || (type & kMaskConstructed) != kTagConstructed) {
+ return nullptr;
+ }
+ size_t length;
+ if (!decode_length(&length) || length > length_) {
+ return nullptr;
+ }
+ asn1_context* app_ctx = new asn1_context(p_, length);
+ app_ctx->app_type_ = type & kMaskAppType;
+ return app_ctx;
+}
+
+bool asn1_context::asn1_constructed_skip_all() {
+ int byte = peek_byte();
+ while (byte != -1 && (byte & kMaskConstructed) == kTagConstructed) {
+ skip_bytes(1);
+ size_t length;
+ if (!decode_length(&length) || !skip_bytes(length)) {
+ return false;
+ }
+ byte = peek_byte();
+ }
+ return byte != -1;
+}
+
+int asn1_context::asn1_constructed_type() const {
+ return app_type_;
+}
+
+asn1_context* asn1_context::asn1_sequence_get() {
+ if ((get_byte() & kMaskTag) != kTagSequence) {
+ return nullptr;
+ }
+ size_t length;
+ if (!decode_length(&length) || length > length_) {
+ return nullptr;
+ }
+ return new asn1_context(p_, length);
+}
+
+asn1_context* asn1_context::asn1_set_get() {
+ if ((get_byte() & kMaskTag) != kTagSet) {
+ return nullptr;
+ }
+ size_t length;
+ if (!decode_length(&length) || length > length_) {
+ return nullptr;
+ }
+ return new asn1_context(p_, length);
+}
+
+bool asn1_context::asn1_sequence_next() {
+ size_t length;
+ if (get_byte() == -1 || !decode_length(&length) || !skip_bytes(length)) {
+ return false;
+ }
+ return true;
+}
+
+bool asn1_context::asn1_oid_get(const uint8_t** oid, size_t* length) {
+ if (get_byte() != kTagOid) {
+ return false;
+ }
+ if (!decode_length(length) || *length == 0 || *length > length_) {
+ return false;
+ }
+ *oid = p_;
+ return true;
+}
+
+bool asn1_context::asn1_octet_string_get(const uint8_t** octet_string, size_t* length) {
+ if (get_byte() != kTagOctetString) {
+ return false;
+ }
+ if (!decode_length(length) || *length == 0 || *length > length_) {
+ return false;
+ }
+ *octet_string = p_;
+ return true;
+}
diff --git a/verifier28/asn1_decoder.h b/verifier28/asn1_decoder.h
new file mode 100644
index 0000000..3e99211
--- /dev/null
+++ b/verifier28/asn1_decoder.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ASN1_DECODER_H_
+#define ASN1_DECODER_H_
+
+#include <stdint.h>
+
+class asn1_context {
+ public:
+ asn1_context(const uint8_t* buffer, size_t length) : p_(buffer), length_(length), app_type_(0) {}
+ int asn1_constructed_type() const;
+ asn1_context* asn1_constructed_get();
+ bool asn1_constructed_skip_all();
+ asn1_context* asn1_sequence_get();
+ asn1_context* asn1_set_get();
+ bool asn1_sequence_next();
+ bool asn1_oid_get(const uint8_t** oid, size_t* length);
+ bool asn1_octet_string_get(const uint8_t** octet_string, size_t* length);
+
+ private:
+ static constexpr int kMaskConstructed = 0xE0;
+ static constexpr int kMaskTag = 0x7F;
+ static constexpr int kMaskAppType = 0x1F;
+
+ static constexpr int kTagOctetString = 0x04;
+ static constexpr int kTagOid = 0x06;
+ static constexpr int kTagSequence = 0x30;
+ static constexpr int kTagSet = 0x31;
+ static constexpr int kTagConstructed = 0xA0;
+
+ int peek_byte() const;
+ int get_byte();
+ bool skip_bytes(size_t num_skip);
+ bool decode_length(size_t* out_len);
+
+ const uint8_t* p_;
+ size_t length_;
+ int app_type_;
+};
+
+#endif /* ASN1_DECODER_H_ */
diff --git a/verifier28/verifier.cpp b/verifier28/verifier.cpp
new file mode 100644
index 0000000..283e043
--- /dev/null
+++ b/verifier28/verifier.cpp
@@ -0,0 +1,553 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "verifier.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <algorithm>
+#include <functional>
+#include <memory>
+#include <vector>
+
+#include <android-base/logging.h>
+#include <openssl/bn.h>
+#include <openssl/ecdsa.h>
+#include <openssl/obj_mac.h>
+
+#include "asn1_decoder.h"
+#include "otautil/print_sha1.h"
+
+static constexpr size_t MiB = 1024 * 1024;
+
+/*
+ * Simple version of PKCS#7 SignedData extraction. This extracts the
+ * signature OCTET STRING to be used for signature verification.
+ *
+ * For full details, see http://www.ietf.org/rfc/rfc3852.txt
+ *
+ * The PKCS#7 structure looks like:
+ *
+ * SEQUENCE (ContentInfo)
+ * OID (ContentType)
+ * [0] (content)
+ * SEQUENCE (SignedData)
+ * INTEGER (version CMSVersion)
+ * SET (DigestAlgorithmIdentifiers)
+ * SEQUENCE (EncapsulatedContentInfo)
+ * [0] (CertificateSet OPTIONAL)
+ * [1] (RevocationInfoChoices OPTIONAL)
+ * SET (SignerInfos)
+ * SEQUENCE (SignerInfo)
+ * INTEGER (CMSVersion)
+ * SEQUENCE (SignerIdentifier)
+ * SEQUENCE (DigestAlgorithmIdentifier)
+ * SEQUENCE (SignatureAlgorithmIdentifier)
+ * OCTET STRING (SignatureValue)
+ */
+static bool read_pkcs7(const uint8_t* pkcs7_der, size_t pkcs7_der_len,
+ std::vector<uint8_t>* sig_der) {
+ CHECK(sig_der != nullptr);
+ sig_der->clear();
+
+ asn1_context ctx(pkcs7_der, pkcs7_der_len);
+
+ std::unique_ptr<asn1_context> pkcs7_seq(ctx.asn1_sequence_get());
+ if (pkcs7_seq == nullptr || !pkcs7_seq->asn1_sequence_next()) {
+ return false;
+ }
+
+ std::unique_ptr<asn1_context> signed_data_app(pkcs7_seq->asn1_constructed_get());
+ if (signed_data_app == nullptr) {
+ return false;
+ }
+
+ std::unique_ptr<asn1_context> signed_data_seq(signed_data_app->asn1_sequence_get());
+ if (signed_data_seq == nullptr ||
+ !signed_data_seq->asn1_sequence_next() ||
+ !signed_data_seq->asn1_sequence_next() ||
+ !signed_data_seq->asn1_sequence_next() ||
+ !signed_data_seq->asn1_constructed_skip_all()) {
+ return false;
+ }
+
+ std::unique_ptr<asn1_context> sig_set(signed_data_seq->asn1_set_get());
+ if (sig_set == nullptr) {
+ return false;
+ }
+
+ std::unique_ptr<asn1_context> sig_seq(sig_set->asn1_sequence_get());
+ if (sig_seq == nullptr ||
+ !sig_seq->asn1_sequence_next() ||
+ !sig_seq->asn1_sequence_next() ||
+ !sig_seq->asn1_sequence_next() ||
+ !sig_seq->asn1_sequence_next()) {
+ return false;
+ }
+
+ const uint8_t* sig_der_ptr;
+ size_t sig_der_length;
+ if (!sig_seq->asn1_octet_string_get(&sig_der_ptr, &sig_der_length)) {
+ return false;
+ }
+
+ sig_der->resize(sig_der_length);
+ std::copy(sig_der_ptr, sig_der_ptr + sig_der_length, sig_der->begin());
+ return true;
+}
+
+/*
+ * Looks for an RSA signature embedded in the .ZIP file comment given the path to the zip. Verifies
+ * that it matches one of the given public keys. A callback function can be optionally provided for
+ * posting the progress.
+ *
+ * Returns VERIFY_SUCCESS or VERIFY_FAILURE (if any error is encountered or no key matches the
+ * signature).
+ */
+int verify_file(const unsigned char* addr, size_t length, const std::vector<Certificate>& keys,
+ const std::function<void(float)>& set_progress) {
+ if (set_progress) {
+ set_progress(0.0);
+ }
+
+ // An archive with a whole-file signature will end in six bytes:
+ //
+ // (2-byte signature start) $ff $ff (2-byte comment size)
+ //
+ // (As far as the ZIP format is concerned, these are part of the archive comment.) We start by
+ // reading this footer, this tells us how far back from the end we have to start reading to find
+ // the whole comment.
+
+#define FOOTER_SIZE 6
+
+ if (length < FOOTER_SIZE) {
+ LOG(ERROR) << "not big enough to contain footer";
+ return VERIFY_FAILURE;
+ }
+
+ const unsigned char* footer = addr + length - FOOTER_SIZE;
+
+ if (footer[2] != 0xff || footer[3] != 0xff) {
+ LOG(ERROR) << "footer is wrong";
+ return VERIFY_FAILURE;
+ }
+
+ size_t comment_size = footer[4] + (footer[5] << 8);
+ size_t signature_start = footer[0] + (footer[1] << 8);
+ LOG(INFO) << "comment is " << comment_size << " bytes; signature is " << signature_start
+ << " bytes from end";
+
+ if (signature_start > comment_size) {
+ LOG(ERROR) << "signature start: " << signature_start << " is larger than comment size: "
+ << comment_size;
+ return VERIFY_FAILURE;
+ }
+
+ if (signature_start <= FOOTER_SIZE) {
+ LOG(ERROR) << "Signature start is in the footer";
+ return VERIFY_FAILURE;
+ }
+
+#define EOCD_HEADER_SIZE 22
+
+ // The end-of-central-directory record is 22 bytes plus any comment length.
+ size_t eocd_size = comment_size + EOCD_HEADER_SIZE;
+
+ if (length < eocd_size) {
+ LOG(ERROR) << "not big enough to contain EOCD";
+ return VERIFY_FAILURE;
+ }
+
+ // Determine how much of the file is covered by the signature. This is everything except the
+ // signature data and length, which includes all of the EOCD except for the comment length field
+ // (2 bytes) and the comment data.
+ size_t signed_len = length - eocd_size + EOCD_HEADER_SIZE - 2;
+
+ const unsigned char* eocd = addr + length - eocd_size;
+
+ // If this is really is the EOCD record, it will begin with the magic number $50 $4b $05 $06.
+ if (eocd[0] != 0x50 || eocd[1] != 0x4b || eocd[2] != 0x05 || eocd[3] != 0x06) {
+ LOG(ERROR) << "signature length doesn't match EOCD marker";
+ return VERIFY_FAILURE;
+ }
+
+ for (size_t i = 4; i < eocd_size-3; ++i) {
+ if (eocd[i] == 0x50 && eocd[i+1] == 0x4b && eocd[i+2] == 0x05 && eocd[i+3] == 0x06) {
+ // If the sequence $50 $4b $05 $06 appears anywhere after the real one, libziparchive will
+ // find the later (wrong) one, which could be exploitable. Fail the verification if this
+ // sequence occurs anywhere after the real one.
+ LOG(ERROR) << "EOCD marker occurs after start of EOCD";
+ return VERIFY_FAILURE;
+ }
+ }
+
+ bool need_sha1 = false;
+ bool need_sha256 = false;
+ for (const auto& key : keys) {
+ switch (key.hash_len) {
+ case SHA_DIGEST_LENGTH: need_sha1 = true; break;
+ case SHA256_DIGEST_LENGTH: need_sha256 = true; break;
+ }
+ }
+
+ SHA_CTX sha1_ctx;
+ SHA256_CTX sha256_ctx;
+ SHA1_Init(&sha1_ctx);
+ SHA256_Init(&sha256_ctx);
+
+ double frac = -1.0;
+ size_t so_far = 0;
+ while (so_far < signed_len) {
+ // On a Nexus 5X, experiment showed 16MiB beat 1MiB by 6% faster for a
+ // 1196MiB full OTA and 60% for an 89MiB incremental OTA.
+ // http://b/28135231.
+ size_t size = std::min(signed_len - so_far, 16 * MiB);
+
+ if (need_sha1) SHA1_Update(&sha1_ctx, addr + so_far, size);
+ if (need_sha256) SHA256_Update(&sha256_ctx, addr + so_far, size);
+ so_far += size;
+
+ if (set_progress) {
+ double f = so_far / (double)signed_len;
+ if (f > frac + 0.02 || size == so_far) {
+ set_progress(f);
+ frac = f;
+ }
+ }
+ }
+
+ uint8_t sha1[SHA_DIGEST_LENGTH];
+ SHA1_Final(sha1, &sha1_ctx);
+ uint8_t sha256[SHA256_DIGEST_LENGTH];
+ SHA256_Final(sha256, &sha256_ctx);
+
+ const uint8_t* signature = eocd + eocd_size - signature_start;
+ size_t signature_size = signature_start - FOOTER_SIZE;
+
+ LOG(INFO) << "signature (offset: " << std::hex << (length - signature_start) << ", length: "
+ << signature_size << "): " << print_hex(signature, signature_size);
+
+ std::vector<uint8_t> sig_der;
+ if (!read_pkcs7(signature, signature_size, &sig_der)) {
+ LOG(ERROR) << "Could not find signature DER block";
+ return VERIFY_FAILURE;
+ }
+
+ // Check to make sure at least one of the keys matches the signature. Since any key can match,
+ // we need to try each before determining a verification failure has happened.
+ size_t i = 0;
+ for (const auto& key : keys) {
+ const uint8_t* hash;
+ int hash_nid;
+ switch (key.hash_len) {
+ case SHA_DIGEST_LENGTH:
+ hash = sha1;
+ hash_nid = NID_sha1;
+ break;
+ case SHA256_DIGEST_LENGTH:
+ hash = sha256;
+ hash_nid = NID_sha256;
+ break;
+ default:
+ continue;
+ }
+
+ // The 6 bytes is the "(signature_start) $ff $ff (comment_size)" that the signing tool appends
+ // after the signature itself.
+ if (key.key_type == Certificate::KEY_TYPE_RSA) {
+ if (!RSA_verify(hash_nid, hash, key.hash_len, sig_der.data(), sig_der.size(),
+ key.rsa.get())) {
+ LOG(INFO) << "failed to verify against RSA key " << i;
+ continue;
+ }
+
+ LOG(INFO) << "whole-file signature verified against RSA key " << i;
+ return VERIFY_SUCCESS;
+ } else if (key.key_type == Certificate::KEY_TYPE_EC && key.hash_len == SHA256_DIGEST_LENGTH) {
+ if (!ECDSA_verify(0, hash, key.hash_len, sig_der.data(), sig_der.size(), key.ec.get())) {
+ LOG(INFO) << "failed to verify against EC key " << i;
+ continue;
+ }
+
+ LOG(INFO) << "whole-file signature verified against EC key " << i;
+ return VERIFY_SUCCESS;
+ } else {
+ LOG(INFO) << "Unknown key type " << key.key_type;
+ }
+ i++;
+ }
+
+ if (need_sha1) {
+ LOG(INFO) << "SHA-1 digest: " << print_hex(sha1, SHA_DIGEST_LENGTH);
+ }
+ if (need_sha256) {
+ LOG(INFO) << "SHA-256 digest: " << print_hex(sha256, SHA256_DIGEST_LENGTH);
+ }
+ LOG(ERROR) << "failed to verify whole-file signature";
+ return VERIFY_FAILURE;
+}
+
+std::unique_ptr<RSA, RSADeleter> parse_rsa_key(FILE* file, uint32_t exponent) {
+ // Read key length in words and n0inv. n0inv is a precomputed montgomery
+ // parameter derived from the modulus and can be used to speed up
+ // verification. n0inv is 32 bits wide here, assuming the verification logic
+ // uses 32 bit arithmetic. However, BoringSSL may use a word size of 64 bits
+ // internally, in which case we don't have a valid n0inv. Thus, we just
+ // ignore the montgomery parameters and have BoringSSL recompute them
+ // internally. If/When the speedup from using the montgomery parameters
+ // becomes relevant, we can add more sophisticated code here to obtain a
+ // 64-bit n0inv and initialize the montgomery parameters in the key object.
+ uint32_t key_len_words = 0;
+ uint32_t n0inv = 0;
+ if (fscanf(file, " %i , 0x%x", &key_len_words, &n0inv) != 2) {
+ return nullptr;
+ }
+
+ if (key_len_words > 8192 / 32) {
+ LOG(ERROR) << "key length (" << key_len_words << ") too large";
+ return nullptr;
+ }
+
+ // Read the modulus.
+ std::unique_ptr<uint32_t[]> modulus(new uint32_t[key_len_words]);
+ if (fscanf(file, " , { %u", &modulus[0]) != 1) {
+ return nullptr;
+ }
+ for (uint32_t i = 1; i < key_len_words; ++i) {
+ if (fscanf(file, " , %u", &modulus[i]) != 1) {
+ return nullptr;
+ }
+ }
+
+ // Cconvert from little-endian array of little-endian words to big-endian
+ // byte array suitable as input for BN_bin2bn.
+ std::reverse((uint8_t*)modulus.get(),
+ (uint8_t*)(modulus.get() + key_len_words));
+
+ // The next sequence of values is the montgomery parameter R^2. Since we
+ // generally don't have a valid |n0inv|, we ignore this (see comment above).
+ uint32_t rr_value;
+ if (fscanf(file, " } , { %u", &rr_value) != 1) {
+ return nullptr;
+ }
+ for (uint32_t i = 1; i < key_len_words; ++i) {
+ if (fscanf(file, " , %u", &rr_value) != 1) {
+ return nullptr;
+ }
+ }
+ if (fscanf(file, " } } ") != 0) {
+ return nullptr;
+ }
+
+ // Initialize the key.
+ std::unique_ptr<RSA, RSADeleter> key(RSA_new());
+ if (!key) {
+ return nullptr;
+ }
+
+ key->n = BN_bin2bn((uint8_t*)modulus.get(),
+ key_len_words * sizeof(uint32_t), NULL);
+ if (!key->n) {
+ return nullptr;
+ }
+
+ key->e = BN_new();
+ if (!key->e || !BN_set_word(key->e, exponent)) {
+ return nullptr;
+ }
+
+ return key;
+}
+
+struct BNDeleter {
+ void operator()(BIGNUM* bn) const {
+ BN_free(bn);
+ }
+};
+
+std::unique_ptr<EC_KEY, ECKEYDeleter> parse_ec_key(FILE* file) {
+ uint32_t key_len_bytes = 0;
+ if (fscanf(file, " %i", &key_len_bytes) != 1) {
+ return nullptr;
+ }
+
+ std::unique_ptr<EC_GROUP, void (*)(EC_GROUP*)> group(
+ EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1), EC_GROUP_free);
+ if (!group) {
+ return nullptr;
+ }
+
+ // Verify that |key_len| matches the group order.
+ if (key_len_bytes != BN_num_bytes(EC_GROUP_get0_order(group.get()))) {
+ return nullptr;
+ }
+
+ // Read the public key coordinates. Note that the byte order in the file is
+ // little-endian, so we convert to big-endian here.
+ std::unique_ptr<uint8_t[]> bytes(new uint8_t[key_len_bytes]);
+ std::unique_ptr<BIGNUM, BNDeleter> point[2];
+ for (int i = 0; i < 2; ++i) {
+ unsigned int byte = 0;
+ if (fscanf(file, " , { %u", &byte) != 1) {
+ return nullptr;
+ }
+ bytes[key_len_bytes - 1] = byte;
+
+ for (size_t i = 1; i < key_len_bytes; ++i) {
+ if (fscanf(file, " , %u", &byte) != 1) {
+ return nullptr;
+ }
+ bytes[key_len_bytes - i - 1] = byte;
+ }
+
+ point[i].reset(BN_bin2bn(bytes.get(), key_len_bytes, nullptr));
+ if (!point[i]) {
+ return nullptr;
+ }
+
+ if (fscanf(file, " }") != 0) {
+ return nullptr;
+ }
+ }
+
+ if (fscanf(file, " } ") != 0) {
+ return nullptr;
+ }
+
+ // Create and initialize the key.
+ std::unique_ptr<EC_KEY, ECKEYDeleter> key(EC_KEY_new());
+ if (!key || !EC_KEY_set_group(key.get(), group.get()) ||
+ !EC_KEY_set_public_key_affine_coordinates(key.get(), point[0].get(),
+ point[1].get())) {
+ return nullptr;
+ }
+
+ return key;
+}
+
+// Reads a file containing one or more public keys as produced by
+// DumpPublicKey: this is an RSAPublicKey struct as it would appear
+// as a C source literal, eg:
+//
+// "{64,0xc926ad21,{1795090719,...,-695002876},{-857949815,...,1175080310}}"
+//
+// For key versions newer than the original 2048-bit e=3 keys
+// supported by Android, the string is preceded by a version
+// identifier, eg:
+//
+// "v2 {64,0xc926ad21,{1795090719,...,-695002876},{-857949815,...,1175080310}}"
+//
+// (Note that the braces and commas in this example are actual
+// characters the parser expects to find in the file; the ellipses
+// indicate more numbers omitted from this example.)
+//
+// The file may contain multiple keys in this format, separated by
+// commas. The last key must not be followed by a comma.
+//
+// A Certificate is a pair of an RSAPublicKey and a particular hash
+// (we support SHA-1 and SHA-256; we store the hash length to signify
+// which is being used). The hash used is implied by the version number.
+//
+// 1: 2048-bit RSA key with e=3 and SHA-1 hash
+// 2: 2048-bit RSA key with e=65537 and SHA-1 hash
+// 3: 2048-bit RSA key with e=3 and SHA-256 hash
+// 4: 2048-bit RSA key with e=65537 and SHA-256 hash
+// 5: 256-bit EC key using the NIST P-256 curve parameters and SHA-256 hash
+//
+// Returns true on success, and appends the found keys (at least one) to certs.
+// Otherwise returns false if the file failed to parse, or if it contains zero
+// keys. The contents in certs would be unspecified on failure.
+bool load_keys(const char* filename, std::vector<Certificate>& certs) {
+ std::unique_ptr<FILE, decltype(&fclose)> f(fopen(filename, "re"), fclose);
+ if (!f) {
+ PLOG(ERROR) << "error opening " << filename;
+ return false;
+ }
+
+ while (true) {
+ certs.emplace_back(0, Certificate::KEY_TYPE_RSA, nullptr, nullptr);
+ Certificate& cert = certs.back();
+ uint32_t exponent = 0;
+
+ char start_char;
+ if (fscanf(f.get(), " %c", &start_char) != 1) return false;
+ if (start_char == '{') {
+ // a version 1 key has no version specifier.
+ cert.key_type = Certificate::KEY_TYPE_RSA;
+ exponent = 3;
+ cert.hash_len = SHA_DIGEST_LENGTH;
+ } else if (start_char == 'v') {
+ int version;
+ if (fscanf(f.get(), "%d {", &version) != 1) return false;
+ switch (version) {
+ case 2:
+ cert.key_type = Certificate::KEY_TYPE_RSA;
+ exponent = 65537;
+ cert.hash_len = SHA_DIGEST_LENGTH;
+ break;
+ case 3:
+ cert.key_type = Certificate::KEY_TYPE_RSA;
+ exponent = 3;
+ cert.hash_len = SHA256_DIGEST_LENGTH;
+ break;
+ case 4:
+ cert.key_type = Certificate::KEY_TYPE_RSA;
+ exponent = 65537;
+ cert.hash_len = SHA256_DIGEST_LENGTH;
+ break;
+ case 5:
+ cert.key_type = Certificate::KEY_TYPE_EC;
+ cert.hash_len = SHA256_DIGEST_LENGTH;
+ break;
+ default:
+ return false;
+ }
+ }
+
+ if (cert.key_type == Certificate::KEY_TYPE_RSA) {
+ cert.rsa = parse_rsa_key(f.get(), exponent);
+ if (!cert.rsa) {
+ return false;
+ }
+
+ LOG(INFO) << "read key e=" << exponent << " hash=" << cert.hash_len;
+ } else if (cert.key_type == Certificate::KEY_TYPE_EC) {
+ cert.ec = parse_ec_key(f.get());
+ if (!cert.ec) {
+ return false;
+ }
+ } else {
+ LOG(ERROR) << "Unknown key type " << cert.key_type;
+ return false;
+ }
+
+ // if the line ends in a comma, this file has more keys.
+ int ch = fgetc(f.get());
+ if (ch == ',') {
+ // more keys to come.
+ continue;
+ } else if (ch == EOF) {
+ break;
+ } else {
+ LOG(ERROR) << "unexpected character between keys";
+ return false;
+ }
+ }
+ return true;
+}
diff --git a/verifier.h b/verifier28/verifier.h
similarity index 100%
rename from verifier.h
rename to verifier28/verifier.h