Search in sources :

Example 6 with Base64DecoderException

use of com.google.android.vending.licensing.util.Base64DecoderException in project Klyph by jonathangerbaud.

the class LicenseChecker method checkAccess.

/**
     * Checks if the user should have access to the app.  Binds the service if necessary.
     * <p>
     * NOTE: This call uses a trivially obfuscated string (base64-encoded).  For best security,
     * we recommend obfuscating the string that is passed into bindService using another method
     * of your own devising.
     * <p>
     * source string: "com.android.vending.licensing.ILicensingService"
     * <p>
     * @param callback
     */
public synchronized void checkAccess(LicenseCheckerCallback callback) {
    // Market.
    if (mPolicy.allowAccess()) {
        Log.i(TAG, "Using cached license response");
        callback.allow(Policy.LICENSED);
    } else {
        LicenseValidator validator = new LicenseValidator(mPolicy, new NullDeviceLimiter(), callback, generateNonce(), mPackageName, mVersionCode);
        if (mService == null) {
            Log.i(TAG, "Binding to licensing service.");
            try {
                boolean bindResult = mContext.bindService(new Intent(new String(Base64.decode("Y29tLmFuZHJvaWQudmVuZGluZy5saWNlbnNpbmcuSUxpY2Vuc2luZ1NlcnZpY2U="))), // ServiceConnection.
                this, Context.BIND_AUTO_CREATE);
                if (bindResult) {
                    mPendingChecks.offer(validator);
                } else {
                    Log.e(TAG, "Could not bind to service.");
                    handleServiceConnectionError(validator);
                }
            } catch (SecurityException e) {
                callback.applicationError(LicenseCheckerCallback.ERROR_MISSING_PERMISSION);
            } catch (Base64DecoderException e) {
                e.printStackTrace();
            }
        } else {
            mPendingChecks.offer(validator);
            runChecks();
        }
    }
}
Also used : Base64DecoderException(com.google.android.vending.licensing.util.Base64DecoderException) Intent(android.content.Intent)

Aggregations

Base64DecoderException (com.google.android.vending.licensing.util.Base64DecoderException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 Intent (android.content.Intent)2 InvalidKeyException (java.security.InvalidKeyException)2 KeyFactory (java.security.KeyFactory)2 Signature (java.security.Signature)2 SignatureException (java.security.SignatureException)2 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)2 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)2