diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index 758b7e9b5..1b0763a46 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -72,7 +72,6 @@ import nodomain.freeyourgadget.gadgetbridge.entities.DaoMaster; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.Device; import nodomain.freeyourgadget.gadgetbridge.externalevents.BluetoothStateChangeReceiver; -import nodomain.freeyourgadget.gadgetbridge.externalevents.TimeChangeReceiver; import nodomain.freeyourgadget.gadgetbridge.externalevents.opentracks.OpenTracksContentObserver; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceService; @@ -128,8 +127,7 @@ public class GBApplication extends Application { private static final int CURRENT_PREFS_VERSION = 30; private static final LimitedQueue mIDSenderLookup = new LimitedQueue<>(16); - private static Prefs prefs; - private static GBPrefs gbPrefs; + private static GBPrefs prefs; private static LockHandler lockHandler; /** * Note: is null on Lollipop @@ -144,7 +142,7 @@ public class GBApplication extends Application { private static GBApplication app; - private static Logging logging = new Logging() { + private static final Logging logging = new Logging() { @Override protected String createLogDirectory() throws IOException { if (GBEnvironment.env().isLocalTest()) { @@ -212,8 +210,7 @@ public class GBApplication extends Application { AndroidThreeTen.init(this); sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); - prefs = new Prefs(sharedPrefs); - gbPrefs = new GBPrefs(prefs); + prefs = new GBPrefs(sharedPrefs); if (!GBEnvironment.isEnvironmentSetup()) { GBEnvironment.setupEnvironment(GBEnvironment.createDeviceEnvironment()); @@ -1588,14 +1585,10 @@ public class GBApplication extends Application { return typedValue.data; } - public static Prefs getPrefs() { + public static GBPrefs getPrefs() { return prefs; } - public static GBPrefs getGBPrefs() { - return gbPrefs; - } - public DeviceManager getDeviceManager() { return deviceManager; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java index 665eaaab7..54897692e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java @@ -127,7 +127,7 @@ public class ExternalPebbleJSActivity extends AbstractGBActivity { showConfig = extras.getBoolean(SHOW_CONFIG, false); } - if (GBApplication.getGBPrefs().isBackgroundJsEnabled()) { + if (GBApplication.getPrefs().isBackgroundJsEnabled()) { if (showConfig) { Objects.requireNonNull(currentDevice, "Must provide a device when invoking this activity"); Objects.requireNonNull(currentUUID, "Must provide a uuid when invoking this activity"); @@ -144,7 +144,7 @@ public class ExternalPebbleJSActivity extends AbstractGBActivity { } private void startBackgroundWebViewAndFinish() { - if (GBApplication.getGBPrefs().isBackgroundJsEnabled()) { + if (GBApplication.getPrefs().isBackgroundJsEnabled()) { WebViewSingleton.ensureCreated(this); } else { LOG.warn("BGJs disabled, not starting webview"); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/AlarmReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/AlarmReceiver.java index 313b91e32..be6a62b5c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/AlarmReceiver.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/AlarmReceiver.java @@ -82,7 +82,7 @@ public class AlarmReceiver extends BroadcastReceiver { GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_SUNRISE, id_tomorrow); GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_SUNSET, id_tomorrow); - GBPrefs gbPrefs = GBApplication.getGBPrefs(); + GBPrefs gbPrefs = GBApplication.getPrefs(); float[] longlat = gbPrefs.getLongLat(context); float longitude = longlat[0]; float latitude = longlat[1]; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/AutoStartReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/AutoStartReceiver.java index 9acc468c8..5ce081ab7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/AutoStartReceiver.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/AutoStartReceiver.java @@ -31,7 +31,7 @@ public class AutoStartReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - if (GBApplication.getGBPrefs().getAutoStart() && + if (GBApplication.getPrefs().getAutoStart() && (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()) || Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction()) )) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/BluetoothStateChangeReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/BluetoothStateChangeReceiver.java index 8d7627fde..663cafdd2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/BluetoothStateChangeReceiver.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/BluetoothStateChangeReceiver.java @@ -28,22 +28,28 @@ import org.slf4j.LoggerFactory; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager; -import nodomain.freeyourgadget.gadgetbridge.util.Prefs; +import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService; +import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs; public class BluetoothStateChangeReceiver extends BroadcastReceiver { private static final Logger LOG = LoggerFactory.getLogger(BluetoothStateChangeReceiver.class); @Override public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); + final String action = intent.getAction(); if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) { if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_ON) { - - Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST); + final Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST); LocalBroadcastManager.getInstance(context).sendBroadcast(refreshIntent); - Prefs prefs = GBApplication.getPrefs(); + final GBPrefs prefs = GBApplication.getPrefs(); + if (!DeviceCommunicationService.isRunning(context) && !prefs.getAutoStart()) { + // Prevent starting the service if it isn't yet running + LOG.debug("DeviceCommunicationService not running, ignoring bluetooth on"); + return; + } + if (!prefs.getBoolean("general_autoconnectonbluetooth", false)) { return; } @@ -51,6 +57,11 @@ public class BluetoothStateChangeReceiver extends BroadcastReceiver { LOG.info("Bluetooth turned on (ACTION_STATE_CHANGED) => connecting..."); GBApplication.deviceService().connect(); } else if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_OFF) { + if (!DeviceCommunicationService.isRunning(context)) { + // Prevent starting the service if it isn't yet running + LOG.debug("DeviceCommunicationService not running, ignoring bluetooth off"); + return; + } LOG.info("Bluetooth turned off => disconnecting..."); GBApplication.deviceService().disconnect(); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java index 4764b1df4..230733e00 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java @@ -645,19 +645,6 @@ public class NotificationListener extends NotificationListenerService { } } - private boolean isServiceRunning() { - ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); - if (manager == null) { - return false; - } - for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { - if (DeviceCommunicationService.class.getName().equals(service.service.getClassName())) { - return true; - } - } - return false; - } - private boolean handleMediaSessionNotification(final StatusBarNotification sbn) { final MediaSession.Token token = sbn.getNotification().extras.getParcelable(Notification.EXTRA_MEDIA_SESSION); return token != null && handleMediaSessionNotification(token); @@ -816,7 +803,7 @@ public class NotificationListener extends NotificationListenerService { * broadcast receivers because it seems to invalidate the permissions that are * necessary for NotificationListenerService */ - if (!isServiceRunning()) { + if (!DeviceCommunicationService.isRunning(this)) { LOG.trace("Service is not running, ignoring notification"); return true; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java index ecc0500c7..5f219b4fd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java @@ -26,6 +26,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.*; import android.Manifest; import android.annotation.SuppressLint; +import android.app.ActivityManager; import android.app.Service; import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; @@ -366,6 +367,19 @@ public class DeviceCommunicationService extends Service implements SharedPrefere DEVICE_SUPPORT_FACTORY = factory; } + public static boolean isRunning(final Context context) { + final ActivityManager manager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); + if (manager == null) { + return false; + } + for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { + if (DeviceCommunicationService.class.getName().equals(service.service.getClassName())) { + return true; + } + } + return false; + } + public DeviceCommunicationService() { } @@ -515,7 +529,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere if (hasPrefs()) { getPrefs().getPreferences().registerOnSharedPreferenceChangeListener(this); allowBluetoothIntentApi = getPrefs().getBoolean(GBPrefs.PREF_ALLOW_INTENT_API, false); - reconnectViaScan = getGBPrefs().getAutoReconnectByScan(); + reconnectViaScan = getPrefs().getAutoReconnectByScan(); } startForeground(); @@ -536,7 +550,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere if(device.getState() != GBDevice.State.NOT_CONNECTED){ continue; } - boolean shouldAutoConnect = getGBPrefs().getAutoReconnect(device); + boolean shouldAutoConnect = getPrefs().getAutoReconnect(device); if(!shouldAutoConnect){ continue; } @@ -614,7 +628,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere boolean autoReconnect = GBPrefs.AUTO_RECONNECT_DEFAULT; if (prefs != null && prefs.getPreferences() != null) { - autoReconnect = getGBPrefs().getAutoReconnect(gbDevice); + autoReconnect = getPrefs().getAutoReconnect(gbDevice); if (!fromExtra && !autoReconnect) { continue; } @@ -1535,7 +1549,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (GBPrefs.DEVICE_AUTO_RECONNECT.equals(key)) { for(DeviceStruct deviceStruct : deviceStructs){ - boolean autoReconnect = getGBPrefs().getAutoReconnect(deviceStruct.getDevice()); + boolean autoReconnect = getPrefs().getAutoReconnect(deviceStruct.getDevice()); deviceStruct.getDeviceSupport().setAutoReconnect(autoReconnect); } } @@ -1552,14 +1566,10 @@ public class DeviceCommunicationService extends Service implements SharedPrefere return getPrefs().getPreferences() != null; } - public Prefs getPrefs() { + public GBPrefs getPrefs() { return GBApplication.getPrefs(); } - public GBPrefs getGBPrefs() { - return GBApplication.getGBPrefs(); - } - public GBDevice[] getGBDevices() { GBDevice[] devices = new GBDevice[deviceStructs.size()]; for(int i = 0; i < devices.length; i++){ diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java index 5f8c1c6da..6811c3296 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java @@ -3305,7 +3305,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements LOG.error("Error sending wind/humidity", ex); } - float[] longlat = GBApplication.getGBPrefs().getLongLat(getContext()); + float[] longlat = GBApplication.getPrefs().getLongLat(getContext()); float longitude = longlat[0]; float latitude = longlat[1]; if (longitude != 0 && latitude != 0) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java index 23b528ed3..b4bc4513c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java @@ -209,7 +209,7 @@ class PebbleIoThread extends GBDeviceIoThread { mOutStream = mBtSocket.getOutputStream(); } } - if (GBApplication.getGBPrefs().isBackgroundJsEnabled()) { + if (GBApplication.getPrefs().isBackgroundJsEnabled()) { Intent startIntent = new Intent(getContext(), ExternalPebbleJSActivity.class); startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startIntent.putExtra(ExternalPebbleJSActivity.START_BG_WEBVIEW, true); @@ -242,7 +242,7 @@ class PebbleIoThread extends GBDeviceIoThread { public void run() { mIsConnected = connect(); if (!mIsConnected) { - if (GBApplication.getGBPrefs().getAutoReconnect(getDevice()) && !mQuit) { + if (GBApplication.getPrefs().getAutoReconnect(getDevice()) && !mQuit) { gbDevice.setState(GBDevice.State.WAITING_FOR_RECONNECT); gbDevice.sendDeviceUpdateIntent(getContext()); } @@ -406,13 +406,13 @@ class PebbleIoThread extends GBDeviceIoThread { enablePebbleKitSupport(false); - if (mQuit || !GBApplication.getGBPrefs().getAutoReconnect(getDevice())) { + if (mQuit || !GBApplication.getPrefs().getAutoReconnect(getDevice())) { gbDevice.setState(GBDevice.State.NOT_CONNECTED); } else { gbDevice.setState(GBDevice.State.WAITING_FOR_RECONNECT); } - if (GBApplication.getGBPrefs().isBackgroundJsEnabled()) { + if (GBApplication.getPrefs().isBackgroundJsEnabled()) { WebViewSingleton.getInstance().disposeWebView(); } @@ -540,7 +540,7 @@ class PebbleIoThread extends GBDeviceIoThread { break; case START: LOG.info("got GBDeviceEventAppManagement START event for uuid: " + appMgmt.uuid); - if (GBApplication.getGBPrefs().isBackgroundJsEnabled()) { + if (GBApplication.getPrefs().isBackgroundJsEnabled()) { if (mPebbleProtocol.hasAppMessageHandler(appMgmt.uuid)) { WebViewSingleton.getInstance().stopJavascriptInterface(); } else { @@ -563,7 +563,7 @@ class PebbleIoThread extends GBDeviceIoThread { setInstallSlot(appInfoEvent.freeSlot); return false; } else if (deviceEvent instanceof GBDeviceEventAppMessage) { - if (GBApplication.getGBPrefs().isBackgroundJsEnabled()) { + if (GBApplication.getPrefs().isBackgroundJsEnabled()) { sendAppMessageJS((GBDeviceEventAppMessage) deviceEvent); } if (mEnablePebblekit) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java index f3a719119..afa9a2250 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java @@ -423,7 +423,7 @@ public class PebbleProtocol extends GBDeviceProtocol { super(device); mAppMessageHandlers.put(UUID_MORPHEUZ, new AppMessageHandlerMorpheuz(UUID_MORPHEUZ, PebbleProtocol.this)); mAppMessageHandlers.put(UUID_MISFIT, new AppMessageHandlerMisfit(UUID_MISFIT, PebbleProtocol.this)); - if (!GBApplication.getGBPrefs().isBackgroundJsEnabled()) { + if (!GBApplication.getPrefs().isBackgroundJsEnabled()) { mAppMessageHandlers.put(UUID_PEBBLE_TIMESTYLE, new AppMessageHandlerTimeStylePebble(UUID_PEBBLE_TIMESTYLE, PebbleProtocol.this)); mAppMessageHandlers.put(UUID_PEBSTYLE, new AppMessageHandlerPebStyle(UUID_PEBSTYLE, PebbleProtocol.this)); mAppMessageHandlers.put(UUID_MARIOTIME, new AppMessageHandlerMarioTime(UUID_MARIOTIME, PebbleProtocol.this)); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/webview/GBWebClient.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/webview/GBWebClient.java index 8295c0042..ce5dabb56 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/webview/GBWebClient.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/webview/GBWebClient.java @@ -79,7 +79,7 @@ public class GBWebClient extends WebViewClient { private WebResourceResponse mimicReply(Uri requestedUri) { if (requestedUri.getHost() != null && (StringUtils.indexOfAny(requestedUri.getHost(), AllowedDomains) != -1)) { - if (GBApplication.getGBPrefs().isBackgroundJsEnabled() && WebViewSingleton.getInstance().internetHelperBound) { + if (GBApplication.getPrefs().isBackgroundJsEnabled() && WebViewSingleton.getInstance().internetHelperBound) { LOG.debug("WEBVIEW forwarding request to the internet helper"); Bundle bundle = new Bundle(); bundle.putString("URL", requestedUri.toString()); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GBPrefs.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GBPrefs.java index 7294cf9ee..00d59486c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GBPrefs.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GBPrefs.java @@ -37,7 +37,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; -public class GBPrefs { +public class GBPrefs extends Prefs { // Since this class must not log to slf4j, we use plain android.util.Log private static final String TAG = "GBPrefs"; @@ -72,10 +72,13 @@ public class GBPrefs { public static final String LAST_DEVICE_ADDRESSES = "last_device_addresses"; public static final String RECONNECT_ONLY_TO_CONNECTED = "general_reconnectonlytoconnected"; - private final Prefs mPrefs; - + @Deprecated public GBPrefs(Prefs prefs) { - mPrefs = prefs; + this(prefs.getPreferences()); + } + + public GBPrefs(final SharedPreferences sharedPrefs) { + super(sharedPrefs); } public boolean getAutoReconnect(GBDevice device) { @@ -84,23 +87,23 @@ public class GBPrefs { } public boolean getAutoReconnectByScan() { - return mPrefs.getBoolean(RECONNECT_SCAN_KEY, RECONNECT_SCAN_DEFAULT); + return getBoolean(RECONNECT_SCAN_KEY, RECONNECT_SCAN_DEFAULT); } public boolean getAutoStart() { - return mPrefs.getBoolean(AUTO_START, AUTO_START_DEFAULT); + return getBoolean(AUTO_START, AUTO_START_DEFAULT); } public boolean isBackgroundJsEnabled() { - return mPrefs.getBoolean(BG_JS_ENABLED, BG_JS_ENABLED_DEFAULT); + return getBoolean(BG_JS_ENABLED, BG_JS_ENABLED_DEFAULT); } public String getUserName() { - return mPrefs.getString(USER_NAME, USER_NAME_DEFAULT); + return getString(USER_NAME, USER_NAME_DEFAULT); } public Date getUserBirthday() { - String date = mPrefs.getString(USER_BIRTHDAY, null); + String date = getString(USER_BIRTHDAY, null); if (date == null) { return null; } @@ -117,7 +120,7 @@ public class GBPrefs { } public String getTimeFormat() { - String timeFormat = mPrefs.getString(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_AUTO); + String timeFormat = getString(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_AUTO); if (DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_AUTO.equals(timeFormat)) { if (DateFormat.is24HourFormat(GBApplication.getContext())) { timeFormat = DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_24H; @@ -130,14 +133,12 @@ public class GBPrefs { } public float[] getLongLat(Context context) { - Prefs prefs = GBApplication.getPrefs(); - - float latitude = prefs.getFloat("location_latitude", 0); - float longitude = prefs.getFloat("location_longitude", 0); + float latitude = getFloat("location_latitude", 0); + float longitude = getFloat("location_longitude", 0); Log.i(TAG, "got longitude/latitude from preferences: " + latitude + "/" + longitude); if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED && - prefs.getBoolean("use_updated_location_if_available", false)) { + getBoolean("use_updated_location_if_available", false)) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); String provider = locationManager.getBestProvider(criteria, false);