Skip to content

Commit

Permalink
Automatically set VNC dimensions to device dimensions (#657)
Browse files Browse the repository at this point in the history
* Add DeviceDimensionsUtility to save and get device dimensions

* When starting VNC session, save device dimensions and set the session's `geometry` property

* Pass the session's `geometry` as an environment variable

* Add `geometry` field to Session to hold screen dimensions.  Useful when starting VNC sessions

* Lint

* Fix unit tests

* Rename saveDeviceDImensions to getDeviceDimensions and add unit test

* Add missing import
  • Loading branch information
luongthomas authored and MatthewTighe committed Feb 27, 2019
1 parent 0a03599 commit 451d646
Show file tree
Hide file tree
Showing 9 changed files with 377 additions and 11 deletions.
259 changes: 259 additions & 0 deletions app/schemas/tech.ula.model.repositories.UlaDatabase/5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
{
"formatVersion": 1,
"database": {
"version": 5,
"identityHash": "e0ab57d3b8ac504ff016fa68d9ee5478",
"entities": [
{
"tableName": "session",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `filesystemId` INTEGER NOT NULL, `filesystemName` TEXT NOT NULL, `active` INTEGER NOT NULL, `username` TEXT NOT NULL, `password` TEXT NOT NULL, `vncPassword` TEXT NOT NULL, `serviceType` TEXT NOT NULL, `port` INTEGER NOT NULL, `pid` INTEGER NOT NULL, `geometry` TEXT NOT NULL, `isAppsSession` INTEGER NOT NULL, FOREIGN KEY(`filesystemId`) REFERENCES `filesystem`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "filesystemId",
"columnName": "filesystemId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "filesystemName",
"columnName": "filesystemName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "active",
"columnName": "active",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "username",
"columnName": "username",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "password",
"columnName": "password",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "vncPassword",
"columnName": "vncPassword",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "serviceType",
"columnName": "serviceType",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "port",
"columnName": "port",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "pid",
"columnName": "pid",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "geometry",
"columnName": "geometry",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isAppsSession",
"columnName": "isAppsSession",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [
{
"name": "index_session_filesystemId",
"unique": false,
"columnNames": [
"filesystemId"
],
"createSql": "CREATE INDEX `index_session_filesystemId` ON `${TABLE_NAME}` (`filesystemId`)"
}
],
"foreignKeys": [
{
"table": "filesystem",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"filesystemId"
],
"referencedColumns": [
"id"
]
}
]
},
{
"tableName": "filesystem",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `distributionType` TEXT NOT NULL, `archType` TEXT NOT NULL, `defaultUsername` TEXT NOT NULL, `defaultPassword` TEXT NOT NULL, `defaultVncPassword` TEXT NOT NULL, `isAppsFilesystem` INTEGER NOT NULL, `lastUpdated` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "distributionType",
"columnName": "distributionType",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "archType",
"columnName": "archType",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "defaultUsername",
"columnName": "defaultUsername",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "defaultPassword",
"columnName": "defaultPassword",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "defaultVncPassword",
"columnName": "defaultVncPassword",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isAppsFilesystem",
"columnName": "isAppsFilesystem",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastUpdated",
"columnName": "lastUpdated",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "apps",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `category` TEXT NOT NULL, `filesystemRequired` TEXT NOT NULL, `supportsCli` INTEGER NOT NULL, `supportsGui` INTEGER NOT NULL, `isPaidApp` INTEGER NOT NULL, `version` INTEGER NOT NULL, PRIMARY KEY(`name`))",
"fields": [
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "category",
"columnName": "category",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "filesystemRequired",
"columnName": "filesystemRequired",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "supportsCli",
"columnName": "supportsCli",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "supportsGui",
"columnName": "supportsGui",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isPaidApp",
"columnName": "isPaidApp",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "version",
"columnName": "version",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"name"
],
"autoGenerate": false
},
"indices": [
{
"name": "index_apps_name",
"unique": true,
"columnNames": [
"name"
],
"createSql": "CREATE UNIQUE INDEX `index_apps_name` ON `${TABLE_NAME}` (`name`)"
}
],
"foreignKeys": []
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"e0ab57d3b8ac504ff016fa68d9ee5478\")"
]
}
}
13 changes: 11 additions & 2 deletions app/src/androidTest/java/tech/ula/model/MigrationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import tech.ula.model.entities.Session
import tech.ula.model.repositories.Migration1To2
import tech.ula.model.repositories.Migration2To3
import tech.ula.model.repositories.Migration3To4
import tech.ula.model.repositories.Migration4To5
import tech.ula.model.repositories.UlaDatabase
import java.io.IOException

