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 OHOS_ROSEN_FOLD_SCREEN_STATE_INTERNEL_H 17 #define OHOS_ROSEN_FOLD_SCREEN_STATE_INTERNEL_H 18 19 #include <sstream> 20 #include <parameters.h> 21 #include <regex> 22 namespace OHOS { 23 namespace Rosen { 24 namespace { 25 static const std::string g_foldScreenType = system::GetParameter("const.window.foldscreen.type", "0,0,0,0"); 26 static const std::string INVALID_DEVICE = "-1"; 27 static const std::string PORTRAIT_DEVICE = "0"; 28 static const std::string SINGLE_DISPLAY = "1"; 29 static const std::string DUAL_DISPLAY = "2"; 30 static const std::string SINGLE_POCKET_DISPLAY = "4"; 31 } 32 class FoldScreenStateInternel { 33 public: getFoldType()34 static std::string getFoldType() 35 { 36 if (!IsValidFoldType(g_foldScreenType)) { 37 return INVALID_DEVICE; 38 } 39 std::vector<std::string> foldTypes = StringSplit(g_foldScreenType, ','); 40 if (foldTypes.empty()) { 41 return INVALID_DEVICE; 42 } 43 return foldTypes[0]; 44 } 45 IsFoldScreenDevice()46 static bool IsFoldScreenDevice() 47 { 48 std::string foldType = getFoldType(); 49 return foldType != INVALID_DEVICE && foldType != PORTRAIT_DEVICE; 50 } 51 52 // is two logic screen device IsDualDisplayFoldDevice()53 static bool IsDualDisplayFoldDevice() 54 { 55 return getFoldType() == DUAL_DISPLAY; 56 } 57 58 // only one logic screen device IsSingleDisplayFoldDevice()59 static bool IsSingleDisplayFoldDevice() 60 { 61 // ALTB ccm property conflict with the chip, waiting for chip conflict resolution 62 return !IsDualDisplayFoldDevice(); 63 } 64 IsSingleDisplayPocketFoldDevice()65 static bool IsSingleDisplayPocketFoldDevice() 66 { 67 if (!IsValidFoldType(g_foldScreenType)) { 68 return false; 69 } 70 std::vector<std::string> foldTypes = StringSplit(g_foldScreenType, ','); 71 if (foldTypes.empty()) { 72 return false; 73 } 74 return foldTypes[0] == SINGLE_POCKET_DISPLAY; 75 } 76 StringSplit(const std::string & str,char delim)77 static std::vector<std::string> StringSplit(const std::string& str, char delim) 78 { 79 std::size_t previous = 0; 80 std::size_t current = str.find(delim); 81 std::vector<std::string> elems; 82 while (current != std::string::npos) { 83 if (current > previous) { 84 elems.push_back(str.substr(previous, current - previous)); 85 } 86 previous = current + 1; 87 current = str.find(delim, previous); 88 } 89 if (previous != str.size()) { 90 elems.push_back(str.substr(previous)); 91 } 92 return elems; 93 } 94 IsValidFoldType(const std::string & foldTypeStr)95 static bool IsValidFoldType(const std::string& foldTypeStr) 96 { 97 std::regex reg("^([0-9],){3}[0-9]{1}$"); 98 return std::regex_match(foldTypeStr, reg); 99 } 100 }; 101 } // Rosen 102 } // OHOS 103 #endif // OHOS_ROSEN_FOLD_SCREEN_STATE_INTERNEL_H