Allow the vendor specific initialization of display_settings.xml.
In hawk_md, I tried to copy the intial settings in vendor-init: ag/7309059 Later, I found that this way doesn't work in SELINUX, since vendor-init is not allowed to access core_data_files: http://shortn/_h6LOOHBVCF So, I'd like to add a hook that vendor can provide the intial display settings. This is a stop-gap solution until b/123226552 is resolved. Bug: 137233447 Test: Check if /vendor/etc/display_settings.xml is copied into /data/system/. Change-Id: Ib87219e62c3414f26d63f072a0e767287ddb156e
This commit is contained in:
committed by
Wale Ogunwale
parent
7e715542f5
commit
f646144ab2
@@ -30,6 +30,7 @@ import android.annotation.IntDef;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.WindowConfiguration;
|
||||
import android.os.Environment;
|
||||
import android.os.FileUtils;
|
||||
import android.provider.Settings;
|
||||
import android.util.AtomicFile;
|
||||
import android.util.Slog;
|
||||
@@ -64,6 +65,11 @@ import java.util.HashMap;
|
||||
class DisplayWindowSettings {
|
||||
private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayWindowSettings" : TAG_WM;
|
||||
|
||||
private static final String SYSTEM_DIRECTORY = "system";
|
||||
private static final String DISPLAY_SETTINGS_FILE_NAME = "display_settings.xml";
|
||||
private static final String VENDOR_DISPLAY_SETTINGS_PATH = "etc/" + DISPLAY_SETTINGS_FILE_NAME;
|
||||
private static final String WM_DISPLAY_COMMIT_TAG = "wm-displays";
|
||||
|
||||
private static final int IDENTIFIER_UNIQUE_ID = 0;
|
||||
private static final int IDENTIFIER_PORT = 1;
|
||||
@IntDef(prefix = { "IDENTIFIER_" }, value = {
|
||||
@@ -688,8 +694,26 @@ class DisplayWindowSettings {
|
||||
private final AtomicFile mAtomicFile;
|
||||
|
||||
AtomicFileStorage() {
|
||||
final File folder = new File(Environment.getDataDirectory(), "system");
|
||||
mAtomicFile = new AtomicFile(new File(folder, "display_settings.xml"), "wm-displays");
|
||||
final File folder = new File(Environment.getDataDirectory(), SYSTEM_DIRECTORY);
|
||||
final File settingsFile = new File(folder, DISPLAY_SETTINGS_FILE_NAME);
|
||||
// If display_settings.xml doesn't exist, try to copy the vendor's one instead
|
||||
// in order to provide the vendor specific initialization.
|
||||
if (!settingsFile.exists()) {
|
||||
copyVendorSettings(settingsFile);
|
||||
}
|
||||
mAtomicFile = new AtomicFile(settingsFile, WM_DISPLAY_COMMIT_TAG);
|
||||
}
|
||||
|
||||
private static void copyVendorSettings(File target) {
|
||||
final File vendorFile = new File(Environment.getVendorDirectory(),
|
||||
VENDOR_DISPLAY_SETTINGS_PATH);
|
||||
if (vendorFile.canRead()) {
|
||||
try {
|
||||
FileUtils.copy(vendorFile, target);
|
||||
} catch (IOException e) {
|
||||
Slog.e(TAG, "Failed to copy vendor display_settings.xml");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user