Skip to content

Commit

Permalink
Merge branch 'release/3.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Jamet committed Sep 24, 2021
2 parents b4f2a1e + d7da1ce commit 7750843
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
KeePassDX(3.0.2)
* Samsung DeX mode #1114 #245 (Thx @chenxiaolong)

KeePassDX(3.0.1)
* Fix text size and smallest margin #1085
* Fix number of lines during an edition #1073
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "com.kunzisoft.keepass"
minSdkVersion 15
targetSdkVersion 30
versionCode = 88
versionName = "3.0.1"
versionCode = 89
versionName = "3.0.2"
multiDexEnabled true

testApplicationId = "com.kunzisoft.keepass.tests"
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@
android:name="com.kunzisoft.keepass.services.KeyboardEntryNotificationService"
android:enabled="true"
android:exported="false" />
<receiver
android:name="com.kunzisoft.keepass.receivers.DexModeReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.app.action.ENTER_KNOX_DESKTOP_MODE" />
<action android:name="android.app.action.EXIT_KNOX_DESKTOP_MODE" />
</intent-filter>
</receiver>

<meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ class FileDatabaseSelectActivity : DatabaseModeActivity(),
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// Enabling/disabling MagikeyboardService is normally done by DexModeReceiver, but this
// additional check will allow the keyboard to be reenabled more easily if the app crashes
// or is force quit within DeX mode and then the user leaves DeX mode. Without this, the
// user would need to enter and exit DeX mode once to reenable the service.
MagikeyboardUtil.setEnabled(this, !DexUtil.isDexMode(resources.configuration))

mFileDatabaseHistoryAction = FileDatabaseHistoryAction.getInstance(applicationContext)

setContentView(R.layout.activity_file_selection)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.kunzisoft.keepass.receivers

import android.content.BroadcastReceiver
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.util.Log
import com.kunzisoft.keepass.magikeyboard.MagikeyboardService
import com.kunzisoft.keepass.utils.DexUtil
import com.kunzisoft.keepass.utils.MagikeyboardUtil

class DexModeReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val enabled = when (intent?.action) {
"android.app.action.ENTER_KNOX_DESKTOP_MODE" -> {
Log.i(TAG, "Entered DeX mode")
false
}
"android.app.action.EXIT_KNOX_DESKTOP_MODE" -> {
Log.i(TAG, "Left DeX mode")
true
}
else -> return
}

MagikeyboardUtil.setEnabled(context!!, enabled)
}

companion object {
private val TAG = DexModeReceiver::class.java.name
}
}
27 changes: 27 additions & 0 deletions app/src/main/java/com/kunzisoft/keepass/utils/DexUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.kunzisoft.keepass.utils

import android.content.res.Configuration
import android.util.Log

object DexUtil {
private val TAG = DexUtil::class.java.name

// Determine if the current environment is in DeX mode. Always returns false on non-Samsung
// devices.
fun isDexMode(config: Configuration): Boolean {
// This is the documented way to check this: https://developer.samsung.com/samsung-dex/modify-optimizing.html
return try {
val configClass = config.javaClass
val enabledConstant = configClass.getField("SEM_DESKTOP_MODE_ENABLED").getInt(configClass)
val enabledField = configClass.getField("semDesktopModeEnabled").getInt(config)
val isEnabled = enabledConstant == enabledField

Log.d(TAG, "DeX currently enabled: $isEnabled")

isEnabled
} catch (e: Exception) {
Log.d(TAG, "Failed to check for DeX mode; likely not Samsung device: $e")
false
}
}
}
27 changes: 27 additions & 0 deletions app/src/main/java/com/kunzisoft/keepass/utils/MagikeyboardUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.kunzisoft.keepass.utils

import android.content.ComponentName
import android.content.Context
import android.content.pm.PackageManager
import android.util.Log
import com.kunzisoft.keepass.magikeyboard.MagikeyboardService

object MagikeyboardUtil {
private val TAG = MagikeyboardUtil::class.java.name

// Set whether MagikeyboardService is enabled. This change is persistent and survives app
// crashes and device restarts. The state is changed immediately and does not require an app
// restart.
fun setEnabled(context: Context, enabled: Boolean) {
val componentState = if (enabled) {
PackageManager.COMPONENT_ENABLED_STATE_ENABLED
} else {
PackageManager.COMPONENT_ENABLED_STATE_DISABLED
}

Log.d(TAG, "Setting service state: $enabled")

val component = ComponentName(context, MagikeyboardService::class.java)
context.packageManager.setComponentEnabledSetting(component, componentState, PackageManager.DONT_KILL_APP)
}
}
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/89.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Samsung DeX mode #1114 #245 (Thx @chenxiaolong)
1 change: 1 addition & 0 deletions fastlane/metadata/android/fr-FR/changelogs/89.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Mode Samsung DeX #1114 #245 (Thx @chenxiaolong)

0 comments on commit 7750843

Please sign in to comment.