Java Code Examples for com.facebook.common.logging.FLog#e()

The following examples show how to use com.facebook.common.logging.FLog#e() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SQLitePlugin.java    From react-native-sqlite-storage with MIT License 6 votes vote down vote up
/**
 * Clean up and close all open databases.
 */
public void closeAllOpenDatabases() {
    while (!dbrmap.isEmpty()) {
        String dbname = dbrmap.keySet().iterator().next();

        this.closeDatabaseNow(dbname);

        DBRunner r = dbrmap.get(dbname);
        try {
            // stop the db runner thread:
            r.q.put(new DBQuery());
        } catch(Exception ex) {
            FLog.e(TAG, "couldn't stop db thread for db: " + dbname,ex);
        }
        dbrmap.remove(dbname);
    }
}
 
Example 2
Source File: DevSupportManagerImpl.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
public void log(Exception e) {
  StringBuilder message = new StringBuilder(e.getMessage() == null ? "Exception in native call from JS" : e.getMessage());
  Throwable cause = e.getCause();
  while (cause != null) {
    message.append("\n\n").append(cause.getMessage());
    cause = cause.getCause();
  }

  if (e instanceof JSException) {
    FLog.e(ReactConstants.TAG, "Exception in native call from JS", e);
    String stack = ((JSException) e).getStack();
    message.append("\n\n").append(stack);

    // TODO #11638796: convert the stack into something useful
    showNewError(
      message.toString(),
      new StackFrame[]{},
      JSEXCEPTION_ERROR_COOKIE,
      ErrorType.JS);
  } else {
    showNewJavaError(message.toString(), e);
  }
}
 
Example 3
Source File: DevSupportManagerImpl.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
protected Void doInBackground(String... jsonData) {
  try {
    String jscProfileUrl =
        Uri.parse(mSourceUrl).buildUpon()
            .path("/jsc-profile")
            .query(null)
            .build()
            .toString();
    OkHttpClient client = new OkHttpClient();
    for (String json: jsonData) {
      RequestBody body = RequestBody.create(JSON, json);
      Request request =
        new Request.Builder().url(jscProfileUrl).post(body).build();
      client.newCall(request).execute();
    }
  } catch (IOException e) {
    FLog.e(ReactConstants.TAG, "Failed not talk to server", e);
  }
  return null;
}
 
Example 4
Source File: SQLitePlugin.java    From react-native-sqlite-storage with MIT License 6 votes vote down vote up
/**
 * Clean up and close all open databases.
 */
public void closeAllOpenDatabases() {
    while (!dbrmap.isEmpty()) {
        String dbname = dbrmap.keySet().iterator().next();

        this.closeDatabaseNow(dbname);

        DBRunner r = dbrmap.get(dbname);
        try {
            // stop the db runner thread:
            r.q.put(new DBQuery());
        } catch(Exception ex) {
            FLog.e(TAG, "couldn't stop db thread for db: " + dbname,ex);
        }
        dbrmap.remove(dbname);
    }
}
 
Example 5
Source File: DebugOverlayController.java    From react-native-GPay with MIT License 6 votes vote down vote up
private static boolean hasPermission(Context context, String permission) {
  try {
    PackageInfo info = context.getPackageManager().getPackageInfo(
            context.getPackageName(),
            PackageManager.GET_PERMISSIONS);
    if (info.requestedPermissions != null) {
      for (String p : info.requestedPermissions) {
        if (p.equals(permission)) {
          return true;
        }
      }
    }
  } catch (PackageManager.NameNotFoundException e) {
    FLog.e(ReactConstants.TAG, "Error while retrieving package info", e);
  }
  return false;
}
 
Example 6
Source File: WebSocketModule.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactMethod
public void close(int code, String reason, int id) {
  WebSocket client = mWebSocketConnections.get(id);
  if (client == null) {
    // WebSocket is already closed
    // Don't do anything, mirror the behaviour on web
    return;
  }
  try {
    client.close(code, reason);
    mWebSocketConnections.remove(id);
    mContentHandlers.remove(id);
  } catch (Exception e) {
    FLog.e(
      ReactConstants.TAG,
      "Could not close WebSocket connection for id " + id,
      e);
  }
}
 
Example 7
Source File: SQLitePlugin.java    From react-native-sqlite-storage with MIT License 6 votes vote down vote up
DBRunner(final String dbname, ReadableMap options, CallbackContext cbc) {
    this.dbname = dbname;
    int openFlags = SQLiteDatabase.OPEN_READWRITE | SQLiteDatabase.CREATE_IF_NECESSARY;
    try {
        this.assetFilename = SQLitePluginConverter.getString(options,"assetFilename",null);
        if (this.assetFilename != null && this.assetFilename.length() > 0) {
            boolean readOnly = SQLitePluginConverter.getBoolean(options,"readOnly",false);
            openFlags = readOnly ? SQLiteDatabase.OPEN_READONLY : openFlags;
        }
    } catch (Exception ex){
        FLog.e(TAG,"Error retrieving assetFilename or mode from options:",ex);
    }
    this.openFlags = openFlags;
    this.androidLockWorkaround = SQLitePluginConverter.getBoolean(options,"androidLockWorkaround",false);
    if (this.androidLockWorkaround)
        FLog.i(TAG, "Android db closing/locking workaround applied");

    this.q = new LinkedBlockingQueue<DBQuery>();
    this.openCbc = cbc;
}
 
