码迷,mamicode.com
首页 > 移动开发 > 详细

Android app黑白名单

时间:2015-05-19 21:04:06      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:ott开发

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");
    }
}   

Android app黑白名单

标签:ott开发

原文地址:http://blog.csdn.net/u012733519/article/details/45848383

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!