BrightnessTracker: don't create stuff directly in /data/system_de
/data/system_de is only for per-user data; it *must* only contain per-user encrypted directories. Only vold should ever create anything directly in this directory. In preparation for removing system_server's write access to this directory (https://r.android.com/2078213), make BrightnessTracker store its brightness_events.xml file at /data/system/brightness_events.xml instead of /data/system_de/brightness_events.xml, and likewise for ambient_brightness_stats.xml. Migration happens lazily, except that the old files aren't ever deleted since the SELinux policy will no longer allow system_server to do that; the old files just stop being used. vold will need to handle the cleanup instead, or we could just leave the files around. Test: Flashed new build without wiping userdata. Log shows "Reading ambient_brightness_stats.xml from old location" as expected. Rebooted. Log message no longer appears, as expected. File /data/system/ambient_brightness_stats.xml exists, as expected. Bug: 156305599 Change-Id: I6e0948ac54ec9183348943234d505e7466042963
This commit is contained in:
@@ -505,12 +505,36 @@ public class BrightnessTracker {
|
||||
}
|
||||
}
|
||||
|
||||
// Return the path to the given file, either the new path
|
||||
// /data/system/$filename, or the old path /data/system_de/$filename if the
|
||||
// file exists there but not at the new path. Only use this for EVENTS_FILE
|
||||
// and AMBIENT_BRIGHTNESS_STATS_FILE.
|
||||
//
|
||||
// Explanation: this service previously incorrectly stored these two files
|
||||
// directly in /data/system_de, instead of in /data/system where they should
|
||||
// have been. As system_server no longer has write access to
|
||||
// /data/system_de itself, these files were moved to /data/system. To
|
||||
// lazily migrate the files, we simply read from the old path if it exists
|
||||
// and the new one doesn't, and always write to the new path. Note that
|
||||
// system_server doesn't have permission to delete the old files.
|
||||
private AtomicFile getFileWithLegacyFallback(String filename) {
|
||||
AtomicFile file = mInjector.getFile(filename);
|
||||
if (file != null && !file.exists()) {
|
||||
AtomicFile legacyFile = mInjector.getLegacyFile(filename);
|
||||
if (legacyFile != null && legacyFile.exists()) {
|
||||
Slog.i(TAG, "Reading " + filename + " from old location");
|
||||
return legacyFile;
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
private void readEvents() {
|
||||
synchronized (mEventsLock) {
|
||||
// Read might prune events so mark as dirty.
|
||||
mEventsDirty = true;
|
||||
mEvents.clear();
|
||||
final AtomicFile readFrom = mInjector.getFile(EVENTS_FILE);
|
||||
final AtomicFile readFrom = getFileWithLegacyFallback(EVENTS_FILE);
|
||||
if (readFrom != null && readFrom.exists()) {
|
||||
FileInputStream input = null;
|
||||
try {
|
||||
@@ -528,7 +552,7 @@ public class BrightnessTracker {
|
||||
|
||||
private void readAmbientBrightnessStats() {
|
||||
mAmbientBrightnessStatsTracker = new AmbientBrightnessStatsTracker(mUserManager, null);
|
||||
final AtomicFile readFrom = mInjector.getFile(AMBIENT_BRIGHTNESS_STATS_FILE);
|
||||
final AtomicFile readFrom = getFileWithLegacyFallback(AMBIENT_BRIGHTNESS_STATS_FILE);
|
||||
if (readFrom != null && readFrom.exists()) {
|
||||
FileInputStream input = null;
|
||||
try {
|
||||
@@ -1095,6 +1119,10 @@ public class BrightnessTracker {
|
||||
}
|
||||
|
||||
public AtomicFile getFile(String filename) {
|
||||
return new AtomicFile(new File(Environment.getDataSystemDirectory(), filename));
|
||||
}
|
||||
|
||||
public AtomicFile getLegacyFile(String filename) {
|
||||
return new AtomicFile(new File(Environment.getDataSystemDeDirectory(), filename));
|
||||
}
|
||||
|
||||
|
||||
@@ -1036,6 +1036,12 @@ public class BrightnessTrackerTest {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtomicFile getLegacyFile(String filename) {
|
||||
// Don't have the test write / read from anywhere.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long currentTimeMillis() {
|
||||
return mCurrentTimeMillis;
|
||||
|
||||
Reference in New Issue
Block a user