Expand All @@ -42,7 +43,7 @@ class MigrationTest {

db.close()

helper.runMigrationsAndValidate(TEST_DB, 2, true, Migration1To2(), Migration2To3(), Migration3To4())
helper.runMigrationsAndValidate(TEST_DB, 2, true, Migration1To2(), Migration2To3(), Migration3To4(), Migration4To5())
}

@Test
Expand Down Expand Up @@ -98,10 +99,18 @@ class MigrationTest {
helper.runMigrationsAndValidate(TEST_DB, 4, true, Migration3To4())
}

@Test
@Throws(IOException::class)
fun migrate4To5() {
helper.createDatabase(TEST_DB, 4)

helper.runMigrationsAndValidate(TEST_DB, 5, true, Migration4To5())
}

private fun getMigratedDatabase(): UlaDatabase {
val db = Room.databaseBuilder(InstrumentationRegistry.getTargetContext(),
UlaDatabase::class.java, TEST_DB)
.addMigrations(Migration1To2(), Migration2To3(), Migration3To4())
.addMigrations(Migration1To2(), Migration2To3(), Migration3To4(), Migration4To5())
.build()

helper.closeWhenFinished(db)
Expand Down
27 changes: 21 additions & 6 deletions app/src/main/java/tech/ula/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import android.os.Environment
import android.support.design.widget.TextInputEditText
import android.support.v4.content.LocalBroadcastManager
import android.support.v7.app.AppCompatActivity
import android.util.DisplayMetrics
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.view.animation.AlphaAnimation
import android.widget.Button
import android.widget.RadioButton
Expand Down Expand Up @@ -316,13 +318,26 @@ class MainActivity : AppCompatActivity(), SessionListFragment.SessionSelection,
// TODO: Alert user when defaulting to VNC
if (session.serviceType == "xsdl" && Build.VERSION.SDK_INT > Build.VERSION_CODES.O_MR1) {
session.serviceType = "vnc"
startSession(session)
} else if (session.serviceType == "xsdl") {
viewModel.lastSelectedSession = session
sendXsdlIntentToSetDisplayNumberAndExpectResult()
} else {
startSession(session)
}

when (session.serviceType) {
"xsdl" -> {
viewModel.lastSelectedSession = session
sendXsdlIntentToSetDisplayNumberAndExpectResult()
}
"vnc" -> {
getDeviceDimensions(session)
startSession(session)
}
else -> startSession(session)
}
}

private fun getDeviceDimensions(session: Session) {
val deviceDimensions = DeviceDimensions()
val windowManager = applicationContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager
deviceDimensions.getDeviceDimensions(windowManager, DisplayMetrics())
session.geometry = deviceDimensions.getGeometry()
}

private fun startSession(session: Session) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/tech/ula/model/entities/Session.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ data class Session(
var serviceType: String = "",
var port: Long = 2022,
var pid: Long = 0,
var geometry: String = "",
val isAppsSession: Boolean = false
) : Parcelable {
override fun toString(): String {
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/tech/ula/model/repositories/UlaDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import tech.ula.model.daos.FilesystemDao
import tech.ula.model.daos.SessionDao
import tech.ula.model.entities.App

@Database(entities = [Session::class, Filesystem::class, App::class], version = 4, exportSchema = true)
@Database(entities = [Session::class, Filesystem::class, App::class], version = 5, exportSchema = true)
abstract class UlaDatabase : RoomDatabase() {

abstract fun sessionDao(): SessionDao
Expand All @@ -36,7 +36,7 @@ abstract class UlaDatabase : RoomDatabase() {
private fun buildDatabase(context: Context): UlaDatabase =
Room.databaseBuilder(context.applicationContext,
UlaDatabase::class.java, "Data.db")
.addMigrations(Migration1To2(), Migration2To3(), Migration3To4())
.addMigrations(Migration1To2(), Migration2To3(), Migration3To4(), Migration4To5())
.addCallback(object : RoomDatabase.Callback() {
override fun onOpen(db: SupportSQLiteDatabase) {
super.onOpen(db)
Expand Down Expand Up @@ -110,4 +110,10 @@ class Migration3To4 : Migration(3, 4) {
database.execSQL("COMMIT;")
database.execSQL("PRAGMA foreign_keys_on")
}
}

class Migration4To5 : Migration(4, 5) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE session ADD COLUMN geometry TEXT NOT NULL DEFAULT ''")
}
}
Loading

0 comments on commit 451d646

Please sign in to comment.