Giter Site home page Giter Site logo

Comments (21)

davidgyoung avatar davidgyoung commented on September 8, 2024 1

from android-beacon-library.

davidgyoung avatar davidgyoung commented on September 8, 2024 1

@kangjjang, this thread is dedicated to detection problems with the screen off ONLY on Android 14 on Pixel phones. It sounds like you need general help configuring an app for fast background detections. Please see this page: Alternate Scan Strategies. You will need to configure the library to use either a Foreground Service or the Intent Scan Strategy described at the very bottom of this page.

If you need further help configuring your custom app, please open a new question on StackOverflow.com, as that is the proper forum for assistance with using the library with third party apps. This thread is ONLY for trouble detecting with the screen off on Android 14 on Pixel phones.

from android-beacon-library.

kerembalcan avatar kerembalcan commented on September 8, 2024 1

I have a similar issue with a Samsung Galaxy A34 (Android 14) in the latest version of the library(2.20.4). Since the issue is very similar, I'm posting it here instead of creating a new one, even though my device is not a Pixel device.

Attaching some log files here to avoid a distracting view in the comment.

As mentioned in the top comment, I’m testing the reference app with the foreground service configuration enabled, and I experience that both ranging and monitoring stop immediately when I lock the screen.

Once I unlock the screen, it starts working again and successfully sends the “A beacon is nearby” notification.

Additionally, if the app was in the foreground when the lock button was hit, ranging and monitoring do not start even after the unlock. I needed to go back to home screen that triggered an “onPause” event which started the beacon scanning again. If you search “onPause” in the logs of “locked_to_unlocked_logs” file, you will see how it triggered the scanning.

After that, you can check the “unlocked_to_locked_logs” file and search “Using a non-empty scan filter since this is 14.0 or Samsung 8.1+” logs to see how it stopped scanning.

I tested these with an OnePlus 7T (Android 12) and it just works as expected after locking the screen. Since it never stops working, I don’t need to trigger an onPause event when I unlocked.

  • iBeacon layout, manufacturer code, and region configuration are set successfully, as the other test device works with no issues proving that. Samsung also works as expected when the screen is unlocked.
  • The version of the library is set to 2.20.4
  • Applied all the settings suggested in https://dontkillmyapp.com/samsung

I hope this is clear, if it’s not or you need more logs not filtered application level, I can provide them too. The issue is easy to reproduce.


Edit: I found a solution for my case. I found this comment by @davidgyoung in the CycledLeScannerForLollipop.java - startScan() method:
// On the Samsung 8.1 and Android 14.0, scans are blocked with screen off when the // scan filter is empty (wildcard). We do a more detailed filter on such devices // only because it might block detections of AltBeacon packets with non-standard // manufacturer codes. See #769 for details.
And then, I changed the manufacturerCode to Apple one(0x004c) instead of the actual manufacturer's one, and now it can scan iBeacons on my Samsung device even if the screen is off.
Maybe this is how it should be -- setting Apple manufacturer code for iBeacon scanning even though you have the iBeacon from a different manufacturer, I don't know, never seen it in the documentation. Maybe this helps someone

locked_to_unlocked_logs.txt
unlocked_to_locked_logs.txt
locked_logs.txt

from android-beacon-library.

davidgyoung avatar davidgyoung commented on September 8, 2024

Hi @juliankotrba thank you for this report.

I was able to reoproduce your results. At first glance, this appears to be a change to Android 14. It seems that with the screen off, scans with empty Bluetooth LE scan filters return no results. (This is how Samsung forks of Android behaved since 8.1, but Pixels did not appear to work this way as recently as Android 13).

I tried modifying the Android Beacon Library code to use non-empty scan filters (like the library already does for Samsung) and the ranging started working even with the screen off: #1176

Does your app target Android 14? Do you know if this matters?

from android-beacon-library.

juliankotrba avatar juliankotrba commented on September 8, 2024

Hi @davidgyoung.

I tried modifying the Android Beacon Library code to use non-empty scan filters (like the library already does for Samsung) and the ranging started working even with the screen off: #1176

Nice, I will test your fix and give you feedback later!

Does your app target Android 14? Do you know if this matters?
Yes, we target Android 14 but I am not sure if this matters. As far as I remember I did some tests were I went back in the git history of the project and it also did not work when we did not target Android 14.

