• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "cj_display_manager.h"
17 
18 #include <mutex>
19 #include <securec.h>
20 
21 #include "cj_display_impl.h"
22 #include "display_manager.h"
23 #include "dm_common.h"
24 #include "singleton_container.h"
25 #include "window_manager_hilog.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 
30 std::map<std::string, std::map<int64_t, sptr<CJDisplayListener>>> CJDisplayManager::cjCbMap_;
31 std::mutex CJDisplayManager::mtx_;
32 
SetDisplayObject(sptr<Display> & obj,RetStruct & ret)33 static void SetDisplayObject(sptr<Display>& obj, RetStruct& ret)
34 {
35     auto result = DisplayImpl::CreateDisplayImpl(obj);
36     if (result == nullptr || ret.data == nullptr) {
37         TLOGE(WmsLogTag::DMS, "[GetDefaultDisplaySync] ERROR Failed to create DisplayImpl.");
38         ret.code = static_cast<int32_t>(DmErrorCode::DM_ERROR_SYSTEM_INNORMAL);
39         return;
40     }
41     int64_t* dataPtr = static_cast<int64_t*>(ret.data);
42     if (dataPtr == nullptr) {
43         TLOGE(WmsLogTag::DMS, "[SetDisplayObject] ERROR Failed to create dataPtr.");
44         ret.code = static_cast<int32_t>(DmErrorCode::DM_ERROR_SYSTEM_INNORMAL);
45         return;
46     }
47     dataPtr[ret.len] = result->GetID();
48     ret.len += 1;
49     ret.code = static_cast<int32_t>(DmErrorCode::DM_OK);
50 }
51 
SetDisplaysArrayObject(std::vector<sptr<Display>> & list,RetStruct & ret)52 static void SetDisplaysArrayObject(std::vector<sptr<Display>>& list, RetStruct& ret)
53 {
54     int64_t* displayImplIdList = static_cast<int64_t*>(malloc(sizeof(int64_t) * list.size()));
55     if (displayImplIdList == nullptr) {
56         TLOGE(WmsLogTag::DMS, "[SetDisplaysArrayObject] ERROR Failed to create displayImplIdList.");
57         ret.code = static_cast<int32_t>(DmErrorCode::DM_ERROR_SYSTEM_INNORMAL);
58         return;
59     }
60     ret.data = displayImplIdList;
61     ret.len = 0;
62     for (auto& display : list) {
63         if (display == nullptr) {
64             continue;
65         }
66         SetDisplayObject(display, ret);
67         if (ret.code != 0) {
68             TLOGE(WmsLogTag::DMS, "[SetDisplaysArrayObject] ERROR Create display failed in %{public}" PRId64 " obj",
69                 ret.len);
70             free(displayImplIdList);
71             ret.data = nullptr;
72             return;
73         }
74     }
75 }
76 
SetCRect(const DMRect & row,CRect * ptr)77 static void SetCRect(const DMRect& row, CRect* ptr)
78 {
79     ptr->left = row.posX_;
80     ptr->top = row.posY_;
81     ptr->width = row.width_;
82     ptr->height = row.height_;
83 }
84 
CreateCreaseRects(std::vector<DMRect> & list)85 static CRect* CreateCreaseRects(std::vector<DMRect>& list)
86 {
87     int32_t number = static_cast<int32_t>(list.size());
88     CRect* result = static_cast<CRect*>(malloc(sizeof(CRect) * number));
89     if (result == nullptr) {
90         return nullptr;
91     }
92     for (int i = 0; i < number; i++) {
93         SetCRect(list[i], (result + i));
94     }
95     return result;
96 }
97 
CreateCFoldCreaseRegionObject(sptr<FoldCreaseRegion> & foldCreaseRegion)98 static CFoldCreaseRegion* CreateCFoldCreaseRegionObject(sptr<FoldCreaseRegion>& foldCreaseRegion)
99 {
100     CFoldCreaseRegion* region = static_cast<CFoldCreaseRegion*>(malloc(sizeof(CFoldCreaseRegion)));
101     if (region == nullptr) {
102         return nullptr;
103     }
104     int ret = memset_s(region, sizeof(CFoldCreaseRegion), 0, sizeof(CFoldCreaseRegion));
105     if (ret != 0) {
106         free(region);
107         return nullptr;
108     }
109     region->displayId = static_cast<uint32_t>(foldCreaseRegion->GetDisplayId());
110     std::vector<DMRect> creaseRects = foldCreaseRegion->GetCreaseRects();
111 
112     region->number = static_cast<int64_t>(creaseRects.size());
113     region->creaseRects = CreateCreaseRects(creaseRects);
114     if (region->creaseRects == nullptr) {
115         TLOGE(WmsLogTag::DMS, "[CreateCreaseRects] ERROR Failed to create creaseRects.");
116         free(region);
117         return nullptr;
118     }
119     return region;
120 }
121 
GetDefaultDisplaySync()122 RetStruct CJDisplayManager::GetDefaultDisplaySync()
123 {
124     RetStruct ret = { .code = static_cast<int32_t>(DmErrorCode::DM_ERROR_SYSTEM_INNORMAL), .len = 0, .data = nullptr };
125     sptr<Display> display = SingletonContainer::Get<DisplayManager>().GetDefaultDisplaySync();
126     if (display == nullptr) {
127         TLOGE(WmsLogTag::DMS, "[DisplayManager] Get default display is nullptr");
128         ret.code = static_cast<int32_t>(DmErrorCode::DM_ERROR_INVALID_SCREEN);
129         return ret;
130     }
131     int64_t* displayImplId = static_cast<int64_t*>(malloc(sizeof(int64_t)));
132     if (displayImplId == nullptr) {
133         TLOGE(WmsLogTag::DMS, "[GetDefaultDisplaySync] ERROR Failed to create displayImplId.");
134         ret.code = static_cast<int32_t>(DmErrorCode::DM_ERROR_INVALID_SCREEN);
135         return ret;
136     }
137     ret.data = displayImplId;
138     ret.len = 0;
139     SetDisplayObject(display, ret);
140     return ret;
141 }
142 
GetAllDisplays()143 RetStruct CJDisplayManager::GetAllDisplays()
144 {
145     RetStruct ret = { .code = static_cast<int32_t>(DmErrorCode::DM_ERROR_SYSTEM_INNORMAL), .len = 0, .data = nullptr };
146     std::vector<sptr<Display>> displays = SingletonContainer::Get<DisplayManager>().GetAllDisplays();
147     if (displays.empty()) {
148         ret.code = static_cast<int32_t>(DmErrorCode::DM_ERROR_INVALID_SCREEN);
149         TLOGE(WmsLogTag::DMS, "[GetAllDisplays] ERROR Failed to get all displays.");
150         return ret;
151     }
152     SetDisplaysArrayObject(displays, ret);
153     return ret;
154 }
155 
HasPrivateWindow(uint32_t displayId)156 RetStruct CJDisplayManager::HasPrivateWindow(uint32_t displayId)
157 {
158     RetStruct ret = { .code = static_cast<int32_t>(DmErrorCode::DM_ERROR_SYSTEM_INNORMAL), .len = 0, .data = nullptr };
159     int64_t displayId_ = static_cast<int64_t>(displayId);
160     bool* hasPrivateWindow = static_cast<bool*>(malloc(sizeof(bool)));
161     if (hasPrivateWindow == nullptr) {
162         ret.code = static_cast<int32_t>(DmErrorCode::DM_ERROR_SYSTEM_INNORMAL);
163         return ret;
164     }
165     *hasPrivateWindow = false;
166     DmErrorCode errorCode = DM_JS_TO_ERROR_CODE_MAP.at(
167         SingletonContainer::Get<DisplayManager>().HasPrivateWindow(displayId_, *hasPrivateWindow));
168     TLOGI(WmsLogTag::DMS,
169         "[DisplayManager] Display id = %{public}" PRIu64 ", hasPrivateWindow = %{public}u err = %{public}d",
170         static_cast<uint64_t>(displayId_), *hasPrivateWindow, errorCode);
171     if (errorCode != DmErrorCode::DM_OK) {
172         ret.code = static_cast<int32_t>(errorCode);
173         free(hasPrivateWindow);
174         return ret;
175     }
176     ret.code = static_cast<int32_t>(DmErrorCode::DM_OK);
177     ret.data = static_cast<void*>(hasPrivateWindow);
178     return ret;
179 }
180 
IsFoldable()181 bool CJDisplayManager::IsFoldable()
182 {
183     return SingletonContainer::Get<DisplayManager>().IsFoldable();
184 }
185 
SetFoldDisplayMode(uint32_t mode)186 void CJDisplayManager::SetFoldDisplayMode(uint32_t mode)
187 {
188     FoldDisplayMode innerMode = static_cast<FoldDisplayMode>(mode);
189     SingletonContainer::Get<DisplayManager>().SetFoldDisplayMode(innerMode);
190 }
191 
GetFoldStatus()192 uint32_t CJDisplayManager::GetFoldStatus()
193 {
194     return static_cast<uint32_t>(SingletonContainer::Get<DisplayManager>().GetFoldStatus());
195 }
196 
GetFoldDisplayMode()197 uint32_t CJDisplayManager::GetFoldDisplayMode()
198 {
199     return static_cast<uint32_t>(SingletonContainer::Get<DisplayManager>().GetFoldDisplayMode());
200 }
201 
GetCurrentFoldCreaseRegion()202 RetStruct CJDisplayManager::GetCurrentFoldCreaseRegion()
203 {
204     RetStruct result = {
205         .code = static_cast<int32_t>(DmErrorCode::DM_ERROR_SYSTEM_INNORMAL), .len = 0, .data = nullptr
206     };
207     sptr<FoldCreaseRegion> region = SingletonContainer::Get<DisplayManager>().GetCurrentFoldCreaseRegion();
208     if (region == nullptr) {
209         result.code = static_cast<int32_t>(DmErrorCode::DM_ERROR_SYSTEM_INNORMAL);
210         return result;
211     }
212     result.data = CreateCFoldCreaseRegionObject(region);
213     result.code = static_cast<int32_t>(DmErrorCode::DM_OK);
214     if (result.data == nullptr) {
215         result.code = static_cast<int32_t>(DmErrorCode::DM_ERROR_SYSTEM_INNORMAL);
216     }
217     return result;
218 }
219 
IsCaptured()220 bool CJDisplayManager::IsCaptured()
221 {
222     return SingletonContainer::Get<DisplayManager>().IsCaptured();
223 }
224 
SetDisplayPhysicalResolutionObject(DisplayPhysicalResolution & resolution,RetStruct & ret)225 static void SetDisplayPhysicalResolutionObject(DisplayPhysicalResolution& resolution, RetStruct& ret)
226 {
227     DisplayPhysicalResolution* dataPtr = static_cast<DisplayPhysicalResolution*>(ret.data);
228     dataPtr[ret.len].foldDisplayMode_ = resolution.foldDisplayMode_;
229     dataPtr[ret.len].physicalWidth_ = resolution.physicalWidth_;
230     dataPtr[ret.len].physicalHeight_ = resolution.physicalHeight_;
231     ret.len++;
232 }
233 
SetDisplayPhysicalResolutionArrayObject(std::vector<DisplayPhysicalResolution> & resolutionList,RetStruct & ret)234 static void SetDisplayPhysicalResolutionArrayObject(
235     std::vector<DisplayPhysicalResolution>& resolutionList, RetStruct& ret)
236 {
237     DisplayPhysicalResolution* resolutions =
238         static_cast<DisplayPhysicalResolution*>(malloc(sizeof(DisplayPhysicalResolution) * resolutionList.size()));
239     if (resolutions == nullptr) {
240         TLOGE(WmsLogTag::DMS,
241             "[SetDisplayPhysicalResolutionArrayObject] ERROR Failed to create display physical resolution list.");
242         ret.code = static_cast<int32_t>(DmErrorCode::DM_ERROR_SYSTEM_INNORMAL);
243         return;
244     }
245     ret.data = resolutions;
246     ret.len = 0;
247     for (auto& resolution : resolutionList) {
248         SetDisplayPhysicalResolutionObject(resolution, ret);
249     }
250 }
251 
GetAllDisplayPhysicalResolution()252 RetStruct CJDisplayManager::GetAllDisplayPhysicalResolution()
253 {
254     RetStruct result = { .code = static_cast<int32_t>(DMError::DM_OK), .len = 0, .data = nullptr };
255     std::vector<DisplayPhysicalResolution> displayPhysicalArray =
256         SingletonContainer::Get<DisplayManager>().GetAllDisplayPhysicalResolution();
257     if (displayPhysicalArray.empty()) {
258         result.code = static_cast<int32_t>(DMError::DM_ERROR_NULLPTR);
259         TLOGE(
260             WmsLogTag::DMS, "[GetAllDisplayPhysicalResolution] ERROR Failed to get all displays physical resolution.");
261         return result;
262     }
263     SetDisplayPhysicalResolutionArrayObject(displayPhysicalArray, result);
264     return result;
265 }
266 
IfCallbackRegistered(const std::string & type,int64_t callbackId)267 bool CJDisplayManager::IfCallbackRegistered(const std::string& type, int64_t callbackId)
268 {
269     if (CJDisplayManager::cjCbMap_.empty() ||
270         CJDisplayManager::cjCbMap_.find(type) == CJDisplayManager::cjCbMap_.end()) {
271         TLOGI(WmsLogTag::DMS, "IfCallbackRegistered methodName %{public}s not registered", type.c_str());
272         return false;
273     }
274 
275     for (auto& iter : CJDisplayManager::cjCbMap_[type]) {
276         if (iter.first == callbackId) {
277             TLOGE(WmsLogTag::DMS, "IfCallbackRegistered callback already registered!");
278             return true;
279         }
280     }
281     return false;
282 }
283 
OnUnregisterAllDisplayListenerWithType(const std::string & type)284 int32_t CJDisplayManager::OnUnregisterAllDisplayListenerWithType(const std::string& type)
285 {
286     TLOGD(WmsLogTag::DMS, "CJDisplayManager::OnUnregisterAllDisplayListenerWithType is called");
287     DmErrorCode ret = DM_JS_TO_ERROR_CODE_MAP.at(CJDisplayManager::UnregisterAllDisplayListenerWithType(type));
288     if (ret != DmErrorCode::DM_OK) {
289         if (ret != DmErrorCode::DM_ERROR_NOT_SYSTEM_APP) {
290             ret = DmErrorCode::DM_ERROR_INVALID_PARAM;
291         }
292         TLOGE(WmsLogTag::DMS, "Failed to unregister display listener with type %{public}s", type.c_str());
293     }
294     return static_cast<int32_t>(ret);
295 }
296 
UnregisterAllDisplayListenerWithType(const std::string & type)297 DMError CJDisplayManager::UnregisterAllDisplayListenerWithType(const std::string& type)
298 {
299     TLOGD(WmsLogTag::DMS, "CJDisplayManager::UnregisterAllDisplayListenerWithType is called");
300     if (CJDisplayManager::cjCbMap_.empty() ||
301         CJDisplayManager::cjCbMap_.find(type) == CJDisplayManager::cjCbMap_.end()) {
302         TLOGI(
303             WmsLogTag::DMS, "UnregisterAllDisplayListenerWithType methodName %{public}s not registered!", type.c_str());
304         return DMError::DM_OK;
305     }
306 
307     std::lock_guard<std::mutex> lock(CJDisplayManager::mtx_);
308     DMError ret = DMError::DM_OK;
309     for (auto it = cjCbMap_[type].begin(); it != cjCbMap_[type].end();) {
310         it->second->RemoveAllCallback();
311         if (type == EVENT_ADD || type == EVENT_REMOVE || type == EVENT_CHANGE) {
312             sptr<DisplayManager::IDisplayListener> thisListener(it->second);
313             ret = SingletonContainer::Get<DisplayManager>().UnregisterDisplayListener(thisListener);
314         } else if (type == EVENT_PRIVATE_MODE_CHANGE) {
315             sptr<DisplayManager::IPrivateWindowListener> thisListener(it->second);
316             ret = SingletonContainer::Get<DisplayManager>().UnregisterPrivateWindowListener(thisListener);
317         } else if (type == EVENT_AVAILABLE_AREA_CHANGED) {
318             sptr<DisplayManager::IAvailableAreaListener> thisListener(it->second);
319             ret = SingletonContainer::Get<DisplayManager>().UnregisterAvailableAreaListener(thisListener);
320         } else if (type == EVENT_FOLD_STATUS_CHANGED) {
321             sptr<DisplayManager::IFoldStatusListener> thisListener(it->second);
322             ret = SingletonContainer::Get<DisplayManager>().UnregisterFoldStatusListener(thisListener);
323         } else if (type == EVENT_DISPLAY_MODE_CHANGED) {
324             sptr<DisplayManager::IDisplayModeListener> thisListener(it->second);
325             ret = SingletonContainer::Get<DisplayManager>().UnregisterDisplayModeListener(thisListener);
326         } else if (type == EVENT_FOLD_ANGLE_CHANGED) {
327             sptr<DisplayManager::IFoldAngleListener> thisListener(it->second);
328             ret = SingletonContainer::Get<DisplayManager>().UnregisterFoldAngleListener(thisListener);
329         } else if (type == EVENT_CAPTURE_STATUS_CHANGED) {
330             sptr<DisplayManager::ICaptureStatusListener> thisListener(it->second);
331             ret = SingletonContainer::Get<DisplayManager>().UnregisterCaptureStatusListener(thisListener);
332         } else {
333             ret = DMError::DM_ERROR_INVALID_PARAM;
334         }
335         CJDisplayManager::cjCbMap_[type].erase(it++);
336         TLOGI(WmsLogTag::DMS, "Unregister display listener with type %{public}s  ret: %{public}u", type.c_str(), ret);
337     }
338     cjCbMap_[type].clear();
339     return ret;
340 }
341 
OnRegisterDisplayListenerWithType(const std::string & type,int64_t callbackId)342 int32_t CJDisplayManager::OnRegisterDisplayListenerWithType(const std::string& type, int64_t callbackId)
343 {
344     TLOGD(WmsLogTag::DMS, "CJDisplayManager::OnRegisterDisplayListenerWithType is called");
345     DmErrorCode ret = DM_JS_TO_ERROR_CODE_MAP.at(CJDisplayManager::RegisterDisplayListenerWithType(type, callbackId));
346     if (ret != DmErrorCode::DM_OK) {
347         if (ret != DmErrorCode::DM_ERROR_NOT_SYSTEM_APP) {
348             ret = DmErrorCode::DM_ERROR_INVALID_PARAM;
349         }
350         TLOGE(WmsLogTag::DMS, "Failed to register display listener with type %{public}s", type.c_str());
351     }
352     return static_cast<int32_t>(ret);
353 }
354 
RegisterDisplayListenerWithType(const std::string & type,int64_t callbackId)355 DMError CJDisplayManager::RegisterDisplayListenerWithType(const std::string& type, int64_t callbackId)
356 {
357     TLOGD(WmsLogTag::DMS, "CJDisplayManager::RegisterDisplayListenerWithType is called");
358     if (IfCallbackRegistered(type, callbackId)) {
359         TLOGI(WmsLogTag::DMS, "RegisterDisplayListenerWithType callback with type %{public}s already registered",
360             type.c_str());
361         return DMError::DM_OK;
362     }
363     std::lock_guard<std::mutex> lock(CJDisplayManager::mtx_);
364     sptr<CJDisplayListener> displayListener = new (std::nothrow) CJDisplayListener();
365     DMError ret = DMError::DM_OK;
366     if (displayListener == nullptr) {
367         TLOGE(WmsLogTag::DMS, "displayListener is nullptr");
368         return DMError::DM_ERROR_INVALID_PARAM;
369     }
370     if (type == EVENT_ADD || type == EVENT_REMOVE || type == EVENT_CHANGE) {
371         ret = SingletonContainer::Get<DisplayManager>().RegisterDisplayListener(displayListener);
372     } else if (type == EVENT_PRIVATE_MODE_CHANGE) {
373         ret = SingletonContainer::Get<DisplayManager>().RegisterPrivateWindowListener(displayListener);
374     } else if (type == EVENT_FOLD_STATUS_CHANGED) {
375         ret = SingletonContainer::Get<DisplayManager>().RegisterFoldStatusListener(displayListener);
376     } else if (type == EVENT_DISPLAY_MODE_CHANGED) {
377         ret = SingletonContainer::Get<DisplayManager>().RegisterDisplayModeListener(displayListener);
378     } else if (type == EVENT_AVAILABLE_AREA_CHANGED) {
379         ret = SingletonContainer::Get<DisplayManager>().RegisterAvailableAreaListener(displayListener);
380     } else if (type == EVENT_FOLD_ANGLE_CHANGED) {
381         ret = SingletonContainer::Get<DisplayManager>().RegisterFoldAngleListener(displayListener);
382     } else if (type == EVENT_CAPTURE_STATUS_CHANGED) {
383         ret = SingletonContainer::Get<DisplayManager>().RegisterCaptureStatusListener(displayListener);
384     } else {
385         TLOGE(WmsLogTag::DMS, "RegisterDisplayListenerWithType failed, %{public}s not support", type.c_str());
386         return DMError::DM_ERROR_INVALID_PARAM;
387     }
388     if (ret != DMError::DM_OK) {
389         TLOGE(WmsLogTag::DMS, "RegisterDisplayListenerWithType failed, ret %{public}u", ret);
390         return ret;
391     }
392     displayListener->AddCallback(type, callbackId);
393     CJDisplayManager::cjCbMap_[type][callbackId] = displayListener;
394     return DMError::DM_OK;
395 }
396 
OnUnRegisterDisplayListenerWithType(const std::string & type,int64_t callbackId)397 int32_t CJDisplayManager::OnUnRegisterDisplayListenerWithType(const std::string& type, int64_t callbackId)
398 {
399     TLOGD(WmsLogTag::DMS, "CJDisplayManager::OnUnRegisterDisplayListenerWithType is called");
400     DmErrorCode ret = DM_JS_TO_ERROR_CODE_MAP.at(CJDisplayManager::UnRegisterDisplayListenerWithType(type, callbackId));
401     if (ret != DmErrorCode::DM_OK) {
402         if (ret != DmErrorCode::DM_ERROR_NOT_SYSTEM_APP) {
403             ret = DmErrorCode::DM_ERROR_INVALID_PARAM;
404         }
405         TLOGE(WmsLogTag::DMS, "Failed to unregister display listener with type %{public}s", type.c_str());
406     }
407     return static_cast<int32_t>(ret);
408 }
409 
UnRegisterDisplayListenerWithType(const std::string & type,int64_t callbackId)410 DMError CJDisplayManager::UnRegisterDisplayListenerWithType(const std::string& type, int64_t callbackId)
411 {
412     TLOGD(WmsLogTag::DMS, "CJDisplayManager::UnRegisterDisplayListenerWithType is called");
413     if (CJDisplayManager::cjCbMap_.empty() ||
414         CJDisplayManager::cjCbMap_.find(type) == CJDisplayManager::cjCbMap_.end()) {
415         TLOGI(WmsLogTag::DMS, "UnRegisterDisplayListenerWithType methodName %{public}s not registered!", type.c_str());
416         return DMError::DM_OK;
417     }
418     std::lock_guard<std::mutex> lock(CJDisplayManager::mtx_);
419     DMError ret = DMError::DM_OK;
420     for (auto it = CJDisplayManager::cjCbMap_[type].begin(); it != CJDisplayManager::cjCbMap_[type].end();) {
421         if (it->first == callbackId) {
422             it->second->RemoveCallback(type, callbackId);
423             if (type == EVENT_ADD || type == EVENT_REMOVE || type == EVENT_CHANGE) {
424                 sptr<DisplayManager::IDisplayListener> thisListener(it->second);
425                 ret = SingletonContainer::Get<DisplayManager>().UnregisterDisplayListener(thisListener);
426             } else if (type == EVENT_PRIVATE_MODE_CHANGE) {
427                 sptr<DisplayManager::IPrivateWindowListener> thisListener(it->second);
428                 ret = SingletonContainer::Get<DisplayManager>().UnregisterPrivateWindowListener(thisListener);
429             } else if (type == EVENT_AVAILABLE_AREA_CHANGED) {
430                 sptr<DisplayManager::IAvailableAreaListener> thisListener(it->second);
431                 ret = SingletonContainer::Get<DisplayManager>().UnregisterAvailableAreaListener(thisListener);
432             } else if (type == EVENT_FOLD_STATUS_CHANGED) {
433                 sptr<DisplayManager::IFoldStatusListener> thisListener(it->second);
434                 ret = SingletonContainer::Get<DisplayManager>().UnregisterFoldStatusListener(thisListener);
435             } else if (type == EVENT_DISPLAY_MODE_CHANGED) {
436                 sptr<DisplayManager::IDisplayModeListener> thisListener(it->second);
437                 ret = SingletonContainer::Get<DisplayManager>().UnregisterDisplayModeListener(thisListener);
438             } else if (type == EVENT_FOLD_ANGLE_CHANGED) {
439                 sptr<DisplayManager::IFoldAngleListener> thisListener(it->second);
440                 ret = SingletonContainer::Get<DisplayManager>().UnregisterFoldAngleListener(thisListener);
441             } else if (type == EVENT_CAPTURE_STATUS_CHANGED) {
442                 sptr<DisplayManager::ICaptureStatusListener> thisListener(it->second);
443                 ret = SingletonContainer::Get<DisplayManager>().UnregisterCaptureStatusListener(thisListener);
444             } else {
445                 ret = DMError::DM_ERROR_INVALID_PARAM;
446             }
447             CJDisplayManager::cjCbMap_[type].erase(it++);
448             TLOGI(
449                 WmsLogTag::DMS, "Unregister display listener with type %{public}s  ret: %{public}u", type.c_str(), ret);
450             break;
451         } else {
452             it++;
453         }
454     }
455     if (CJDisplayManager::cjCbMap_[type].empty()) {
456         CJDisplayManager::cjCbMap_.erase(type);
457     }
458     return ret;
459 }
460 } // namespace Rosen
461 } // namespace OHOS
462