348 lines
12 KiB
C++
Executable File
348 lines
12 KiB
C++
Executable File
/*
|
|
* 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.
|
|
*/
|
|
|
|
#include "builtins.h"
|
|
#include "first_stage_init.h"
|
|
#include "init.h"
|
|
#include "selinux.h"
|
|
#include "subcontext.h"
|
|
#include "ueventd.h"
|
|
|
|
#include <android-base/logging.h>
|
|
|
|
/***rpdzkj**/
|
|
#include <functional>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <optional>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
#include <android-base/chrono_utils.h>
|
|
#include <android-base/file.h>
|
|
#include <android-base/logging.h>
|
|
#include <android-base/parseint.h>
|
|
#include <android-base/properties.h>
|
|
#include <android-base/stringprintf.h>
|
|
#include <android-base/strings.h>
|
|
#include <fs_avb/fs_avb.h>
|
|
#include <fs_mgr_vendor_overlay.h>
|
|
#include <keyutils.h>
|
|
#include <libavb/libavb.h>
|
|
#include <libgsi/libgsi.h>
|
|
#include <processgroup/processgroup.h>
|
|
#include <processgroup/setup.h>
|
|
#include <selinux/android.h>
|
|
|
|
#include "action_parser.h"
|
|
#include "builtins.h"
|
|
#include "epoll.h"
|
|
#include "first_stage_init.h"
|
|
#include "first_stage_mount.h"
|
|
#include "import_parser.h"
|
|
#include "keychords.h"
|
|
#include "lmkd_service.h"
|
|
#include "mount_handler.h"
|
|
#include "mount_namespace.h"
|
|
#include "property_service.h"
|
|
#include "proto_utils.h"
|
|
#include "reboot.h"
|
|
#include "reboot_utils.h"
|
|
#include "security.h"
|
|
#include "selabel.h"
|
|
#include "selinux.h"
|
|
#include "service.h"
|
|
#include "service_parser.h"
|
|
#include "sigchld_handler.h"
|
|
#include "subcontext.h"
|
|
#include "system/core/init/property_service.pb.h"
|
|
#include "util.h"
|
|
|
|
using namespace std::chrono_literals;
|
|
using namespace std::string_literals;
|
|
|
|
using android::base::boot_clock;
|
|
using android::base::ConsumePrefix;
|
|
using android::base::GetProperty;
|
|
using android::base::ReadFileToString;
|
|
using android::base::SetProperty;
|
|
using android::base::StringPrintf;
|
|
using android::base::Timer;
|
|
using android::base::Trim;
|
|
using android::fs_mgr::AvbHandle;
|
|
/***rpdzkj**/
|
|
|
|
|
|
#if __has_feature(address_sanitizer)
|
|
#include <sanitizer/asan_interface.h>
|
|
#elif __has_feature(hwaddress_sanitizer)
|
|
#include <sanitizer/hwasan_interface.h>
|
|
#endif
|
|
|
|
#if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer)
|
|
// Load asan.options if it exists since these are not yet in the environment.
|
|
// Always ensure detect_container_overflow=0 as there are false positives with this check.
|
|
// Always ensure abort_on_error=1 to ensure we reboot to bootloader for development builds.
|
|
extern "C" const char* __asan_default_options() {
|
|
return "include_if_exists=/system/asan.options:detect_container_overflow=0:abort_on_error=1";
|
|
}
|
|
|
|
__attribute__((no_sanitize("address", "memory", "thread", "undefined"))) extern "C" void
|
|
__sanitizer_report_error_summary(const char* summary) {
|
|
LOG(ERROR) << "Init (error summary): " << summary;
|
|
}
|
|
|
|
__attribute__((no_sanitize("address", "memory", "thread", "undefined"))) static void
|
|
AsanReportCallback(const char* str) {
|
|
LOG(ERROR) << "Init: " << str;
|
|
}
|
|
#endif
|
|
|
|
using namespace android::init;
|
|
|
|
int dts2prop(char* dts_path,char* prop_name) {
|
|
char s[64] ={'\0'};
|
|
|
|
FILE *fp = fopen(dts_path, "r" );
|
|
if(fp==NULL){
|
|
LOG(INFO) << "rpdzkj read rpdzkj_config dts fail," << dts_path;
|
|
SetProperty(prop_name, "0");
|
|
}else{
|
|
fgets(s, sizeof(s), fp);
|
|
fclose(fp);
|
|
LOG(INFO) << "rpdzkj read rpdzkj_config dts," << prop_name << "=" << s;
|
|
SetProperty(prop_name, s);
|
|
memset(s,'\0',sizeof(s));
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int lcd2prop(char* dts_path,char* prop_name) {
|
|
char s[64] ={'\0'};
|
|
|
|
FILE *fp = fopen(dts_path, "r" );
|
|
if(fp==NULL){
|
|
LOG(INFO) << "rpdzkj read rpdzkj_config dts fail," << dts_path;
|
|
SetProperty(prop_name, "0");
|
|
}else{
|
|
fgets(s, sizeof(s), fp);
|
|
fclose(fp);
|
|
LOG(INFO) << "rpdzkj read rpdzkj_config dts," << prop_name << "=" << s;
|
|
|
|
if(!strncmp("0",s,1)) {
|
|
SetProperty(prop_name, "ORIENTATION_0");
|
|
} else if(!strncmp("90",s,2)) {
|
|
SetProperty(prop_name, "ORIENTATION_90");
|
|
} else if(!strncmp("180",s,3)) {
|
|
SetProperty(prop_name, "ORIENTATION_180");
|
|
} else if(!strncmp("270",s,3)) {
|
|
SetProperty(prop_name, "ORIENTATION_270");
|
|
}
|
|
|
|
|
|
memset(s,'\0',sizeof(s));
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
int language2prop(char* dts_path,char* prop1_name,char* prop2_name,char* prop3_name) {
|
|
char s[64] ={'\0'};
|
|
char buf[3] ={'\0'};
|
|
FILE *fp = fopen(dts_path, "r" );
|
|
if(fp==NULL){
|
|
LOG(INFO) << "rpdzkj read rpdzkj_config dts fail," << dts_path;
|
|
SetProperty(prop1_name, "en");
|
|
SetProperty(prop2_name, "US");
|
|
SetProperty(prop3_name, "en-US");
|
|
|
|
}else{
|
|
fgets(s, sizeof(s), fp);
|
|
fclose(fp);
|
|
buf[0] = s[0];
|
|
buf[1] = s[1];
|
|
SetProperty(prop1_name, buf);
|
|
buf[0] = s[3];
|
|
buf[1] = s[4];
|
|
SetProperty(prop2_name, buf);
|
|
SetProperty(prop3_name, s);
|
|
memset(s,'\0',sizeof(s));
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
int bar2prop(char* dts_path,char* prop_name) {
|
|
char s[64] ={'\0'};
|
|
FILE *fp = fopen(dts_path, "r" );
|
|
if(fp==NULL){
|
|
LOG(INFO) << "rpdzkj read rpdzkj_config dts fail," << dts_path;
|
|
SetProperty(prop_name, "0");
|
|
}else{
|
|
fgets(s, sizeof(s), fp);
|
|
if( 0 == strncmp(s,"false",5)){
|
|
SetProperty(prop_name, "0");
|
|
}else if( 0 == strncmp(s,"true",4)){
|
|
SetProperty(prop_name, "1");
|
|
}
|
|
fclose(fp);
|
|
memset(s,'\0',sizeof(s));
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
void rp_change_properties() {
|
|
char system_rotate_dts[64] = "/proc/device-tree/rpdzkj_config/system_rotate";
|
|
char system_rotate_prop[64] = "ro.surface_flinger.primary_display_orientation";
|
|
|
|
char csi_camera_rotate_dts[64] = "/proc/device-tree/rpdzkj_config/csi_camera_rotate";
|
|
char csi_camera_rotate_prop[64] = "ro.sf.csi.camera.rotation";
|
|
|
|
char usb_camera_rotate_dts[64] = "/proc/device-tree/rpdzkj_config/usb_camera_rotate";
|
|
char usb_camera_rotate_prop[64] = "ro.sf.usb.camera.rotation";
|
|
|
|
|
|
char csi_camera_facing_dts[64] = "/proc/device-tree/rpdzkj_config/csi_camera_facing";
|
|
char csi_camera_facing_prop[64] = "ro.sf.csi.camera.facing";
|
|
|
|
char usb_camera_facing_dts[64] = "/proc/device-tree/rpdzkj_config/usb_camera_facing";
|
|
char usb_camera_facing_prop[64] = "ro.sf.usb.camera.facing";
|
|
|
|
|
|
char lcd_density_dts[64] = "/proc/device-tree/rpdzkj_config/lcd_density";
|
|
char lcd_density_prop[64] = "ro.sf.lcd_density";
|
|
|
|
char language_dts[64] = "/proc/device-tree/rpdzkj_config/language";
|
|
char language1_prop[64] = "persist.sys.language";
|
|
char language2_prop[64] = "persist.sys.country";
|
|
char language3_prop[64] = "persist.sys.localevar";
|
|
|
|
char time_zone_dts[64] = "/proc/device-tree/rpdzkj_config/time_zone";
|
|
char time_zone_prop[64] = "persist.sys.timezone";
|
|
|
|
char not_status_bar_dts[64] = "/proc/device-tree/rpdzkj_config/not_status_bar";
|
|
char not_status_bar_prop[64] = "ro.rpdzkj.no.statusbar";
|
|
|
|
char default_launcher_dts[64] = "/proc/device-tree/rpdzkj_config/default_launcher";
|
|
char default_launcher_prop[64] = "rpdzkj.default.launcher";
|
|
|
|
char has_root_dts[64] = "/proc/device-tree/rpdzkj_config/has_root";
|
|
char has_root_prop[64] = "rpdzkj.has.root";
|
|
|
|
char usb_not_permission_dts[64] = "/proc/device-tree/rpdzkj_config/usb_not_permission";
|
|
char usb_not_permission_prop[64] = "ro.rpdzkj.no.usb.permission";
|
|
|
|
char gps_use_dts[64] = "/proc/device-tree/rpdzkj_config/gps_use";
|
|
char gps_use_prop[64] = "ro.factory.hasGPS";
|
|
|
|
char gps_serial_port_dts[64] = "/proc/device-tree/rpdzkj_config/gps_serial_port";
|
|
char gps_serial_port_prop[64] = "ro.sf.gps.serial";
|
|
|
|
char user_version_dts[64] = "/proc/device-tree/rpdzkj_config/user_version";
|
|
char user_version_prop[64] = "ro.sf.user_version";
|
|
|
|
char not_navigation_bar_dts[64] = "/proc/device-tree/rpdzkj_config/not_navigation_bar";
|
|
char not_navigation_bar_prop[64] = "qemu.hw.mainkeys";
|
|
|
|
char home_apk_dts[64] = "/proc/device-tree/rpdzkj_config/home_apk";
|
|
char home_apk_prop[64] = "ro.Start.apk";
|
|
|
|
char extend_rotate1[64]= "/proc/device-tree/rpdzkj_config/extend_rotate";
|
|
char extend_rotate1_prop[64] = "persist.sys.rotation.einit-1";
|
|
|
|
char extend_rotate2[64]= "/proc/device-tree/rpdzkj_config/extend_rotate_2";
|
|
char extend_rotate2_prop[64] = "persist.sys.rotation.einit-2";
|
|
|
|
char extend_rotate3[64]= "/proc/device-tree/rpdzkj_config/extend_rotate_3";
|
|
char extend_rotate3_prop[64] = "persist.sys.rotation.einit-3";
|
|
|
|
char extend_efull1[64]= "/proc/device-tree/rpdzkj_config/rotation_efull";
|
|
char extend_efull1_prop[64] = "persist.sys.rotation.efull-1";
|
|
|
|
char extend_efull2[64]= "/proc/device-tree/rpdzkj_config/rotation_efull_2";
|
|
char extend_efull2_prop[64] = "persist.sys.rotation.efull-2";
|
|
|
|
char extend_efull3[64]= "/proc/device-tree/rpdzkj_config/rotation_efull_3";
|
|
char extend_efull3_prop[64] = "persist.sys.rotation.efull-3";
|
|
|
|
char primary_device_dts[64]= "/proc/device-tree/rpdzkj_config/primary_device";
|
|
char primary_device_prop[64] = "vendor.hwc.device.primary";
|
|
|
|
char extend_device_dts[64]= "/proc/device-tree/rpdzkj_config/extend_device";
|
|
char extend_device_prop[64] = "vendor.hwc.device.extend";
|
|
|
|
lcd2prop(system_rotate_dts,system_rotate_prop);
|
|
dts2prop(csi_camera_rotate_dts,csi_camera_rotate_prop);
|
|
dts2prop(usb_camera_rotate_dts,usb_camera_rotate_prop);
|
|
dts2prop(csi_camera_facing_dts,csi_camera_facing_prop);
|
|
dts2prop(usb_camera_facing_dts,usb_camera_facing_prop);
|
|
dts2prop(lcd_density_dts,lcd_density_prop);
|
|
dts2prop(time_zone_dts,time_zone_prop);
|
|
dts2prop(not_status_bar_dts,not_status_bar_prop);
|
|
dts2prop(default_launcher_dts,default_launcher_prop);
|
|
dts2prop(has_root_dts,has_root_prop);
|
|
dts2prop(usb_not_permission_dts,usb_not_permission_prop);
|
|
dts2prop(gps_use_dts,gps_use_prop);
|
|
dts2prop(gps_serial_port_dts,gps_serial_port_prop);
|
|
dts2prop(user_version_dts,user_version_prop);
|
|
language2prop(language_dts,language1_prop,language2_prop,language3_prop);
|
|
bar2prop(not_navigation_bar_dts,not_navigation_bar_prop);
|
|
dts2prop(home_apk_dts,home_apk_prop);
|
|
dts2prop(extend_rotate1, extend_rotate1_prop);
|
|
dts2prop(extend_rotate2, extend_rotate2_prop);
|
|
dts2prop(extend_rotate3, extend_rotate3_prop);
|
|
dts2prop(extend_efull1, extend_efull1_prop);
|
|
dts2prop(extend_efull2, extend_efull2_prop);
|
|
dts2prop(extend_efull3, extend_efull3_prop);
|
|
dts2prop(primary_device_dts, primary_device_prop);
|
|
dts2prop(extend_device_dts, extend_device_prop);
|
|
}
|
|
|
|
int main(int argc, char** argv) {
|
|
#if __has_feature(address_sanitizer)
|
|
__asan_set_error_report_callback(AsanReportCallback);
|
|
#elif __has_feature(hwaddress_sanitizer)
|
|
__hwasan_set_error_report_callback(AsanReportCallback);
|
|
#endif
|
|
// Boost prio which will be restored later
|
|
setpriority(PRIO_PROCESS, 0, -20);
|
|
if (!strcmp(basename(argv[0]), "ueventd")) {
|
|
return ueventd_main(argc, argv);
|
|
}
|
|
|
|
if (argc > 1) {
|
|
if (!strcmp(argv[1], "subcontext")) {
|
|
android::base::InitLogging(argv, &android::base::KernelLogger);
|
|
const BuiltinFunctionMap& function_map = GetBuiltinFunctionMap();
|
|
// rpdzkj custom
|
|
rp_change_properties();
|
|
return SubcontextMain(argc, argv, &function_map);
|
|
}
|
|
|
|
if (!strcmp(argv[1], "selinux_setup")) {
|
|
return SetupSelinux(argv);
|
|
}
|
|
|
|
if (!strcmp(argv[1], "second_stage")) {
|
|
return SecondStageMain(argc, argv);
|
|
}
|
|
}
|
|
|
|
return FirstStageMain(argc, argv);
|
|
}
|