Example usage for android.util Log isLoggable

List of usage examples for android.util Log isLoggable

Introduction

In this page you can find the example usage for android.util Log isLoggable.

Prototype

public static native boolean isLoggable(String tag, int level);

Source Link

Document

Checks to see whether or not a log for the specified tag is loggable at the specified level.

Usage

From source file:org.ametro.app.ApplicationEx.java

public void onCreate() {
    if (Log.isLoggable(Constants.LOG_TAG_MAIN, Log.INFO)) {
        Log.i(Constants.LOG_TAG_MAIN, "aMetro application started");
    }/*w ww  .  j a  v a  2 s  . co m*/
    mInstance = this;
    mConnectionManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    FileUtil.touchDirectory(Constants.ROOT_PATH);
    FileUtil.touchDirectory(Constants.LOCAL_CATALOG_PATH);
    FileUtil.touchDirectory(Constants.IMPORT_CATALOG_PATH);
    FileUtil.touchDirectory(Constants.TEMP_CATALOG_PATH);
    FileUtil.touchDirectory(Constants.ICONS_PATH);
    FileUtil.touchFile(Constants.NO_MEDIA_FILE);
    extractEULA(this);

    super.onCreate();
}

From source file:ir.keloud.android.lib.common.SingleSessionManager.java

@Override
public KeloudClient removeClientFor(KeloudAccount account) {

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log_OC.d(TAG, "removeClientFor starting ");
    }/*from ww w  . j  a va 2 s.  c  o  m*/

    if (account == null) {
        return null;
    }

    KeloudClient client = null;
    String accountName = account.getName();
    if (accountName != null) {
        client = mClientsWithKnownUsername.remove(accountName);
        if (client != null) {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log_OC.v(TAG, "Removed client for account " + accountName);
            }
            return client;
        } else {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log_OC.v(TAG, "No client tracked for  account " + accountName);
            }
        }
    }

    mClientsWithUnknownUsername.clear();

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log_OC.d(TAG, "removeClientFor finishing ");
    }
    return null;

}

From source file:com.cerema.cloud2.lib.common.SingleSessionManager.java

@Override
public OwnCloudClient removeClientFor(OwnCloudAccount account) {

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log_OC.d(TAG, "removeClientFor starting ");
    }/*from ww w .j  av a2 s  .c  om*/

    if (account == null) {
        return null;
    }

    OwnCloudClient client = null;
    String accountName = account.getName();
    if (accountName != null) {
        client = mClientsWithKnownUsername.remove(accountName);
        if (client != null) {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log_OC.v(TAG, "Removed client for account " + accountName);
            }
            return client;
        } else {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log_OC.v(TAG, "No client tracked for  account " + accountName);
            }
        }
    }

    mClientsWithUnknownUsername.clear();

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log_OC.d(TAG, "removeClientFor finishing ");
    }
    return null;

}

From source file:com.google.android.gcm.GCMRegistrar.java

private static void checkReceiver(Context context, Set<String> allowedReceivers, String action) {
    PackageManager pm = context.getPackageManager();
    String packageName = context.getPackageName();
    Intent intent = new Intent(action);
    intent.setPackage(packageName);/*from   w  w w .jav  a2  s  .  co  m*/
    List<ResolveInfo> receivers = pm.queryBroadcastReceivers(intent, PackageManager.GET_INTENT_FILTERS);
    if (receivers.isEmpty()) {
        throw new IllegalStateException("No receivers for action " + action);
    }
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "Found " + receivers.size() + " receivers for action " + action);
    }
    // make sure receivers match
    for (ResolveInfo receiver : receivers) {
        String name = receiver.activityInfo.name;
        if (!allowedReceivers.contains(name)) {
            throw new IllegalStateException(
                    "Receiver " + name + " is not set with permission " + GCMConstants.PERMISSION_GCM_INTENTS);
        }
    }
}

From source file:com.emorym.android_pusher.Pusher.java

public void send(String event_name, JSONObject data, String channel) {
    JSONObject message = new JSONObject();

    try {//w  w w. j a  va2s .c  o m
        data.put("channel", channel);
        message.put("event", event_name);
        message.put("data", data);

        if (Log.isLoggable(TAG, DEBUG))
            Log.d(TAG, "Message: " + message.toString());
        mWebSocket.send(message.toString());
    } catch (WebSocketException e) {
        if (Log.isLoggable(TAG, DEBUG))
            Log.d(TAG, "Exception sending message", e);
    } catch (JSONException e) {
        if (Log.isLoggable(TAG, DEBUG))
            Log.d(TAG, "JSON exception", e);
    }
}

From source file:com.android.car.trust.CarEnrolmentActivity.java

@Override
public void onResume() {
    super.onResume();

    if (!mPrefs.contains(SP_HANDLE_KEY)) {
        appendOutputText("No handles found.");
        return;//from  ww w.  ja v  a  2s.c o m
    }

    try {
        mHandle = mPrefs.getLong(SP_HANDLE_KEY, -1);
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "onResume, checking handle active: " + mHandle);
        }
        isTokenActive(mHandle);
    } catch (RemoteException e) {
        Log.e(TAG, "Error checking if token is valid");
        appendOutputText("Error checking if token is valid");
    }
}

From source file:com.hyung.jin.seo.getup.wear.G3tUpActivity.java

@Override
protected void onResume() {
    super.onResume();

    // update threshold
    setUpThreshold();// w  ww .ja v a  2  s  . c  o  m

    if (sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL)) {
        if (Log.isLoggable(G3tUpConstants.TAG, Log.DEBUG)) {
            Log.d(G3tUpConstants.TAG, "Successfully registered for the sensor updates");
        }
    }
}

From source file:com.hyung.jin.seo.getup.wear.G3tUpActivity.java

@Override
protected void onPause() {
    super.onPause();
    sensorManager.unregisterListener(this);
    if (Log.isLoggable(G3tUpConstants.TAG, Log.DEBUG)) {
        Log.d(G3tUpConstants.TAG, "Unregistered for sensor events");
    }//from   ww w.j  av  a2  s  .  c o m
}

From source file:com.example.jumpnote.android.SyncAdapter.java

@Override
public void onPerformSync(final Account account, Bundle extras, String authority,
        final ContentProviderClient provider, final SyncResult syncResult) {
    TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    String clientDeviceId = tm.getDeviceId();

    final long newSyncTime = System.currentTimeMillis();

    final boolean uploadOnly = extras.getBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, false);
    final boolean manualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
    final boolean initialize = extras.getBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, false);

    C2DMReceiver.refreshAppC2DMRegistrationState(mContext);

    Log.i(TAG, "Beginning " + (uploadOnly ? "upload-only" : "full") + " sync for account " + account.name);

    // Read this account's sync metadata
    final SharedPreferences syncMeta = mContext.getSharedPreferences("sync:" + account.name, 0);
    long lastSyncTime = syncMeta.getLong(LAST_SYNC, 0);
    long lastServerSyncTime = syncMeta.getLong(SERVER_LAST_SYNC, 0);

    // Check for changes in either app-wide auto sync registration information, or changes in
    // the user's preferences for auto sync on this account; if either changes, piggy back the
    // new registration information in this sync.
    long lastRegistrationChangeTime = C2DMessaging.getLastRegistrationChange(mContext);

    boolean autoSyncDesired = ContentResolver.getMasterSyncAutomatically()
            && ContentResolver.getSyncAutomatically(account, JumpNoteContract.AUTHORITY);
    boolean autoSyncEnabled = syncMeta.getBoolean(DM_REGISTERED, false);

    // Will be 0 for no change, -1 for unregister, 1 for register.
    final int deviceRegChange;
    JsonRpcClient.Call deviceRegCall = null;
    if (autoSyncDesired != autoSyncEnabled || lastRegistrationChangeTime > lastSyncTime || initialize
            || manualSync) {/*ww w  . j  a v  a2  s  . com*/

        String registrationId = C2DMessaging.getRegistrationId(mContext);
        deviceRegChange = (autoSyncDesired && registrationId != null) ? 1 : -1;

        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG,
                    "Auto sync selection or registration information has changed, "
                            + (deviceRegChange == 1 ? "registering" : "unregistering")
                            + " messaging for this device, for account " + account.name);
        }

        try {
            if (deviceRegChange == 1) {
                // Register device for auto sync on this account.
                deviceRegCall = new JsonRpcClient.Call(JumpNoteProtocol.DevicesRegister.METHOD);
                JSONObject params = new JSONObject();

                DeviceRegistration device = new DeviceRegistration(clientDeviceId, DEVICE_TYPE, registrationId);
                params.put(JumpNoteProtocol.DevicesRegister.ARG_DEVICE, device.toJSON());
                deviceRegCall.setParams(params);
            } else {
                // Unregister device for auto sync on this account.
                deviceRegCall = new JsonRpcClient.Call(JumpNoteProtocol.DevicesUnregister.METHOD);
                JSONObject params = new JSONObject();
                params.put(JumpNoteProtocol.DevicesUnregister.ARG_DEVICE_ID, clientDeviceId);
                deviceRegCall.setParams(params);
            }
        } catch (JSONException e) {
            logErrorMessage("Error generating device registration remote RPC parameters.", manualSync);
            e.printStackTrace();
            return;
        }
    } else {
        deviceRegChange = 0;
    }

    // Get the list of locally changed notes. If this is an upload-only sync and there were
    // no local changes, cancel the sync.
    List<ModelJava.Note> locallyChangedNotes = null;
    try {
        locallyChangedNotes = getLocallyChangedNotes(provider, account, new Date(lastSyncTime));
    } catch (RemoteException e) {
        logErrorMessage("Remote exception accessing content provider: " + e.getMessage(), manualSync);
        e.printStackTrace();
        syncResult.stats.numIoExceptions++;
        return;
    }

    if (uploadOnly && locallyChangedNotes.isEmpty() && deviceRegCall == null) {
        Log.i(TAG, "No local changes; upload-only sync canceled.");
        return;
    }

    // Set up the RPC sync calls
    final AuthenticatedJsonRpcJavaClient jsonRpcClient = new AuthenticatedJsonRpcJavaClient(mContext,
            Config.SERVER_AUTH_URL_TEMPLATE, Config.SERVER_RPC_URL);
    try {
        jsonRpcClient.blockingAuthenticateAccount(account,
                manualSync ? AuthenticatedJsonRpcJavaClient.NEED_AUTH_INTENT
                        : AuthenticatedJsonRpcJavaClient.NEED_AUTH_NOTIFICATION,
                false);
    } catch (AuthenticationException e) {
        logErrorMessage("Authentication exception when attempting to sync.", manualSync);
        e.printStackTrace();
        syncResult.stats.numAuthExceptions++;
        return;
    } catch (OperationCanceledException e) {
        Log.i(TAG, "Sync for account " + account.name + " manually canceled.");
        return;
    } catch (RequestedUserAuthenticationException e) {
        syncResult.stats.numAuthExceptions++;
        return;
    } catch (InvalidAuthTokenException e) {
        logErrorMessage("Invalid auth token provided by AccountManager when attempting to " + "sync.",
                manualSync);
        e.printStackTrace();
        syncResult.stats.numAuthExceptions++;
        return;
    }

    // Set up the notes sync call.
    JsonRpcClient.Call notesSyncCall = new JsonRpcClient.Call(JumpNoteProtocol.NotesSync.METHOD);
    try {
        JSONObject params = new JSONObject();
        params.put(JumpNoteProtocol.ARG_CLIENT_DEVICE_ID, clientDeviceId);
        params.put(JumpNoteProtocol.NotesSync.ARG_SINCE_DATE,
                Util.formatDateISO8601(new Date(lastServerSyncTime)));

        JSONArray locallyChangedNotesJson = new JSONArray();
        for (ModelJava.Note locallyChangedNote : locallyChangedNotes) {
            locallyChangedNotesJson.put(locallyChangedNote.toJSON());
        }

        params.put(JumpNoteProtocol.NotesSync.ARG_LOCAL_NOTES, locallyChangedNotesJson);
        notesSyncCall.setParams(params);
    } catch (JSONException e) {
        logErrorMessage("Error generating sync remote RPC parameters.", manualSync);
        e.printStackTrace();
        syncResult.stats.numParseExceptions++;
        return;
    }

    List<JsonRpcClient.Call> jsonRpcCalls = new ArrayList<JsonRpcClient.Call>();
    jsonRpcCalls.add(notesSyncCall);
    if (deviceRegChange != 0)
        jsonRpcCalls.add(deviceRegCall);

    jsonRpcClient.callBatch(jsonRpcCalls, new JsonRpcClient.BatchCallback() {
        public void onData(Object[] data) {
            if (data[0] != null) {
                // Read notes sync data.
                JSONObject dataJson = (JSONObject) data[0];
                try {
                    List<ModelJava.Note> changedNotes = new ArrayList<ModelJava.Note>();
                    JSONArray notesJson = dataJson.getJSONArray(JumpNoteProtocol.NotesSync.RET_NOTES);
                    for (int i = 0; i < notesJson.length(); i++) {
                        changedNotes.add(new ModelJava.Note(notesJson.getJSONObject(i)));
                    }

                    reconcileSyncedNotes(provider, account, changedNotes, syncResult.stats);

                    // If sync is successful (no exceptions thrown), update sync metadata
                    long newServerSyncTime = Util
                            .parseDateISO8601(dataJson.getString(JumpNoteProtocol.NotesSync.RET_NEW_SINCE_DATE))
                            .getTime();
                    syncMeta.edit().putLong(LAST_SYNC, newSyncTime).commit();
                    syncMeta.edit().putLong(SERVER_LAST_SYNC, newServerSyncTime).commit();
                    Log.i(TAG, "Sync complete, setting last sync time to " + Long.toString(newSyncTime));
                } catch (JSONException e) {
                    logErrorMessage("Error parsing note sync RPC response", manualSync);
                    e.printStackTrace();
                    syncResult.stats.numParseExceptions++;
                    return;
                } catch (ParseException e) {
                    logErrorMessage("Error parsing note sync RPC response", manualSync);
                    e.printStackTrace();
                    syncResult.stats.numParseExceptions++;
                    return;
                } catch (RemoteException e) {
                    logErrorMessage("RemoteException in reconcileSyncedNotes: " + e.getMessage(), manualSync);
                    e.printStackTrace();
                    return;
                } catch (OperationApplicationException e) {
                    logErrorMessage("Could not apply batch operations to content provider: " + e.getMessage(),
                            manualSync);
                    e.printStackTrace();
                    return;
                } finally {
                    provider.release();
                }
            }

            // Read device reg data.
            if (deviceRegChange != 0) {
                // data[1] will be null in case of an error (successful unregisters
                // will have an empty JSONObject, not null).
                boolean registered = (data[1] != null && deviceRegChange == 1);
                syncMeta.edit().putBoolean(DM_REGISTERED, registered).commit();
                if (Log.isLoggable(TAG, Log.DEBUG)) {
                    Log.d(TAG, "Stored account auto sync registration state: " + Boolean.toString(registered));
                }
            }
        }

        public void onError(int callIndex, JsonRpcException e) {
            if (e.getHttpCode() == 403) {
                Log.w(TAG, "Got a 403 response, invalidating App Engine ACSID token");
                jsonRpcClient.invalidateAccountAcsidToken(account);
            }

            provider.release();
            logErrorMessage("Error calling remote note sync RPC", manualSync);
            e.printStackTrace();
        }
    });
}

From source file:com.senechaux.rutino.utils.NetworkUtilities.java

public static String authenticateGetToken(String username, String password, Handler handler,
        final Context context) {
    final HttpResponse resp;
    String response = "";
    final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair(PARAM_USERNAME, username));
    params.add(new BasicNameValuePair(PARAM_PASSWORD, password));
    HttpEntity entity = null;// ww w  .  j  a  va2s  .c  o m
    try {
        entity = new UrlEncodedFormEntity(params);
    } catch (final UnsupportedEncodingException e) {
        // this should never happen.
        throw new AssertionError(e);
    }

    final HttpPost post = new HttpPost(Constants.AUTH_URI);
    post.addHeader(entity.getContentType());
    post.setEntity(entity);
    maybeCreateHttpClient();

    try {
        resp = mHttpClient.execute(post);
        response = EntityUtils.toString(resp.getEntity());
        response = response.replace("\"", "");
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "Resp: " + resp.toString());
        }
        if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, "Successful authentication, resp: " + resp.toString());
            }
            sendResult(true, handler, context, response);
            return response;
        } else {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, "Error authenticating" + resp.getStatusLine());
            }
            sendResult(false, handler, context, response);
            return response;
        }
    } catch (final IOException e) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "IOException when getting authtoken", e);
        }
        sendResult(false, handler, context, response);
        return response;
    } finally {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "getAuthtoken completing");
        }
    }
}