Merge "Switch /data/misc/reboot/last_reboot_reason to persistent property"
This commit is contained in:
@@ -200,8 +200,8 @@ public final class PowerManagerService extends SystemService
|
||||
// Possible reasons for shutting down for use in data/misc/reboot/last_shutdown_reason
|
||||
private static final String REASON_SHUTDOWN = "shutdown";
|
||||
private static final String REASON_REBOOT = "reboot";
|
||||
private static final String REASON_USERREQUESTED = "userrequested";
|
||||
private static final String REASON_THERMAL_SHUTDOWN = "thermal-shutdown";
|
||||
private static final String REASON_USERREQUESTED = "shutdown,userrequested";
|
||||
private static final String REASON_THERMAL_SHUTDOWN = "shutdown,thermal";
|
||||
|
||||
private static final String TRACE_SCREEN_ON = "Screen turning on";
|
||||
|
||||
@@ -216,8 +216,8 @@ public final class PowerManagerService extends SystemService
|
||||
private static final int HALT_MODE_REBOOT = 1;
|
||||
private static final int HALT_MODE_REBOOT_SAFE_MODE = 2;
|
||||
|
||||
// File location for last reboot reason
|
||||
private static final String LAST_REBOOT_LOCATION = "/data/misc/reboot/last_reboot_reason";
|
||||
// Persistent property for last reboot reason
|
||||
private static final String LAST_REBOOT_PROPERTY = "persist.sys.boot.reason";
|
||||
|
||||
private final Context mContext;
|
||||
private final ServiceThread mHandlerThread;
|
||||
@@ -4373,7 +4373,7 @@ public final class PowerManagerService extends SystemService
|
||||
|
||||
final long ident = Binder.clearCallingIdentity();
|
||||
try {
|
||||
return getLastShutdownReasonInternal(new File(LAST_REBOOT_LOCATION));
|
||||
return getLastShutdownReasonInternal(LAST_REBOOT_PROPERTY);
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
}
|
||||
@@ -4607,13 +4607,9 @@ public final class PowerManagerService extends SystemService
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
int getLastShutdownReasonInternal(File lastRebootReason) {
|
||||
String line = "";
|
||||
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(lastRebootReason))){
|
||||
line = bufferedReader.readLine();
|
||||
} catch (IOException e) {
|
||||
Slog.e(TAG, "Failed to read last_reboot_reason file", e);
|
||||
}
|
||||
// lastRebootReasonProperty argument to permit testing
|
||||
int getLastShutdownReasonInternal(String lastRebootReasonProperty) {
|
||||
String line = SystemProperties.get(lastRebootReasonProperty);
|
||||
if (line == null) {
|
||||
return PowerManager.SHUTDOWN_REASON_UNKNOWN;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.content.Context;
|
||||
import android.hardware.display.DisplayManagerInternal.DisplayPowerRequest;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerSaveState;
|
||||
import android.os.SystemProperties;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.text.TextUtils;
|
||||
@@ -44,17 +45,14 @@ public class PowerManagerServiceTest extends AndroidTestCase {
|
||||
private static final float PRECISION = 0.001f;
|
||||
private static final float BRIGHTNESS_FACTOR = 0.7f;
|
||||
private static final boolean BATTERY_SAVER_ENABLED = true;
|
||||
private static final String LAST_REBOOT_REASON = "last_reboot_reason";
|
||||
private static final String TEST_LAST_REBOOT_PROPERTY = "test.sys.boot.reason";
|
||||
|
||||
private @Mock BatterySaverPolicy mBatterySaverPolicy;
|
||||
private PowerManagerService mService;
|
||||
private PowerSaveState mPowerSaveState;
|
||||
private DisplayPowerRequest mDisplayPowerRequest;
|
||||
private File mTempReason;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
MockitoAnnotations.initMocks(this);
|
||||
@@ -68,8 +66,6 @@ public class PowerManagerServiceTest extends AndroidTestCase {
|
||||
.thenReturn(mPowerSaveState);
|
||||
mDisplayPowerRequest = new DisplayPowerRequest();
|
||||
mService = new PowerManagerService(getContext(), mBatterySaverPolicy);
|
||||
temporaryFolder.create();
|
||||
mTempReason = temporaryFolder.newFile(LAST_REBOOT_REASON);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@@ -82,14 +78,9 @@ public class PowerManagerServiceTest extends AndroidTestCase {
|
||||
|
||||
@SmallTest
|
||||
public void testGetLastShutdownReasonInternal() {
|
||||
try {
|
||||
FileWriter writer = new FileWriter(mTempReason);
|
||||
writer.append("thermal-shutdown\n");
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
int reason = mService.getLastShutdownReasonInternal(mTempReason);
|
||||
SystemProperties.set(TEST_LAST_REBOOT_PROPERTY, "shutdown,thermal");
|
||||
int reason = mService.getLastShutdownReasonInternal(TEST_LAST_REBOOT_PROPERTY);
|
||||
SystemProperties.set(TEST_LAST_REBOOT_PROPERTY, "");
|
||||
assertThat(reason).isEqualTo(PowerManager.SHUTDOWN_REASON_THERMAL_SHUTDOWN);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user