When you were able to reproduce the issue, on which Pixel did you test? For us, the issue only appeared on our Pixel 7, but not Pixel 8 (tested on one Pixel 7 and two Pixel 8).

Thanks for your help!

from android-beacon-library.

juliankotrba avatar juliankotrba commented on September 8, 2024

@davidgyoung Pixel 7 is working again! 👏

from android-beacon-library.

davidgyoung avatar davidgyoung commented on September 8, 2024

Test results on various devices:

Model      OS         Library Version   Ranges with Screen Off
--------  ----------  ---------------   ------------------------
Pixel 4a  Android 13  2.20.2            YES
Pixel 4a  Android 13  #1176             YES
Pixel 6a  Android 12  2.20.2            YES
Pixel 6a  Android 12  #1176             YES
Pixel 6a  Android 13  2.20.2            YES
Pixel 6a  Android 13  #1176             YES
Pixel 6a  Android 14  2.20.2            YES   
Pixel 6a  Android 14  #1176             YES
Pixel 7   Android 14  2.20.2            NO
Pixel 7   Android 14  #1176             YES

Note: the two different Android 14 build numbers above are:

Pixel 6a Android 14 build number UP1A.231105.003
Pixel 7 Android 14 build number U1B2.230922.006

Only the Pixel 7 Android 14 build shown above ever seems to block beacon detections with the screen off unless a non-empty bluetooth scan filter is active as added to library build #1176

from android-beacon-library.

davidgyoung avatar davidgyoung commented on September 8, 2024

I did a few more tests with Pixel 7 Android 14, varying the target SDK in the app:

Model      OS         Library Version Target SDK   Ranges with Screen Off  Notes
--------  ----------  --------------- ----------   ----------------------  -----
Pixel 7   Android 14  2.20.2          33           YES                     Clean install
Pixel 7   Android 14  2.20.2          34           YES                     Upgrade from above
Pixel 7   Android 14  2.20.2          34           NO                      Clean install

So the problem only happens on the Pixel 7 if set the targetSdk to 34. Further, if you set the targetSdk to 33, run the app, then change the targetSdk to 34 and run the app again (without uninstall), the behavior is not seen. So it seems the behavior only applies to apps targeting Android 14 and newly installed on Pixel 7s.

from android-beacon-library.

kangjjang avatar kangjjang commented on September 8, 2024

I don't recognize the beacon after a few minutes after the screen is turned off.
After a few minutes (10 minutes to 15 minutes), sometimes it is recognized.

image

Your Kotlin reference code is used and Alt Beacon Library 2.20.2 is being used.
In the code below, which part should I activate or modify it to use the beacons in a short time (within 1 minute to 2 minutes) even in the LCD OFF state below?
Or is it impossible to scan a beacon within 1 to 2 minutes in Android LCD OFF?

In the code below, which part should I activate or modify it to use the beacons in a short time (within 1 minute to 2 minutes) even in the LCD OFF state below?
I added the code below.

https://github.com/davidgyoung/android-beacon-library-rational-kotlin/blob/master/app/src/main/java/org/OLTBEACON/BEACONREPERENCE Plcation.kt

Added code
BeaconManager.setBackgroundBetWeyenscanperiod (100);
BeaconManager.SetBackgroundScanperiod (1000);
BeaconManager.SetForegroundBet WeEenscanperiod (100)
BeaconManager.setScanperiod (1000)

from android-beacon-library.

akoskuczi-bw avatar akoskuczi-bw commented on September 8, 2024

Hi @davidgyoung,
Same issue with Motorola g54 even with Android version 13.
Build: 5.10.168-android12-9-00003-g828a3b1f7462-ab10564101

From logcat: "BtGatt.ScanManager com.android.bluetooth W Cannot start unfiltered scan in screen-off. This scan will be resumed later: 14"

from android-beacon-library.

davidgyoung avatar davidgyoung commented on September 8, 2024

@akoskuczi-bw, the logcat line you mention has been around since Android 8.1, and as originally created, applied only to the case where there are zero scan filters attached to the scan:

https://android.googlesource.com/platform/packages/apps/Bluetooth/+/319aeae6f4ebd13678b4f77375d1804978c4a1e1%5E%21/#F1

When do you see this log line with Android 13? Does it happen every time you try to start a scan with the screen off or just sometimes? Is in an app using this library?

