LVL类及接口使用介绍(License Verification Library )

原文:http://android.eoe.cn/topic/android_sdk

LVL Classes and Interfaces-LVL类和接口

Table 1 lists all of the source files in the License Verification Library (LVL) available through the Android SDK. All of the files are part of the com.android.vending.licensing package.

表一列出了通过AndroidSDK可以获得的许可认证库(LVL)的源代码文件。这些文件都是com.android.vending.licensing这包的一部分。
Table 1. Summary of LVL library classes and interfaces.

表一:LVL库的类文件和接口

<!-- 表格开始 -->
{|style="border-spacing: 0px;margin: 4px 4px; 90%; border-left:1px solid #ccc;border-top:1px solid #ccc; "

<!-- 这段是表头 -->
|-style="background:#DEE8F1; "
! style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px" | Category目录
! style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px" | Name名字
! style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px" | Description描述

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:0px solid #ccc; padding:5px 15px; " |
License check and result许可查看和结果
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
LicenseChecker
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Class that you instantiate (or subclass) to initiate a license check.一个您实例化或者子类话的类,这个类用来开始一个许可检查。

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
LicenseCheckerCallback
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Interface that you implement to handle result of the license check.您可以通过实现这个接口来处理许可检查的结果。

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:0px solid #ccc; padding:5px 15px; " |
Policy策略
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Policy
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Interface that you implement to determine whether to allow access to the application, based on the license response.通过实现这个接口您可以决定是否允许通过许可反馈来访问应用

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:0px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
ServerManagedPolicy
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Default Policy implementation. Uses settings provided by the licensing server to manage local storage of license data, license validity, retry.默认的Policy接口。使用许可服务器提供的设置来管理本地的存储数据,许可合法性和尝试。

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
StrictPolicy
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Alternative Policy implementation. Enforces licensing based on a direct license response from the server only. No caching or request retry.本地Policy接口。强制许可基于来自服务器的直接的许可响应。不缓存也不请求重试。

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:0px solid #ccc; padding:5px 15px; " |
Data obfuscation(optional)

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Obfuscator
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Interface that you implement if you are using a Policy (such as ServerManagedPolicy) that caches license response data in a persistent store. Applies an obfuscation algorithm to encode and decode data being written or read.
如果您使用Policy(比ServerManagedPolicy),您将继承这个接口。这个接口把许可响应数据缓存在一个持久存储区里。在被读写的时候,它使用模糊算法来编码和解码。

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
AESObfuscator
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Default Obfuscator implementation that uses AES encryption/decryption algorithm to obfuscate/unobfuscate data.使用AES加密/解密算法来混淆/反混淆数据的默认算法接口。

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:0px solid #ccc; padding:5px 15px; " |
Device limitation(optional)

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
DeviceLimiter

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Interface that you implement if you want to restrict use of an application to a specific device.
实现这个接口,您可以限制应用在特定设备上的使用。Called from LicenseValidator. 调用来自LicenseValidator。
Implementing DeviceLimiter is not recommended for most applications because it requires a backend server and may cause the user to lose access to licensed applications, unless designed with care.
对于大多数应用,我们不推荐继承DeviceLimiter接口,它他需要一个后台服务器并且它可能导致用户和许可的应用失去联系,除非在设计的时候认真的考虑了。

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
NullDeviceLimiter
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Default DeviceLimiter implementation that is a no-op (allows access to all devices).默认的DeviceLimiter接口,这个接口允许访问任何设备。

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:0px solid #ccc; padding:5px 15px; " |
Library core, no integration needed

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
ResponseData

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Class that holds the fields of a license response.这个类控制一个许可响应的区域

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:0px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
LicenseValidator

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Class that decrypts and verifies a response received from the licensing server.这个类用来解密并验证从许可服务器发来的响应

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:0px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
ValidationException
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Class that indicates errors that occur when validating the integrity of data managed by an Obfuscator.这个类指出在验证Obfuscator管理的数据的完整性时出现的错误

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:0px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
PreferenceObfuscator

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Utility class that writes/reads obfuscated data to the system's SharedPreferences store.这个工具类用于读写混淆数据存储到系统的Sharedpreferences

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:0px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
ILicensingService

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
One-way IPC interface over which a license check request is passed to the Google Play client.单向的进程间通讯接口,这个接口的许可检查请求来自google play客户端

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
ILicenseResultListener

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
One-way IPC callback implementation over which the application receives an asynchronous response from the licensing server.单向进程间通讯调用的实现,这个实现基于应用收到的来自许可服务器的异步响应

|}
<!-- 表格结束 -->

