Home | History | Annotate | Download | only in server
      1 /*
      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 
     17 package com.android.server;
     18 
     19 import static android.os.Process.THREAD_PRIORITY_DISPLAY;
     20 
     21 import android.os.Handler;
     22 import android.os.Trace;
     23 
     24 /**
     25  * Thread for handling all legacy window animations, or anything that's directly impacting
     26  * animations like starting windows or traversals.
     27  */
     28 public final class AnimationThread extends ServiceThread {
     29     private static AnimationThread sInstance;
     30     private static Handler sHandler;
     31 
     32     private AnimationThread() {
     33         super("android.anim", THREAD_PRIORITY_DISPLAY, false /*allowIo*/);
     34     }
     35 
     36     private static void ensureThreadLocked() {
     37         if (sInstance == null) {
     38             sInstance = new AnimationThread();
     39             sInstance.start();
     40             sInstance.getLooper().setTraceTag(Trace.TRACE_TAG_WINDOW_MANAGER);
     41             sHandler = new Handler(sInstance.getLooper());
     42         }
     43     }
     44 
     45     public static AnimationThread get() {
     46         synchronized (AnimationThread.class) {
     47             ensureThreadLocked();
     48             return sInstance;
     49         }
     50     }
     51 
     52     public static Handler getHandler() {
     53         synchronized (AnimationThread.class) {
     54             ensureThreadLocked();
     55             return sHandler;
     56         }
     57     }
     58 }
     59