diff options
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/bluetooth/BluetoothAdapter.java | 6 | ||||
-rw-r--r-- | core/java/android/bluetooth/BluetoothInputStream.java | 6 | ||||
-rw-r--r-- | core/java/android/bluetooth/BluetoothOutputStream.java | 4 | ||||
-rw-r--r-- | core/java/android/bluetooth/BluetoothServerSocket.java | 5 | ||||
-rw-r--r-- | core/java/android/bluetooth/BluetoothSocket.java | 102 | ||||
-rw-r--r-- | core/java/android/content/Intent.java | 2 | ||||
-rw-r--r-- | core/java/android/content/SyncManager.java | 10 | ||||
-rw-r--r-- | core/java/android/webkit/BrowserFrame.java | 20 | ||||
-rw-r--r-- | core/java/android/webkit/WebTextView.java | 6 |
9 files changed, 138 insertions, 23 deletions
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java index 6bd2a5a..8975fe2 100644 --- a/core/java/android/bluetooth/BluetoothAdapter.java +++ b/core/java/android/bluetooth/BluetoothAdapter.java @@ -312,7 +312,7 @@ public final class BluetoothAdapter { BluetoothServerSocket socket = new BluetoothServerSocket( BluetoothSocket.TYPE_RFCOMM, true, true, channel); try { - socket.mSocket.bindListenNative(); + socket.mSocket.bindListen(); } catch (IOException e) { try { socket.close(); @@ -334,7 +334,7 @@ public final class BluetoothAdapter { BluetoothServerSocket socket = new BluetoothServerSocket( BluetoothSocket.TYPE_RFCOMM, false, false, port); try { - socket.mSocket.bindListenNative(); + socket.mSocket.bindListen(); } catch (IOException e) { try { socket.close(); @@ -356,7 +356,7 @@ public final class BluetoothAdapter { BluetoothServerSocket socket = new BluetoothServerSocket( BluetoothSocket.TYPE_SCO, false, false, -1); try { - socket.mSocket.bindListenNative(); + socket.mSocket.bindListen(); } catch (IOException e) { try { socket.close(); diff --git a/core/java/android/bluetooth/BluetoothInputStream.java b/core/java/android/bluetooth/BluetoothInputStream.java index c060f32..03af953 100644 --- a/core/java/android/bluetooth/BluetoothInputStream.java +++ b/core/java/android/bluetooth/BluetoothInputStream.java @@ -37,7 +37,7 @@ import java.io.InputStream; * Return number of bytes available before this stream will block. */ public int available() throws IOException { - return mSocket.availableNative(); + return mSocket.available(); } public void close() throws IOException { @@ -57,7 +57,7 @@ import java.io.InputStream; */ public int read() throws IOException { byte b[] = new byte[1]; - int ret = mSocket.readNative(b, 0, 1); + int ret = mSocket.read(b, 0, 1); if (ret == 1) { return (int)b[0] & 0xff; } else { @@ -93,6 +93,6 @@ import java.io.InputStream; if ((offset | length) < 0 || length > b.length - offset) { throw new ArrayIndexOutOfBoundsException("invalid offset or length"); } - return mSocket.readNative(b, offset, length); + return mSocket.read(b, offset, length); } } diff --git a/core/java/android/bluetooth/BluetoothOutputStream.java b/core/java/android/bluetooth/BluetoothOutputStream.java index 7e2ead4..62242a2 100644 --- a/core/java/android/bluetooth/BluetoothOutputStream.java +++ b/core/java/android/bluetooth/BluetoothOutputStream.java @@ -53,7 +53,7 @@ import java.io.OutputStream; public void write(int oneByte) throws IOException { byte b[] = new byte[1]; b[0] = (byte)oneByte; - mSocket.writeNative(b, 0, 1); + mSocket.write(b, 0, 1); } /** @@ -82,6 +82,6 @@ import java.io.OutputStream; if ((offset | count) < 0 || count > b.length - offset) { throw new IndexOutOfBoundsException("invalid offset or length"); } - mSocket.writeNative(b, offset, count); + mSocket.write(b, offset, count); } } diff --git a/core/java/android/bluetooth/BluetoothServerSocket.java b/core/java/android/bluetooth/BluetoothServerSocket.java index e653c23..b650841 100644 --- a/core/java/android/bluetooth/BluetoothServerSocket.java +++ b/core/java/android/bluetooth/BluetoothServerSocket.java @@ -47,6 +47,7 @@ import java.io.IOException; * operations and close the socket. */ public final class BluetoothServerSocket implements Closeable { + /*package*/ final BluetoothSocket mSocket; /** @@ -88,7 +89,7 @@ public final class BluetoothServerSocket implements Closeable { * timeout */ public BluetoothSocket accept(int timeout) throws IOException { - return mSocket.acceptNative(timeout); + return mSocket.accept(timeout); } /** @@ -97,6 +98,6 @@ public final class BluetoothServerSocket implements Closeable { * throw an IOException. */ public void close() throws IOException { - mSocket.closeNative(); + mSocket.close(); } } diff --git a/core/java/android/bluetooth/BluetoothSocket.java b/core/java/android/bluetooth/BluetoothSocket.java index eae0f37..ccbe23e 100644 --- a/core/java/android/bluetooth/BluetoothSocket.java +++ b/core/java/android/bluetooth/BluetoothSocket.java @@ -21,6 +21,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.concurrent.locks.ReentrantReadWriteLock; + /** * A connected or connecting Bluetooth socket. * @@ -63,7 +65,14 @@ public final class BluetoothSocket implements Closeable { private final BluetoothInputStream mInputStream; private final BluetoothOutputStream mOutputStream; - private int mSocketData; /* used by native code only */ + /** prevents all native calls after destroyNative() */ + private boolean mClosed; + + /** protects mClosed */ + private final ReentrantReadWriteLock mLock; + + /** used by native code only */ + private int mSocketData; /** * Construct a BluetoothSocket. @@ -95,6 +104,8 @@ public final class BluetoothSocket implements Closeable { } mInputStream = new BluetoothInputStream(this); mOutputStream = new BluetoothOutputStream(this); + mClosed = false; + mLock = new ReentrantReadWriteLock(); } /** @@ -132,7 +143,13 @@ public final class BluetoothSocket implements Closeable { * @throws IOException on error, for example connection failure */ public void connect() throws IOException { - connectNative(); + mLock.readLock().lock(); + try { + if (mClosed) throw new IOException("socket closed"); + connectNative(); + } finally { + mLock.readLock().unlock(); + } } /** @@ -141,7 +158,24 @@ public final class BluetoothSocket implements Closeable { * throw an IOException. */ public void close() throws IOException { - closeNative(); + // abort blocking operations on the socket + mLock.readLock().lock(); + try { + if (mClosed) return; + abortNative(); + } finally { + mLock.readLock().unlock(); + } + + // all native calls are guarenteed to immediately return after + // abortNative(), so this lock should immediatley acquire + mLock.writeLock().lock(); + try { + mClosed = true; + destroyNative(); + } finally { + mLock.writeLock().unlock(); + } } /** @@ -174,14 +208,64 @@ public final class BluetoothSocket implements Closeable { return mOutputStream; } + /*package*/ void bindListen() throws IOException { + mLock.readLock().lock(); + try { + if (mClosed) throw new IOException("socket closed"); + bindListenNative(); + } finally { + mLock.readLock().unlock(); + } + } + + /*package*/ BluetoothSocket accept(int timeout) throws IOException { + mLock.readLock().lock(); + try { + if (mClosed) throw new IOException("socket closed"); + return acceptNative(timeout); + } finally { + mLock.readLock().unlock(); + } + } + + /*package*/ int available() throws IOException { + mLock.readLock().lock(); + try { + if (mClosed) throw new IOException("socket closed"); + return availableNative(); + } finally { + mLock.readLock().unlock(); + } + } + + /*package*/ int read(byte[] b, int offset, int length) throws IOException { + mLock.readLock().lock(); + try { + if (mClosed) throw new IOException("socket closed"); + return readNative(b, offset, length); + } finally { + mLock.readLock().unlock(); + } + } + + /*package*/ int write(byte[] b, int offset, int length) throws IOException { + mLock.readLock().lock(); + try { + if (mClosed) throw new IOException("socket closed"); + return writeNative(b, offset, length); + } finally { + mLock.readLock().unlock(); + } + } + private native void initSocketNative() throws IOException; private native void initSocketFromFdNative(int fd) throws IOException; private native void connectNative() throws IOException; - /*package*/ native void bindListenNative() throws IOException; - /*package*/ native BluetoothSocket acceptNative(int timeout) throws IOException; - /*package*/ native int availableNative() throws IOException; - /*package*/ native int readNative(byte[] b, int offset, int length) throws IOException; - /*package*/ native int writeNative(byte[] b, int offset, int length) throws IOException; - /*package*/ native void closeNative() throws IOException; + private native void bindListenNative() throws IOException; + private native BluetoothSocket acceptNative(int timeout) throws IOException; + private native int availableNative() throws IOException; + private native int readNative(byte[] b, int offset, int length) throws IOException; + private native int writeNative(byte[] b, int offset, int length) throws IOException; + private native void abortNative() throws IOException; private native void destroyNative() throws IOException; } diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index 2a17672..87a8f39 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -2039,7 +2039,7 @@ public class Intent implements Parcelable { /** * Used as an int extra field in {@link android.content.Intent#ACTION_PACKAGE_CHANGED} * intent to supply the name of the component that changed. - * @hide + * */ public static final String EXTRA_CHANGED_COMPONENT_NAME = "android.intent.extra.changed_component_name"; diff --git a/core/java/android/content/SyncManager.java b/core/java/android/content/SyncManager.java index 4e9e49c..1f3fbf6 100644 --- a/core/java/android/content/SyncManager.java +++ b/core/java/android/content/SyncManager.java @@ -177,6 +177,7 @@ class SyncManager implements OnAccountsUpdatedListener { private BroadcastReceiver mBootCompletedReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { if (!mFactoryTest) { + mBootCompleted = true; AccountManager.get(mContext).addOnAccountsUpdatedListener(SyncManager.this, mSyncHandler, true /* updateImmediately */); } @@ -283,6 +284,8 @@ class SyncManager implements OnAccountsUpdatedListener { private final boolean mFactoryTest; + private volatile boolean mBootCompleted = false; + private ConnectivityManager getConnectivityManager() { synchronized (this) { if (mConnManagerDoNotUseDirectly == null) { @@ -541,6 +544,13 @@ class SyncManager implements OnAccountsUpdatedListener { Bundle extras, long delay, boolean onlyThoseWithUnkownSyncableState) { boolean isLoggable = Log.isLoggable(TAG, Log.VERBOSE); + if (!mBootCompleted) { + if (isLoggable) { + Log.v(TAG, "suppressing scheduleSync() since boot hasn't completed"); + } + return; + } + if (!isSyncEnabled()) { if (isLoggable) { Log.v(TAG, "not syncing because sync is disabled"); diff --git a/core/java/android/webkit/BrowserFrame.java b/core/java/android/webkit/BrowserFrame.java index ce27fd7..599c6b0 100644 --- a/core/java/android/webkit/BrowserFrame.java +++ b/core/java/android/webkit/BrowserFrame.java @@ -112,8 +112,6 @@ class BrowserFrame extends Handler { // create PluginManager with current Context PluginManager.getInstance(context); } - AssetManager am = context.getAssets(); - nativeCreateFrame(w, am, proxy.getBackForwardList()); mSettings = settings; mContext = context; @@ -121,6 +119,9 @@ class BrowserFrame extends Handler { mDatabase = WebViewDatabase.getInstance(context); mWebViewCore = w; + AssetManager am = context.getAssets(); + nativeCreateFrame(w, am, proxy.getBackForwardList()); + if (DebugFlags.BROWSER_FRAME) { Log.v(LOGTAG, "BrowserFrame constructor: this=" + this); } @@ -670,6 +671,7 @@ class BrowserFrame extends Handler { // these ids need to be in sync with enum RAW_RES_ID in WebFrame private static final int NODOMAIN = 1; private static final int LOADERROR = 2; + private static final int DRAWABLEDIR = 3; String getRawResFilename(int id) { int resid; @@ -682,12 +684,26 @@ class BrowserFrame extends Handler { resid = com.android.internal.R.raw.loaderror; break; + case DRAWABLEDIR: + // use one known resource to find the drawable directory + resid = com.android.internal.R.drawable.btn_check_off; + break; + default: Log.e(LOGTAG, "getRawResFilename got incompatible resource ID"); return ""; } TypedValue value = new TypedValue(); mContext.getResources().getValue(resid, value, true); + if (id == DRAWABLEDIR) { + String path = value.string.toString(); + int index = path.lastIndexOf('/'); + if (index < 0) { + Log.e(LOGTAG, "Can't find drawable directory."); + return ""; + } + return path.substring(0, index + 1); + } return value.string.toString(); } diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java index a1f2223..95b3a12 100644 --- a/core/java/android/webkit/WebTextView.java +++ b/core/java/android/webkit/WebTextView.java @@ -697,8 +697,12 @@ import java.util.ArrayList; * Set the selection, and disable our onSelectionChanged action. */ /* package */ void setSelectionFromWebKit(int start, int end) { + if (start < 0 || end < 0) return; + Spannable text = (Spannable) getText(); + int length = text.length(); + if (start > length || end > length) return; mFromWebKit = true; - Selection.setSelection((Spannable) getText(), start, end); + Selection.setSelection(text, start, end); mFromWebKit = false; } |