Server Response Codes-服务器返回码

Table 2 lists all of the license response codes supported by the licensing server. In general, an application should handle all of these response codes. By default, the LicenseValidator class in the LVL provides all of the necessary handling of these response codes for you.

表二列出了许可服务器所支持的所有许可返回码. 一般的,一个应用应该处理所有的这些返回码.默认的, LVL中的LicenseValidator(许可校验码)类提供所有需要处理的响应代码

Table 2. Summary of response codes returned by the Google Play server in a license response.

表二 google play商店服务器以许可响应的形式返回的响应代码

<!-- 表格开始 -->
{|style="border-spacing: 0px;margin: 4px 4px; 90%; border-left:1px solid #ccc;border-top:1px solid #ccc; "

<!-- 这段是表头 -->
|-style="background:#DEE8F1; "
! style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px" | Response Code返回码
! style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px" | Description描述
! style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px" | Signed? 是否签名?
! style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px" | Extras 值
! style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px" | Comments 评价

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
LICENSED
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
The application is licensed to the user. The user has purchased the application or the application only exists as a draft.
这个应用被授权给这个用户,这个用户购买了这个应用,或者这个应用仅仅是一个草稿版本(已经上传,但是没有发布).
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Yes是
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
VT, GT,GR
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Allow access according to Policy constraints经过Policy验证后运行使用应用

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
LICENSED_OLD_KEY
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
The application is licensed to the user, but there is an updated application version available that is signed with a different key.
这个应用被授权给这个用户,这个应用有升级版,但是升级版的签名和当前的应用不同
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Yes是
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
VT, GT,GR, UT
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Optionally allow access according to Policyconstraints.
Can indicate that the key pair used by the installed application version is invalid or compromised. The application can allow access if needed or inform the user that an upgrade is available and limit further use until upgrade.
有选择性的允许使用应用.可以表明已安装的应用所使用的密钥不存在或者已经被损坏.如果需要应用可以被允许使用或者通知用户需要进行升级才能使用

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
NOT_LICENSED
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
The application is not licensed to the user.
这个应用没有授权给这个用户
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
No
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Do not allow access.不允许使用该应用

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
ERROR_CONTACTING_SERVER
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
The application is not licensed to the user.
Local error — the Google Play application was not able to reach the licensing server, possibly because of network availability problems.
本地错误—google play 应用不能连接到许可服务器,可能是因为网络连接问题
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
No
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
according toPolicy retry limits.试用次数取决于Policy

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
ERROR_SERVER_FAILURE
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Server error — the server could not load the publisher account's key pair for licensing.
服务器错误—服务器不能获取发布者的密钥来进行许可操作
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
No
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Retry the license check according toPolicy retry limits.根据Policy的使用次数重新进行许可检查

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
ERROR_INVALID_PACKAGE_NAME
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Local error — the application requested a license check for a package that is not installed on the device.
本地错误,这个应用需要一个许可证来对包进行许可检查,但是这个许可证没有安装在设备上
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
No
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Retry the license check according toPolicy retry limits.根据Policy的使用次数重新进行许可检查
Do not retry the license check.Typically caused by a development error.不要进行许可坚持,一般是由于应用开发错误.

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
ERROR_NON_MATCHING_UID
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Local error — the application requested a license check for a package whose UID (package, user ID pair) does not match that of the requesting application.
本地错误---这个应用需要一个许可证来对安装包进行检查,但是这个许可证的UID(包,用户ID)和当前的请求应用不相吻合.
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
No
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Do not retry the license check.Typically caused by a development error. 不要进行许可检查,一般是由于应用开发错误

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
ERROR_NOT_MARKET_MANAGED
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Server error — the application (package name) was not recognized by Google Play.
服务器错误 应用(包名)没有被google play识别.
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
No
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Do not retry the license check.
Can indicate that the application was not published through Google Play or that there is an development error in the licensing implementation.
不要进行许可检查,可以表明应用没有在google play上发布或者在开发中许可实现的时候存在错误
|}
<!-- 表格结束 -->

