在 Android 11 上,从客户端应用程序调用时,远程绑定服务绑定失败

2023-12-12

On 安卓11从客户端应用程序调用时远程绑定服务绑定失败

问题仅针对 Android 11。

1:使用带有 AIDL 接口的远程绑定服务。该服务源自服务B,服务B也使用AIDL接口。

public class IPCEnterpriseServicePcsc extends IPCServicePcsc {
    ...
    protected IPCEnterpriseInterfaceLicense licenseBinder;
    ...
}

public class IPCEnterpriseInterfaceLicense extends IRemotePcscServiceLicense.Stub {...}

public class IPCServicePcsc extends IPCService {
        ...
    protected IPCInterfacePcsc mBinder;
    ...
}

public class IPCInterfacePcsc extends IRemotePcscService.Stub{...}

2.以下是定义服务的服务器应用程序的清单:

    <service android:label="@string/pcsc_service_name" android:name=".IPCEnterpriseServicePcsc" >
        <intent-filter>
            <action android:name="com.baimobile.android.enterprise.credential.service.ipc.action.BIND_PCSC" />
            <action android:name="com.baimobile.android.enterprise.credential.service.ipc.action.BIND_LICENSE" />
            <action android:name="com.baimobile.android.enterprise.credential.service.license.action.VALIDATE_USER_LICENSE_INFO" />
        </intent-filter>
    </service>

server app id is "com.baimobile.android.enterprise.credential.service"

3.1从客户端应用程序中,调用服务“IPCEnterpriseServicePcsc”,如下所示:

Intent意图 = new Intent("com.baimobile.android.enterprise.credential.service.ipc.action.BIND_LICENSE"); Intent.setPackage("com.baimobile.android.enterprise.credential.service"); Intent.putExtra("接口","IRemotePcscServiceLicense");

boolean pcscServiceInstalled = appContext.bindService(intent, connectionToPcscInterface, Context.BIND_AUTO_CREATE);

3.2:连接到Pcsc接口定义为:

private ServiceConnection connectionToPcscInterface = new ServiceConnection() {
    public void onServiceConnected(ComponentName remoteComponent, IBinder binder) {...};
    public void onServiceDisconnected(ComponentName arg0) {..};
}

3.3:步骤 3.1 中的 appContext.bindService() 成功后,服务将调用步骤 3.2 中提到的 onServiceConnected()。这里我们进行一些验证,然后绑定到基类服务 IPCServicePcsc

    Intent intent = new Intent("com.baimobile.android.pcsclite.service.ipc.action.BIND_PCSC");
    intent.setPackage("com.baimobile.android.enterprise.credential.service");
    intent.putExtra("Interface","IRemotePcscService");          // Request the PC/SC interface instead of the license interface.
    pcscServiceInstalled = appContext.bindService(intent, connectionToPcscInterface, Context.BIND_AUTO_CREATE);
    if( ! pcscServiceInstalled ){
        Log.e("TAG","bindService failed.");
    }

问题陈述:在 Android 10 之前,客户端应用程序能够很好地与这些服务连接,但是在 Android 11 上,步骤 3.3 下的绑定失败。

知道可能是什么问题并寻找解决问题的建议。 Android 11 上似乎有些东西被破坏或强化了。


如果您还没有这样做,您的客户端应用程序需要a <queries>清单中的元素识别服务应用程序。

例如,在这个客户端应用程序, 我有:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.commonsware.android.r.embed.client">
  <queries>
    <package android:name="com.commonsware.android.r.embed.server" />
  </queries>

  <application
    android:name=".MainApp"
    android:allowBackup="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
  </application>

</manifest>

That <queries>元素标识包一个单独的应用程序具有客户端应用程序绑定到的绑定服务。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Android 11 上,从客户端应用程序调用时,远程绑定服务绑定失败 的相关文章

随机推荐