DisplayManager.java revision aa871b0ff0fb38112a1693e80e1146cecc5db21d
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 android.hardware.display;
18
19import android.content.Context;
20import android.os.IBinder;
21import android.os.RemoteException;
22import android.os.ServiceManager;
23import android.util.Log;
24import android.view.DisplayInfo;
25
26/**
27 * Manages the properties, media routing and power state of attached displays.
28 * <p>
29 * Get an instance of this class by calling
30 * {@link android.content.Context#getSystemService(java.lang.String)
31 * Context.getSystemService()} with the argument
32 * {@link android.content.Context#DISPLAY_SERVICE}.
33 * </p>
34 */
35public final class DisplayManager {
36    private static final String TAG = "DisplayManager";
37
38    private static DisplayManager sInstance;
39
40    private final IDisplayManager mDm;
41
42    private DisplayManager(IDisplayManager dm) {
43        mDm = dm;
44    }
45
46    /**
47     * Gets an instance of the display manager.
48     * @return The display manager instance.
49     * @hide
50     */
51    public static DisplayManager getInstance() {
52        synchronized (DisplayManager.class) {
53            if (sInstance == null) {
54                IBinder b = ServiceManager.getService(Context.DISPLAY_SERVICE);
55                sInstance = new DisplayManager(IDisplayManager.Stub.asInterface(b));
56            }
57            return sInstance;
58        }
59    }
60
61    /**
62     * Get information about a particular logical display.
63     *
64     * @param displayId The logical display id.
65     * @param outInfo A structure to populate with the display info.
66     * @return True if the logical display exists, false otherwise.
67     * @hide
68     */
69    public boolean getDisplayInfo(int displayId, DisplayInfo outInfo) {
70        try {
71            return mDm.getDisplayInfo(displayId, outInfo);
72        } catch (RemoteException ex) {
73            Log.e(TAG, "Could not get display information from display manager.", ex);
74            return false;
75        }
76    }
77}
78