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