Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android 12 running java example (sample) #798

Closed
pascalpm opened this issue Jun 29, 2022 · 14 comments · Fixed by #800
Closed

Android 12 running java example (sample) #798

pascalpm opened this issue Jun 29, 2022 · 14 comments · Fixed by #800
Labels
bug Bug that is caused by the library

Comments

@pascalpm
Copy link

Anyone found a solution to this? Running the java sample in Android 12 results to (debug mode):

java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for AttributionSource ......

Older Android versions do not ask for this permission and seem to work fine!

R1.15.1
Android Studio Chipmunk 2021.2.1 Patch 1
Sdk 32

@pascalpm pascalpm added the bug Bug that is caused by the library label Jun 29, 2022
@dariuszseweryn
Copy link
Owner

Could you describe in more detail what steps did you take that ended up with such result?

@dariuszseweryn
Copy link
Owner

dariuszseweryn commented Jun 29, 2022

Could you try out 1.15.2-SNAPSHOT release with DEBUG log level enabled and show the logs that precede the exception?
Instructions how to integrate snapshot repositories are here.

If you could checkout branch fix/permissions_logging, build and run the sample app again and show the logs that precede the exception — it could help me out to diagnose the problem.

@pascalpm
Copy link
Author

pascalpm commented Jun 30, 2022

