Example usage for android.util Config LOGV

List of usage examples for android.util Config LOGV

Introduction

In this page you can find the example usage for android.util Config LOGV.

Prototype

boolean LOGV

To view the source code for android.util Config LOGV.

Click Source Link

Usage

From source file:com.android.email.mail.store.zx.LocalStore.java

/**
 * @param uri local://localhost/path/to/database/uuid.db
 *//*from  w ww .  j a  v a2  s.c  o m*/
public LocalStore(String _uri, Context context) throws MessagingException {
    mContext = context;
    URI uri = null;
    try {
        uri = new URI(_uri);
    } catch (Exception e) {
        throw new MessagingException("Invalid uri for LocalStore");
    }
    if (!uri.getScheme().equals("local")) {
        throw new MessagingException("Invalid scheme");
    }
    mPath = uri.getPath();

    File parentDir = new File(mPath).getParentFile();
    if (!parentDir.exists()) {
        parentDir.mkdirs();
    }
    mDb = SQLiteDatabase.openOrCreateDatabase(mPath, null);
    int oldVersion = mDb.getVersion();

    /*
     *  TODO we should have more sophisticated way to upgrade database.
     */
    if (oldVersion != DB_VERSION) {
        if (Config.LOGV) {
            Log.v(Email.LOG_TAG, String.format("Upgrading database from %d to %d", oldVersion, DB_VERSION));
        }
        if (oldVersion < 18) {
            /**
             * Missing or old:  Create up-to-date tables
             */
            mDb.execSQL("DROP TABLE IF EXISTS folders");
            mDb.execSQL("CREATE TABLE folders (id INTEGER PRIMARY KEY, name TEXT, "
                    + "last_updated INTEGER, unread_count INTEGER, visible_limit INTEGER)");

            mDb.execSQL("DROP TABLE IF EXISTS messages");
            mDb.execSQL("CREATE TABLE messages (id INTEGER PRIMARY KEY, folder_id INTEGER, "
                    + "uid TEXT, subject TEXT, date INTEGER, flags TEXT, sender_list TEXT, "
                    + "to_list TEXT, cc_list TEXT, bcc_list TEXT, reply_to_list TEXT, "
                    + "html_content TEXT, text_content TEXT, attachment_count INTEGER, "
                    + "internal_date INTEGER, message_id TEXT)");

            mDb.execSQL("DROP TABLE IF EXISTS attachments");
            mDb.execSQL("CREATE TABLE attachments (id INTEGER PRIMARY KEY, message_id INTEGER,"
                    + "store_data TEXT, content_uri TEXT, size INTEGER, name TEXT,"
                    + "mime_type TEXT, content_id TEXT)");

            mDb.execSQL("DROP TABLE IF EXISTS pending_commands");
            mDb.execSQL("CREATE TABLE pending_commands "
                    + "(id INTEGER PRIMARY KEY, command TEXT, arguments TEXT)");

            mDb.execSQL("DROP TRIGGER IF EXISTS delete_folder");
            mDb.execSQL(
                    "CREATE TRIGGER delete_folder BEFORE DELETE ON folders BEGIN DELETE FROM messages WHERE old.id = folder_id; END;");

            mDb.execSQL("DROP TRIGGER IF EXISTS delete_message");
            mDb.execSQL(
                    "CREATE TRIGGER delete_message BEFORE DELETE ON messages BEGIN DELETE FROM attachments WHERE old.id = message_id; END;");
            mDb.setVersion(DB_VERSION);
        } else {
            if (oldVersion < 19) {
                /**
                 * Upgrade 18 to 19:  add message_id to messages table
                 */
                mDb.execSQL("ALTER TABLE messages ADD COLUMN message_id TEXT;");
                mDb.setVersion(19);
            }
            if (oldVersion < 20) {
                /**
                 * Upgrade 19 to 20:  add content_id to attachments table
                 */
                mDb.execSQL("ALTER TABLE attachments ADD COLUMN content_id TEXT;");
                mDb.setVersion(20);
            }
        }

        if (mDb.getVersion() != DB_VERSION) {
            throw new Error("Database upgrade failed!");
        }
    }
    mAttachmentsDir = new File(mPath + "_att");
    if (!mAttachmentsDir.exists()) {
        mAttachmentsDir.mkdirs();
    }
}

From source file:com.google.android.net.GoogleHttpClient.java

public HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException {
    // Rewrite the supplied URL...
    URI uri = request.getURI();/*from w  w w  . ja va 2s .  co  m*/
    String original = uri.toString();
    UrlRules rules = UrlRules.getRules(mResolver);
    UrlRules.Rule rule = rules.matchRule(original);
    String rewritten = rule.apply(original);

    if (rewritten == null) {
        Log.w(TAG, "Blocked by " + rule.mName + ": " + original);
        throw new BlockedRequestException(rule);
    } else if (rewritten == original) {
        return executeWithoutRewriting(request, context); // Pass through
    }

    try {
        uri = new URI(rewritten);
    } catch (URISyntaxException e) {
        throw new RuntimeException("Bad URL from rule: " + rule.mName, e);
    }

    // Wrap request so we can replace the URI.
    RequestWrapper wrapper = wrapRequest(request);
    wrapper.setURI(uri);
    request = wrapper;

    if (Config.LOGV) {
        Log.v(TAG, "Rule " + rule.mName + ": " + original + " -> " + rewritten);
    }
    return executeWithoutRewriting(request, context);
}

From source file:android.webkit.LoadListener.java

LoadListener(Context context, BrowserFrame frame, String url, int nativeLoader, boolean synchronous,
        boolean isMainPageLoader) {
    if (Config.LOGV) {
        Log.v(LOGTAG, "LoadListener constructor url=" + url);
    }//from  w w w  . j  ava2 s  .  c  o  m
    mContext = context;
    mBrowserFrame = frame;
    setUrl(url);
    mNativeLoader = nativeLoader;
    mMimeType = "";
    mEncoding = "";
    mSynchronous = synchronous;
    if (synchronous) {
        mMessageQueue = new Vector<Message>();
    }
    mIsMainPageLoader = isMainPageLoader;
}

From source file:android.webkit.LoadListener.java

/**
 * Parse the headers sent from the server.
 * @param headers gives up the HeaderGroup
 * IMPORTANT: as this is called from network thread, can't call native
 * directly/*ww  w  .  j  a  v  a 2 s  .c o m*/
 */
public void headers(Headers headers) {
    if (Config.LOGV)
        Log.v(LOGTAG, "LoadListener.headers");
    if (mCancelled)
        return;
    mHeaders = headers;
    mMimeType = "";
    mEncoding = "";

    ArrayList<String> cookies = headers.getSetCookie();
    for (int i = 0; i < cookies.size(); ++i) {
        CookieManager.getInstance().setCookie(mUri, cookies.get(i));
    }

    long contentLength = headers.getContentLength();
    if (contentLength != Headers.NO_CONTENT_LENGTH) {
        mContentLength = contentLength;
    } else {
        mContentLength = 0;
    }

    String contentType = headers.getContentType();
    if (contentType != null) {
        parseContentTypeHeader(contentType);

        // If we have one of "generic" MIME types, try to deduce
        // the right MIME type from the file extension (if any):
        if (mMimeType.equalsIgnoreCase("text/plain")
                || mMimeType.equalsIgnoreCase("application/octet-stream")) {

            String newMimeType = guessMimeTypeFromExtension();
            if (newMimeType != null) {
                mMimeType = newMimeType;
            }
        } else if (mMimeType.equalsIgnoreCase("text/vnd.wap.wml")) {
            // As we don't support wml, render it as plain text
            mMimeType = "text/plain";
        } else {
            // XXX: Until the servers send us either correct xhtml or
            // text/html, treat application/xhtml+xml as text/html.
            // It seems that xhtml+xml and vnd.wap.xhtml+xml mime
            // subtypes are used interchangeably. So treat them the same.
            if (mMimeType.equalsIgnoreCase("application/xhtml+xml")
                    || mMimeType.equals("application/vnd.wap.xhtml+xml")) {
                mMimeType = "text/html";
            }
        }
    } else {
        /* Often when servers respond with 304 Not Modified or a
           Redirect, then they don't specify a MIMEType. When this
           occurs, the function below is called.  In the case of
           304 Not Modified, the cached headers are used rather
           than the headers that are returned from the server. */
        guessMimeType();
    }

    // is it an authentication request?
    boolean mustAuthenticate = (mStatusCode == HTTP_AUTH || mStatusCode == HTTP_PROXY_AUTH);
    // is it a proxy authentication request?
    boolean isProxyAuthRequest = (mStatusCode == HTTP_PROXY_AUTH);
    // is this authentication request due to a failed attempt to
    // authenticate ealier?
    mAuthFailed = false;

    // if we tried to authenticate ourselves last time
    if (mAuthHeader != null) {
        // we failed, if we must to authenticate again now and
        // we have a proxy-ness match
        mAuthFailed = (mustAuthenticate && isProxyAuthRequest == mAuthHeader.isProxy());

        // if we did NOT fail and last authentication request was a
        // proxy-authentication request
        if (!mAuthFailed && mAuthHeader.isProxy()) {
            Network network = Network.getInstance(mContext);
            // if we have a valid proxy set
            if (network.isValidProxySet()) {
                /* The proxy credentials can be read in the WebCore thread
                */
                synchronized (network) {
                    // save authentication credentials for pre-emptive proxy
                    // authentication
                    network.setProxyUsername(mAuthHeader.getUsername());
                    network.setProxyPassword(mAuthHeader.getPassword());
                }
            }
        }
    }
    // it is only here that we can reset the last mAuthHeader object
    // (if existed) and start a new one!!!
    mAuthHeader = null;
    if (mustAuthenticate) {
        if (mStatusCode == HTTP_AUTH) {
            mAuthHeader = parseAuthHeader(headers.getWwwAuthenticate());
        } else {
            mAuthHeader = parseAuthHeader(headers.getProxyAuthenticate());
            // if successfully parsed the header
            if (mAuthHeader != null) {
                // mark the auth-header object as a proxy
                mAuthHeader.setProxy();
            }
        }
    }

    // Only create a cache file if the server has responded positively.
    if ((mStatusCode == HTTP_OK || mStatusCode == HTTP_FOUND || mStatusCode == HTTP_MOVED_PERMANENTLY
            || mStatusCode == HTTP_TEMPORARY_REDIRECT) && mNativeLoader != 0) {
        // Content arriving from a StreamLoader (eg File, Cache or Data)
        // will not be cached as they have the header:
        // cache-control: no-store
        mCacheResult = CacheManager.createCacheFile(mUrl, mStatusCode, headers, mMimeType, false);
        if (mCacheResult != null) {
            mCacheResult.encoding = mEncoding;
        }
    }
    sendMessageInternal(obtainMessage(MSG_CONTENT_HEADERS));
}

