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 #ifndef SERVICES_INCLUDE_GLOBAL_H 17 #define SERVICES_INCLUDE_GLOBAL_H 18 19 #include <errno.h> 20 #include <sys/time.h> 21 #include <time.h> 22 23 #include "hilog/log.h" 24 #include "ipc_object_stub.h" 25 #include "iremote_broker.h" 26 #include "peer_holder.h" 27 #include "refbase.h" 28 29 namespace OHOS { 30 namespace MiscServices { 31 #define PLATFORM OHOS 32 33 using BRemoteObject = IPCObjectStub; 34 35 #define LOG_INFO(fmt, args...) \ 36 LogTimeStamp(); printf("I %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args) 37 38 #define LOG_ERROR(fmt, args...) \ 39 LogTimeStamp(); printf("E %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args) 40 41 #define LOG_WARNING(fmt, args...) \ 42 LogTimeStamp(); printf("W %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args) 43 44 #if DEBUG 45 #define LOG_DEBUG(fmt, args...) \ 46 LogTimeStamp(); printf("D %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args) 47 #else 48 #define LOG_DEBUG(fmt, args...) 49 #endif 50 51 void LogTimeStamp(); 52 53 namespace CommonEvent { 54 // the events handled in input method management system 55 enum { 56 COMMON_EVENT_USER_STARTED = 10001, // a user is started. 57 COMMON_EVENT_USER_STOPPED = 10002, // a user is stopped. 58 COMMON_EVENT_USER_UNLOCKED = 10003, // a user is unlocked. 59 COMMON_EVENT_USER_LOCKED = 10004, // a user is locked. 60 COMMON_EVENT_SETTING_CHANGED = 10005, // input method setting data is changed. 61 COMMON_EVENT_PACKAGE_ADDED = 10006, // a package is installed. 62 COMMON_EVENT_PACKAGE_REMOVED = 10007, // a package is removed 63 }; 64 }; // namespace CommonEvent 65 66 // User State 67 namespace UserState { 68 // The states of a user in the system. 69 enum { 70 USER_STATE_NOT_AVAILABLE = -1, 71 USER_STATE_STARTED = 0, // a user is started. 72 USER_STATE_UNLOCKED, // a user is unlocked. 73 }; 74 }; // namespace UserState 75 76 // Error Code 77 namespace ErrorCode { 78 // Error Code definition in the input method management system 79 enum { 80 ERROR_STATUS_UNKNOWN_ERROR = (-2147483647 - 1), // unknown error 81 ERROR_STATUS_NO_MEMORY = -ENOMEM, // no memory 82 ERROR_STATUS_INVALID_OPERATION = -ENOSYS, // invalid operation 83 ERROR_STATUS_BAD_VALUE = -EINVAL, // bad value 84 ERROR_STATUS_BAD_TYPE = ERROR_STATUS_UNKNOWN_ERROR + 1, // bad type 85 ERROR_STATUS_NAME_NOT_FOUND = -ENOENT, // name not found 86 ERROR_STATUS_PERMISSION_DENIED = -EPERM, // permission denied 87 ERROR_STATUS_NO_INIT = -ENODEV, // no init 88 ERROR_STATUS_ALREADY_EXISTS = -EEXIST, // already exist 89 ERROR_STATUS_DEAD_OBJECT = -EPIPE, // dead object 90 ERROR_STATUS_FAILED_TRANSACTION = ERROR_STATUS_UNKNOWN_ERROR + 2, // failed transaction 91 ERROR_STATUS_BAD_INDEX = -EOVERFLOW, // bad index 92 ERROR_STATUS_NOT_ENOUGH_DATA = -ENODATA, // not enough data 93 ERROR_STATUS_WOULD_BLOCK = -EWOULDBLOCK, // would block 94 ERROR_STATUS_TIMED_OUT = -ETIMEDOUT, // time out 95 ERROR_STATUS_UNKNOWN_TRANSACTION = -EBADMSG, // unknown transaction 96 ERROR_STATUS_FDS_NOT_ALLOWED = ERROR_STATUS_UNKNOWN_ERROR + 7, // fds not allowed 97 ERROR_STATUS_UNEXPECTED_NULL = ERROR_STATUS_UNKNOWN_ERROR + 8, // unexpected null, 98 99 // binder exception error code from Status.h 100 ERROR_EX_ILLEGAL_ARGUMENT = -3, // illegal argument exception 101 ERROR_EX_NULL_POINTER = -4, // null pointer exception 102 ERROR_EX_ILLEGAL_STATE = -5, // illegal state exception 103 ERROR_EX_NETWORK_MAIN_THREAD = -6, // network main thread exception 104 ERROR_EX_UNSUPPORTED_OPERATION = -7, // unsupported operation exception 105 ERROR_EX_SERVICE_SPECIFIC = -8, // service specific exception 106 ERROR_EX_PARCELABLE = -9, // parcelable exception 107 // no error 108 NO_ERROR = 0, // no error 109 110 // system service error 111 ERROR_NULL_POINTER = 1, // null pointer 112 ERROR_BAD_PARAMETERS = 2, // bad parameters 113 ERROR_USER_NOT_STARTED = 3, // user is not started 114 ERROR_USER_ALREADY_STARTED = 4, // user has already started 115 ERROR_USER_NOT_UNLOCKED = 5, // user is not unlocked 116 ERROR_USER_ALREADY_UNLOCKED = 6, // user has already unlocked 117 ERROR_USER_NOT_LOCKED = 7, // user is not locked 118 119 ERROR_IME_NOT_AVAILABLE = 8, // input method engine is not available 120 ERROR_SECURITY_IME_NOT_AVAILABLE = 9, // security input method engine is not available 121 ERROR_TOKEN_CREATE_FAILED = 10, // failed to create window token 122 ERROR_TOKEN_DESTROY_FAILED = 11, // failed to destroy window token 123 ERROR_IME_BIND_FAILED = 12, // failed to bind IME service 124 ERROR_IME_UNBIND_FAILED = 13, // failed to unbind IME service 125 ERROR_IME_START_FAILED = 14, // failed to start IME service 126 ERROR_KBD_SHOW_FAILED = 15, // failed to show keyboard 127 ERROR_KBD_HIDE_FAILED = 16, // failed to hide keyboard 128 ERROR_IME_NOT_STARTED = 17, // input method service is not started 129 ERROR_KBD_IS_OCCUPIED = 18, // keyboard is showing by other client 130 ERROR_KBD_IS_NOT_SHOWING = 19, // keyboard is not showing 131 ERROR_NOT_IME_PACKAGE = 20, // not an IME package 132 ERROR_IME_PACKAGE_DUPLICATED = 21, // duplicated IME package 133 ERROR_SETTING_SAME_VALUE = 22, // same setting value 134 ERROR_ADD_CLIENT_FAILED = 23, // add client failed 135 ERROR_SWITCH_IME = 24, 136 // error from ime 137 ERROR_REMOTE_IME_DIED = 25, // remote input method service died abnormally 138 // error from client 139 ERROR_REMOTE_CLIENT_DIED = 26, // remote client died abnormally 140 ERROR_CLIENT_NOT_FOUND = 27, // client is not found 141 ERROR_CLIENT_NULL_POINTER = 28, // null pointer 142 ERROR_SUBSCRIBE_KEYBOARD_EVENT = 29, 143 ERROR_CONTROLLER_INVOKING_FAILED = 30, 144 ERROR_PERSIST_CONFIG = 31, 145 ERROR_PACKAGE_MANAGER = 32, 146 ERROR_SERVICE_START_FAILED = 33, 147 ERROR_NOT_CURRENT_IME = 34, 148 }; 149 const char *ToString(int errorCode); 150 }; // namespace ErrorCode 151 152 static constexpr HiviewDFX::HiLogLabel g_SMALL_SERVICES_LABEL = { 153 LOG_CORE, 154 0xD001C00, 155 "ImsaKit" 156 }; 157 158 #define IMSA_HILOGD(fmt, ...) (void)OHOS::HiviewDFX::HiLog::Debug(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \ 159 "line: %{public}d, function: %{public}s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__) 160 #define IMSA_HILOGE(fmt, ...) (void)OHOS::HiviewDFX::HiLog::Error(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \ 161 "line: %{public}d, function: %{public}s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__) 162 #define IMSA_HILOGF(fmt, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \ 163 "line: %{public}d, function: %{public}s," fmt, __LINE__FILE__, __FUNCTION__, ##__VA_ARGS__) 164 #define IMSA_HILOGI(fmt, ...) (void)OHOS::HiviewDFX::HiLog::Info(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \ 165 "line: %{public}d, function: %{public}s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__) 166 #define IMSA_HILOGW(fmt, ...) (void)OHOS::HiviewDFX::HiLog::Warn(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \ 167 "line: %{public}d, function: %{public}s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__) 168 } // namespace MiscServices 169 } // namespace OHOS 170 #endif // SERVICES_INCLUDE_GLOBAL_H 171