/// <summary> /// Checks if the user should have access to the app. Binds the service if necessary. /// </summary> /// <param name="callback"> /// The callback. /// </param> public void CheckAccess(ILicenseCheckerCallback callback) { lock (this.locker) { // If we have a valid recent LICENSED response, we can skip asking Market/Play. if (this.policy.AllowAccess()) { System.Diagnostics.Debug.WriteLine("Using cached license response"); callback.Allow(PolicyServerResponse.Licensed); } else { var validator = new LicenseValidator( this.policy, new NullDeviceLimiter(), callback, GenerateNumberUsedOnce(), this.packageName, this.versionCode); if (this.licensingService == null) { try { var i = new Intent(LicensingServiceIntentString); i.SetPackage(LicensingServicePackageString); if (this.context.BindService(i, this, Bind.AutoCreate)) { this.pendingChecks.Enqueue(validator); } else { Debug.WriteLine("Could not bind to service."); this.HandleServiceConnectionError(validator); } } catch (Java.Lang.SecurityException) { callback.ApplicationError(CallbackErrorCode.MissingPermission); } catch (Exception ex) { Debug.WriteLine(ex.StackTrace); } } else { this.pendingChecks.Enqueue(validator); this.RunChecks(); } } } }
/// <summary> /// Initializes a new instance of the <see cref="LicenseValidator"/> class. /// </summary> /// <param name="policy"> /// The policy. /// </param> /// <param name="deviceLimiter"> /// The device limiter. /// </param> /// <param name="callback"> /// The callback. /// </param> /// <param name="nonce"> /// The nonce. /// </param> /// <param name="packageName"> /// The package name. /// </param> /// <param name="versionCode"> /// The version code. /// </param> internal LicenseValidator( IPolicy policy, IDeviceLimiter deviceLimiter, ILicenseCheckerCallback callback, int nonce, string packageName, string versionCode) { this.policy = policy; this.deviceLimiter = deviceLimiter; this.licenseCheckerCallback = callback; this.numberUsedOnce = nonce; this.packageName = packageName; this.versionCode = versionCode; }
/// <summary> /// Initializes a new instance of the <see cref="LicenseValidator"/> class. /// </summary> /// <param name="policy"> /// The policy. /// </param> /// <param name="deviceLimiter"> /// The device limiter. /// </param> /// <param name="callback"> /// The callback. /// </param> /// <param name="nonce"> /// The nonce. /// </param> /// <param name="packageName"> /// The package name. /// </param> /// <param name="versionCode"> /// The version code. /// </param> internal LicenseValidator( IPolicy policy, IDeviceLimiter deviceLimiter, ILicenseCheckerCallback callback, int nonce, string packageName, string versionCode) { this.policy = policy; this.deviceLimiter = deviceLimiter; this.licenseCheckerCallback = callback; this.numberUsedOnce = nonce; this.packageName = packageName; this.versionCode = versionCode; }
/// <summary> /// Checks if the user should have access to the app. Binds the service if necessary. /// </summary> /// <param name="callback"> /// The callback. /// </param> public void CheckAccess(ILicenseCheckerCallback callback) { lock (this.locker) { // If we have a valid recent LICENSED response, we can skip asking Market/Play. if (this.policy.AllowAccess()) { System.Diagnostics.Debug.WriteLine("Using cached license response"); callback.Allow(PolicyServerResponse.Licensed); } else { var validator = new LicenseValidator( this.policy, new NullDeviceLimiter(), callback, GenerateNumberUsedOnce(), this.packageName, this.versionCode); if (this.licensingService == null) { try { var i = new Intent(LicensingServiceIntentString); i.SetPackage(LicensingServicePackageString); if (this.context.BindService(i, this, Bind.AutoCreate)) { this.pendingChecks.Enqueue(validator); } else { Debug.WriteLine("Could not bind to service."); this.HandleServiceConnectionError(validator); } } catch (Java.Lang.SecurityException) { callback.ApplicationError(CallbackErrorCode.MissingPermission); } catch (Exception ex) { Debug.WriteLine(ex.StackTrace); } } else { this.pendingChecks.Enqueue(validator); this.RunChecks(); } } } }