blob: 85c799cad321df966d3302a80783d38fc33e1747 [file] [log] [blame]
Jeff Brown4ccb8232014-01-16 22:16:42 -08001/*
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;
Jorim Jaggied7993b2017-03-28 18:50:01 +010020import android.os.Process;
Jeff Sharkey74cd3de2016-04-06 17:40:54 -060021import android.os.Trace;
Jeff Brown4ccb8232014-01-16 22:16:42 -080022
23/**
24 * Shared singleton foreground thread for the system. This is a thread for
25 * operations that affect what's on the display, which needs to have a minimum
26 * of latency. This thread should pretty much only be used by the WindowManager,
27 * DisplayManager, and InputManager to perform quick operations in real time.
28 */
29public final class DisplayThread extends ServiceThread {
30 private static DisplayThread sInstance;
31 private static Handler sHandler;
32
33 private DisplayThread() {
Jorim Jaggied7993b2017-03-28 18:50:01 +010034 // DisplayThread runs important stuff, but these are not as important as things running in
35 // AnimationThread. Thus, set the priority to one lower.
36 super("android.display", Process.THREAD_PRIORITY_DISPLAY + 1, false /*allowIo*/);
Jeff Brown4ccb8232014-01-16 22:16:42 -080037 }
38
39 private static void ensureThreadLocked() {
40 if (sInstance == null) {
41 sInstance = new DisplayThread();
42 sInstance.start();
Michael Wrightdaf72b12017-11-01 22:24:08 +000043 sInstance.getLooper().setTraceTag(Trace.TRACE_TAG_SYSTEM_SERVER);
Jeff Brown4ccb8232014-01-16 22:16:42 -080044 sHandler = new Handler(sInstance.getLooper());
45 }
46 }
47
48 public static DisplayThread get() {
Jeff Brownbf58d9b2014-06-23 16:13:53 -070049 synchronized (DisplayThread.class) {
Jeff Brown4ccb8232014-01-16 22:16:42 -080050 ensureThreadLocked();
51 return sInstance;
52 }
53 }
54
55 public static Handler getHandler() {
Jeff Brownbf58d9b2014-06-23 16:13:53 -070056 synchronized (DisplayThread.class) {
Jeff Brown4ccb8232014-01-16 22:16:42 -080057 ensureThreadLocked();
58 return sHandler;
59 }
60 }
61}