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 #define LOG_TAG "ProcessUserCrossStrategy"
16 #include "process_single_app_user_cross_strategy.h"
17
18 #include "bundlemgr/bundle_mgr_client.h"
19 #include "check_is_single_app_strategy.h"
20 #include "empty_strategy.h"
21 #include "log_print.h"
22
23 namespace OHOS::DataShare {
ProcessSingleAppUserCrossStrategy()24 ProcessSingleAppUserCrossStrategy::ProcessSingleAppUserCrossStrategy()
25 : DivStrategy(std::make_shared<CheckIsSingleAppStrategy>(), std::make_shared<ProcessUserCrossStrategy>(),
26 std::make_shared<EmptyStrategy>())
27 {
28 }
29
operator ()(std::shared_ptr<Context> context)30 bool ProcessUserCrossStrategy::operator()(std::shared_ptr<Context> context)
31 {
32 if (context->accessSystemMode == UNDEFINED) {
33 ZLOGE("single app must config user cross mode, please check it, bundleName: %{public}s",
34 context->calledBundleName.c_str());
35 return false;
36 }
37 if (context->accessSystemMode == USER_SINGLE_MODE) {
38 context->calledTableName.append("_").append(std::to_string(context->currentUserId));
39 return true;
40 }
41 return true;
42 }
43 } // namespace OHOS::DataShare