Cache IAlarmManager binder handle.

Bug: 218909495
Test: treehugger
Change-Id: Ib73dac85999311993fa9f0d552609065c24a155c
This commit is contained in:
Sudheer Shanka
2022-02-11 15:44:38 -08:00
parent 4bfadd57b8
commit 7cbad8a063

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.