From source file:android.webkit.LoadListener.java

/**
 * Report the status of the response.//from w w  w.j  ava2 s.  c  o  m
 * TODO: Comments about each parameter.
 * IMPORTANT: as this is called from network thread, can't call native
 * directly
 */
public void status(int majorVersion, int minorVersion, int code, /* Status-Code value */ String reasonPhrase) {
    if (Config.LOGV) {
        Log.v(LOGTAG, "LoadListener: from: " + mUrl + " major: " + majorVersion + " minor: " + minorVersion
                + " code: " + code + " reason: " + reasonPhrase);
    }

    if (mCancelled)
        return;

    mStatusCode = code;
    mStatusText = reasonPhrase;
    mPermanent = false;
}

From source file:android.webkit.LoadListener.java

/**
 * Implementation of error handler for EventHandler.
 * Subclasses should call this method to have error fields set.
 * @param id The error id described by EventHandler.
 * @param description A string description of the error.
 * IMPORTANT: as this is called from network thread, can't call native
 * directly//from  w w w .j  a v a 2s .co  m
 */
public void error(int id, String description) {
    mErrorID = id;
    mErrorDescription = description;
    sendMessageInternal(obtainMessage(MSG_CONTENT_ERROR));
    if (Config.LOGV) {
        Log.v(LOGTAG, "LoadListener.error url:" + url() + " id:" + id + " description:" + description);
    }
    detachRequestHandle();
}

From source file:android.webkit.LoadListener.java

/**
 * Add data to the internal collection of data. This function is used by
 * the data: scheme, about: scheme and http/https schemes.
 * @param data A byte array containing the content.
 * @param length The length of data./*  w w w  . j av a2  s  .c o  m*/
 * IMPORTANT: as this is called from network thread, can't call native
 * directly
 */
public void data(byte[] data, int length) {
    if (Config.LOGV) {
        Log.v(LOGTAG, "LoadListener.data(): url: " + url());
    }

    if (ignoreCallbacks()) {
        return;
    }

    // Decode base64 data
    // Note: It's fine that we only decode base64 here and not in the other
    // data call because the only caller of the stream version is not
    // base64 encoded.
    if ("base64".equalsIgnoreCase(mTransferEncoding)) {
        if (length < data.length) {
            byte[] trimmedData = new byte[length];
            System.arraycopy(data, 0, trimmedData, 0, length);
            data = trimmedData;
        }
        data = Base64.decodeBase64(data);
        length = data.length;
    }
    // Synchronize on mData because commitLoad may write mData to WebCore
    // and we don't want to replace mData or mDataLength at the same time
    // as a write.
    boolean sendMessage = false;
    synchronized (mDataBuilder) {
        sendMessage = mDataBuilder.isEmpty();
        mDataBuilder.append(data, 0, length);
    }
    if (sendMessage) {
        // Send a message whenever data comes in after a write to WebCore
        sendMessageInternal(obtainMessage(MSG_CONTENT_DATA));
    }
}

From source file:com.android.email.activity.zx.MessageView.java

