• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 FOUNDATION_APPEXECFWK_OHOS_ABILITY_PROCESS_H
17 #define FOUNDATION_APPEXECFWK_OHOS_ABILITY_PROCESS_H
18 
19 #include <mutex>
20 #include "feature_ability.h"
21 #include "napi_context.h"
22 
23 namespace OHOS {
24 namespace AppExecFwk {
25 /**
26  * @class AbilityProcess
27  * Provides the feature ability function.
28  */
29 class AbilityProcess {
30 public:
31     AbilityProcess();
32     virtual ~AbilityProcess();
33     static std::shared_ptr<AbilityProcess> GetInstance();
34 
35     void StartAbility(Ability *ability, CallAbilityParam param, CallbackInfo callbackInfo);
36     void OnAbilityResult(Ability *ability, int requestCode, int resultCode, const Want &resultData);
37 
38     void RequestPermissionsFromUser(Ability *ability, CallAbilityPermissionParam &param, CallbackInfo callbackInfo);
39     void OnRequestPermissionsFromUserResult(Ability *ability, int requestCode,
40         const std::vector<std::string> &permissions, const std::vector<int> &grantResults);
41 
42 private:
43     static std::mutex mutex_;
44     static std::shared_ptr<AbilityProcess> instance_;
45     static std::map<Ability *, std::map<int, CallbackInfo>> abilityResultMap_;
46     static std::map<Ability *, std::map<int, CallbackInfo>> abilityRequestPermissionsForUserMap_;
47 };
48 }  // namespace AppExecFwk
49 }  // namespace OHOS
50 #endif  // FOUNDATION_APPEXECFWK_OHOS_ABILITY_PROCESS_H