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
Change-Id: I8a34c801d82c769fd8d06e5b0b3177ce92b5f072
This commit is contained in:
Neil Fuller
2022-10-12 21:20:36 +01:00
parent 1b3db4d5aa
commit bdf7b5dc78

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) {