Set a default wtf handler for system_server at initialization

In case the ActivityManagerService hasn't started yet.

Bug: 153704326
Bug: 153598920
Test: Manual - induce wtf logs in early-booted services
Change-Id: I2b444cf70d9126963084ab15f9cd17fe5b464529
This commit is contained in:
Jing Ji
2020-04-16 15:02:50 -07:00
parent da4751452e
commit 6674e0d654
3 changed files with 121 additions and 4 deletions

View File

@@ -21,6 +21,8 @@ import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL;
import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_HIGH;
import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_NORMAL;
import static android.os.IServiceManager.DUMP_FLAG_PROTO;
import static android.os.Process.SYSTEM_UID;
import static android.os.Process.myPid;
import static android.view.Display.DEFAULT_DISPLAY;
import static com.android.server.utils.TimingsTraceAndSlog.SYSTEM_SERVER_TIMING_TAG;
@@ -29,6 +31,7 @@ import android.annotation.NonNull;
import android.annotation.StringRes;
import android.app.ActivityThread;
import android.app.AppCompatCallbacks;
import android.app.ApplicationErrorReport;
import android.app.INotificationManager;
import android.app.SystemServiceRegistry;
import android.app.usage.UsageStatsManagerInternal;
@@ -53,6 +56,7 @@ import android.os.Debug;
import android.os.Environment;
import android.os.FactoryTest;
import android.os.FileUtils;
import android.os.IBinder;
import android.os.IIncidentManager;
import android.os.Looper;
import android.os.Message;
@@ -67,16 +71,19 @@ import android.os.UserHandle;
import android.os.storage.IStorageManager;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.server.ServerProtoEnums;
import android.sysprop.VoldProperties;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.EventLog;
import android.util.Pair;
import android.util.Slog;
import android.view.contentcapture.ContentCaptureManager;
import com.android.internal.R;
import com.android.internal.notification.SystemNotificationChannels;
import com.android.internal.os.BinderInternal;
import com.android.internal.os.RuntimeInit;
import com.android.internal.util.ConcurrentUtils;
import com.android.internal.util.EmergencyAffordanceManager;
import com.android.internal.util.FrameworkStatsLog;
@@ -179,6 +186,7 @@ import com.google.android.startop.iorap.IorapForwardingService;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Timer;
import java.util.concurrent.CountDownLatch;
@@ -357,6 +365,11 @@ public final class SystemServer {
private Future<?> mZygotePreload;
private Future<?> mBlobStoreServiceStart;
/**
* The pending WTF to be logged into dropbox.
*/
private static LinkedList<Pair<String, ApplicationErrorReport.CrashInfo>> sPendingWtfs;
/**
* Start the sensor service. This is a blocking call and can take time.
*/
@@ -568,6 +581,9 @@ public final class SystemServer {
t.traceEnd(); // InitBeforeStartServices
}
// Setup the default WTF handler
RuntimeInit.setDefaultApplicationWtfHandler(SystemServer::handleEarlySystemWtf);
// Start services.
try {
t.traceBegin("StartServices");
@@ -2114,6 +2130,14 @@ public final class SystemServer {
}
t.traceEnd();
// Emit any pending system_server WTFs
synchronized (SystemService.class) {
if (sPendingWtfs != null) {
mActivityManagerService.schedulePendingSystemServerWtfs(sPendingWtfs);
sPendingWtfs = null;
}
}
if (safeMode) {
mActivityManagerService.showSafeModeOverlay();
}
@@ -2503,4 +2527,29 @@ public final class SystemServer {
context.startServiceAsUser(intent, UserHandle.SYSTEM);
windowManager.onSystemUiStarted();
}
/**
* Handle the serious errors during early system boot, used by {@link Log} via
* {@link com.android.internal.os.RuntimeInit}.
*/
private static boolean handleEarlySystemWtf(final IBinder app, final String tag, boolean system,
final ApplicationErrorReport.ParcelableCrashInfo crashInfo, int immediateCallerPid) {
final String processName = "system_server";
final int myPid = myPid();
com.android.server.am.EventLogTags.writeAmWtf(UserHandle.getUserId(SYSTEM_UID), myPid,
processName, -1, tag, crashInfo.exceptionMessage);
FrameworkStatsLog.write(FrameworkStatsLog.WTF_OCCURRED, SYSTEM_UID, tag, processName,
myPid, ServerProtoEnums.SYSTEM_SERVER);
synchronized (SystemServer.class) {
if (sPendingWtfs == null) {
sPendingWtfs = new LinkedList<>();
}
sPendingWtfs.add(new Pair<>(tag, crashInfo));
}
return false;
}
}