Advertisement
GeneralGDA

WebView corruption detection.

Nov 25th, 2016
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. import android.content.Context;
  2. import android.os.Build;
  3. import com.piggybank.framework.tools.Guard;
  4. import com.piggybank.framework.tools.OsUtils;
  5.  
  6. /*
  7. Created by GeneralGDA on 24.09.2015.
  8. */
  9. public final class WebViewUtils
  10. {
  11.     private static final String WEB_VIEW_DATABASE_FILE = "webview.db";
  12.  
  13.     private WebViewUtils()
  14.     {
  15.         throw new UnsupportedOperationException();
  16.     }
  17.  
  18.     public static boolean isWebViewCorrupted(final Context context)
  19.     {
  20.         Guard.nonNullArgument(context, "context");
  21.  
  22.         try
  23.         {
  24.             final int currentSdk = Build.VERSION.SDK_INT;
  25.  
  26.             if (currentSdk <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
  27.             {
  28.                 try
  29.                 {
  30.                     context.openOrCreateDatabase(WEB_VIEW_DATABASE_FILE, 0, null).close();
  31.                 }
  32.                 catch (final Throwable e)
  33.                 {
  34.                     // try again by deleting the old db and create a new one
  35.                     context.deleteDatabase(WEB_VIEW_DATABASE_FILE);
  36.                     context.openOrCreateDatabase(WEB_VIEW_DATABASE_FILE, 0, null).close();
  37.                 }
  38.             }
  39.             return false;
  40.         }
  41.         catch (final Throwable ignored)
  42.         {
  43.         }
  44.         return true;
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement