diff options
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/app/ActivityThread.java | 24 | ||||
-rw-r--r-- | core/java/android/app/backup/BackupAgent.java | 2 | ||||
-rw-r--r-- | core/java/android/net/LocalServerSocket.java | 10 | ||||
-rw-r--r-- | core/java/android/os/Debug.java | 2 | ||||
-rw-r--r-- | core/java/android/printservice/PrintService.java | 8 | ||||
-rw-r--r-- | core/java/android/provider/Settings.java | 9 | ||||
-rw-r--r-- | core/java/com/android/internal/os/WrapperInit.java | 3 | ||||
-rw-r--r-- | core/java/com/android/internal/os/ZygoteConnection.java | 21 | ||||
-rw-r--r-- | core/java/com/android/internal/os/ZygoteInit.java | 167 |
9 files changed, 78 insertions, 168 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 17a31f3..6233676 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -4161,22 +4161,24 @@ public final class ActivityThread { final void handleDispatchPackageBroadcast(int cmd, String[] packages) { boolean hasPkgInfo = false; if (packages != null) { - for (int i=packages.length-1; i>=0; i--) { - //Slog.i(TAG, "Cleaning old package: " + packages[i]); - if (!hasPkgInfo) { - WeakReference<LoadedApk> ref; - ref = mPackages.get(packages[i]); - if (ref != null && ref.get() != null) { - hasPkgInfo = true; - } else { - ref = mResourcePackages.get(packages[i]); + synchronized (mResourcesManager) { + for (int i=packages.length-1; i>=0; i--) { + //Slog.i(TAG, "Cleaning old package: " + packages[i]); + if (!hasPkgInfo) { + WeakReference<LoadedApk> ref; + ref = mPackages.get(packages[i]); if (ref != null && ref.get() != null) { hasPkgInfo = true; + } else { + ref = mResourcePackages.get(packages[i]); + if (ref != null && ref.get() != null) { + hasPkgInfo = true; + } } } + mPackages.remove(packages[i]); + mResourcePackages.remove(packages[i]); } - mPackages.remove(packages[i]); - mResourcePackages.remove(packages[i]); } } ApplicationPackageManager.handlePackageBroadcast(cmd, packages, diff --git a/core/java/android/app/backup/BackupAgent.java b/core/java/android/app/backup/BackupAgent.java index 87d785a..1b1e600 100644 --- a/core/java/android/app/backup/BackupAgent.java +++ b/core/java/android/app/backup/BackupAgent.java @@ -105,7 +105,7 @@ import java.util.concurrent.CountDownLatch; */ public abstract class BackupAgent extends ContextWrapper { private static final String TAG = "BackupAgent"; - private static final boolean DEBUG = true; + private static final boolean DEBUG = false; /** @hide */ public static final int TYPE_EOF = 0; diff --git a/core/java/android/net/LocalServerSocket.java b/core/java/android/net/LocalServerSocket.java index a36203b..9464222 100644 --- a/core/java/android/net/LocalServerSocket.java +++ b/core/java/android/net/LocalServerSocket.java @@ -20,12 +20,8 @@ import java.io.IOException; import java.io.FileDescriptor; /** - * non-standard class for creating inbound UNIX-domain socket - * on the Android platform, this is created in the Linux non-filesystem - * namespace. - * - * On simulator platforms, this may be created in a temporary directory on - * the filesystem + * Non-standard class for creating an inbound UNIX-domain socket + * in the Linux abstract namespace. */ public class LocalServerSocket { private final LocalSocketImpl impl; @@ -35,7 +31,7 @@ public class LocalServerSocket { private static final int LISTEN_BACKLOG = 50; /** - * Crewates a new server socket listening at specified name. + * Creates a new server socket listening at specified name. * On the Android platform, the name is created in the Linux * abstract namespace (instead of on the filesystem). * diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java index 344dc91..9377def 100644 --- a/core/java/android/os/Debug.java +++ b/core/java/android/os/Debug.java @@ -104,7 +104,7 @@ public final class Debug /** * This class is used to retrieved various statistics about the memory mappings for this - * process. The returns info broken down by dalvik, native, and other. All results are in kB. + * process. The returned info is broken down by dalvik, native, and other. All results are in kB. */ public static class MemoryInfo implements Parcelable { /** The proportional set size for dalvik heap. (Doesn't include other Dalvik overhead.) */ diff --git a/core/java/android/printservice/PrintService.java b/core/java/android/printservice/PrintService.java index c5aee7b..ae95854 100644 --- a/core/java/android/printservice/PrintService.java +++ b/core/java/android/printservice/PrintService.java @@ -386,7 +386,7 @@ public abstract class PrintService extends Service { @Override public void setClient(IPrintServiceClient client) { - mHandler.obtainMessage(ServiceHandler.MSG_SET_CLEINT, client) + mHandler.obtainMessage(ServiceHandler.MSG_SET_CLIENT, client) .sendToTarget(); } @@ -414,7 +414,7 @@ public abstract class PrintService extends Service { public static final int MSG_STOP_PRINTER_STATE_TRACKING = 7; public static final int MSG_ON_PRINTJOB_QUEUED = 8; public static final int MSG_ON_REQUEST_CANCEL_PRINTJOB = 9; - public static final int MSG_SET_CLEINT = 10; + public static final int MSG_SET_CLIENT = 10; public ServiceHandler(Looper looper) { super(looper, null, true); @@ -528,9 +528,9 @@ public abstract class PrintService extends Service { onPrintJobQueued(new PrintJob(printJobInfo, mClient)); } break; - case MSG_SET_CLEINT: { + case MSG_SET_CLIENT: { if (DEBUG) { - Log.i(LOG_TAG, "MSG_SET_CLEINT " + Log.i(LOG_TAG, "MSG_SET_CLIENT " + getPackageName()); } mClient = (IPrintServiceClient) message.obj; diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 79e84d9..d08758b 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -6343,14 +6343,7 @@ public final class Settings { public static final String CALL_AUTO_RETRY = "call_auto_retry"; /** - * The preferred network mode 7 = Global - * 6 = EvDo only - * 5 = CDMA w/o EvDo - * 4 = CDMA / EvDo auto - * 3 = GSM / WCDMA auto - * 2 = WCDMA only - * 1 = GSM only - * 0 = GSM / WCDMA preferred + * See RIL_PreferredNetworkType in ril.h * @hide */ public static final String PREFERRED_NETWORK_MODE = diff --git a/core/java/com/android/internal/os/WrapperInit.java b/core/java/com/android/internal/os/WrapperInit.java index 3301cbe..af821ba 100644 --- a/core/java/com/android/internal/os/WrapperInit.java +++ b/core/java/com/android/internal/os/WrapperInit.java @@ -62,7 +62,8 @@ public class WrapperInit { // wrapper that it directly forked). if (fdNum != 0) { try { - FileDescriptor fd = ZygoteInit.createFileDescriptor(fdNum); + FileDescriptor fd = new FileDescriptor(); + fd.setInt$(fdNum); DataOutputStream os = new DataOutputStream(new FileOutputStream(fd)); os.writeInt(Process.myPid()); os.close(); diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java index 24820bc..c03938a 100644 --- a/core/java/com/android/internal/os/ZygoteConnection.java +++ b/core/java/com/android/internal/os/ZygoteConnection.java @@ -16,6 +16,11 @@ package com.android.internal.os; +import static android.system.OsConstants.O_CLOEXEC; +import static android.system.OsConstants.STDERR_FILENO; +import static android.system.OsConstants.STDIN_FILENO; +import static android.system.OsConstants.STDOUT_FILENO; + import android.net.Credentials; import android.net.LocalSocket; import android.os.Process; @@ -186,10 +191,9 @@ class ZygoteConnection { } if (parsedArgs.runtimeInit && parsedArgs.invokeWith != null) { - FileDescriptor[] pipeFds = Os.pipe(); + FileDescriptor[] pipeFds = Os.pipe2(O_CLOEXEC); childPipeFd = pipeFds[1]; serverPipeFd = pipeFds[0]; - ZygoteInit.setCloseOnExec(serverPipeFd, true); } /** @@ -224,8 +228,6 @@ class ZygoteConnection { parsedArgs.debugFlags, rlimits, parsedArgs.mountExternal, parsedArgs.seInfo, parsedArgs.niceName, fdsToClose, parsedArgs.instructionSet, parsedArgs.appDataDir); - } catch (IOException ex) { - logAndPrintError(newStderr, "Exception creating pipe", ex); } catch (ErrnoException ex) { logAndPrintError(newStderr, "Exception creating pipe", ex); } catch (IllegalArgumentException ex) { @@ -857,14 +859,15 @@ class ZygoteConnection { if (descriptors != null) { try { - ZygoteInit.reopenStdio(descriptors[0], - descriptors[1], descriptors[2]); + Os.dup2(descriptors[0], STDIN_FILENO); + Os.dup2(descriptors[1], STDOUT_FILENO); + Os.dup2(descriptors[2], STDERR_FILENO); for (FileDescriptor fd: descriptors) { IoUtils.closeQuietly(fd); } newStderr = System.err; - } catch (IOException ex) { + } catch (ErrnoException ex) { Log.e(TAG, "Error reopening stdio", ex); } } @@ -990,8 +993,8 @@ class ZygoteConnection { private void setChildPgid(int pid) { // Try to move the new child into the peer's process group. try { - ZygoteInit.setpgid(pid, ZygoteInit.getpgid(peer.getPid())); - } catch (IOException ex) { + Os.setpgid(pid, Os.getpgid(peer.getPid())); + } catch (ErrnoException ex) { // This exception is expected in the case where // the peer is not in our session // TODO get rid of this log message in the case where diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java index 62088fa..0fa9a97 100644 --- a/core/java/com/android/internal/os/ZygoteInit.java +++ b/core/java/com/android/internal/os/ZygoteInit.java @@ -16,6 +16,8 @@ package com.android.internal.os; +import static android.system.OsConstants.POLLIN; +import static android.system.OsConstants.POLLOUT; import static android.system.OsConstants.S_IRWXG; import static android.system.OsConstants.S_IRWXO; @@ -32,6 +34,7 @@ import android.os.Trace; import android.system.ErrnoException; import android.system.Os; import android.system.OsConstants; +import android.system.StructPollfd; import android.util.EventLog; import android.util.Log; import android.util.Slog; @@ -165,8 +168,9 @@ public class ZygoteInit { } try { - sServerSocket = new LocalServerSocket( - createFileDescriptor(fileDesc)); + FileDescriptor fd = new FileDescriptor(); + fd.setInt$(fileDesc); + sServerSocket = new LocalServerSocket(fd); } catch (IOException ex) { throw new RuntimeException( "Error binding to local socket '" + fileDesc + "'", ex); @@ -225,26 +229,6 @@ public class ZygoteInit { private static final int ROOT_UID = 0; private static final int ROOT_GID = 0; - /** - * Sets effective user ID. - */ - private static void setEffectiveUser(int uid) { - int errno = setreuid(ROOT_UID, uid); - if (errno != 0) { - Log.e(TAG, "setreuid() failed. errno: " + errno); - } - } - - /** - * Sets effective group ID. - */ - private static void setEffectiveGroup(int gid) { - int errno = setregid(ROOT_GID, gid); - if (errno != 0) { - Log.e(TAG, "setregid() failed. errno: " + errno); - } - } - static void preload() { Log.d(TAG, "begin preload"); preloadClasses(); @@ -292,8 +276,12 @@ public class ZygoteInit { long startTime = SystemClock.uptimeMillis(); // Drop root perms while running static initializers. - setEffectiveGroup(UNPRIVILEGED_GID); - setEffectiveUser(UNPRIVILEGED_UID); + try { + Os.setregid(ROOT_GID, UNPRIVILEGED_GID); + Os.setreuid(ROOT_UID, UNPRIVILEGED_UID); + } catch (ErrnoException ex) { + throw new RuntimeException("Failed to drop root", ex); + } // Alter the target heap utilization. With explicit GCs this // is not likely to have any effect. @@ -348,8 +336,12 @@ public class ZygoteInit { runtime.preloadDexCaches(); // Bring back root. We'll need it later. - setEffectiveUser(ROOT_UID); - setEffectiveGroup(ROOT_GID); + try { + Os.setreuid(ROOT_UID, ROOT_UID); + Os.setregid(ROOT_GID, ROOT_GID); + } catch (ErrnoException ex) { + throw new RuntimeException("Failed to restore root", ex); + } } } @@ -698,119 +690,42 @@ public class ZygoteInit { private static void runSelectLoop(String abiList) throws MethodAndArgsCaller { ArrayList<FileDescriptor> fds = new ArrayList<FileDescriptor>(); ArrayList<ZygoteConnection> peers = new ArrayList<ZygoteConnection>(); - FileDescriptor[] fdArray = new FileDescriptor[4]; fds.add(sServerSocket.getFileDescriptor()); peers.add(null); while (true) { - int index; - + StructPollfd[] pollFds = new StructPollfd[fds.size()]; + for (int i = 0; i < pollFds.length; ++i) { + pollFds[i] = new StructPollfd(); + pollFds[i].fd = fds.get(i); + pollFds[i].events = (short) POLLIN; + } try { - fdArray = fds.toArray(fdArray); - index = selectReadable(fdArray); - } catch (IOException ex) { - throw new RuntimeException("Error in select()", ex); + Os.poll(pollFds, -1); + } catch (ErrnoException ex) { + throw new RuntimeException("poll failed", ex); } - - if (index < 0) { - throw new RuntimeException("Error in select()"); - } else if (index == 0) { - ZygoteConnection newPeer = acceptCommandPeer(abiList); - peers.add(newPeer); - fds.add(newPeer.getFileDesciptor()); - } else { - boolean done; - done = peers.get(index).runOnce(); - - if (done) { - peers.remove(index); - fds.remove(index); + for (int i = pollFds.length - 1; i >= 0; --i) { + if ((pollFds[i].revents & POLLIN) == 0) { + continue; + } + if (i == 0) { + ZygoteConnection newPeer = acceptCommandPeer(abiList); + peers.add(newPeer); + fds.add(newPeer.getFileDesciptor()); + } else { + boolean done = peers.get(i).runOnce(); + if (done) { + peers.remove(i); + fds.remove(i); + } } } } } /** - * The Linux syscall "setreuid()" - * @param ruid real uid - * @param euid effective uid - * @return 0 on success, non-zero errno on fail - */ - static native int setreuid(int ruid, int euid); - - /** - * The Linux syscall "setregid()" - * @param rgid real gid - * @param egid effective gid - * @return 0 on success, non-zero errno on fail - */ - static native int setregid(int rgid, int egid); - - /** - * Invokes the linux syscall "setpgid" - * - * @param pid pid to change - * @param pgid new process group of pid - * @return 0 on success or non-zero errno on fail - */ - static native int setpgid(int pid, int pgid); - - /** - * Invokes the linux syscall "getpgid" - * - * @param pid pid to query - * @return pgid of pid in question - * @throws IOException on error - */ - static native int getpgid(int pid) throws IOException; - - /** - * Invokes the syscall dup2() to copy the specified descriptors into - * stdin, stdout, and stderr. The existing stdio descriptors will be - * closed and errors during close will be ignored. The specified - * descriptors will also remain open at their original descriptor numbers, - * so the caller may want to close the original descriptors. - * - * @param in new stdin - * @param out new stdout - * @param err new stderr - * @throws IOException - */ - static native void reopenStdio(FileDescriptor in, - FileDescriptor out, FileDescriptor err) throws IOException; - - /** - * Toggles the close-on-exec flag for the specified file descriptor. - * - * @param fd non-null; file descriptor - * @param flag desired close-on-exec flag state - * @throws IOException - */ - static native void setCloseOnExec(FileDescriptor fd, boolean flag) - throws IOException; - - /** - * Invokes select() on the provider array of file descriptors (selecting - * for readability only). Array elements of null are ignored. - * - * @param fds non-null; array of readable file descriptors - * @return index of descriptor that is now readable or -1 for empty array. - * @throws IOException if an error occurs - */ - static native int selectReadable(FileDescriptor[] fds) throws IOException; - - /** - * Creates a file descriptor from an int fd. - * - * @param fd integer OS file descriptor - * @return non-null; FileDescriptor instance - * @throws IOException if fd is invalid - */ - static native FileDescriptor createFileDescriptor(int fd) - throws IOException; - - /** * Class not instantiable. */ private ZygoteInit() { |