diff --git a/api/@ohos.systemParameterV9.d.ts b/api/@ohos.systemParameterV9.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..ad0e5889ad6d0db3f01d5ad89f425933a8cda719 --- /dev/null +++ b/api/@ohos.systemParameterV9.d.ts @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AsyncCallback, BusinessError } from './basic'; + +/** + * Enumerates error code. + * + * @since 9 + */ +export enum SystemParameterErrorCode { + /** + * Input parameter is missing or invalid. + * + * @since 9 + */ + SYSPARAM_INVALID_INPUT = 401, + + /** + * System parameter can not be found.
+ * When getting system parameter values, if def value is specified, it will not return this error. + * + * @since 9 + */ + SYSPARAM_NOT_FOUND = 14700101, + + /** + * System parameter value is invalid.
+ * -

When setting system parameters, the value length should not exceed 95 bytes.

+ * -

And system parameter has three value types: string, integer and bool. + * if the value type is not matched, it will also return this error code.

+ * + * @since 9 + */ + SYSPARAM_INVALID_VALUE = 14700102, + + /** + * System permission operation permission denied.
+ *

System parameter are system resources, each parameter is protected by DAC and MAC rules. + *

Typical permission checking include:

+ * -

systemapi: only system application can call system parameter related APIs

+ * -

DAC: each system parameter has user and group owner with get, set permissions. + * Applications can only operate User/Group/Ownership matched system parameters.

+ * -

MAC: each system parameter is also protected by SELinux labels.

+ * + * @since 9 + */ + SYSPARAM_PERMISSION_DENIED = 14700103, + + /** + * System internal error including out of memory, deadlock etc. + * + * @since 9 + */ + SYSPARAM_SYSTEM_ERROR = 14700104, +} + + /** + * The interface of system parameters class. + * + * @since 9 + * @syscap SystemCapability.Startup.SystemInfo + * @systemapi Hide this for inner system use. + */ +declare namespace systemParameterV9 { + /** + * Gets the value of the attribute with the specified key. + * + * @param key Key of the system attribute. + * @param def Default value. + * @return the value of the parameter. + * @throws {BusinessError} with SYSPARAM_INVALID_INPUT if type of key is not string or key is not specified. + * @throws {BusinessError} with SYSPARAM_NOT_FOUND if key is not found + * @throws {BusinessError} with SYSPARAM_PERMISSION_DENIED if permission denied + * @throws {BusinessError} with SYSPARAM_SYSTEM_ERROR if system internal error + * @syscap SystemCapability.Startup.SystemInfo + * @since 9 + */ + function getSync(key: string, def?: string): string; + + /** + * Gets the value of the attribute with the specified key. + * + * @param key Key of the system attribute. + * @param callback Callback function. + * @throws {BusinessError} with SYSPARAM_INVALID_INPUT if type of key is not string or key is not specified. + * @throws {BusinessError} with SYSPARAM_NOT_FOUND if key is not found + * @throws {BusinessError} with SYSPARAM_PERMISSION_DENIED if permission denied + * @throws {BusinessError} with SYSPARAM_SYSTEM_ERROR if system internal error + * @syscap SystemCapability.Startup.SystemInfo + * @since 9 + */ + function get(key: string, callback: AsyncCallback): void; + + /** + * Gets the value of the attribute with the specified key. + * + * @param key Key of the system attribute. + * @param def Default value. + * @param callback Callback function. + * @throws {BusinessError} with SYSPARAM_INVALID_INPUT if type of key is not string or key is not specified. + * @throws {BusinessError} with SYSPARAM_NOT_FOUND if key is not found + * @throws {BusinessError} with SYSPARAM_PERMISSION_DENIED if permission denied + * @throws {BusinessError} with SYSPARAM_SYSTEM_ERROR if system internal error + * @syscap SystemCapability.Startup.SystemInfo + * @since 9 + */ + function get(key: string, def: string, callback: AsyncCallback): void; + + /** + * Gets the value of the attribute with the specified key. + * + * @param key Key of the system attribute. + * @param def Default value. + * @throws {BusinessError} with SYSPARAM_INVALID_INPUT if type of key is not string or key is not specified. + * @throws {BusinessError} with SYSPARAM_NOT_FOUND if key is not found + * @throws {BusinessError} with SYSPARAM_PERMISSION_DENIED if permission denied + * @throws {BusinessError} with SYSPARAM_SYSTEM_ERROR if system internal error + * @return Promise, which is used to obtain the result asynchronously. + * @syscap SystemCapability.Startup.SystemInfo + * @since 9 + */ + function get(key: string, def?: string): Promise; + + /** + * Sets a value for the attribute with the specified key. + * + * @param key Key of the system attribute. + * @param value System attribute value to set. + * @throws {BusinessError} with SYSPARAM_INVALID_INPUT if type of key is not string or key is not specified. + * @throws {BusinessError} with SYSPARAM_INVALID_VALUE if value is invalid + * @throws {BusinessError} with SYSPARAM_PERMISSION_DENIED if permission denied + * @throws {BusinessError} with SYSPARAM_SYSTEM_ERROR if system internal error + * @syscap SystemCapability.Startup.SystemInfo + * @since 9 + */ + function setSync(key: string, value: string): void; + + /** + * Sets a value for the attribute with the specified key. + * + * @param key Key of the system attribute. + * @param value System attribute value to set. + * @param callback Callback function. + * @throws {BusinessError} with SYSPARAM_INVALID_INPUT if type of key is not string or key is not specified. + * @throws {BusinessError} with SYSPARAM_INVALID_VALUE if value is invalid + * @throws {BusinessError} with SYSPARAM_PERMISSION_DENIED if permission denied + * @throws {BusinessError} with SYSPARAM_SYSTEM_ERROR if system internal error + * @syscap SystemCapability.Startup.SystemInfo + * @since 9 + */ + function set(key: string, value: string, callback: AsyncCallback): void; + + /** + * Sets a value for the attribute with the specified key. + * + * @param key Key of the system attribute. + * @param value Default value. + * @return Promise, which is used to obtain the result asynchronously. + * @throws {BusinessError} with SYSPARAM_INVALID_INPUT if type of key is not string or key is not specified. + * @throws {BusinessError} with SYSPARAM_INVALID_VALUE if value is invalid + * @throws {BusinessError} with SYSPARAM_PERMISSION_DENIED if permission denied + * @throws {BusinessError} with SYSPARAM_SYSTEM_ERROR if system internal error + * @syscap SystemCapability.Startup.SystemInfo + * @since 9 + */ + function set(key: string, value: string): Promise; +} + +export default systemParameter;