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 <sys/stat.h> 17 namespace OHOS { 18 namespace AppExecFwk { 19 const std::string BUNDLE_DATA_ROOT_PATH = "/data/accounts/account_0/appdata/"; OnStart(const Want & want)20void PageAbilityDemo::OnStart(const Want &want) 21 { 22 APP_LOGI("PageAbilityDemo::onStart"); 23 Ability::OnStart(want); 24 const std::string appName = "com.third.hiworld.example2"; 25 const std::string testCacheDiR1 = BUNDLE_DATA_ROOT_PATH + appName + "/cache/testDir1"; 26 const std::string testCacheDiR2 = BUNDLE_DATA_ROOT_PATH + appName + "/cache/testDir2"; 27 CreateDir(testCacheDiR1); 28 CreateDir(testCacheDiR2); 29 } 30 OnNewWant(const Want & want)31void PageAbilityDemo::OnNewWant(const Want &want) 32 { 33 APP_LOGI("PageAbilityDemo::OnNewWant"); 34 Ability::OnNewWant(want); 35 } 36 OnForeground(const Want & want)37void PageAbilityDemo::OnForeground(const Want &want) 38 { 39 APP_LOGI("PageAbilityDemo::OnForeground"); 40 Ability::OnForeground(want); 41 } 42 OnStop()43void PageAbilityDemo::OnStop() 44 { 45 APP_LOGI("PageAbilityDemo::onStop"); 46 Ability::OnStop(); 47 } 48 OnActive()49void PageAbilityDemo::OnActive() 50 { 51 APP_LOGI("PageAbilityDemo::OnActive"); 52 Ability::OnActive(); 53 } 54 OnInactive()55void PageAbilityDemo::OnInactive() 56 { 57 APP_LOGI("PageAbilityDemo::OnInactive"); 58 Ability::OnInactive(); 59 } 60 OnBackground()61void PageAbilityDemo::OnBackground() 62 { 63 APP_LOGI("PageAbilityDemo::OnBackground"); 64 Ability::OnBackground(); 65 } 66 CreateDir(const std::string & path) const67void PageAbilityDemo::CreateDir(const std::string &path) const 68 { 69 if (access(path.c_str(), F_OK) != 0) { 70 if (mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) { 71 APP_LOGE("CreateDir:%{public}s error", path.c_str()); 72 } 73 } 74 } 75 76 REGISTER_AA(PageAbilityDemo) 77 } // namespace AppExecFwk 78 } // namespace OHOS