PageRenderTime 22ms CodeModel.GetById 13ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/services/java/com/android/server/display/HeadlessDisplayAdapter.java

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