• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16import { AsyncCallback, BusinessError } from './basic';
17
18 /**
19 * The interface of system parameters class.
20 *
21 * @devices phone, tablet
22 * @since 6
23 * @Syscap SystemCapability.Startup.SysInfo
24 * @systemapi
25 */
26declare namespace systemParameter {
27    /**
28     * Gets the value of the attribute with the specified key.
29     *
30     * @param key Key of the system attribute.
31     * @param def Default value.
32     * @return if the parameter is empty or doesn't exist, empty string will be returned.
33     * @since 6
34     */
35    function getSync(key: string, def?: string): string;
36
37    /**
38     * Gets the value of the attribute with the specified key.
39     *
40     * @param key Key of the system attribute.
41     * @param callback Callback function.
42     * @since 6
43     */
44    function get(key: string, callback: AsyncCallback<string>): void;
45
46    /**
47     * Gets the value of the attribute with the specified key.
48     *
49     * @param key Key of the system attribute.
50     * @param def Default value.
51     * @param callback Callback function.
52     * @since 6
53     */
54    function get(key: string, def: string, callback: AsyncCallback<string>): void;
55
56    /**
57     * Gets the value of the attribute with the specified key.
58     *
59     * @param key Key of the system attribute.
60     * @param def Default value.
61     * @return Promise, which is used to obtain the result asynchronously.
62     * @since 6
63     */
64    function get(key: string, def?: string): Promise<string>;
65
66    /**
67     * Sets a value for the attribute with the specified key.
68     *
69     * @param key Key of the system attribute.
70     * @param value System attribute value to set.
71     * @since 6
72     */
73    function setSync(key: string, value: string): void;
74
75    /**
76     * Sets a value for the attribute with the specified key.
77     *
78     * @param key Key of the system attribute.
79     * @param value System attribute value to set.
80     * @param callback Callback function.
81     * @since 6
82     */
83    function set(key: string, value: string, callback: AsyncCallback<void>): void;
84
85    /**
86     * Sets a value for the attribute with the specified key.
87     *
88     * @param key Key of the system attribute.
89     * @param value Default value.
90     * @return Promise, which is used to obtain the result asynchronously.
91     * @since 6
92     */
93    function set(key: string, value: string): Promise<void>;
94
95    /**
96     * Wait for a parameter with specified value.
97     *
98     * @param key Key of the system parameter.
99     * @param value System parameter value to be wait.
100     * @param timeout Indicates the timeout value, in seconds.
101     * <=0 means wait for ever.
102     * >0 means wait for specified seconds
103     * @param callback Callback function.
104     * @since 7
105     */
106     function wait(key: string, value: string, timeout: number, callback: AsyncCallback<void>): void;
107
108     /**
109      * Sets a value for the parameter with the specified key.
110      *
111      * @param key Key of the system parameter.
112      * @param value System parameter value to be wait.
113      * @param timeout Indicates the timeout value, in seconds.
114      * <=0 means wait for ever.
115      * >0 means wait for specified seconds
116      * @return Promise, which is used to obtain the result asynchronously.
117      * @since 7
118      */
119     function wait(key: string, value: string, timeout: number): Promise<void>;
120
121     /**
122      * Wait for a parameter with specified value.
123      *
124      * @param keyPrefix Key prefix of the system parameters to be watched.
125      * @param callback Callback function.
126      * @since 7
127      */
128     function getWatcher(keyPrefix: string): Watcher;
129
130     /**
131      * Called when the system parameter value changes. You need to implement this method in a child class.
132      *
133      * @param key Indicates changed system parameter key name.
134      * @param value Indicates changed system parameter value.
135      * @since 7
136      */
137     export interface ParameterChangeCallback {
138         (key: string, value: string): void;
139     }
140
141     export interface Watcher {
142         /**
143          * Subscribe to parameter value changess
144          *
145          * @since 7
146          */
147         on(eventType: 'valueChange', callback: ParameterChangeCallback): void;
148         /**
149          * Unsubscribe to parameter value changess
150          *
151          * @since 7
152          */
153         off(eventType: 'valueChange', callback?: ParameterChangeCallback): void;
154     }
155}
156
157export default systemParameter;
158