Merge "Move dump() to dumpAsync(), more oneway calls."

This commit is contained in:
Treehugger Robot
2016-12-06 20:15:27 +00:00
committed by Gerrit Code Review
7 changed files with 55 additions and 47 deletions

View File

@@ -16,6 +16,7 @@
package com.android.internal.os; package com.android.internal.os;
import java.io.Closeable;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@@ -32,13 +33,13 @@ import android.util.Slog;
/** /**
* Helper for transferring data through a pipe from a client app. * 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 String TAG = "TransferPipe";
static final boolean DEBUG = false; static final boolean DEBUG = false;
static final long DEFAULT_TIMEOUT = 5000; // 5 seconds static final long DEFAULT_TIMEOUT = 5000; // 5 seconds
final Thread mThread;; final Thread mThread;
final ParcelFileDescriptor[] mFds; final ParcelFileDescriptor[] mFds;
FileDescriptor mOutFd; FileDescriptor mOutFd;
@@ -54,8 +55,13 @@ public final class TransferPipe implements Runnable {
} }
public TransferPipe() throws IOException { public TransferPipe() throws IOException {
this(null);
}
public TransferPipe(String bufferPrefix) throws IOException {
mThread = new Thread(this, "TransferPipe"); mThread = new Thread(this, "TransferPipe");
mFds = ParcelFileDescriptor.createPipe(); mFds = ParcelFileDescriptor.createPipe();
mBufferPrefix = bufferPrefix;
} }
ParcelFileDescriptor getReadFd() { ParcelFileDescriptor getReadFd() {
@@ -70,6 +76,11 @@ public final class TransferPipe implements Runnable {
mBufferPrefix = prefix; 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, static void go(Caller caller, IInterface iface, FileDescriptor out,
String prefix, String[] args) throws IOException, RemoteException { String prefix, String[] args) throws IOException, RemoteException {
go(caller, iface, out, prefix, args, DEFAULT_TIMEOUT); go(caller, iface, out, prefix, args, DEFAULT_TIMEOUT);
@@ -86,12 +97,9 @@ public final class TransferPipe implements Runnable {
return; return;
} }
TransferPipe tp = new TransferPipe(); try (TransferPipe tp = new TransferPipe()) {
try {
caller.go(iface, tp.getWriteFd().getFileDescriptor(), prefix, args); caller.go(iface, tp.getWriteFd().getFileDescriptor(), prefix, args);
tp.go(out, timeout); tp.go(out, timeout);
} finally {
tp.kill();
} }
} }
@@ -111,12 +119,9 @@ public final class TransferPipe implements Runnable {
return; return;
} }
TransferPipe tp = new TransferPipe(); try (TransferPipe tp = new TransferPipe()) {
try {
binder.dumpAsync(tp.getWriteFd().getFileDescriptor(), args); binder.dumpAsync(tp.getWriteFd().getFileDescriptor(), args);
tp.go(out, timeout); 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() { public void kill() {
synchronized (this) { synchronized (this) {
closeFd(0); closeFd(0);

View File

@@ -22,7 +22,7 @@ import android.hardware.location.IFusedLocationHardware;
* Interface definition for Location providers that require FLP services. * Interface definition for Location providers that require FLP services.
* @hide * @hide
*/ */
interface IFusedProvider { oneway interface IFusedProvider {
/** /**
* Provides access to a FusedLocationHardware instance needed for the provider to work. * Provides access to a FusedLocationHardware instance needed for the provider to work.
* *

View File

@@ -24,6 +24,7 @@ import com.android.internal.inputmethod.InputMethodUtils;
import com.android.internal.inputmethod.InputMethodUtils.InputMethodSettings; import com.android.internal.inputmethod.InputMethodUtils.InputMethodSettings;
import com.android.internal.os.HandlerCaller; import com.android.internal.os.HandlerCaller;
import com.android.internal.os.SomeArgs; import com.android.internal.os.SomeArgs;
import com.android.internal.os.TransferPipe;
import com.android.internal.util.FastXmlSerializer; import com.android.internal.util.FastXmlSerializer;
import com.android.internal.view.IInputContext; import com.android.internal.view.IInputContext;
import com.android.internal.view.IInputMethod; import com.android.internal.view.IInputMethod;
@@ -3976,9 +3977,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
if (client != null) { if (client != null) {
pw.flush(); pw.flush();
try { try {
client.client.asBinder().dump(fd, args); TransferPipe.dumpAsync(client.client.asBinder(), fd, args);
} catch (RemoteException e) { } catch (IOException | RemoteException e) {
p.println("Input method client dead: " + e); p.println("Failed to dump input method client: " + e);
} }
} else { } else {
p.println("No input method client."); p.println("No input method client.");
@@ -3992,9 +3993,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
p.println(" "); p.println(" ");
pw.flush(); pw.flush();
try { try {
focusedWindowClient.client.asBinder().dump(fd, args); TransferPipe.dumpAsync(focusedWindowClient.client.asBinder(), fd, args);
} catch (RemoteException e) { } catch (IOException | RemoteException e) {
p.println("Input method client in focused window dead: " + e); p.println("Failed to dump input method client in focused window: " + e);
} }
} }
@@ -4002,9 +4003,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
if (method != null) { if (method != null) {
pw.flush(); pw.flush();
try { try {
method.asBinder().dump(fd, args); TransferPipe.dumpAsync(method.asBinder(), fd, args);
} catch (RemoteException e) { } catch (IOException | RemoteException e) {
p.println("Input method service dead: " + e); p.println("Failed to dump input method service: " + e);
} }
} else { } else {
p.println("No input method service."); p.println("No input method service.");

View File

@@ -43,8 +43,10 @@ import com.android.internal.R;
import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.content.PackageMonitor; import com.android.internal.content.PackageMonitor;
import com.android.internal.os.TransferPipe;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@@ -426,12 +428,9 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
for (INetworkScoreCache scoreCache : getScoreCaches()) { for (INetworkScoreCache scoreCache : getScoreCaches()) {
try { try {
scoreCache.asBinder().dump(fd, args); TransferPipe.dumpAsync(scoreCache.asBinder(), fd, args);
} catch (RemoteException e) { } catch (IOException | RemoteException e) {
writer.println("Unable to dump score cache"); writer.println("Failed to dump score cache: " + e);
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "Unable to dump score cache", e);
}
} }
} }
if (mServiceConnection != null) { if (mServiceConnection != null) {

View File

@@ -17,6 +17,7 @@
package com.android.server.location; package com.android.server.location;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import android.content.Context; import android.content.Context;
@@ -30,6 +31,7 @@ import android.util.Log;
import com.android.internal.location.ProviderProperties; import com.android.internal.location.ProviderProperties;
import com.android.internal.location.ILocationProvider; import com.android.internal.location.ILocationProvider;
import com.android.internal.location.ProviderRequest; import com.android.internal.location.ProviderRequest;
import com.android.internal.os.TransferPipe;
import com.android.server.LocationManagerService; import com.android.server.LocationManagerService;
import com.android.server.ServiceWatcher; import com.android.server.ServiceWatcher;
@@ -230,14 +232,9 @@ public class LocationProviderProxy implements LocationProviderInterface {
pw.flush(); pw.flush();
try { try {
service.asBinder().dump(fd, args); TransferPipe.dumpAsync(service.asBinder(), fd, args);
} catch (RemoteException e) { } catch (IOException | RemoteException e) {
pw.println("service down (RemoteException)"); pw.println("Failed to dump location provider: " + e);
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);
} }
} }

View File

@@ -32,8 +32,10 @@ import android.util.TimedRemoteCaller;
import com.android.internal.app.EphemeralResolverService; import com.android.internal.app.EphemeralResolverService;
import com.android.internal.app.IEphemeralResolver; import com.android.internal.app.IEphemeralResolver;
import com.android.internal.os.TransferPipe;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -85,13 +87,11 @@ final class EphemeralResolverConnection {
.append((mRemoteInstance != null) ? "true" : "false").println(); .append((mRemoteInstance != null) ? "true" : "false").println();
pw.flush(); pw.flush();
try { try {
getRemoteInstanceLazy().asBinder().dump(fd, new String[] { prefix }); TransferPipe.dumpAsync(getRemoteInstanceLazy().asBinder(), fd,
} catch (TimeoutException te) { new String[] { prefix });
/* ignore */ } catch (IOException | TimeoutException | RemoteException e) {
} catch (RemoteException re) { pw.println("Failed to dump remote instance: " + e);
/* ignore */
} }
} }
} }

View File

@@ -43,9 +43,12 @@ import android.printservice.PrintService;
import android.util.Slog; import android.util.Slog;
import android.util.TimedRemoteCaller; import android.util.TimedRemoteCaller;
import com.android.internal.os.TransferPipe;
import libcore.io.IoUtils; import libcore.io.IoUtils;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.List; import java.util.List;
@@ -569,13 +572,11 @@ final class RemotePrintSpooler {
.append((mRemoteInstance != null) ? "true" : "false").println(); .append((mRemoteInstance != null) ? "true" : "false").println();
pw.flush(); pw.flush();
try { try {
getRemoteInstanceLazy().asBinder().dump(fd, new String[]{prefix}); TransferPipe.dumpAsync(getRemoteInstanceLazy().asBinder(), fd,
} catch (TimeoutException te) { new String[] { prefix });
/* ignore */ } catch (IOException | TimeoutException | RemoteException e) {
} catch (RemoteException re) { pw.println("Failed to dump remote instance: " + e);
/* ignore */
} }
} }
} }