com.google.android.vending.licensing.Policy Java Examples

The following examples show how to use com.google.android.vending.licensing.Policy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerManagedPolicyTest.java    From play-licensing with Apache License 2.0 6 votes vote down vote up
/**
 * Verify that LU extra is parsed on NOT_LICENSED responses.
 */
@Test
public void licensingUrlExtraParsed() {
    String sampleResponse = "0|1579380448|com.example.android.market.licensing|1|" +
        "ADf8I4ajjgc1P5ZI1S1DN/YIPIUNPECLrg==|1279578835423:" +
        "LU=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcom.example.android.market.licensing";
    // Sanity test
    p.processServerResponse(Policy.LICENSED,
        ResponseData.parse(sampleResponse));
    assertNull(p.getLicensingUrl());

    // Actual test
    p.processServerResponse(Policy.NOT_LICENSED, ResponseData.parse(sampleResponse));
    assertEquals(
        "https://play.google.com/store/apps/details?id=com.example.android.market.licensing",
        p.getLicensingUrl());
}
 
Example #2
Source File: MainActivity.java    From play-licensing with Apache License 2.0 6 votes vote down vote up
public void dontAllow(int policyReason) {
    if (isFinishing()) {
        // Don't update UI if Activity is finishing.
        return;
    }
    displayResult(getString(R.string.dont_allow));
    // Should not allow access. In most cases, the app should assume
    // the user has access unless it encounters this. If it does,
    // the app should inform the user of their unlicensed ways
    // and then either shut down the app or limit the user to a
    // restricted set of features.
    // In this example, we show a dialog that takes the user to a deep
    // link returned by the license checker.
    // If the reason for the lack of license is that the service is
    // unavailable or there is another problem, we display a
    // retry button on the dialog and a different message.
    displayDialog(policyReason == Policy.RETRY);
}
 
Example #3
Source File: ServerManagedPolicyTest.java    From play-licensing with Apache License 2.0 6 votes vote down vote up
/**
 * Verify that retry counts are cleared after getting a NOT_LICENSED response.
 */
@Test
public void retryCountsCleared() {
    String sampleResponse = "0|1579380448|com.example.android.market.licensing|1|" +
            "ADf8I4ajjgc1P5ZI1S1DN/YIPIUNPECLrg==|1279578835423:VT=1&GT=2&GR=3";
    // Sanity test
    p.processServerResponse(Policy.LICENSED,
            ResponseData.parse(sampleResponse));
    assertTrue(0l != p.getValidityTimestamp());
    assertTrue(0l != p.getRetryUntil());
    assertTrue(0l != p.getMaxRetries());

    // Actual test
    p.processServerResponse(Policy.NOT_LICENSED, null);
    assertEquals(0l, p.getValidityTimestamp());
    assertEquals(0l, p.getRetryUntil());
    assertEquals(0l, p.getMaxRetries());
}
 
Example #4
Source File: APKExpansionPolicyTest.java    From play-licensing with Apache License 2.0 6 votes vote down vote up
/**
 * Verify that retry counts are cleared after getting a NOT_LICENSED response.
 */
@Test
public void retryCountsCleared() {
    String sampleResponse = "0|1579380448|com.example.android.market.licensing|1|" +
            "ADf8I4ajjgc1P5ZI1S1DN/YIPIUNPECLrg==|1279578835423:VT=1&GT=2&GR=3";
    p.processServerResponse(Policy.LICENSED,
            ResponseData.parse(sampleResponse));
    // Sanity test
    assertTrue(0L != p.getValidityTimestamp());
    assertTrue(0L != p.getRetryUntil());
    assertTrue(0L != p.getMaxRetries());

    // Actual test
    p.processServerResponse(Policy.NOT_LICENSED, ResponseData.parse(sampleResponse));
    assertEquals(0L, p.getValidityTimestamp());
    assertEquals(0L, p.getRetryUntil());
    assertEquals(0L, p.getMaxRetries());
}
 
Example #5
Source File: APKExpansionPolicyTest.java    From play-licensing with Apache License 2.0 5 votes vote down vote up
@Test
public void noFailureOnAdditionalEncodedExtras() {
    String sampleResponse = "0|1579380448|com.example.android.market.licensing|1|" +
            "ADf8I4ajjgc1P5ZI1S1DN/YIPIUNPECLrg==|1279578835423:VT=1&test=hello%20world%20%26" +
            "%20friends&GT=2&GR=3";
    p.processServerResponse(Policy.LICENSED,
            ResponseData.parse(sampleResponse));
    assertEquals(1L, p.getValidityTimestamp());
    assertEquals(2L, p.getRetryUntil());
    assertEquals(3L, p.getMaxRetries());
}
 
