java.lang.RuntimeException: No data directory found for package android
at android.app.ContextImpl.getDataDir(ContextImpl.java:2916)
at android.app.ContextImpl.getPreferencesDir(ContextImpl.java:696)
at android.app.ContextImpl.getSharedPreferencesPath(ContextImpl.java:923)
at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:545)
at com.android.server.am.ActivityManagerService.getWhiteAppProcessList(ActivityManagerService.java:1903)
at com.android.server.am.OomAdjuster.isInWhitelist(OomAdjuster.java:2696)
at com.android.server.am.OomAdjuster.applyOomAdjLSP(OomAdjuster.java:2782)
at com.android.server.am.OomAdjuster.updateAndTrimProcessLSP(OomAdjuster.java:1264)
at com.android.server.am.OomAdjuster.updateOomAdjInnerLSP(OomAdjuster.java:1038)
at com.android.server.am.OomAdjuster.performUpdateOomAdjLSP(OomAdjuster.java:629)
at com.android.server.am.OomAdjuster.updateOomAdjLSP(OomAdjuster.java:615)
at com.android.server.am.OomAdjuster.updateOomAdjLocked(OomAdjuster.java:603)
at com.android.server.am.ActivityManagerService.updateOomAdjLocked(ActivityManagerService.java:14869)
at com.android.server.am.ActivityManagerService.setSystemProcess(ActivityManagerService.java:1851)
at com.android.server.SystemServer.startBootstrapServices(SystemServer.java:1225)
at com.android.server.SystemServer.run(SystemServer.java:887)
at com.android.server.SystemServer.main(SystemServer.java:620)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
2、一开始我们是封装在自定义系统服务里面,后面更换时序位置,通过一个工具类去调用。解决这个问题。所以简单记录下。代码如下图所示
public static List<String> getWhiteAppProcessList() {
List<String> list = new ArrayList();
String sizeKey = "persist.xxx.aliveapps_s";
String valKey = "persist.xxx.aliveapps_";
int size = 0;
try
{
size = Integer.parseInt(SystemProperties.get(sizeKey));
}
catch(Exception e)
{
}
if(size>0)
{
for(int i=0;i<size;i++)
{
list.add(SystemProperties.get(valKey+i));
}
}
return list;
}
public static void setWhiteAppProcessList(List<String> whiteAppProcessList) {
if(whiteAppProcessList==null || whiteAppProcessList.size()==0)
{
whiteAppProcessList = new ArrayList();
}
String sizeKey = "persist.xxx.aliveapps_s";
String valKey = "persist.xxx.aliveapps_";
int orgSize = 0;
try
{
orgSize = Integer.parseInt(SystemProperties.get(sizeKey));
}
catch(Exception e)
{
}
if (orgSize > 0) {
for(int i=0;i<orgSize;i++)
{
SystemProperties.set(valKey+i,"");
}
}
int size = whiteAppProcessList.size();
SystemProperties.set(sizeKey,String.valueOf(size));
for(int i=0;i<size;i++)
{
SystemProperties.set(valKey+i,whiteAppProcessList.get(i));
}
}
public static List<String> getBackgroundAliveAppList() {
String sizeKey = "persist.xxx.backgroundapps_s";
String valKey = "persist.xxx.backgroundapps_";
List<String> list = new ArrayList();
int size = 0;
try
{
size = Integer.parseInt(SystemProperties.get(sizeKey));
}
catch(Exception e)
{
}
if(size>0)
{
for(int i=0;i<size;i++)
{
list.add(SystemProperties.get(valKey+i));
}
}
return list;
}
public static void setBackgroundAliveAppList(List<String> backgroundAliveAppList) {
if(backgroundAliveAppList==null || backgroundAliveAppList.size()==0)
{
backgroundAliveAppList = new ArrayList();
}
String sizeKey = "persist.xxx.backgroundapps_s";
String valKey = "persist.xxx.backgroundapps_";
int orgSize = 0;
try
{
orgSize = Integer.parseInt(SystemProperties.get(sizeKey));
}
catch(Exception e)
{
}
if (orgSize > 0) {
for(int i=0;i<orgSize;i++)
{
SystemProperties.set(valKey+i,"");
}
}
int size = backgroundAliveAppList.size();
SystemProperties.set(sizeKey,String.valueOf(size));
for(int i=0;i<size;i++)
{
SystemProperties.set(valKey+i,backgroundAliveAppList.get(i));
}
}
转载请注明出处高通Android 12应用保活时序问题踩坑-CSDN博客,谢谢!