2017-05-26 00:58:59 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 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.
|
|
|
|
*/
|
|
|
|
|
2019-08-08 01:02:28 +02:00
|
|
|
#pragma once
|
|
|
|
|
2021-05-13 11:56:31 +02:00
|
|
|
#include <grp.h>
|
2019-08-08 01:02:28 +02:00
|
|
|
#include <pwd.h>
|
2017-05-26 00:58:59 +02:00
|
|
|
|
2020-09-18 07:41:22 +02:00
|
|
|
#include <functional>
|
2018-07-14 00:32:02 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-08-08 01:02:28 +02:00
|
|
|
#include "result.h"
|
2017-05-26 00:58:59 +02:00
|
|
|
#include "uevent.h"
|
2018-08-01 22:12:20 +02:00
|
|
|
#include "uevent_handler.h"
|
2017-05-26 00:58:59 +02:00
|
|
|
|
2017-06-22 21:53:17 +02:00
|
|
|
namespace android {
|
|
|
|
namespace init {
|
|
|
|
|
2019-08-08 01:02:28 +02:00
|
|
|
struct ExternalFirmwareHandler {
|
2021-04-06 04:22:49 +02:00
|
|
|
ExternalFirmwareHandler(std::string devpath, uid_t uid, std::string handler_path);
|
2021-05-13 11:56:31 +02:00
|
|
|
ExternalFirmwareHandler(std::string devpath, uid_t uid, gid_t gid, std::string handler_path);
|
2021-04-06 04:22:49 +02:00
|
|
|
|
2019-08-08 01:02:28 +02:00
|
|
|
std::string devpath;
|
|
|
|
uid_t uid;
|
2021-05-13 11:56:31 +02:00
|
|
|
gid_t gid;
|
2019-08-08 01:02:28 +02:00
|
|
|
std::string handler_path;
|
2021-04-06 04:22:49 +02:00
|
|
|
|
|
|
|
std::function<bool(const std::string&)> match;
|
2019-08-08 01:02:28 +02:00
|
|
|
};
|
|
|
|
|
2018-08-01 22:12:20 +02:00
|
|
|
class FirmwareHandler : public UeventHandler {
|
|
|
|
public:
|
2019-08-08 01:02:28 +02:00
|
|
|
FirmwareHandler(std::vector<std::string> firmware_directories,
|
|
|
|
std::vector<ExternalFirmwareHandler> external_firmware_handlers);
|
2018-08-01 22:12:20 +02:00
|
|
|
virtual ~FirmwareHandler() = default;
|
2018-07-14 00:32:02 +02:00
|
|
|
|
2018-08-01 22:12:20 +02:00
|
|
|
void HandleUevent(const Uevent& uevent) override;
|
|
|
|
|
|
|
|
private:
|
2019-08-08 01:02:28 +02:00
|
|
|
friend void FirmwareTestWithExternalHandler(const std::string& test_name,
|
|
|
|
bool expect_new_firmware);
|
|
|
|
|
2021-05-13 11:56:31 +02:00
|
|
|
Result<std::string> RunExternalHandler(const std::string& handler, uid_t uid, gid_t gid,
|
2019-08-08 01:02:28 +02:00
|
|
|
const Uevent& uevent) const;
|
|
|
|
std::string GetFirmwarePath(const Uevent& uevent) const;
|
2024-04-05 10:22:34 +02:00
|
|
|
void ProcessFirmwareEvent(const std::string& path, const std::string& firmware) const;
|
2020-09-18 07:41:22 +02:00
|
|
|
bool ForEachFirmwareDirectory(std::function<bool(const std::string&)> handler) const;
|
2018-08-01 22:12:20 +02:00
|
|
|
|
|
|
|
std::vector<std::string> firmware_directories_;
|
2019-08-08 01:02:28 +02:00
|
|
|
std::vector<ExternalFirmwareHandler> external_firmware_handlers_;
|
2018-08-01 22:12:20 +02:00
|
|
|
};
|
2017-05-26 00:58:59 +02:00
|
|
|
|
2017-06-22 21:53:17 +02:00
|
|
|
} // namespace init
|
|
|
|
} // namespace android
|