Example #6
Source File: ServerManagedPolicyTest.java    From play-licensing with Apache License 2.0 5 votes vote down vote up
@Test
public void noFailureOnAdditionalEncodedExtras() {
    String sampleResponse = "0|1579380448|com.example.android.market.licensing|1|" +
            "ADf8I4ajjgc1P5ZI1S1DN/YIPIUNPECLrg==|1279578835423:VT=1&test=hello%20world%20%26" +
            "%20friends&GT=2&GR=3";
    p.processServerResponse(Policy.LICENSED,
            ResponseData.parse(sampleResponse));
    assertEquals(1l, p.getValidityTimestamp());
    assertEquals(2l, p.getRetryUntil());
    assertEquals(3l, p.getMaxRetries());
}
 
Example #7
Source File: ServerManagedPolicyTest.java    From play-licensing with Apache License 2.0 5 votes vote down vote up
/**
 * Verify that extra data is parsed correctly on a LICENSED response.
 */
@Test
public void extraDataParsed() {

    String sampleResponse = "0|1579380448|com.example.android.market.licensing|1|" +
            "ADf8I4ajjgc1P5ZI1S1DN/YIPIUNPECLrg==|1279578835423:VT=11&GT=22&GR=33";
    p.processServerResponse(Policy.LICENSED,
            ResponseData.parse(sampleResponse));
    assertEquals(11l, p.getValidityTimestamp());
    assertEquals(22l, p.getRetryUntil());
    assertEquals(33l, p.getMaxRetries());
}
 
Example #8
Source File: StrictPolicyTest.java    From play-licensing with Apache License 2.0 5 votes vote down vote up
/**
 * Verify that after receiving a RETRY response, the policy denies
 * access.
 */
@Test
public void retryResponse() {
    StrictPolicy p = new StrictPolicy();
    p.processServerResponse(Policy.RETRY, null);
    boolean result = p.allowAccess();
    assertFalse(result);
}
 
Example #9
Source File: StrictPolicyTest.java    From play-licensing with Apache License 2.0 5 votes vote down vote up
/**
 * Verify that after receiving a NOT_LICENSED response, the policy denies
 * access and extracts the licensing URL from the response.
 */
@Test
public void notLicensedResponse() {
    StrictPolicy p = new StrictPolicy();

    String sampleResponse = "0|1579380448|com.example.android.market.licensing|1|" +
        "ADf8I4ajjgc1P5ZI1S1DN/YIPIUNPECLrg==|1279578835423:" +
        "LU=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcom.example.android.market.licensing";
    p.processServerResponse(Policy.NOT_LICENSED, ResponseData.parse(sampleResponse));
    boolean result = p.allowAccess();
    assertFalse(result);
    assertEquals(
        "https://play.google.com/store/apps/details?id=com.example.android.market.licensing",
        p.getLicensingUrl());
}
 
Example #10
Source File: StrictPolicyTest.java    From play-licensing with Apache License 2.0 5 votes vote down vote up
/**
 * Verify that after receiving a LICENSED response, the policy grants
 * access.
 */
@Test
public void licensedResponse()  {
    StrictPolicy p = new StrictPolicy();
    p.processServerResponse(Policy.LICENSED, null);
    boolean result = p.allowAccess();
    assertTrue(result);
}
 
Example #11
Source File: MainActivity.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
private void checkLicense() {
    mHandler = new Handler();
    Policy policy = PolicyFactory.createPolicy(this, getPackageName());
    mChecker = new LicenseChecker(this, policy, Key.BASE_64_PUBLIC_KEY);
    mCallBack = new CheckLicenseCallBack();
    mChecker.checkAccess(mCallBack);
}
 
Example #12
Source File: APKExpansionPolicyTest.java    From play-licensing with Apache License 2.0 5 votes vote down vote up
/**
 * Verify that LU extra is parsed on NOT_LICENSED responses.
 */
@Test
public void licensingUrlExtraParsed() {
    String sampleResponse = "0|1579380448|com.example.android.market.licensing|1|" +
        "ADf8I4ajjgc1P5ZI1S1DN/YIPIUNPECLrg==|1279578835423:" +
        "LU=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcom.example.android.market.licensing";
    // Sanity test
    p.processServerResponse(Policy.LICENSED, ResponseData.parse(sampleResponse));
    assertNull(p.getLicensingUrl());

    // Actual test
    p.processServerResponse(Policy.NOT_LICENSED, ResponseData.parse(sampleResponse));
    assertEquals("https://play.google.com/store/apps/details?id=com.example.android.market.licensing",
        p.getLicensingUrl());
}
 
