从客户端应用程序调用时,在 Android 11 远程绑定服务绑定失败 [英] On Android 11 Remote Bound Service binding fails when invoked from Client app

查看:138
本文介绍了从客户端应用程序调用时,在 Android 11 远程绑定服务绑定失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

On Android 11 Remote bound Service binding fails when invoked from Client app

问题仅针对 Android 11.

Problem is specific to Android 11 only.

1: 使用带有 AIDL 接口的远程绑定服务.该服务派生自服务B,同样使用AIDL接口.

1: Using remote bound service with AIDL interface. This service is derived from service B, which is also using AIDL interface.

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. 以下是定义服务的服务器应用程序清单:

2. Below is the Manifest of server application defining the service:

    <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"如下:

3.1 From a client app, Service 'IPCEnterpriseServicePcsc' is invoked as below:

Intent intent = new Intent("com.baimobile.android.enterprise.credential.service.ipc.action.BIND_LICENSE");intent.setPackage(com.baimobile.android.enterprise.credential.service");intent.putExtra("Interface","IRemotePcscServiceLicense");

Intent intent = new Intent("com.baimobile.android.enterprise.credential.service.ipc.action.BIND_LICENSE"); intent.setPackage("com.baimobile.android.enterprise.credential.service"); intent.putExtra("Interface","IRemotePcscServiceLicense");

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

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

3.2: connectionToPcscInterface 定义为:

3.2: connectionToPcscInterface is defined as:

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

3.3: With successful appContext.bindService()in step 3.1, onServiceConnected() mentoned in Step 3.2 is invoked by service. Here we are doing some validation and then binding to base class service 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 下的绑定失败.

Problem Statement: Till Android 10, client application is able to connect with these services very well however on Android 11, binding under Step 3.3 fails.

知道可能是什么问题并寻找解决问题的建议.Android 11 上的某些东西似乎已损坏或加固.

Any idea what could be the problem and looking for suggestions to troubleshoot it. Seems something broken or hardened on Android 11.

推荐答案

如果您还没有这样做,您的客户端应用程序需要 清单中的 元素 用于标识服务应用.

If you have not done so already, your client app needs a <queries> element in the manifest to identify the service app.

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

<?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>

那个 <queries> 元素标识了 一个单独的应用,它有一个客户端应用绑定到的绑定服务.

That <queries> element identifies the package of a separate app that has a bound service that the client app binds to.

这篇关于从客户端应用程序调用时,在 Android 11 远程绑定服务绑定失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