Example #1
0
  public static void trustAllHttpsURLConnection() {
    // Create a trust manager that does not validate certificate chains
    if (sslSocketFactory == null) {
      TrustManager[] trustAllCerts =
          new TrustManager[] {
            new X509TrustManager() {
              @Override
              public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
              }

              @Override
              public void checkClientTrusted(X509Certificate[] certs, String authType) {}

              @Override
              public void checkServerTrusted(X509Certificate[] certs, String authType) {}
            }
          };
      try {
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, trustAllCerts, null);
        sslSocketFactory = sslContext.getSocketFactory();
      } catch (Throwable e) {
        LogUtils.e(e.getMessage(), e);
      }
    }

    if (sslSocketFactory != null) {
      HttpsURLConnection.setDefaultSSLSocketFactory(sslSocketFactory);
      HttpsURLConnection.setDefaultHostnameVerifier(
          org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    }
  }
Example #2
0
  public static boolean checkFsWritable() {
    // Create a temporary file to see whether a volume is really writeable.
    // It's important not to put it in the root directory which may have a
    // limit on the number of files.

    // Logger.d(TAG, "checkFsWritable directoryName ==   "
    // + PathCommonDefines.APP_FOLDER_ON_SD);
    File directory = new File(Persistence.APP_FOLDER_ON_SD);
    if (!directory.isDirectory()) {
      if (!directory.mkdirs()) {
        LogUtils.e("checkFsWritable directoryName 000  ");
        return false;
      }
    }
    File f = new File(Persistence.APP_FOLDER_ON_SD, ".probe");
    try {
      // Remove stale file if any
      if (f.exists()) {
        f.delete();
      }
      if (!f.createNewFile()) {
        return false;
      }
      f.delete();
      return true;
    } catch (IOException ex) {
      return false;
    }
  }