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

Commit f0fc23a1 authored by Selim Cinek's avatar Selim Cinek Committed by Android Git Automerger
Browse files

am 962b06f9: Merge "Fixed several time related states for secondary users" into lmp-mr1-dev

* commit '962b06f9':
  Fixed several time related states for secondary users
parents 4f1cce63 962b06f9
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -474,13 +474,14 @@ public class ZenModeConfig implements Parcelable {
        return downtime;
    }

    public static Condition toTimeCondition(Context context, int minutesFromNow) {
    public static Condition toTimeCondition(Context context, int minutesFromNow, int userHandle) {
        final long now = System.currentTimeMillis();
        final long millis = minutesFromNow == 0 ? ZERO_VALUE_MS : minutesFromNow * MINUTES_MS;
        return toTimeCondition(context, now + millis, minutesFromNow, now);
        return toTimeCondition(context, now + millis, minutesFromNow, now, userHandle);
    }

    public static Condition toTimeCondition(Context context, long time, int minutes, long now) {
    public static Condition toTimeCondition(Context context, long time, int minutes, long now,
            int userHandle) {
        final int num, summaryResId, line1ResId;
        if (minutes < 60) {
            // display as minutes
@@ -493,7 +494,7 @@ public class ZenModeConfig implements Parcelable {
            summaryResId = com.android.internal.R.plurals.zen_mode_duration_hours_summary;
            line1ResId = com.android.internal.R.plurals.zen_mode_duration_hours;
        }
        final String skeleton = DateFormat.is24HourFormat(context) ? "Hm" : "hma";
        final String skeleton = DateFormat.is24HourFormat(context, userHandle) ? "Hm" : "hma";
        final String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
        final CharSequence formattedTime = DateFormat.format(pattern, time);
        final Resources res = context.getResources();
+28 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.text.format;

import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
@@ -166,8 +167,20 @@ public class DateFormat {
     * @return true if 24 hour time format is selected, false otherwise.
     */
    public static boolean is24HourFormat(Context context) {
        String value = Settings.System.getString(context.getContentResolver(),
                Settings.System.TIME_12_24);
        return is24HourFormat(context, UserHandle.myUserId());
    }

    /**
     * Returns true if user preference with the given user handle is set to 24-hour format.
     * @param context the context to use for the content resolver
     * @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(Context context, int userHandle) {
        String value = Settings.System.getStringForUser(context.getContentResolver(),
                Settings.System.TIME_12_24, userHandle);

        if (value == null) {
            Locale locale = context.getResources().getConfiguration().locale;
@@ -253,8 +266,19 @@ public class DateFormat {
     * @hide
     */
    public static String getTimeFormatString(Context context) {
        return getTimeFormatString(context, UserHandle.myUserId());
    }

    /**
     * Returns a String pattern that can be used to format the time according
     * to the current locale and the user's 12-/24-hour clock preference.
     * @param context the application context
     * @param userHandle the user handle of the user to query the format for
     * @hide
     */
    public static String getTimeFormatString(Context context, int userHandle) {
        LocaleData d = LocaleData.get(context.getResources().getConfiguration().locale);
        return is24HourFormat(context) ? d.timeFormat24 : d.timeFormat12;
        return is24HourFormat(context, userHandle) ? d.timeFormat24 : d.timeFormat12;
    }

    /**
+32 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.widget;

import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
@@ -26,6 +27,7 @@ import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.format.DateFormat;
import android.util.AttributeSet;
@@ -127,6 +129,8 @@ public class TextClock extends TextView {
    private Calendar mTime;
    private String mTimeZone;

    private boolean mShowCurrentUserTime;

    private final ContentObserver mFormatChangeObserver = new ContentObserver(new Handler()) {
        @Override
        public void onChange(boolean selfChange) {
@@ -341,6 +345,22 @@ public class TextClock extends TextView {
        onTimeChanged();
    }

    /**
     * Sets whether this clock should always track the current user and not the user of the
     * current process. This is used for single instance processes like the systemUI who need
     * to display time for different users.
     *
     * @hide
     */
    public void setShowCurrentUserTime(boolean showCurrentUserTime) {
        mShowCurrentUserTime = showCurrentUserTime;

        chooseFormat();
        onTimeChanged();
        unregisterObserver();
        registerObserver();
    }

    /**
     * Indicates whether the system is currently using the 24-hour mode.
     *
@@ -360,8 +380,12 @@ public class TextClock extends TextView {
     * @see #getFormat24Hour()
     */
    public boolean is24HourModeEnabled() {
        if (mShowCurrentUserTime) {
            return DateFormat.is24HourFormat(getContext(), ActivityManager.getCurrentUser());
        } else {
            return DateFormat.is24HourFormat(getContext());
        }
    }

    /**
     * Indicates which time zone is currently used by this view.
@@ -500,7 +524,13 @@ public class TextClock extends TextView {

    private void registerObserver() {
        final ContentResolver resolver = getContext().getContentResolver();
        resolver.registerContentObserver(Settings.System.CONTENT_URI, true, mFormatChangeObserver);
        if (mShowCurrentUserTime) {
            resolver.registerContentObserver(Settings.System.CONTENT_URI, true,
                    mFormatChangeObserver, UserHandle.USER_ALL);
        } else {
            resolver.registerContentObserver(Settings.System.CONTENT_URI, true,
                    mFormatChangeObserver);
        }
    }

    private void unregisterReceiver() {
+6 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.keyguard;

import android.app.ActivityManager;
import android.app.AlarmManager;
import android.content.ContentResolver;
import android.content.Context;
@@ -105,6 +106,8 @@ public class KeyguardStatusView extends GridLayout {
        mAlarmStatusView = (TextView) findViewById(R.id.alarm_status);
        mDateView = (TextClock) findViewById(R.id.date_view);
        mClockView = (TextClock) findViewById(R.id.clock_view);
        mDateView.setShowCurrentUserTime(true);
        mClockView.setShowCurrentUserTime(true);
        mOwnerInfo = (TextView) findViewById(R.id.owner_info);
        mLockPatternUtils = new LockPatternUtils(getContext());
        final boolean screenOn = KeyguardUpdateMonitor.getInstance(mContext).isScreenOn();
@@ -160,7 +163,9 @@ public class KeyguardStatusView extends GridLayout {
        if (info == null) {
            return "";
        }
        String skeleton = DateFormat.is24HourFormat(context) ? "EHm" : "Ehma";
        String skeleton = DateFormat.is24HourFormat(context, ActivityManager.getCurrentUser())
                ? "EHm"
                : "Ehma";
        String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
        return DateFormat.format(pattern, info.getTriggerTime()).toString();
    }
+5 −2
Original line number Diff line number Diff line
@@ -16,12 +16,14 @@

package com.android.systemui.statusbar.policy;

import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.UserHandle;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.format.DateFormat;
@@ -91,7 +93,8 @@ public class Clock extends TextView implements DemoMode {
            filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
            filter.addAction(Intent.ACTION_USER_SWITCHED);

            getContext().registerReceiver(mIntentReceiver, filter, null, getHandler());
            getContext().registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, filter,
                    null, getHandler());
        }

        // NOTE: It's safe to do these after registering the receiver since the receiver always runs
@@ -142,7 +145,7 @@ public class Clock extends TextView implements DemoMode {

    private final CharSequence getSmallTime() {
        Context context = getContext();
        boolean is24 = DateFormat.is24HourFormat(context);
        boolean is24 = DateFormat.is24HourFormat(context, ActivityManager.getCurrentUser());
        LocaleData d = LocaleData.get(context.getResources().getConfiguration().locale);

        final char MAGIC1 = '\uEF00';
Loading