rk3568 android 11.0 允许第三方应用自启动
功能:android 11.0默认不允许第三方应用自启动,修改通过包名过滤允许启动1.添加文件,将报名写入到文件中,并拷贝到系统文件夹中在device/rockchip/common/device.mk中添加2.在frameworks/base/services/core/java/com/android/server/wm/中增加文件ActivityBackgroundStartCheckUti
功能:android 11.0默认不允许第三方应用自启动,修改通过包名过滤允许启动
1.添加文件,将报名写入到文件中,并拷贝到系统文件夹中
在device/rockchip/common/device.mk中添加
2.在frameworks/base/services/core/java/com/android/server/wm/中增加文件ActivityBackgroundStartCheckUtil.java
package com.android.server.wm;
import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.os.Process;
import android.text.TextUtils;
import android.util.Log;
import com.android.internal.util.ArrayUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
public class ActivityBackgroundStartCheckUtil{
private static String TAG = "ActivityBackgroundStartCheckUtil";
private static final File GRANT_SYS_APP_LIST_SYSTEM = Environment
.buildPath(Environment.getRootDirectory(), "etc", "permissions",
"pms_sysapp_grant_permission_list.txt");
private static HashSet<String> mCustomMadeAppSet = new HashSet<String>();
private static String CustomeKey[] = {"android", "call"};
public static boolean isCustomMadeApp(String callingPackage, Intent intent){
sGetGrantSystemAppFromFile(mCustomMadeAppSet, GRANT_SYS_APP_LIST_SYSTEM);
Log.d(TAG, "isCustomMadeApp callingPackage="+callingPackage);
try {
String packageName = intent.getComponent().getPackageName();
String className = intent.getComponent().getClassName();
if (mCustomMadeAppSet.contains(callingPackage) ||
mCustomMadeAppSet.contains(packageName)) {
return true;
}
for (String key : CustomeKey) {
if (className.contains(key)) {
return true;
}
}
} catch (Exception e) {
//e.printStackTrace();
Log.d(TAG, e.getMessage());
}
return false;
}
/**
* Get removable system app list from config file
*
* @param resultSet
* Returned result list
* @param file
* The config file
*/
private static void sGetGrantSystemAppFromFile(
HashSet<String> resultSet, File file) {
resultSet.clear();
FileReader fr = null;
BufferedReader br = null;
try {
if (file.exists()) {
fr = new FileReader(file);
} else {
Log.d(TAG, "file in " + file + " does not exist!");
return;
}
br = new BufferedReader(fr);
String line;
while ((line = br.readLine()) != null) {
line = line.trim();
if (!TextUtils.isEmpty(line)) {
Log.d(TAG, "read line " + line);
resultSet.add(line);
}
}
Log.e(TAG,"GRANT_SYS_APP_LIST_SYSTEM size="+resultSet.size());
} catch (Exception io) {
Log.d(TAG, io.getMessage());
} finally {
try {
if (br != null) {
br.close();
}
if (fr != null) {
fr.close();
}
} catch (IOException io) {
Log.d(TAG, io.getMessage());
}
}
}
}
3.在frameworks/base/services/core/java/com/android/server/wm/ActivityStarter.java里的shouldAbortBackgroundActivityStart中调用
if(ActivityBackgroundStartCheckUtil.isCustomMadeApp(callingPackage, intent)){
Slog.w(TAG, "Background activity start for CustomMadeApp ,ignored");
return false;
}
更多推荐
所有评论(0)