from android-beacon-library.

akoskuczi-bw avatar akoskuczi-bw commented on September 8, 2024

Yes, it is on Android 13. The scanning stops working consistently when the screen is off, and it restarts when the screen is on (not necessarily unlocked). I am using it with the following Flutter plugin: https://github.com/Lukangi/beacon_scanner/tree/main/beacon_scanner

from android-beacon-library.

davidgyoung avatar davidgyoung commented on September 8, 2024

Researching AOSP commits, I found this change from July 2023 that is now part of Android 14:

https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2654980

Interestingly the commit is from a Motorola engineer, so perhaps the change went in to an earlier proprietary change on Motorola that does not show up in AOSP.

OK, so this sounds believable. However, this does not explain the OP's report that the restriction did not apply to Pixel 8 with Android 14, and my observation above that it did not apply to Pixel 6a with Android 14. Could it be that this AOSP change was not in the Android 14 builds for the Pixel 6a and Pixel 8? What else could explain this?

from android-beacon-library.

davidgyoung avatar davidgyoung commented on September 8, 2024

I have merged the change to fix this for Android 14. This does not address the problem for Motorola Android 13 as reported by @akoskuczi-bw. Does anybody else on this thread have a Motorola device with Android 13 to confirm the problem there?

If we can get a confirmation of this on a second Motorola Android 13 device, I will make a new change that creates a scan filter for those devices, too. (I am reluctant to do this without confirmation since it could be a breaking change for apps that have been running on Motorola phones for the past year.) Until this is resolved I will leave this issue open.

from android-beacon-library.

akoskuczi-bw avatar akoskuczi-bw commented on September 8, 2024

@davidgyoung I absolutely understand your position regarding Motorola. I'm wondering if anyone can confirm the issue with Motorola. Thank you very much for your time and efforts.

from android-beacon-library.

juliankotrba avatar juliankotrba commented on September 8, 2024

@akoskuczi-bw @davidgyoung FYI I can't confirm the issue on the Motorola, however, I can reproduce it on our "new" Asus Zenfone 9 running with Android 13. Maybe also on a OnePlus but for that I need to do some more investigation.

Adding Build.MANUFACTURER.equalsIgnoreCase("asus") to the scan filter check if statement solves the issue on my Asus.

EDIT:

To make it more clear what I did locally to get it working:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
                if ((Build.MANUFACTURER.equalsIgnoreCase("samsung") || 
                          --> Build.MANUFACTURER.equalsIgnoreCase("asus")  || <--
                          Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) &&
                          !mPowerManager.isInteractive()) {
                    // On the Samsung 8.1 and Android 14.0, scans are blocked with screen off when the
                    // scan filter is empty (wildcard).  We do a more detailed filter on such devices
                    // only because it might block detections of AltBeacon packets with non-standard
                    // manufacturer codes.  See #769 for details.
                    LogManager.d(TAG, "Using a non-empty scan filter since this is 14.0 or Samsung 8.1+");
                    filters = new ScanFilterUtils().createScanFiltersForBeaconParsers(
                            mBeaconManager.getBeaconParsers());
                }

from android-beacon-library.

davidgyoung avatar davidgyoung commented on September 8, 2024

thanks, @juliankotrba. it sounds like we do need to include Asus and Motorola on Android 13

from android-beacon-library.

tomerpetel avatar tomerpetel commented on September 8, 2024

Seeing the same issue on
14, UP1A.231005.007, 22101316UG, Xiaomi
Running version 2.20.4

from android-beacon-library.

RajatSinghBisht avatar RajatSinghBisht commented on September 8, 2024

I have merged the change to fix this for Android 14. This does not address the problem for Motorola Android 13 as reported by @akoskuczi-bw. Does anybody else on this thread have a Motorola device with Android 13 to confirm the problem there?

If we can get a confirmation of this on a second Motorola Android 13 device, I will make a new change that creates a scan filter for those devices, too. (I am reluctant to do this without confirmation since it could be a breaking change for apps that have been running on Motorola phones for the past year.) Until this is resolved I will leave this issue open.

hi @davidgyoung @akoskuczi-bw , i face the same issue in Motorola edge40, Samsung F12. Please consider fixing this issue for these devices.
I am using the same flutter library to access iBeacon.

from android-beacon-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.