Add Kodi version to Hosts table on DB and keep it periodically updated
This commit is contained in:
parent
39ee0b6634
commit
a4945c8534
|
@ -16,6 +16,7 @@
|
|||
package org.xbmc.kore.host;
|
||||
|
||||
import org.xbmc.kore.jsonrpc.HostConnection;
|
||||
import org.xbmc.kore.jsonrpc.method.System;
|
||||
import org.xbmc.kore.utils.LogUtils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
@ -49,7 +50,12 @@ public class HostInfo {
|
|||
*/
|
||||
public static final int DEFAULT_EVENT_SERVER_PORT = 9777;
|
||||
|
||||
/**
|
||||
public static final int DEFAULT_KODI_VERSION_MAJOR = 16;
|
||||
public static final int DEFAULT_KODI_VERSION_MINOR = 1;
|
||||
public static final String DEFAULT_KODI_VERSION_REVISION = "Unknown";
|
||||
public static final String DEFAULT_KODI_VERSION_TAG = "stable";
|
||||
|
||||
/**
|
||||
* Internal id of the host
|
||||
*/
|
||||
private int id;
|
||||
|
@ -86,6 +92,20 @@ public class HostInfo {
|
|||
*/
|
||||
private int protocol;
|
||||
|
||||
|
||||
/**
|
||||
* Kodi Version
|
||||
*/
|
||||
private int kodiVersionMajor;
|
||||
private int kodiVersionMinor;
|
||||
private String kodiVersionRevision;
|
||||
private String kodiVersionTag;
|
||||
|
||||
/**
|
||||
* Last time updated (in millis)
|
||||
*/
|
||||
private long updated;
|
||||
|
||||
private String auxImageHttpAddress;
|
||||
|
||||
/**
|
||||
|
@ -102,7 +122,9 @@ public class HostInfo {
|
|||
*/
|
||||
public HostInfo(int id, String name, String address, int protocol, int httpPort, int tcpPort,
|
||||
String username, String password, String macAddress, int wolPort,
|
||||
boolean useEventServer, int eventServerPort) {
|
||||
boolean useEventServer, int eventServerPort,
|
||||
int kodiVersionMajor, int kodiVersionMinor, String kodiVersionRevision, String kodiVersionTag,
|
||||
long updated) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.address = address;
|
||||
|
@ -120,6 +142,12 @@ public class HostInfo {
|
|||
this.useEventServer = useEventServer;
|
||||
this.eventServerPort = eventServerPort;
|
||||
|
||||
this.kodiVersionMajor = kodiVersionMajor;
|
||||
this.kodiVersionMinor = kodiVersionMinor;
|
||||
this.kodiVersionRevision = kodiVersionRevision;
|
||||
this.kodiVersionTag = kodiVersionTag;
|
||||
this.updated = updated;
|
||||
|
||||
// For performance reasons
|
||||
this.auxImageHttpAddress = getHttpURL() + "/image/";
|
||||
}
|
||||
|
@ -139,7 +167,10 @@ public class HostInfo {
|
|||
int tcpPort, String username, String password,
|
||||
boolean useEventServer, int eventServerPort) {
|
||||
this(-1, name, address, protocol, httpPort, tcpPort, username,
|
||||
password, null, DEFAULT_WOL_PORT, useEventServer, eventServerPort);
|
||||
password, null, DEFAULT_WOL_PORT, useEventServer, eventServerPort,
|
||||
DEFAULT_KODI_VERSION_MAJOR, DEFAULT_KODI_VERSION_MINOR,
|
||||
DEFAULT_KODI_VERSION_REVISION, DEFAULT_KODI_VERSION_TAG,
|
||||
0);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
@ -198,7 +229,27 @@ public class HostInfo {
|
|||
return eventServerPort;
|
||||
}
|
||||
|
||||
/**
|
||||
public int getKodiVersionMajor() {
|
||||
return kodiVersionMajor;
|
||||
}
|
||||
|
||||
public int getKodiVersionMinor() {
|
||||
return kodiVersionMinor;
|
||||
}
|
||||
|
||||
public String getKodiVersionRevision() {
|
||||
return kodiVersionRevision;
|
||||
}
|
||||
|
||||
public String getKodiVersionTag() {
|
||||
return kodiVersionTag;
|
||||
}
|
||||
|
||||
public long getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the protocol for this host info
|
||||
* @param protocol Protocol
|
||||
*/
|
||||
|
@ -217,6 +268,22 @@ public class HostInfo {
|
|||
this.useEventServer = useEventServer;
|
||||
}
|
||||
|
||||
public void setKodiVersionMajor(int kodiVersionMajor) {
|
||||
this.kodiVersionMajor = kodiVersionMajor;
|
||||
}
|
||||
|
||||
public void setKodiVersionMinor(int kodiVersionMinor) {
|
||||
this.kodiVersionMinor = kodiVersionMinor;
|
||||
}
|
||||
|
||||
public void setKodiVersionRevision(String kodiVersionRevision) {
|
||||
this.kodiVersionRevision = kodiVersionRevision;
|
||||
}
|
||||
|
||||
public void setKodiVersionTag(String kodiVersionTag) {
|
||||
this.kodiVersionTag = kodiVersionTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL of the host
|
||||
* @return HTTP URL eg. http://192.168.1.1:8080
|
||||
|
|
|
@ -20,8 +20,10 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.Base64;
|
||||
|
||||
import com.squareup.okhttp.Interceptor;
|
||||
|
@ -33,7 +35,11 @@ import com.squareup.picasso.Picasso;
|
|||
|
||||
import org.xbmc.kore.BuildConfig;
|
||||
import org.xbmc.kore.Settings;
|
||||
import org.xbmc.kore.jsonrpc.ApiCallback;
|
||||
import org.xbmc.kore.jsonrpc.HostConnection;
|
||||
import org.xbmc.kore.jsonrpc.method.Application;
|
||||
import org.xbmc.kore.jsonrpc.method.System;
|
||||
import org.xbmc.kore.jsonrpc.type.ApplicationType;
|
||||
import org.xbmc.kore.provider.MediaContract;
|
||||
import org.xbmc.kore.utils.BasicAuthUrlConnectionDownloader;
|
||||
import org.xbmc.kore.utils.LogUtils;
|
||||
|
@ -145,8 +151,16 @@ public class HostManager {
|
|||
boolean useEventServer = (cursor.getInt(idx++) != 0);
|
||||
int eventServerPort = cursor.getInt(idx++);
|
||||
|
||||
hosts.add(new HostInfo(id, name, address, protocol, httpPort, tcpPort,
|
||||
username, password, macAddress, wolPort, useEventServer, eventServerPort));
|
||||
int kodiVersionMajor = cursor.getInt(idx++);
|
||||
int kodiVersionMinor = cursor.getInt(idx++);
|
||||
String kodiVersionRevision = cursor.getString(idx++);
|
||||
String kodiVersionTag = cursor.getString(idx++);
|
||||
|
||||
hosts.add(new HostInfo(
|
||||
id, name, address, protocol, httpPort, tcpPort,
|
||||
username, password, macAddress, wolPort, useEventServer, eventServerPort,
|
||||
kodiVersionMajor, kodiVersionMinor, kodiVersionRevision, kodiVersionTag,
|
||||
updated));
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
|
@ -312,10 +326,11 @@ public class HostManager {
|
|||
hostInfo.getHttpPort(), hostInfo.getTcpPort(),
|
||||
hostInfo.getUsername(), hostInfo.getPassword(),
|
||||
hostInfo.getMacAddress(), hostInfo.getWolPort(),
|
||||
hostInfo.getUseEventServer(), hostInfo.getEventServerPort());
|
||||
hostInfo.getUseEventServer(), hostInfo.getEventServerPort(),
|
||||
hostInfo.getKodiVersionMajor(), hostInfo.getKodiVersionMinor(),
|
||||
hostInfo.getKodiVersionRevision(), hostInfo.getKodiVersionTag());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a new XBMC host to the database
|
||||
* @param name Name of this instance
|
||||
|
@ -329,7 +344,8 @@ public class HostManager {
|
|||
*/
|
||||
public HostInfo addHost(String name, String address, int protocol, int httpPort, int tcpPort,
|
||||
String username, String password, String macAddress, int wolPort,
|
||||
boolean useEventServer, int eventServerPort) {
|
||||
boolean useEventServer, int eventServerPort,
|
||||
int kodiVersionMajor, int kodiVersionMinor, String kodiVersionRevision, String kodiVersionTag) {
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(MediaContract.HostsColumns.NAME, name);
|
||||
|
@ -344,6 +360,11 @@ public class HostManager {
|
|||
values.put(MediaContract.HostsColumns.USE_EVENT_SERVER, useEventServer);
|
||||
values.put(MediaContract.HostsColumns.EVENT_SERVER_PORT, eventServerPort);
|
||||
|
||||
values.put(MediaContract.HostsColumns.KODI_VERSION_MAJOR, kodiVersionMajor);
|
||||
values.put(MediaContract.HostsColumns.KODI_VERSION_MINOR, kodiVersionMinor);
|
||||
values.put(MediaContract.HostsColumns.KODI_VERSION_REVISION, kodiVersionRevision);
|
||||
values.put(MediaContract.HostsColumns.KODI_VERSION_TAG, kodiVersionTag);
|
||||
|
||||
Uri newUri = context.getContentResolver()
|
||||
.insert(MediaContract.Hosts.CONTENT_URI, values);
|
||||
long newId = Long.valueOf(MediaContract.Hosts.getHostId(newUri));
|
||||
|
@ -380,6 +401,11 @@ public class HostManager {
|
|||
values.put(MediaContract.HostsColumns.USE_EVENT_SERVER, newHostInfo.getUseEventServer());
|
||||
values.put(MediaContract.HostsColumns.EVENT_SERVER_PORT, newHostInfo.getEventServerPort());
|
||||
|
||||
values.put(MediaContract.HostsColumns.KODI_VERSION_MAJOR, newHostInfo.getKodiVersionMajor());
|
||||
values.put(MediaContract.HostsColumns.KODI_VERSION_MINOR, newHostInfo.getKodiVersionMinor());
|
||||
values.put(MediaContract.HostsColumns.KODI_VERSION_REVISION, newHostInfo.getKodiVersionRevision());
|
||||
values.put(MediaContract.HostsColumns.KODI_VERSION_TAG, newHostInfo.getKodiVersionTag());
|
||||
|
||||
context.getContentResolver()
|
||||
.update(MediaContract.Hosts.buildHostUri(hostId), values, null, null);
|
||||
|
||||
|
@ -452,4 +478,42 @@ public class HostManager {
|
|||
currentPicasso = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Check Kodi's version every 2 days
|
||||
private final static long KODI_VERSION_CHECK_INTERVAL_MILLIS = 2 * DateUtils.DAY_IN_MILLIS;
|
||||
|
||||
/**
|
||||
* Periodic checks Kodi's version and updates the DB to reflect that.
|
||||
* This should be called somewhere that gets executed periodically
|
||||
*
|
||||
* @param hostInfo Host for which to check version
|
||||
*/
|
||||
public void checkAndUpdateKodiVersion(final HostInfo hostInfo) {
|
||||
if (hostInfo.getUpdated() + KODI_VERSION_CHECK_INTERVAL_MILLIS < java.lang.System.currentTimeMillis()) {
|
||||
LogUtils.LOGD(TAG, "Checking Kodi version...");
|
||||
final HostConnection hostConnection = new HostConnection(hostInfo);
|
||||
final Application.GetProperties getProperties = new Application.GetProperties(Application.GetProperties.VERSION);
|
||||
getProperties.execute(hostConnection, new ApiCallback<ApplicationType.PropertyValue>() {
|
||||
@Override
|
||||
public void onSuccess(ApplicationType.PropertyValue result) {
|
||||
LogUtils.LOGD(TAG, "Successfully checked Kodi version.");
|
||||
hostInfo.setKodiVersionMajor(result.version.major);
|
||||
hostInfo.setKodiVersionMinor(result.version.minor);
|
||||
hostInfo.setKodiVersionRevision(result.version.revision);
|
||||
hostInfo.setKodiVersionTag(result.version.tag);
|
||||
|
||||
editHost(hostInfo.getId(), hostInfo);
|
||||
|
||||
hostConnection.disconnect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int errorCode, String description) {
|
||||
// Couldn't get Kodi version... Ignore
|
||||
LogUtils.LOGD(TAG, "Couldn't get Kodi version. Error: " + description);
|
||||
hostConnection.disconnect();
|
||||
}
|
||||
}, new Handler());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,6 +66,11 @@ public class MediaContract {
|
|||
String WOL_PORT = "wol_port";
|
||||
String USE_EVENT_SERVER = "use_event_server";
|
||||
String EVENT_SERVER_PORT = "event_server_port";
|
||||
|
||||
String KODI_VERSION_MAJOR = "kodi_version_major";
|
||||
String KODI_VERSION_MINOR = "kodi_version_minor";
|
||||
String KODI_VERSION_REVISION = "kodi_version_revision";
|
||||
String KODI_VERSION_TAG = "kodi_version_tag";
|
||||
}
|
||||
|
||||
public static class Hosts implements BaseColumns, SyncColumns, HostsColumns {
|
||||
|
@ -89,7 +94,8 @@ public class MediaContract {
|
|||
|
||||
public final static String[] ALL_COLUMNS = {
|
||||
_ID, UPDATED, NAME, ADDRESS, PROTOCOL, HTTP_PORT, TCP_PORT, USERNAME, PASSWORD,
|
||||
MAC_ADDRESS, WOL_PORT, USE_EVENT_SERVER, EVENT_SERVER_PORT
|
||||
MAC_ADDRESS, WOL_PORT, USE_EVENT_SERVER, EVENT_SERVER_PORT,
|
||||
KODI_VERSION_MAJOR, KODI_VERSION_MINOR, KODI_VERSION_REVISION, KODI_VERSION_TAG
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,8 @@ public class MediaDatabase extends SQLiteOpenHelper {
|
|||
DB_VERSION_PRE_SONG_ARTISTS = 5,
|
||||
DB_VERSION_PRE_SONG_DISPLAY_ARTIST = 6,
|
||||
DB_VERSION_PRE_SONG_DISC = 7,
|
||||
DB_VERSION = 8;
|
||||
DB_VERSION_PRE_HOST_VERSION = 8,
|
||||
DB_VERSION = 9;
|
||||
|
||||
/**
|
||||
* Tables exposed
|
||||
|
@ -151,7 +152,12 @@ public class MediaDatabase extends SQLiteOpenHelper {
|
|||
MediaContract.HostsColumns.MAC_ADDRESS + " TEXT, " +
|
||||
MediaContract.HostsColumns.WOL_PORT + " INTEGER, " +
|
||||
MediaContract.HostsColumns.USE_EVENT_SERVER + " INTEGER, " +
|
||||
MediaContract.HostsColumns.EVENT_SERVER_PORT + " INTEGER)"
|
||||
MediaContract.HostsColumns.EVENT_SERVER_PORT + " INTEGER, " +
|
||||
|
||||
MediaContract.HostsColumns.KODI_VERSION_MAJOR + " INTEGER, " +
|
||||
MediaContract.HostsColumns.KODI_VERSION_MINOR + " INTEGER, " +
|
||||
MediaContract.HostsColumns.KODI_VERSION_REVISION + " TEXT, " +
|
||||
MediaContract.HostsColumns.KODI_VERSION_TAG + " TEXT)"
|
||||
);
|
||||
|
||||
// Movies
|
||||
|
@ -496,6 +502,19 @@ public class MediaDatabase extends SQLiteOpenHelper {
|
|||
db.execSQL("ALTER TABLE " + Tables.SONGS +
|
||||
" ADD COLUMN " + MediaContract.SongsColumns.DISC +
|
||||
" INTEGER DEFAULT 1;");
|
||||
case DB_VERSION_PRE_HOST_VERSION:
|
||||
db.execSQL("ALTER TABLE " + Tables.HOSTS +
|
||||
" ADD COLUMN " + MediaContract.HostsColumns.KODI_VERSION_MAJOR +
|
||||
" INTEGER DEFAULT " + String.valueOf(HostInfo.DEFAULT_KODI_VERSION_MAJOR) + ";");
|
||||
db.execSQL("ALTER TABLE " + Tables.HOSTS +
|
||||
" ADD COLUMN " + MediaContract.HostsColumns.KODI_VERSION_MINOR +
|
||||
" INTEGER DEFAULT " + String.valueOf(HostInfo.DEFAULT_KODI_VERSION_MINOR) + ";");
|
||||
db.execSQL("ALTER TABLE " + Tables.HOSTS +
|
||||
" ADD COLUMN " + MediaContract.HostsColumns.KODI_VERSION_REVISION +
|
||||
" TEXT DEFAULT " + HostInfo.DEFAULT_KODI_VERSION_REVISION + ";");
|
||||
db.execSQL("ALTER TABLE " + Tables.HOSTS +
|
||||
" ADD COLUMN " + MediaContract.HostsColumns.KODI_VERSION_TAG +
|
||||
" TEXT DEFAULT " + HostInfo.DEFAULT_KODI_VERSION_TAG + ";");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -144,6 +144,9 @@ public class RemoteActivity extends BaseActivity
|
|||
|
||||
setupActionBar();
|
||||
|
||||
// Periodic Check of Kodi version
|
||||
hostManager.checkAndUpdateKodiVersion(hostManager.getHostInfo());
|
||||
|
||||
// If we should start playing something
|
||||
|
||||
// // Setup system bars and content padding
|
||||
|
|
|
@ -39,7 +39,9 @@ import org.xbmc.kore.host.HostInfo;
|
|||
import org.xbmc.kore.jsonrpc.ApiCallback;
|
||||
import org.xbmc.kore.jsonrpc.ApiException;
|
||||
import org.xbmc.kore.jsonrpc.HostConnection;
|
||||
import org.xbmc.kore.jsonrpc.method.Application;
|
||||
import org.xbmc.kore.jsonrpc.method.JSONRPC;
|
||||
import org.xbmc.kore.jsonrpc.type.ApplicationType;
|
||||
import org.xbmc.kore.utils.LogUtils;
|
||||
import org.xbmc.kore.utils.NetUtils;
|
||||
|
||||
|
@ -375,19 +377,46 @@ public class HostFragmentManualConfiguration extends Fragment {
|
|||
|
||||
LogUtils.LOGD(TAG, "Check ES connection: " + success);
|
||||
if (success) {
|
||||
hostConnectionChecked(hostInfo);
|
||||
chainCallCheckKodiVersion(hostInfo);
|
||||
} else {
|
||||
hostInfo.setUseEventServer(false);
|
||||
hostConnectionChecked(hostInfo);
|
||||
chainCallCheckKodiVersion(hostInfo);
|
||||
}
|
||||
}
|
||||
},
|
||||
handler);
|
||||
} else {
|
||||
hostConnectionChecked(hostInfo);
|
||||
chainCallCheckKodiVersion(hostInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private void chainCallCheckKodiVersion(final HostInfo hostInfo) {
|
||||
final HostConnection hostConnection = new HostConnection(hostInfo);
|
||||
hostConnection.setProtocol(HostConnection.PROTOCOL_HTTP);
|
||||
|
||||
final Application.GetProperties getProperties = new Application.GetProperties(Application.GetProperties.VERSION);
|
||||
getProperties.execute(hostConnection, new ApiCallback<ApplicationType.PropertyValue>() {
|
||||
@Override
|
||||
public void onSuccess(ApplicationType.PropertyValue result) {
|
||||
LogUtils.LOGD(TAG, "Successfully checked Kodi version.");
|
||||
hostInfo.setKodiVersionMajor(result.version.major);
|
||||
hostInfo.setKodiVersionMinor(result.version.minor);
|
||||
hostInfo.setKodiVersionRevision(result.version.revision);
|
||||
hostInfo.setKodiVersionTag(result.version.tag);
|
||||
|
||||
hostConnection.disconnect();
|
||||
hostConnectionChecked(hostInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int errorCode, String description) {
|
||||
// Couldn't get Kodi version... Odd, but let's proceed anyway with the defaults
|
||||
hostConnection.disconnect();
|
||||
hostConnectionChecked(hostInfo);
|
||||
}
|
||||
}, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* The connection was checked, and hostInfo has all the correct parameters to communicate
|
||||
* with it
|
||||
|
|
|
@ -60,7 +60,9 @@ public class Database {
|
|||
|
||||
private static HostInfo addHost(Context context) {
|
||||
return HostManager.getInstance(context).addHost("TestHost", "127.0.0.1", 1, 80, 9090, null,
|
||||
null, "52:54:00:12:35:02", 9, false, 9777);
|
||||
null, "52:54:00:12:35:02", 9, false, 9777,
|
||||
HostInfo.DEFAULT_KODI_VERSION_MAJOR, HostInfo.DEFAULT_KODI_VERSION_MINOR,
|
||||
HostInfo.DEFAULT_KODI_VERSION_REVISION, HostInfo.DEFAULT_KODI_VERSION_TAG);
|
||||
}
|
||||
|
||||
public static void insertMovies(Context context, ContentResolver contentResolver, int hostId)
|
||||
|
|
Loading…
Reference in New Issue