In the unlikely case someone finds himself in the same situation, here my final solution so far, a python script to run as root with ‘sailcron’. It seems to protect me from unnoticed offline times.
Thank you all for the help.
#!/usr/bin/python3
# Robomike's workaround to STAY mostly connected in Germany.
# My Sailfish-devices have massive problems in weak, messy
# mobile cells. Maybe the problem is also related to my provider
# (O2) or whatever, anyway, when in an area with multiple cells with
# similar bad signal strength, something goes wrong and the phone is
# not only offline, but also does no attempt to regain a network anymore.
# This python script checks the situation and restarts ofono, if necessary.
# It should be run as root by cron or similar mechanics repeatedly.
# (Setting up event loops are possible, but I'm not sure if
# battery friendly...)
# References:
# https://forum.sailfishos.org/t/where-is-run-state-providers-ofono-cellular-gone-in-koli/4920
# (thanks to the contributors in this thread)
#
# First discussions on this topic:
# https://together.jolla.com/question/128155/bug-mobile-data-connection-dies-since-201x/
# https://together.jolla.com/question/170394/xperia-x-loss-of-mobile-network/
#
import os
import dbus
bus = dbus.SystemBus() # define the bus
busObject = bus.get_object('org.ofono','/ril_0') # define the bus-object
def isCallActive():
# Test if call is active.
callsInterface = dbus.Interface(busObject,dbus_interface='org.ofono.VoiceCallManager')
calls = callsInterface.GetCalls()
return (len(calls) > 0)
def isNetworkActive():
# Test if NetworkRegistration says 'registered' or 'roaming'
# According to https://git.sailfishos.org/mer-core/ofono/blob/master/ofono/doc/network-api.txt we'll find
# "unregistered" Not registered to any network
# "registered" Registered to home network
# "searching" Not registered, but searching
# "denied" Registration has been denied
# "unknown" Status is unknown
# "roaming" Registered, but roaming
netRegIface = dbus.Interface(busObject,dbus_interface='org.ofono.NetworkRegistration')
netRegInfos = netRegIface.GetProperties()
return ((netRegInfos['Status'] == 'registered') or (netRegInfos['Status'] == 'roaming'))
def isDataPossible():
# In many cases ofono seems just blocked. We can see a 'registered' state then,
# but we are not able to make calls, recieve messages etc.
# Then, the sailfish status bar shows a signal strength indicator, but no
# '2G/3G/4G' quality at all. AFAIK the only way to find out is asking the
# 'ConnectionManager', if it is 'attached'.
dataConnIface = dbus.Interface(busObject,dbus_interface='org.ofono.ConnectionManager')
dataConnInfos = dataConnIface.GetProperties()
return (dataConnInfos['Attached'] == True)
def phoneIsOffline():
problem = False
if isCallActive():
# If a call is active, we shouldn't even try to disrupt.
pass
else:
if isNetworkActive():
# This is not a guarantee that all is working!
pass # means problem remains 'False'
else:
# But here's a known problem.
problem = True
if isDataPossible():
#Okay, seems running well. Do not disturb.
pass
else:
problem = True # Here's the annoying situation I try to work around
return (problem)
if phoneIsOffline():
# Thing here is, I tried several things to make
# ofono run properly again, but found no way to
# do it without restarting it.
# For some reasons restarting ofono in Sailfish 4.x is faster
# than in older versions. Normally we'll have immediate success.
# Ok then, finally:
print ('checkOfono.py is restarting ofono service NOW')
os.system("systemctl restart ofono")