blob: 4279e007016347f91ec25a6ad9acaeb5de01e29e [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;
Doug Zongker1af33d02010-01-05 11:28:55 -080026import android.os.RecoverySystem;
Dan Egnor3d40df32009-11-17 13:36:31 -080027import android.os.SystemProperties;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.provider.Settings;
Dan Egnor3d40df32009-11-17 13:36:31 -080029import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030
Dan Egnor3d40df32009-11-17 13:36:31 -080031import java.io.File;
32import java.io.IOException;
33
34/**
35 * Performs a number of miscellaneous, non-system-critical actions
36 * after the system has finished booting.
37 */
38public class BootReceiver extends BroadcastReceiver {
39 private static final String TAG = "BootReceiver";
40
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041 @Override
Dan Egnor3d40df32009-11-17 13:36:31 -080042 public void onReceive(Context context, Intent intent) {
43 try {
44 logBootEvents(context);
45 } catch (Exception e) {
46 Log.e(TAG, "Can't log boot events", e);
47 }
48
49 try {
50 RecoverySystem.handleAftermath();
51 } catch (Exception e) {
52 Log.e(TAG, "Can't handle recovery aftermath", e);
53 }
54
55 try {
56 // Start the load average overlay, if activated
57 ContentResolver res = context.getContentResolver();
58 if (Settings.System.getInt(res, Settings.System.SHOW_PROCESSES, 0) != 0) {
59 Intent loadavg = new Intent(context, com.android.server.LoadAverageService.class);
60 context.startService(loadavg);
61 }
62 } catch (Exception e) {
63 Log.e(TAG, "Can't start load average service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 }
65 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066
Dan Egnor3d40df32009-11-17 13:36:31 -080067 private void logBootEvents(Context context) throws IOException {
68 DropBoxManager db = (DropBoxManager) context.getSystemService(Context.DROPBOX_SERVICE);
69
70 String build =
71 "Build: " + Build.FINGERPRINT + "\nKernel: " +
72 FileUtils.readTextFile(new File("/proc/version"), 1024, "...\n");
73
74 if (SystemProperties.getLong("ro.runtime.firstboot", 0) == 0) {
75 String now = Long.toString(System.currentTimeMillis());
76 SystemProperties.set("ro.runtime.firstboot", now);
77 if (db != null) db.addText("SYSTEM_BOOT", build);
78 } else {
79 if (db != null) db.addText("SYSTEM_RESTART", build);
80 return; // Subsequent boot, don't log kernel boot log
81 }
82
83 ContentResolver cr = context.getContentResolver();
84 logBootFile(cr, db, "/cache/recovery/log", "SYSTEM_RECOVERY_LOG");
Dan Egnorc4cf6ca2009-11-23 19:23:49 -080085 logBootFile(cr, db, "/proc/last_kmsg", "SYSTEM_LAST_KMSG");
Dan Egnor3d40df32009-11-17 13:36:31 -080086 logBootFile(cr, db, "/data/dontpanic/apanic_console", "APANIC_CONSOLE");
87 logBootFile(cr, db, "/data/dontpanic/apanic_threads", "APANIC_THREADS");
88 }
89
90 private void logBootFile(ContentResolver cr, DropBoxManager db, String filename, String tag)
91 throws IOException {
92 if (cr == null || db == null || !db.isTagEnabled(tag)) return; // Logging disabled
93
94 File file = new File(filename);
95 long fileTime = file.lastModified();
96 if (fileTime <= 0) return; // File does not exist
97
98 String setting = "logfile:" + filename;
99 long lastTime = Settings.Secure.getLong(cr, setting, 0);
100 if (lastTime == fileTime) return; // Already logged this particular file
Dan Egnoreb7a7d52009-11-25 12:38:00 -0800101 db.addFile(tag, file, DropBoxManager.IS_TEXT);
Dan Egnor3d40df32009-11-17 13:36:31 -0800102 }
103}