blob: 7991e388af7ef78c958843c4b6daf0a8fbf9fccb [file] [log] [blame]
Adrian Roos0fb55ae2017-04-14 14:49:11 -07001/*
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.systemui.util.wakelock;
18
19import android.os.Handler;
20
21/**
22 * A wake lock that has a built in delay when releasing to give the framebuffer time to update.
23 */
24public class DelayedWakeLock implements WakeLock {
25
Lucas Dupinee4c9b72019-02-18 17:04:58 -080026 private static final String TO_STRING_PREFIX = "[DelayedWakeLock] ";
Lucas Dupina11298b2018-06-26 15:09:08 -070027 private static final long RELEASE_DELAY_MS = 100;
Adrian Roos0fb55ae2017-04-14 14:49:11 -070028
29 private final Handler mHandler;
30 private final WakeLock mInner;
Adrian Roos0fb55ae2017-04-14 14:49:11 -070031
32 public DelayedWakeLock(Handler h, WakeLock inner) {
33 mHandler = h;
34 mInner = inner;
Adrian Roos0fb55ae2017-04-14 14:49:11 -070035 }
36
37 @Override
Lucas Dupinee4c9b72019-02-18 17:04:58 -080038 public void acquire(String why) {
39 mInner.acquire(why);
Adrian Roos0fb55ae2017-04-14 14:49:11 -070040 }
41
42 @Override
Lucas Dupinee4c9b72019-02-18 17:04:58 -080043 public void release(String why) {
44 mHandler.postDelayed(() -> mInner.release(why), RELEASE_DELAY_MS);
Adrian Roos0fb55ae2017-04-14 14:49:11 -070045 }
46
47 @Override
48 public Runnable wrap(Runnable r) {
49 return WakeLock.wrapImpl(this, r);
50 }
Lucas Dupinee4c9b72019-02-18 17:04:58 -080051
52 @Override
53 public String toString() {
54 return TO_STRING_PREFIX + mInner;
55 }
Adrian Roos0fb55ae2017-04-14 14:49:11 -070056}