Commit 4617f56b authored by Anton Danilov's avatar Anton Danilov Committed by Anton Danilov

#367 Added game attribute - hw serial number

parent af4aa7c7
......@@ -4,6 +4,7 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Bundle;
import com.badlogic.gdx.Gdx;
......@@ -44,7 +45,8 @@ public class AndroidLauncher extends AndroidApplication {
new AndroidConnectionManager(getContext()),
getResources().getString(R.string.sentry_dsn),
HAS_SOFT_BACK_BUTTON,
savedInstanceState == null), config);
savedInstanceState == null,
Build.SERIAL), config);
if (TablexiaSettings.getInstance().getBuildType().isBugReport() && TablexiaBuildConfig.FLURRY_KEY != null) {
FlurryAgent.setLogEnabled(false);
......
external @ fa23a0ee
Subproject commit d8cb4a89e64ceec83718fc478f76a5eb31d8fb3e
Subproject commit fa23a0ee74fa26368e645da6d9ab17115a95717d
......@@ -97,12 +97,12 @@ public class Tablexia extends TablexiaApplication {
}
}
public Tablexia(String buildType, Locale systemLocale, SQLConnectionType sqlConnectionType, IConnectionManager connManager, String sentryDSN, boolean hasSoftBackButton, boolean reset) {
public Tablexia(String buildType, Locale systemLocale, SQLConnectionType sqlConnectionType, IConnectionManager connManager, String sentryDSN, boolean hasSoftBackButton, boolean reset, String hwSerial) {
this.reset = reset;
connectionManager = validateConnectionManager(connManager);
this.sqlConnectionType = sqlConnectionType;
TablexiaSettings.init(buildType, systemLocale, hasSoftBackButton);
TablexiaSettings.init(buildType, systemLocale, hasSoftBackButton, hwSerial);
// register error handler for exceptions in event bus handler methods
ApplicationBus.getInstance().addErrorHandler(new IPublicationErrorHandler() {
......
......@@ -57,6 +57,7 @@ public class TablexiaSettings {
private final String VERSION_NAME = TablexiaBuildConfig.VERSION_NAME;
private final BuildType BUILD_TYPE;
private final boolean HAS_SOFT_BACK_BUTTON;
private static String hwSerial;
private Preferences preferences;
private LocaleDefinition systemLocale;
......@@ -164,11 +165,11 @@ public class TablexiaSettings {
return instance;
}
static void init(String buildTypeKey, Locale systemLocale, boolean hasSoftBackButton) {
TablexiaSettings.init(BuildType.getBuildTypeForKey(buildTypeKey), systemLocale, hasSoftBackButton);
static void init(String buildTypeKey, Locale systemLocale, boolean hasSoftBackButton, String hwSerial) {
TablexiaSettings.init(BuildType.getBuildTypeForKey(buildTypeKey), systemLocale, hasSoftBackButton, hwSerial);
}
static void init(BuildType buildType, Locale systemLocale, boolean hasSoftBackButton) {
static void init(BuildType buildType, Locale systemLocale, boolean hasSoftBackButton, String hwSerial) {
if (instance != null) {
String exceptionMessage = "Tablexia settings already initialized!";
Log.err(TablexiaSettings.class, exceptionMessage);
......@@ -176,6 +177,7 @@ public class TablexiaSettings {
}
instance = new TablexiaSettings(buildType, systemLocale, hasSoftBackButton);
TablexiaSettings.hwSerial = hwSerial;
}
void dispose() {
......@@ -214,6 +216,10 @@ public class TablexiaSettings {
return HAS_SOFT_BACK_BUTTON;
}
public String getHwSerial() {
return hwSerial;
}
public boolean isWinterMode() { return winterMode; }
public boolean isShowBoundingBoxes() {
......
......@@ -430,7 +430,7 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
random = TablexiaSettings.GAMES_RANDOM_SEED == null ? new TablexiaRandom() : new TablexiaRandom(TablexiaSettings.GAMES_RANDOM_SEED);
GameDefinition gameDefinition = GameDefinition.getGameDefinitionForClass(AbstractTablexiaGame.this.getClass());
GameDifficulty gameDifficulty = gameDefinition.hasTutorial() && UserDAO.isTutorialForGameDefinition(gameDefinition, getSelectedUser()) ? GameDifficulty.TUTORIAL : getGameDifficulty();
game = GameDAO.createGame(getSelectedUser(), gameDifficulty, gameDefinition, random);
game = GameDAO.createGame(getSelectedUser(), gameDifficulty, gameDefinition, random, TablexiaSettings.getInstance().getHwSerial());
Log.info(getClass(), "[DB] Created new GAME object: " + game);
} else {
Log.info(getClass(), "[DB] Restored last GAME object: " + game);
......
......@@ -33,11 +33,11 @@ public class GameDAO {
//////////////////////////// Game API
public static Game createGame(User user, GameDifficulty difficulty, GameDefinition gameDefinition, TablexiaRandom random) {
public static Game createGame(User user, GameDifficulty difficulty, GameDefinition gameDefinition, TablexiaRandom random, String hwSerial) {
Game game = null;
Long id = insertNewGame(user, difficulty, gameDefinition, random);
Long id = insertNewGame(user, difficulty, gameDefinition, random, hwSerial);
if (id != null) {
game = new Game(id, user, difficulty.getDifficultyNumber(), gameDefinition.getGameNumber(), random.getSeed());
game = new Game(id, user, difficulty.getDifficultyNumber(), gameDefinition.getGameNumber(), random.getSeed(), hwSerial);
game.setGamePauses(GamePauseDAO.selectGamePausesForGame(game));
}
return game;
......@@ -146,36 +146,37 @@ public class GameDAO {
//////////////////////////// DB ACCESS
// prepared statements
public static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS game (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, start_time INTEGER, end_time INTEGER, difficulty_number INTEGER NOT NULL, game_number INTEGER NOT NULL, random_seed INTEGER NOT NULL, sync_at INTEGER, FOREIGN KEY(user_id) REFERENCES user(id))";
public static final String NEW_GAME_INSERT = "INSERT INTO game (user_id, difficulty_number, game_number, random_seed) VALUES (?, ?, ?, ?)";
public static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS game (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, start_time INTEGER, end_time INTEGER, difficulty_number INTEGER NOT NULL, game_number INTEGER NOT NULL, random_seed INTEGER NOT NULL, sync_at INTEGER, hw_serial_number TEXT, FOREIGN KEY(user_id) REFERENCES user(id))";
public static final String NEW_GAME_INSERT = "INSERT INTO game (user_id, difficulty_number, game_number, random_seed, hw_serial_number) VALUES (?, ?, ?, ?, ?)";
public static final String GAME_UPDATE_START = "UPDATE game SET start_time = ? WHERE id = ?";
public static final String GAME_UPDATE_END = "UPDATE game SET end_time = ? WHERE id = ?";
public static final String GAME_UPDATE_SYNC_AT = "UPDATE game SET sync_at = ? WHERE id = ?";
public static final String GAME_SELECT_FOR_ID = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time FROM game WHERE id = ?";
public static final String GAME_SELECT_FOR_ID = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time, hw_serial_number FROM game WHERE id = ?";
public static final String GAME_SELECT_LAST_ID = "SELECT max(id) FROM game";
public static final String GAME_SELECT_COUNT_FOR_GAME_AND_DIFFICULTY = "SELECT count(id) FROM game WHERE game_number = ? AND difficulty_number = ? AND user_id = ? AND end_time IS NOT NULL";
public static final String GAME_SELECT_FOR_USER_AND_DEFINITION = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time FROM game WHERE user_id = ? AND game_number = ? AND end_time IS NOT NULL AND end_time != 0 ORDER BY start_time ASC";
public static final String GAME_SELECT_FOR_USER_AND_DEFINITION = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time, hw_serial_number FROM game WHERE user_id = ? AND game_number = ? AND end_time IS NOT NULL AND end_time != 0 ORDER BY start_time ASC";
public static final String GAME_SELECT_COUNT_FOR_GAME = "SELECT count(id) FROM game WHERE game_number = ? AND user_id = ?";
public static final String GAME_SELECT_ALL_FOR_USER_SYNC = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time FROM game where user_id = ? AND sync_at is null";
public static final String GAME_SELECT_ALL_FOR_USER_SYNC = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time, hw_serial_number FROM game where user_id = ? AND sync_at is null";
public static final String GAME_SELECT_BY_START_AND_END = "SELECT id FROM game WHERE user_id = ? AND start_time = ? AND end_time = ?";
public static final String GAME_SELECT_BY_START_AND_NULL_END = "SELECT id FROM game WHERE user_id = ? AND start_time = ? AND end_time IS NULL";
public static final String GAME_SELECT_LAST_SCORES_FOR_USER_AND_GAME = "SELECT value FROM game_score INNER JOIN game ON game_score.game_id=game.id AND game.user_id=? AND game.game_number=? WHERE game_score.key=? AND end_time IS NOT NULL ORDER BY game_id DESC LIMIT 1";
public static final String GAME_SELECT_FOR_RANK_MANAGER = "SELECT id, difficulty_number, game_number, start_time, end_time FROM game WHERE user_id = ? AND start_time IS NOT NULL AND start_time != 0 AND end_time IS NOT NULL AND end_time != 0 ORDER BY end_time ASC";
public static final String GAME_SELECT_FOR_RANK_MANAGER = "SELECT id, difficulty_number, game_number, start_time, end_time, hw_serial_number FROM game WHERE user_id = ? AND start_time IS NOT NULL AND start_time != 0 AND end_time IS NOT NULL AND end_time != 0 ORDER BY end_time ASC";
// classic statements
public static final String IMPORT_GAME_INSERT = "INSERT INTO game (user_id, difficulty_number, game_number, random_seed, start_time, end_time, sync_at) VALUES (%d, %d, %d, %d, %d, %s, %d)";
public static final String IMPORT_GAME_INSERT = "INSERT INTO game (user_id, difficulty_number, game_number, random_seed, start_time, end_time, sync_at, hw_serial_number) VALUES (%d, %d, %d, %d, %d, %s, %d, %d)";
private static Long insertNewGame(User user, GameDifficulty difficulty, GameDefinition gameDefinition, TablexiaRandom random) {
private static Long insertNewGame(User user, GameDifficulty difficulty, GameDefinition gameDefinition, TablexiaRandom random, String hwSerial) {
try {
PreparedStatement insertStatement = TablexiaStorage.getInstance().prepareStatement(NEW_GAME_INSERT);
insertStatement.setLong(1, user.getId());
insertStatement.setInt(2, difficulty.getDifficultyNumber());
insertStatement.setInt(3, gameDefinition.getGameNumber());
insertStatement.setLong(4, random.getSeed());
insertStatement.setString(5, hwSerial);
insertStatement.executeUpdate();
insertStatement.close();
// insertStatement.getGeneratedKeys().getLong(1) cannot be used -> getGeneratedKeys() is not implemented in SQLDroid
......@@ -267,7 +268,8 @@ public class GameDAO {
resultSet.getInt(4),
resultSet.getLong(5),
startTimeStr != null ? Long.valueOf(startTimeStr) : null,
endTimeStr != null ? Long.valueOf(endTimeStr) : null);
endTimeStr != null ? Long.valueOf(endTimeStr) : null,
resultSet.getString(8));
selectedGame.setGamePauses(GamePauseDAO.selectGamePausesForGame(selectedGame));
selectedGame.getGameScoreMap().addAll(GameScoreDAO.selectGameScores(selectedGame.getId()));
......@@ -299,7 +301,8 @@ public class GameDAO {
resultSet.getInt(4),
resultSet.getLong(5),
startTimeStr != null ? Long.valueOf(startTimeStr) : null,
endTimeStr != null ? Long.valueOf(endTimeStr) : null);
endTimeStr != null ? Long.valueOf(endTimeStr) : null,
resultSet.getString(8));
game.setGamePauses(GamePauseDAO.selectGamePausesForGame(game));
game.getGameScoreMap().addAll(GameScoreDAO.selectGameScores(game.getId()));
......@@ -330,6 +333,7 @@ public class GameDAO {
int gameNum = resultSet.getInt(3);
String startTime = resultSet.getString(4);
String endTime = resultSet.getString(5);
String hwSerial = resultSet.getString(6);
Long startTimeLong = startTime != null ? Long.valueOf(startTime) : null;
Long endTimeLong = endTime != null ? Long.valueOf(endTime) : null;
......@@ -343,7 +347,8 @@ public class GameDAO {
gameNum,
0L,
startTimeLong,
endTimeLong
endTimeLong,
hwSerial
);
game.setGamePauses(GamePauseDAO.selectGamePausesForGame(game));
......@@ -386,7 +391,8 @@ public class GameDAO {
resultSet.getInt(4),
resultSet.getLong(5),
startTimeStr != null ? Long.valueOf(startTimeStr) : null,
endTimeStr != null ? Long.valueOf(endTimeStr) : null);
endTimeStr != null ? Long.valueOf(endTimeStr) : null,
resultSet.getString(8));
game.setGamePauses(GamePauseDAO.selectGamePausesForGame(game));
game.getGameScoreMap().addAll(GameScoreDAO.selectGameScores(game.getId()));
......
......@@ -55,7 +55,7 @@ public class GameTrophy {
public static class ThreeStarsReceived implements GameTrophyResolver {
public static final String GAME_SELECT_FOR_GAME_AND_DIFFICULTY = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time FROM game WHERE game_number = ? AND difficulty_number = ? AND user_id = ? AND end_time IS NOT NULL";
public static final String GAME_SELECT_FOR_GAME_AND_DIFFICULTY = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time, hw_serial_number FROM game WHERE game_number = ? AND difficulty_number = ? AND user_id = ? AND end_time IS NOT NULL";
private static List<Game> getGamesForGameAndDifficulty(User user, GameTrophyDefinition trophyDef) {
List<Game> games = new ArrayList<Game>();
......@@ -75,7 +75,8 @@ public class GameTrophy {
resultSet.getInt(4),
resultSet.getLong(5),
startTimeStr != null ? Long.valueOf(startTimeStr) : null,
endTimeStr != null ? Long.valueOf(endTimeStr) : null);
endTimeStr != null ? Long.valueOf(endTimeStr) : null,
resultSet.getString(8));
game.setGamePauses(GamePauseDAO.selectGamePausesForGame(game));
game.getGameScoreMap().addAll(GameScoreDAO.selectGameScores(game.getId()));
games.add(game);
......
......@@ -155,8 +155,8 @@ public class UserTrophy {
public static class AllStarsGame implements UserTrophyResolver {
public static final String GAME_SELECT_FOR_USER_AND_DIFFICULTY = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time FROM game WHERE difficulty_number = ? AND user_id = ? AND end_time IS NOT NULL";
public static final String GAME_SELECT_FOR_USER = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time FROM game WHERE user_id = ? AND difficulty_number != ? AND start_time IS NOT NULL AND start_time != 0 AND end_time IS NOT NULL AND end_time != 0";
public static final String GAME_SELECT_FOR_USER_AND_DIFFICULTY = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time, hw_serial_number FROM game WHERE difficulty_number = ? AND user_id = ? AND end_time IS NOT NULL";
public static final String GAME_SELECT_FOR_USER = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time, hw_serial_number FROM game WHERE user_id = ? AND difficulty_number != ? AND start_time IS NOT NULL AND start_time != 0 AND end_time IS NOT NULL AND end_time != 0";
private static List<Game> getGamesForUserAndDifficulty(User user, UserTrophyDefinition trophyDef) throws SQLException {
PreparedStatement statement = TablexiaStorage.getInstance().prepareStatement(GAME_SELECT_FOR_USER_AND_DIFFICULTY);
......@@ -188,7 +188,8 @@ public class UserTrophy {
resultSet.getInt(4),
resultSet.getLong(5),
startTimeStr != null ? Long.valueOf(startTimeStr) : null,
endTimeStr != null ? Long.valueOf(endTimeStr) : null);
endTimeStr != null ? Long.valueOf(endTimeStr) : null,
resultSet.getString(8));
game.setGamePauses(GamePauseDAO.selectGamePausesForGame(game));
game.getGameScoreMap().addAll(GameScoreDAO.selectGameScores(game.getId()));
......
......@@ -57,7 +57,7 @@ public class DesktopLauncher {
config.addIcon(DESKTOP_ICON_128, Files.FileType.Internal);
}
new LwjglApplication(new Tablexia(buildType, Locale.getDefault(), SQL_CONNECTION_TYPE, new DesktopConnectionManager(), sentryDSN, HAS_SOFT_BACK_BUTTON, true), config);
new LwjglApplication(new Tablexia(buildType, Locale.getDefault(), SQL_CONNECTION_TYPE, new DesktopConnectionManager(), sentryDSN, HAS_SOFT_BACK_BUTTON, true, null), config);
}
private static String loadAttributeFromManifest(String attributeName, String defaultValue) {
......
......@@ -54,7 +54,8 @@ public class IOSLauncher extends IOSApplication.Delegate {
new IOSConnectionManager(),
sentryDSN,
HAS_SOFT_BACK_BUTTON,
false), config) {
false,
null), config) {
@Override
public Files getFiles() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment