从另一个上下文信息传递给HostApduService [英] Passing information to a HostApduService from another Context

查看:909
本文介绍了从另一个上下文信息传递给HostApduService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这已经问过,没有反应,所以我会尽量表达出该问题有点不同。什么是各种方式的一些数据传递到一个Android 服务,而不能对自己绑定到它或启动它?

This has been asked before with no responses, so I will try to phrase the question a bit differently. What are the various ways to pass some data to an Android Service without being able to bind to it or start it myself?

这里的问题 - 我有一个 HostApduService 是由每一个NFC卡交易操作系统启动的。它需要的权限 android.permission.BIND_NFC_SERVICE ,这是一个系统的权限,所以我的应用程序不能绑定到它。我不想在休息留下的数据,以便被写入到磁盘的任何事情都是一个不走。我想到了几个可能的解决方案,但他们要么是混乱的或不安全的:

Here's the issue - I have a HostApduService that is started by the operating system on every NFC card transaction. It requires the permission android.permission.BIND_NFC_SERVICE, which is a system permission, so my application can't bind to it. I don't want to leave data at rest so anything that gets written to the disk is a no-go. I thought of a few possible solutions, but they are either messy or insecure:

  1. 将数据放在我们的应用程序的共享preferences。这presents一个DAR问题。
  2. 广播信息到服务。该 HostApduService 运行的卡交易的持续时间,所以我不能可靠地时间就开始工作前广播到达的服务。
  3. 把我想通过在成静态域中存在的信息。这是混乱的,可能会导致并发问题,但是是我目前使用的。
  1. Put the data in our app's SharedPreferences. This presents a DAR issue.
  2. Broadcast information to the Service. The HostApduService runs for the duration of the card transaction, so I can't reliably time the broadcast to reach the service before it starts working.
  3. Put the information I want to pass in into a static field somewhere. This is messy and could potentially cause concurrency issues, but is what I'm currently using.

任何其他的想法?先谢谢了。

Any other ideas? Thanks in advance.

推荐答案

我认为这个问题可以归结为一个问题:

I think this question comes down to another question:

你将如何存储在一个绑定服务(持久)数据?

How would you store (persistent) data within a bound service?

该HCE服务是绑定的服务,因此,它只能保证运行,而其调用上下文存在(见<一href="http://developer.android.com/reference/android/content/Context.html#bindService%28android.content.Intent,%20android.content.ServiceConnection,%20int%29"相对=nofollow>这里)。其结果是,不管数据您服务内储存(&RIGHTARROW;存在于RAM变量)将只为服务的生命周期已经存在,将不再可用的服务重新启动之后

The HCE service is a bound service, thus it is only guaranteed to run while its calling context exists (see here). As a result, whatever data you store within the service (→ variables that exist in RAM) will only exist for the lifetime of the service and will no longer be available after the service is restarted.

因此​​,在服务中绑定到服务,并设置一些值将不能可靠地工作,即使你可以绑定到HCE服务。同样的问题也适用于您的广播服务数据。

Consequently, binding to the service and setting some values within the service would not reliably work, even if you could bind to the HCE service. The same issue applies to data that you broadcast to the service.

有一个类似的问题存在着在静态字段中存储的值。只要这些领域只存在他们的声明范围内的虚拟机的内存加载(声明它们在IE浏览器类)。由于虚拟机可以在任何时候被杀死在不使用的服务和应用程序的任何活动将显示在前台,你不能确定你把静态字段的数据生存,你需要它的整个期间。

A similar problem exists with storing values in static fields. Those fields only exist as long as their declaring context (i.e. the class they are declared in) is loaded in the virtual machine's memory. As the VM can be killed at any time when the service is not used and no activity of the app is displayed in the foreground, you can't be sure that data you put into static fields survives the whole duration that you need it.

所以,唯一的可靠的方法来存储数据是使用持久性存储技术,这是要么使用共享preferences机制,使用内容提供者(这是支持由数据库关于持久性存储器),或直接将数据存储到文件中。我想你可以做的最好的是存储加密的文件系统上的数据。然而,这种为您带来另一个问题:如何(安全)存储加密密钥。但是,您可能能够使用Android密钥库(看到adeqately解决ISSE的这里和的这里)。

So the only reliable method to store your data is to use persistent storage technology, which is to either use the SharedPreferences mechanism, to use a content provider (that's backed by a database on persistent storage) or to directly store data to files. I guess the best you could do is to store the data on the files system encrypted. However, this brings you to another issue: How to (securely) store the encryption key. But you might be able to adeqately solve that isse using the Android key store (see here and here).

这篇关于从另一个上下文信息传递给HostApduService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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