am 7762d936: Unbundling work

Merge commit '7762d93621f508f4410fd37b5bbdfec0071b0420' into eclair-mr2-plus-aosp

* commit '7762d93621f508f4410fd37b5bbdfec0071b0420':
  Unbundling work
diff --git a/core/java/android/net/http/AndroidHttpClient.java b/common/java/com/android/common/AndroidHttpClient.java
similarity index 96%
rename from core/java/android/net/http/AndroidHttpClient.java
rename to common/java/com/android/common/AndroidHttpClient.java
index c2013d5..6fa6da1 100644
--- a/core/java/android/net/http/AndroidHttpClient.java
+++ b/common/java/com/android/common/AndroidHttpClient.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.net.http;
+package com.android.common;
 
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
@@ -59,11 +59,12 @@
 import java.net.URI;
 import java.security.KeyManagementException;
 
-import android.util.Log;
 import android.content.ContentResolver;
+import android.os.Looper;
+import android.os.SystemProperties;
 import android.provider.Settings;
 import android.text.TextUtils;
-import android.os.SystemProperties;
+import android.util.Log;
 
 /**
  * Subclass of the Apache {@link DefaultHttpClient} that is configured with
@@ -86,15 +87,12 @@
     private static final String TAG = "AndroidHttpClient";
 
 
-    /** Set if HTTP requests are blocked from being executed on this thread */
-    private static final ThreadLocal<Boolean> sThreadBlocked =
-            new ThreadLocal<Boolean>();
-
     /** Interceptor throws an exception if the executing thread is blocked */
     private static final HttpRequestInterceptor sThreadCheckInterceptor =
             new HttpRequestInterceptor() {
         public void process(HttpRequest request, HttpContext context) {
-            if (sThreadBlocked.get() != null && sThreadBlocked.get()) {
+            // Prevent the HttpRequest from being sent on the main thread
+            if (Looper.myLooper() != null && Looper.myLooper() == Looper.getMainLooper() ) {
                 throw new RuntimeException("This thread forbids HTTP requests");
             }
         }
@@ -221,15 +219,6 @@
     }
 
     /**
-     * Block this thread from executing HTTP requests.
-     * Used to guard against HTTP requests blocking the main application thread.
-     * @param blocked if HTTP requests run on this thread should be denied
-     */
-    public static void setThreadBlocked(boolean blocked) {
-        sThreadBlocked.set(blocked);
-    }
-
-    /**
      * Modifies a request to indicate to the server that we would like a
      * gzipped response.  (Uses the "Accept-Encoding" HTTP header.)
      * @param request the request to modify
diff --git a/core/java/android/text/util/Rfc822InputFilter.java b/common/java/com/android/common/Rfc822InputFilter.java
similarity index 74%
rename from core/java/android/text/util/Rfc822InputFilter.java
rename to common/java/com/android/common/Rfc822InputFilter.java
index 8c8b7fc..6dfdc7b 100644
--- a/core/java/android/text/util/Rfc822InputFilter.java
+++ b/common/java/com/android/common/Rfc822InputFilter.java
@@ -1,4 +1,20 @@
-package android.text.util;
+/*
+ * 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.android.common;
 
 import android.text.InputFilter;
 import android.text.Spanned;
diff --git a/core/java/android/text/util/Rfc822Validator.java b/common/java/com/android/common/Rfc822Validator.java
similarity index 97%
rename from core/java/android/text/util/Rfc822Validator.java
rename to common/java/com/android/common/Rfc822Validator.java
index 6a6bf69..087e425 100644
--- a/core/java/android/text/util/Rfc822Validator.java
+++ b/common/java/com/android/common/Rfc822Validator.java
@@ -14,9 +14,11 @@
  * limitations under the License.
  */
 
-package android.text.util;
+package com.android.common;
 
 import android.text.TextUtils;
+import android.text.util.Rfc822Token;
+import android.text.util.Rfc822Tokenizer;
 import android.widget.AutoCompleteTextView;
 
 import java.util.regex.Pattern;
@@ -65,7 +67,7 @@
                EMAIL_ADDRESS_PATTERN.
                    matcher(tokens[0].getAddress()).matches();
     }
