1 /* 2 * Copyright (C) 2006 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.compat.annotation.UnsupportedAppUsage; 20 import android.os.Build; 21 22 /** 23 * An instance of this class represents a connection to the surface 24 * flinger, from which you can create one or more Surface instances that will 25 * be composited to the screen. 26 * {@hide} 27 */ 28 public final class SurfaceSession { 29 // Note: This field is accessed by native code. 30 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 31 private long mNativeClient; // SurfaceComposerClient* 32 nativeCreate()33 private static native long nativeCreate(); nativeDestroy(long ptr)34 private static native void nativeDestroy(long ptr); 35 36 /** Create a new connection with the surface flinger. */ 37 @UnsupportedAppUsage SurfaceSession()38 public SurfaceSession() { 39 mNativeClient = nativeCreate(); 40 } 41 42 /* no user serviceable parts here ... */ 43 @Override finalize()44 protected void finalize() throws Throwable { 45 try { 46 kill(); 47 } finally { 48 super.finalize(); 49 } 50 } 51 52 /** 53 * Remove the reference to the native Session object. The native object may still exist if 54 * there are other references to it, but it cannot be accessed from this Java object anymore. 55 */ 56 @UnsupportedAppUsage kill()57 public void kill() { 58 if (mNativeClient != 0) { 59 nativeDestroy(mNativeClient); 60 mNativeClient = 0; 61 } 62 } 63 } 64 65