This PR fixes some issues with connections and threading. Specifically, the change in #618 introduced threading in `HostConnection`, which had some issues. To fix them, the following changes were made:
- A specific TCP listener thread is used and manually started, instead of using one of the threads in the pool. The TCP listener thread is a long lived thread that should always be running (as long as the connection is through TCP), blocked listening on the TCP socket, so it shouldn't be managed in a pool, where, theoretically, it can be paused and reused.
- Changed the number of threads to 5. We shouldn't need more than this, otherwise we can overwhelm some Kodi hardware.
- Had to sprinkle some `synchronized` to avoid race conditions. For instance, through a TCP connection, as soon as Kore is opened (on the remote screen) it will call at least `GetActivePlayers`, `GetProperties`, `Ping`. If the TCP socket isn't set up yet, each of these calls would create a socket (and a TCP listener thread), so we would open 3 or more sockets when we should just open 1. A `synchronized` in `executeThroughTcp` prevents this. The others prevent similar issues.
Aditionally:
- Tweaked the playlist fetching code, so that it happens exclusively in `HostConnectionObserver` and when PlaylistFragment is notified of changes, it already gets the playlist data. This somewhat simplifies the code, and makes it more consistent with the Player Observer code;
- Change `EventServerConnection` to accept a Handler on which to post the result of the connection, so that the caller can control on which thread the result is called;
- Calls to the various `RegisterObserver` loose the reply immediately parameter, as it was always true.
Added support for handling multiple playlists in the Mock TCP server.
Refactored SlideUpPanelTests to support the new playlist handler.
Some code cleanup and enhancements
- Removed throw exception declarations from methods that never throw the exception.
- Changed deleting the test database on the test device to delete all databases.
The former method of only deleting the test database resulted in many old databases
that were not removed when the test run crashed.
- Enhanced robustness of testing async code by explicitly waiting for a view
to reach a certain state.
After a library clean operation on Kodi, if a TV Show that was previously present is absent it is still returned in a call to `VideoLibrary.GetTVShows` with 0 episodes. Kore shouldn't consider these TV Shows, as they have no episodes.
Some ANRs are reported on Google Play. This is an atempt to remove them, by making sure that `startForeground` is always called when the service starts.
Implemented showing a music/video/picture playlist in PlaylistFragment even
when playback has stopped but the playlist is still available on Kodi.
The playlist is now only cleared if the Playlist.OnClear event is received
from Kodi.
As the pictures playlist does not support moving/removing items this has
been disabled for the pictures playlist only.
Added a new package org.xbmc.kore.host.actions to hold all Callable's that
we use to handle complex interactions with Kodi that use multiple JSON RPC
calls.
Fixed issue in HostConnectionObserver in method notifySomethingIsPlaying
where hostState.lastGetItemResult.label might not be set.
Reduced calling (force)refreshPlaylist considerably as it should now be
handled by the playlist observer.
Registering observers would cause the runnables to be
posted multiple times to the checkerHandler. This resulted
in callbacks being called more than once when a result was
received.
When the title is longer than fits on screen, it wil first be ellipsized
and when user clicks on the title it will start scrolling to make it
fully readable.
* This gives the user a choice of their hosts to share a url to.
* Sadly the youtube app doesn't appear to support this. It wants to
use some sort of crappy "Message on Youtube" thing rather than using
standard android stuff (go figure). It does, however, work from a
chrome browser of the youtube video, or likely any other supported
share.
* Fixed Espresso not waiting on ViewPager switching
* Removed BaseMediaActivityTests abstract class.
Unfortunately the click action on list items now requires
a unique item to be able to select the item to click.
Therefore the tests from BaseMediaActivityTests have been
moved to the specific test classes. This made the
BaseMediaActivityTests class obsolete.
* Removed dependency on Context class in AddonsHandler and inlined
the json data to allow the AddonsHandler to be initialized before
the test activity is started. This was needed to have the
AddonsActivityTests directly start the AddonsActivity, instead of
first starting MoviesActivity and from there start the AddonsActivity.
Hitting the back button in the remote activity was being ignored, thus preventing exiting the app. This issue was inadvertidely introduced in d11dbe6853
The onDestroyView method is used to unregister the application observer
from the dialog. However the parent got called first which destroys the
view of the dialog. This could lead to Null Pointer Exceptions when
the listener tries to update the UI of the dialog right after it was
destroyed.
The VolumeControllerDialogFragmentListener was created twice as creation
was triggered on both the down and up event of the volume keys. This has
been changed to only trigger on down events.
The applicationObserver was never unregistered resulting in a memory leak
and even worse, crashes when destroyed dialogs still got called through
the applicationOnVolumeChanged callback.
Also changed the view resource identifiers used by the controller dialog
as it used the same resource identifiers as the now playing panel.
Somewhere along the line, the edits made in b0f2adb876 where lost because the `AddonsActivity` was instantiating `AddonListFragment` instead of `AddonListContainerFragment`.
This PR reinstates the ability to bookmark and access addons, and refactors the way those settings were being stored in the Shared Preferences to use the default Shared Preferences and take into account the specific host we're connected to.
During tests, activities were not closed properly causing increasing
memory usage, which resulted in failing tests because of
out of memory errors.
This has been fixed by using the test orchestrator which runs
each test in its own instrumentation instance.
Removed the instrumentationTest flavor and replaced it by using the
default debug build type. The flavor was used to keep the required
permissions during testing separate from release versions. This can
also be accomplished using the debug build type.
The PagerSlidingTabStrip from astuetz doesn't work with the new
android build tools. As the project seems dead, I replaced it with
PagerTabStrip from the support library.
Refactored MusicListFragment and PVRListFragment to use AbstractTabsFragment
Fixed scrolling in a nested scroll view using espresso
Fixed issue with setting and checking Kodi major version
When a silent sync is running the refresh animation shouldn't appear and this wasn't being repected in some situations. For instance, when not connected to Kodi, starting from a TV Show details, selecting one episode or season and hitting back, the animation would appear. This PR makes sure that it is only shown if it isn't silent.