16
submitted 5 months ago* (last edited 5 months ago) by salvador@lemmy.world to c/android@lemmy.world

I have an app which polls a remote server by sending to it its cache GPS location. Sometimes a remote server will ask for live location and an app must send it to it.


object MyLocationManager {
    val providers = listOf(
        LocationManager.GPS_PROVIDER,
        "fused",
        LocationManager.NETWORK_PROVIDER,
        LocationManager.PASSIVE_PROVIDER,
    )


    fun getCached(ctx: Context, locationManager: LocationManager): Location? {
        for (provider in providers) {
            when (provider) {
                "fused" -> {
                    val fusedLocationClient =
                        LocationServices.getFusedLocationProviderClient(ctx)
                    val fusedLocationTask = fusedLocationClient.lastLocation
                    val fusedLocation = getTaskResult(fusedLocationTask)
                    if (fusedLocation != null) {
                        return fusedLocation
                    }
                }
                else -> {
                    if (locationManager.isProviderEnabled(provider)) {
                        val lastKnownLocation = locationManager.getLastKnownLocation(provider)
                        Log.d(
                            TAG,
                            "Provider: $provider, Last Known Location: $lastKnownLocation"
                        )

                        if (lastKnownLocation != null) {
                            return lastKnownLocation
                        }
                    }
                }
            }
        }

        return null
    }

    fun getLive(ctx: Context, locationManager: LocationManager): Location? {
        val locationListener = object : LocationListener {
            override fun onLocationChanged(location: Location) {

                //This works correctly!
                //
                //1) how to save its result? How to save it into cache?
                //2) or how to return it from here?
                Log.d(TAG, "onLocationChanged: ${location.latitude}, ${location.longitude}")

                stopLocationUpdates()
            }

            private fun stopLocationUpdates() {
                val fusedLocationClient = LocationServices.getFusedLocationProviderClient(ctx)

                try {
                    // Stop location updates
                    fusedLocationClient.removeLocationUpdates(locationCallback)
                    Log.d(TAG, "Location updates stopped")
                } catch (e: SecurityException) {
                    Log.e(TAG, "SecurityException while stopping location updates: ${e.message}")
                }
            }

            private val locationCallback = object : LocationCallback() {
                override fun onLocationResult(locationResult: LocationResult) {
                    super.onLocationResult(locationResult)
                    val location = locationResult.lastLocation
                    if (location != null) {
                        onLocationChanged(location)
                    } else {
                        Log.e(TAG, "Received null location in onLocationResult")
                    }
                }
            }
        }

        for (provider in providers) {
            when (provider) {
                LocationManager.GPS_PROVIDER -> {

                    //obsolete, in the last Android versions
                    val _locationRequest = LocationRequest.create()
                        .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
                        .setInterval(0)
                        .setFastestInterval(0)

                    val fusedLocationClient = LocationServices.getFusedLocationProviderClient(ctx)
                    val locationResult: Task = fusedLocationClient.getLocationAvailability()

                    if (!Tasks.await(locationResult).isLocationAvailable) {
                        return null
                    }

                    val locationTask: Task = fusedLocationClient.getCurrentLocation(
                        LocationRequest.PRIORITY_HIGH_ACCURACY,
                        null
                    )

                    return Tasks.await(locationTask)
                }

                "fused" -> {
                    val apiAvailability = GoogleApiAvailability.getInstance()
                    val resultCode = apiAvailability.isGooglePlayServicesAvailable(ctx)

                    if (resultCode == ConnectionResult.SUCCESS) {
                        val fusedLocationClient = LocationServices.getFusedLocationProviderClient(ctx)
                        val fusedLocationTask = fusedLocationClient.lastLocation
                        val fusedLocation = getTaskResult(fusedLocationTask)
                        if (fusedLocation != null) {
                            return fusedLocation
                        }
                    } else {
                        Log.w(TAG, " Google Play Services aren't available, can't use fused")
                    }

                }

                else -> {
                    if (locationManager.isProviderEnabled(provider)) {
                        locationManager.requestSingleUpdate(
                            provider,
                            locationListener,
                            Looper.getMainLooper()
                        )

                        val lastKnownLocation = locationManager.getLastKnownLocation(provider)
                        if (lastKnownLocation != null) {
                            return lastKnownLocation
                        }
                    }
                }
            }
        }

        return null
    }
}


An issue is that the code for obtaining GPS location doesn't work properly. Firstly, I don't know whether the approach in the code is correct. Secondly, I don't know how to properly to return the GPS coordinates from a callback -- see the comments. Thirdly, I don't know how to force it to store the latest coordinates that it's obtained into cache.

And there're some functions that's been derprecated in the latest versions of Android, particularly in Android 10.

How to do all of this?

My device is rooted.

15
submitted 6 months ago* (last edited 6 months ago) by salvador@lemmy.world to c/android@lemmy.world

I have a rooted Android 10. And I've written a service (off the class Service) which I want to run under too, in background. A service uses a microphone and location. It's written in Kotlin.

I've not found any information of how to run a service on a rooted device under root. I've found some, about running some commands in a service (code) itself under root, though, but it may be only a part of what I need.

How to do it?

Essentially, I want my service to run forever, with elevated preveligies, get itself restarted if it fails, gets killed by Android.


Also, I've tried to copy it into /system and /system/init directories, but I haven't been able to, due to "read-only file system". Nor have I been able to remount it to make it writteable. I've managed to make the / writteable, but it didn't allow me to copy my service in /system nonetheless.

-8
submitted 8 months ago* (last edited 8 months ago) by salvador@lemmy.world to c/worldnews@sh.itjust.works
-32
submitted 8 months ago by salvador@lemmy.world to c/worldnews@lemmy.ml
-40
submitted 8 months ago* (last edited 8 months ago) by salvador@lemmy.world to c/world@lemmy.world

