• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "app_utils.h"
17 
18 #include "hilog_wrapper.h"
19 #include "parameters.h"
20 #include "scene_board_judgement.h"
21 
22 namespace OHOS {
23 namespace AAFwk {
24 namespace {
25 const std::string BUNDLE_NAME_LAUNCHER = "com.ohos.launcher";
26 const std::string BUNDLE_NAME_SCENEBOARD = "com.ohos.sceneboard";
27 const std::string LAUNCHER_ABILITY_NAME = "com.ohos.launcher.MainAbility";
28 const std::string SCENEBOARD_ABILITY_NAME = "com.ohos.sceneboard.MainAbility";
29 const std::string DEVICE_2IN1 = "2in1";
30 const std::string DEVICE_PC = "pc";
31 const std::string DEVICE_TABLET = "tablet";
32 }
~AppUtils()33 AppUtils::~AppUtils() {}
34 
AppUtils()35 AppUtils::AppUtils()
36 {
37     if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
38         isSceneBoard_ = true;
39     }
40     auto deviceType = system::GetDeviceType();
41     if (deviceType == DEVICE_2IN1 || deviceType == DEVICE_PC) {
42         isPcDevice_ = true;
43     }
44     if (isPcDevice_ || deviceType == DEVICE_TABLET) {
45         isMultiProcessModel_ = true;
46     }
47 }
48 
GetInstance()49 AppUtils &AppUtils::GetInstance()
50 {
51     static AppUtils utils;
52     return utils;
53 }
54 
IsLauncher(const std::string & bundleName) const55 bool AppUtils::IsLauncher(const std::string &bundleName) const
56 {
57     if (isSceneBoard_) {
58         return bundleName == BUNDLE_NAME_SCENEBOARD;
59     }
60 
61     return bundleName == BUNDLE_NAME_LAUNCHER;
62 }
63 
IsLauncherAbility(const std::string & abilityName) const64 bool AppUtils::IsLauncherAbility(const std::string &abilityName) const
65 {
66     if (isSceneBoard_) {
67         return abilityName == SCENEBOARD_ABILITY_NAME;
68     }
69 
70     return abilityName == LAUNCHER_ABILITY_NAME;
71 }
72 
JudgePCDevice() const73 bool AppUtils::JudgePCDevice() const
74 {
75     return isPcDevice_;
76 }
77 
isMultiProcessModel() const78 bool AppUtils::isMultiProcessModel() const
79 {
80     return isMultiProcessModel_;
81 }
82 }  // namespace AAFwk
83 }  // namespace OHOS
84