1 /* 2 * Copyright (C) 2018 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.wm.flicker.monitor; 18 19 import android.os.IBinder; 20 import android.os.Parcel; 21 import android.os.RemoteException; 22 import android.os.ServiceManager; 23 import android.util.Log; 24 25 /** 26 * Captures Layers trace from SurfaceFlinger. 27 */ 28 public class LayersTraceMonitor extends TraceMonitor { 29 private static final String TAG = "LayersTraceMonitor"; 30 private IBinder mSurfaceFlinger = ServiceManager.getService("SurfaceFlinger"); 31 32 public LayersTraceMonitor() { 33 traceFileName = "layers_trace.pb"; 34 } 35 36 @Override 37 public void start() { 38 setEnabled(true); 39 } 40 41 @Override 42 public void stop() { 43 setEnabled(false); 44 } 45 46 @Override 47 public boolean isEnabled() throws RemoteException { 48 Parcel data = Parcel.obtain(); 49 Parcel reply = Parcel.obtain(); 50 data.writeInterfaceToken("android.ui.ISurfaceComposer"); 51 mSurfaceFlinger.transact(/* LAYER_TRACE_STATUS_CODE */ 1026, 52 data, reply, 0 /* flags */); 53 return reply.readBoolean(); 54 } 55 56 private void setEnabled(boolean isEnabled) { 57 Parcel data = null; 58 try { 59 if (mSurfaceFlinger != null) { 60 data = Parcel.obtain(); 61 data.writeInterfaceToken("android.ui.ISurfaceComposer"); 62 data.writeInt(isEnabled ? 1 : 0); 63 mSurfaceFlinger.transact( /* LAYER_TRACE_CONTROL_CODE */ 1025, 64 data, null, 0 /* flags */); 65 } 66 } catch (RemoteException e) { 67 Log.e(TAG, "Could not set layer tracing." + e.toString()); 68 } finally { 69 if (data != null) { 70 data.recycle(); 71 } 72 } 73 } 74 } 75