Note: As documented in Setting Up The Testing Environment, the response code can be manually overridden for the application developer and any registered test users via the Google Play publisher site.

注意:就像在设置测试环境一张描述的那样,相应码可以手动被google play的注册开发者或者测试者重写.

Additionally, as noted above, applications that are in draft mode (in other words, applications that have been uploaded but have never been published) will return LICENSED for all users, even if not listed as a test user. Since the application has never been offered for download, it is assumed that any users running it must have obtained it from an authorized channel for testing purposes.

除此之外,如上所述,在”草稿”状态的应用(这个应用已经上传,但是从未发布)将会返回LICENSED 给所有的用户,即使这些用户不是列出的测试用户.由于这个应用从来没有提供下载,所以这个应用被视为从一个授权渠道拿来做测试之用的

Server Response Extras-服务器返回值

To assist your application in managing access to the application across the application refund period and provide other information, The licensing server includes several pieces of information in the license responses. Specifically, the service provides recommended values for the application's license validity period, retry grace period, maximum allowable retry count, and other settings. If your application uses APK expansion files, the response also includes the file names, sizes, and URLs. The server appends the settings as key-value pairs in the license response "extras" field.
为了帮助您的应用管理用户在退款期间的使用并提供其他信息,许可服务器包含了几组许可返回信息.具体来说,服务器提供应用许可证有效期期间的建议值,重试宽限期,允许的最大重试次数,以及其他设置。如果您的应用使用了apk’扩充文件,那返回值也包括文件名,文件大小,URL等.服务器在许可响应的”额外”领域作为键值对追加设置项.

Any Policy implementation can extract the extras settings from the license response and use them as needed.

任何Policy类的继承可以从许可返回信息中提取设置的值,在需要的时候使用他们.

The LVL default Policy implementation, ServerManagedPolicy, serves as a working implementation and an illustration of how to obtain, store, and use the settings.

LVL的默认Policy类默认继承 ServerManagedPolicy,实现功能,说明怎么获取,存储,使用这些设置.

Table 3. Summary of license-management settings supplied by the Google Play server in a license response.

表3 google play服务器以一个许可响应的形式提供的许可管理设置

<!-- 表格开始 -->
{|style="border-spacing: 0px;margin: 4px 4px; 90%; border-left:1px solid #ccc;border-top:1px solid #ccc; "

<!-- 这段是表头 -->
|-style="background:#DEE8F1; "
! style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px" | Extra
! style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px" | Description

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
VT
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
License validity timestamp. Specifies the date/time at which the current (cached) license response expires and must be rechecked on the licensing server. See the section below about License validity period.
许可有效期时间戳.指定了当前(或是缓存的)许可响应已经过期,必须去许可服务器上复查. 有关许可证有效期,请参阅下文

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
GT
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Grace period timestamp. Specifies the end of the period during which a Policy may allow access to the application, even though the response status is RETRY.宽限期的时间戳.指定在许可响应信号是RETRY的时候允许应用使用的最后日期.
The value is managed by the server, however a typical value would be 5 or more days. See the section below about Retry period and maximum retry count.这个值是由服务器管理的,一般这个值是5天或者更多.参阅下面的使用期限和最大使用次数

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
GR
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Maximum retries count. Specifies how many consecutive RETRY license checks the Policyshould allow, before denying the user access to the application.

最大使用次数,指定在禁止用户使用应用前,Policy可以允许多少次连续的RETRY许可检查信号.

The value is managed by the server, however a typical value would be "10" or higher. See the section below about Retry period and maximum retry count.

这个值也是由服务器管理,一般是”10”或者更大,参阅下面的使用期限和最大使用次数

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
UT
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
Update timestamp. Specifies the day/time when the most recent update to this application was uploaded and published.更新时间戳.指定应用新版本上传或发布的日期和时间.

The server returns this extra only for LICENSED_OLD_KEYS responses, to allow the Policyto determine how much time has elapsed since an update was published with new licensing keys before denying the user access to the application.服务器只返回LICENSED_OLD_KEYS的响应来允许Policy决定一个含有新的许可信息的更新版本发布后还有多少时间来禁止用户使用旧版本

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
FILE_URL1orFILE_URL2
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
The URL for an expansion file (1 is for the main file, 2 is the patch file). Use this to download the file over HTTP.扩展文件的URL(1代表主文件,2是补丁文件).使用这个URL来从HTTP上下载文件.

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
FILE_NAME1orFILE_NAME2
| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
The expansion file's name (1 is for the main file, 2 is the patch file). You must use this name when saving the file on the device.
扩展文件的名字(1是主文件,2是补丁文件).在设备上保存这个文件时,您必须使用这个名字

<!-- 这段是表格 -->
|- style=" vertical-align:top;"
| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
FILE_SIZE1orFILE_SIZE2

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |
The size of the file in bytes (1 is for the main file, 2 is the patch file). Use this to assist with downloading and to ensure that enough space is available on the device's shared storage location before downloading.
文件的大小,以字节为单位(1是主文件,2是补丁文件).使用他来辅助下载并在下载前确保设备的存储空间足够.
|}
<!-- 表格结束 -->

