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 16 #ifndef OHOS_GLOBAL_I18N_I18N_SERVICE_ABILITY_H 17 #define OHOS_GLOBAL_I18N_I18N_SERVICE_ABILITY_H 18 19 #include "event_handler.h" 20 #include "i18n_service_ability_stub.h" 21 #include "system_ability.h" 22 23 namespace OHOS { 24 namespace Global { 25 namespace I18n { 26 class I18nServiceAbility : public SystemAbility, public I18nServiceAbilityStub { 27 DECLARE_SYSTEM_ABILITY(I18nServiceAbility); 28 public: 29 DISALLOW_COPY_AND_MOVE(I18nServiceAbility); 30 I18nServiceAbility(int32_t saId, bool runOnCreate); 31 ~I18nServiceAbility(); 32 33 // The following are the i18n service implement functions. 34 I18nErrorCode SetSystemLanguage(const std::string &language) override; 35 I18nErrorCode SetSystemRegion(const std::string ®ion) override; 36 I18nErrorCode SetSystemLocale(const std::string &locale) override; 37 I18nErrorCode Set24HourClock(const std::string &flag) override; 38 I18nErrorCode SetUsingLocalDigit(bool flag) override; 39 I18nErrorCode AddPreferredLanguage(const std::string &language, int32_t index) override; 40 I18nErrorCode RemovePreferredLanguage(int32_t index) override; 41 /** 42 * @brief Trigger unload i18n service after one request finished, but service will not unload 43 * until there no request in 10s. 44 */ 45 void UnloadI18nServiceAbility() override; 46 47 protected: 48 /** 49 * @brief Called when i18n service start. 50 */ 51 void OnStart() override; 52 53 /** 54 * @brief Called when i18n service stop. 55 */ 56 void OnStop() override; 57 58 private: 59 // i18n service unload event handler. 60 std::shared_ptr<AppExecFwk::EventHandler> handler; 61 }; 62 } // namespace I18n 63 } // namespace Global 64 } // namespace OHOS 65 #endif // OHOS_GLOBAL_I18N_I18N_SERVICE_ABILITY_H