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
|
|
|
|
|
|
|
|
#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 {
|
|
|
|
ExternalFirmwareHandler(std::string devpath, uid_t uid, std::string handler_path)
|
|
|
|
: devpath(std::move(devpath)), uid(uid), handler_path(std::move(handler_path)) {}
|
|
|
|
std::string devpath;
|
|
|
|
uid_t uid;
|
|
|
|
std::string handler_path;
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
Result<std::string> RunExternalHandler(const std::string& handler, uid_t uid,
|
|
|
|
const Uevent& uevent) const;
|
|
|
|
std::string GetFirmwarePath(const Uevent& uevent) const;
|
|
|
|
void ProcessFirmwareEvent(const std::string& root, 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
|