License validity period-许可有效阶段

The Google Play licensing server sets a license validity period for all downloaded applications.

Google play许可服务器对所有的下载了的应用设置了一个有效期.

The period expresses the interval of time over which an application's license status should be considered as unchanging and cacheable by a licensing Policy in the application.

这个阶段在表述时,一个应用许可状态的时间间隔应该作为没有在变化和可以通过应用中的Policy许可证被缓存来考虑.

The licensing server includes the validity period in its response to all license checks, appending an end-of-validity timestamp to the response as an extra under the key VT.

许可服务器在他的对所有许可检查响应中包含了有效期,这个操作通过在响应中追加有效期结束时间戳作为VT键下额外的数值来实现的.

A Policy can extract the VT key value and use it to conditionally allow access to the application without rechecking the license, until the validity period expires.

一个Policy可以把VT的键提取出来然后使用它来在不重新检查许可证的情况下使用应用,直到有效时间结束.

The license validity signals to a licensing Policy when it must recheck the licensing status with the licensing server.

当一个许可证必须使用许可服务器重新检查许可状态的时候, 许可证向一个许可Policy发一个有效性信号

It is not intended to imply whether an application is actually licensed for use.

他不是想要去暗示这个应用是否被许可可以使用.

That is, when an application's license validity period expires, this does not mean that the application is no longer licensed for use — rather, it indicates only that the Policy must recheck the licensing status with the server.

而是,当一个应用的许可过期了,这不意味着这个应用再也不能被许可使用了—而是,他暗示只有Policy必须重新使用服务器检查许可状态.

It follows that, as long as the license validity period has not expired, it is acceptable for the Policy to cache the initial license status locally and return the cached license status instead of sending a new license check to the server.

只要许可有效期没有过期,他就可以被Policy接受并缓存最初的还没有过期的许可状态到本地,然后返回缓存的许可状态而不是向服务器发送一个新的许可检查.

The licensing server manages the validity period as a means of helping the application properly enforce licensing across the refund period offered by Google Play for paid applications. It sets the validity period based on whether the application was purchased and, if so, how long ago. Specifically, the server sets a validity period as follows:

作为一种辅助在google play上的付费应用恰当的强制许可的方式,许可服务器会管理该应用的许可有效时间.他判断是否这个应用是付费的,如果是,允许使用多长时间 , 通过这个来设置许可的有效时间.具体来说,服务器设置有效期的方法如下:

• For a paid application, the server sets the initial license validity period so that the license response remains valid for as long as the application is refundable. A licensing Policy in the application may cache the result of the initial license check and does not need to recheck the license until the validity period has expired.

• 对于一个付费的应用,服务器通过设置最初的许可有效期来使许可响应保持有效.只要应用在退还期.一个在应用中的许可Policy可能缓存最初许可证的检查结果,而不需要重新检查许可直到有效期结束.

• When an application is no longer refundable, the server sets a longer validity period — typically a number of days.

• 当一个应用不再可以退还,服务器会设置一个比较长的有效期,通常是很多天.

