Merge "Fix permission issues for network update service"

This commit is contained in:
Neil Fuller
2022-10-13 10:32:10 +00:00
committed by Android (Google) Code Review

View File

@@ -172,9 +172,14 @@ public class NetworkTimeUpdateService extends Binder {
mContext.enforceCallingPermission(
android.Manifest.permission.SET_TIME, "clear latest network time");
mTime.clearCachedTimeResult();
final long token = Binder.clearCallingIdentity();
try {
mTime.clearCachedTimeResult();
mLocalLog.log("clearTimeForTests");
mLocalLog.log("clearTimeForTests");
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
@@ -188,15 +193,19 @@ public class NetworkTimeUpdateService extends Binder {
mContext.enforceCallingPermission(
android.Manifest.permission.SET_TIME, "force network time refresh");
boolean success = mTime.forceRefresh();
mLocalLog.log("forceRefreshForTests: success=" + success);
final long token = Binder.clearCallingIdentity();
try {
boolean success = mTime.forceRefresh();
mLocalLog.log("forceRefreshForTests: success=" + success);
if (success) {
makeNetworkTimeSuggestion(mTime.getCachedTimeResult(),
"Origin: NetworkTimeUpdateService: forceRefreshForTests");
if (success) {
makeNetworkTimeSuggestion(mTime.getCachedTimeResult(),
"Origin: NetworkTimeUpdateService: forceRefreshForTests");
}
return success;
} finally {
Binder.restoreCallingIdentity(token);
}
return success;
}
/**
@@ -207,8 +216,13 @@ public class NetworkTimeUpdateService extends Binder {
mContext.enforceCallingPermission(
android.Manifest.permission.SET_TIME, "set NTP server config for tests");
mLocalLog.log("Setting server config for tests: ntpConnectionInfo=" + ntpConfig);
mTime.setServerConfigForTests(ntpConfig);
final long token = Binder.clearCallingIdentity();
try {
mLocalLog.log("Setting server config for tests: ntpConnectionInfo=" + ntpConfig);
mTime.setServerConfigForTests(ntpConfig);
} finally {
Binder.restoreCallingIdentity(token);
}
}
private void onPollNetworkTime(int event) {