diff options
author | Dan Egnor <egnor@google.com> | 2009-12-30 19:29:03 -0800 |
---|---|---|
committer | Dan Egnor <egnor@google.com> | 2010-01-04 10:14:21 -0800 |
commit | e38d58bf890c03eb034afd18c62c730c7d735f1c (patch) | |
tree | f8b42d11fc37826b1afd7a7242f94eee83299458 /core/java/com/google | |
parent | 2c3058a88f035398fee4321a15347ca51af31cc7 (diff) | |
download | frameworks_base-e38d58bf890c03eb034afd18c62c730c7d735f1c.zip frameworks_base-e38d58bf890c03eb034afd18c62c730c7d735f1c.tar.gz frameworks_base-e38d58bf890c03eb034afd18c62c730c7d735f1c.tar.bz2 |
Remove Google-specific (or only-used-by-Google-code) classes.
Fix a small typo in Context javadoc.
Diffstat (limited to 'core/java/com/google')
3 files changed, 0 insertions, 382 deletions
diff --git a/core/java/com/google/android/net/NetworkStatsEntity.java b/core/java/com/google/android/net/NetworkStatsEntity.java deleted file mode 100644 index a22fa1e..0000000 --- a/core/java/com/google/android/net/NetworkStatsEntity.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.android.net; - -import android.net.TrafficStats; -import android.os.SystemClock; -import android.os.SystemProperties; -import android.util.EventLog; -import org.apache.http.HttpEntity; -import org.apache.http.entity.HttpEntityWrapper; - -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; - - -public class NetworkStatsEntity extends HttpEntityWrapper { - - private static final int HTTP_STATS_EVENT = 52001; - - private class NetworkStatsInputStream extends FilterInputStream { - - public NetworkStatsInputStream(InputStream wrapped) { - super(wrapped); - } - - @Override - public void close() throws IOException { - try { - super.close(); - } finally { - long processingTime = SystemClock.elapsedRealtime() - mProcessingStartTime; - long tx = TrafficStats.getUidTxBytes(mUid); - long rx = TrafficStats.getUidRxBytes(mUid); - - EventLog.writeEvent(HTTP_STATS_EVENT, mUa, mResponseLatency, processingTime, - tx - mStartTx, rx - mStartRx); - } - } - } - - private final String mUa; - private final int mUid; - private final long mStartTx; - private final long mStartRx; - private final long mResponseLatency; - private final long mProcessingStartTime; - - public NetworkStatsEntity(HttpEntity orig, String ua, - int uid, long startTx, long startRx, long responseLatency, - long processingStartTime) { - super(orig); - this.mUa = ua; - this.mUid = uid; - this.mStartTx = startTx; - this.mStartRx = startRx; - this.mResponseLatency = responseLatency; - this.mProcessingStartTime = processingStartTime; - } - - public static boolean shouldLogNetworkStats() { - return "1".equals(SystemProperties.get("googlehttpclient.logstats")); - } - - @Override - public InputStream getContent() throws IOException { - InputStream orig = super.getContent(); - return new NetworkStatsInputStream(orig); - } -} diff --git a/core/java/com/google/android/net/SSLClientSessionCacheFactory.java b/core/java/com/google/android/net/SSLClientSessionCacheFactory.java deleted file mode 100644 index 6570a9bd..0000000 --- a/core/java/com/google/android/net/SSLClientSessionCacheFactory.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.google.android.net; - -import org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache; -import org.apache.harmony.xnet.provider.jsse.FileClientSessionCache; -import android.content.Context; -import android.provider.Settings; -import android.util.Log; - -import java.io.File; -import java.io.IOException; - -import com.android.internal.net.DbSSLSessionCache; - -/** - * Factory that returns the appropriate implementation of a {@link SSLClientSessionCache} based - * on gservices. - * - * @hide - */ -// TODO: return a proxied implementation that is updated as the gservices value changes. -public final class SSLClientSessionCacheFactory { - - private static final String TAG = "SSLClientSessionCacheFactory"; - - public static final String DB = "db"; - public static final String FILE = "file"; - - // utility class - private SSLClientSessionCacheFactory() {} - - /** - * Returns a new {@link SSLClientSessionCache} based on the persistent cache that's specified, - * if any, in gservices. If no cache is specified, returns null. - * @param context The application context used for the per-process persistent cache. - * @return A new {@link SSLClientSessionCache}, or null if no persistent cache is configured. - */ - public static SSLClientSessionCache getCache(Context context) { - String type = Settings.Gservices.getString(context.getContentResolver(), - Settings.Gservices.SSL_SESSION_CACHE); - - if (type != null) { - if (DB.equals(type)) { - return DbSSLSessionCache.getInstanceForPackage(context); - } else if (FILE.equals(type)) { - File dir = context.getFilesDir(); - File cacheDir = new File(dir, "sslcache"); - if (!cacheDir.exists()) { - cacheDir.mkdir(); - } - try { - return FileClientSessionCache.usingDirectory(cacheDir); - } catch (IOException ioe) { - Log.w(TAG, "Unable to create FileClientSessionCache in " + cacheDir.getName(), ioe); - return null; - } - } else { - Log.w(TAG, "Ignoring unrecognized type: '" + type + "'"); - } - } - return null; - } -} diff --git a/core/java/com/google/android/net/UrlRules.java b/core/java/com/google/android/net/UrlRules.java deleted file mode 100644 index 54d139d..0000000 --- a/core/java/com/google/android/net/UrlRules.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.android.net; - -import android.content.ContentResolver; -import android.database.Cursor; -import android.provider.Checkin; -import android.provider.Settings; -import android.util.Config; -import android.util.Log; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * A set of rules rewriting and blocking URLs. Used to offer a point of - * control for redirecting HTTP requests, often to the Android proxy server. - * - * <p>Each rule has the following format: - * - * <pre><em>url-prefix</em> [REWRITE <em>new-prefix</em>] [BLOCK]</pre> - * - * <p>Any URL which starts with <em>url-prefix</em> will trigger the rule. - * If BLOCK is specified, requests to that URL will be blocked and fail. - * If REWRITE is specified, the matching prefix will be removed and replaced - * with <em>new-prefix</em>. (If both are specified, BLOCK wins.) Case is - * insensitive for the REWRITE and BLOCK keywords, but sensitive for URLs. - * - * <p>In Gservices, the value of any key that starts with "url:" will be - * interpreted as a rule. The full name of the key is unimportant (but can - * be used to document the intent of the rule, and must be unique). - * Example gservices keys: - * - * <pre> - * url:use_proxy_for_calendar = "http://www.google.com/calendar/ REWRITE http://android.clients.google.com/proxy/calendar/" - * url:stop_crash_reports = "http://android.clients.google.com/crash/ BLOCK" - * url:use_ssl_for_contacts = "http://www.google.com/m8/ REWRITE https://www.google.com/m8/" - * </pre> - */ -public class UrlRules { - public static final String TAG = "UrlRules"; - public static final boolean LOCAL_LOGV = Config.LOGV || false; - - /** Thrown when the rewrite rules can't be parsed. */ - public static class RuleFormatException extends Exception { - public RuleFormatException(String msg) { super(msg); } - } - - /** A single rule specifying actions for URLs matching a certain prefix. */ - public static class Rule implements Comparable { - /** Name assigned to the rule (for logging and debugging). */ - public final String mName; - - /** Prefix required to match this rule. */ - public final String mPrefix; - - /** Text to replace mPrefix with (null to leave alone). */ - public final String mRewrite; - - /** True if matching URLs should be blocked. */ - public final boolean mBlock; - - /** Default rule that does nothing. */ - public static final Rule DEFAULT = new Rule(); - - /** Parse a rewrite rule as given in a Gservices value. */ - public Rule(String name, String rule) throws RuleFormatException { - mName = name; - String[] words = PATTERN_SPACE_PLUS.split(rule); - if (words.length == 0) throw new RuleFormatException("Empty rule"); - - mPrefix = words[0]; - String rewrite = null; - boolean block = false; - for (int pos = 1; pos < words.length; ) { - String word = words[pos].toLowerCase(); - if (word.equals("rewrite") && pos + 1 < words.length) { - rewrite = words[pos + 1]; - pos += 2; - } else if (word.equals("block")) { - block = true; - pos += 1; - } else { - throw new RuleFormatException("Illegal rule: " + rule); - } - // TODO: Parse timeout specifications, etc. - } - - mRewrite = rewrite; - mBlock = block; - } - - /** Create the default Rule. */ - private Rule() { - mName = "DEFAULT"; - mPrefix = ""; - mRewrite = null; - mBlock = false; - } - - /** - * Apply the rule to a particular URL (assumed to match the rule). - * @param url to rewrite or modify. - * @return modified URL, or null if the URL is blocked. - */ - public String apply(String url) { - if (mBlock) { - return null; - } else if (mRewrite != null) { - return mRewrite + url.substring(mPrefix.length()); - } else { - return url; - } - } - - /** More generic rules are greater than more specific rules. */ - public int compareTo(Object o) { - return ((Rule) o).mPrefix.compareTo(mPrefix); - } - } - - /** Cached rule set from Gservices. */ - private static UrlRules sCachedRules = new UrlRules(new Rule[] {}); - - private static final Pattern PATTERN_SPACE_PLUS = Pattern.compile(" +"); - private static final Pattern RULE_PATTERN = Pattern.compile("\\W"); - - /** Gservices digest when sCachedRules was cached. */ - private static String sCachedDigest = null; - - /** Currently active set of Rules. */ - private final Rule[] mRules; - - /** Regular expression with one capturing group for each Rule. */ - private final Pattern mPattern; - - /** - * Create a rewriter from an array of Rules. Normally used only for - * testing. Instead, use {@link #getRules} to get rules from Gservices. - * @param rules to use. - */ - public UrlRules(Rule[] rules) { - // Sort the rules to put the most specific rules first. - Arrays.sort(rules); - - // Construct a regular expression, escaping all the prefix strings. - StringBuilder pattern = new StringBuilder("("); - for (int i = 0; i < rules.length; ++i) { - if (i > 0) pattern.append(")|("); - pattern.append(RULE_PATTERN.matcher(rules[i].mPrefix).replaceAll("\\\\$0")); - } - mPattern = Pattern.compile(pattern.append(")").toString()); - mRules = rules; - } - - /** - * Match a string against every Rule and find one that matches. - * @param uri to match against the Rules in the rewriter. - * @return the most specific matching Rule, or Rule.DEFAULT if none match. - */ - public Rule matchRule(String url) { - Matcher matcher = mPattern.matcher(url); - if (matcher.lookingAt()) { - for (int i = 0; i < mRules.length; ++i) { - if (matcher.group(i + 1) != null) { - return mRules[i]; // Rules are sorted most specific first. - } - } - } - return Rule.DEFAULT; - } - - /** - * Get the (possibly cached) UrlRules based on the rules in Gservices. - * @param resolver to use for accessing the Gservices database. - * @return an updated UrlRules instance - */ - public static synchronized UrlRules getRules(ContentResolver resolver) { - String digest = Settings.Gservices.getString(resolver, - Settings.Gservices.PROVISIONING_DIGEST); - if (sCachedDigest != null && sCachedDigest.equals(digest)) { - // The digest is the same, so the rules are the same. - if (LOCAL_LOGV) Log.v(TAG, "Using cached rules for digest: " + digest); - return sCachedRules; - } - - if (LOCAL_LOGV) Log.v(TAG, "Scanning for Gservices \"url:*\" rules"); - Cursor cursor = resolver.query(Settings.Gservices.CONTENT_URI, - new String[] { - Settings.Gservices.NAME, - Settings.Gservices.VALUE - }, - Settings.Gservices.NAME + " like \"url:%\"", null, - Settings.Gservices.NAME); - try { - ArrayList<Rule> rules = new ArrayList<Rule>(); - while (cursor.moveToNext()) { - try { - String name = cursor.getString(0).substring(4); // "url:X" - String value = cursor.getString(1); - if (value == null || value.length() == 0) continue; - if (LOCAL_LOGV) Log.v(TAG, " Rule " + name + ": " + value); - rules.add(new Rule(name, value)); - } catch (RuleFormatException e) { - // Oops, Gservices has an invalid rule! Skip it. - Log.e(TAG, "Invalid rule from Gservices", e); - Checkin.logEvent(resolver, - Checkin.Events.Tag.GSERVICES_ERROR, e.toString()); - } - } - sCachedRules = new UrlRules(rules.toArray(new Rule[rules.size()])); - sCachedDigest = digest; - if (LOCAL_LOGV) Log.v(TAG, "New rules stored for digest: " + digest); - } finally { - cursor.close(); - } - - return sCachedRules; - } -} |