diff options
| author | 2009-12-11 14:13:48 -0800 | |
|---|---|---|
| committer | 2009-12-14 09:24:09 -0800 | |
| commit | 7762d93621f508f4410fd37b5bbdfec0071b0420 (patch) | |
| tree | 1429bfabf0ebbc77c5bd2e924d46530e96db981b | |
| parent | b6ddc7ae3507f0e1ea9a76c76f829bc8b26a292c (diff) | |
Unbundling work
Moved AndroidHttpClient, Rfc822InputFilter, Rfc822Validator
NumberPicker, NumberPickerButton to android-common
---
14 files changed, 59 insertions, 58 deletions
diff --git a/core/java/android/net/http/AndroidHttpClient.java b/common/java/com/android/common/AndroidHttpClient.java index c2013d5bfcd4..6fa6da138682 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.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 diff --git a/core/java/android/text/util/Rfc822InputFilter.java b/common/java/com/android/common/Rfc822InputFilter.java index 8c8b7fc2aba5..6dfdc7bf6166 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 index 6a6bf698360f..087e4256e0fa 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 @@ 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;              } diff --git a/core/java/com/android/internal/widget/NumberPicker.java b/common/java/com/android/common/widget/NumberPicker.java index ae08eca11551..64b436f0c3f8 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 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 +} diff --git a/core/java/com/android/internal/widget/NumberPickerButton.java b/common/java/com/android/common/widget/NumberPickerButton.java index 39f1e2c5175c..f6b6d5dce567 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 @@ 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)) { diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 909620d21dca..10fef0d6bfea 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -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);      } diff --git a/core/java/android/widget/DatePicker.java b/core/java/android/widget/DatePicker.java index 5e76cc3a28af..b657e8ee21a9 100644 --- a/core/java/android/widget/DatePicker.java +++ b/core/java/android/widget/DatePicker.java @@ -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; diff --git a/core/java/android/widget/TimePicker.java b/core/java/android/widget/TimePicker.java index ab4edc5a8a79..b87e278c73b0 100644 --- a/core/java/android/widget/TimePicker.java +++ b/core/java/android/widget/TimePicker.java @@ -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());      }  } - diff --git a/core/java/com/google/android/net/GoogleHttpClient.java b/core/java/com/google/android/net/GoogleHttpClient.java index 7bdc7f86fe61..03376723a03e 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.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; diff --git a/location/java/com/android/internal/location/GpsXtraDownloader.java b/location/java/com/android/internal/location/GpsXtraDownloader.java index 33ebce7f91ea..02a9f4828002 100644 --- a/location/java/com/android/internal/location/GpsXtraDownloader.java +++ b/location/java/com/android/internal/location/GpsXtraDownloader.java @@ -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 {      }  } - diff --git a/preloaded-classes b/preloaded-classes index 04105579527c..a50ccc8ed47b 100644 --- a/preloaded-classes +++ b/preloaded-classes @@ -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 diff --git a/tests/AndroidTests/src/com/android/unit_tests/GoogleHttpClientTest.java b/tests/AndroidTests/src/com/android/unit_tests/GoogleHttpClientTest.java index d970de344caa..bf0245c97d7c 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 @@ 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); diff --git a/tests/AndroidTests/src/com/android/unit_tests/TextUtilsTest.java b/tests/AndroidTests/src/com/android/unit_tests/TextUtilsTest.java index 7720041fccca..b1948962e63b 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.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; diff --git a/tests/SslLoad/src/com/android/sslload/SslLoad.java b/tests/SslLoad/src/com/android/sslload/SslLoad.java index 9a0802404efa..1470d48f1d8b 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;  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;  |