Example 8
Source File: SQLitePlugin.java    From react-native-sqlite-storage with MIT License 6 votes vote down vote up
/**
 * Close a database (in another thread).
 *
 * @param dbName - The name of the database file
 * @param cbc - JS callback
 */
private void closeDatabase(String dbName, CallbackContext cbc) {
    DBRunner r = dbrmap.get(dbName);
    if (r != null) {
        try {
            r.q.put(new DBQuery(false, cbc));
        } catch(Exception ex) {
            if (cbc != null) {
                cbc.error("couldn't close database" + ex);
            }
            FLog.e(TAG, "couldn't close database", ex);
        }
    } else {
        if (cbc != null) {
            cbc.success("database closed");
        }
    }
}
 
Example 9
Source File: UdpSockets.java    From react-native-udp with MIT License 6 votes vote down vote up
@Override
public void onCatalystInstanceDestroy() {
    mShuttingDown = true;

    // serialize on the AsyncTask thread, and block
    try {
        new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
            @Override
            protected void doInBackgroundGuarded(Void... params) {
                for (int i = 0; i < mClients.size(); i++) {
                    try {
                        mClients.valueAt(i).close();
                    } catch (IOException e) {
                        FLog.e(TAG, "exception when shutting down", e);
                    }
                }
                mClients.clear();
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR).get();
    } catch (InterruptedException ioe) {
        FLog.e(TAG, "onCatalystInstanceDestroy", ioe);
    } catch (ExecutionException ee) {
        FLog.e(TAG, "onCatalystInstanceDestroy", ee);
    }
}
 
Example 10
Source File: ExceptionsManagerModule.java    From react-native-GPay with MIT License 5 votes vote down vote up
@ReactMethod
public void reportSoftException(String title, ReadableArray details, int exceptionId) {
  if (mDevSupportManager.getDevSupportEnabled()) {
    mDevSupportManager.showNewJSError(title, details, exceptionId);
  } else {
    FLog.e(ReactConstants.TAG, JSStackTrace.format(title, details));
  }
}
 
Example 11
Source File: Inspector.java    From react-native-GPay with MIT License 5 votes vote down vote up
public static List<Page> getPages() {
  try {
    return Arrays.asList(instance().getPagesNative());
  } catch (UnsatisfiedLinkError e) {
    FLog.e(ReactConstants.TAG, "Inspector doesn't work in open source yet", e);
    return Collections.emptyList();
  }
}
 
Example 12
Source File: JSPackagerClient.java    From react-native-GPay with MIT License 5 votes vote down vote up
private void abortOnMessage(Object id, String reason) {
  if (id != null) {
    (new ResponderImpl(id)).error(reason);
  }

  FLog.e(TAG, "Handling the message failed with reason: " + reason);
}
 
Example 13
Source File: PriorityNetworkFetcher.java    From fresco with MIT License 5 votes vote down vote up
@Override
public void fetch(
    final PriorityNetworkFetcher.PriorityFetchState<FETCH_STATE> fetchState,
    final Callback callback) {
  fetchState
      .getContext()
      .addCallbacks(
          new BaseProducerContextCallbacks() {
            @Override
            public void onCancellationRequested() {
              removeFromQueue(fetchState, "CANCEL");
              callback.onCancellation();
            }

            @Override
            public void onPriorityChanged() {
              changePriority(fetchState, fetchState.getContext().getPriority() == HIGH);
            }
          });

  synchronized (mLock) {
    if (mCurrentlyFetching.contains(fetchState)) {
      FLog.e(TAG, "fetch state was enqueued twice: " + fetchState);
      return;
    }

    boolean isHiPri = fetchState.getContext().getPriority() == HIGH;
    FLog.v(TAG, "enqueue: %s %s", isHiPri ? "HI-PRI" : "LOW-PRI", fetchState.getUri());
    fetchState.callback = callback;
    putInQueue(fetchState, isHiPri);
  }
  dequeueIfAvailableSlots();
}
 
Example 14
Source File: SQLitePlugin.java    From react-native-sqlite-storage with MIT License 5 votes vote down vote up
/**
 * Close a database (in the current thread).
 */
@Override
void closeDatabaseNow() {
    try {
        if (mydb != null)
            mydb.dispose();
    } catch (Exception ex) {
        FLog.e(TAG, "couldn't close database, ignoring", ex);
    }
}
 
