1 /* 2 * Copyright (C) 2019 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 package com.android.server.telecom; 17 18 import android.os.Handler; 19 import android.telecom.Logging.Runnable; 20 21 import java.util.concurrent.Executor; 22 23 /** An executor that starts a log session before executing a runnable */ 24 public class LoggedHandlerExecutor implements Executor { 25 private Handler mHandler; 26 private String mSessionName; 27 private TelecomSystem.SyncRoot mLock; 28 29 public LoggedHandlerExecutor(Handler handler, String sessionName, 30 TelecomSystem.SyncRoot lock) { 31 mHandler = handler; 32 mSessionName = sessionName; 33 mLock = lock; 34 } 35 36 @Override 37 public void execute(java.lang.Runnable command) { 38 mHandler.post(new Runnable(mSessionName, mLock) { 39 @Override 40 public void loggedRun() { 41 command.run(); 42 } 43 }.prepare()); 44 } 45 } 46