Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;

import app.notesr.core.security.crypto.CryptoManager;
import app.notesr.core.security.SecretCache;
import app.notesr.core.security.crypto.CryptoManagerProvider;
import app.notesr.data.DatabaseProvider;
import app.notesr.service.AndroidService;
Expand Down Expand Up @@ -81,6 +81,7 @@ protected AndroidServiceEntry getEntry(String payload, String state) {
@Override
public void onTaskRemoved(Intent rootIntent) {
if (getOtherRunningServicesCount() == 0) {
clearSecretCache();
closeDatabase();
destroySecrets();

Expand Down Expand Up @@ -116,6 +117,10 @@ long getOtherRunningServicesCount() {
.count();
}

void clearSecretCache() {
SecretCache.clear();
}

void closeDatabase() {
DatabaseProvider.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void setUp() {
@Test
void testOnTaskRemovedWhenNoOtherServicesRunningClosesEverythingAndExits() {
doReturn(0L).when(service).getOtherRunningServicesCount();
doNothing().when(service).clearSecretCache();
doNothing().when(service).closeDatabase();
doNothing().when(service).destroySecrets();
doNothing().when(service).stopForegroundService();
Expand All @@ -44,6 +45,9 @@ void testOnTaskRemovedWhenNoOtherServicesRunningClosesEverythingAndExits() {

service.onTaskRemoved(intent);

verify(service, description("Secret cache should be cleared" +
" when no other services are running"))
.clearSecretCache();
verify(service, description("Database should be closed" +
" when no other services are running"))
.closeDatabase();
Expand Down Expand Up @@ -74,6 +78,9 @@ void testOnTaskRemovedWhenOtherServicesRunningOnlyStopsSelf() {

service.onTaskRemoved(intent);

verify(service, never().description("Secret cache should NOT be cleared" +
" when other services are running"))
.clearSecretCache();
verify(service, never().description("Database should NOT be closed" +
" when other services are running"))
.closeDatabase();
Expand Down
Loading