Skip to content

Commit

Permalink
Remove EventListener for Android 14 on Play Store
Browse files Browse the repository at this point in the history
According to Google the permission `FOREGROUND_SERVICE_DATA_SYNC` may not be requested
by openHAB. The ItemUpdateWorker can use the foreground type `shortService` instead, but
I haven't found a good replacement for `EventListenerService`, so it
needs to be removed for Android 14 on Play Store builds.

Signed-off-by: mueller-ma <[email protected]>
  • Loading branch information
mueller-ma committed Jan 27, 2025
1 parent 31ec680 commit 3b96e16
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
13 changes: 13 additions & 0 deletions mobile/src/foss/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Not allowed on Play Store -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<application>
<service
android:name=".background.EventListenerService"
android:foregroundServiceType="dataSync"
android:enabled="true"
android:exported="false" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2010-2025 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.openhab.habdroid.util

fun isDataSyncForegroundServiceAllowed() = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2010-2025 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.openhab.habdroid.util

import android.os.Build

fun isDataSyncForegroundServiceAllowed() = Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE
4 changes: 1 addition & 3 deletions mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

Expand Down Expand Up @@ -307,7 +306,6 @@

<service
android:name=".background.EventListenerService"
android:foregroundServiceType="dataSync"
android:enabled="true"
android:exported="false" />

Expand All @@ -316,7 +314,7 @@
android:directBootAware="false"
android:enabled="@bool/enable_system_foreground_service_default"
android:exported="false"
android:foregroundServiceType="dataSync"
android:foregroundServiceType="shortService"
tools:targetApi="n"
tools:ignore="Instantiatable" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.openhab.habdroid.ui.preference.widgets.ItemUpdatingPreference
import org.openhab.habdroid.util.PrefKeys
import org.openhab.habdroid.util.getPreference
import org.openhab.habdroid.util.getPrefixForBgTasks
import org.openhab.habdroid.util.isDataSyncForegroundServiceAllowed
import org.openhab.habdroid.util.isInstalled

class SendDeviceInfoSettingsFragment :
Expand Down Expand Up @@ -72,6 +73,10 @@ class SendDeviceInfoSettingsFragment :
foregroundServicePref.setSummary(R.string.send_device_info_foreground_service_summary_pre_o)
}

if (!isDataSyncForegroundServiceAllowed()) {
preferenceScreen.removePreferenceRecursively(PrefKeys.SEND_DEVICE_INFO_FOREGROUND_SERVICE)
}

foregroundServicePref.setOnPreferenceChangeListener { preference, newValue ->
EventListenerService.startOrStopService(preference.context, newValue as Boolean)
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ fun SharedPreferences.getScreenLockMode(context: Context): ScreenLockMode {
fun SharedPreferences.isItemUpdatePrefEnabled(key: String) = getString(key, null).toItemUpdatePrefValue().first

fun SharedPreferences.isEventListenerEnabled() = getBoolean(PrefKeys.SEND_DEVICE_INFO_FOREGROUND_SERVICE, false)
&& isDataSyncForegroundServiceAllowed()

enum class DeviceControlSubtitleMode {
LOCATION,
Expand Down

0 comments on commit 3b96e16

Please sign in to comment.