• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.net.module.util.async;
18 
19 import android.os.ParcelFileDescriptor;
20 import android.system.StructPollfd;
21 
22 import java.io.FileDescriptor;
23 import java.io.IOException;
24 
25 /**
26  * Provides access to all relevant OS functions..
27  *
28  * @hide
29  */
30 public abstract class OsAccess {
31     /** Closes the given file, suppressing IO exceptions. */
close(ParcelFileDescriptor fd)32     public abstract void close(ParcelFileDescriptor fd);
33 
34     /** Returns file name for debugging purposes. */
getFileDebugName(ParcelFileDescriptor fd)35     public abstract String getFileDebugName(ParcelFileDescriptor fd);
36 
37     /** Returns inner FileDescriptor instance. */
getInnerFileDescriptor(ParcelFileDescriptor fd)38     public abstract FileDescriptor getInnerFileDescriptor(ParcelFileDescriptor fd);
39 
40     /**
41      * Reads available data from the given non-blocking file descriptor.
42      *
43      * Returns zero if there's no data to read at this moment.
44      * Returns -1 if the file has reached its end or the input stream has been closed.
45      * Otherwise returns the number of bytes read.
46      */
read(FileDescriptor fd, byte[] buffer, int pos, int len)47     public abstract int read(FileDescriptor fd, byte[] buffer, int pos, int len)
48             throws IOException;
49 
50     /**
51      * Writes data into the given non-blocking file descriptor.
52      *
53      * Returns zero if there's no buffer space to write to at this moment.
54      * Otherwise returns the number of bytes written.
55      */
write(FileDescriptor fd, byte[] buffer, int pos, int len)56     public abstract int write(FileDescriptor fd, byte[] buffer, int pos, int len)
57             throws IOException;
58 
monotonicTimeMillis()59     public abstract long monotonicTimeMillis();
setNonBlocking(FileDescriptor fd)60     public abstract void setNonBlocking(FileDescriptor fd) throws IOException;
pipe()61     public abstract ParcelFileDescriptor[] pipe() throws IOException;
62 
poll(StructPollfd[] fds, int timeoutMs)63     public abstract int poll(StructPollfd[] fds, int timeoutMs) throws IOException;
getPollInMask()64     public abstract short getPollInMask();
getPollOutMask()65     public abstract short getPollOutMask();
66 }
67