diff options
9 files changed, 146 insertions, 68 deletions
diff --git a/core/java/com/android/internal/os/TransferPipe.java b/core/java/com/android/internal/os/TransferPipe.java index e76b395e9e2d..f9041507ffdd 100644 --- a/core/java/com/android/internal/os/TransferPipe.java +++ b/core/java/com/android/internal/os/TransferPipe.java @@ -16,6 +16,7 @@ package com.android.internal.os; +import java.io.Closeable; import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -32,13 +33,13 @@ import android.util.Slog; /** * Helper for transferring data through a pipe from a client app. */ -public final class TransferPipe implements Runnable { +public final class TransferPipe implements Runnable, Closeable { static final String TAG = "TransferPipe"; static final boolean DEBUG = false; static final long DEFAULT_TIMEOUT = 5000; // 5 seconds - final Thread mThread;; + final Thread mThread; final ParcelFileDescriptor[] mFds; FileDescriptor mOutFd; @@ -54,8 +55,13 @@ public final class TransferPipe implements Runnable { } public TransferPipe() throws IOException { + this(null); + } + + public TransferPipe(String bufferPrefix) throws IOException { mThread = new Thread(this, "TransferPipe"); mFds = ParcelFileDescriptor.createPipe(); + mBufferPrefix = bufferPrefix; } ParcelFileDescriptor getReadFd() { @@ -70,6 +76,11 @@ public final class TransferPipe implements Runnable { mBufferPrefix = prefix; } + public static void dumpAsync(IBinder binder, FileDescriptor out, String[] args) + throws IOException, RemoteException { + goDump(binder, out, args); + } + static void go(Caller caller, IInterface iface, FileDescriptor out, String prefix, String[] args) throws IOException, RemoteException { go(caller, iface, out, prefix, args, DEFAULT_TIMEOUT); @@ -86,12 +97,9 @@ public final class TransferPipe implements Runnable { return; } - TransferPipe tp = new TransferPipe(); - try { + try (TransferPipe tp = new TransferPipe()) { caller.go(iface, tp.getWriteFd().getFileDescriptor(), prefix, args); tp.go(out, timeout); - } finally { - tp.kill(); } } @@ -111,12 +119,9 @@ public final class TransferPipe implements Runnable { return; } - TransferPipe tp = new TransferPipe(); - try { + try (TransferPipe tp = new TransferPipe()) { binder.dumpAsync(tp.getWriteFd().getFileDescriptor(), args); tp.go(out, timeout); - } finally { - tp.kill(); } } @@ -173,6 +178,11 @@ public final class TransferPipe implements Runnable { } } + @Override + public void close() { + kill(); + } + public void kill() { synchronized (this) { closeFd(0); diff --git a/location/java/android/location/IFusedProvider.aidl b/location/java/android/location/IFusedProvider.aidl index 8870d2a2a420..e86ad1ac5147 100644 --- a/location/java/android/location/IFusedProvider.aidl +++ b/location/java/android/location/IFusedProvider.aidl @@ -22,11 +22,11 @@ import android.hardware.location.IFusedLocationHardware; * Interface definition for Location providers that require FLP services. * @hide */ -interface IFusedProvider { +oneway interface IFusedProvider { /** * Provides access to a FusedLocationHardware instance needed for the provider to work. * * @param instance The FusedLocationHardware available for the provider to use. */ void onFusedLocationHardwareChange(in IFusedLocationHardware instance); -}
\ No newline at end of file +} diff --git a/services/core/java/com/android/server/InputMethodManagerService.java b/services/core/java/com/android/server/InputMethodManagerService.java index df1b6f51bc33..3ad264d38bb5 100644 --- a/services/core/java/com/android/server/InputMethodManagerService.java +++ b/services/core/java/com/android/server/InputMethodManagerService.java @@ -25,6 +25,7 @@ import com.android.internal.inputmethod.InputMethodUtils; import com.android.internal.inputmethod.InputMethodUtils.InputMethodSettings; import com.android.internal.os.HandlerCaller; import com.android.internal.os.SomeArgs; +import com.android.internal.os.TransferPipe; import com.android.internal.util.FastXmlSerializer; import com.android.internal.view.IInputContext; import com.android.internal.view.IInputMethod; @@ -4030,9 +4031,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub if (client != null) { pw.flush(); try { - client.client.asBinder().dump(fd, args); - } catch (RemoteException e) { - p.println("Input method client dead: " + e); + TransferPipe.dumpAsync(client.client.asBinder(), fd, args); + } catch (IOException | RemoteException e) { + p.println("Failed to dump input method client: " + e); } } else { p.println("No input method client."); @@ -4046,9 +4047,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub p.println(" "); pw.flush(); try { - focusedWindowClient.client.asBinder().dump(fd, args); - } catch (RemoteException e) { - p.println("Input method client in focused window dead: " + e); + TransferPipe.dumpAsync(focusedWindowClient.client.asBinder(), fd, args); + } catch (IOException | RemoteException e) { + p.println("Failed to dump input method client in focused window: " + e); } } @@ -4056,9 +4057,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub if (method != null) { pw.flush(); try { - method.asBinder().dump(fd, args); - } catch (RemoteException e) { - p.println("Input method service dead: " + e); + TransferPipe.dumpAsync(method.asBinder(), fd, args); + } catch (IOException | RemoteException e) { + p.println("Failed to dump input method service: " + e); } } else { p.println("No input method service."); diff --git a/services/core/java/com/android/server/NetworkScoreService.java b/services/core/java/com/android/server/NetworkScoreService.java index 4e969bef864f..4c9ea58e6395 100644 --- a/services/core/java/com/android/server/NetworkScoreService.java +++ b/services/core/java/com/android/server/NetworkScoreService.java @@ -46,8 +46,10 @@ import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.content.PackageMonitor; +import com.android.internal.os.TransferPipe; import java.io.FileDescriptor; +import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; @@ -439,12 +441,9 @@ public class NetworkScoreService extends INetworkScoreService.Stub { for (INetworkScoreCache scoreCache : getScoreCaches()) { try { - scoreCache.asBinder().dump(fd, args); - } catch (RemoteException e) { - writer.println("Unable to dump score cache"); - if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.v(TAG, "Unable to dump score cache", e); - } + TransferPipe.dumpAsync(scoreCache.asBinder(), fd, args); + } catch (IOException | RemoteException e) { + writer.println("Failed to dump score cache: " + e); } } if (mServiceConnection != null) { diff --git a/services/core/java/com/android/server/location/LocationProviderProxy.java b/services/core/java/com/android/server/location/LocationProviderProxy.java index 5eb06ed20b42..b44087c07c16 100644 --- a/services/core/java/com/android/server/location/LocationProviderProxy.java +++ b/services/core/java/com/android/server/location/LocationProviderProxy.java @@ -17,6 +17,7 @@ package com.android.server.location; import java.io.FileDescriptor; +import java.io.IOException; import java.io.PrintWriter; import android.content.Context; @@ -30,6 +31,7 @@ import android.util.Log; import com.android.internal.location.ProviderProperties; import com.android.internal.location.ILocationProvider; import com.android.internal.location.ProviderRequest; +import com.android.internal.os.TransferPipe; import com.android.server.LocationManagerService; import com.android.server.ServiceWatcher; @@ -230,14 +232,9 @@ public class LocationProviderProxy implements LocationProviderInterface { pw.flush(); try { - service.asBinder().dump(fd, args); - } catch (RemoteException e) { - pw.println("service down (RemoteException)"); - Log.w(TAG, e); - } catch (Exception e) { - pw.println("service down (Exception)"); - // never let remote service crash system server - Log.e(TAG, "Exception from " + mServiceWatcher.getBestPackageName(), e); + TransferPipe.dumpAsync(service.asBinder(), fd, args); + } catch (IOException | RemoteException e) { + pw.println("Failed to dump location provider: " + e); } } diff --git a/services/core/java/com/android/server/pm/EphemeralResolverConnection.java b/services/core/java/com/android/server/pm/EphemeralResolverConnection.java index 68b465aaf816..07d98bc0077a 100644 --- a/services/core/java/com/android/server/pm/EphemeralResolverConnection.java +++ b/services/core/java/com/android/server/pm/EphemeralResolverConnection.java @@ -32,7 +32,10 @@ import android.os.SystemClock; import android.os.UserHandle; import android.util.TimedRemoteCaller; +import com.android.internal.os.TransferPipe; + import java.io.FileDescriptor; +import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; @@ -85,13 +88,11 @@ final class EphemeralResolverConnection { .append((mRemoteInstance != null) ? "true" : "false").println(); pw.flush(); - try { - getRemoteInstanceLazy().asBinder().dump(fd, new String[] { prefix }); - } catch (TimeoutException te) { - /* ignore */ - } catch (RemoteException re) { - /* ignore */ + TransferPipe.dumpAsync(getRemoteInstanceLazy().asBinder(), fd, + new String[] { prefix }); + } catch (IOException | TimeoutException | RemoteException e) { + pw.println("Failed to dump remote instance: " + e); } } } diff --git a/services/core/java/com/android/server/pm/Installer.java b/services/core/java/com/android/server/pm/Installer.java index d8f6b80970c0..bff68d85b4e5 100644 --- a/services/core/java/com/android/server/pm/Installer.java +++ b/services/core/java/com/android/server/pm/Installer.java @@ -204,35 +204,70 @@ public final class Installer extends SystemService { outputPath, dexFlags, compilerFilter, volumeUuid, sharedLibraries); } - public boolean mergeProfiles(int uid, String pkgName) throws InstallerException { - return mInstaller.mergeProfiles(uid, pkgName); + public boolean mergeProfiles(int uid, String packageName) throws InstallerException { + checkLock(); + try { + return mInstalld.mergeProfiles(uid, packageName); + } catch (RemoteException | ServiceSpecificException e) { + throw new InstallerException(e.getMessage()); + } } - public boolean dumpProfiles(String gid, String packageName, String codePaths) + public boolean dumpProfiles(int uid, String packageName, String codePaths) throws InstallerException { - return mInstaller.dumpProfiles(gid, packageName, codePaths); + checkLock(); + try { + return mInstalld.dumpProfiles(uid, packageName, codePaths); + } catch (RemoteException | ServiceSpecificException e) { + throw new InstallerException(e.getMessage()); + } } public void idmap(String targetApkPath, String overlayApkPath, int uid) throws InstallerException { - mInstaller.execute("idmap", targetApkPath, overlayApkPath, uid); + checkLock(); + try { + mInstalld.idmap(targetApkPath, overlayApkPath, uid); + } catch (RemoteException | ServiceSpecificException e) { + throw new InstallerException(e.getMessage()); + } } public void rmdex(String codePath, String instructionSet) throws InstallerException { assertValidInstructionSet(instructionSet); - mInstaller.execute("rmdex", codePath, instructionSet); + checkLock(); + try { + mInstalld.rmdex(codePath, instructionSet); + } catch (RemoteException | ServiceSpecificException e) { + throw new InstallerException(e.getMessage()); + } } public void rmPackageDir(String packageDir) throws InstallerException { - mInstaller.execute("rmpackagedir", packageDir); + checkLock(); + try { + mInstalld.rmPackageDir(packageDir); + } catch (RemoteException | ServiceSpecificException e) { + throw new InstallerException(e.getMessage()); + } } - public void clearAppProfiles(String pkgName) throws InstallerException { - mInstaller.execute("clear_app_profiles", pkgName); + public void clearAppProfiles(String packageName) throws InstallerException { + checkLock(); + try { + mInstalld.clearAppProfiles(packageName); + } catch (RemoteException | ServiceSpecificException e) { + throw new InstallerException(e.getMessage()); + } } - public void destroyAppProfiles(String pkgName) throws InstallerException { - mInstaller.execute("destroy_app_profiles", pkgName); + public void destroyAppProfiles(String packageName) throws InstallerException { + checkLock(); + try { + mInstalld.destroyAppProfiles(packageName); + } catch (RemoteException | ServiceSpecificException e) { + throw new InstallerException(e.getMessage()); + } } public void createUserData(String uuid, int userId, int userSerial, int flags) @@ -256,11 +291,21 @@ public final class Installer extends SystemService { public void markBootComplete(String instructionSet) throws InstallerException { assertValidInstructionSet(instructionSet); - mInstaller.execute("markbootcomplete", instructionSet); + checkLock(); + try { + mInstalld.markBootComplete(instructionSet); + } catch (RemoteException | ServiceSpecificException e) { + throw new InstallerException(e.getMessage()); + } } public void freeCache(String uuid, long freeStorageSize) throws InstallerException { - mInstaller.execute("freecache", uuid, freeStorageSize); + checkLock(); + try { + mInstalld.freeCache(uuid, freeStorageSize); + } catch (RemoteException | ServiceSpecificException e) { + throw new InstallerException(e.getMessage()); + } } /** @@ -268,29 +313,54 @@ public final class Installer extends SystemService { * directory to the real location for backward compatibility. Note that no * such symlink is created for 64 bit shared libraries. */ - public void linkNativeLibraryDirectory(String uuid, String dataPath, String nativeLibPath32, + public void linkNativeLibraryDirectory(String uuid, String packageName, String nativeLibPath32, int userId) throws InstallerException { - mInstaller.execute("linklib", uuid, dataPath, nativeLibPath32, userId); + checkLock(); + try { + mInstalld.linkNativeLibraryDirectory(uuid, packageName, nativeLibPath32, userId); + } catch (RemoteException | ServiceSpecificException e) { + throw new InstallerException(e.getMessage()); + } } public void createOatDir(String oatDir, String dexInstructionSet) throws InstallerException { - mInstaller.execute("createoatdir", oatDir, dexInstructionSet); + checkLock(); + try { + mInstalld.createOatDir(oatDir, dexInstructionSet); + } catch (RemoteException | ServiceSpecificException e) { + throw new InstallerException(e.getMessage()); + } } public void linkFile(String relativePath, String fromBase, String toBase) throws InstallerException { - mInstaller.execute("linkfile", relativePath, fromBase, toBase); + checkLock(); + try { + mInstalld.linkFile(relativePath, fromBase, toBase); + } catch (RemoteException | ServiceSpecificException e) { + throw new InstallerException(e.getMessage()); + } } public void moveAb(String apkPath, String instructionSet, String outputPath) throws InstallerException { - mInstaller.execute("move_ab", apkPath, instructionSet, outputPath); + checkLock(); + try { + mInstalld.moveAb(apkPath, instructionSet, outputPath); + } catch (RemoteException | ServiceSpecificException e) { + throw new InstallerException(e.getMessage()); + } } public void deleteOdex(String apkPath, String instructionSet, String outputPath) throws InstallerException { - mInstaller.execute("delete_odex", apkPath, instructionSet, outputPath); + checkLock(); + try { + mInstalld.deleteOdex(apkPath, instructionSet, outputPath); + } catch (RemoteException | ServiceSpecificException e) { + throw new InstallerException(e.getMessage()); + } } private static void assertValidInstructionSet(String instructionSet) diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 56a01737eac2..9102fee89422 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -7530,9 +7530,8 @@ public class PackageManagerService extends IPackageManager.Stub { final int sharedGid = UserHandle.getSharedAppGid(pkg.applicationInfo.uid); try { List<String> allCodePaths = pkg.getAllCodePathsExcludingResourceOnly(); - String gid = Integer.toString(sharedGid); String codePaths = TextUtils.join(";", allCodePaths); - mInstaller.dumpProfiles(gid, packageName, codePaths); + mInstaller.dumpProfiles(sharedGid, packageName, codePaths); } catch (InstallerException e) { Slog.w(TAG, "Failed to dump profiles", e); } diff --git a/services/print/java/com/android/server/print/RemotePrintSpooler.java b/services/print/java/com/android/server/print/RemotePrintSpooler.java index 07b26e83e934..6b919df290bb 100644 --- a/services/print/java/com/android/server/print/RemotePrintSpooler.java +++ b/services/print/java/com/android/server/print/RemotePrintSpooler.java @@ -43,9 +43,12 @@ import android.printservice.PrintService; import android.util.Slog; import android.util.TimedRemoteCaller; +import com.android.internal.os.TransferPipe; + import libcore.io.IoUtils; import java.io.FileDescriptor; +import java.io.IOException; import java.io.PrintWriter; import java.lang.ref.WeakReference; import java.util.List; @@ -572,13 +575,11 @@ final class RemotePrintSpooler { .append((mRemoteInstance != null) ? "true" : "false").println(); pw.flush(); - try { - getRemoteInstanceLazy().asBinder().dump(fd, new String[]{prefix}); - } catch (TimeoutException te) { - /* ignore */ - } catch (RemoteException re) { - /* ignore */ + TransferPipe.dumpAsync(getRemoteInstanceLazy().asBinder(), fd, + new String[] { prefix }); + } catch (IOException | TimeoutException | RemoteException e) { + pw.println("Failed to dump remote instance: " + e); } } } |