Merge "Initial version of dump() for bugreport service" into udc-dev
This commit is contained in:
@@ -44,9 +44,12 @@ import android.util.Slog;
|
|||||||
|
|
||||||
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.util.DumpUtils;
|
||||||
import com.android.server.SystemConfig;
|
import com.android.server.SystemConfig;
|
||||||
|
import com.android.server.utils.Slogf;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
|
import java.io.PrintWriter;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
@@ -56,7 +59,10 @@ import java.util.OptionalInt;
|
|||||||
* <p>Delegates the actualy generation to a native implementation of {@code IDumpstate}.
|
* <p>Delegates the actualy generation to a native implementation of {@code IDumpstate}.
|
||||||
*/
|
*/
|
||||||
class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
||||||
|
|
||||||
private static final String TAG = "BugreportManagerService";
|
private static final String TAG = "BugreportManagerService";
|
||||||
|
private static final boolean DEBUG = false;
|
||||||
|
|
||||||
private static final String BUGREPORT_SERVICE = "bugreportd";
|
private static final String BUGREPORT_SERVICE = "bugreportd";
|
||||||
private static final long DEFAULT_BUGREPORT_SERVICE_TIMEOUT_MILLIS = 30 * 1000;
|
private static final long DEFAULT_BUGREPORT_SERVICE_TIMEOUT_MILLIS = 30 * 1000;
|
||||||
|
|
||||||
@@ -64,7 +70,7 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
|||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final AppOpsManager mAppOps;
|
private final AppOpsManager mAppOps;
|
||||||
private final TelephonyManager mTelephonyManager;
|
private final TelephonyManager mTelephonyManager;
|
||||||
private final ArraySet<String> mBugreportWhitelistedPackages;
|
private final ArraySet<String> mBugreportAllowlistedPackages;
|
||||||
private final BugreportFileManager mBugreportFileManager;
|
private final BugreportFileManager mBugreportFileManager;
|
||||||
|
|
||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
@@ -77,11 +83,8 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
|||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
|
|
||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
private final ArrayMap<Pair<Integer, String>, ArraySet<String>> mBugreportFiles;
|
private final ArrayMap<Pair<Integer, String>, ArraySet<String>> mBugreportFiles =
|
||||||
|
new ArrayMap<>();
|
||||||
BugreportFileManager() {
|
|
||||||
mBugreportFiles = new ArrayMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks that a given file was generated on behalf of the given caller. If the file was
|
* Checks that a given file was generated on behalf of the given caller. If the file was
|
||||||
@@ -159,11 +162,9 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
|||||||
mAppOps = mContext.getSystemService(AppOpsManager.class);
|
mAppOps = mContext.getSystemService(AppOpsManager.class);
|
||||||
mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
|
mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
|
||||||
mBugreportFileManager = new BugreportFileManager();
|
mBugreportFileManager = new BugreportFileManager();
|
||||||
mBugreportWhitelistedPackages =
|
mBugreportAllowlistedPackages = injector.getAllowlistedPackages();
|
||||||
injector.getAllowlistedPackages();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@RequiresPermission(android.Manifest.permission.DUMP)
|
@RequiresPermission(android.Manifest.permission.DUMP)
|
||||||
public void preDumpUiData(String callingPackage) {
|
public void preDumpUiData(String callingPackage) {
|
||||||
@@ -196,6 +197,7 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
|||||||
Binder.restoreCallingIdentity(identity);
|
Binder.restoreCallingIdentity(identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Slogf.i(TAG, "Starting bugreport for %s / %d", callingPackage, callingUid);
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
startBugreportLocked(callingUid, callingPackage, bugreportFd, screenshotFd,
|
startBugreportLocked(callingUid, callingPackage, bugreportFd, screenshotFd,
|
||||||
bugreportMode, bugreportFlags, listener, isScreenshotRequested);
|
bugreportMode, bugreportFlags, listener, isScreenshotRequested);
|
||||||
@@ -208,6 +210,7 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
|||||||
int callingUid = Binder.getCallingUid();
|
int callingUid = Binder.getCallingUid();
|
||||||
enforcePermission(callingPackage, callingUid, true /* checkCarrierPrivileges */);
|
enforcePermission(callingPackage, callingUid, true /* checkCarrierPrivileges */);
|
||||||
|
|
||||||
|
Slogf.i(TAG, "Cancelling bugreport for %s / %d", callingPackage, callingUid);
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
IDumpstate ds = getDumpstateBinderServiceLocked();
|
IDumpstate ds = getDumpstateBinderServiceLocked();
|
||||||
if (ds == null) {
|
if (ds == null) {
|
||||||
@@ -234,6 +237,7 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
|||||||
int callingUid = Binder.getCallingUid();
|
int callingUid = Binder.getCallingUid();
|
||||||
enforcePermission(callingPackage, callingUid, false);
|
enforcePermission(callingPackage, callingUid, false);
|
||||||
|
|
||||||
|
Slogf.i(TAG, "Retrieving bugreport for %s / %d", callingPackage, callingUid);
|
||||||
try {
|
try {
|
||||||
mBugreportFileManager.ensureCallerPreviouslyGeneratedFile(
|
mBugreportFileManager.ensureCallerPreviouslyGeneratedFile(
|
||||||
new Pair<>(callingUid, callingPackage), bugreportFile);
|
new Pair<>(callingUid, callingPackage), bugreportFile);
|
||||||
@@ -299,7 +303,7 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
|||||||
|
|
||||||
// To gain access through the DUMP permission, the OEM has to allow this package explicitly
|
// To gain access through the DUMP permission, the OEM has to allow this package explicitly
|
||||||
// via sysconfig and privileged permissions.
|
// via sysconfig and privileged permissions.
|
||||||
if (mBugreportWhitelistedPackages.contains(callingPackage)
|
if (mBugreportAllowlistedPackages.contains(callingPackage)
|
||||||
&& mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
|
&& mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
|
||||||
== PackageManager.PERMISSION_GRANTED) {
|
== PackageManager.PERMISSION_GRANTED) {
|
||||||
return;
|
return;
|
||||||
@@ -522,6 +526,37 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
|||||||
SystemProperties.set("ctl.stop", BUGREPORT_SERVICE);
|
SystemProperties.set("ctl.stop", BUGREPORT_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresPermission(android.Manifest.permission.DUMP)
|
||||||
|
@Override
|
||||||
|
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||||
|
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
|
||||||
|
|
||||||
|
pw.printf("Allow-listed packages: %s\n", mBugreportAllowlistedPackages);
|
||||||
|
|
||||||
|
synchronized (mLock) {
|
||||||
|
pw.print("Pre-dumped data UID: ");
|
||||||
|
if (mPreDumpedDataUid.isEmpty()) {
|
||||||
|
pw.println("none");
|
||||||
|
} else {
|
||||||
|
pw.println(mPreDumpedDataUid.getAsInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (mBugreportFileManager.mLock) {
|
||||||
|
int numberFiles = mBugreportFileManager.mBugreportFiles.size();
|
||||||
|
pw.printf("%d call%s", numberFiles, (numberFiles > 1 ? "s" : ""));
|
||||||
|
if (numberFiles > 0) {
|
||||||
|
for (int i = 0; i < numberFiles; i++) {
|
||||||
|
Pair<Integer, String> caller = mBugreportFileManager.mBugreportFiles.keyAt(i);
|
||||||
|
ArraySet<String> files = mBugreportFileManager.mBugreportFiles.valueAt(i);
|
||||||
|
pw.printf(" %s/%d: %s\n", caller.second, caller.first, files);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pw.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private int clearBugreportFlag(int flags, @BugreportParams.BugreportFlag int flag) {
|
private int clearBugreportFlag(int flags, @BugreportParams.BugreportFlag int flag) {
|
||||||
flags &= ~flag;
|
flags &= ~flag;
|
||||||
return flags;
|
return flags;
|
||||||
@@ -563,11 +598,15 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProgress(int progress) throws RemoteException {
|
public void onProgress(int progress) throws RemoteException {
|
||||||
|
if (DEBUG) {
|
||||||
|
Slogf.d(TAG, "onProgress: %d", progress);
|
||||||
|
}
|
||||||
mListener.onProgress(progress);
|
mListener.onProgress(progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(int errorCode) throws RemoteException {
|
public void onError(int errorCode) throws RemoteException {
|
||||||
|
Slogf.e(TAG, "onError(): %d", errorCode);
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
mDone = true;
|
mDone = true;
|
||||||
}
|
}
|
||||||
@@ -576,6 +615,7 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFinished(String bugreportFile) throws RemoteException {
|
public void onFinished(String bugreportFile) throws RemoteException {
|
||||||
|
Slogf.e(TAG, "onFinished(): %s", bugreportFile);
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
mDone = true;
|
mDone = true;
|
||||||
}
|
}
|
||||||
@@ -587,11 +627,17 @@ class BugreportManagerServiceImpl extends IDumpstate.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onScreenshotTaken(boolean success) throws RemoteException {
|
public void onScreenshotTaken(boolean success) throws RemoteException {
|
||||||
|
if (DEBUG) {
|
||||||
|
Slogf.d(TAG, "onScreenshotTaken(): %b", success);
|
||||||
|
}
|
||||||
mListener.onScreenshotTaken(success);
|
mListener.onScreenshotTaken(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUiIntensiveBugreportDumpsFinished() throws RemoteException {
|
public void onUiIntensiveBugreportDumpsFinished() throws RemoteException {
|
||||||
|
if (DEBUG) {
|
||||||
|
Slogf.d(TAG, "onUiIntensiveBugreportDumpsFinished()");
|
||||||
|
}
|
||||||
mListener.onUiIntensiveBugreportDumpsFinished();
|
mListener.onUiIntensiveBugreportDumpsFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user