1 /* 2 * Copyright (c) 2025-2026 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 HWOSAPPID_H 16 #define HWOSAPPID_H 17 #include <string> 18 #include <vector> 19 #include "networksliceutil.h" 20 21 namespace OHOS { 22 namespace NetManagerStandard { 23 class HwOsAppId { 24 public: 25 static const int NUMBER_OF_APPID_WITHOUD_OSID_PARTS = 1; 26 static const int NUMBER_OF_APPID_PARTS = 2; 27 static const int INVALID_INDEX = -1; 28 static const std::string SEPARATOR_FOR_APPID; 29 HwOsAppId()30 HwOsAppId() : mOsId(""), mAppId("") {} 31 Create(const std::string & osAppId)32 static HwOsAppId Create(const std::string& osAppId) 33 { 34 if (osAppId.empty()) { 35 NETMGR_EXT_LOG_I("HwOsAppId return1"); 36 return HwOsAppId(); 37 } 38 39 std::vector<std::string> values = Split(osAppId, SEPARATOR_FOR_APPID); 40 if (values.size() == 0 || !((int)values.size() == NUMBER_OF_APPID_WITHOUD_OSID_PARTS || 41 (int)values.size() == NUMBER_OF_APPID_PARTS)) { 42 return HwOsAppId(); 43 } 44 45 HwOsAppId id; 46 if ((int)values.size() == NUMBER_OF_APPID_PARTS) { 47 id.mOsId = values[0]; 48 id.mAppId = values[1]; 49 } else { 50 id.mOsId = ""; 51 id.mAppId = values[0]; 52 } 53 NETMGR_EXT_LOG_I("HwOsAppId Create OsId = %{public}s, AppId = %{public}s", id.mOsId.c_str(), id.mAppId.c_str()); 54 return id; 55 } 56 getOsId()57 std::string getOsId() const 58 { 59 return mOsId; 60 } 61 getAppId()62 std::string getAppId() const 63 { 64 return mAppId; 65 } 66 67 bool operator==(const HwOsAppId& other) const 68 { 69 return mOsId == other.mOsId && mAppId == other.mAppId; 70 } 71 72 private: 73 std::string mOsId; 74 std::string mAppId; 75 }; 76 77 const inline std::string HwOsAppId::SEPARATOR_FOR_APPID = "#"; 78 } // namespace NetManagerStandard 79 } // namespace OHOS 80 #endif // HWOSAPPID_H 81