Skip to content

bindToService fails on newer Android API versions #7

@hannesa2

Description

@hannesa2

In the code block below found in OpenPgpServiceConnection.java, connect = mApplicationContext.bindService(serviceIntent, mServiceConnection, Context.BIND_AUTO_CREATE); returns false to the variable connect. This is apparently a change that was made in Android API 30 according to a post I found here.

public void bindToService() {
        // if not already bound...
        if (mService == null) {
            try {
                Intent serviceIntent = new Intent(OpenPgpApi.SERVICE_INTENT_2);
                // NOTE: setPackage is very important to restrict the intent to this provider only!
                serviceIntent.setPackage(mProviderPackageName);
                boolean connect = mApplicationContext.bindService(serviceIntent, mServiceConnection,
                        Context.BIND_AUTO_CREATE);
                if (!connect) {
                    throw new Exception("bindService() returned false!");
                }
            } catch (Exception e) {
                if (mOnBoundListener != null) {
                    mOnBoundListener.onError(e);
                }
            }
        }

I compiled the code from your PR from 2 years ago and ran it in an emulator with Android 14. I also installed a copy of OpenKeychain in the emulator.

When I include the code in my patch above in AndroidManifest, connect is true and OpenKeychain appears as an option for "Select OpenPGP app!". When it's not there, it`s false and I can't select OpenKeychain.

Originally posted by @brendanpward in #4 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions