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

Commit cfe627f2 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Android (Google) Code Review
Browse files

Merge "Cache IAlarmManager binder handle."

parents 963101ca 7cbad8a0
Loading
Loading
Loading
Loading
+12 −4
Original line number Original line Diff line number Diff line
@@ -104,6 +104,8 @@ import java.time.ZoneOffset;
public final class SystemClock {
public final class SystemClock {
    private static final String TAG = "SystemClock";
    private static final String TAG = "SystemClock";


    private static volatile IAlarmManager sIAlarmManager;

    /**
    /**
     * This class is uninstantiable.
     * This class is uninstantiable.
     */
     */
@@ -151,8 +153,7 @@ public final class SystemClock {
     * @return if the clock was successfully set to the specified time.
     * @return if the clock was successfully set to the specified time.
     */
     */
    public static boolean setCurrentTimeMillis(long millis) {
    public static boolean setCurrentTimeMillis(long millis) {
        final IAlarmManager mgr = IAlarmManager.Stub
        final IAlarmManager mgr = getIAlarmManager();
                .asInterface(ServiceManager.getService(Context.ALARM_SERVICE));
        if (mgr == null) {
        if (mgr == null) {
            Slog.e(TAG, "Unable to set RTC: mgr == null");
            Slog.e(TAG, "Unable to set RTC: mgr == null");
            return false;
            return false;
@@ -280,8 +281,7 @@ public final class SystemClock {
     * @hide
     * @hide
     */
     */
    public static long currentNetworkTimeMillis() {
    public static long currentNetworkTimeMillis() {
        final IAlarmManager mgr = IAlarmManager.Stub
        final IAlarmManager mgr = getIAlarmManager();
                .asInterface(ServiceManager.getService(Context.ALARM_SERVICE));
        if (mgr != null) {
        if (mgr != null) {
            try {
            try {
                return mgr.currentNetworkTimeMillis();
                return mgr.currentNetworkTimeMillis();
@@ -296,6 +296,14 @@ public final class SystemClock {
        }
        }
    }
    }


    private static IAlarmManager getIAlarmManager() {
        if (sIAlarmManager == null) {
            sIAlarmManager = IAlarmManager.Stub
                    .asInterface(ServiceManager.getService(Context.ALARM_SERVICE));
        }
        return sIAlarmManager;
    }

    /**
    /**
     * Returns a {@link Clock} that starts at January 1, 1970 00:00:00.0 UTC,
     * Returns a {@link Clock} that starts at January 1, 1970 00:00:00.0 UTC,
     * synchronized using a remote network source outside the device.
     * synchronized using a remote network source outside the device.