Unbundling work
Moved AndroidHttpClient, Rfc822InputFilter, Rfc822Validator NumberPicker, NumberPickerButton to android-common ---
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -220,15 +218,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.)
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)) {
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user