Advertisement
0xroot

checkAccess Java

Jul 19th, 2011
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1.  /**
  2.      * Checks if the user should have access to the app.
  3.      *
  4.      * @param callback
  5.      */
  6.     public synchronized void checkAccess(LicenseCheckerCallback callback) {
  7.         // If we have a valid recent LICENSED response, we can skip asking
  8.         // Market.
  9.         if (mPolicy.allowAccess()) {
  10.             Log.i(TAG, "Using cached license response");
  11.             callback.allow();
  12.         } else {
  13.             LicenseValidator validator = new LicenseValidator(mPolicy, new NullDeviceLimiter(),
  14.                 callback, generateNonce(), mPackageName, mVersionCode);
  15.  
  16.             if (mService == null) {
  17.                Log.i(TAG, "Binding to licensing service.");
  18.                 try {
  19.                     boolean bindResult = mContext.bindService(
  20.                         new Intent(ILicensingService.class.getName()),
  21.                         this,  // ServiceConnection.
  22.                         Context.BIND_AUTO_CREATE);
  23.  
  24.                     if (bindResult) {
  25.                         mPendingChecks.offer(validator);
  26.                     } else {
  27.                         Log.e(TAG, "Could not bind to service.");
  28.                         handleServiceConnectionError(validator);
  29.                     }
  30.                 } catch (SecurityException e) {
  31.                     callback.applicationError(ApplicationErrorCode.MISSING_PERMISSION);
  32.                 }
  33.             } else {
  34.                 mPendingChecks.offer(validator);
  35.                 runChecks();
  36.             }
  37.         }
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement