HeadlessDisplayAdapter.java revision c5df37c285221d0fb113f55b9e78b35632241d3f
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    public HeadlessDisplayAdapter(DisplayManagerService.SyncRoot syncRoot,
33            Context context, Handler handler, Listener listener) {
34        super(syncRoot, context, handler, listener, TAG);
35    }
36
37    @Override
38    public void registerLocked() {
39        super.registerLocked();
40        sendDisplayDeviceEventLocked(new HeadlessDisplayDevice(), DISPLAY_DEVICE_EVENT_ADDED);
41    }
42
43    private final class HeadlessDisplayDevice extends DisplayDevice {
44        private DisplayDeviceInfo mInfo;
45
46        public HeadlessDisplayDevice() {
47            super(HeadlessDisplayAdapter.this, null);
48        }
49
50        @Override
51        public DisplayDeviceInfo getDisplayDeviceInfoLocked() {
52            if (mInfo == null) {
53                mInfo = new DisplayDeviceInfo();
54                mInfo.name = getContext().getResources().getString(
55                        com.android.internal.R.string.display_manager_built_in_display_name);
56                mInfo.width = 640;
57                mInfo.height = 480;
58                mInfo.refreshRate = 60;
59                mInfo.densityDpi = DisplayMetrics.DENSITY_DEFAULT;
60                mInfo.xDpi = 160;
61                mInfo.yDpi = 160;
62                mInfo.flags = DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY
63                        | DisplayDeviceInfo.FLAG_SUPPORTS_SECURE_VIDEO_OUTPUT;
64                mInfo.touch = DisplayDeviceInfo.TOUCH_NONE;
65            }
66            return mInfo;
67        }
68    }
69}
70