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 "utils/window_options_utils.h"
17
18 #include "ability_record.h"
19 #include "app_utils.h"
20
21 namespace OHOS {
22 namespace AAFwk {
SetWindowPositionAndSize(Want & want,const sptr<IRemoteObject> & callerToken,const StartOptions & startOptions)23 void WindowOptionsUtils::SetWindowPositionAndSize(Want& want,
24 const sptr<IRemoteObject>& callerToken, const StartOptions& startOptions)
25 {
26 if (!AppUtils::GetInstance().IsStartOptionsWithAnimation()) {
27 return;
28 }
29 if (startOptions.windowLeftUsed_) {
30 want.SetParam(Want::PARAM_RESV_WINDOW_LEFT, startOptions.GetWindowLeft());
31 }
32 if (startOptions.windowTopUsed_) {
33 want.SetParam(Want::PARAM_RESV_WINDOW_TOP, startOptions.GetWindowTop());
34 }
35 if (startOptions.windowWidthUsed_) {
36 want.SetParam(Want::PARAM_RESV_WINDOW_WIDTH, startOptions.GetWindowWidth());
37 }
38 if (startOptions.windowHeightUsed_) {
39 want.SetParam(Want::PARAM_RESV_WINDOW_HEIGHT, startOptions.GetWindowHeight());
40 }
41 bool withAnimation = startOptions.GetWithAnimation();
42 auto abilityRecord = Token::GetAbilityRecordByToken(callerToken);
43 if (!withAnimation && abilityRecord != nullptr &&
44 abilityRecord->GetAbilityInfo().bundleName == want.GetBundle()) {
45 want.SetParam(Want::PARAM_RESV_WITH_ANIMATION, withAnimation);
46 }
47 }
48
WindowModeMap(int32_t windowMode)49 std::pair<bool, AppExecFwk::SupportWindowMode> WindowOptionsUtils::WindowModeMap(int32_t windowMode)
50 {
51 std::pair<bool, AppExecFwk::SupportWindowMode> result(false, AppExecFwk::SupportWindowMode::FULLSCREEN);
52
53 if (windowMode == MULTI_WINDOW_DISPLAY_FULLSCREEN) {
54 result.first = true;
55 result.second = AppExecFwk::SupportWindowMode::FULLSCREEN;
56 } else if (windowMode == MULTI_WINDOW_DISPLAY_PRIMARY) {
57 result.first = true;
58 result.second = AppExecFwk::SupportWindowMode::SPLIT;
59 } else if (windowMode == MULTI_WINDOW_DISPLAY_SECONDARY) {
60 result.first = true;
61 result.second = AppExecFwk::SupportWindowMode::SPLIT;
62 } else if (windowMode == MULTI_WINDOW_DISPLAY_FLOATING) {
63 result.first = true;
64 result.second = AppExecFwk::SupportWindowMode::FLOATING;
65 }
66 return result;
67 }
68 } // namespace AAFwk
69 } // namespace OHOS
70