From 4387693302e65f9e35c74ca49ccf45d1043aa3e0 Mon Sep 17 00:00:00 2001 From: Jan Altensen Date: Tue, 17 May 2022 09:28:47 +0200 Subject: [PATCH] emerald: add custom service to update logo partition Change-Id: I57a2f5ff23027de4cae73549df60f8ffb9506ff4 --- emerald.mk | 4 +++ logo_updater/Android.mk | 31 ++++++++++++++++++ logo_updater/logo_updater.cpp | 61 +++++++++++++++++++++++++++++++++++ logo_updater/logo_updater.rc | 4 +++ sepolicy/file_contexts | 2 ++ sepolicy/logo_updater.te | 7 ++++ 6 files changed, 109 insertions(+) create mode 100644 logo_updater/Android.mk create mode 100644 logo_updater/logo_updater.cpp create mode 100644 logo_updater/logo_updater.rc create mode 100644 sepolicy/logo_updater.te diff --git a/emerald.mk b/emerald.mk index 6c1a62f..1e251c2 100644 --- a/emerald.mk +++ b/emerald.mk @@ -212,6 +212,10 @@ PRODUCT_COPY_FILES += \ PRODUCT_PACKAGES += \ android.hardware.keymaster@4.0 +# logo updater +PRODUCT_PACKAGES += \ + logo_updater + # NFC PRODUCT_PACKAGES += \ android.hardware.nfc@1.0 \ diff --git a/logo_updater/Android.mk b/logo_updater/Android.mk new file mode 100644 index 0000000..aef4494 --- /dev/null +++ b/logo_updater/Android.mk @@ -0,0 +1,31 @@ +# +# Copyright (C) 2022 ECORP SAS - Author: Jan Altensen +# +# 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 := logo_updater.cpp + +LOCAL_SHARED_LIBRARIES := libbase + +LOCAL_MODULE := logo_updater +LOCAL_INIT_RC := logo_updater.rc +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_MODULE_TAGS := optional +LOCAL_VENDOR_MODULE := true + +include $(BUILD_EXECUTABLE) diff --git a/logo_updater/logo_updater.cpp b/logo_updater/logo_updater.cpp new file mode 100644 index 0000000..f78c3eb --- /dev/null +++ b/logo_updater/logo_updater.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2022 ECORP SAS - Author: Jan Altensen + * + * 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 +#include +#include +#include +#include + +using namespace std; + +int main () { + std::fstream image("/vendor/firmware/logo.bin", std::ios::binary | std::ios::in); + if (image.fail()) { + // bail out if logo.bin can't be opened + return 0; + } + + std::vector image_data((std::istreambuf_iterator(image)), std::istreambuf_iterator()); + + std::fstream partition("/dev/block/platform/bootdevice/by-name/logo", std::ios::binary | std::ios::in | std::ios::out); + if (partition.fail()) { + // bail out if the logo partition can't be opened + image.close(); + return 0; + } + + std::vector partition_data((std::istreambuf_iterator(partition)), std::istreambuf_iterator()); + + // check if the partition contents is equal to the image + if (!std::equal(image_data.begin(), image_data.end(), partition_data.begin())) { + // seek to the beginning + partition.seekg(0); + + // write the logo.bin content to the partition + partition.write((const char*)&image_data[0], image_data.size()); + + // fill the rest of the partition with null bytes + vector temp(partition_data.size() - image_data.size()); + std::fill(temp.begin(), temp.begin()+(partition_data.size() - image_data.size()), 0x00); + partition.write((const char*)&temp[0], temp.size()); + } + + // close the partitions + image.close(); + partition.close(); + return 0; +} diff --git a/logo_updater/logo_updater.rc b/logo_updater/logo_updater.rc new file mode 100644 index 0000000..8ebb41f --- /dev/null +++ b/logo_updater/logo_updater.rc @@ -0,0 +1,4 @@ +service logo_updater /vendor/bin/hw/logo_updater + class late_start + group system root + oneshot diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts index b47b455..41f1b56 100755 --- a/sepolicy/file_contexts +++ b/sepolicy/file_contexts @@ -1 +1,3 @@ /dev/fpsensor u:object_r:fpsensor_fp_device:s0 + +/vendor/bin/hw/logo_updater u:object_r:logo_updater_exec:s0 diff --git a/sepolicy/logo_updater.te b/sepolicy/logo_updater.te new file mode 100644 index 0000000..a6ead89 --- /dev/null +++ b/sepolicy/logo_updater.te @@ -0,0 +1,7 @@ +type logo_updater, domain, mlstrustedsubject; +type logo_updater_exec, exec_type, file_type, vendor_file_type; +init_daemon_domain(logo_updater) + +allow logo_updater logo_block_device:blk_file rw_file_perms; +allow logo_updater vendor_file:file r_file_perms; +allow logo_updater block_device:dir search; -- GitLab