You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
refactor source tree organization, switch to meson
This commit is contained in:
668
src/api-impl/android/os/AsyncTask.java
Normal file
668
src/api-impl/android/os/AsyncTask.java
Normal file
File diff suppressed because it is too large
Load Diff
5
src/api-impl/android/os/Binder.java
Normal file
5
src/api-impl/android/os/Binder.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package android.os;
|
||||
|
||||
public class Binder extends IBinder {
|
||||
|
||||
}
|
||||
506
src/api-impl/android/os/Build.java
Normal file
506
src/api-impl/android/os/Build.java
Normal file
File diff suppressed because it is too large
Load Diff
1498
src/api-impl/android/os/Bundle.java
Normal file
1498
src/api-impl/android/os/Bundle.java
Normal file
File diff suppressed because it is too large
Load Diff
7
src/api-impl/android/os/CancellationSignal.java
Normal file
7
src/api-impl/android/os/CancellationSignal.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package android.os;
|
||||
|
||||
//import android.os.ICancellationSignal;
|
||||
|
||||
public final class CancellationSignal {
|
||||
|
||||
}
|
||||
768
src/api-impl/android/os/Environment.java
Normal file
768
src/api-impl/android/os/Environment.java
Normal file
File diff suppressed because it is too large
Load Diff
796
src/api-impl/android/os/Handler.java
Normal file
796
src/api-impl/android/os/Handler.java
Normal file
File diff suppressed because it is too large
Load Diff
19
src/api-impl/android/os/HandlerThread.java
Normal file
19
src/api-impl/android/os/HandlerThread.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package android.os;
|
||||
|
||||
public class HandlerThread extends Thread {
|
||||
String name;
|
||||
|
||||
public HandlerThread() {}
|
||||
|
||||
public HandlerThread(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
// if(name.equals("FlurryAgent")) { return; }
|
||||
}
|
||||
|
||||
public Looper getLooper() {
|
||||
return new Looper();
|
||||
}
|
||||
}
|
||||
5
src/api-impl/android/os/IBinder.java
Normal file
5
src/api-impl/android/os/IBinder.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package android.os;
|
||||
|
||||
public class IBinder {
|
||||
|
||||
}
|
||||
25
src/api-impl/android/os/IMessenger.java
Normal file
25
src/api-impl/android/os/IMessenger.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/* //device/java/android/android/app/IActivityPendingResult.aidl
|
||||
**
|
||||
** Copyright 2007, 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 android.os;
|
||||
|
||||
import android.os.Message;
|
||||
|
||||
/** @hide */
|
||||
interface IMessenger {
|
||||
void send(Message msg);
|
||||
}
|
||||
319
src/api-impl/android/os/Looper.java
Normal file
319
src/api-impl/android/os/Looper.java
Normal file
@@ -0,0 +1,319 @@
|
||||
/*
|
||||
* Copyright (C) 2006 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 android.os;
|
||||
|
||||
import android.util.Log;
|
||||
import android.util.Printer;
|
||||
import android.util.PrefixPrinter;
|
||||
|
||||
/**
|
||||
* Class used to run a message loop for a thread. Threads by default do
|
||||
* not have a message loop associated with them; to create one, call
|
||||
* {@link #prepare} in the thread that is to run the loop, and then
|
||||
* {@link #loop} to have it process messages until the loop is stopped.
|
||||
*
|
||||
* <p>Most interaction with a message loop is through the
|
||||
* {@link Handler} class.
|
||||
*
|
||||
* <p>This is a typical example of the implementation of a Looper thread,
|
||||
* using the separation of {@link #prepare} and {@link #loop} to create an
|
||||
* initial Handler to communicate with the Looper.
|
||||
*
|
||||
* <pre>
|
||||
* class LooperThread extends Thread {
|
||||
* public Handler mHandler;
|
||||
*
|
||||
* public void run() {
|
||||
* Looper.prepare();
|
||||
*
|
||||
* mHandler = new Handler() {
|
||||
* public void handleMessage(Message msg) {
|
||||
* // process incoming messages here
|
||||
* }
|
||||
* };
|
||||
*
|
||||
* Looper.loop();
|
||||
* }
|
||||
* }</pre>
|
||||
*/
|
||||
public final class Looper {
|
||||
private static final String TAG = "Looper";
|
||||
|
||||
// FIXME
|
||||
public Looper() {
|
||||
mQueue = null;
|
||||
mThread = Thread.currentThread();
|
||||
System.out.println("making a fake Looper object, let's hope noone tries to actually use it");
|
||||
}
|
||||
|
||||
// sThreadLocal.get() will return null unless you've called prepare().
|
||||
static final ThreadLocal<Looper> sThreadLocal = new ThreadLocal<Looper>();
|
||||
private static Looper sMainLooper; // guarded by Looper.class
|
||||
|
||||
final MessageQueue mQueue;
|
||||
final Thread mThread;
|
||||
|
||||
private Printer mLogging;
|
||||
|
||||
/** Initialize the current thread as a looper.
|
||||
* This gives you a chance to create handlers that then reference
|
||||
* this looper, before actually starting the loop. Be sure to call
|
||||
* {@link #loop()} after calling this method, and end it by calling
|
||||
* {@link #quit()}.
|
||||
*/
|
||||
public static void prepare() {
|
||||
prepare(true);
|
||||
}
|
||||
|
||||
private static void prepare(boolean quitAllowed) {
|
||||
if (sThreadLocal.get() != null) {
|
||||
throw new RuntimeException("Only one Looper may be created per thread");
|
||||
}
|
||||
sThreadLocal.set(new Looper(/*quitAllowed*/));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the current thread as a looper, marking it as an
|
||||
* application's main looper. The main looper for your application
|
||||
* is created by the Android environment, so you should never need
|
||||
* to call this function yourself. See also: {@link #prepare()}
|
||||
*/
|
||||
public static void prepareMainLooper() {
|
||||
prepare(false);
|
||||
synchronized (Looper.class) {
|
||||
if (sMainLooper != null) {
|
||||
throw new IllegalStateException("The main Looper has already been prepared.");
|
||||
}
|
||||
sMainLooper = myLooper();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the application's main looper, which lives in the main thread of the application.
|
||||
*/
|
||||
public static Looper getMainLooper() {
|
||||
synchronized (Looper.class) {
|
||||
return sMainLooper;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the message queue in this thread. Be sure to call
|
||||
* {@link #quit()} to end the loop.
|
||||
*/
|
||||
public static void loop() {/*
|
||||
final Looper me = myLooper();
|
||||
if (me == null) {
|
||||
throw new RuntimeException("No Looper; Looper.prepare() wasn't called on this thread.");
|
||||
}
|
||||
final MessageQueue queue = me.mQueue;
|
||||
|
||||
// Make sure the identity of this thread is that of the local process,
|
||||
// and keep track of what that identity token actually is.
|
||||
// Binder.clearCallingIdentity();
|
||||
// final long ident = Binder.clearCallingIdentity();
|
||||
|
||||
for (;;) {
|
||||
Message msg = queue.next(); // might block
|
||||
if (msg == null) {
|
||||
// No message indicates that the message queue is quitting.
|
||||
return;
|
||||
}
|
||||
|
||||
// This must be in a local variable, in case a UI event sets the logger
|
||||
Printer logging = me.mLogging;
|
||||
if (logging != null) {
|
||||
logging.println(">>>>> Dispatching to " + msg.target + " " +
|
||||
msg.callback + ": " + msg.what);
|
||||
}
|
||||
|
||||
msg.target.dispatchMessage(msg);
|
||||
|
||||
if (logging != null) {
|
||||
logging.println("<<<<< Finished to " + msg.target + " " + msg.callback);
|
||||
}
|
||||
|
||||
// Make sure that during the course of dispatching the
|
||||
// identity of the thread wasn't corrupted.
|
||||
// final long newIdent = Binder.clearCallingIdentity();
|
||||
/* if (ident != newIdent) {
|
||||
Log.wtf(TAG, "Thread identity changed from 0x"
|
||||
+ Long.toHexString(ident) + " to 0x"
|
||||
+ Long.toHexString(newIdent) + " while dispatching to "
|
||||
+ msg.target.getClass().getName() + " "
|
||||
+ msg.callback + " what=" + msg.what);
|
||||
}* /
|
||||
|
||||
msg.recycle();
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Looper object associated with the current thread. Returns
|
||||
* null if the calling thread is not associated with a Looper.
|
||||
*/
|
||||
public static Looper myLooper() {
|
||||
if(sThreadLocal.get() == null) {
|
||||
prepare(false);
|
||||
}
|
||||
return sThreadLocal.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Control logging of messages as they are processed by this Looper. If
|
||||
* enabled, a log message will be written to <var>printer</var>
|
||||
* at the beginning and ending of each message dispatch, identifying the
|
||||
* target Handler and message contents.
|
||||
*
|
||||
* @param printer A Printer object that will receive log messages, or
|
||||
* null to disable message logging.
|
||||
*/
|
||||
public void setMessageLogging(Printer printer) {
|
||||
mLogging = printer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link MessageQueue} object associated with the current
|
||||
* thread. This must be called from a thread running a Looper, or a
|
||||
* NullPointerException will be thrown.
|
||||
*/
|
||||
public static MessageQueue myQueue() {
|
||||
return myLooper().mQueue;
|
||||
}
|
||||
|
||||
private Looper(boolean quitAllowed) {
|
||||
mQueue = new MessageQueue(quitAllowed);
|
||||
mThread = Thread.currentThread();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current thread is this looper's thread.
|
||||
* @hide
|
||||
*/
|
||||
public boolean isCurrentThread() {
|
||||
return Thread.currentThread() == mThread;
|
||||
}
|
||||
|
||||
/**
|
||||
* Quits the looper.
|
||||
* <p>
|
||||
* Causes the {@link #loop} method to terminate without processing any
|
||||
* more messages in the message queue.
|
||||
* </p><p>
|
||||
* Any attempt to post messages to the queue after the looper is asked to quit will fail.
|
||||
* For example, the {@link Handler#sendMessage(Message)} method will return false.
|
||||
* </p><p class="note">
|
||||
* Using this method may be unsafe because some messages may not be delivered
|
||||
* before the looper terminates. Consider using {@link #quitSafely} instead to ensure
|
||||
* that all pending work is completed in an orderly manner.
|
||||
* </p>
|
||||
*
|
||||
* @see #quitSafely
|
||||
*/
|
||||
public void quit() {
|
||||
mQueue.quit(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Quits the looper safely.
|
||||
* <p>
|
||||
* Causes the {@link #loop} method to terminate as soon as all remaining messages
|
||||
* in the message queue that are already due to be delivered have been handled.
|
||||
* However pending delayed messages with due times in the future will not be
|
||||
* delivered before the loop terminates.
|
||||
* </p><p>
|
||||
* Any attempt to post messages to the queue after the looper is asked to quit will fail.
|
||||
* For example, the {@link Handler#sendMessage(Message)} method will return false.
|
||||
* </p>
|
||||
*/
|
||||
public void quitSafely() {
|
||||
mQueue.quit(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts a synchronization barrier to the Looper's message queue.
|
||||
*
|
||||
* Message processing occurs as usual until the message queue encounters the
|
||||
* synchronization barrier that has been posted. When the barrier is encountered,
|
||||
* later synchronous messages in the queue are stalled (prevented from being executed)
|
||||
* until the barrier is released by calling {@link #removeSyncBarrier} and specifying
|
||||
* the token that identifies the synchronization barrier.
|
||||
*
|
||||
* This method is used to immediately postpone execution of all subsequently posted
|
||||
* synchronous messages until a condition is met that releases the barrier.
|
||||
* Asynchronous messages (see {@link Message#isAsynchronous} are exempt from the barrier
|
||||
* and continue to be processed as usual.
|
||||
*
|
||||
* This call must be always matched by a call to {@link #removeSyncBarrier} with
|
||||
* the same token to ensure that the message queue resumes normal operation.
|
||||
* Otherwise the application will probably hang!
|
||||
*
|
||||
* @return A token that uniquely identifies the barrier. This token must be
|
||||
* passed to {@link #removeSyncBarrier} to release the barrier.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public int postSyncBarrier() {
|
||||
return mQueue.enqueueSyncBarrier(SystemClock.uptimeMillis());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes a synchronization barrier.
|
||||
*
|
||||
* @param token The synchronization barrier token that was returned by
|
||||
* {@link #postSyncBarrier}.
|
||||
*
|
||||
* @throws IllegalStateException if the barrier was not found.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public void removeSyncBarrier(int token) {
|
||||
mQueue.removeSyncBarrier(token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Thread associated with this Looper.
|
||||
*/
|
||||
public Thread getThread() {
|
||||
return mThread;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public MessageQueue getQueue() {
|
||||
return mQueue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this looper's thread is currently idle, waiting for new work
|
||||
* to do. This is intrinsically racy, since its state can change before you get
|
||||
* the result back.
|
||||
* @hide
|
||||
*/
|
||||
public boolean isIdling() {
|
||||
return mQueue.isIdling();
|
||||
}
|
||||
|
||||
public void dump(Printer pw, String prefix) {
|
||||
pw.println(prefix + toString());
|
||||
mQueue.dump(pw, prefix + " ");
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Looper (" + mThread.getName() + ", tid " + mThread.getId()
|
||||
+ ") {" + Integer.toHexString(System.identityHashCode(this)) + "}";
|
||||
}
|
||||
}
|
||||
345
src/api-impl/android/os/MemoryFile.java
Normal file
345
src/api-impl/android/os/MemoryFile.java
Normal file
@@ -0,0 +1,345 @@
|
||||
/*
|
||||
* 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 android.os;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
|
||||
/**
|
||||
* MemoryFile is a wrapper for the Linux ashmem driver.
|
||||
* MemoryFiles are backed by shared memory, which can be optionally
|
||||
* set to be purgeable.
|
||||
* Purgeable files may have their contents reclaimed by the kernel
|
||||
* in low memory conditions (only if allowPurging is set to true).
|
||||
* After a file is purged, attempts to read or write the file will
|
||||
* cause an IOException to be thrown.
|
||||
*/
|
||||
public class MemoryFile
|
||||
{
|
||||
private static String TAG = "MemoryFile";
|
||||
|
||||
// mmap(2) protection flags from <sys/mman.h>
|
||||
private static final int PROT_READ = 0x1;
|
||||
private static final int PROT_WRITE = 0x2;
|
||||
|
||||
private static native FileDescriptor native_open(String name, int length) throws IOException;
|
||||
// returns memory address for ashmem region
|
||||
private static native int native_mmap(FileDescriptor fd, int length, int mode)
|
||||
throws IOException;
|
||||
private static native void native_munmap(int addr, int length) throws IOException;
|
||||
private static native void native_close(FileDescriptor fd);
|
||||
private static native int native_read(FileDescriptor fd, int address, byte[] buffer,
|
||||
int srcOffset, int destOffset, int count, boolean isUnpinned) throws IOException;
|
||||
private static native void native_write(FileDescriptor fd, int address, byte[] buffer,
|
||||
int srcOffset, int destOffset, int count, boolean isUnpinned) throws IOException;
|
||||
private static native void native_pin(FileDescriptor fd, boolean pin) throws IOException;
|
||||
private static native int native_get_size(FileDescriptor fd) throws IOException;
|
||||
|
||||
private FileDescriptor mFD; // ashmem file descriptor
|
||||
private int mAddress; // address of ashmem memory
|
||||
private int mLength; // total length of our ashmem region
|
||||
private boolean mAllowPurging = false; // true if our ashmem region is unpinned
|
||||
|
||||
/**
|
||||
* Allocates a new ashmem region. The region is initially not purgable.
|
||||
*
|
||||
* @param name optional name for the file (can be null).
|
||||
* @param length of the memory file in bytes.
|
||||
* @throws IOException if the memory file could not be created.
|
||||
*/
|
||||
public MemoryFile(String name, int length) throws IOException {
|
||||
mLength = length;
|
||||
mFD = native_open(name, length);
|
||||
if (length > 0) {
|
||||
mAddress = native_mmap(mFD, length, PROT_READ | PROT_WRITE);
|
||||
} else {
|
||||
mAddress = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the memory file. If there are no other open references to the memory
|
||||
* file, it will be deleted.
|
||||
*/
|
||||
public void close() {
|
||||
deactivate();
|
||||
if (!isClosed()) {
|
||||
native_close(mFD);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unmaps the memory file from the process's memory space, but does not close it.
|
||||
* After this method has been called, read and write operations through this object
|
||||
* will fail, but {@link #getFileDescriptor()} will still return a valid file descriptor.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
void deactivate() {
|
||||
if (!isDeactivated()) {
|
||||
try {
|
||||
native_munmap(mAddress, mLength);
|
||||
mAddress = 0;
|
||||
} catch (IOException ex) {
|
||||
Log.e(TAG, ex.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the memory file has been deactivated.
|
||||
*/
|
||||
private boolean isDeactivated() {
|
||||
return mAddress == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the memory file has been closed.
|
||||
*/
|
||||
private boolean isClosed() {
|
||||
return !mFD.valid();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() {
|
||||
if (!isClosed()) {
|
||||
Log.e(TAG, "MemoryFile.finalize() called while ashmem still open");
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the memory file.
|
||||
*
|
||||
* @return file length.
|
||||
*/
|
||||
public int length() {
|
||||
return mLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is memory file purging enabled?
|
||||
*
|
||||
* @return true if the file may be purged.
|
||||
*/
|
||||
public boolean isPurgingAllowed() {
|
||||
return mAllowPurging;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables purging of the memory file.
|
||||
*
|
||||
* @param allowPurging true if the operating system can purge the contents
|
||||
* of the file in low memory situations
|
||||
* @return previous value of allowPurging
|
||||
*/
|
||||
synchronized public boolean allowPurging(boolean allowPurging) throws IOException {
|
||||
boolean oldValue = mAllowPurging;
|
||||
if (oldValue != allowPurging) {
|
||||
native_pin(mFD, !allowPurging);
|
||||
mAllowPurging = allowPurging;
|
||||
}
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new InputStream for reading from the memory file.
|
||||
*
|
||||
@return InputStream
|
||||
*/
|
||||
public InputStream getInputStream() {
|
||||
return new MemoryInputStream();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new OutputStream for writing to the memory file.
|
||||
*
|
||||
@return OutputStream
|
||||
*/
|
||||
public OutputStream getOutputStream() {
|
||||
return new MemoryOutputStream();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads bytes from the memory file.
|
||||
* Will throw an IOException if the file has been purged.
|
||||
*
|
||||
* @param buffer byte array to read bytes into.
|
||||
* @param srcOffset offset into the memory file to read from.
|
||||
* @param destOffset offset into the byte array buffer to read into.
|
||||
* @param count number of bytes to read.
|
||||
* @return number of bytes read.
|
||||
* @throws IOException if the memory file has been purged or deactivated.
|
||||
*/
|
||||
public int readBytes(byte[] buffer, int srcOffset, int destOffset, int count)
|
||||
throws IOException {
|
||||
if (isDeactivated()) {
|
||||
throw new IOException("Can't read from deactivated memory file.");
|
||||
}
|
||||
if (destOffset < 0 || destOffset > buffer.length || count < 0
|
||||
|| count > buffer.length - destOffset
|
||||
|| srcOffset < 0 || srcOffset > mLength
|
||||
|| count > mLength - srcOffset) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
return native_read(mFD, mAddress, buffer, srcOffset, destOffset, count, mAllowPurging);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write bytes to the memory file.
|
||||
* Will throw an IOException if the file has been purged.
|
||||
*
|
||||
* @param buffer byte array to write bytes from.
|
||||
* @param srcOffset offset into the byte array buffer to write from.
|
||||
* @param destOffset offset into the memory file to write to.
|
||||
* @param count number of bytes to write.
|
||||
* @throws IOException if the memory file has been purged or deactivated.
|
||||
*/
|
||||
public void writeBytes(byte[] buffer, int srcOffset, int destOffset, int count)
|
||||
throws IOException {
|
||||
if (isDeactivated()) {
|
||||
throw new IOException("Can't write to deactivated memory file.");
|
||||
}
|
||||
if (srcOffset < 0 || srcOffset > buffer.length || count < 0
|
||||
|| count > buffer.length - srcOffset
|
||||
|| destOffset < 0 || destOffset > mLength
|
||||
|| count > mLength - destOffset) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
native_write(mFD, mAddress, buffer, srcOffset, destOffset, count, mAllowPurging);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a FileDescriptor for the memory file.
|
||||
*
|
||||
* The returned file descriptor is not duplicated.
|
||||
*
|
||||
* @throws IOException If the memory file has been closed.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public FileDescriptor getFileDescriptor() throws IOException {
|
||||
return mFD;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the memory file that the file descriptor refers to,
|
||||
* or -1 if the file descriptor does not refer to a memory file.
|
||||
*
|
||||
* @throws IOException If <code>fd</code> is not a valid file descriptor.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static int getSize(FileDescriptor fd) throws IOException {
|
||||
return native_get_size(fd);
|
||||
}
|
||||
|
||||
private class MemoryInputStream extends InputStream {
|
||||
|
||||
private int mMark = 0;
|
||||
private int mOffset = 0;
|
||||
private byte[] mSingleByte;
|
||||
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
if (mOffset >= mLength) {
|
||||
return 0;
|
||||
}
|
||||
return mLength - mOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean markSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mark(int readlimit) {
|
||||
mMark = mOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() throws IOException {
|
||||
mOffset = mMark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
if (mSingleByte == null) {
|
||||
mSingleByte = new byte[1];
|
||||
}
|
||||
int result = read(mSingleByte, 0, 1);
|
||||
if (result != 1) {
|
||||
return -1;
|
||||
}
|
||||
return mSingleByte[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte buffer[], int offset, int count) throws IOException {
|
||||
if (offset < 0 || count < 0 || offset + count > buffer.length) {
|
||||
// readBytes() also does this check, but we need to do it before
|
||||
// changing count.
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
count = Math.min(count, available());
|
||||
if (count < 1) {
|
||||
return -1;
|
||||
}
|
||||
int result = readBytes(buffer, mOffset, offset, count);
|
||||
if (result > 0) {
|
||||
mOffset += result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long skip(long n) throws IOException {
|
||||
if (mOffset + n > mLength) {
|
||||
n = mLength - mOffset;
|
||||
}
|
||||
mOffset += n;
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
private class MemoryOutputStream extends OutputStream {
|
||||
|
||||
private int mOffset = 0;
|
||||
private byte[] mSingleByte;
|
||||
|
||||
@Override
|
||||
public void write(byte buffer[], int offset, int count) throws IOException {
|
||||
writeBytes(buffer, offset, mOffset, count);
|
||||
mOffset += count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int oneByte) throws IOException {
|
||||
if (mSingleByte == null) {
|
||||
mSingleByte = new byte[1];
|
||||
}
|
||||
mSingleByte[0] = (byte)oneByte;
|
||||
write(mSingleByte, 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
479
src/api-impl/android/os/Message.java
Normal file
479
src/api-impl/android/os/Message.java
Normal file
@@ -0,0 +1,479 @@
|
||||
/*
|
||||
* Copyright (C) 2006 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 android.os;
|
||||
|
||||
/**
|
||||
*
|
||||
* Defines a message containing a description and arbitrary data object that can be
|
||||
* sent to a {@link Handler}. This object contains two extra int fields and an
|
||||
* extra object field that allow you to not do allocations in many cases.
|
||||
*
|
||||
* <p class="note">While the constructor of Message is public, the best way to get
|
||||
* one of these is to call {@link #obtain Message.obtain()} or one of the
|
||||
* {@link Handler#obtainMessage Handler.obtainMessage()} methods, which will pull
|
||||
* them from a pool of recycled objects.</p>
|
||||
*/
|
||||
public final class Message {
|
||||
/**
|
||||
* User-defined message code so that the recipient can identify
|
||||
* what this message is about. Each {@link Handler} has its own name-space
|
||||
* for message codes, so you do not need to worry about yours conflicting
|
||||
* with other handlers.
|
||||
*/
|
||||
public int what;
|
||||
|
||||
/**
|
||||
* arg1 and arg2 are lower-cost alternatives to using
|
||||
* {@link #setData(Bundle) setData()} if you only need to store a
|
||||
* few integer values.
|
||||
*/
|
||||
public int arg1;
|
||||
|
||||
/**
|
||||
* arg1 and arg2 are lower-cost alternatives to using
|
||||
* {@link #setData(Bundle) setData()} if you only need to store a
|
||||
* few integer values.
|
||||
*/
|
||||
public int arg2;
|
||||
|
||||
/**
|
||||
* An arbitrary object to send to the recipient. When using
|
||||
* {@link Messenger} to send the message across processes this can only
|
||||
* be non-null if it contains a Parcelable of a framework class (not one
|
||||
* implemented by the application). For other data transfer use
|
||||
* {@link #setData}.
|
||||
*
|
||||
* <p>Note that Parcelable objects here are not supported prior to
|
||||
* the {@link android.os.Build.VERSION_CODES#FROYO} release.
|
||||
*/
|
||||
public Object obj;
|
||||
|
||||
/**
|
||||
* Optional Messenger where replies to this message can be sent. The
|
||||
* semantics of exactly how this is used are up to the sender and
|
||||
* receiver.
|
||||
*/
|
||||
public Messenger replyTo;
|
||||
|
||||
/** If set message is in use */
|
||||
/*package*/ static final int FLAG_IN_USE = 1 << 0;
|
||||
|
||||
/** If set message is asynchronous */
|
||||
/*package*/ static final int FLAG_ASYNCHRONOUS = 1 << 1;
|
||||
|
||||
/** Flags to clear in the copyFrom method */
|
||||
/*package*/ static final int FLAGS_TO_CLEAR_ON_COPY_FROM = FLAG_IN_USE;
|
||||
|
||||
/*package*/ int flags;
|
||||
|
||||
/*package*/ long when;
|
||||
|
||||
/*package*/ Bundle data;
|
||||
|
||||
/*package*/ Handler target;
|
||||
|
||||
/*package*/ Runnable callback;
|
||||
|
||||
// sometimes we store linked lists of these things
|
||||
/*package*/ Message next;
|
||||
|
||||
private static final Object sPoolSync = new Object();
|
||||
private static Message sPool;
|
||||
private static int sPoolSize = 0;
|
||||
|
||||
private static final int MAX_POOL_SIZE = 50;
|
||||
|
||||
/**
|
||||
* Return a new Message instance from the global pool. Allows us to
|
||||
* avoid allocating new objects in many cases.
|
||||
*/
|
||||
public static Message obtain() {
|
||||
synchronized (sPoolSync) {
|
||||
if (sPool != null) {
|
||||
Message m = sPool;
|
||||
sPool = m.next;
|
||||
m.next = null;
|
||||
sPoolSize--;
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return new Message();
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #obtain()}, but copies the values of an existing
|
||||
* message (including its target) into the new one.
|
||||
* @param orig Original message to copy.
|
||||
* @return A Message object from the global pool.
|
||||
*/
|
||||
public static Message obtain(Message orig) {
|
||||
Message m = obtain();
|
||||
m.what = orig.what;
|
||||
m.arg1 = orig.arg1;
|
||||
m.arg2 = orig.arg2;
|
||||
m.obj = orig.obj;
|
||||
m.replyTo = orig.replyTo;
|
||||
if (orig.data != null) {
|
||||
m.data = new Bundle(orig.data);
|
||||
}
|
||||
m.target = orig.target;
|
||||
m.callback = orig.callback;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #obtain()}, but sets the value for the <em>target</em> member on the Message returned.
|
||||
* @param h Handler to assign to the returned Message object's <em>target</em> member.
|
||||
* @return A Message object from the global pool.
|
||||
*/
|
||||
public static Message obtain(Handler h) {
|
||||
Message m = obtain();
|
||||
m.target = h;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #obtain(Handler)}, but assigns a callback Runnable on
|
||||
* the Message that is returned.
|
||||
* @param h Handler to assign to the returned Message object's <em>target</em> member.
|
||||
* @param callback Runnable that will execute when the message is handled.
|
||||
* @return A Message object from the global pool.
|
||||
*/
|
||||
public static Message obtain(Handler h, Runnable callback) {
|
||||
Message m = obtain();
|
||||
m.target = h;
|
||||
m.callback = callback;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #obtain()}, but sets the values for both <em>target</em> and
|
||||
* <em>what</em> members on the Message.
|
||||
* @param h Value to assign to the <em>target</em> member.
|
||||
* @param what Value to assign to the <em>what</em> member.
|
||||
* @return A Message object from the global pool.
|
||||
*/
|
||||
public static Message obtain(Handler h, int what) {
|
||||
Message m = obtain();
|
||||
m.target = h;
|
||||
m.what = what;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #obtain()}, but sets the values of the <em>target</em>, <em>what</em>, and <em>obj</em>
|
||||
* members.
|
||||
* @param h The <em>target</em> value to set.
|
||||
* @param what The <em>what</em> value to set.
|
||||
* @param obj The <em>object</em> method to set.
|
||||
* @return A Message object from the global pool.
|
||||
*/
|
||||
public static Message obtain(Handler h, int what, Object obj) {
|
||||
Message m = obtain();
|
||||
m.target = h;
|
||||
m.what = what;
|
||||
m.obj = obj;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #obtain()}, but sets the values of the <em>target</em>, <em>what</em>,
|
||||
* <em>arg1</em>, and <em>arg2</em> members.
|
||||
*
|
||||
* @param h The <em>target</em> value to set.
|
||||
* @param what The <em>what</em> value to set.
|
||||
* @param arg1 The <em>arg1</em> value to set.
|
||||
* @param arg2 The <em>arg2</em> value to set.
|
||||
* @return A Message object from the global pool.
|
||||
*/
|
||||
public static Message obtain(Handler h, int what, int arg1, int arg2) {
|
||||
Message m = obtain();
|
||||
m.target = h;
|
||||
m.what = what;
|
||||
m.arg1 = arg1;
|
||||
m.arg2 = arg2;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #obtain()}, but sets the values of the <em>target</em>, <em>what</em>,
|
||||
* <em>arg1</em>, <em>arg2</em>, and <em>obj</em> members.
|
||||
*
|
||||
* @param h The <em>target</em> value to set.
|
||||
* @param what The <em>what</em> value to set.
|
||||
* @param arg1 The <em>arg1</em> value to set.
|
||||
* @param arg2 The <em>arg2</em> value to set.
|
||||
* @param obj The <em>obj</em> value to set.
|
||||
* @return A Message object from the global pool.
|
||||
*/
|
||||
public static Message obtain(Handler h, int what,
|
||||
int arg1, int arg2, Object obj) {
|
||||
Message m = obtain();
|
||||
m.target = h;
|
||||
m.what = what;
|
||||
m.arg1 = arg1;
|
||||
m.arg2 = arg2;
|
||||
m.obj = obj;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Message instance to the global pool. You MUST NOT touch
|
||||
* the Message after calling this function -- it has effectively been
|
||||
* freed.
|
||||
*/
|
||||
public void recycle() {
|
||||
clearForRecycle();
|
||||
|
||||
synchronized (sPoolSync) {
|
||||
if (sPoolSize < MAX_POOL_SIZE) {
|
||||
next = sPool;
|
||||
sPool = this;
|
||||
sPoolSize++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this message like o. Performs a shallow copy of the data field.
|
||||
* Does not copy the linked list fields, nor the timestamp or
|
||||
* target/callback of the original message.
|
||||
*/
|
||||
public void copyFrom(Message o) {
|
||||
this.flags = o.flags & ~FLAGS_TO_CLEAR_ON_COPY_FROM;
|
||||
this.what = o.what;
|
||||
this.arg1 = o.arg1;
|
||||
this.arg2 = o.arg2;
|
||||
this.obj = o.obj;
|
||||
this.replyTo = o.replyTo;
|
||||
|
||||
if (o.data != null) {
|
||||
this.data = (Bundle) o.data.clone();
|
||||
} else {
|
||||
this.data = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the targeted delivery time of this message, in milliseconds.
|
||||
*/
|
||||
public long getWhen() {
|
||||
return when;
|
||||
}
|
||||
|
||||
public void setTarget(Handler target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the a {@link android.os.Handler Handler} implementation that
|
||||
* will receive this message. The object must implement
|
||||
* {@link android.os.Handler#handleMessage(android.os.Message)
|
||||
* Handler.handleMessage()}. Each Handler has its own name-space for
|
||||
* message codes, so you do not need to
|
||||
* worry about yours conflicting with other handlers.
|
||||
*/
|
||||
public Handler getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve callback object that will execute when this message is handled.
|
||||
* This object must implement Runnable. This is called by
|
||||
* the <em>target</em> {@link Handler} that is receiving this Message to
|
||||
* dispatch it. If
|
||||
* not set, the message will be dispatched to the receiving Handler's
|
||||
* {@link Handler#handleMessage(Message Handler.handleMessage())}.
|
||||
*/
|
||||
public Runnable getCallback() {
|
||||
return callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a Bundle of arbitrary data associated with this
|
||||
* event, lazily creating it if necessary. Set this value by calling
|
||||
* {@link #setData(Bundle)}. Note that when transferring data across
|
||||
* processes via {@link Messenger}, you will need to set your ClassLoader
|
||||
* on the Bundle via {@link Bundle#setClassLoader(ClassLoader)
|
||||
* Bundle.setClassLoader()} so that it can instantiate your objects when
|
||||
* you retrieve them.
|
||||
* @see #peekData()
|
||||
* @see #setData(Bundle)
|
||||
*/
|
||||
public Bundle getData() {
|
||||
if (data == null) {
|
||||
data = new Bundle();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like getData(), but does not lazily create the Bundle. A null
|
||||
* is returned if the Bundle does not already exist. See
|
||||
* {@link #getData} for further information on this.
|
||||
* @see #getData()
|
||||
* @see #setData(Bundle)
|
||||
*/
|
||||
public Bundle peekData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a Bundle of arbitrary data values. Use arg1 and arg1 members
|
||||
* as a lower cost way to send a few simple integer values, if you can.
|
||||
* @see #getData()
|
||||
* @see #peekData()
|
||||
*/
|
||||
public void setData(Bundle data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends this Message to the Handler specified by {@link #getTarget}.
|
||||
* Throws a null pointer exception if this field has not been set.
|
||||
*/
|
||||
public void sendToTarget() {
|
||||
target.sendMessage(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the message is asynchronous.
|
||||
*
|
||||
* Asynchronous messages represent interrupts or events that do not require global ordering
|
||||
* with represent to synchronous messages. Asynchronous messages are not subject to
|
||||
* the synchronization barriers introduced by {@link MessageQueue#enqueueSyncBarrier(long)}.
|
||||
*
|
||||
* @return True if the message is asynchronous.
|
||||
*
|
||||
* @see #setAsynchronous(boolean)
|
||||
* @see MessageQueue#enqueueSyncBarrier(long)
|
||||
* @see MessageQueue#removeSyncBarrier(int)
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public boolean isAsynchronous() {
|
||||
return (flags & FLAG_ASYNCHRONOUS) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the message is asynchronous.
|
||||
*
|
||||
* Asynchronous messages represent interrupts or events that do not require global ordering
|
||||
* with represent to synchronous messages. Asynchronous messages are not subject to
|
||||
* the synchronization barriers introduced by {@link MessageQueue#enqueueSyncBarrier(long)}.
|
||||
*
|
||||
* @param async True if the message is asynchronous.
|
||||
*
|
||||
* @see #isAsynchronous()
|
||||
* @see MessageQueue#enqueueSyncBarrier(long)
|
||||
* @see MessageQueue#removeSyncBarrier(int)
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public void setAsynchronous(boolean async) {
|
||||
if (async) {
|
||||
flags |= FLAG_ASYNCHRONOUS;
|
||||
} else {
|
||||
flags &= ~FLAG_ASYNCHRONOUS;
|
||||
}
|
||||
}
|
||||
|
||||
/*package*/ void clearForRecycle() {
|
||||
flags = 0;
|
||||
what = 0;
|
||||
arg1 = 0;
|
||||
arg2 = 0;
|
||||
obj = null;
|
||||
replyTo = null;
|
||||
when = 0;
|
||||
target = null;
|
||||
callback = null;
|
||||
data = null;
|
||||
}
|
||||
|
||||
/*package*/ boolean isInUse() {
|
||||
return ((flags & FLAG_IN_USE) == FLAG_IN_USE);
|
||||
}
|
||||
|
||||
/*package*/ void markInUse() {
|
||||
flags |= FLAG_IN_USE;
|
||||
}
|
||||
|
||||
/** Constructor (but the preferred way to get a Message is to call {@link #obtain() Message.obtain()}).
|
||||
*/
|
||||
public Message() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(SystemClock.uptimeMillis());
|
||||
}
|
||||
|
||||
String toString(long now) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("{ when=");
|
||||
b.append(when);
|
||||
b.append(" - ");
|
||||
b.append(now);
|
||||
|
||||
if (target != null) {
|
||||
if (callback != null) {
|
||||
b.append(" callback=");
|
||||
b.append(callback.getClass().getName());
|
||||
} else {
|
||||
b.append(" what=");
|
||||
b.append(what);
|
||||
}
|
||||
|
||||
if (arg1 != 0) {
|
||||
b.append(" arg1=");
|
||||
b.append(arg1);
|
||||
}
|
||||
|
||||
if (arg2 != 0) {
|
||||
b.append(" arg2=");
|
||||
b.append(arg2);
|
||||
}
|
||||
|
||||
if (obj != null) {
|
||||
b.append(" obj=");
|
||||
b.append(obj);
|
||||
}
|
||||
|
||||
b.append(" target=");
|
||||
b.append(target.getClass().getName());
|
||||
} else {
|
||||
b.append(" barrier=");
|
||||
b.append(arg1);
|
||||
}
|
||||
|
||||
b.append(" }");
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
559
src/api-impl/android/os/MessageQueue.java
Normal file
559
src/api-impl/android/os/MessageQueue.java
Normal file
File diff suppressed because it is too large
Load Diff
86
src/api-impl/android/os/Messenger.java
Normal file
86
src/api-impl/android/os/Messenger.java
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2006 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 android.os;
|
||||
|
||||
/**
|
||||
* Reference to a Handler, which others can use to send messages to it.
|
||||
* This allows for the implementation of message-based communication across
|
||||
* processes, by creating a Messenger pointing to a Handler in one process,
|
||||
* and handing that Messenger to another process.
|
||||
*/
|
||||
public final class Messenger {
|
||||
private final IMessenger mTarget;
|
||||
|
||||
/**
|
||||
* Create a new Messenger pointing to the given Handler. Any Message
|
||||
* objects sent through this Messenger will appear in the Handler as if
|
||||
* {@link Handler#sendMessage(Message) Handler.sendMessage(Message)} had
|
||||
* been called directly.
|
||||
*
|
||||
* @param target The Handler that will receive sent messages.
|
||||
*/
|
||||
public Messenger(Handler target) {
|
||||
mTarget = target.getIMessenger();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a Message to this Messenger's Handler.
|
||||
*
|
||||
* @param message The Message to send. Usually retrieved through
|
||||
* {@link Message#obtain() Message.obtain()}.
|
||||
*
|
||||
* @throws RemoteException Throws DeadObjectException if the target
|
||||
* Handler no longer exists.
|
||||
*/
|
||||
public void send(Message message) throws RemoteException {
|
||||
mTarget.send(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the IBinder that this Messenger is using to communicate with
|
||||
* its associated Handler.
|
||||
*
|
||||
* @return Returns the IBinder backing this Messenger.
|
||||
*/
|
||||
public IBinder getBinder() {
|
||||
return null;//mTarget.asBinder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparison operator on two Messenger objects, such that true
|
||||
* is returned then they both point to the same Handler.
|
||||
*/
|
||||
public boolean equals(Object otherObj) {
|
||||
/*if (otherObj == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return mTarget.asBinder().equals(((Messenger)otherObj)
|
||||
.mTarget.asBinder());
|
||||
} catch (ClassCastException e) {
|
||||
}*/
|
||||
return false;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return 0;//mTarget.asBinder().hashCode();
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
976
src/api-impl/android/os/ParcelFileDescriptor.java
Normal file
976
src/api-impl/android/os/ParcelFileDescriptor.java
Normal file
File diff suppressed because it is too large
Load Diff
5
src/api-impl/android/os/Parcelable.java
Normal file
5
src/api-impl/android/os/Parcelable.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package android.os;
|
||||
|
||||
public interface Parcelable {
|
||||
|
||||
}
|
||||
176
src/api-impl/android/os/PatternMatcher.java
Normal file
176
src/api-impl/android/os/PatternMatcher.java
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* 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 android.os;
|
||||
|
||||
/**
|
||||
* A simple pattern matcher, which is safe to use on untrusted data: it does
|
||||
* not provide full reg-exp support, only simple globbing that can not be
|
||||
* used maliciously.
|
||||
*/
|
||||
public class PatternMatcher {
|
||||
/**
|
||||
* Pattern type: the given pattern must exactly match the string it is
|
||||
* tested against.
|
||||
*/
|
||||
public static final int PATTERN_LITERAL = 0;
|
||||
|
||||
/**
|
||||
* Pattern type: the given pattern must match the
|
||||
* beginning of the string it is tested against.
|
||||
*/
|
||||
public static final int PATTERN_PREFIX = 1;
|
||||
|
||||
/**
|
||||
* Pattern type: the given pattern is interpreted with a
|
||||
* simple glob syntax for matching against the string it is tested against.
|
||||
* In this syntax, you can use the '*' character to match against zero or
|
||||
* more occurrences of the character immediately before. If the
|
||||
* character before it is '.' it will match any character. The character
|
||||
* '\' can be used as an escape. This essentially provides only the '*'
|
||||
* wildcard part of a normal regexp.
|
||||
*/
|
||||
public static final int PATTERN_SIMPLE_GLOB = 2;
|
||||
|
||||
private final String mPattern;
|
||||
private final int mType;
|
||||
|
||||
public PatternMatcher(String pattern, int type) {
|
||||
mPattern = pattern;
|
||||
mType = type;
|
||||
}
|
||||
|
||||
public final String getPath() {
|
||||
return mPattern;
|
||||
}
|
||||
|
||||
public final int getType() {
|
||||
return mType;
|
||||
}
|
||||
|
||||
public boolean match(String str) {
|
||||
return matchPattern(mPattern, str, mType);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String type = "? ";
|
||||
switch (mType) {
|
||||
case PATTERN_LITERAL:
|
||||
type = "LITERAL: ";
|
||||
break;
|
||||
case PATTERN_PREFIX:
|
||||
type = "PREFIX: ";
|
||||
break;
|
||||
case PATTERN_SIMPLE_GLOB:
|
||||
type = "GLOB: ";
|
||||
break;
|
||||
}
|
||||
return "PatternMatcher{" + type + mPattern + "}";
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static boolean matchPattern(String pattern, String match, int type) {
|
||||
if (match == null) return false;
|
||||
if (type == PATTERN_LITERAL) {
|
||||
return pattern.equals(match);
|
||||
} if (type == PATTERN_PREFIX) {
|
||||
return match.startsWith(pattern);
|
||||
} else if (type != PATTERN_SIMPLE_GLOB) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final int NP = pattern.length();
|
||||
if (NP <= 0) {
|
||||
return match.length() <= 0;
|
||||
}
|
||||
final int NM = match.length();
|
||||
int ip = 0, im = 0;
|
||||
char nextChar = pattern.charAt(0);
|
||||
while ((ip<NP) && (im<NM)) {
|
||||
char c = nextChar;
|
||||
ip++;
|
||||
nextChar = ip < NP ? pattern.charAt(ip) : 0;
|
||||
final boolean escaped = (c == '\\');
|
||||
if (escaped) {
|
||||
c = nextChar;
|
||||
ip++;
|
||||
nextChar = ip < NP ? pattern.charAt(ip) : 0;
|
||||
}
|
||||
if (nextChar == '*') {
|
||||
if (!escaped && c == '.') {
|
||||
if (ip >= (NP-1)) {
|
||||
// at the end with a pattern match, so
|
||||
// all is good without checking!
|
||||
return true;
|
||||
}
|
||||
ip++;
|
||||
nextChar = pattern.charAt(ip);
|
||||
// Consume everything until the next character in the
|
||||
// pattern is found.
|
||||
if (nextChar == '\\') {
|
||||
ip++;
|
||||
nextChar = ip < NP ? pattern.charAt(ip) : 0;
|
||||
}
|
||||
do {
|
||||
if (match.charAt(im) == nextChar) {
|
||||
break;
|
||||
}
|
||||
im++;
|
||||
} while (im < NM);
|
||||
if (im == NM) {
|
||||
// Whoops, the next character in the pattern didn't
|
||||
// exist in the match.
|
||||
return false;
|
||||
}
|
||||
ip++;
|
||||
nextChar = ip < NP ? pattern.charAt(ip) : 0;
|
||||
im++;
|
||||
} else {
|
||||
// Consume only characters matching the one before '*'.
|
||||
do {
|
||||
if (match.charAt(im) != c) {
|
||||
break;
|
||||
}
|
||||
im++;
|
||||
} while (im < NM);
|
||||
ip++;
|
||||
nextChar = ip < NP ? pattern.charAt(ip) : 0;
|
||||
}
|
||||
} else {
|
||||
if (c != '.' && match.charAt(im) != c) return false;
|
||||
im++;
|
||||
}
|
||||
}
|
||||
|
||||
if (ip >= NP && im >= NM) {
|
||||
// Reached the end of both strings, all is good!
|
||||
return true;
|
||||
}
|
||||
|
||||
// One last check: we may have finished the match string, but still
|
||||
// have a '.*' at the end of the pattern, which should still count
|
||||
// as a match.
|
||||
if (ip == NP-2 && pattern.charAt(ip) == '.'
|
||||
&& pattern.charAt(ip+1) == '*') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
784
src/api-impl/android/os/Process.java
Normal file
784
src/api-impl/android/os/Process.java
Normal file
File diff suppressed because it is too large
Load Diff
31
src/api-impl/android/os/RemoteException.java
Normal file
31
src/api-impl/android/os/RemoteException.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2006 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 android.os;
|
||||
import android.util.AndroidException;
|
||||
|
||||
/**
|
||||
* Parent exception for all Binder remote-invocation errors
|
||||
*/
|
||||
public class RemoteException extends AndroidException {
|
||||
public RemoteException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public RemoteException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user