blob: b4138f12777567008a0756f74d9986fe6a3ca3db [file] [log] [blame]
Tom Cherryed506f72017-05-25 15:58:59 -07001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tom Cherrydcb3d152019-08-07 16:02:28 -070017#pragma once
18
19#include <pwd.h>
Tom Cherryed506f72017-05-25 15:58:59 -070020
Tom Cherry7421fa12018-07-13 15:32:02 -070021#include <string>
22#include <vector>
23
Tom Cherrydcb3d152019-08-07 16:02:28 -070024#include "result.h"
Tom Cherryed506f72017-05-25 15:58:59 -070025#include "uevent.h"
Tom Cherry457e28f2018-08-01 13:12:20 -070026#include "uevent_handler.h"
Tom Cherryed506f72017-05-25 15:58:59 -070027
Tom Cherry81f5d3e2017-06-22 12:53:17 -070028namespace android {
29namespace init {
30
Tom Cherrydcb3d152019-08-07 16:02:28 -070031struct ExternalFirmwareHandler {
32 ExternalFirmwareHandler(std::string devpath, uid_t uid, std::string handler_path)
33 : devpath(std::move(devpath)), uid(uid), handler_path(std::move(handler_path)) {}
34 std::string devpath;
35 uid_t uid;
36 std::string handler_path;
37};
38
Tom Cherry457e28f2018-08-01 13:12:20 -070039class FirmwareHandler : public UeventHandler {
40 public:
Tom Cherrydcb3d152019-08-07 16:02:28 -070041 FirmwareHandler(std::vector<std::string> firmware_directories,
42 std::vector<ExternalFirmwareHandler> external_firmware_handlers);
Tom Cherry457e28f2018-08-01 13:12:20 -070043 virtual ~FirmwareHandler() = default;
Tom Cherry7421fa12018-07-13 15:32:02 -070044
Tom Cherry457e28f2018-08-01 13:12:20 -070045 void HandleUevent(const Uevent& uevent) override;
46
47 private:
Tom Cherrydcb3d152019-08-07 16:02:28 -070048 friend void FirmwareTestWithExternalHandler(const std::string& test_name,
49 bool expect_new_firmware);
50
51 Result<std::string> RunExternalHandler(const std::string& handler, uid_t uid,
52 const Uevent& uevent) const;
53 std::string GetFirmwarePath(const Uevent& uevent) const;
54 void ProcessFirmwareEvent(const std::string& root, const std::string& firmware) const;
Tom Cherry457e28f2018-08-01 13:12:20 -070055
56 std::vector<std::string> firmware_directories_;
Tom Cherrydcb3d152019-08-07 16:02:28 -070057 std::vector<ExternalFirmwareHandler> external_firmware_handlers_;
Tom Cherry457e28f2018-08-01 13:12:20 -070058};
Tom Cherryed506f72017-05-25 15:58:59 -070059
Tom Cherry81f5d3e2017-06-22 12:53:17 -070060} // namespace init
61} // namespace android