I have an Pixel 3a device that I connect to a Linux computer via USB cable (A to C). Sometimes when I plug in the device, the notification on the Pixel 3a says, "Android System - Charging this device via USB". However, the battery icon indicates the phone is not charging (does not show the lightning bolt), and indeed, the charge level does not go up. If I switch the USB connection to MIDI, PTP, USB tethering or file transfer, then the phone starts charging.
How can I get my phone to reliably charge without granting extra data permissions?
As for "sometimes", if the Pixel 3a previously did not charge with no data transfer, then it will continue to not charge with no data transfer in subsequent connections until some data is granted. If the Pixel 3a charged in the last connection, it may or may not charge on the next connection with no data transfer.