Android app黑白名单

Android app黑白名单

Android设备系统正常工作时,很多Service运行在后台,只用在系统内存不够使用时候,才会自动kill掉后台Service
Android OTT盒子项目开发中,网络机顶盒运行内存512M/1G 内存不够使用,为了提高系统的流畅性,编译固件时加入app黑白名单功能。

Android系统开机后会发出BroadcastReceiver开机广播,
在设置app 添加BootCompletedReceiverAML.java

public class BootCompletedReceiverAML extends BroadcastReceiver {
    public static final String TAG = "BootCompletedReceiverAML";
    public void onReceive(Context context, Intent intent) {

    initScreenSaver(); 
    initEnableRunningBackgroudComponents();
    initEnableAutoRunningComponents();  
    initLauncherComponents();
    }

    //设置进入屏保黑白名单
    private void initScreenSaver() {
        Settings.System.putInt(mContext.getContentResolver(),
        Settings.System.BOOT_GUIDE_COMPLETED, 1);
        IDreamManager mDreamManager = IDreamManager.Stub.asInterface(ServiceManager.getService(DreamService.DREAM_SERVICE));
        ComponentName dream = newComponentName("com.mipt.screensaver",
                "com.mipt.screensaver.ScreenSaverService");
        try {
            ComponentName[] dreams = { dream };
            mDreamManager.setDreamComponents(dream == null ? null : dreams);
        } 
        catch (RemoteException e) {
        }

        String dreamEnableComponentNames = "com.skyworthdigital.filexplorer/com.skyworthdigital.weather.main/com.skyworthdigital.ihome.settings/com.study.pumpkinstudy/com.android.dreams.phototable";
        Settings.System.putString(mContext.getContentResolver(),
        Settings.System.DREAM_ENABLE_COMPONENT,dreamEnableComponentNames);

        try {
            long currentTimeout = Settings.System.getLong(
                    mContext.getContentResolver(), SCREEN_OFF_TIMEOUT);
            if (currentTimeout < 0) {
                Settings.System.putInt(mContext.getContentResolver(),
                        SCREEN_OFF_TIMEOUT, 2147483646);
            }
            currentTimeout = Settings.System.getLong(
                    mContext.getContentResolver(), SCREEN_DREAM_TIMEOUT, -1);
            if (currentTimeout < 0) {
                Settings.System.putInt(mContext.getContentResolver(),
                        SCREEN_DREAM_TIMEOUT, 240000);
            }

        } catch (SettingNotFoundException e) {
            e.printStackTrace();
        }
    }

    // 使能自动运行在后台service
    private void initEnableRunningBackgroudComponents() {
        Settings.Secure.putString(mContext.getContentResolver(),
        Settings.Secure.ENABLE_RUNNING_BACKGROUD_COMPONENTS,
        "android/system/com.android/com.mipt/com.skyworth/com.google.android/com.skydigital/com.sky/com.starcor.hunan/com.explorer/com.slanissue.tv.erge/eu.chainfire.perfmon");
    }

    //开机自动运行
    private void initEnableAutoRunningComponents() {
        Settings.Secure.putString(mContext.getContentResolver(),
        Settings.Secure.ENABLE_AUTO_LAUNCH_COMPONENTS,
        "com.android/android/system/com.mipt/com.skyworth/com.mipt.metro.launcher/com.skydigital/com.sky/com.starcor.hunan");
    }
    //开机Launcher
    private void initLauncherComponents() {
        Settings.Secure.putString(mContext.getContentResolver(),
        Settings.Secure.ENABLE_LAUNCHER_COMPONENTS,
        "com.mipt.metro.launcher");
    }
}   

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。