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_STUB_H 17 #define OHOS_GLOBAL_I18N_I18N_SERVICE_ABILITY_STUB_H 18 19 #include <map> 20 #include "i18n_types.h" 21 #include "ii18n_service_ability.h" 22 #include "iremote_stub.h" 23 #include "message_parcel.h" 24 #include "refbase.h" 25 26 namespace OHOS { 27 namespace Global { 28 namespace I18n { 29 class I18nServiceAbilityStub : public IRemoteStub<II18nServiceAbility> { 30 public: 31 I18nServiceAbilityStub(bool serialInvokeFlag = true); 32 ~I18nServiceAbilityStub(); 33 34 /** 35 * @brief Process request from i18n service proxy. Call request handling function corresponding request code. 36 * 37 * @param code Indicates request code. 38 * @param data Indicates request data. 39 * @param reply Indicates request reply. 40 * @param option Indicates request option. 41 * @return int32_t Indicates request status. 42 */ 43 int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 44 45 /** 46 * @brief Trigger unload i18n service after one request finished, but service will not unload 47 * until there no request in 10s. 48 */ 49 virtual void UnloadI18nServiceAbility() = 0; 50 51 private: 52 /** 53 * @brief Construct map from request codes to request handling functions. 54 */ 55 int32_t InvokeInnerFunc(uint32_t code, MessageParcel &data, MessageParcel &reply); 56 57 /** 58 * @brief Check whether caller's token type is system app or shell, and has UPDATE_CONFIGURATION permission. 59 * 60 * @return I18nErrorCode Return SUCCESS indicates that the caller has the permission 61 * to request i18n system api service. 62 */ 63 I18nErrorCode CheckPermission(); 64 65 // The following are the request handling functions. 66 int32_t SetSystemLanguageInner(MessageParcel &data, MessageParcel &reply); 67 int32_t SetSystemRegionInner(MessageParcel &data, MessageParcel &reply); 68 int32_t SetSystemLocaleInner(MessageParcel &data, MessageParcel &reply); 69 int32_t Set24HourClockInner(MessageParcel &data, MessageParcel &reply); 70 int32_t SetUsingLocalDigitInner(MessageParcel &data, MessageParcel &reply); 71 int32_t AddPreferredLanguageInner(MessageParcel &data, MessageParcel &reply); 72 int32_t RemovePreferredLanguageInner(MessageParcel &data, MessageParcel &reply); 73 }; 74 } // namespace I18n 75 } // namespace Global 76 } // namespace OHOS 77 #endif // OHOS_GLOBAL_I18N_I18N_SERVICE_ABILITY_STUB_H