blob: 0d3afc06a86cb8f676b736ba473ad12f995effff [file] [log] [blame]
Jorim Jaggi21c39a72017-10-20 15:47:51 +02001/*
2 * Copyright (C) 2017 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.wm;
18
19import static android.os.Process.THREAD_PRIORITY_DISPLAY;
20
21import android.os.Handler;
22import android.os.Trace;
23
24import com.android.server.ServiceThread;
25
26/**
27 * Thread for running {@link SurfaceAnimationRunner} that does not hold the window manager lock.
28 */
29public final class SurfaceAnimationThread extends ServiceThread {
30 private static SurfaceAnimationThread sInstance;
31 private static Handler sHandler;
32
33 private SurfaceAnimationThread() {
34 super("android.anim.lf", THREAD_PRIORITY_DISPLAY, false /*allowIo*/);
35 }
36
37 private static void ensureThreadLocked() {
38 if (sInstance == null) {
39 sInstance = new SurfaceAnimationThread();
40 sInstance.start();
41 sInstance.getLooper().setTraceTag(Trace.TRACE_TAG_WINDOW_MANAGER);
42 sHandler = new Handler(sInstance.getLooper());
43 }
44 }
45
46 public static SurfaceAnimationThread get() {
47 synchronized (SurfaceAnimationThread.class) {
48 ensureThreadLocked();
49 return sInstance;
50 }
51 }
52
53 public static Handler getHandler() {
54 synchronized (SurfaceAnimationThread.class) {
55 ensureThreadLocked();
56 return sHandler;
57 }
58 }
59}