• For a free application, the server sets the validity period to a very high value (long.MAX_VALUE). This ensures that, provided the Policy has cached the validity timestamp locally, it will not need to recheck the license status of the application in the future.

• 对于一个免费的应用,服务器设置有效期为一个非常大的数值(long.MAX_VALUE).这样可以确保Policy已经在本地缓存了一个有效的时间戳,他在将来不需要重新检查许可状态.

The ServerManagedPolicy implementation uses the extracted timestamp (mValidityTimestamp) as a primary condition for determining whether to recheck the license status with the server before allowing the user access to the application.

ServerManagedPolicy (服务管理策略)的实现使用了提取到的时间戳(mValidityTimestamp)来作为基本的判断是否需要在允许用户使用该应用之前通过服务器重新检查许可状态的条件

Retry period and maximum retry count-试用时间和最大使用次数

In some cases, system or network conditions can prevent an application's license check from reaching the licensing server, or prevent the server's response from reaching the Google Play client application. For example, the user might launch an application when there is no cell network or data connection available—such as when on an airplane—or when the network connection is unstable or the cell signal is weak.

在一些情况下,系统或网络条件可能阻止应用通过许可服务器进行许可检查或者阻止来自google play客户端的服务器响应.例如,用户可能在没有基站网络或者数据连接的环境下启动应用—比如在飞机上—或者,基站信号很弱或者网络部稳定.

When network problems prevent or interrupt a license check, the Google Play client notifies the application by returning a RETRY response code to the Policy's processServerResponse() method. In the case of system problems, such as when the application is unable to bind with Google Play's ILicensingServiceimplementation, the LicenseChecker library itself calls the Policy processServerResonse() method with aRETRY response code.

当网络问题阻止或者中断了许可检查,googleplay客户端会通过返回一个RRTRY响应码给Policy的processServerResponse() 方法来通知应用这个情况.在系统问题情况下,比如当应用不能和google play的 ILicensingService服务绑定, LicenseChecker库会使用RETRY响应码来调用processServerResonse()方法.

In general, the RETRY response code is a signal to the application that an error has occurred that has prevented a license check from completing.

一般的,RETRY响应码一般表明应用存在一个错误导致不能完成许可检查.

The Google Play server helps an application to manage licensing under error conditions by setting a retry "grace period" and a recommended maximum retries count. The server includes these values in all license check responses, appending them as extras under the keys GT and GR.

Google play服务器通过设置一个”宽限期”并设置最多使用次数来帮助应用在存在错误的情况下处理许可.服务器在所有的许可检查响应中包含这些值,他们被作为GT和GR的追加值.

The application Policy can extract the GT and GR extras and use them to conditionally allow access to the application, as follows:

应用的Policy可以提取GT和GR值并使用它们来有条件允许用户使用应用程序:

• For a license check that results in a RETRY response, the Policy should cache the RETRY response code and increment a count of RETRY responses.

• 如果许可检查返回RETRY响应,Policy应该缓存RETRY响应码并记录,并不断增加RETRY的响应次数

• The Policy should allow the user to access the application, provided that either the retry grace period is still active or the maximum retries count has not been reached.
The ServerManagedPolicy uses the server-supplied GT and GR values as described above. The example below shows the conditional handling of the retry responses in the allow() method. The count of RETRY responses is maintained in the processServerResponse() method, not shown.

如果试用的”宽限期”还没到或者最大使用次数还没到,那Policy应该允许用户访问应用. ServerManagedPolicy使用服务器提供的GT和GR值.下面的例子在allow()方法中展示了怎么处理使用时的响应.RETRY的数量在processServerResponse()方法中保存,在这里没有展示.

public boolean allowAccess() {
long ts = System.currentTimeMillis();
if (mLastResponse == LicenseResponse.LICENSED) {
// Check if the LICENSED response occurred within the validity timeout.
if (ts <= mValidityTimestamp) {
// Cached LICENSED response is still valid.
return true;
}
} else if (mLastResponse == LicenseResponse.RETRY &&
ts < mLastResponseTime + MILLIS_PER_MINUTE) {
// Only allow access if we are within the retry period or we haven't used up our
// max retries.
return (ts

原文地址:https://www.cnblogs.com/vus520/p/3152733.html