Loading vending-app/src/main/java/com/android/vending/licensing/LicenseChecker.java +55 −51 Original line number Diff line number Diff line Loading @@ -79,6 +79,9 @@ public abstract class LicenseChecker<D, R> { static final String AUTH_TOKEN_SCOPE = "oauth2:https://www.googleapis.com/auth/googleplay"; public abstract Request<?> createRequest(String packageName, String auth, int versionCode, D data, BiConsumer<Integer, R> then, Response.ErrorListener errorListener); public void checkLicense(Account account, AccountManager accountManager, String packageName, PackageManager packageManager, RequestQueue queue, D queryData, Loading @@ -95,14 +98,7 @@ public abstract class LicenseChecker<D, R> { onResult.accept(ERROR_NON_MATCHING_UID, null); } else { accountManager.getAuthToken( account, AUTH_TOKEN_SCOPE, false, future -> { try { String auth = future.getResult().getString(KEY_AUTHTOKEN); Request<?> request = createRequest(packageName, auth, versionCode, queryData, (Integer integer, R r) -> { BiConsumer<Integer, R> onRequestFinished = (Integer integer, R r) -> { try { onResult.accept(integer, r); } catch (RemoteException e) { Loading @@ -110,10 +106,20 @@ public abstract class LicenseChecker<D, R> { "After telling it the license check result, remote threw an Exception."); e.printStackTrace(); } }, error -> { }; Response.ErrorListener onRequestError = error -> { Log.e(TAG, "license request failed with " + error.toString()); safeSendResult(onResult, ERROR_CONTACTING_SERVER, null); }); }; accountManager.getAuthToken( account, AUTH_TOKEN_SCOPE, false, future -> { try { String auth = future.getResult().getString(KEY_AUTHTOKEN); Request<?> request = createRequest(packageName, auth, versionCode, queryData, onRequestFinished, onRequestError); request.setShouldCache(false); queue.add(request); } catch (AuthenticatorException | IOException | OperationCanceledException e) { Loading @@ -138,28 +144,6 @@ public abstract class LicenseChecker<D, R> { } } public abstract Request<?> createRequest(String packageName, String auth, int versionCode, D data, BiConsumer<Integer, R> then, Response.ErrorListener errorListener); // Functional interfaces interface BiConsumerWithException<A, B, T extends Exception> { void accept(A a, B b) throws T; } interface BiConsumer<A, B> { void accept(A a, B b); } static class Tuple<A, B> { public final A a; public final B b; public Tuple(A a, B b) { this.a = a; this.b = b; } } // Implementations public static class V1 extends LicenseChecker<Long, Tuple<String, String>> { Loading Loading @@ -199,4 +183,24 @@ public abstract class LicenseChecker<D, R> { ); } } // Functional interfaces interface BiConsumerWithException<A, B, T extends Exception> { void accept(A a, B b) throws T; } interface BiConsumer<A, B> { void accept(A a, B b); } static class Tuple<A, B> { public final A a; public final B b; public Tuple(A a, B b) { this.a = a; this.b = b; } } } Loading
vending-app/src/main/java/com/android/vending/licensing/LicenseChecker.java +55 −51 Original line number Diff line number Diff line Loading @@ -79,6 +79,9 @@ public abstract class LicenseChecker<D, R> { static final String AUTH_TOKEN_SCOPE = "oauth2:https://www.googleapis.com/auth/googleplay"; public abstract Request<?> createRequest(String packageName, String auth, int versionCode, D data, BiConsumer<Integer, R> then, Response.ErrorListener errorListener); public void checkLicense(Account account, AccountManager accountManager, String packageName, PackageManager packageManager, RequestQueue queue, D queryData, Loading @@ -95,14 +98,7 @@ public abstract class LicenseChecker<D, R> { onResult.accept(ERROR_NON_MATCHING_UID, null); } else { accountManager.getAuthToken( account, AUTH_TOKEN_SCOPE, false, future -> { try { String auth = future.getResult().getString(KEY_AUTHTOKEN); Request<?> request = createRequest(packageName, auth, versionCode, queryData, (Integer integer, R r) -> { BiConsumer<Integer, R> onRequestFinished = (Integer integer, R r) -> { try { onResult.accept(integer, r); } catch (RemoteException e) { Loading @@ -110,10 +106,20 @@ public abstract class LicenseChecker<D, R> { "After telling it the license check result, remote threw an Exception."); e.printStackTrace(); } }, error -> { }; Response.ErrorListener onRequestError = error -> { Log.e(TAG, "license request failed with " + error.toString()); safeSendResult(onResult, ERROR_CONTACTING_SERVER, null); }); }; accountManager.getAuthToken( account, AUTH_TOKEN_SCOPE, false, future -> { try { String auth = future.getResult().getString(KEY_AUTHTOKEN); Request<?> request = createRequest(packageName, auth, versionCode, queryData, onRequestFinished, onRequestError); request.setShouldCache(false); queue.add(request); } catch (AuthenticatorException | IOException | OperationCanceledException e) { Loading @@ -138,28 +144,6 @@ public abstract class LicenseChecker<D, R> { } } public abstract Request<?> createRequest(String packageName, String auth, int versionCode, D data, BiConsumer<Integer, R> then, Response.ErrorListener errorListener); // Functional interfaces interface BiConsumerWithException<A, B, T extends Exception> { void accept(A a, B b) throws T; } interface BiConsumer<A, B> { void accept(A a, B b); } static class Tuple<A, B> { public final A a; public final B b; public Tuple(A a, B b) { this.a = a; this.b = b; } } // Implementations public static class V1 extends LicenseChecker<Long, Tuple<String, String>> { Loading Loading @@ -199,4 +183,24 @@ public abstract class LicenseChecker<D, R> { ); } } // Functional interfaces interface BiConsumerWithException<A, B, T extends Exception> { void accept(A a, B b) throws T; } interface BiConsumer<A, B> { void accept(A a, B b); } static class Tuple<A, B> { public final A a; public final B b; public Tuple(A a, B b) { this.a = a; this.b = b; } } }