diff --git a/libc/tzcode/bionic.cpp b/libc/tzcode/bionic.cpp index 1742d7941..6d84303a4 100644 --- a/libc/tzcode/bionic.cpp +++ b/libc/tzcode/bionic.cpp @@ -199,37 +199,36 @@ static int __bionic_open_tzdata_path(const char* path, int __bionic_open_tzdata(const char* olson_id, int32_t* entry_length) { int fd; -#if defined(__ANDROID__) - // On Android devices, try the four hard-coded locations in order. - // + // Try the three locations for the tzdata file in a strict order: // 1: The O-MR1 time zone updates via APK update mechanism. This is - // tried first because it allows us to test that the time zone updates - // via APK mechanism still works even on devices with the time zone - // module. + // tried first because it allows us to test that the time zone updates + // via APK mechanism still works even on devices with the time zone + // module. + // 2: The time zone data module which contains the main copy. This is the + // common case. + // 3: The ultimate fallback: the non-updatable copy in /system. + +#if defined(__ANDROID__) + // On Android devices, bionic has to work even if exec takes place without + // environment variables set. So, all paths are hardcoded here. + fd = __bionic_open_tzdata_path("/data/misc/zoneinfo/current/tzdata", olson_id, entry_length); if (fd >= 0) return fd; - // 2: The time zone data module which may contain newer data on - // devices that support module updates. fd = __bionic_open_tzdata_path("/apex/com.android.tzdata/etc/tz/tzdata", olson_id, entry_length); if (fd >= 0) return fd; - // 3: The runtime module, which should exist even on devices that - // do not support APEX file updates. - fd = __bionic_open_tzdata_path("/apex/com.android.runtime/etc/tz/tzdata", - olson_id, entry_length); - if (fd >= 0) return fd; - - // 4: The ultimate fallback: the non-updatable copy in /system. fd = __bionic_open_tzdata_path("/system/usr/share/zoneinfo/tzdata", olson_id, entry_length); if (fd >= 0) return fd; #else - // On the host, we don't expect those locations to exist, and we're not - // worried about security so we trust $ANDROID_DATA, $ANDROID_RUNTIME_ROOT, - // $ANDROID_TZDATA_ROOT, and $ANDROID_ROOT to point us in the right direction. + // On the host, we don't expect the hard-coded locations above to exist, and + // we're not worried about security so we trust $ANDROID_DATA, + // $ANDROID_TZDATA_ROOT, and $ANDROID_ROOT to point us in the right direction + // instead. + char* path = make_path("ANDROID_DATA", "/misc/zoneinfo/current/tzdata"); fd = __bionic_open_tzdata_path(path, olson_id, entry_length); free(path); @@ -240,11 +239,6 @@ int __bionic_open_tzdata(const char* olson_id, int32_t* entry_length) { free(path); if (fd >= 0) return fd; - path = make_path("ANDROID_RUNTIME_ROOT", "/etc/tz/tzdata"); - fd = __bionic_open_tzdata_path(path, olson_id, entry_length); - free(path); - if (fd >= 0) return fd; - path = make_path("ANDROID_ROOT", "/usr/share/zoneinfo/tzdata"); fd = __bionic_open_tzdata_path(path, olson_id, entry_length); free(path);