1 /* 2 * Copyright 2024 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 android.view; 18 19 import android.annotation.RequiresPermission; 20 21 import libcore.util.NativeAllocationRegistry; 22 23 /** 24 * Allows for the monitoring of visible layers that are using picture processing. 25 * @hide 26 */ 27 public abstract class SurfaceControlActivePictureListener { 28 private static final NativeAllocationRegistry sRegistry = 29 NativeAllocationRegistry.createMalloced( 30 SurfaceControlActivePictureListener.class.getClassLoader(), 31 nativeGetDestructor()); 32 33 /** 34 * Callback when there are changes in the visible layers that are using picture processing. 35 * 36 * @param activePictures The visible layers that are using picture processing. 37 */ onActivePicturesChanged(SurfaceControlActivePicture[] activePictures)38 public abstract void onActivePicturesChanged(SurfaceControlActivePicture[] activePictures); 39 40 /** 41 * Start listening to changes in active pictures. 42 */ 43 @RequiresPermission(android.Manifest.permission.OBSERVE_PICTURE_PROFILES) startListening()44 public void startListening() { 45 synchronized (this) { 46 long nativePtr = nativeMakeAndStartListening(); 47 mDestructor = sRegistry.registerNativeAllocation(this, nativePtr); 48 } 49 } 50 51 /** 52 * Stop listening to changes in active pictures. 53 */ 54 @RequiresPermission(android.Manifest.permission.OBSERVE_PICTURE_PROFILES) stopListening()55 public void stopListening() { 56 final Runnable destructor; 57 synchronized (this) { 58 destructor = mDestructor; 59 } 60 if (destructor != null) { 61 destructor.run(); 62 } 63 } 64 nativeMakeAndStartListening()65 private native long nativeMakeAndStartListening(); nativeGetDestructor()66 private static native long nativeGetDestructor(); 67 68 private Runnable mDestructor; 69 } 70