-    
+
     /**
      * @return a string in which all the characters that are illegal for the username
      * or the domain name part of the email address have been removed.
@@ -82,7 +84,7 @@
              * A local-part can contain multiple atoms, concatenated by
              * periods, so do allow periods here.
              */
-    
+
             if (c <= ' ' || c > '~') {
                 continue;
             }
diff --git a/core/java/com/android/internal/widget/NumberPicker.java b/common/java/com/android/common/widget/NumberPicker.java
similarity index 98%
rename from core/java/com/android/internal/widget/NumberPicker.java
rename to common/java/com/android/common/widget/NumberPicker.java
index ae08eca..64b436f 100644
--- a/core/java/com/android/internal/widget/NumberPicker.java
+++ b/common/java/com/android/common/widget/NumberPicker.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.internal.widget;
+package com.android.common.widget;
 
 import android.content.Context;
 import android.os.Handler;
@@ -104,7 +104,8 @@
     public NumberPicker(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs);
         setOrientation(VERTICAL);
-        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+        LayoutInflater inflater =
+                (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         inflater.inflate(R.layout.number_picker, this, true);
         mHandler = new Handler();
         InputFilter inputFilter = new NumberPickerInputFilter();
@@ -408,4 +409,4 @@
     public int getCurrent() {
         return mCurrent;
     }
-}
\ No newline at end of file
+}
diff --git a/core/java/com/android/internal/widget/NumberPickerButton.java b/common/java/com/android/common/widget/NumberPickerButton.java
similarity index 96%
rename from core/java/com/android/internal/widget/NumberPickerButton.java
rename to common/java/com/android/common/widget/NumberPickerButton.java
index 39f1e2c..f6b6d5d 100644
--- a/core/java/com/android/internal/widget/NumberPickerButton.java
+++ b/common/java/com/android/common/widget/NumberPickerButton.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.internal.widget;
+package com.android.common.widget;
 
 import android.content.Context;
 import android.util.AttributeSet;
@@ -30,7 +30,7 @@
 public class NumberPickerButton extends ImageButton {
 
     private NumberPicker mNumberPicker;
-    
+
     public NumberPickerButton(Context context, AttributeSet attrs,
             int defStyle) {
         super(context, attrs, defStyle);
@@ -43,23 +43,23 @@
     public NumberPickerButton(Context context) {
         super(context);
     }
-    
+
     public void setNumberPicker(NumberPicker picker) {
         mNumberPicker = picker;
     }
-    
+
     @Override
     public boolean onTouchEvent(MotionEvent event) {
         cancelLongpressIfRequired(event);
         return super.onTouchEvent(event);
     }
-    
+
     @Override
     public boolean onTrackballEvent(MotionEvent event) {
         cancelLongpressIfRequired(event);
         return super.onTrackballEvent(event);
     }
-    
+
     @Override
     public boolean onKeyUp(int keyCode, KeyEvent event) {
         if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
@@ -68,7 +68,7 @@
         }
         return super.onKeyUp(keyCode, event);
     }
-    
+
     private void cancelLongpressIfRequired(MotionEvent event) {
         if ((event.getAction() == MotionEvent.ACTION_CANCEL)
                 || (event.getAction() == MotionEvent.ACTION_UP)) {
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 909620d..10fef0d 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -40,7 +40,6 @@
 import android.database.sqlite.SQLiteDebug;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
-import android.net.http.AndroidHttpClient;
 import android.os.Bundle;
 import android.os.Debug;
 import android.os.Handler;
@@ -4303,7 +4302,6 @@
     private final void attach(boolean system) {
         sThreadLocal.set(this);
         mSystemThread = system;
-        AndroidHttpClient.setThreadBlocked(true);
         if (!system) {
             android.ddm.DdmHandleAppName.setAppName("<pre-initialized>");
             RuntimeInit.setApplicationObject(mAppThread.asBinder());
@@ -4333,7 +4331,6 @@
 
     private final void detach()
     {
-        AndroidHttpClient.setThreadBlocked(false);
         sThreadLocal.set(null);
     }
 
diff --git a/core/java/android/widget/DatePicker.java b/core/java/android/widget/DatePicker.java
index 5e76cc3..b657e8e 100644
--- a/core/java/android/widget/DatePicker.java
+++ b/core/java/android/widget/DatePicker.java
@@ -26,9 +26,9 @@
 import android.util.SparseArray;
 import android.view.LayoutInflater;
 
+import com.android.common.widget.NumberPicker;
+import com.android.common.widget.NumberPicker.OnChangedListener;
 import com.android.internal.R;
-import com.android.internal.widget.NumberPicker;
-import com.android.internal.widget.NumberPicker.OnChangedListener;
 
 import java.text.DateFormatSymbols;
 import java.text.SimpleDateFormat;
diff --git a/core/java/android/widget/TimePicker.java b/core/java/android/widget/TimePicker.java
index ab4edc5..b87e278 100644
--- a/core/java/android/widget/TimePicker.java
+++ b/core/java/android/widget/TimePicker.java
@@ -25,7 +25,7 @@
 import android.view.View;
 
 import com.android.internal.R;
-import com.android.internal.widget.NumberPicker;
+import com.android.common.widget.NumberPicker;
 
 import java.text.DateFormatSymbols;
 import java.util.Calendar;
@@ -357,4 +357,3 @@
         mOnTimeChangedListener.onTimeChanged(this, getCurrentHour(), getCurrentMinute());
     }
 }
-
diff --git a/core/java/com/google/android/net/GoogleHttpClient.java b/core/java/com/google/android/net/GoogleHttpClient.java
index 7bdc7f8..0337672 100644
--- a/core/java/com/google/android/net/GoogleHttpClient.java
+++ b/core/java/com/google/android/net/GoogleHttpClient.java
@@ -20,12 +20,12 @@
 import android.content.ContentValues;
 import android.content.Context;
 import android.net.TrafficStats;
-import android.net.http.AndroidHttpClient;
 import android.os.Build;
 import android.os.SystemClock;
 import android.provider.Checkin;
 import android.util.Config;
 import android.util.Log;
+import com.android.common.AndroidHttpClient;
 import org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
diff --git a/location/java/com/android/internal/location/GpsXtraDownloader.java b/location/java/com/android/internal/location/GpsXtraDownloader.java
index 33ebce7..02a9f48 100644
--- a/location/java/com/android/internal/location/GpsXtraDownloader.java
+++ b/location/java/com/android/internal/location/GpsXtraDownloader.java
@@ -32,10 +32,12 @@
 
 import android.content.Context;
 import android.net.Proxy;
-import android.net.http.AndroidHttpClient;
 import android.util.Config;
 import android.util.Log;
 
+import com.android.common.AndroidHttpClient;
+
+
 /**
  * A class for downloading GPS XTRA data.
  *
@@ -169,4 +171,3 @@
     }
 
 }
-
diff --git a/preloaded-classes b/preloaded-classes
index 452a8f7..690e729 100644
--- a/preloaded-classes
+++ b/preloaded-classes
@@ -441,10 +441,6 @@
 android.net.Uri$PathSegments
 android.net.Uri$StringUri
 android.net.WebAddress
-android.net.http.AndroidHttpClient
-android.net.http.AndroidHttpClient$1
-android.net.http.AndroidHttpClient$2
-android.net.http.AndroidHttpClientConnection
 android.net.http.CertificateChainValidator
 android.net.http.Connection
 android.net.http.ConnectionThread
@@ -718,7 +714,6 @@
 android.text.util.Linkify$1
 android.text.util.Linkify$4
 android.text.util.Rfc822Tokenizer
-android.text.util.Rfc822Validator
 android.util.AttributeSet
 android.util.DayOfMonthCursor
 android.util.DisplayMetrics
@@ -1077,10 +1072,6 @@
 com.android.internal.widget.DialogTitle
 com.android.internal.widget.EditableInputConnection
 com.android.internal.widget.LockPatternUtils
-com.android.internal.widget.NumberPicker
-com.android.internal.widget.NumberPicker$1
-com.android.internal.widget.NumberPicker$NumberRangeKeyListener
-com.android.internal.widget.NumberPickerButton
 com.android.internal.widget.RotarySelector
 com.android.internal.widget.Smileys
 com.google.android.gles_jni.EGLDisplayImpl
diff --git a/tests/AndroidTests/src/com/android/unit_tests/GoogleHttpClientTest.java b/tests/AndroidTests/src/com/android/unit_tests/GoogleHttpClientTest.java
index d970de3..bf0245c 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/GoogleHttpClientTest.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/GoogleHttpClientTest.java
@@ -17,7 +17,6 @@
 package com.android.unit_tests;
 
 import android.content.ContentResolver;
-import android.net.http.AndroidHttpClient;
 import android.provider.Checkin;
 import android.provider.Settings;
 import android.test.AndroidTestCase;
@@ -64,6 +63,10 @@
         if (mServer != null) mServer.shutdown();
     }
 
+    //
+    // Fix this test to use the new mechanism to indicate that the
+    // Http client is running in the UI thread
+    // bug: http://b/2322326
     @LargeTest
     public void testThreadCheck() throws Exception {
         ContentResolver resolver = getContext().getContentResolver();
@@ -77,7 +80,9 @@
 
             // This is actually an AndroidHttpClient feature...
             // TODO: somehow test that Activity threads have the flag set?
-            AndroidHttpClient.setThreadBlocked(true);
+            // Thus now uses the looper state to determine if it is in a UI 
+            // thread
+            //AndroidHttpClient.setThreadBlocked(true);
 
             try {
                 client.execute(method);
@@ -85,7 +90,7 @@
             } catch (RuntimeException e) {
                 if (!e.toString().contains("forbids HTTP requests")) throw e;
             } finally {
-                AndroidHttpClient.setThreadBlocked(false);
+              // AndroidHttpClient.setThreadBlocked(false);
             }
 
             HttpResponse response = client.execute(method);
diff --git a/tests/AndroidTests/src/com/android/unit_tests/TextUtilsTest.java b/tests/AndroidTests/src/com/android/unit_tests/TextUtilsTest.java
index 7720041..b194896 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/TextUtilsTest.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/TextUtilsTest.java
@@ -16,9 +16,6 @@
 
 package com.android.unit_tests;
 
-import com.google.android.collect.Lists;
-import com.google.android.collect.Maps;
-
 import android.graphics.Paint;
 import android.test.suitebuilder.annotation.LargeTest;
 import android.test.suitebuilder.annotation.SmallTest;
@@ -29,9 +26,12 @@
 import android.text.TextPaint;
 import android.text.TextUtils;
 import android.text.style.StyleSpan;
-import android.text.util.Rfc822Validator;
 import android.test.MoreAsserts;
 
+import com.android.common.Rfc822Validator;
+import com.google.android.collect.Lists;
+import com.google.android.collect.Maps;
+
 import junit.framework.TestCase;
 
 import java.util.List;
diff --git a/tests/SslLoad/src/com/android/sslload/SslLoad.java b/tests/SslLoad/src/com/android/sslload/SslLoad.java
index 9a08024..1470d48 100644
--- a/tests/SslLoad/src/com/android/sslload/SslLoad.java
+++ b/tests/SslLoad/src/com/android/sslload/SslLoad.java
@@ -34,8 +34,8 @@
 import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.TextView;
-import android.net.http.AndroidHttpClient;
 import android.util.Log;
+import com.android.common.AndroidHttpClient;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.ResponseHandler;
 import org.apache.http.client.methods.HttpGet;