Example #13
Source File: APKExpansionPolicyTest.java    From play-licensing with Apache License 2.0 5 votes vote down vote up
/**
 * Verify that extra data is parsed correctly on a LICENSED resopnse..
 */
@Test
public void extraDataParsed() {
    // This is a sample server response from Google Play for an application that has both
    // a main and a patch APK Expansion file.  The response includes the URLs used to
    // download the files from Google Play, the names of the files to save, and the
    // sizes of each file.  In addition, this response also contains licensing data, including
    // information about the server-managed policy.
    String sampleResponse = "0|1579380448|com.example.android.market.licensing|1|" +
            "ADf8I4ajjgc1P5ZI1S1DN/YIPIUNPECLrg==|1279578835423:VT=11&GT=22&GR=33" +
            "&FILE_URL1=http://jmt17.google.com/vending_kila/download/AppDownload?packageName%3Dcom.example.android.market.licensing%26versionCode%3D3%26ft%3Do%26token%3DAOTCm0RwlzqFYylBNSCTLJApGH0cYtm9g8mGMdUhKLSLJW4v9VM8GLj4GVlGU5oyW6y3FsXrJiQqMunTGw9B" +
            "&FILE_NAME1=main.3.com.example.android.market.licensing.obb&FILE_SIZE1=687801613" +
            "&FILE_URL2=http://jmt17.google.com/vending_kila/download/AppDownload?packageName%3Dcom.example.android.market.licensing%26versionCode%3D3%26ft%3Do%26token%3DAOTCm0RwlzqFYylBNSCTLJApGH0cYtm9g8mGMdUhKLSLJW4v9VM8GLsdSDjefsdfEKdVaseEsfaMeifTek9B" +
            "&FILE_NAME2=patch.3.com.example.android.market.licensing.obb&FILE_SIZE2=204233";
    p.processServerResponse(Policy.LICENSED,
            ResponseData.parse(sampleResponse));
    assertEquals(11L, p.getValidityTimestamp());
    assertEquals(22L, p.getRetryUntil());
    assertEquals(33L, p.getMaxRetries());
    assertEquals(2, p.getExpansionURLCount());
    assertEquals("main.3.com.example.android.market.licensing.obb",p.getExpansionFileName(0));
    assertEquals(687801613L,p.getExpansionFileSize(0));
    assertEquals("http://jmt17.google.com/vending_kila/download/AppDownload?packageName=com.example.android.market.licensing&versionCode=3&ft=o&token=AOTCm0RwlzqFYylBNSCTLJApGH0cYtm9g8mGMdUhKLSLJW4v9VM8GLj4GVlGU5oyW6y3FsXrJiQqMunTGw9B",
            p.getExpansionURL(0));
    assertEquals("patch.3.com.example.android.market.licensing.obb",p.getExpansionFileName(1));
    assertEquals(204233,p.getExpansionFileSize(1));
    assertEquals("http://jmt17.google.com/vending_kila/download/AppDownload?packageName=com.example.android.market.licensing&versionCode=3&ft=o&token=AOTCm0RwlzqFYylBNSCTLJApGH0cYtm9g8mGMdUhKLSLJW4v9VM8GLsdSDjefsdfEKdVaseEsfaMeifTek9B",
            p.getExpansionURL(1));
}
 
Example #14
Source File: PolicyFactory.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
public static Policy createPolicy(@NonNull Context context, @NonNull String packageName) {
    String deviceID = Installation.id(context);
    return new ServerManagedPolicy(context, new AESObfuscator(Key.SALT, packageName, deviceID));
}
 
Example #15
Source File: MainActivity.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void dontAllow(int reason) {
    if (isFinishing()) {
        return;
    }
    if (reason == Policy.NOT_LICENSED) {
        handleCracked();
    }
}
 
Example #16
Source File: APKExpansionPolicyTest.java    From play-licensing with Apache License 2.0 4 votes vote down vote up
/**
 * Verify that the policy can process null server responses.
 */
@Test
public void noFailureOnNullResponseData() {
    p.processServerResponse(Policy.RETRY, null);
    assertFalse(p.allowAccess());
}
 
Example #17
Source File: ServerManagedPolicyTest.java    From play-licensing with Apache License 2.0 4 votes vote down vote up
/**
 * Verify that the policy can process null server responses.
 */
@Test
public void noFailureOnNullResponseData() {
    p.processServerResponse(Policy.RETRY, null);
    assertFalse(p.allowAccess());
}