Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android app黑白名單

Android app黑白名單

編輯:關於Android編程

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");
    }
}   
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved