Add @CorePlatformApi for customization of Libcore.os by frameworks.

Provide a @CorePlatformApi to replace the default implementation of
libcore.io.Os, held in the static (internal) field libcore.io.Libcore.os,
which should not otherwise be updated.

This allows callers to safely update the Os implementation even when
there may be concurrent callers:

while (true) {
    Os os = Os.getDefault();
    Os wrapper = new ForwardingOs(os) {
        // ...override/customize some methods...
    };

    if (Os.compareAndSetDefault(os, wrapper)) {
        break;
    }
}

Initially, ForwardingOs is the only Os implementation that can be
used from outside libcore, and open() is the only method that can be
overridden/customized; the plan is that customization of additional
methods will be supported in future.

Existing code that directly reads the field Libcore.os continues to
be safe / correct. Writing directly to that field continues to be
not be supported.

Bug: 115503977
Test: CtsLibcoreTestCases
Test: OsTest
Test: Checked that locally adding code similar to the above to
      frameworks' ActivityThread.main() compiles.
Change-Id: I49d9171fb869664b0e72c4cbc055d168c101c669
6 files changed