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 #include "application_env.h"
17 #include "application_env_impl.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /**
24  * @brief Obtains the bundle name of the application
25  * @param -
26  * @return Returns the pointer to the bundle name if the operation is successful; returns a null pointer otherwise.
27  */
GetBundleName()28 const char *GetBundleName()
29 {
30     OHOS::AppExecFwk::ApplicationEnvImpl *pApplicationEnvIml = OHOS::AppExecFwk::ApplicationEnvImpl::GetInstance();
31     const char *pBundleName = nullptr;
32 
33     if (pApplicationEnvIml) {
34         pBundleName = pApplicationEnvIml->GetBundleName().c_str();
35     }
36 
37     return pBundleName;
38 }
39 
40 /**
41  * @brief Obtains the source code path of this application.
42  * @param -
43  * @return Returns the pointer to the source code path of this application.
44  */
GetSrcPath()45 const char *GetSrcPath()
46 {
47     OHOS::AppExecFwk::ApplicationEnvImpl *pApplicationEnvIml = OHOS::AppExecFwk::ApplicationEnvImpl::GetInstance();
48     const char *pSrcPath = nullptr;
49 
50     if (pApplicationEnvIml) {
51         pSrcPath = pApplicationEnvIml->GetSrcPath().c_str();
52     }
53 
54     return pSrcPath;
55 }
56 
57 /**
58  * @brief Obtains the data path of this application.
59  * @param -
60  * @return Returns the pointer to the data path of this application.
61  */
GetDataPath()62 const char *GetDataPath()
63 {
64     OHOS::AppExecFwk::ApplicationEnvImpl *pApplicationEnvIml = OHOS::AppExecFwk::ApplicationEnvImpl::GetInstance();
65     const char *pDataPath = nullptr;
66 
67     if (pApplicationEnvIml) {
68         pDataPath = pApplicationEnvIml->GetDataPath().c_str();
69     }
70 
71     return pDataPath;
72 }
73 
74 #ifdef __cplusplus
75 }  // extern "C"
76 #endif
77