問題:在最近的工作中,發現機器恢復出廠設置後,出現冷屏凍屏的現象。。
分析:(1)可能是硬件驅動導致屏幕無法正常喚醒。
查看:用adb shell 命令去查看設備當中的配置文件是否存在,如存在則排除是硬件驅動導致的屏幕無法正常啓動和顯示。
結果: 在文件相應的目錄下沒有所需的配置文件,我們把相應的文件push到相應的文件夾下。之後reboot機器。機器可以正常啓動 不會出現冷屏凍屏的現象。
解決方案:先備份一份文件到vendor目錄下。然後在開機的時候copy一份到指定的文件目錄下,即可修復機器冷屏凍屏的現象。
隨後在組長review代碼時發現這種方法不行。因爲這樣會導致一個機器內存在兩個配置文件,如果要更改配置,就要更改兩個文件的配置。所以這種方法不可行!
最終方案
由於是系統啓動時配置文件不在該指定的文件夾下,導致屏幕出現問題。所以我們通過find 命令找到文件所在的文件夾;
在SystermService中添加如下代碼:
private void copyQvrFiles() {
String sourceDirPath = Environment.getRootDirectory().getPath()+"/vendor/etc/tools/";
String destiDirDisplayPath = Environment.getDataDirectory().getPath()+"/misc/display/";
String destiDirPath = Environment.getDataDirectory().getPath()+"/misc/qvr/";
String qvrDestiDirPath = Environment.getDataDirectory().getPath()+"/misc/vr/";
File sourceDir = new File(sourceDirPath);
if (!sourceDir.exists() || !sourceDir.isDirectory()) {
return;
}
File destiDir = new File(destiDirPath);
if (!destiDir.exists()) {
destiDir.mkdirs();
}
File qvrDestiDir = new File(qvrDestiDirPath);
if (!qvrDestiDir.exists()) {
qvrDestiDir.mkdirs();
}
File[] sourceFiles = sourceDir.listFiles();
for (File file : sourceFiles ){
if (!file.isDirectory()){
String path = file.getAbsolutePath();
if (file.getName().startsWith("tsbloptimize")){
copyFile(path, destiDirDisplayPath+"/"+file.getName());
}else if (file.getName().startsWith("svrapi_config")) {
copyFile(path, qvrDestiDirPath+"/"+file.getName());
}else {
copyFile(path, destiDirPath+"/"+file.getName());
}
}
}
}
private void copyFile(String oldPath, String newPath) {
if (new File(newPath).exists()){
return;
}
Slog.i(TAG,"start copy file "+newPath);
FileInputStream fis = null;
FileOutputStream fos = null;
try {
int len = 0;
fis = new FileInputStream(oldPath);
fos = new FileOutputStream(newPath);
byte[] buffer = new byte[1024];
while ((len = fis.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
fos.flush();
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
fis.close();
} catch (Exception e2) {
}finally{
fis = null;
}
try {
fos.close();
} catch (Exception e2) {
}finally{
fis = null;
}
}
}
}