rk3568 android 11.0 允许第三方应用自启动

功能: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;
 }
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Max.Chen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值