Skip to content

Commit

Permalink
Removed profile idle timer (#259)
Browse files Browse the repository at this point in the history
* Removed profile idle timer

* Fixed failing tests
  • Loading branch information
nunommts authored Nov 13, 2023
1 parent f7102dc commit 4ed88dc
Show file tree
Hide file tree
Showing 18 changed files with 3 additions and 579 deletions.
5 changes: 3 additions & 2 deletions README-CHANGES.xml
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
<c:change date="2022-04-29T00:00:00+00:00" summary="Fixed &quot;Unable to initialize audio engine&quot; error playing some audio books."/>
</c:changes>
</c:release>
<c:release date="2023-11-10T14:25:49+00:00" is-open="true" ticket-system="org.lyrasis.jira" version="1.8.0">
<c:release date="2023-11-10T16:44:59+00:00" is-open="true" ticket-system="org.lyrasis.jira" version="1.8.0">
<c:changes>
<c:change date="2023-11-07T00:00:00+00:00" summary="Book sample buttons are no longer displayed for loaned books.">
<c:tickets>
Expand All @@ -389,11 +389,12 @@
</c:change>
<c:change date="2023-11-09T00:00:00+00:00" summary="Started using device registration URI from patron authentication document."/>
<c:change date="2023-11-10T00:00:00+00:00" summary="Updated notification calls to be run in a background thread."/>
<c:change date="2023-11-10T14:25:49+00:00" summary="Prevent a crash caused by tabs and the back button.">
<c:change date="2023-11-10T00:00:00+00:00" summary="Prevent a crash caused by tabs and the back button.">
<c:tickets>
<c:ticket id="PP-714"/>
</c:tickets>
</c:change>
<c:change date="2023-11-10T16:44:59+00:00" summary="Removed profile idle timer."/>
</c:changes>
</c:release>
</c:releases>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ import org.nypl.simplified.profiles.api.ProfileUpdated
import org.nypl.simplified.profiles.api.ProfilesDatabaseType
import org.nypl.simplified.profiles.api.ProfilesDatabaseType.AnonymousProfileEnabled
import org.nypl.simplified.profiles.api.ProfilesDatabaseType.AnonymousProfileEnabled.ANONYMOUS_PROFILE_ENABLED
import org.nypl.simplified.profiles.api.idle_timer.ProfileIdleTimerType
import org.nypl.simplified.profiles.controller.api.ProfileAccountCreationStringResourcesType
import org.nypl.simplified.profiles.controller.api.ProfileAccountDeletionStringResourcesType
import org.nypl.simplified.profiles.controller.api.ProfileAccountLoginRequest
Expand Down Expand Up @@ -141,8 +140,6 @@ class Controller private constructor(
this.services.requireService(ProfilesDatabaseType::class.java)
private val revokeStrings =
this.services.requireService(BookRevokeStringResourcesType::class.java)
private val profileIdleTimer =
this.services.requireService(ProfileIdleTimerType::class.java)
private val crashlytics =
this.services.optionalService(CrashlyticsServiceType::class.java)
private val metrics =
Expand Down Expand Up @@ -575,10 +572,6 @@ class Controller private constructor(
throw UnreachableCodeException()
}

override fun profileIdleTimer(): ProfileIdleTimerType {
return this.profileIdleTimer
}

override fun bookBorrow(
accountID: AccountID,
bookID: BookID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,6 @@ class MainActivity : AppCompatActivity(R.layout.main_host) {
return true
}

override fun onUserInteraction() {
super.onUserInteraction()

/*
* Each time the user interacts with something onscreen, reset the timer.
*/

if (Services.isInitialized()) {
Services.serviceDirectory()
.requireService(ProfilesControllerType::class.java)
.profileIdleTimer()
.reset()
}
}

override fun onStart() {
super.onStart()
this.listenerRepo.registerHandler(this::handleEvent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ import org.nypl.simplified.listeners.api.ListenerRepository
import org.nypl.simplified.listeners.api.listenerRepositories
import org.nypl.simplified.profiles.api.ProfileEvent
import org.nypl.simplified.profiles.api.ProfileUpdated
import org.nypl.simplified.profiles.api.ProfilesDatabaseType.AnonymousProfileEnabled.ANONYMOUS_PROFILE_DISABLED
import org.nypl.simplified.profiles.api.ProfilesDatabaseType.AnonymousProfileEnabled.ANONYMOUS_PROFILE_ENABLED
import org.nypl.simplified.profiles.api.idle_timer.ProfileIdleTimeOutSoon
import org.nypl.simplified.profiles.api.idle_timer.ProfileIdleTimedOut
import org.nypl.simplified.ui.accounts.AccountListFragment
import org.nypl.simplified.ui.accounts.AccountListFragmentParameters
import org.nypl.simplified.ui.announcements.AnnouncementsDialog
Expand Down Expand Up @@ -78,19 +74,6 @@ class MainFragment : Fragment(R.layout.main_tabbed_host) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

/*
* If named profiles are enabled, subscribe to profile timer events so that users are
* logged out after a period of inactivity.
*/

when (viewModel.profilesController.profileAnonymousEnabled()) {
ANONYMOUS_PROFILE_ENABLED -> {
}
ANONYMOUS_PROFILE_DISABLED -> {
viewModel.profilesController.profileIdleTimer().start()
}
}

/*
* Demand that onOptionsItemSelected be called.
*/
Expand Down Expand Up @@ -205,13 +188,6 @@ class MainFragment : Fragment(R.layout.main_tabbed_host) {
when (event) {
is ProfileUpdated.Succeeded ->
this.onProfileUpdateSucceeded(event)

is ProfileIdleTimeOutSoon -> {
// Unused
}
is ProfileIdleTimedOut -> {
// Unused
}
}
}

Expand Down Expand Up @@ -346,18 +322,6 @@ class MainFragment : Fragment(R.layout.main_tabbed_host) {
this.subscriptions.clear()
}

override fun onDestroy() {
super.onDestroy()

when (viewModel.profilesController.profileAnonymousEnabled()) {
ANONYMOUS_PROFILE_ENABLED -> {
}
ANONYMOUS_PROFILE_DISABLED -> {
viewModel.profilesController.profileIdleTimer().stop()
}
}
}

override val defaultViewModelProviderFactory: ViewModelProvider.Factory
get() = this.defaultViewModelFactory
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ import org.nypl.simplified.profiles.ProfilesDatabases
import org.nypl.simplified.profiles.api.ProfileDatabaseException
import org.nypl.simplified.profiles.api.ProfileEvent
import org.nypl.simplified.profiles.api.ProfilesDatabaseType
import org.nypl.simplified.profiles.api.idle_timer.ProfileIdleTimer
import org.nypl.simplified.profiles.api.idle_timer.ProfileIdleTimerConfigurationServiceType
import org.nypl.simplified.profiles.api.idle_timer.ProfileIdleTimerType
import org.nypl.simplified.profiles.controller.api.ProfileAccountCreationStringResourcesType
import org.nypl.simplified.profiles.controller.api.ProfileAccountDeletionStringResourcesType
import org.nypl.simplified.profiles.controller.api.ProfilesControllerType
Expand Down Expand Up @@ -406,14 +403,6 @@ internal object MainServices {
.firstOrNull()
}

private fun createProfileIdleTimer(
profileEvents: PublishSubject<ProfileEvent>
): ProfileIdleTimerType {
val execProfileTimer =
NamedThreadPools.namedThreadPool(1, "profile-timer", 19)
return ProfileIdleTimer.create(execProfileTimer, profileEvents)
}

private fun createBookmarksService(
http: LSHTTPClientType,
bookController: ProfilesControllerType
Expand Down Expand Up @@ -498,23 +487,6 @@ internal object MainServices {
throw IllegalStateException("Missing build configuration service")
}

private fun findIdleTimerConfiguration(): ProfileIdleTimerConfigurationServiceType {
val existing =
this.optionalFromServiceLoader(ProfileIdleTimerConfigurationServiceType::class.java)

if (existing != null) {
return existing
}

this.logger.debug("returning fallback idle timer configuration service")
return object : ProfileIdleTimerConfigurationServiceType {
override val warningWhenSecondsRemaining: Int
get() = 60
override val logOutAfterSeconds: Int
get() = 10 * 60
}
}

fun setup(
context: Context,
onProgress: (BootEvent) -> Unit
Expand Down Expand Up @@ -890,11 +862,6 @@ internal object MainServices {
)

val profileEvents = PublishSubject.create<ProfileEvent>()
addService(
message = strings.bootingGeneral("profile idle timer"),
interfaceType = ProfileIdleTimerType::class.java,
serviceConstructor = { this.createProfileIdleTimer(profileEvents) }
)

addService(
message = strings.bootingGeneral("audio book manifest strategies"),
Expand Down Expand Up @@ -1014,17 +981,6 @@ internal object MainServices {
serviceConstructor = { NetworkConnectivity.create(context) }
)

val idleTimerConfiguration =
addService(
message = strings.bootingGeneral("idle timer configuration service"),
interfaceType = ProfileIdleTimerConfigurationServiceType::class.java,
serviceConstructor = { this.findIdleTimerConfiguration() }
)

val idleTimer = bookController.profileIdleTimer()
idleTimer.setWarningIdleSecondsRemaining(idleTimerConfiguration.warningWhenSecondsRemaining)
idleTimer.setMaximumIdleSeconds(idleTimerConfiguration.logOutAfterSeconds)

addService(
message = strings.bootingGeneral("migrations"),
interfaceType = MigrationsType::class.java,
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4ed88dc

Please sign in to comment.