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 #include "pageAbilityDemo.h"
16 #include <fcntl.h>
17 #include <fstream>
18 namespace OHOS {
19 namespace AppExecFwk {
20 const std::string BUNDLE_DATA_ROOT_PATH = "/data/app/el2/100/base/";
OnStart(const Want & want,sptr<AAFwk::SessionInfo> sessionInfo)21 void PageAbilityDemo::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
22 {
23 APP_LOGI("PageAbilityDemo::onStart");
24 Ability::OnStart(want, sessionInfo);
25 const std::string appName = "com.third.hiworld.example1";
26 const std::string testCacheFileNamE1 = BUNDLE_DATA_ROOT_PATH + appName + "/cache/name1.txt";
27 const std::string testCacheFileNamE2 = BUNDLE_DATA_ROOT_PATH + appName + "/cache/name2.txt";
28 CreateFile(testCacheFileNamE1);
29 CreateFile(testCacheFileNamE2);
30 }
31
OnNewWant(const Want & want)32 void PageAbilityDemo::OnNewWant(const Want &want)
33 {
34 APP_LOGI("PageAbilityDemo::OnNewWant");
35 Ability::OnNewWant(want);
36 }
37
OnForeground(const Want & want)38 void PageAbilityDemo::OnForeground(const Want &want)
39 {
40 APP_LOGI("PageAbilityDemo::OnForeground");
41 Ability::OnForeground(want);
42 }
43
OnStop()44 void PageAbilityDemo::OnStop()
45 {
46 APP_LOGI("PageAbilityDemo::onStop");
47 Ability::OnStop();
48 }
49
OnActive()50 void PageAbilityDemo::OnActive()
51 {
52 APP_LOGI("PageAbilityDemo::OnActive");
53 Ability::OnActive();
54 }
55
OnInactive()56 void PageAbilityDemo::OnInactive()
57 {
58 APP_LOGI("PageAbilityDemo::OnInactive");
59 Ability::OnInactive();
60 }
61
OnBackground()62 void PageAbilityDemo::OnBackground()
63 {
64 APP_LOGI("PageAbilityDemo::OnBackground");
65 Ability::OnBackground();
66 }
67
CreateFile(const std::string & path) const68 void PageAbilityDemo::CreateFile(const std::string &path) const
69 {
70 std::ofstream file(path);
71 file.close();
72
73 if (access(path.c_str(), F_OK) != 0) {
74 APP_LOGE("CreateFile-checkFile:%{private}s not exist", path.c_str());
75 }
76 }
77
78 REGISTER_AA(PageAbilityDemo)
79 } // namespace AppExecFwk
80 } // namespace OHOS