Here it is (from the branch "fix/permissions_logging". Hopefully this helps.

06/30 18:28:26: Launching 'sample' on samsung SM-A315G.
Install successfully finished in 543 ms.
$ adb shell am start -n "com.polidea.rxandroidble.sample/com.polidea.rxandroidble2.sample.example1_scanning.ScanActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.polidea.rxandroidble.sample
Connecting to com.polidea.rxandroidble.sample
Connected to the target VM, address: 'localhost:51145', transport: 'socket'
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/droidble.sampl: Late-enabling -Xcheck:jni
E/USNET: USNET: appName: com.polidea.rxandroidble.sample
D/ProcessState: Binder ioctl to enable oneway spam detection failed: Invalid argument
D/ActivityThread: setConscryptValidator
D/ActivityThread: setConscryptValidator - put
V/studio.deploy: Startup agent attached to VM
V/studio.deploy: No existing instrumentation found. Loading instrumentation from instruments-962d6e1a.jar
W/droidble.sampl: DexFile /data/data/com.polidea.rxandroidble.sample/code_cache/.studio/instruments-962d6e1a.jar is in boot class path but is not in a known location
V/studio.deploy: ModifyParameterTransform failed: Landroid/app/ApplicationLoaders;
W/droidble.sampl: Current dex file has more than one class in it. Calling RetransformClasses on this class might fail if no transformations are applied to it!
W/droidble.sampl: Current dex file has more than one class in it. Calling RetransformClasses on this class might fail if no transformations are applied to it!
W/droidble.sampl: Redefining intrinsic method java.lang.Thread java.lang.Thread.currentThread(). This may cause the unexpected use of the original definition of java.lang.Thread java.lang.Thread.currentThread()in methods that have already been compiled.
W/droidble.sampl: Redefining intrinsic method boolean java.lang.Thread.interrupted(). This may cause the unexpected use of the original definition of boolean java.lang.Thread.interrupted()in methods that have already been compiled.
W/droidble.sampl: Current dex file has more than one class in it. Calling RetransformClasses on this class might fail if no transformations are applied to it!
W/droidble.sampl: Current dex file has more than one class in it. Calling RetransformClasses on this class might fail if no transformations are applied to it!
W/droidble.sampl: Current dex file has more than one class in it. Calling RetransformClasses on this class might fail if no transformations are applied to it!
D/ActivityThread: handleBindApplication()++ app=com.polidea.rxandroidble.sample
D/CompatibilityChangeReporter: Compat change id reported: 171979766; UID 10481; state: ENABLED
W/ActivityThread: Application com.polidea.rxandroidble.sample is waiting for the debugger on port 8100...
I/System.out: Sending WAIT chunk
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
W/System: A resource failed to call close. 
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1484)
W/ActivityThread: Slow operation: 2021ms so far, now at handleBindApplication: Before HardwareRenderer
W/ActivityThread: Slow operation: 2046ms so far, now at handleBindApplication: After HardwareRenderer
D/ApplicationLoaders: Returning zygote-cached class loader: /system/framework/android.test.base.jar
V/GraphicsEnvironment: ANGLE Developer option for 'com.polidea.rxandroidble.sample' set to: 'default'
V/GraphicsEnvironment: Neither updatable production driver nor prerelease driver is supported.
D/LoadedApk: LoadedApk::makeApplication() appContext.mOpPackageName=com.polidea.rxandroidble.sample appContext.mBasePackageName=com.polidea.rxandroidble.sample
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/ActivityThread: handleBindApplication() --
I/BluetoothAdapter: BluetoothAdapter() : com.polidea.rxandroidble.sample
I/BluetoothAdapter: BluetoothAdapter() : com.polidea.rxandroidble.sample
D/OpenGLRenderer: RenderThread::requireGlContext()
D/hw-ProcessState: Binder ioctl to enable oneway spam detection failed: Invalid argument
E/OpenGLRenderer: Device claims wide gamut support, cannot find matching config, error = EGL_SUCCESS
W/OpenGLRenderer: Failed to initialize 101010-2 format, error = EGL_SUCCESS
D/OpenGLRenderer: RenderThread::setGrContext()
I/DecorView: [INFO] isPopOver=false, config=true
I/DecorView: updateCaptionType >> DecorView@2cf52e5[], isFloating=false, isApplication=true, hasWindowControllerCallback=true, hasWindowDecorCaption=false
D/DecorView: setCaptionType = 0, this = DecorView@2cf52e5[]
I/DecorView: getCurrentDensityDpi: from real metrics. densityDpi=420 msg=resources_loaded
W/droidble.sampl: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (unsupported, reflection, allowed)
W/droidble.sampl: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (unsupported, reflection, allowed)
I/ViewRootImpl@47f536e[ScanActivity]: setView = com.android.internal.policy.DecorView@2cf52e5 TM=true
I/BufferQueueConsumer: [](id:453300000000,api:0,p:-1,c:17715) connect: controlledByApp=false
I/BLASTBufferQueue: [ViewRootImpl@47f536e[ScanActivity]#0] constructor()
I/ViewRootImpl@47f536e[ScanActivity]: Relayout returned: old=(0,0,1080,2400) new=(0,0,1080,2400) req=(1080,2400)0 dur=30 res=0x7 s={true -5476376639154884608} ch=true fn=-1
I/BufferQueueProducer: [ViewRootImpl@47f536e[ScanActivity]#0(BLAST Consumer)0](id:453300000000,api:1,p:17715,c:17715) connect: api=1 producerControlledByApp=true
D/OpenGLRenderer: eglCreateWindowSurface
E/ion: ioctl c0044901 failed with code -1: Invalid argument
I/ViewRootImpl@47f536e[ScanActivity]: [DP] dp(1) 1 android.view.ViewRootImpl.reportNextDraw:11387 android.view.ViewRootImpl.performTraversals:4185 android.view.ViewRootImpl.doTraversal:2911 
D/ViewRootImpl@47f536e[ScanActivity]: Creating frameDrawingCallback nextDrawUseBlastSync=false reportNextDraw=true hasBlurUpdates=false
D/ViewRootImpl@47f536e[ScanActivity]: Creating frameCompleteCallback
D/hw-ProcessState: Binder ioctl to enable oneway spam detection failed: Invalid argument
D/ViewRootImpl@47f536e[ScanActivity]: Received frameDrawingCallback frameNum=1. Creating transactionCompleteCallback=false
D/ViewRootImpl@47f536e[ScanActivity]: Received frameCompleteCallback  lastAcquiredFrameNum=1 lastAttemptedDrawFrameNum=1
I/ViewRootImpl@47f536e[ScanActivity]: [DP] pdf(0) 1 android.view.ViewRootImpl.lambda$addFrameCompleteCallbackIfNeeded$3$ViewRootImpl:4987 android.view.ViewRootImpl$$ExternalSyntheticLambda16.run:6 android.os.Handler.handleCallback:938 
I/ViewRootImpl@47f536e[ScanActivity]: [DP] rdf()
D/ViewRootImpl@47f536e[ScanActivity]: reportDrawFinished (fn: -1) 
I/droidble.sampl: Background concurrent copying GC freed 3787(1081KB) AllocSpace objects, 1(20KB) LOS objects, 61% free, 3803KB/9947KB, paused 8.537ms,52us total 67.032ms
D/InsetsSourceConsumer: ensureControlAlpha: for ITYPE_NAVIGATION_BAR on com.polidea.rxandroidble.sample/com.polidea.rxandroidble2.sample.example1_scanning.ScanActivity
D/InsetsSourceConsumer: ensureControlAlpha: for ITYPE_STATUS_BAR on com.polidea.rxandroidble.sample/com.polidea.rxandroidble2.sample.example1_scanning.ScanActivity
I/ViewRootImpl@47f536e[ScanActivity]: MSG_WINDOW_FOCUS_CHANGED 1 1
D/InputMethodManager: startInputInner - Id : 0
I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
D/InputMethodManager: startInputInner - Id : 0
I/ViewRootImpl@47f536e[ScanActivity]: ViewPostIme pointer 0
I/ViewRootImpl@47f536e[ScanActivity]: ViewPostIme pointer 1
D/RxBle#CheckerScanPermission: Checking Permission: android.permission.BLUETOOTH_SCAN => true
D/RxBle#Client: Scan Runtime Permission Granted: true
D/RxBle#CheckerScanPermission: Checking Permission: android.permission.BLUETOOTH_SCAN => true
D/RxBle#LocationServicesStatusApi31: Scan Runtime Permission Granted: true
D/RxBle#ClientOperationQueue: QUEUED   ScanOperationApi21(205963980)
D/RxBle#ClientOperationQueue: STARTED  ScanOperationApi21(205963980)
I/RxBle#ClientOperationQueue: RUNNING  ScanOperationApi21{ANY_MUST_MATCH -> nativeFilters=[BluetoothLeScanFilter [mDeviceName=null, MAC=null, mUuid=null, mUuidMask=null, mSolicitedUuid=null, mSolicitedUuidMask=null, mServiceDataUuid=null, mServiceData=null, mServiceDataMask=null, mManufacturerId=-1, mManufacturerData=null, mManufacturerDataMask=null]]}
I/RxBle#QueueOperation: Scan operation is requested to start.
D/RxBle#ScanOperationApi21: No library side filtering —> debug logs of scanned devices disabled
I/BluetoothAdapter: STATE_ON
I/BluetoothAdapter: STATE_ON
I/BluetoothAdapter: STATE_ON
I/BluetoothAdapter: STATE_ON
D/BluetoothLeScanner: Start Scan with callback
D/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=17 mScannerId=0
D/RxBle#ClientOperationQueue: FINISHED ScanOperationApi21(205963980) in 48 ms
I/RxBle#CancellableDisposable: Scan operation is requested to stop.
I/BluetoothAdapter: STATE_ON
I/BluetoothAdapter: STATE_ON
D/BluetoothLeScanner: Stop Scan with callback
W/ScanActivity: Scan failed
    java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for AttributionSource { uid = 10481, packageName = com.polidea.rxandroidble.sample, attributionTag = null, token = android.os.BinderProxy@5955a3e, next = null }: AdapterService getRemoteName

@dariuszseweryn
Copy link
Owner

Awesome, thank you. TIL that calling BluetoothDevice#getName() needs android.permission.BLUETOOTH_CONNECT.

I will need to think if the library should warn the user and return null in case connect permission is not granted or leave it as it is

@dariuszseweryn
Copy link
Owner

It should be just a formality but you could check fix/sample_scan_device_name branch — it should be working fine. I should merge it somewhere this weekend probably if it works for you.

@pascalpm
Copy link
Author

pascalpm commented Jul 1, 2022

Thanks, but this did not work for me.
Please note that this permission issue happens when you hit the 'START SCAN' button, not when selecting a Bluetooth device! No list is displayed!

@dariuszseweryn
Copy link
Owner

I have changed the list adapter to use device name from the advertisement class which should not need the permission I think. Unless there is something else now. Could you share what is the exception now?

@pascalpm
Copy link
Author

pascalpm commented Jul 1, 2022

Same exception:
java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for AttributionSource { uid = 10488, packageName = com.polidea.rxandroidble.sample, attributionTag = null, token = android.os.BinderProxy@287f744, next = null }: AdapterService getRemoteName

@pascalpm
Copy link
Author

pascalpm commented Jul 1, 2022

When run for the first time a message will show:
'Allow sample to find, connect to and determine the relative position of nearby devices? Allow/Don't allow'

After pressing 'Allow' the exception is generated in the debugger.

@dariuszseweryn
Copy link
Owner

There should be no more access to the device name in the code of ScanActivity. Are you able to pinpoint the place / stacktrace of the exception?

I would do it myself but I don't have access to Android 12 phone

@pascalpm
Copy link
Author

pascalpm commented Jul 1, 2022

Thanks for following this through.
As far as I can see the exception is created after executing 'resultAdapter.setOnAdapterItemClickListener(.....' in configureResultList(){...} (ScanPermission.java).

@pascalpm
Copy link
Author

pascalpm commented Jul 1, 2022

I am happy to give you remote access to my PC if you want. If so please send me an email (pascalmater@gmail.com).

@dariuszseweryn
Copy link
Owner

I think I might have found the problem. Could you pull fix/sample_scan_device_name branch again and re-check?
Thank you for proposing — I hope not to have to take it :)

@pascalpm
Copy link
Author

pascalpm commented Jul 2, 2022

Yes, you did. Thank you very much! Should I close this issue or do you want to add some additional comment?
Again thanks for your help. I can finish my project now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug that is caused by the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants