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:com.android.contacts.ContactSaveService.java

private void saveContact(Intent intent) {
    RawContactDeltaList state = intent.getParcelableExtra(EXTRA_CONTACT_STATE);
    boolean isProfile = intent.getBooleanExtra(EXTRA_SAVE_IS_PROFILE, false);
    Bundle updatedPhotos = intent.getParcelableExtra(EXTRA_UPDATED_PHOTOS);

    if (state == null) {
        Log.e(TAG, "Invalid arguments for saveContact request");
        return;//from   w  w w  .jav  a 2s  . c om
    }

    int saveMode = intent.getIntExtra(EXTRA_SAVE_MODE, -1);
    // Trim any empty fields, and RawContacts, before persisting
    final AccountTypeManager accountTypes = AccountTypeManager.getInstance(this);
    RawContactModifier.trimEmpty(state, accountTypes);

    Uri lookupUri = null;

    final ContentResolver resolver = getContentResolver();

    boolean succeeded = false;

    // Keep track of the id of a newly raw-contact (if any... there can be at most one).
    long insertedRawContactId = -1;

    // Attempt to persist changes
    int tries = 0;
    while (tries++ < PERSIST_TRIES) {
        try {
            // Build operations and try applying
            final ArrayList<CPOWrapper> diffWrapper = state.buildDiffWrapper();

            final ArrayList<ContentProviderOperation> diff = Lists.newArrayList();

            for (CPOWrapper cpoWrapper : diffWrapper) {
                diff.add(cpoWrapper.getOperation());
            }

            if (DEBUG) {
                Log.v(TAG, "Content Provider Operations:");
                for (ContentProviderOperation operation : diff) {
                    Log.v(TAG, operation.toString());
                }
            }

            int numberProcessed = 0;
            boolean batchFailed = false;
            final ContentProviderResult[] results = new ContentProviderResult[diff.size()];
            while (numberProcessed < diff.size()) {
                final int subsetCount = applyDiffSubset(diff, numberProcessed, results, resolver);
                if (subsetCount == -1) {
                    Log.w(TAG, "Resolver.applyBatch failed in saveContacts");
                    batchFailed = true;
                    break;
                } else {
                    numberProcessed += subsetCount;
                }
            }

            if (batchFailed) {
                // Retry save
                continue;
            }

            final long rawContactId = getRawContactId(state, diffWrapper, results);
            if (rawContactId == -1) {
                throw new IllegalStateException("Could not determine RawContact ID after save");
            }
            // We don't have to check to see if the value is still -1.  If we reach here,
            // the previous loop iteration didn't succeed, so any ID that we obtained is bogus.
            insertedRawContactId = getInsertedRawContactId(diffWrapper, results);
            if (isProfile) {
                // Since the profile supports local raw contacts, which may have been completely
                // removed if all information was removed, we need to do a special query to
                // get the lookup URI for the profile contact (if it still exists).
                Cursor c = resolver.query(Profile.CONTENT_URI,
                        new String[] { Contacts._ID, Contacts.LOOKUP_KEY }, null, null, null);
                if (c == null) {
                    continue;
                }
                try {
                    if (c.moveToFirst()) {
                        final long contactId = c.getLong(0);
                        final String lookupKey = c.getString(1);
                        lookupUri = Contacts.getLookupUri(contactId, lookupKey);
                    }
                } finally {
                    c.close();
                }
            } else {
                final Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
                lookupUri = RawContacts.getContactLookupUri(resolver, rawContactUri);
            }
            if (lookupUri != null && Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, "Saved contact. New URI: " + lookupUri);
            }

            // We can change this back to false later, if we fail to save the contact photo.
            succeeded = true;
            break;

        } catch (RemoteException e) {
            // Something went wrong, bail without success
            FeedbackHelper.sendFeedback(this, TAG, "Problem persisting user edits", e);
            break;

        } catch (IllegalArgumentException e) {
            // This is thrown by applyBatch on malformed requests
            FeedbackHelper.sendFeedback(this, TAG, "Problem persisting user edits", e);
            showToast(R.string.contactSavedErrorToast);
            break;

        } catch (OperationApplicationException e) {
            // Version consistency failed, re-parent change and try again
            Log.w(TAG, "Version consistency failed, re-parenting: " + e.toString());
            final StringBuilder sb = new StringBuilder(RawContacts._ID + " IN(");
            boolean first = true;
            final int count = state.size();
            for (int i = 0; i < count; i++) {
                Long rawContactId = state.getRawContactId(i);
                if (rawContactId != null && rawContactId != -1) {
                    if (!first) {
                        sb.append(',');
                    }
                    sb.append(rawContactId);
                    first = false;
                }
            }
            sb.append(")");

            if (first) {
                throw new IllegalStateException("Version consistency failed for a new contact", e);
            }

            final RawContactDeltaList newState = RawContactDeltaList.fromQuery(
                    isProfile ? RawContactsEntity.PROFILE_CONTENT_URI : RawContactsEntity.CONTENT_URI, resolver,
                    sb.toString(), null, null);
            state = RawContactDeltaList.mergeAfter(newState, state);

            // Update the new state to use profile URIs if appropriate.
            if (isProfile) {
                for (RawContactDelta delta : state) {
                    delta.setProfileQueryUri();
                }
            }
        }
    }

    // Now save any updated photos.  We do this at the end to ensure that
    // the ContactProvider already knows about newly-created contacts.
    if (updatedPhotos != null) {
        for (String key : updatedPhotos.keySet()) {
            Uri photoUri = updatedPhotos.getParcelable(key);
            long rawContactId = Long.parseLong(key);

            // If the raw-contact ID is negative, we are saving a new raw-contact;
            // replace the bogus ID with the new one that we actually saved the contact at.
            if (rawContactId < 0) {
                rawContactId = insertedRawContactId;
            }

            // If the save failed, insertedRawContactId will be -1
            if (rawContactId < 0 || !saveUpdatedPhoto(rawContactId, photoUri, saveMode)) {
                succeeded = false;
            }
        }
    }

    Intent callbackIntent = intent.getParcelableExtra(EXTRA_CALLBACK_INTENT);
    if (callbackIntent != null) {
        if (succeeded) {
            // Mark the intent to indicate that the save was successful (even if the lookup URI
            // is now null).  For local contacts or the local profile, it's possible that the
            // save triggered removal of the contact, so no lookup URI would exist..
            callbackIntent.putExtra(EXTRA_SAVE_SUCCEEDED, true);
        }
        callbackIntent.setData(lookupUri);
        deliverCallback(callbackIntent);
    }
}

From source file:com.mobileglobe.android.customdialer.common.model.AccountTypeManager.java

/**
 * Find the best {@link DataKind} matching the requested
 * {@link AccountType#accountType}, {@link AccountType#dataSet}, and {@link DataKind#mimeType}.
 * If no direct match found, we try searching {@link FallbackAccountType}.
 *///from   w w w  .j av a 2s .c o  m
@Override
public DataKind getKindOrFallback(AccountType type, String mimeType) {
    ensureAccountsLoaded();
    DataKind kind = null;

    // Try finding account type and kind matching request
    if (type != null) {
        kind = type.getKindForMimetype(mimeType);
    }

    if (kind == null) {
        // Nothing found, so try fallback as last resort
        kind = mFallbackAccountType.getKindForMimetype(mimeType);
    }

    if (kind == null) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Unknown type=" + type + ", mime=" + mimeType);
        }
    }

    return kind;
}

From source file:com.android.contacts.group.GroupMembersFragment.java

private void onGroupMetadataLoaded() {
    if (Log.isLoggable(TAG, Log.VERBOSE))
        Log.v(TAG, "Loaded " + mGroupMetaData);

    maybeAttachCheckBoxListener();// www . j  a va 2 s .co  m

    mActivity.setTitle(mGroupMetaData.groupName);
    mActivity.invalidateOptionsMenu();
    mActivity.updateDrawerGroupMenu(mGroupMetaData.groupId);

    // Start loading the group members
    super.startLoading();
}

From source file:org.springframework.web.client.RestTemplate.java

private void logResponseStatus(HttpMethod method, URI url, ClientHttpResponse response) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        try {//ww w  .  j  a va 2 s.c om
            Log.d(TAG, method.name() + " request for \"" + url + "\" resulted in " + response.getStatusCode()
                    + " (" + response.getStatusText() + ")");
        } catch (IOException e) {
            // ignore
        }
    }
}

From source file:org.springframework.web.client.RestTemplate.java

private void handleResponseError(HttpMethod method, URI url, ClientHttpResponse response) throws IOException {
    if (Log.isLoggable(TAG, Log.WARN)) {
        try {//from  w  w  w.  j  a  v  a2  s.  c o m
            Log.w(TAG, method.name() + " request for \"" + url + "\" resulted in " + response.getStatusCode()
                    + " (" + response.getStatusText() + "); invoking error handler");
        } catch (IOException e) {
            // ignore
        }
    }
    getErrorHandler().handleError(response);
}

From source file:com.mobileglobe.android.customdialer.common.model.AccountTypeManager.java

/**
 * Return all {@link AccountType}s with at least one account which supports "invite", i.e.
 * its {@link AccountType#getInviteContactActivityClassName()} is not empty.
 *//*from w  w w . j a  va  2 s.  c o m*/
@VisibleForTesting
static Map<AccountTypeWithDataSet, AccountType> findAllInvitableAccountTypes(Context context,
        Collection<AccountWithDataSet> accounts,
        Map<AccountTypeWithDataSet, AccountType> accountTypesByTypeAndDataSet) {
    HashMap<AccountTypeWithDataSet, AccountType> result = Maps.newHashMap();
    for (AccountWithDataSet account : accounts) {
        AccountTypeWithDataSet accountTypeWithDataSet = account.getAccountTypeWithDataSet();
        AccountType type = accountTypesByTypeAndDataSet.get(accountTypeWithDataSet);
        if (type == null)
            continue; // just in case
        if (result.containsKey(accountTypeWithDataSet))
            continue;

        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Type " + accountTypeWithDataSet + " inviteClass="
                    + type.getInviteContactActivityClassName());
        }
        if (!TextUtils.isEmpty(type.getInviteContactActivityClassName())) {
            result.put(accountTypeWithDataSet, type);
        }
    }
    return Collections.unmodifiableMap(result);
}

From source file:com.google.samples.apps.iosched.service.SessionAlarmService.java

@Override
public void onConnected(Bundle connectionHint) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Connected to Google Api Service");
    }//w  w  w.  j  av a  2  s.c o  m
}

From source file:com.google.samples.apps.iosched.service.SessionAlarmService.java

@Override
public void onConnectionFailed(ConnectionResult result) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Disconnected from Google Api Service");
    }/*from ww  w.  j ava 2  s.  com*/
}

From source file:com.android.mms.ui.MessageUtils.java

public static void recordVideo(Activity activity, int requestCode, long sizeLimit) {
    // The video recorder can sometimes return a file that's larger than the max we
    // say we can handle. Try to handle that overshoot by specifying an 85% limit.
    /// M: media recoder can handle this issue,so mark it.
    //        sizeLimit *= .85F;

    int durationLimit = getVideoCaptureDurationLimit();

    if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
        log("recordVideo: durationLimit: " + durationLimit + " sizeLimit: " + sizeLimit);
    }/*from   www .j  ava2  s .c  o m*/

    Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
    intent.putExtra("android.intent.extra.sizeLimit", sizeLimit);
    intent.putExtra("android.intent.extra.durationLimit", durationLimit);
    /// M: Code analyze 009, For fix bug ALPS00241707, You can not add
    // capture video to Messaging after you preview it in Gallery. @{
    intent.putExtra(MediaStore.EXTRA_OUTPUT, TempFileProvider.SCRAP_VIDEO_URI);
    /// M: fix bug ALPS01043585
    intent.putExtra("CanShare", false);
    activity.startActivityForResult(intent, requestCode);
}

From source file:com.concentriclivers.mms.com.android.mms.transaction.MessagingNotification.java

