• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
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 #include "app_state_listener.h"
17 #include "player_mem_manage.h"
18 #include "media_log.h"
19 
20 namespace {
21     constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_PLAYER, "AppStateListener"};
22 }
23 
24 namespace OHOS {
25 namespace Media {
AppStateListener()26 AppStateListener::AppStateListener()
27 {
28     MEDIA_LOGI("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
29 }
30 
~AppStateListener()31 AppStateListener::~AppStateListener()
32 {
33     MEDIA_LOGI("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
34 }
35 
OnConnected()36 void AppStateListener::OnConnected()
37 {
38     MEDIA_LOGI("enter");
39     PlayerMemManage::GetInstance().HandleOnConnected();
40 }
41 
OnDisconnected()42 void AppStateListener::OnDisconnected()
43 {
44     MEDIA_LOGI("enter");
45     PlayerMemManage::GetInstance().HandleOnDisconnected();
46 }
47 
OnRemoteDied(const wptr<IRemoteObject> & object)48 void AppStateListener::OnRemoteDied(const wptr<IRemoteObject> &object)
49 {
50     (void)object;
51     MEDIA_LOGI("enter");
52     PlayerMemManage::GetInstance().HandleOnRemoteDied(object);
53 }
54 
ForceReclaim(int32_t pid,int32_t uid)55 void AppStateListener::ForceReclaim(int32_t pid, int32_t uid)
56 {
57     MEDIA_LOGI("enter");
58     PlayerMemManage::GetInstance().HandleForceReclaim(uid, pid);
59 }
60 
OnTrim(Memory::SystemMemoryLevel level)61 void AppStateListener::OnTrim(Memory::SystemMemoryLevel level)
62 {
63     MEDIA_LOGI("enter level:%{public}d", level);
64     PlayerMemManage::GetInstance().HandleOnTrim(level);
65 }
66 
OnAppStateChanged(int32_t pid,int32_t uid,int32_t state)67 void AppStateListener::OnAppStateChanged(int32_t pid, int32_t uid, int32_t state)
68 {
69     MEDIA_LOGI("enter pid:%{public}d, uid:%{public}d, state:%{public}d", pid, uid, state);
70     PlayerMemManage::GetInstance().RecordAppState(uid, pid, state);
71 }
72 }
73 }
74