|
| 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 | + |
| 17 | +package android.hardware.display; |
| 18 | + |
| 19 | +import android.content.Context; |
| 20 | +import android.os.IBinder; |
| 21 | +import android.os.RemoteException; |
| 22 | +import android.os.ServiceManager; |
| 23 | +import android.util.Log; |
| 24 | +import 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 | + */ |
| 35 | +public 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 | + */ |
| 68 | + public boolean getDisplayInfo(int displayId, DisplayInfo outInfo) { |
| 69 | + try { |
| 70 | + return mDm.getDisplayInfo(displayId, outInfo); |
| 71 | + } catch (RemoteException ex) { |
| 72 | + Log.e(TAG, "Could not get display information from display manager.", ex); |
| 73 | + return false; |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments