Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2f5d1201 authored by Wilhelm Fitzpatrick's avatar Wilhelm Fitzpatrick Committed by Steve Kondik
Browse files

Fix "Select correct 12 or 24 time format" breaking Chrome

Due to Chrome's process isolation, using a ContentResolver is
forbidden. However ActivityThread already has direct access to
settings and locale, so modify DateFormat's utility method to
allow those values to be passed directly.

CYNGNOS-495

Change-Id: I5284b94459ac03214f1712c8a1fddcbefeae3783
parent a4e229c7
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -4555,7 +4555,8 @@ public final class ActivityThread {
        }


        final boolean is24Hr = android.text.format.DateFormat.is24HourFormat(appContext);
        final boolean is24Hr = android.text.format.DateFormat.is24HourFormat(
            mCoreSettings.getString(Settings.System.TIME_12_24), data.config.locale);
        DateFormat.set24HourTimePref(is24Hr);

        View.mDebugViewAttributes =
+20 −9
Original line number Diff line number Diff line
@@ -177,12 +177,23 @@ public class DateFormat {
     * @hide
     */
    public static boolean is24HourFormat(Context context, int userHandle) {
        String value = Settings.System.getStringForUser(context.getContentResolver(),
        String setting = Settings.System.getStringForUser(context.getContentResolver(),
                Settings.System.TIME_12_24, userHandle);

        if (value == null) {
        Locale locale = context.getResources().getConfiguration().locale;
        return is24HourFormat(setting, locale);
    }

    /**
     * Returns true if user preference with the given user handle is set to 24-hour format.
     * @param setting value of the TIME_12_24 system setting, which may be null
     * @param locale current default locale for this device
     * @param userHandle the user handle of the user to query.
     * @return true if 24 hour time format is selected, false otherwise.
     *
     * @hide
     */
    public static boolean is24HourFormat(String setting, Locale locale) {
        if (setting == null) {
            synchronized (sLocaleLock) {
                if (sIs24HourLocale != null && sIs24HourLocale.equals(locale)) {
                    return sIs24Hour;
@@ -197,23 +208,23 @@ public class DateFormat {
                String pattern = sdf.toPattern();

                if (pattern.indexOf('H') >= 0) {
                    value = "24";
                    setting = "24";
                } else {
                    value = "12";
                    setting = "12";
                }
            } else {
                value = "12";
                setting = "12";
            }

            synchronized (sLocaleLock) {
                sIs24HourLocale = locale;
                sIs24Hour = value.equals("24");
                sIs24Hour = setting.equals("24");
            }

            return sIs24Hour;
        }

        return value.equals("24");
        return setting.equals("24");
    }

    /**