• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 ST_STANDALONE_MODE_MANAGER_H
17 #define ST_STANDALONE_MODE_MANAGER_H
18 
19 #include <string>
20 #include <unordered_map>
21 #include <unordered_set>
22 #include "audio_info.h"
23 
24 namespace OHOS {
25 namespace AudioStandard {
26 
27 static constexpr int32_t INVALID_ID = INT_MIN;
28 
29 class AudioInterruptService;
30 class StandaloneModeManager {
31 public:
32     static StandaloneModeManager &GetInstance();
33     void InIt(std::shared_ptr<AudioInterruptService> interruptService);
34     bool CheckAndRecordStandaloneApp(const int32_t appUid, const bool isOnlyRecordUid = true,
35         const int32_t sessionId = -1);
36     int32_t SetAppSlientOnDisplay(const int32_t ownerPid, const int32_t displayId);
37     int32_t SetAppConcurrencyMode(const int32_t ownerPid,
38         const int32_t appUid, const int32_t mode);
39     void EraseDeactivateAudioStream(const int32_t &appUid,
40         const int32_t &sessionId);
41     void ResumeAllStandaloneApp(const int32_t appPid);
42 
43 private:
44     StandaloneModeManager() = default;
45     ~StandaloneModeManager();
46     StandaloneModeManager(const StandaloneModeManager&) = delete;
47     StandaloneModeManager &operator = (const StandaloneModeManager&) = delete;
48 
49     void CleanAllStandaloneInfo();
50     void RemoveExistingFocus(const int32_t appUid);
51     bool CheckOwnerPidPermissions(const int32_t ownerPid);
52     void ExitStandaloneAndResumeFocus(const int32_t appUid);
53     bool CheckAppOnVirtualScreenByUid(const int32_t appUid);
54     void RecordStandaloneAppSessionIdInfo(const int32_t appUid, const bool isOnlyRecordUid = true,
55         const int32_t sessionId = -1);
56 
57     std::mutex mutex_;
58     std::shared_ptr<AudioInterruptService> interruptService_;
59     int32_t ownerPid_ = INVALID_ID;
60     int32_t displayId_ = INVALID_ID;
61     bool isSetSlientDisplay_ = false;
62     std::unordered_map<int32_t,
63         std::unordered_set<int32_t>>activedZoneSessionsMap_ = {}; //{appUid {zoneId {sessionId}}}
64 };
65 } // namespace AudioStandard
66 } // namespace OHOS
67 
68 #endif // ST_STANDALONE_MODE_MANAGER_H