1 /* 2 * Copyright (c) 2024-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 #ifndef POWERMGR_BATTERY_MANAGER_CHARGING_SOUND_H 16 #define POWERMGR_BATTERY_MANAGER_CHARGING_SOUND_H 17 #include <atomic> 18 #include <memory> 19 #include <string> 20 #include "nocopyable.h" 21 namespace OHOS { 22 namespace Media { 23 class Player; 24 } // namespace Media 25 26 namespace PowerMgr { 27 class ChargingSound { 28 public: 29 ChargingSound(); 30 ~ChargingSound(); 31 bool Play(); 32 void Release(); 33 void Stop(); 34 bool IsPlaying(); 35 // single instance for now 36 static bool IsPlayingGlobal(); 37 static bool PlayGlobal(); 38 static void ReleaseGlobal(); 39 40 private: 41 DISALLOW_COPY_AND_MOVE(ChargingSound); 42 std::string GetPath(const char* uri) const; 43 std::string uri_; 44 std::shared_ptr<Media::Player> player_ {}; 45 std::atomic<bool> isPlaying_ {false}; 46 static std::shared_ptr<ChargingSound> instance_; 47 }; 48 49 // export apis 50 extern "C" { 51 __attribute__ ((visibility ("default"))) bool ChargingSoundStart(void); 52 __attribute__ ((visibility ("default"))) bool IsPlaying(void); 53 } 54 } // namespace PowerMgr 55 } // namespace OHOS 56 #endif