DisplayManager.java revision 848c2dc93b6795e171f3dd6f64ea0be65e2762ca
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     *
49     * @return The display manager instance, may be null early in system startup
50     * before the display manager has been fully initialized.
51     *
52     * @hide
53     */
54    public static DisplayManager getInstance() {
55        synchronized (DisplayManager.class) {
56            if (sInstance == null) {
57                IBinder b = ServiceManager.getService(Context.DISPLAY_SERVICE);
58                if (b != null) {
59                    sInstance = new DisplayManager(IDisplayManager.Stub.asInterface(b));
60                }
61            }
62            return sInstance;
63        }
64    }
65
66    /**
67     * Get information about a particular logical display.
68     *
69     * @param displayId The logical display id.
70     * @param outInfo A structure to populate with the display info.
71     * @return True if the logical display exists, false otherwise.
72     * @hide
73     */
74    public boolean getDisplayInfo(int displayId, DisplayInfo outInfo) {
75        try {
76            return mDm.getDisplayInfo(displayId, outInfo);
77        } catch (RemoteException ex) {
78            Log.e(TAG, "Could not get display information from display manager.", ex);
79            return false;
80        }
81    }
82}
83