Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Android 11's equivalent of '/dev/null'

Android 11 introduced multiple changes to file storage and access. Apparently one of them is that one can no longer target output to '/dev/null' (my scenario is actually exactly explained in this old question).

Although the cited question solved the particular issue, one thing remains unanswered: what is Android 11's equivalent to '/dev/null'. That is, if one does not need the output of a particular operation (and in our case it is an operation that creates a biggish file).

like image 868
Boris Strandjev Avatar asked Jan 20 '21 13:01

Boris Strandjev


People also ask

Is dev null a device?

Usage. The null device is typically used for disposing of unwanted output streams of a process, or as a convenient empty file for input streams. This is usually done by redirection. The /dev/null device is a special file, not a directory, so one cannot move a whole file or directory into it with the Unix mv command.

How dev null?

/dev/null in Linux is a null device file. This will discard anything written to it, and will return EOF on reading. This is a command-line hack that acts as a vacuum, that sucks anything thrown to it. Let's take a look at understanding what it means, and what we can do with this file.

Can you read from dev Null?

You write to /dev/null every time you use it in a command such as touch file 2> /dev/null. You read from /dev/null every time you empty an existing file using a command such as cat /dev/null > bigfile or just > bigfile. Because of the file's nature, you can't change it in any way; you can only use it.

What are the folders dev dev Null used for?

/dev/null can be used to remove error messages. For example, if it is undesirable to get error messages in the output, then redirect errors to /dev/null.


1 Answers

Eventually I ended up solving my problem the following way (answer tailored to MediaRecorder problem but can be generalized to other situations too):

fun MediaRecorder.setOutputFile(context: Context) {
    val tmpRecordingFolder = File(context.filesDir, "tmp_media")
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        setOutputFile(File(tmpRecordingFolder, "recording.mp3"))
    } else {
        setOutputFile("/dev/null")
    }
}

Basically I am setting the output to be in the internal storage. I hope the file will not get huge and I am deleting the file in as many places in the code as possible. This seems to work on newer devices, currently have not yet ran into storage problems either, but the solution is not rolled out to production yet. Will update my answer if problems are identified.

like image 185
Boris Strandjev Avatar answered Oct 29 '22 16:10

Boris Strandjev