Skip to content

Commit bb708f0

Browse files
authored
Add missing annotation (#136)
*Add missing nullable annotation for calls in kotlin
1 parent 90745f5 commit bb708f0

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

core/src/main/java/io/snabble/sdk/auth/TokenRegistry.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public void invalidate() {
5151
tokens.clear();
5252
}
5353

54+
@Nullable
5455
private synchronized Token refreshToken(Project project, boolean isRetry) {
5556
if (totp == null) {
5657
return null;
@@ -162,19 +163,16 @@ private long getOffsetTime() {
162163
* <p>
163164
* Returns null if not valid token could be generated. (invalid secret, timeouts, no connection)
164165
*/
165-
public synchronized Token getToken(Project project) {
166+
@Nullable
167+
public synchronized Token getToken(@Nullable Project project) {
166168
if (project == null) {
167169
return null;
168170
}
169171

170172
Token token = tokens.get(project.getId());
171173

172174
if (token != null) {
173-
long tokenInterval = (token.expiresAt - token.issuedAt);
174-
long invalidAt = token.issuedAt + tokenInterval / 2;
175-
176-
long seconds = getOffsetTime();
177-
if (seconds >= invalidAt) {
175+
if (isValid(token)) {
178176
Logger.d("Token timed out, requesting new token");
179177
Token newToken = refreshToken(project, false);
180178
if (newToken != null) {
@@ -190,20 +188,6 @@ public synchronized Token getToken(Project project) {
190188
return token;
191189
}
192190

193-
/**
194-
* Returns the locally stored token or null if invalid
195-
*/
196-
@Nullable
197-
public Token getLocalToken(@NonNull final Project project) {
198-
final Token token = tokens.get(project.getId());
199-
200-
if (isValid(token)) {
201-
return token;
202-
} else {
203-
return null;
204-
}
205-
}
206-
207191
@NonNull
208192
private Boolean isValid(@Nullable final Token token) {
209193
if (token == null) return false;

0 commit comments

Comments
 (0)