private void onClickSender() {
    if (mMessage != null) {
        try {/* ww  w.j av  a2s .c o m*/
            Address senderEmail = mMessage.getFrom()[0];
            Uri contactUri = Uri.fromParts("mailto", senderEmail.getAddress(), null);

            Intent contactIntent = new Intent(Contacts.Intents.SHOW_OR_CREATE_CONTACT);
            contactIntent.setData(contactUri);

            // Pass along full E-mail string for possible create dialog  
            contactIntent.putExtra(Contacts.Intents.EXTRA_CREATE_DESCRIPTION, senderEmail.toString());

            // Only provide personal name hint if we have one
            String senderPersonal = senderEmail.getPersonal();
            if (senderPersonal != null) {
                contactIntent.putExtra(Intents.Insert.NAME, senderPersonal);
            }

            startActivity(contactIntent);
        } catch (MessagingException me) {
            if (Config.LOGV) {
                Log.v(Email.LOG_TAG, "loadMessageForViewHeadersAvailable", me);
            }
        }
    }
}

From source file:android.webkit.LoadListener.java

/**
 * Event handler's endData call. Send a message to the handler notifying
 * them that the data has finished.//from  ww  w  . jav  a2 s  .  c  o m
 * IMPORTANT: as this is called from network thread, can't call native
 * directly
 */
public void endData() {
    if (Config.LOGV) {
        Log.v(LOGTAG, "LoadListener.endData(): url: " + url());
    }

    if (mCancelled)
        return;

    switch (mStatusCode) {
    case HTTP_MOVED_PERMANENTLY:
        // 301 - permanent redirect
        mPermanent = true;
    case HTTP_FOUND:
    case HTTP_SEE_OTHER:
    case HTTP_TEMPORARY_REDIRECT:
        if (mMethod == null && mRequestHandle == null) {
            Log.e(LOGTAG, "LoadListener.endData(): method is null!");
            Log.e(LOGTAG, "LoadListener.endData(): url = " + url());
        }
        // 301, 302, 303, and 307 - redirect
        if (mStatusCode == HTTP_TEMPORARY_REDIRECT) {
            if (mRequestHandle != null && mRequestHandle.getMethod().equals("POST")) {
                sendMessageInternal(obtainMessage(MSG_LOCATION_CHANGED_REQUEST));
            } else if (mMethod != null && mMethod.equals("POST")) {
                sendMessageInternal(obtainMessage(MSG_LOCATION_CHANGED_REQUEST));
            } else {
                sendMessageInternal(obtainMessage(MSG_LOCATION_CHANGED));
            }
        } else {
            sendMessageInternal(obtainMessage(MSG_LOCATION_CHANGED));
        }
        return;

    case HTTP_AUTH:
    case HTTP_PROXY_AUTH:
        // According to rfc2616, the response for HTTP_AUTH must include
        // WWW-Authenticate header field and the response for 
        // HTTP_PROXY_AUTH must include Proxy-Authenticate header field.
        if (mAuthHeader != null
                && (Network.getInstance(mContext).isValidProxySet() || !mAuthHeader.isProxy())) {
            Network.getInstance(mContext).handleAuthRequest(this);
            return;
        }
        break; // use default

    case HTTP_NOT_MODIFIED:
        // Server could send back NOT_MODIFIED even if we didn't
        // ask for it, so make sure we have a valid CacheLoader
        // before calling it.
        if (mCacheLoader != null) {
            detachRequestHandle();
            mCacheLoader.load();
            if (Config.LOGV) {
                Log.v(LOGTAG, "LoadListener cache load url=" + url());
            }
            return;
        }
        break; // use default

    case HTTP_NOT_FOUND:
        // Not an error, the server can send back content.
    default:
        break;
    }

    sendMessageInternal(obtainMessage(MSG_CONTENT_FINISHED));
    detachRequestHandle();
}

From source file:android.webkit.LoadListener.java

/**
 * Check the cache for the current URL, and load it if it is valid.
 *
 * @param headers for the request//  w w  w  .  j ava2 s  . c om
 * @return true if cached response is used.
 */
boolean checkCache(Map<String, String> headers) {
    // Get the cache file name for the current URL
    CacheResult result = CacheManager.getCacheFile(url(), headers);

    if (result != null) {
        CacheLoader cacheLoader = new CacheLoader(this, result);

        // If I got a cachedUrl and the revalidation header was not
        // added, then the cached content valid, we should use it.
        if (!headers.containsKey(CacheManager.HEADER_KEY_IFNONEMATCH)
                && !headers.containsKey(CacheManager.HEADER_KEY_IFMODIFIEDSINCE)) {
            if (Config.LOGV) {
                Log.v(LOGTAG, "FrameLoader: HTTP URL in cache " + "and usable: " + url());
            }
            // Load the cached file
            cacheLoader.load();
            return true;
        } else {
            // The contents of the cache need to be revalidated
            // so just provide the listener with the cache loader
            // in the case that the server response positively to
            // the cached content.
            setCacheLoader(cacheLoader);
        }
    }
    return false;
}