1/* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.server; 18 19import android.os.Handler; 20 21/** 22 * Shared singleton foreground thread for the system. This is a thread for 23 * operations that affect what's on the display, which needs to have a minimum 24 * of latency. This thread should pretty much only be used by the WindowManager, 25 * DisplayManager, and InputManager to perform quick operations in real time. 26 */ 27public final class DisplayThread extends ServiceThread { 28 private static DisplayThread sInstance; 29 private static Handler sHandler; 30 31 private DisplayThread() { 32 super("android.display", android.os.Process.THREAD_PRIORITY_DISPLAY, false /*allowIo*/); 33 } 34 35 private static void ensureThreadLocked() { 36 if (sInstance == null) { 37 sInstance = new DisplayThread(); 38 sInstance.start(); 39 sHandler = new Handler(sInstance.getLooper()); 40 } 41 } 42 43 public static DisplayThread get() { 44 synchronized (DisplayThread.class) { 45 ensureThreadLocked(); 46 return sInstance; 47 } 48 } 49 50 public static Handler getHandler() { 51 synchronized (DisplayThread.class) { 52 ensureThreadLocked(); 53 return sHandler; 54 } 55 } 56} 57