OSDN Git Service

Unbundling work
authorPaul Westbrook <pwestbro@google.com>
Fri, 11 Dec 2009 22:13:48 +0000 (14:13 -0800)
committerPaul Westbrook <pwestbro@google.com>
Mon, 14 Dec 2009 17:24:09 +0000 (09:24 -0800)
Moved AndroidHttpClient, Rfc822InputFilter, Rfc822Validator
NumberPicker, NumberPickerButton to android-common
---

14 files changed:
common/java/com/android/common/AndroidHttpClient.java [moved from core/java/android/net/http/AndroidHttpClient.java with 96% similarity]
common/java/com/android/common/Rfc822InputFilter.java [moved from core/java/android/text/util/Rfc822InputFilter.java with 75% similarity]
common/java/com/android/common/Rfc822Validator.java [moved from core/java/android/text/util/Rfc822Validator.java with 97% similarity]
common/java/com/android/common/widget/NumberPicker.java [moved from core/java/com/android/internal/widget/NumberPicker.java with 98% similarity]
common/java/com/android/common/widget/NumberPickerButton.java [moved from core/java/com/android/internal/widget/NumberPickerButton.java with 97% similarity]
core/java/android/app/ActivityThread.java
core/java/android/widget/DatePicker.java
core/java/android/widget/TimePicker.java
core/java/com/google/android/net/GoogleHttpClient.java
location/java/com/android/internal/location/GpsXtraDownloader.java
preloaded-classes
tests/AndroidTests/src/com/android/unit_tests/GoogleHttpClientTest.java
tests/AndroidTests/src/com/android/unit_tests/TextUtilsTest.java
tests/SslLoad/src/com/android/sslload/SslLoad.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.util.zip.GZIPOutputStream;
 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 @@ public final class AndroidHttpClient implements HttpClient {
     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 @@ public final class AndroidHttpClient implements HttpClient {
     }
 
     /**
-     * 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
@@ -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;
  * 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 @@ public class Rfc822Validator implements AutoCompleteTextView.Validator {
                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 @@ public class Rfc822Validator implements AutoCompleteTextView.Validator {
              * A local-part can contain multiple atoms, concatenated by
              * periods, so do allow periods here.
              */
-    
+
             if (c <= ' ' || c > '~') {
                 continue;
             }
@@ -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 class NumberPicker extends LinearLayout implements OnClickListener,
     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 class NumberPicker extends LinearLayout implements OnClickListener,
     public int getCurrent() {
         return mCurrent;
     }
-}
\ No newline at end of file
+}
@@ -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 @@ import com.android.internal.R;
 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 class NumberPickerButton extends ImageButton {
     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 @@ public class NumberPickerButton extends ImageButton {
         }
         return super.onKeyUp(keyCode, event);
     }
-    
+
     private void cancelLongpressIfRequired(MotionEvent event) {
         if ((event.getAction() == MotionEvent.ACTION_CANCEL)
                 || (event.getAction() == MotionEvent.ACTION_UP)) {
index 909620d..10fef0d 100644 (file)
@@ -40,7 +40,6 @@ import android.database.sqlite.SQLiteDatabase;
 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 @@ public final class ActivityThread {
     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 @@ public final class ActivityThread {
 
     private final void detach()
     {
-        AndroidHttpClient.setThreadBlocked(false);
         sThreadLocal.set(null);
     }
 
index 5e76cc3..b657e8e 100644 (file)
@@ -26,9 +26,9 @@ import android.util.AttributeSet;
 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;
index ab4edc5..b87e278 100644 (file)
@@ -25,7 +25,7 @@ import android.view.LayoutInflater;
 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 @@ public class TimePicker extends FrameLayout {
         mOnTimeChangedListener.onTimeChanged(this, getCurrentHour(), getCurrentMinute());
     }
 }
-
index 7bdc7f8..0337672 100644 (file)
@@ -20,12 +20,12 @@ import android.content.ContentResolver;
 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;
index 33ebce7..02a9f48 100644 (file)
@@ -32,10 +32,12 @@ import java.util.Random;
 
 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 @@ public class GpsXtraDownloader {
     }
 
 }
-
index 0410557..a50ccc8 100644 (file)
@@ -441,10 +441,6 @@ android.net.Uri$Part
 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
 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.ContactHeaderWidget
 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
index d970de3..bf0245c 100644 (file)
@@ -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 @@ public class GoogleHttpClientTest extends AndroidTestCase {
         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 @@ public class GoogleHttpClientTest extends AndroidTestCase {
 
             // 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 @@ public class GoogleHttpClientTest extends AndroidTestCase {
             } catch (RuntimeException e) {
                 if (!e.toString().contains("forbids HTTP requests")) throw e;
             } finally {
-                AndroidHttpClient.setThreadBlocked(false);
+              // AndroidHttpClient.setThreadBlocked(false);
             }
 
             HttpResponse response = client.execute(method);
index 7720041..b194896 100644 (file)
@@ -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.SpannedString;
 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;
index 9a08024..1470d48 100644 (file)
@@ -34,8 +34,8 @@ import android.view.View;
 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;