Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fs_mgr/fs_mgr_fstab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ void ParseFsMgrFlags(const std::string& flags, FstabEntry* entry) {
}
} else if (StartsWith(flag, "zram_backing_dev_path=")) {
entry->zram_backing_dev_path = arg;
} else if (StartsWith(flag, "wrappedkey")) {
entry->fs_mgr_flags.wrappedkey = true;
} else {
LWARNING << "Warning: unknown flag: " << flag;
}
Expand Down
13 changes: 1 addition & 12 deletions fs_mgr/fs_mgr_roots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,7 @@ bool EnsurePathMounted(Fstab* fstab, const std::string& path, const std::string&
return false;
}

int result = fs_mgr_do_mount_one(*rec, mount_point);
if (result == -1 && rec->fs_mgr_flags.formattable) {
PERROR << "Failed to mount " << mount_point << "; formatting";
bool crypt_footer = rec->is_encryptable() && rec->key_loc == "footer";
if (fs_mgr_do_format(*rec, crypt_footer) != 0) {
PERROR << "Failed to format " << mount_point;
return false;
}
result = fs_mgr_do_mount_one(*rec, mount_point);
}

if (result == -1) {
if (fs_mgr_do_mount_one(*rec, mount_point) == -1) {
PERROR << "Failed to mount " << mount_point;
return false;
}
Expand Down
1 change: 1 addition & 0 deletions fs_mgr/include_fstab/fstab/fstab.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct FstabEntry {
bool first_stage_mount : 1;
bool slot_select_other : 1;
bool fs_verity : 1;
bool wrappedkey : 1;
} fs_mgr_flags = {};

bool is_encryptable() const {
Expand Down
7 changes: 6 additions & 1 deletion healthd/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,13 @@ include $$(BUILD_PREBUILT)
endef

_img_modules :=
ifeq ($(strip $(BOARD_HEALTHD_CUSTOM_CHARGER_RES)),)
IMAGES_DIR := images
else
IMAGES_DIR := ../../../$(BOARD_HEALTHD_CUSTOM_CHARGER_RES)
endif
_images :=
$(foreach _img, $(call find-subdir-subdir-files, "images", "*.png"), \
$(foreach _img, $(call find-subdir-subdir-files, "$(IMAGES_DIR)", "*.png"), \
$(eval $(call _add-charger-image,$(_img))))

include $(CLEAR_VARS)
Expand Down
41 changes: 41 additions & 0 deletions healthd/BatteryMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,14 @@ BatteryMonitor::PowerSupplyType BatteryMonitor::readPowerSupplyType(const String
{ "USB", ANDROID_POWER_SUPPLY_TYPE_USB },
{ "USB_DCP", ANDROID_POWER_SUPPLY_TYPE_AC },
{ "USB_HVDCP", ANDROID_POWER_SUPPLY_TYPE_AC },
{ "USB_HVDCP_3", ANDROID_POWER_SUPPLY_TYPE_AC },
{ "USB_CDP", ANDROID_POWER_SUPPLY_TYPE_AC },
{ "USB_ACA", ANDROID_POWER_SUPPLY_TYPE_AC },
{ "USB_C", ANDROID_POWER_SUPPLY_TYPE_AC },
{ "USB_PD", ANDROID_POWER_SUPPLY_TYPE_AC },
{ "USB_PD_DRP", ANDROID_POWER_SUPPLY_TYPE_USB },
{ "Wireless", ANDROID_POWER_SUPPLY_TYPE_WIRELESS },
{ "DASH", ANDROID_POWER_SUPPLY_TYPE_AC },
{ NULL, 0 },
};

Expand Down Expand Up @@ -244,6 +246,40 @@ bool BatteryMonitor::update(void) {

double MaxPower = 0;

// Rescan for the available charger types
std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(POWER_SUPPLY_SYSFS_PATH), closedir);
if (dir == NULL) {
KLOG_ERROR(LOG_TAG, "Could not open %s\n", POWER_SUPPLY_SYSFS_PATH);
} else {
struct dirent* entry;
String8 path;

mChargerNames.clear();

while ((entry = readdir(dir.get()))) {
const char* name = entry->d_name;

if (!strcmp(name, ".") || !strcmp(name, ".."))
continue;

// Look for "type" file in each subdirectory
path.clear();
path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, name);
switch(BatteryMonitor::readPowerSupplyType(path)) {
case ANDROID_POWER_SUPPLY_TYPE_AC:
case ANDROID_POWER_SUPPLY_TYPE_USB:
case ANDROID_POWER_SUPPLY_TYPE_WIRELESS:
path.clear();
path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name);
if (access(path.string(), R_OK) == 0)
mChargerNames.add(String8(name));
break;
default:
break;
}
}
}

for (size_t i = 0; i < mChargerNames.size(); i++) {
String8 path;
path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH,
Expand Down Expand Up @@ -280,6 +316,11 @@ bool BatteryMonitor::update(void) {
(access(path.string(), R_OK) == 0) ? getIntField(path) :
DEFAULT_VBUS_VOLTAGE;

// there are devices that have the file but with a value of 0
if (ChargingVoltage == 0) {
ChargingVoltage = DEFAULT_VBUS_VOLTAGE;
}

double power = ((double)ChargingCurrent / MILLION) *
((double)ChargingVoltage / MILLION);
if (MaxPower < power) {
Expand Down
11 changes: 10 additions & 1 deletion init/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cc_defaults {
"-Wextra",
"-Wno-unused-parameter",
"-Werror",
"-DALLOW_LOCAL_PROP_OVERRIDE=0",
"-DALLOW_LOCAL_PROP_OVERRIDE=1",
"-DALLOW_PERMISSIVE_SELINUX=0",
"-DREBOOT_BOOTLOADER_ON_PANIC=0",
"-DWORLD_WRITABLE_KMSG=0",
Expand Down Expand Up @@ -136,6 +136,7 @@ cc_library_static {
"ueventd.cpp",
"ueventd_parser.cpp",
"util.cpp",
"vendor_init.cpp",
],
whole_static_libs: ["libcap", "com.android.sysprop.apex"],
header_libs: ["bootimg_headers"],
Expand All @@ -150,6 +151,14 @@ cc_library_static {
exclude_shared_libs: ["libbinder", "libutils"],
},
},

product_variables: {
rr: {
target_init_vendor_lib: {
whole_static_libs: ["%s"],
},
},
},
}

cc_binary {
Expand Down
1 change: 1 addition & 0 deletions init/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ LOCAL_STATIC_LIBRARIES := \
LOCAL_SANITIZE := signed-integer-overflow
# First stage init is weird: it may start without stdout/stderr, and no /proc.
LOCAL_NOSANITIZE := hwaddress

include $(BUILD_EXECUTABLE)
endif

Expand Down
26 changes: 26 additions & 0 deletions init/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,29 @@

END OF TERMS AND CONDITIONS

Copyright (c) 2013, The Linux Foundation. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 4 additions & 0 deletions init/property_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include "selinux.h"
#include "subcontext.h"
#include "util.h"
#include "vendor_init.h"

using namespace std::literals;

Expand Down Expand Up @@ -912,6 +913,9 @@ void property_load_boot_defaults(bool load_debug_prop) {
}
}

// Update with vendor-specific property runtime overrides
vendor_load_properties();

property_initialize_ro_product_props();
property_derive_build_fingerprint();

Expand Down
15 changes: 10 additions & 5 deletions init/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,16 @@ static Result<std::string> ComputeContextFromExecutable(const std::string& servi
free(new_con);
}
if (rc == 0 && computed_context == mycon.get()) {
return Error() << "File " << service_path << "(labeled \"" << filecon.get()
<< "\") has incorrect label or no domain transition from " << mycon.get()
<< " to another SELinux domain defined. Have you configured your "
"service correctly? https://source.android.com/security/selinux/"
"device-policy#label_new_services_and_address_denials";
std::string error = StringPrintf(
"File %s (labeled \"%s\") has incorrect label or no domain transition from %s to "
"another SELinux domain defined. Have you configured your "
"service correctly? https://source.android.com/security/selinux/"
"device-policy#label_new_services_and_address_denials",
service_path.c_str(), filecon.get(), mycon.get());
if (selinux_status_getenforce() > 0) {
return Error() << error;
}
LOG(ERROR) << error;
}
if (rc < 0) {
return Error() << "Could not get process context";
Expand Down
50 changes: 43 additions & 7 deletions init/ueventd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
#include "ueventd.h"

#include <ctype.h>
#include <dirent.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>

#include <set>
#include <thread>
Expand Down Expand Up @@ -120,8 +123,9 @@ class ColdBoot {
void UeventHandlerMain(unsigned int process_num, unsigned int total_processes);
void RegenerateUevents();
void ForkSubProcesses();
void DoRestoreCon();
void WaitForSubProcesses();
void RestoreConHandler(unsigned int process_num, unsigned int total_processes);
void GenerateRestoreCon(const std::string& directory);

UeventListener& uevent_listener_;
std::vector<std::unique_ptr<UeventHandler>>& uevent_handlers_;
Expand All @@ -130,6 +134,8 @@ class ColdBoot {
std::vector<Uevent> uevent_queue_;

std::set<pid_t> subprocess_pids_;

std::vector<std::string> restorecon_queue_;
};

void ColdBoot::UeventHandlerMain(unsigned int process_num, unsigned int total_processes) {
Expand All @@ -140,9 +146,38 @@ void ColdBoot::UeventHandlerMain(unsigned int process_num, unsigned int total_pr
uevent_handler->HandleUevent(uevent);
}
}
}

void ColdBoot::RestoreConHandler(unsigned int process_num, unsigned int total_processes) {
for (unsigned int i = process_num; i < restorecon_queue_.size(); i += total_processes) {
auto& dir = restorecon_queue_[i];

selinux_android_restorecon(dir.c_str(), SELINUX_ANDROID_RESTORECON_RECURSE);
}
_exit(EXIT_SUCCESS);
}

void ColdBoot::GenerateRestoreCon(const std::string& directory) {
std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(directory.c_str()), &closedir);

if (!dir) return;

struct dirent* dent;
while ((dent = readdir(dir.get())) != NULL) {
if (strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0) continue;

struct stat st;
if (fstatat(dirfd(dir.get()), dent->d_name, &st, 0) == -1) continue;

if (S_ISDIR(st.st_mode)) {
std::string fullpath = directory + "/" + dent->d_name;
if (fullpath != "/sys/devices") {
restorecon_queue_.emplace_back(fullpath);
}
}
}
}

void ColdBoot::RegenerateUevents() {
uevent_listener_.RegenerateUevents([this](const Uevent& uevent) {
uevent_queue_.emplace_back(std::move(uevent));
Expand All @@ -159,16 +194,13 @@ void ColdBoot::ForkSubProcesses() {

if (pid == 0) {
UeventHandlerMain(i, num_handler_subprocesses_);
RestoreConHandler(i, num_handler_subprocesses_);
}

subprocess_pids_.emplace(pid);
}
}

void ColdBoot::DoRestoreCon() {
selinux_android_restorecon("/sys", SELINUX_ANDROID_RESTORECON_RECURSE);
}

void ColdBoot::WaitForSubProcesses() {
// Treat subprocesses that crash or get stuck the same as if ueventd itself has crashed or gets
// stuck.
Expand Down Expand Up @@ -207,9 +239,13 @@ void ColdBoot::Run() {

RegenerateUevents();

ForkSubProcesses();
selinux_android_restorecon("/sys", 0);
selinux_android_restorecon("/sys/devices", 0);
GenerateRestoreCon("/sys");
// takes long time for /sys/devices, parallelize it
GenerateRestoreCon("/sys/devices");

DoRestoreCon();
ForkSubProcesses();

WaitForSubProcesses();

Expand Down
37 changes: 37 additions & 0 deletions init/vendor_init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright (c) 2013, The Linux Foundation. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "vendor_init.h"

/* init vendor override stubs */

__attribute__ ((weak))
void vendor_load_properties()
{
}
Loading