summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2022-01-27 08:50:37 +0100
committerAlbin <albin@mullvad.net>2022-01-27 11:29:07 +0100
commit12d04a384cda1ab21617ad164fa5291506073f4c (patch)
treeaa5483f03f724c736ed907bf1ea769cdbea52ff3 /android
parentc81d787c9588800688930c88d0a69fa3ee6a06e9 (diff)
downloadmullvadvpn-12d04a384cda1ab21617ad164fa5291506073f4c.tar.xz
mullvadvpn-12d04a384cda1ab21617ad164fa5291506073f4c.zip
Fix app startup crash on Android TVs
The main activity and tv activity are both designed to be running as singleTask and the app would crash if both were started. This would not be common, but possible, on a phone or tablet, however this can potentially occur frequently on Android TV (perhaps depending on OEM), as both categories LAUNCHER and LEANBACK_LAUNCHER are used. E.g.the tv launcher would use LEANBACK_LAUNCHER whereas the settings app would use LAUNCHER. As the tv activity isn't used for any customization atm, this was fixed by simply removing the tv activity and adding the LEANBACK_LAUNCHER category to the main activity.
Diffstat (limited to 'android')
-rw-r--r--android/app/src/main/AndroidManifest.xml14
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/VpnPermission.kt17
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt6
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/activities/TVActivity.kt5
4 files changed, 7 insertions, 35 deletions
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 5216de46d2..2cb2809891 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -28,27 +28,17 @@
android:label="@string/app_name"
android:launchMode="singleTask"
android:configChanges="orientation|screenSize|screenLayout"
- android:screenOrientation="sensorPortrait"
+ android:screenOrientation="locked"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
+ <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
</intent-filter>
</activity>
- <activity android:name="net.mullvad.mullvadvpn.ui.activities.TVActivity"
- android:label="@string/app_name"
- android:launchMode="singleTask"
- android:configChanges="orientation|screenSize|screenLayout"
- android:screenOrientation="sensor"
- android:windowSoftInputMode="adjustPan">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
- </intent-filter>
- </activity>
<service android:name="net.mullvad.mullvadvpn.service.MullvadVpnService"
android:permission="android.permission.BIND_VPN_SERVICE"
android:process=":mullvadvpn_daemon"
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/VpnPermission.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/VpnPermission.kt
index 9602ec7a3b..b92dab3f98 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/VpnPermission.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/VpnPermission.kt
@@ -1,19 +1,14 @@
package net.mullvad.mullvadvpn.service.endpoint
-import android.app.UiModeManager
import android.content.Context
-import android.content.Context.UI_MODE_SERVICE
import android.content.Intent
-import android.content.res.Configuration.UI_MODE_TYPE_TELEVISION
import android.net.VpnService
import net.mullvad.mullvadvpn.ipc.Event
import net.mullvad.mullvadvpn.ipc.Request
import net.mullvad.mullvadvpn.ui.MainActivity
-import net.mullvad.mullvadvpn.ui.activities.TVActivity
import net.mullvad.mullvadvpn.util.Intermittent
class VpnPermission(private val context: Context, private val endpoint: ServiceEndpoint) {
- private val activityClass = discoverActivityClass()
private val isGranted = Intermittent<Boolean>()
var waitingForResponse = false
@@ -32,7 +27,7 @@ class VpnPermission(private val context: Context, private val endpoint: ServiceE
if (intent == null) {
isGranted.update(true)
} else {
- val activityIntent = Intent(context, activityClass).apply {
+ val activityIntent = Intent(context, MainActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
}
@@ -46,14 +41,4 @@ class VpnPermission(private val context: Context, private val endpoint: ServiceE
return isGranted.await()
}
-
- private fun discoverActivityClass(): Class<out MainActivity> {
- val uiModeManager = context.getSystemService(UI_MODE_SERVICE) as UiModeManager
-
- return if (uiModeManager.currentModeType == UI_MODE_TYPE_TELEVISION) {
- TVActivity::class.java
- } else {
- MainActivity::class.java
- }
- }
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt
index dfc541d8d5..bda1055c76 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt
@@ -64,8 +64,10 @@ open class MainActivity : FragmentActivity() {
var backButtonHandler: (() -> Boolean)? = null
override fun onCreate(savedInstanceState: Bundle?) {
- if (deviceIsTv) {
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
+ requestedOrientation = if (deviceIsTv) {
+ ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
+ } else {
+ ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}
super.onCreate(savedInstanceState)
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/activities/TVActivity.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/activities/TVActivity.kt
deleted file mode 100644
index c83c47e7cd..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/activities/TVActivity.kt
+++ /dev/null
@@ -1,5 +0,0 @@
-package net.mullvad.mullvadvpn.ui.activities
-
-import net.mullvad.mullvadvpn.ui.MainActivity
-
-class TVActivity : MainActivity()