1 /* 2 * Copyright (C) 2025 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.virtualization.terminal 17 18 import android.os.Bundle 19 import android.system.virtualmachine.VirtualMachineManager 20 import android.view.SurfaceView 21 import android.view.WindowInsets 22 import android.view.WindowInsetsController 23 24 class DisplayActivity : BaseActivity() { 25 private lateinit var displayProvider: DisplayProvider 26 onCreatenull27 override fun onCreate(savedInstanceState: Bundle?) { 28 super.onCreate(savedInstanceState) 29 setContentView(R.layout.activity_display) 30 val mainView = findViewById<SurfaceView>(R.id.surface_view) 31 val cursorView = findViewById<SurfaceView>(R.id.cursor_surface_view) 32 makeFullscreen() 33 // Connect the views to the VM 34 displayProvider = DisplayProvider(mainView, cursorView) 35 val vmm = 36 applicationContext.getSystemService<VirtualMachineManager>( 37 VirtualMachineManager::class.java 38 ) 39 val debianVm = vmm.get("debian") 40 if (debianVm != null) { 41 InputForwarder( 42 this, 43 debianVm, 44 findViewById(R.id.background_touch_view), 45 findViewById(R.id.surface_view), 46 findViewById(R.id.surface_view), 47 ) 48 } 49 } 50 onPausenull51 override fun onPause() { 52 super.onPause() 53 displayProvider.notifyDisplayIsGoingToInvisible() 54 } 55 makeFullscreennull56 private fun makeFullscreen() { 57 val w = window 58 w.setDecorFitsSystemWindows(false) 59 val insetsCtrl = w.insetsController 60 insetsCtrl?.hide(WindowInsets.Type.systemBars()) 61 insetsCtrl?.setSystemBarsBehavior( 62 WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE 63 ) 64 } 65 } 66