private static final void addSmsNotificationInfos(Context context, Set<Long> threads) {
    // TDH/*from  w w w .  j  a  v  a2s  .  co  m*/
    Log.d("NotificationDebug", "addSmsNotificationInfos");

    // TDH: On my Samsung phone, the message has a type of 4 (OUTBOX)
    // instead of 1 (INBOX)! God knows why. Samsung are fucking retards.

    // Ok, but that seems to be only when I send a text to myself.
    // When I get one from someone else the type is 1 (INBOX) but seen
    // is also 1! How am I supposed to know... blargh!
    // read is also 1. I'm getting to the point where I will need
    // to add duplicate columns to the DB (e.g. seen_by_tdh).
    // Alternatively maintain another database just for "seen".
    // Or as a hacky workaround, maintain a count of the number of unread
    // messages in each thread id.

    // TDH: TODO: Do I really need this custom constraint? It
    // seems to be working as expected now...
    final String NEW_INCOMING_SM_CONSTRAINT_TDH = "((" + Sms.TYPE + " = " + Sms.MESSAGE_TYPE_INBOX + " OR "
            + Sms.TYPE + " = " + Sms.MESSAGE_TYPE_OUTBOX + ")" + " AND " + Sms.SEEN + " = 0)";
    ContentResolver resolver = context.getContentResolver();
    Cursor cursor = SqliteWrapper.query(context, resolver, Sms.CONTENT_URI, SMS_STATUS_PROJECTION,
            NEW_INCOMING_SM_CONSTRAINT_TDH, null, Sms.DATE + " desc");

    if (cursor == null) {
        // TDH: TODO: This happens because our SQL code above
        // assumes columns exist that don't or something...
        // but to get the error I need to read logcat and automatically
        // send myself a message.
        Log.d("NotificationDebug", "cursor null");

        return;
    }

    // TDH
    Log.d("NotificationDebug", "Cursor count: " + cursor.getCount());

    String[] testProjection = new String[] { Sms.THREAD_ID, Sms.DATE, Sms.ADDRESS, Sms.SUBJECT, Sms.BODY,
            Sms.SEEN, Sms.READ, Sms.TYPE };
    // TDH: Test
    Cursor cursor2 = SqliteWrapper.query(context, resolver, Sms.CONTENT_URI, testProjection, null, null,
            Sms.DATE + " desc");
    if (cursor2 == null) {
        Log.d("NotificationDebug", "Cursor2 null");

        return;
    }
    Log.d("NotificationDebug", "Cursor2 count: " + cursor2.getCount());
    int i = 0;
    while (cursor2.moveToNext() && ++i < 3) {
        Log.d("NotificationDebug",
                "message: " + cursor2.getString(COLUMN_SMS_BODY) + ", threadId: "
                        + cursor2.getLong(COLUMN_THREAD_ID) + ", seen: " + cursor2.getInt(5) + ", read: "
                        + cursor2.getInt(6) + ", type: " + cursor2.getInt(7));
    }

    // TDH: Ok we get here. cursor isn't null but something still fails below.
    // I think it is still because it is looking up the SMS in the database
    // and it doesn't exist yet. Yeah seems to be that way.
    // Ok I will just add a delay for 2 second to the receive code.

    try {
        while (cursor.moveToNext()) {
            Log.d("NotificationDebug", "movedToNext.");
            String address = cursor.getString(COLUMN_SMS_ADDRESS);
            Log.d("NotificationDebug", "address: " + address);

            Contact contact = Contact.get(address, false);
            Log.d("NotificationDebug", "contact: " + contact);

            if (contact.getSendToVoicemail()) {
                Log.d("NotificationDebug", "getSendToVoicemail() = true");

                // don't notify, skip this one
                continue;
            }

            String message = cursor.getString(COLUMN_SMS_BODY);
            long threadId = cursor.getLong(COLUMN_THREAD_ID);

            Log.d("NotificationDebug", "message: " + message + ", threadId: " + threadId);

            // TDH: Never gets to here!
            Log.d("NotificationDebug", "Got thread id: " + threadId);

            long timeMillis = cursor.getLong(COLUMN_DATE);

            if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
                Log.d(TAG, "addSmsNotificationInfos: count=" + cursor.getCount() + ", addr=" + address
                        + ", thread_id=" + threadId);
            }

            NotificationInfo info = getNewMessageNotificationInfo(context, true /* isSms */, address, message,
                    null /* subject */, threadId, timeMillis, null /* attachmentBitmap */, contact,
                    WorkingMessage.TEXT);

            sNotificationSet.add(info);

            threads.add(threadId);
            threads.add(cursor.getLong(COLUMN_THREAD_ID));
        }
    } catch (Exception e) {
        // TDH
        e.printStackTrace();
    } finally {
        cursor.close();
    }
}