Fix permission issues for network update service

Fix permission issues for network update service command-line commands
used in tests.

Bug: 251726675
Test: atest android.os.cts.SystemClockSntpTest
Merged-In: I8a34c801d82c769fd8d06e5b0b3177ce92b5f072
Change-Id: I8a34c801d82c769fd8d06e5b0b3177ce92b5f072
This commit is contained in:
Neil Fuller
2022-10-12 21:20:36 +01:00
parent de8f4b28ee
commit 605d4acdcd

View File

@@ -165,9 +165,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);
}
}
/**
@@ -181,15 +186,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;
}
/**
@@ -201,10 +210,15 @@ 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: hostname=" + hostname
+ ", port=" + port
+ ", timeout=" + timeout);
mTime.setServerConfigForTests(hostname, port, timeout);
final long token = Binder.clearCallingIdentity();
try {
mLocalLog.log("Setting server config for tests: hostname=" + hostname
+ ", port=" + port
+ ", timeout=" + timeout);
mTime.setServerConfigForTests(hostname, port, timeout);
} finally {
Binder.restoreCallingIdentity(token);
}
}
private void onPollNetworkTime(int event) {