Merge "Change OtDaemonState ephemeralKeyExpiryMillis to ephemeralKeyLifetimeMillis" into main

This commit is contained in:
Yang Sun 2024-10-11 01:19:01 +00:00 • committed by Gerrit Code Review
commit adee3295ff
4 changed files with 10 additions and 6 deletions

View file

@ -24,5 +24,5 @@ oneway interface IStateCallback {
void onPartitionIdChanged(long partitionId);
void onThreadEnableStateChanged(int enabledState);
void onEphemeralKeyStateChanged(
int ephemeralKeyState, @nullable String ephemeralKey, long expiryMillis);
int ephemeralKeyState, @nullable String ephemeralKey, long lifetimeMillis);
}

View file

@ -420,7 +420,9 @@ public final class ThreadNetworkController {
@Override
public void onEphemeralKeyStateChanged(
@EphemeralKeyState int ephemeralKeyState, String ephemeralKey, long expiryMillis) {
@EphemeralKeyState int ephemeralKeyState,
String ephemeralKey,
long lifetimeMillis) {
if (!Flags.epskcEnabled()) {
throw new IllegalStateException(
"This should not be called when Ephemeral key API is disabled");
@ -430,7 +432,7 @@ public final class ThreadNetworkController {
final Instant expiry =
ephemeralKeyState == EPHEMERAL_KEY_DISABLED
? null
: Instant.ofEpochMilli(expiryMillis);
: Instant.now().plusMillis(lifetimeMillis);
try {
mExecutor.execute(

View file

@ -1785,7 +1785,7 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub
.onEphemeralKeyStateChanged(
newState.ephemeralKeyState,
passcode,
newState.ephemeralKeyExpiryMillis);
newState.ephemeralKeyLifetimeMillis);
} catch (RemoteException ignored) {
// do nothing if the client is dead
}
@ -1798,7 +1798,7 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub
if (oldState.ephemeralKeyState != newState.ephemeralKeyState) return true;
if (oldState.ephemeralKeyState == EPHEMERAL_KEY_DISABLED) return false;
return (!Objects.equals(oldState.ephemeralKeyPasscode, newState.ephemeralKeyPasscode)
|| oldState.ephemeralKeyExpiryMillis != newState.ephemeralKeyExpiryMillis);
|| oldState.ephemeralKeyLifetimeMillis != newState.ephemeralKeyLifetimeMillis);
}
private void onActiveOperationalDatasetChanged(

View file

@ -1043,7 +1043,9 @@ public class ThreadNetworkControllerTest {
listener2.expectThreadEphemeralKeyMode(EPHEMERAL_KEY_ENABLED);
assertThat(epskc2.getSecond()).isEqualTo(epskc1.getSecond());
assertThat(epskc2.getThird()).isEqualTo(epskc1.getThird());
// allow time precision loss of a second since the value is passed via IPC
assertThat(epskc2.getThird()).isGreaterThan(epskc1.getThird().minusSeconds(1));
assertThat(epskc2.getThird()).isLessThan(epskc1.getThird().plusSeconds(1));
} finally {
listener2.unregisterStateCallback();
}