• 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 } from './basic'
17
18declare namespace rpc {
19    /**
20     * A data object used for reomote procedure call (RPC).
21     * <p>
22     * During RPC, the sender can use the write methods provided by {@link MessageParcel} to
23     * write the to-be-sent data into a {@link MessageParcel} object in a specific format, and the receiver can use the
24     * read methods provided by {@link MessageParcel} to read data of the specific format from the {@link MessageParcel} object.
25     * <p>
26     * <p>
27     * The default capacity of a {@link MessageParcel} instance is 200KB. If you want more or less, use {@link #setCapacity(int)}
28     * to change it.
29     * </p>
30     * <b>Note</b>: Only data of the following data types can be written into or read from a {@link MessageParcel}: byte,
31     * byteArray, short, shortArray, int, intArray, long, longArray, float, floatArray, double, doubleArray, boolean,
32     * booleanArray, char, charArray, String, StringArray, {@link IRemoteObject}, IRemoteObjectArray,
33     * {@link Sequenceable}, and SequenceableArray.
34     *
35     * @since 7
36     * @syscap SystemCapability.Communication.IPC.Core
37     * @import import rpc from '@ohos.rpc'
38     */
39    class MessageParcel {
40        /**
41         * Creates an empty {@link MessageParcel} object.
42         * @return Returns the object created.
43         * @since 7
44         */
45        static create(): MessageParcel;
46
47        /**
48         * Reclaims the {@link MessageParcel} object.
49         * @since 7
50         */
51        reclaim(): void;
52
53        /**
54         * Serializes a remote object and writes it to the {@link MessageParcel} object.
55         * @param object Remote object to serialize.
56         * @return Returns true if it is successful; returns false otherwise.
57         * @since 7
58         */
59        writeRemoteObject(object: IRemoteObject): boolean;
60
61        /**
62         * Reads a remote object from {@link MessageParcel} object.
63         * @return Returns the remote object.
64         * @since 7
65         */
66        readRemoteObject(): IRemoteObject;
67
68        /**
69         * Writes an interface token into the {@link MessageParcel} object.
70         * @param token Interface descriptor to write.
71         * @return Returns {@code true} if the interface token has been written into the {@link MessageParcel};
72         *         returns {@code false} otherwise.
73         * @since 7
74         */
75        writeInterfaceToken(token: string): boolean;
76
77        /**
78         * Reads an interface token from the {@link MessageParcel} object.
79         * @return Returns a string value.
80         * @since 7
81         */
82        readInterfaceToken(): string;
83
84        /**
85         * Obtains the size of data (in bytes) contained in the {@link MessageParcel} object.
86         * @return Returns the size of data contained in the {@link MessageParcel} object.
87         * @since 7
88         */
89        getSize(): number;
90
91        /**
92         * Obtains the storage capacity (in bytes) of the {@link MessageParcel} object.
93         * @return Returns the storage capacity of the {@link MessageParcel} object.
94         * @since 7
95         */
96        getCapacity(): number;
97
98        /**
99         * Sets the size of data (in bytes) contained in the {@link MessageParcel} object.
100         * <p>{@code false} is returned if the data size set in this method is greater
101         * than the storage capacity of the {@link MessageParcel}.
102         *
103         * @param size Indicates the data size of the {@link MessageParcel} object.
104         * @return Returns {@code true} if the setting is successful; returns {@code false} otherwise.
105         * @since 7
106         */
107        setSize(size: number): boolean;
108
109        /**
110         * Sets the storage capacity (in bytes) of the {@link MessageParcel} object.
111         * <p>{@code false} is returned if the capacity set in this method is less than
112         * the size of data contained in the {@link MessageParcel}.
113         *
114         * @param size Indicates the storage capacity of the {@link MessageParcel} object.
115         * @return Returns {@code true} if the setting is successful; returns {@code false} otherwise.
116         * @since 7
117         */
118        setCapacity(size: number): boolean;
119
120        /**
121         * Obtains the writable data space (in bytes) in the {@link MessageParcel} object.
122         * <p>Writable data space = Storage capacity of the {@link MessageParcel} – Size of data contained in the {@link MessageParcel}.
123         *
124         * @return Returns the writable data space of the {@link MessageParcel} object.
125         * @since 7
126         */
127        getWritableBytes(): number;
128
129        /**
130         * Obtains the readable data space (in bytes) in the {@link MessageParcel} object.
131         * <p>Readable data space = Size of data contained in the {@link MessageParcel} – Size of data that has been read.
132         *
133         * @return Returns the readable data space of the {@link MessageParcel} object.
134         * @since 7
135         */
136        getReadableBytes(): number;
137
138        /**
139         * Obtains the current read position in the {@link MessageParcel} object.
140         * @return Returns the current read position in the {@link MessageParcel} object.
141         * @since 7
142         */
143        getReadPosition(): number;
144
145        /**
146         * Obtains the current write position in the {@link MessageParcel} object.
147         * @return Returns the current write position in the {@link MessageParcel} object.
148         * @since 7
149         */
150        getWritePosition(): number;
151
152        /**
153         * Changes the current read position in the {@link MessageParcel} object.
154         * <p>Generally, you are advised not to change the current read position. If you must
155         * change it, change it to an accurate position. Otherwise, the read data may be incorrect.
156         *
157         * @param pos Indicates the target position to start data reading.
158         * @return Returns {@code true} if the read position is changed; returns {@code false} otherwise.
159         * @since 7
160         */
161        rewindRead(pos: number): boolean;
162
163        /**
164         * Changes the current write position in the {@link MessageParcel} object.
165         * <p>Generally, you are advised not to change the current write position. If you must
166         * change it, change it to an accurate position. Otherwise, the data to be read may be incorrect.
167         *
168         * @param pos Indicates the target position to start data writing.
169         * @return Returns {@code true} if the write position is changed; returns {@code false} otherwise.
170         * @since 7
171         */
172        rewindWrite(pos: number): boolean;
173
174        /**
175         * Writes information to this MessageParcel object indicating that no exception occurred.
176         * <p>After handling requests, you should call this method before writing any data to reply {@link MessageParcel}.
177         * @since 8
178         */
179        writeNoException(): void;
180
181        /**
182         * Reads the exception information from this MessageParcel object.
183         * <p>If exception was thrown in server side, it will be thrown here.
184         * This method should be called before reading any data from reply {@link MessageParcel}
185         * if {@link writeNoException} was invoked in server side.
186         * @throws Throws an exception if it thrown in server side.
187         * @since 8
188         */
189        readException(): void;
190
191        /**
192         * Writes a byte value into the {@link MessageParcel} object.
193         * @param val Indicates the byte value to write.
194         * @return Returns {@code true} if the value has been written into the {@link MessageParcel};
195         *         returns {@code false} otherwise.
196         * @throws ParcelException When capacity in this parcel is insufficient,
197         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
198         * @since 7
199         */
200        writeByte(val: number): boolean;
201
202        /**
203         * Writes a short integer value into the {@link MessageParcel} object.
204         * @param val Indicates the short integer value to write.
205         * @return Returns {@code true} if the value has been written into the {@link MessageParcel};
206         *         returns {@code false} otherwise.
207         * @throws ParcelException When capacity in this parcel is insufficient,
208         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
209         * @since 7
210         */
211        writeShort(val: number): boolean;
212
213        /**
214         * Writes an integer value into the {@link MessageParcel} object.
215         * @param val Indicates the integer value to write.
216         * @return Returns {@code true} if the value has been written into the {@link MessageParcel};
217         *         returns {@code false} otherwise.
218         * @throws ParcelException When capacity in this parcel is insufficient,
219         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
220         * @since 7
221         */
222        writeInt(val: number): boolean;
223
224        /**
225         * Writes a long integer value into the {@link MessageParcel} object.
226         * @param val Indicates the long integer value to write.
227         * @return Returns {@code true} if the value has been written into the {@link MessageParcel};
228         *         returns {@code false} otherwise.
229         * @throws ParcelException When capacity in this parcel is insufficient,
230         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
231         * @since 7
232         */
233        writeLong(val: number): boolean;
234
235        /**
236         * Writes a floating point value into the {@link MessageParcel} object.
237         * @param val Indicates the floating point value to write.
238         * @return Returns {@code true} if the value has been written into the {@link MessageParcel};
239         *         returns {@code false} otherwise.
240         * @throws ParcelException When capacity in this parcel is insufficient,
241         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
242         * @since 7
243         */
244        writeFloat(val: number): boolean;
245
246        /**
247         * Writes a double-precision floating point value into the {@link MessageParcel} object.
248         * @param val Indicates the double-precision floating point value to write.
249         * @return Returns {@code true} if the value has been written into the {@link MessageParcel};
250         *         returns {@code false} otherwise.
251         * @throws ParcelException When capacity in this parcel is insufficient,
252         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
253         * @since 7
254         */
255        writeDouble(val: number): boolean;
256
257        /**
258         * Writes a boolean value into the {@link MessageParcel} object.
259         * @param val Indicates the boolean value to write.
260         * @return Returns {@code true} if the value has been written into the {@link MessageParcel};
261         *         returns {@code false} otherwise.
262         * @throws ParcelException When capacity in this parcel is insufficient,
263         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
264         * @since 7
265         */
266        writeBoolean(val: boolean): boolean;
267
268        /**
269         * Writes a single character value into the {@link MessageParcel} object.
270         * @param val Indicates the single character value to write.
271         * @return Returns {@code true} if the value has been written into the {@link MessageParcel};
272         *         returns {@code false} otherwise.
273         * @throws ParcelException When capacity in this parcel is insufficient,
274         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
275         * @since 7
276         */
277        writeChar(val: number): boolean;
278
279        /**
280         * Writes a string value into the {@link MessageParcel} object.
281         * @param val Indicates the string value to write.
282         * @return Returns {@code true} if the value has been written into the {@link MessageParcel};
283         *         returns {@code false} otherwise.
284         * @throws ParcelException When capacity in this parcel is insufficient,
285         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
286         * @since 7
287         */
288        writeString(val: string): boolean;
289
290        /**
291         * Writes a {@link Sequenceable} object into the {@link MessageParcel} object.
292         * @param val Indicates the {@link Sequenceable} object to write.
293         * @throws ParcelException When capacity in this parcel is insufficient,
294         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
295         * @since 7
296         */
297        writeSequenceable(val: Sequenceable): boolean;
298
299        /**
300         * Writes a byte array into the {@link MessageParcel} object.
301         * @param byteArray Indicates the byte array to write.
302         * @return Returns {@code true} if the array has been written into the {@link MessageParcel};
303         *         returns {@code false} otherwise.
304         * @throws ParcelException When capacity in this parcel is insufficient,
305         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
306         * @since 7
307         */
308        writeByteArray(byteArray: number[]): boolean;
309
310        /**
311         * Writes a short integer array into the {@link MessageParcel} object.
312         * @param shortArray Indicates the short integer array to write.
313         * @return Returns {@code true} if the array has been written into the {@link MessageParcel};
314         *         returns {@code false} otherwise.
315         * @throws ParcelException When capacity in this parcel is insufficient,
316         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
317         * @Note   Ensure that the data type and size comply with the interface definition.
318         *         Otherwise,data may be truncated.
319         * @since 7
320         */
321        writeShortArray(shortArray: number[]): boolean;
322
323        /**
324         * Writes an integer array into the {@link MessageParcel} object.
325         * @param intArray Indicates the integer array to write.
326         * @return Returns {@code true} if the array has been written into the {@link MessageParcel};
327         *         returns {@code false} otherwise.
328         * @throws ParcelException When capacity in this parcel is insufficient,
329         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
330         * @Note   Ensure that the data type and size comply with the interface definition.
331         *         Otherwise,data may be truncated.
332         * @since 7
333         */
334        writeIntArray(intArray: number[]): boolean;
335
336        /**
337         * Writes a long integer array into the {@link MessageParcel} object.
338         * @param longArray Indicates the long integer array to write.
339         * @return Returns {@code true} if the array has been written into the {@link MessageParcel};
340         *         returns {@code false} otherwise.
341         * @throws ParcelException When capacity in this parcel is insufficient,
342         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
343         * @Note   Ensure that the data type and size comply with the interface definition.
344         *         Otherwise,data may be truncated.
345         * @since 7
346         */
347        writeLongArray(longArray: number[]): boolean;
348
349        /**
350         * Writes a floating point array into the {@link MessageParcel} object.
351         * @param floatArray Indicates the floating point array to write.
352         * @return Returns {@code true} if the array has been written into the {@link MessageParcel};
353         *         returns {@code false} otherwise.
354         * @throws ParcelException When capacity in this parcel is insufficient,
355         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
356         * @Note   Ensure that the data type and size comply with the interface definition.
357         *         Otherwise,data may be truncated.
358         * @since 7
359         */
360        writeFloatArray(floatArray: number[]): boolean;
361
362        /**
363         * Writes a double-precision floating point array into the {@link MessageParcel} object.
364         * @param doubleArray Indicates the double-precision floating point array to write.
365         * @return Returns {@code true} if the array has been written into the {@link MessageParcel};
366         *         returns {@code false} otherwise.
367         * @throws ParcelException When capacity in this parcel is insufficient,
368         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
369         * @Note   Ensure that the data type and size comply with the interface definition.
370         *         Otherwise,data may be truncated.
371         * @since 7
372         */
373        writeDoubleArray(doubleArray: number[]): boolean;
374
375        /**
376         * Writes a boolean array into the {@link MessageParcel} object.
377         * @param booleanArray Indicates the boolean array to write.
378         * @return Returns {@code true} if the array has been written into the {@link MessageParcel};
379         *         returns {@code false} otherwise.
380         * @throws ParcelException When capacity in this parcel is insufficient,
381         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
382         * @Note   Ensure that the data type and size comply with the interface definition.
383         *         Otherwise,data may be truncated.
384         * @since 7
385         */
386        writeBooleanArray(booleanArray: boolean[]): boolean;
387
388        /**
389         * Writes a single character array into the {@link MessageParcel} object.
390         * @param charArray Indicates the single character array to write.
391         * @return Returns {@code true} if the array has been written into the {@link MessageParcel};
392         *         returns {@code false} otherwise.
393         * @throws ParcelException When capacity in this parcel is insufficient,
394         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
395         * @Note   Ensure that the data type and size comply with the interface definition.
396         *         Otherwise,data may be truncated.
397         * @since 7
398         */
399        writeCharArray(charArray: number[]): boolean;
400
401        /**
402         * Writes a string array into the {@link MessageParcel} object.
403         * @param stringArray Indicates the string array to write.
404         * @return Returns {@code true} if the array has been written into the {@link MessageParcel};
405         *         returns {@code false} otherwise.
406         * @throws ParcelException When capacity in this parcel is insufficient,
407         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
408         * @Note   Ensure that the data type and size comply with the interface definition.
409         *         Otherwise,data may be truncated.
410         * @since 7
411         */
412        writeStringArray(stringArray: string[]): boolean;
413
414        /**
415         * Writes a {@link Sequenceable} object array into the {@link MessageParcel} object.
416         * @param sequenceableArray Indicates the {@link Sequenceable} object array to write.
417         * @return Returns {@code true} if the array has been written into the {@link MessageParcel};
418         *         returns {@code false} otherwise.
419         * @throws ParcelException When capacity in this parcel is insufficient,
420         *         exception message: {@link ParcelException#NO_CAPACITY_ERROR}.
421         * @since 7
422         */
423        writeSequenceableArray(sequenceableArray: Sequenceable[]): boolean;
424
425        /**
426         * Writes an array of {@link IRemoteObject} objects to this {@link MessageParcel} object.
427         * @param objectArray Array of {@link IRemoteObject} objects to write.
428         * @return Returns {@code true} if the {@link IRemoteObject} array is successfully written to the {@link MessageParcel};
429         *         returns false if the {@link IRemoteObject} array is null or fails to be written to the {@lini MessageParcel}.
430         * @since 8
431         */
432        writeRemoteObjectArray(objectArray: IRemoteObject[]): boolean;
433
434        /**
435         * Reads a byte value from the {@link MessageParcel} object.
436         * @return Returns a byte value.
437         * @since 7
438         */
439        readByte(): number;
440
441        /**
442         * Reads a short integer value from the {@link MessageParcel} object.
443         * @return Returns a short integer value.
444         * @since 7
445         */
446        readShort(): number;
447
448        /**
449         * Reads an integer value from the {@link MessageParcel} object.
450         * @return Returns an integer value.
451         * @since 7
452         */
453        readInt(): number;
454
455        /**
456         * Reads a long integer value from the {@link MessageParcel} object.
457         * @return Returns a long integer value.
458         * @since 7
459         */
460        readLong(): number;
461
462        /**
463         * Reads a floating point value from the {@link MessageParcel} object.
464         * @return Returns a floating point value.
465         * @since 7
466         */
467        readFloat(): number;
468
469        /**
470         * Reads a double-precision floating point value from the {@link MessageParcel} object.
471         * @return Returns a double-precision floating point value.
472         * @since 7
473         */
474        readDouble(): number;
475
476        /**
477         * Reads a boolean value from the {@link MessageParcel} object.
478         * @return Returns a boolean value.
479         * @since 7
480         */
481        readBoolean(): boolean;
482
483        /**
484         * Reads a single character value from the {@link MessageParcel} object.
485         * @return Returns a single character value.
486         * @since 7
487         */
488        readChar(): number;
489
490        /**
491         * Reads a string value from the {@link MessageParcel} object.
492         * @return Returns a string value.
493         * @since 7
494         */
495        readString(): string;
496
497        /**
498         * Reads a {@link Sequenceable} object from the {@link MessageParcel} instance.
499         * @param dataIn Indicates the {@link Sequenceable} object that needs to perform the {@code unmarshalling} operation
500         *        using the {@link MessageParcel}.
501         * @return Returns {@code true} if the unmarshalling is successful; returns {@code false} otherwise.
502         * @since 7
503         */
504        readSequenceable(dataIn: Sequenceable) : boolean;
505
506        /**
507         * Writes a byte array into the {@link MessageParcel} object.
508         * @param dataIn Indicates the byte array read from MessageParcel.
509         * @return Returns {@code true} if the array has been written into the {@link MessageParcel};
510         *         returns {@code false} otherwise.
511         * @throws ParcelException When capacity in this MessageParcel is insufficient,
512         *         exception message: {@link *MessageParcelException#NO_CAPACITY_ERROR}.
513         * @since 7
514         */
515        readByteArray(dataIn: number[]) : void;
516
517        /**
518         * Reads a byte array from the {@link MessageParcel} object.
519         * @return Returns a byte array.
520         * @since 7
521         */
522        readByteArray(): number[];
523
524        /**
525         * Reads a short integer array from the {@link MessageParcel} object.
526         * @param dataIn Indicates the short integer array read from MessageParcel.
527         * @since 7
528         */
529        readShortArray(dataIn: number[]) : void;
530
531        /**
532         * Reads a short integer array from the {@link MessageParcel} object.
533         * @return Returns a short integer array.
534         * @since 7
535         */
536        readShortArray(): number[];
537
538        /**
539         * Reads an integer array from the {@link MessageParcel} object.
540         * @param dataIn Indicates the integer array to read.
541         * @throws ParcelException Throws this exception if reading the integer array fails.
542         * @since 7
543         */
544        readIntArray(dataIn: number[]) : void;
545
546        /**
547         * Reads an integer array from the {@link MessageParcel} object.
548         * @return Returns an integer array.
549         * @since 7
550         */
551        readIntArray(): number[];
552
553        /**
554         * Reads a long integer array from the {@link MessageParcel} object.
555         * @param dataIn Indicates the long integer array to read.
556         * @throws ParcelException Throws this exception if reading the long array fails.
557         * @since 7
558         */
559        readLongArray(dataIn: number[]) : void;
560
561        /**
562         * Reads a long integer array from the {@link MessageParcel} object.
563         * @return Returns a long integer array.
564         * @since 7
565         */
566        readLongArray(): number[];
567
568        /**
569         * Reads a floating point array from the {@link MessageParcel} object.
570         * @param dataIn Indicates the floating point array to read.
571         * @throws ParcelException Throws this exception if reading the float array fails.
572         * @since 7
573         */
574        readFloatArray(dataIn: number[]) : void;
575
576        /**
577         * Reads a floating point array from the {@link MessageParcel} object.
578         * @return Returns a floating point array.
579         * @since 7
580         */
581        readFloatArray(): number[];
582
583        /**
584         * Reads a double-precision floating point array from the {@link MessageParcel} object.
585         * @param dataIn Indicates the double-precision floating point array to read.
586         * @throws ParcelException Throws this exception if reading the double array fails.
587         * @since 7
588         */
589        readDoubleArray(dataIn: number[]) : void;
590
591        /**
592         * Reads a double-precision floating point array from the {@link MessageParcel} object.
593         * @return Returns a double-precision floating point array.
594         * @since 7
595         */
596        readDoubleArray(): number[];
597
598        /**
599         * Reads a boolean array from the {@link MessageParcel} object.
600         * @param dataIn Indicates the boolean array to read.
601         * @throws ParcelException Throws this exception if reading the boolean array fails.
602         * @since 7
603         */
604        readBooleanArray(dataIn: boolean[]) : void;
605
606        /**
607         * Reads a boolean array from the {@link MessageParcel} object.
608         * @return Returns a boolean array.
609         * @since 7
610         */
611        readBooleanArray(): boolean[];
612
613        /**
614         * Reads a single character array from the {@link MessageParcel} object.
615         * @param dataIn Indicates the single character array to read.
616         * @throws ParcelException Throws this exception if reading the char array fails.
617         * @since 7
618         */
619        readCharArray(dataIn: number[]) : void;
620
621        /**
622         * Reads a single character array from the {@link MessageParcel} object.
623         * @return Returns a single character array.
624         * @since 7
625         */
626        readCharArray(): number[];
627
628        /**
629         * Reads a string array from the {@link MessageParcel} object.
630         * @param dataIn Indicates the string array to read.
631         * @throws ParcelException Throws this exception if reading the string array fails.
632         * @since 7
633         */
634        readStringArray(dataIn: string[]) : void;
635
636        /**
637         * Reads a string array from the {@link MessageParcel} object.
638         * @return Returns a string array.
639         * @since 7
640         */
641        readStringArray(): string[];
642
643        /**
644         * Reads the specified {@link Sequenceable} array from this {@link MessageParcel} object.
645         * @param sequenceableArray Sequenceable array to read.
646         * @since 8
647         */
648        readSequenceableArray(sequenceableArray: Sequenceable[]): void;
649
650        /**
651         * Reads the specified {@link IRemoteObject} array from this {@link MessageParcel} object.
652         * @param objects Reads data from this {@link MessageParcel} object to the specified {@link IRemoteObject} array.
653         * @since 8
654         */
655        readRemoteObjectArray(objects: IRemoteObject[]): void;
656
657        /**
658         * Reads {@link IRemoteObject} objects from this {@link MessageParcel} object.
659         * @return An array of {@link IRemoteObject} objects obtained.
660         * @since 8
661         */
662        readRemoteObjectArray(): IRemoteObject[];
663
664        /**
665         * Closes the specified file descriptor.
666         * @param fd File descriptor to be closed.
667         * @since 8
668         */
669        static closeFileDescriptor(fd: number): void;
670
671        /**
672         * Duplicates the specified file descriptor.
673         * @param fd File descriptor to be duplicated.
674         * @return A duplicated file descriptor.
675         * @since 8
676         */
677        static dupFileDescriptor(fd: number) :number;
678
679        /**
680         * Checks whether this {@link MessageParcel} object contains a file descriptor.
681         * @return Returns true if the {@link MessageParcel} object contains a file descriptor;
682         * returns false otherwise.
683         * @since 8
684         */
685        containFileDescriptors(): boolean;
686
687        /**
688         * Writes a file descriptor to this {@link MessageParcel} object.
689         * @param fd File descriptor to wrote.
690         * @return Returns true if the operation is successful; returns false otherwise.
691         * @since 8
692         */
693        writeFileDescriptor(fd: number): boolean;
694
695        /**
696         * Reads a file descriptor from this {@link MessageParcel} object.
697         * @return File descriptor obtained.
698         * @since 8
699         */
700        readFileDescriptor(): number;
701
702        /**
703         * Writes an anonymous shared memory object to this {@link MessageParcel} object.
704         * @param ashmem Anonymous shared memory object to wrote.
705         * @return Returns true if the operation is successful; returns false otherwise.
706         * @since 8
707         */
708        writeAshmem(ashmem: Ashmem): boolean;
709
710        /**
711         * Reads the anonymous shared memory object from this {@link MessageParcel} object.
712         * @return Anonymous share object obtained.
713         * @since 8
714         */
715        readAshmem(): Ashmem;
716
717        /**
718         * Obtains the maximum amount of raw data that can be sent in a time.
719         * @return 128 MB.
720         * @since 8
721         */
722        getRawDataCapacity(): number;
723
724        /**
725         * Writes raw data to this {@link MessageParcel} object.
726         * @param rawData Raw data to wrote.
727         * @param size Size of the raw data, in bytes.
728         * @return Returns true if the operation is successful; returns false otherwise.
729         * @since 8
730         */
731        writeRawData(rawData: number[], size: number): boolean;
732
733        /**
734         * Reads raw data from this {@link MessageParcel} object.
735         * @param size Size of the raw data to read.
736         * @return Raw data obtained, in bytes.
737         * @since 8
738         */
739        readRawData(size: number): number[];
740    }
741
742
743    /**
744     * @syscap SystemCapability.Communication.IPC.Core
745     * @import import rpc from '@ohos.rpc'
746     * @since 7
747     */
748    interface Sequenceable {
749        /**
750         * Marshals this {@code Sequenceable} object into a {@link MessageParcel}.
751         *
752         * @param dataOut Indicates the {@link MessageParcel} object to which the {@code Sequenceable}
753         *        object will be marshaled..
754         * @return Returns {@code true} if the marshalling is successful; returns {@code false} otherwise.
755         * @throws ParcelException Throws this exception if the operation fails.
756         * @since 7
757         */
758        marshalling(dataOut: MessageParcel): boolean;
759
760        /**
761         * Unmarshals this {@code Sequenceable} object from a {@link MessageParcel}.
762         *
763         * @param dataIn Indicates the {@link MessageParcel} object into which the {@code Sequenceable}
764         *        object has been marshaled.
765         * @return Returns {@code true} if the unmarshalling is successful; returns {@code false} otherwise.
766         * @throws ParcelException Throws this exception if the operation fails.
767         * @since 7
768         */
769        unmarshalling(dataIn: MessageParcel) : boolean;
770    }
771
772    /**
773     * Defines the response to the request.
774     * <p> SendRequestResult object contains four members,
775     * namely error code of this operation, request code, data parcel
776     * and reply parcel.
777     * @syscap SystemCapability.Communication.IPC.Core
778     * @import import rpc from '@ohos.rpc'
779     * @since 8
780     */
781    interface SendRequestResult {
782        /**
783         * Error code. 0 indicates successful, otherwise it is failed.
784         * @since 8
785         */
786        errCode: number;
787
788        /**
789         * Message code. It is same as the code in {@link SendRequest} method.
790         * @since 8
791         */
792        code: number;
793
794        /**
795         * MessageParcel object sent to the peer process.
796         * It is the same object in {@link SendRequest} method.
797         * @since 8
798         */
799        data: MessageParcel;
800
801        /**
802         * MessageParcel object returned by the peer process.
803         * It is the same object in {@link SendRequest} method.
804         * @since 8
805         */
806        reply: MessageParcel;
807    }
808
809    /**
810     * @syscap SystemCapability.Communication.IPC.Core
811     * @import import rpc from '@ohos.rpc'
812     * @since 7
813     */
814    abstract class IRemoteObject {
815        /**
816         * Queries the description of an interface.
817         *
818         * <p>A valid {@link IRemoteBroker} object is returned for an interface used by the service provider;
819         * {@code null} is returned for an interface used by the service user,
820         * indicating that the interface is not a local one.
821         *
822         * @param descriptor Indicates the interface descriptor.
823         * @return Returns the {@link IRemoteBroker} object bound to the specified interface descriptor.
824         * @since 7
825         */
826        queryLocalInterface(descriptor: string): IRemoteBroker;
827
828        /**
829         * Sends a {@link MessageParcel} message to the peer process in synchronous or asynchronous mode.
830         *
831         * <p>If asynchronous mode is set for {@code option}, a response is returned immediately.
832         * If synchronous mode is set for {@code option}, the interface will wait for a response from the peer process
833         * until the request times out. The user must prepare {@code reply} for receiving the execution result
834         * given by the peer process.
835         *
836         * @param code Indicates the message code, which is determined by both sides of the communication.
837         * If the interface is generated by the IDL tool, the message code is automatically generated by IDL.
838         * @param data Indicates the {@link MessageParcel} object sent to the peer process.
839         * @param reply Indicates the {@link MessageParcel} object returned by the peer process.
840         * @param options Indicates the synchronous or asynchronous mode to send messages.
841         * @return Returns {@code true} if the method is called successfully; returns {@code false} otherwise.
842         * @throws RemoteException Throws this exception if the method fails to be called.
843         * @deprecated since 8
844         * @since 7
845         */
846        sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean;
847
848        /**
849         * Sends a {@link MessageParcel} message to the peer process in synchronous or asynchronous mode.
850         *
851         * <p>If options indicates the asynchronous mode, a promise will be fulfilled immediately
852         * and the reply message does not contain any content. If options indicates the synchronous mode,
853         * a promise will be fulfilled when the response to sendRequest is returned,
854         * and the reply message contains the returned information.
855         * param code Message code called by the request, which is determined by the client and server.
856         * If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.
857         * param data {@link MessageParcel} object holding the data to send.
858         * param reply {@link MessageParcel} object that receives the response.
859         * param operations Indicates the synchronous or asynchronous mode to send messages.
860         * @returns Promise used to return the {@link SendRequestResult} instance.
861         * @throws Throws an exception if the method fails to be called.
862         * @since 8
863         */
864        sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise<SendRequestResult>;
865
866        /**
867         * Sends a {@link MessageParcel} message to the peer process in synchronous or asynchronous mode.
868         *
869         * <p>If options indicates the asynchronous mode, a callback will be invoked immediately
870         * and the reply message does not contain any content. If options indicates the synchronous mode,
871         * a callback will be invoked when the response to sendRequest is returned,
872         * and the reply message contains the returned information.
873         * param code Message code called by the request, which is determined by the client and server.
874         * If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.
875         * param data {@link MessageParcel} object holding the data to send.
876         * param reply {@link MessageParcel} object that receives the response.
877         * param operations Indicates the synchronous or asynchronous mode to send messages.
878         * param callback Callback for receiving the sending result.
879         * @since 8
880         */
881        sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback<SendRequestResult>): void;
882
883        /**
884         * Registers a callback used to receive notifications of the death of a remote object.
885         *
886         * @param recipient Indicates the callback to be registered.
887         * @param flags Indicates the flag of the death notification.
888         * @return Returns {@code true} if the callback is registered successfully; returns {@code false} otherwise.
889         * @since 7
890         */
891        addDeathRecipient(recipient: DeathRecipient, flags: number): boolean;
892
893        /**
894         * Deregisters a callback used to receive notifications of the death of a remote object.
895         *
896         * @param recipient Indicates the callback to be deregistered.
897         * @param flags Indicates the flag of the death notification.
898         * @return Returns {@code true} if the callback is deregistered successfully; returns {@code false} otherwise.
899         * @since 7
900         */
901        removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean;
902
903        /**
904         * Obtains the interface descriptor of an object.
905         *
906         * <p>The interface descriptor is a character string.
907         *
908         * @return Returns the interface descriptor.
909         * @since 7
910         */
911        getInterfaceDescriptor(): string;
912
913        /**
914         * Checks whether an object is dead.
915         *
916         * @return Returns {@code true} if the object is dead; returns {@code false} otherwise.
917         * @since 7
918         */
919        isObjectDead(): boolean;
920    }
921
922    /**
923     * @syscap SystemCapability.Communication.IPC.Core
924     * @import import rpc from '@ohos.rpc'
925     * @since 7
926     */
927    interface IRemoteBroker {
928        /**
929         * Obtains a proxy or remote object. This method must be implemented by its derived classes.
930         *
931         * @return Returns the RemoteObject if the caller is a RemoteObject; returns the IRemoteObject,
932         * that is, the holder of this RemoteProxy object, if the caller is a RemoteProxy object.
933         * @since 7
934         */
935        asObject(): IRemoteObject;
936    }
937
938    /**
939     * @since 7
940     * @syscap SystemCapability.Communication.IPC.Core
941     * @import import rpc from '@ohos.rpc'
942     */
943    interface DeathRecipient {
944        /**
945         * Called to perform subsequent operations when a death notification of the remote object is received.
946         *
947         * @since 7
948         */
949        onRemoteDied(): void;
950    }
951
952    /**
953     * @syscap SystemCapability.Communication.IPC.Core
954     * @import import rpc from '@ohos.rpc'
955     * @since 7
956     */
957    class MessageOption {
958        /**
959         * Indicates synchronous call.
960         *
961         * @constant
962         * @default 0
963         * @since 7
964         */
965        TF_SYNC: number;
966
967        /**
968         * Indicates asynchronous call.
969         *
970         * @constant
971         * @default 1
972         * @since 7
973         */
974        TF_ASYNC: number;
975
976        /**
977         * Indicates the sendRequest API for returning the file descriptor.
978         *
979         * @constant
980         * @default 16
981         * @since 7
982         */
983        TF_ACCEPT_FDS: number;
984
985        /**
986         * Indicates the wait time for RPC, in seconds. It is NOT used in IPC case.
987         *
988         * @constant
989         * @default 4
990         * @since 7
991         */
992        TF_WAIT_TIME: number;
993
994        /**
995         * A constructor used to create a MessageOption instance.
996         *
997         * @param syncFlags Specifies whether the SendRequest is called synchronously (default) or asynchronously.
998         * @param waitTime Maximum wait time for a RPC call. The default value is TF_WAIT_TIME.
999         * @since 7
1000         */
1001        constructor(syncFlags?: number, waitTime?: number);
1002
1003        /**
1004         * Obtains the SendRequest call flag, which can be synchronous or asynchronous.
1005         *
1006         * @return Returns whether the SendRequest is called synchronously or asynchronously.
1007         * @since 7
1008         */
1009        getFlags(): number;
1010
1011        /**
1012         * Sets the SendRequest call flag, which can be synchronous or asynchronous.
1013         *
1014         * @param flags Indicates the call flag, which can be synchronous or asynchronous.
1015         * @since 7
1016         */
1017        setFlags(flags: number): void;
1018
1019        /**
1020         * Obtains the maximum wait time for this RPC call.
1021         *
1022         * @return Returns maximum wait time obtained.
1023         * @since 7
1024         */
1025        getWaitTime(): number;
1026
1027        /**
1028         * Sets the maximum wait time for this RPC call.
1029         *
1030         * @param waitTime Indicates maximum wait time to set.
1031         * @since 7
1032         */
1033        setWaitTime(waitTime: number): void;
1034    }
1035
1036    /**
1037     * @syscap SystemCapability.Communication.IPC.Core
1038     * @import import rpc from '@ohos.rpc'
1039     * @since 7
1040     */
1041    class RemoteObject extends IRemoteObject {
1042        /**
1043         * A constructor to create a RemoteObject instance.
1044         *
1045         * @param descriptor Specifies interface descriptor.
1046         * @since 7
1047         */
1048        constructor(descriptor: string);
1049
1050        /**
1051         * Queries a remote object using an interface descriptor.
1052         *
1053         * @param descriptor Indicates the interface descriptor used to query the remote object.
1054         * @return Returns the remote object matching the interface descriptor; returns null
1055         * if no such remote object is found.
1056         * @since 7
1057         */
1058        queryLocalInterface(descriptor: string): IRemoteBroker;
1059
1060        /**
1061         * Queries an interface descriptor.
1062         *
1063         * @return Returns the interface descriptor.
1064         * @since 7
1065         */
1066        getInterfaceDescriptor(): string;
1067
1068        /**
1069         * Sets an entry for receiving requests.
1070         *
1071         * <p>This method is implemented by the remote service provider. You need to override this method with
1072         * your own service logic when you are using IPC.
1073         *
1074         * @param code Indicates the service request code sent from the peer end.
1075         * @param data Indicates the {@link MessageParcel} object sent from the peer end.
1076         * @param reply Indicates the response message object sent from the remote service.
1077         * The local service writes the response data to the {@link MessageParcel} object.
1078         * @param options Indicates whether the operation is synchronous or asynchronous.
1079         * @return Returns {@code true} if the operation succeeds; returns {@code false} otherwise.
1080         * @throws RemoteException Throws this exception if a remote service error occurs.
1081         * @since 7
1082         */
1083        onRemoteRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean;
1084
1085        /**
1086         * Sends a request to the peer object.
1087         *
1088         * <p>If the peer object and {@code RemoteObject} are on the same device, the request is sent by the IPC driver.
1089         * If they are on different devices, the request is sent by the socket driver.
1090         *
1091         * @param code Indicates the message code of the request.
1092         * @param data Indicates the {@link MessageParcel} object storing the data to be sent.
1093         * @param reply Indicates the {@link MessageParcel} object receiving the response data.
1094         * @param options Indicates a synchronous (default) or asynchronous request.
1095         * @return Returns {@code true} if the operation succeeds; returns {@code false} otherwise.
1096         * @deprecated since 8
1097         * @since 7
1098         */
1099        sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean;
1100
1101        /**
1102         * Sends a {@link MessageParcel} message to the peer process in synchronous or asynchronous mode.
1103         *
1104         * <p>If options indicates the asynchronous mode, a promise will be fulfilled immediately
1105         * and the reply message does not contain any content. If options indicates the synchronous mode,
1106         * a promise will be fulfilled when the response to sendRequest is returned,
1107         * and the reply message contains the returned information.
1108         * param code Message code called by the request, which is determined by the client and server.
1109         * If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.
1110         * param data {@link MessageParcel} object holding the data to send.
1111         * param reply {@link MessageParcel} object that receives the response.
1112         * param operations Indicates the synchronous or asynchronous mode to send messages.
1113         * @returns Promise used to return the {@link SendRequestResult} instance.
1114         * @throws Throws an exception if the method fails to be called.
1115         * @since 8
1116         */
1117        sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise<SendRequestResult>;
1118
1119        /**
1120         * Sends a {@link MessageParcel} message to the peer process in synchronous or asynchronous mode.
1121         *
1122         * <p>If options indicates the asynchronous mode, a callback will be invoked immediately
1123         * and the reply message does not contain any content. If options indicates the synchronous mode,
1124         * a callback will be invoked when the response to sendRequest is returned,
1125         * and the reply message contains the returned information.
1126         * param code Message code called by the request, which is determined by the client and server.
1127         * If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.
1128         * param data {@link MessageParcel} object holding the data to send.
1129         * param reply {@link MessageParcel} object that receives the response.
1130         * param operations Indicates the synchronous or asynchronous mode to send messages.
1131         * param callback Callback for receiving the sending result.
1132         * @since 8
1133         */
1134        sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback<SendRequestResult>): void;
1135
1136        /**
1137         * Obtains the PID of the {@link RemoteProxy} object.
1138         *
1139         * @return Returns the PID of the {@link RemoteProxy} object.
1140         * @since 7
1141         */
1142        getCallingPid(): number;
1143
1144        /**
1145         * Obtains the UID of the {@link RemoteProxy} object.
1146         *
1147         * @return Returns the UID of the {@link RemoteProxy} object.
1148         * @since 7
1149         */
1150        getCallingUid(): number;
1151
1152        /**
1153         * Modifies the description of the current {@code RemoteObject}.
1154         *
1155         * <p>This method is used to change the default descriptor specified during the creation of {@code RemoteObject}.
1156         *
1157         * @param localInterface Indicates the {@code RemoteObject} whose descriptor is to be changed.
1158         * @param descriptor Indicates the new descriptor of the {@code RemoteObject}.
1159         * @since 7
1160         */
1161        attachLocalInterface(localInterface: IRemoteBroker, descriptor: string): void;
1162    }
1163
1164    /**
1165     * @syscap SystemCapability.Communication.IPC.Core
1166     * @import import rpc from '@ohos.rpc'
1167     * @since 7
1168     */
1169    class RemoteProxy implements IRemoteObject {
1170        /**
1171         * Indicates the message code for a Ping operation.
1172         *
1173         * @constant
1174         * @default 1599098439
1175         * @since 7
1176         */
1177        PING_TRANSACTION: number;
1178
1179        /**
1180         * Indicates the message code for a dump operation.
1181         *
1182         * @constant
1183         * @default 1598311760
1184         * @since 7
1185         */
1186        DUMP_TRANSACTION: number;
1187
1188        /**
1189         * Indicates the message code for a transmission.
1190         *
1191         * @constant
1192         * @default 1598968902
1193         * @since 7
1194         */
1195        INTERFACE_TRANSACTION: number;
1196
1197        /**
1198         * Indicates the minimum value of a valid message code.
1199         *
1200         * <p>This constant is used to check the validity of an operation.
1201         *
1202         * @constant
1203         * @default 0x1
1204         * @since 7
1205         */
1206        MIN_TRANSACTION_ID: number;
1207
1208        /**
1209         * Indicates the maximum value of a valid message code.
1210         *
1211         * <p>This constant is used to check the validity of an operation.
1212         *
1213         * @constant
1214         * @default 0x00FFFFFF
1215         * @since 7
1216         */
1217        MAX_TRANSACTION_ID: number;
1218
1219        /**
1220         * Queries a local interface with a specified descriptor.
1221         *
1222         * @param descriptor Indicates the descriptor of the interface to query.
1223         * @return Returns null by default, indicating a proxy interface.
1224         * @since 7
1225         */
1226        queryLocalInterface(interface: string): IRemoteBroker;
1227
1228        /**
1229         * Registers a callback used to receive death notifications of a remote object.
1230         *
1231         * @param recipient Indicates the callback to be registered.
1232         * @param flags Indicates the flag of the death notification. This is a reserved parameter. Set it to {@code 0}.
1233         * @return Returns {@code true} if the callback is registered successfully; returns {@code false} otherwise.
1234         * @since 7
1235         */
1236        addDeathRecipient(recipient: DeathRecipient, flags: number): boolean;
1237
1238        /**
1239         * Deregisters a callback used to receive death notifications of a remote object.
1240         *
1241         * @param recipient Indicates the callback to be deregistered.
1242         * @param flags Indicates the flag of the death notification. This is a reserved parameter. Set it to {@code 0}.
1243         * @return Returns {@code true} if the callback is deregistered successfully; returns {@code false} otherwise.
1244         * @since 7
1245         */
1246        removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean;
1247
1248        /**
1249         * Queries the interface descriptor of remote object.
1250         *
1251         * @return Returns the interface descriptor.
1252         * @since 7
1253         */
1254        getInterfaceDescriptor(): string;
1255
1256        /**
1257         * Sends a request to the peer object.
1258         *
1259         * <p>If the peer object and {@code RemoteProxy} are on the same device, the request is sent by the IPC driver.
1260         * If they are on different devices, the request is sent by the socket driver.
1261         *
1262         * @param code Indicates the message code of the request.
1263         * @param data Indicates the {@link MessageParcel} object storing the data to be sent.
1264         * @param reply Indicates the {@link MessageParcel} object receiving the response data.
1265         * @param options Indicates a synchronous (default) or asynchronous request.
1266         * @return Returns {@code true} if the operation succeeds; returns {@code false} otherwise.
1267         * @throws RemoteException Throws this exception if a remote object exception occurs.
1268         * @deprecated since 8
1269         * @since 7
1270         */
1271        sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean;
1272
1273        /**
1274         * Sends a {@link MessageParcel} message to the peer process in synchronous or asynchronous mode.
1275         *
1276         * <p>If options indicates the asynchronous mode, a promise will be fulfilled immediately
1277         * and the reply message does not contain any content. If options indicates the synchronous mode,
1278         * a promise will be fulfilled when the response to sendRequest is returned,
1279         * and the reply message contains the returned information.
1280         * param code Message code called by the request, which is determined by the client and server.
1281         * If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.
1282         * param data {@link MessageParcel} object holding the data to send.
1283         * param reply {@link MessageParcel} object that receives the response.
1284         * param operations Indicates the synchronous or asynchronous mode to send messages.
1285         * @returns Promise used to return the {@link sendRequestResult} instance.
1286         * @throws Throws an exception if the method fails to be called.
1287         * @since 8
1288         */
1289        sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise<SendRequestResult>;
1290
1291        /**
1292         * Sends a {@link MessageParcel} message to the peer process in synchronous or asynchronous mode.
1293         *
1294         * <p>If options indicates the asynchronous mode, a callback will be invoked immediately
1295         * and the reply message does not contain any content. If options indicates the synchronous mode,
1296         * a callback will be invoked when the response to sendRequest is returned,
1297         * and the reply message contains the returned information.
1298         * param code Message code called by the request, which is determined by the client and server.
1299         * If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.
1300         * param data {@link MessageParcel} object holding the data to send.
1301         * param reply {@link MessageParcel} object that receives the response.
1302         * param operations Indicates the synchronous or asynchronous mode to send messages.
1303         * param callback Callback for receiving the sending result.
1304         * @since 8
1305         */
1306        sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback<SendRequestResult>): void;
1307
1308        /**
1309         * Checks whether the {@code RemoteObject} corresponding to a {@code RemoteProxy} is dead.
1310         *
1311         * @return Returns {@code true} if the {@code RemoteObject} is dead; returns {@code false} otherwise.
1312         * @since 7
1313         */
1314        isObjectDead(): boolean;
1315    }
1316
1317    /**
1318     * @syscap SystemCapability.Communication.IPC.Core
1319     * @import import rpc from '@ohos.rpc'
1320     * @since 7
1321     */
1322    class IPCSkeleton {
1323        /**
1324         * Obtains a local {@link IRemoteObject} reference of a registered service.
1325         *
1326         * <p>This method is static.
1327         *
1328         * @return Returns an {@link IRemoteObject} reference of the registered service.
1329         * @since 7
1330         */
1331        static getContextObject(): IRemoteObject;
1332
1333        /**
1334         * Obtains the PID of a proxy.
1335         *
1336         * <p>This method is static. The PID is a positive integer during the communication between
1337         * the {@link RemoteProxy} object and {@link RemoteObject} object, and resumes to {@code 0}
1338         * when the communication ends. If this method is called from the {@link RemoteProxy} object,
1339         * {@code 0} is returned; if this method is called from the {@link RemoteObject} object,
1340         * the PID of the corresponding {@link RemoteProxy} object is returned.
1341         *
1342         * @return Returns the PID of the proxy.
1343         * @since 7
1344         */
1345        static getCallingPid(): number;
1346
1347        /**
1348         * Obtains the UID of a proxy.
1349         *
1350         * <p>This method is static. The UID is a positive integer during the communication between
1351         * the {@link RemoteProxy} object and {@link RemoteObject} object, and resumes to {@code 0}
1352         * when the communication ends. If this method is called from the {@link RemoteProxy} object,
1353         * {@code 0} is returned; if this method is called from the {@link RemoteObject} object,
1354         * the UID of the corresponding {@link RemoteProxy} object is returned.
1355         *
1356         * @return Returns the UID of the proxy.
1357         * @since 7
1358         */
1359        static getCallingUid(): number;
1360
1361        /**
1362         * Obtains the TOKENID.
1363         *
1364         * <p>This method is static.
1365         *
1366         * @return Returns the TOKENID.
1367         * @since 8
1368         */
1369         static getCallingTokenId(): number;
1370
1371        /**
1372         * Obtains the ID of the device where the peer process resides.
1373         *
1374         * <p>This method is static.
1375         *
1376         * @return Returns the ID of the device where the peer process resides.
1377         * @since 7
1378         */
1379        static getCallingDeviceID(): string;
1380
1381        /**
1382         * Obtains the ID of the local device.
1383         *
1384         * <p>This method is static.
1385         *
1386         * @return Returns the ID of the local device.
1387         * @since 7
1388         */
1389        static getLocalDeviceID(): string;
1390
1391        /**
1392         * Checks whether a call is made on the same device.
1393         *
1394         * <p>This method is static.
1395         *
1396         * @return Returns {@code true} if the call is made on the same device; returns {@code false} otherwise.
1397         * @since 7
1398         */
1399        static isLocalCalling(): boolean;
1400
1401        /**
1402         * Flushes all pending commands from a specified {@link RemoteProxy} to the corresponding {@link RemoteObject}.
1403         *
1404         * <p>This method is static. You are advised to call this method before performing any time-sensitive operations.
1405         *
1406         * @param object Indicates the specified {@link RemoteProxy}.
1407         * @return Returns {@code 0} if the operation succeeds; returns an error code if the input object is empty
1408         * or {@link RemoteObject}, or the operation fails.
1409         * @since 7
1410         */
1411        static flushCommands(object: IRemoteObject): number;
1412
1413        /**
1414         * Replaces the UID and PID of the remote user with those of the local user.
1415         *
1416         * <p>This method is static. It can be used in scenarios like authentication.
1417         *
1418         * @return Returns a string containing the UID and PID of the remote user.
1419         * @since 7
1420         */
1421        static resetCallingIdentity(): string;
1422
1423        /**
1424         * Restores the UID and PID to those of the remote user.
1425         *
1426         * <p>This method is static. It is usually called after {@code resetCallingIdentity} is used
1427         * and requires the UID and PID of the remote user returned by {@code resetCallingIdentity}.
1428         *
1429         * @param identity Indicates the string containing the UID and PID of the remote user,
1430         * which is returned by {@code resetCallingIdentity}.
1431         * @return Returns {@code true} if the operation succeeds; returns {@code false} otherwise.
1432         * @since 7
1433         */
1434        static setCallingIdentity(identity: string): boolean;
1435    }
1436
1437    /**
1438     * Provides methods related to anonymous shared memory objects,
1439     * including creating, closing, mapping, and unmapping an Ashmem object,
1440     * reading data from and writing data to an Ashmem object,
1441     * obtaining the Ashmem size, and setting Ashmem protection.
1442     * @syscap SystemCapability.Communication.IPC.Core
1443     * @import import rpc from '@ohos.rpc'
1444     * @since 8
1445     */
1446    class Ashmem {
1447        /**
1448         * The mapped memory is executable.
1449         *
1450         * @constant
1451         * @default 4
1452         * @since 8
1453         */
1454        PROT_EXEC: number;
1455
1456        /**
1457         * The mapped memory is inaccessible.
1458         *
1459         * @constant
1460         * @default 0
1461         * @since 8
1462         */
1463        PROT_NONE: number;
1464
1465        /**
1466         * The mapped memory is readable.
1467         *
1468         * @constant
1469         * @default 1
1470         * @since 8
1471         */
1472        PROT_READ: number;
1473
1474        /**
1475         * The mapped memory is writable.
1476         *
1477         * @constant
1478         * @default 2
1479         * @since 8
1480         */
1481        PROT_WRITE: number;
1482
1483        /**
1484         * Creates an Ashmem object with the specified name and size.
1485         * @param name Name of the Ashmem object to create.
1486         * @param size Size (in bytes) of the Ashmem object to create.
1487         * @return Returns the Ashmem object if it is created successfully; returns null otherwise.
1488         * @since 8
1489         */
1490        static createAshmem(name: string, size: number): Ashmem;
1491
1492        /**
1493         * Creates an Ashmem object by copying the file descriptor (FD) of an existing Ashmem object.
1494         * The two Ashmem objects point to the same shared memory region.
1495         * @param ashmem Existing Ashmem object.
1496         * @return Ashmem object created.
1497         * @since 8
1498         */
1499        static createAshmemFromExisting(ashmem: Ashmem): Ashmem;
1500
1501        /**
1502         * Closes this Ashmem object.
1503         * @since 8
1504         */
1505        closeAshmem(): void;
1506
1507        /**
1508         * Deletes the mappings for the specified address range of this Ashmem object.
1509         * @since 8
1510         */
1511        unmapAshmem(): void;
1512
1513        /**
1514         * Obtains the mapped memory size of this Ashmem object.
1515         * @return Memory size mapped.
1516         * @since 8
1517         */
1518        getAshmemSize(): number;
1519
1520        /**
1521         * Creates the shared file mapping on the virtual address space of this process.
1522         * The size of the mapping region is specified by this Ashmem object.
1523         * @param mapType Protection level of the memory region to which the shared file is mapped.
1524         * @return Returns true if the operation is successful; returns false otherwise.
1525         * @since 8
1526         */
1527        mapAshmem(mapType: number): boolean;
1528
1529        /**
1530         * Maps the shared file to the readable and writable virtual address space of the process.
1531         * @return Returns true if the operation is successful; returns false otherwise.
1532         * @since 8
1533         */
1534        mapReadAndWriteAshmem(): boolean;
1535
1536        /**
1537         * Maps the shared file to the read-only virtual address space of the process.
1538         * @return Returns true if the operation is successful; returns false otherwise.
1539         * @since 8
1540         */
1541        mapReadOnlyAshmem(): boolean;
1542
1543        /**
1544         * Sets the protection level of the memory region to which the shared file is mapped.
1545         * @param protectionType Protection type to set.
1546         * @return Returns true if the operation is successful; returns false otherwise.
1547         * @since 8
1548         */
1549        setProtection(protectionType: number): boolean;
1550
1551        /**
1552         * Writes data to the shared file associated with this Ashmem object.
1553         * @param buf Data to write
1554         * @param size Size of the data to write
1555         * @param offset Start position of the data to write in the memory region associated with this Ashmem object.
1556         * @return Returns true is the data is written successfully; returns false otherwise.
1557         * @since 8
1558         */
1559        writeToAshmem(buf: number[], size: number, offset: number): boolean;
1560
1561        /**
1562         * Reads data from the shared file associated with this Ashmem object.
1563         * @param size Size of the data to read.
1564         * @param offset Start position of the data to read in the memory region associated with this Ashmem object.
1565         * @return Data read.
1566         * @since 8
1567         */
1568        readFromAshmem(size: number, offset: number): number[];
1569    }
1570}
1571
1572export default rpc;