HeadlessDisplayAdapter.java revision 66692500344cab2f53cdb6ee1545c567fff7cb16
1/* 2 * Copyright (C) 2012 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 17package com.android.server.display; 18 19import android.content.Context; 20import android.os.Handler; 21import android.util.DisplayMetrics; 22 23/** 24 * Provides a fake default display for headless systems. 25 * <p> 26 * Display adapters are guarded by the {@link DisplayManagerService.SyncRoot} lock. 27 * </p> 28 */ 29final class HeadlessDisplayAdapter extends DisplayAdapter { 30 private static final String TAG = "HeadlessDisplayAdapter"; 31 32 // Called with SyncRoot lock held. 33 public HeadlessDisplayAdapter(DisplayManagerService.SyncRoot syncRoot, 34 Context context, Handler handler, Listener listener) { 35 super(syncRoot, context, handler, listener, TAG); 36 } 37 38 @Override 39 public void registerLocked() { 40 super.registerLocked(); 41 sendDisplayDeviceEventLocked(new HeadlessDisplayDevice(), DISPLAY_DEVICE_EVENT_ADDED); 42 } 43 44 private final class HeadlessDisplayDevice extends DisplayDevice { 45 private DisplayDeviceInfo mInfo; 46 47 public HeadlessDisplayDevice() { 48 super(HeadlessDisplayAdapter.this, null); 49 } 50 51 @Override 52 public DisplayDeviceInfo getDisplayDeviceInfoLocked() { 53 if (mInfo == null) { 54 mInfo = new DisplayDeviceInfo(); 55 mInfo.name = getContext().getResources().getString( 56 com.android.internal.R.string.display_manager_built_in_display_name); 57 mInfo.width = 640; 58 mInfo.height = 480; 59 mInfo.refreshRate = 60; 60 mInfo.densityDpi = DisplayMetrics.DENSITY_DEFAULT; 61 mInfo.xDpi = 160; 62 mInfo.yDpi = 160; 63 mInfo.flags = DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY 64 | DisplayDeviceInfo.FLAG_SECURE 65 | DisplayDeviceInfo.FLAG_SUPPORTS_PROTECTED_BUFFERS; 66 mInfo.touch = DisplayDeviceInfo.TOUCH_NONE; 67 } 68 return mInfo; 69 } 70 } 71} 72