1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef STORAGE_DAEMON_CRYPTO_DELAY_HANDLER_H
17 #define STORAGE_DAEMON_CRYPTO_DELAY_HANDLER_H
18 
19 #include <atomic>
20 #include <thread>
21 #include <vector>
22 
23 #include "base_key.h"
24 #include "event_handler.h"
25 #include "libfscrypt/key_control.h"
26 
27 namespace OHOS {
28 namespace StorageDaemon {
29 class DelayHandler {
30 static const uint8_t CANCEL_CLEAR_ECE_SECE_TASK = 0;
31 static const uint8_t START_CLEAR_ECE_SECE_TASK = 1;
32 public:
33     DelayHandler(uint32_t userId);
34     ~DelayHandler();
35     void StartDelayTask(std::shared_ptr<BaseKey> &elKey);
36     void CancelDelayTask();
37 
38 private:
39     void StartDelayHandler();
40     void ClearEceSeceKey();
41 
42     std::mutex eventMutex_;
43     std::thread eventThread_;
44     std::condition_variable eventCon_;
45     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr;
46     std::shared_ptr<BaseKey> el4Key_;
47     uint32_t userId_;
48 };
49 } // StorageDaemon
50 } // OHOS
51 
52 #endif // STORAGE_DAEMON_CRYPTO_DELAY_HANDLER_H
53