blob: 84f0068093f672d41474e7ace31eb8f877cda2b7 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
Dan Egnor3d40df32009-11-17 13:36:31 -08002 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080016
17package com.android.server;
18
Dan Egnor3d40df32009-11-17 13:36:31 -080019import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.content.ContentResolver;
21import android.content.Context;
22import android.content.Intent;
Dan Egnor3d40df32009-11-17 13:36:31 -080023import android.os.Build;
24import android.os.DropBoxManager;
25import android.os.FileUtils;
Dan Egnor3d40df32009-11-17 13:36:31 -080026import android.os.SystemProperties;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.provider.Settings;
Dan Egnor3d40df32009-11-17 13:36:31 -080028import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029
Dan Egnor3d40df32009-11-17 13:36:31 -080030import com.android.internal.os.RecoverySystem;
31
32import java.io.File;
33import java.io.IOException;
34
35/**
36 * Performs a number of miscellaneous, non-system-critical actions
37 * after the system has finished booting.
38 */
39public class BootReceiver extends BroadcastReceiver {
40 private static final String TAG = "BootReceiver";
41
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042 @Override
Dan Egnor3d40df32009-11-17 13:36:31 -080043 public void onReceive(Context context, Intent intent) {
44 try {
45 logBootEvents(context);
46 } catch (Exception e) {
47 Log.e(TAG, "Can't log boot events", e);
48 }
49
50 try {
51 RecoverySystem.handleAftermath();
52 } catch (Exception e) {
53 Log.e(TAG, "Can't handle recovery aftermath", e);
54 }
55
56 try {
57 // Start the load average overlay, if activated
58 ContentResolver res = context.getContentResolver();
59 if (Settings.System.getInt(res, Settings.System.SHOW_PROCESSES, 0) != 0) {
60 Intent loadavg = new Intent(context, com.android.server.LoadAverageService.class);
61 context.startService(loadavg);
62 }
63 } catch (Exception e) {
64 Log.e(TAG, "Can't start load average service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 }
66 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067
Dan Egnor3d40df32009-11-17 13:36:31 -080068 private void logBootEvents(Context context) throws IOException {
69 DropBoxManager db = (DropBoxManager) context.getSystemService(Context.DROPBOX_SERVICE);
70
71 String build =
72 "Build: " + Build.FINGERPRINT + "\nKernel: " +
73 FileUtils.readTextFile(new File("/proc/version"), 1024, "...\n");
74
75 if (SystemProperties.getLong("ro.runtime.firstboot", 0) == 0) {
76 String now = Long.toString(System.currentTimeMillis());
77 SystemProperties.set("ro.runtime.firstboot", now);
78 if (db != null) db.addText("SYSTEM_BOOT", build);
79 } else {
80 if (db != null) db.addText("SYSTEM_RESTART", build);
81 return; // Subsequent boot, don't log kernel boot log
82 }
83
84 ContentResolver cr = context.getContentResolver();
85 logBootFile(cr, db, "/cache/recovery/log", "SYSTEM_RECOVERY_LOG");
Dan Egnorc4cf6ca2009-11-23 19:23:49 -080086 logBootFile(cr, db, "/proc/last_kmsg", "SYSTEM_LAST_KMSG");
Dan Egnor3d40df32009-11-17 13:36:31 -080087 logBootFile(cr, db, "/data/dontpanic/apanic_console", "APANIC_CONSOLE");
88 logBootFile(cr, db, "/data/dontpanic/apanic_threads", "APANIC_THREADS");
89 }
90
91 private void logBootFile(ContentResolver cr, DropBoxManager db, String filename, String tag)
92 throws IOException {
93 if (cr == null || db == null || !db.isTagEnabled(tag)) return; // Logging disabled
94
95 File file = new File(filename);
96 long fileTime = file.lastModified();
97 if (fileTime <= 0) return; // File does not exist
98
99 String setting = "logfile:" + filename;
100 long lastTime = Settings.Secure.getLong(cr, setting, 0);
101 if (lastTime == fileTime) return; // Already logged this particular file
Dan Egnoreb7a7d52009-11-25 12:38:00 -0800102 db.addFile(tag, file, DropBoxManager.IS_TEXT);
Dan Egnor3d40df32009-11-17 13:36:31 -0800103 }
104}