The US and Europe admit that they're been believing in their own propaganda about Russia and Putin.

5
submitted 9 months ago* (last edited 9 months ago) by salvador@lemmy.world to c/programming@programming.dev

I connect to a WireGuard installed on my VPS. Then I go to a random VPN service marketing page on which I'll discover that my DNS leaks. And which is correct because I've specified DNS = 1.1.1.1 in [Interface] for all the Peers.

In order to avoid DNS leakadge, do I have to a) run DNS server on the a VPS -- along with WireGuard, and b) use this one and only it, instead of 1.1.1.1?


But if so, how will this possibly work?

[Peer]
PublicKey = [....;....]
PresharedKey = [......]
Endpoint = wg.my_domain123.com:51820

In order to resolve Endpoint of my VPS to begin with, other DNS server will have to be used -- by IP. But there'll be none because I'll use a DNS on my VPS instead of 1.1.1.1. In other words, it'll be a circular dependency.

3
submitted 10 months ago by salvador@lemmy.world to c/elixir@programming.dev

In a third-party project, in the models, I've encountered functions like this:

  def changeset(model \\ %__MODULE__{}, params) do
    model
    |> cast(params, @required_fields ++ @optional_fields)
    |> validate_required(@required_fields)
  end

How can a function have a default argument which is both a) first and b) followed by a mandatory one?

What's interesting, they work properly.

[-] salvador@lemmy.world 1 points 10 months ago* (last edited 10 months ago)

None other than pro-West "The S&P Global Purchasing Managers' Index (PMI)" claims so. Putin had already paid them for it, of course. And as usually "Putin is in panic! In panic!!!1"

3
submitted 10 months ago* (last edited 10 months ago) by salvador@lemmy.world to c/linux@lemmy.world

A docker, when run for the 1st time, won't do so:

$ docker-compose -f docker-compose.local.yml up -d

permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json?all=1&filters=%7B%22label%22%3A%7B%22com.docker.compose.config-hash%22%3Atrue%2C%22com.docker.compose.project%3Doxygen%22%3Atrue%7D%7D": dial unix /var/run/docker.sock: connect: permission denied

I'll run this command

$ sudo setfacl --modify user:user1:rw /var/run/docker.sock

which will resolve the issue. However, after a reboot, the issue will arise again.

Why? How to make the change permanent?

10
submitted 10 months ago by salvador@lemmy.world to c/world@lemmy.world

"Sanctions from hell" are working

27
submitted 10 months ago by salvador@lemmy.world to c/world@lemmy.world
[-] salvador@lemmy.world 1 points 10 months ago

But the mailboxes of MailCow are always encrypted

-1
submitted 10 months ago* (last edited 10 months ago) by salvador@lemmy.world to c/linux@programming.dev

I've set up WireGuard on a VPS.

A client on Linux desktop works with no issues.

The one on an android phone too, but not completely. Namely, TX and RX get updated, "handshake" and "last connected" with a phone on a server gets updated too, as well as on a phone itself. However, I can't open any single website.

However, Telegram, for instance, works well. Another android app too, it appears. But all the rest of the apps don't, not do the Firefox and Chrome.

What's the matter?

8

Not Russia, Putin! has created yet a more powerfull missle.

Yeah, Putin himself -- during the breaks for lunch whilst in Kremlin.

[-] salvador@lemmy.world 1 points 10 months ago* (last edited 10 months ago)
  1. "check bias". I have. And?

  2. US and European sources - are also "non Russian" ones. Are they biased against Russia or not? The ones on the website that come from Russia itself - may also be biased. Why? Because there're certain people, as in every country, who want to change the current government from within.

  3. On Youtube, listen, for instance, to:

  • a) Scott Ritter (US ex-marine, lived in Russia too) / Ask the inspector / he has a SubStack also

  • b) The New Atlas - by Brian Berletic

  • c) The Duran

All these are english sources, and they all are knowlegable about Russia and geopolitics

[-] salvador@lemmy.world 1 points 10 months ago* (last edited 10 months ago)
  1. What does mediabiasfactcheck.com have to do with russian economy and my original post?

  2. What makes it neutral and unbiased?

  3. A website can feed you a lot of bullshit whilst pretending to be unbiased, hard-core, independent "fact checker". It's even easier. I've seen this during the little-flu c-19 virus: the "fact check" websites were the greatest source of bullshit


Go read some Brazilian, Indian sources, for instances, about Russian economy in 2022-2023. Or the ones from Malaysia, Indonesia. From the Middle East. Hungary, Serbia. These will be more or less neutral.

You can even go listen to Alexander Mercouris -- he's from the UK.

[-] salvador@lemmy.world 1 points 10 months ago* (last edited 10 months ago)

Where's any trustworthy or neural source for 2022 or 2023? Show me a few. Then make claims

[-] salvador@lemmy.world 1 points 10 months ago* (last edited 10 months ago)

You're mentally stuck in the world of 1990s or 2000s :) And even in the era of USSR

You mentioned the sources of 2013. What year is now: 2013 or 2023?

[-] salvador@lemmy.world 2 points 10 months ago

"May as well" -- how about October, March and August?

[-] salvador@lemmy.world 2 points 10 months ago

Look at what I quoted.

[-] salvador@lemmy.world 1 points 10 months ago* (last edited 10 months ago)

Europe and US like to accuse others of everything. But they, strangely, don't like to be accused themselves in anything

[-] salvador@lemmy.world 2 points 10 months ago

Arch Linux.

view more: next ›

salvador

joined 10 months ago