Example 15
Source File: DevSupportManagerImpl.java    From react-native-GPay with MIT License 5 votes vote down vote up
/**
 * @return {@code true} if JS bundle {@param bundleAssetName} exists, in that case
 * {@link com.facebook.react.ReactInstanceManager} should use that file from assets instead of
 * downloading bundle from dev server
 */
public boolean hasBundleInAssets(String bundleAssetName) {
  try {
    String[] assets = mApplicationContext.getAssets().list("");
    for (int i = 0; i < assets.length; i++) {
      if (assets[i].equals(bundleAssetName)) {
        return true;
      }
    }
  } catch (IOException e) {
    // Ignore this error and just fallback to downloading JS from devserver
    FLog.e(ReactConstants.TAG, "Error while loading assets list");
  }
  return false;
}
 
Example 16
Source File: CordovaPlugin.java    From react-native-cordova with MIT License 5 votes vote down vote up
public void executeReactMethod(String action, ReadableArray args, Callback success, Callback error) {
    try {
        this.execute(action, JsonConvert.reactToJSON(args), new CallbackContext(success, error));
    } catch (Exception ex) {
        FLog.e(getName(), "Unexpected error:" + ex.getMessage());
    }
}
 
Example 17
Source File: LocalContentUriThumbnailFetchProducer.java    From fresco with MIT License 5 votes vote down vote up
private static int getRotationAngle(String pathname) {
  if (pathname != null) {
    try {
      ExifInterface exif = new ExifInterface(pathname);
      return JfifUtil.getAutoRotateAngleFromOrientation(
          exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL));
    } catch (IOException ioe) {
      FLog.e(TAG, ioe, "Unable to retrieve thumbnail rotation for %s", pathname);
    }
  }
  return 0;
}
 
Example 18
Source File: BasePool.java    From fresco with MIT License 4 votes vote down vote up
/**
 * Releases the given value to the pool. In a few cases, the value is 'freed' instead of being
 * released to the pool. If - the pool currently exceeds its max size OR - if the value does not
 * map to a bucket that's currently maintained by the pool, OR - if the bucket for the value
 * exceeds its maxLength, OR - if the value is not recognized by the pool then, the value is
 * 'freed'.
 *
 * @param value the value to release to the pool
 */
@Override
public void release(V value) {
  Preconditions.checkNotNull(value);

  final int bucketedSize = getBucketedSizeForValue(value);
  final int sizeInBytes = getSizeInBytes(bucketedSize);
  synchronized (this) {
    final Bucket<V> bucket = getBucketIfPresent(bucketedSize);
    if (!mInUseValues.remove(value)) {
      // This value was not 'known' to the pool (i.e.) allocated via the pool.
      // Something is going wrong, so let's free the value and report soft error.
      FLog.e(
          TAG,
          "release (free, value unrecognized) (object, size) = (%x, %s)",
          System.identityHashCode(value),
          bucketedSize);
      free(value);
      mPoolStatsTracker.onFree(sizeInBytes);
    } else {
      // free the value, if
      //  - pool exceeds maxSize
      //  - there is no bucket for this value
      //  - there is a bucket for this value, but it has exceeded its maxLength
      //  - the value is not reusable
      // If no bucket was found for the value, simply free it
      // We should free the value if no bucket is found, or if the bucket length cap is exceeded.
      // However, if the pool max size softcap is exceeded, it may not always be best to free
      // *this* value.
      if (bucket == null
          || bucket.isMaxLengthExceeded()
          || isMaxSizeSoftCapExceeded()
          || !isReusable(value)) {
        if (bucket != null) {
          bucket.decrementInUseCount();
        }

        if (FLog.isLoggable(FLog.VERBOSE)) {
          FLog.v(
              TAG,
              "release (free) (object, size) = (%x, %s)",
              System.identityHashCode(value),
              bucketedSize);
        }
        free(value);
        mUsed.decrement(sizeInBytes);
        mPoolStatsTracker.onFree(sizeInBytes);
      } else {
        bucket.release(value);
        mFree.increment(sizeInBytes);
        mUsed.decrement(sizeInBytes);
        mPoolStatsTracker.onValueRelease(sizeInBytes);
        if (FLog.isLoggable(FLog.VERBOSE)) {
          FLog.v(
              TAG,
              "release (reuse) (object, size) = (%x, %s)",
              System.identityHashCode(value),
              bucketedSize);
        }
      }
    }
    logStats();
  }
}
 
Example 19
Source File: NotificationOnlyHandler.java    From react-native-GPay with MIT License 4 votes vote down vote up
final public void onRequest(@Nullable Object params, Responder responder) {
  responder.error("Request is not supported");
  FLog.e(TAG, "Request is not supported");
}
 
Example 20
Source File: ReconnectingWebSocket.java    From react-native-GPay with MIT License 4 votes vote down vote up
private void abort(String message, Throwable cause) {
  FLog.e(TAG, "Error occurred, shutting down websocket connection: " + message, cause);
  closeWebSocketQuietly();
}