Merge "Cache IAlarmManager binder handle."

This commit is contained in:
Sudheer Shanka
2022-02-15 21:39:43 +00:00
committed by Android (Google) Code Review

View File

@@ -104,6 +104,8 @@ import java.time.ZoneOffset;
public final class SystemClock {
private static final String TAG = "SystemClock";
private static volatile IAlarmManager sIAlarmManager;
/**
* This class is uninstantiable.
*/
@@ -151,8 +153,7 @@ public final class SystemClock {
* @return if the clock was successfully set to the specified time.
*/
public static boolean setCurrentTimeMillis(long millis) {
final IAlarmManager mgr = IAlarmManager.Stub
.asInterface(ServiceManager.getService(Context.ALARM_SERVICE));
final IAlarmManager mgr = getIAlarmManager();
if (mgr == null) {
Slog.e(TAG, "Unable to set RTC: mgr == null");
return false;
@@ -280,8 +281,7 @@ public final class SystemClock {
* @hide
*/
public static long currentNetworkTimeMillis() {
final IAlarmManager mgr = IAlarmManager.Stub
.asInterface(ServiceManager.getService(Context.ALARM_SERVICE));
final IAlarmManager mgr = getIAlarmManager();
if (mgr != null) {
try {
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,
* synchronized using a remote network source outside the device.