Java Code Examples for android.hardware.display.DisplayManager#getDisplay()

The following examples show how to use android.hardware.display.DisplayManager#getDisplay() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public IInputForwarder createInputForwarder(int displayId) throws RemoteException {
    if (!checkCallingPermission(android.Manifest.permission.INJECT_EVENTS,
            "createInputForwarder()")) {
        throw new SecurityException("Requires INJECT_EVENTS permission");
    }
    final DisplayManager displayManager = mContext.getSystemService(DisplayManager.class);
    final Display display = displayManager.getDisplay(displayId);
    if (display == null) {
        throw new IllegalArgumentException(
                "Can't create input forwarder for non-existent displayId: " + displayId);
    }
    final int callingUid = Binder.getCallingUid();
    final int displayOwnerUid = display.getOwnerUid();
    if (callingUid != displayOwnerUid) {
        throw new SecurityException(
                "Only owner of the display can forward input events to it.");
    }

    return new InputForwarder(displayId);
}
 
Example 2
Source File: OffscreenDisplay.java    From FirefoxReality with Mozilla Public License 2.0 6 votes vote down vote up
public void onResume() {
    if (mVirtualDisplay == null) {
        DisplayManager manager = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
        Display defaultDisplay = manager.getDisplay(Display.DEFAULT_DISPLAY);

        int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY;
        defaultDisplay.getMetrics(mDefaultMetrics);

        mVirtualDisplay = manager.createVirtualDisplay("OffscreenViews", mWidth, mHeight,
                mDefaultMetrics.densityDpi, mSurface, flags);
    }

    if (mPresentation == null) {
        mPresentation = new OffscreenPresentation(mContext, mVirtualDisplay.getDisplay());
        mPresentation.show();
        if (mContentView != null) {
            mPresentation.setContentView(mContentView);
        }
    }
}
 
Example 3
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
public Object getService(ContextImpl ctx) {
    Display display = ctx.mDisplay;
    if (display == null) {
        if (mDefaultDisplay == null) {
            DisplayManager dm = (DisplayManager)ctx.getOuterContext().
                    getSystemService(Context.DISPLAY_SERVICE);
            mDefaultDisplay = dm.getDisplay(Display.DEFAULT_DISPLAY);
        }
        display = mDefaultDisplay;
    }
    return new WindowManagerImpl(display);
}
 
Example 4
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
public Object getService(ContextImpl ctx) {
    Display display = ctx.mDisplay;
    if (display == null) {
        if (mDefaultDisplay == null) {
            DisplayManager dm = (DisplayManager)ctx.getOuterContext().
                    getSystemService(Context.DISPLAY_SERVICE);
            mDefaultDisplay = dm.getDisplay(Display.DEFAULT_DISPLAY);
        }
        display = mDefaultDisplay;
    }
    return new WindowManagerImpl(display);
}
 
Example 5
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
public Object getService(ContextImpl ctx) {
    Display display = ctx.mDisplay;
    if (display == null) {
        DisplayManager dm = (DisplayManager)ctx.getOuterContext().getSystemService(
                Context.DISPLAY_SERVICE);
        display = dm.getDisplay(Display.DEFAULT_DISPLAY);
    }
    return new WindowManagerImpl(display);
}
 
Example 6
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
public Object getService(ContextImpl ctx) {
    Display display = ctx.mDisplay;
    if (display == null) {
        DisplayManager dm = (DisplayManager)ctx.getOuterContext().getSystemService(
                Context.DISPLAY_SERVICE);
        display = dm.getDisplay(Display.DEFAULT_DISPLAY);
    }
    return new WindowManagerImpl(display);
}
 
Example 7
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
public Object getService(ContextImpl ctx) {
    Display display = ctx.mDisplay;
    if (display == null) {
        if (mDefaultDisplay == null) {
            DisplayManager dm = (DisplayManager)ctx.getOuterContext().
                    getSystemService(Context.DISPLAY_SERVICE);
            mDefaultDisplay = dm.getDisplay(Display.DEFAULT_DISPLAY);
        }
        display = mDefaultDisplay;
    }
    return new WindowManagerImpl(display);
}
 
Example 8
Source File: BurnInProtectionHelper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public BurnInProtectionHelper(Context context, int minHorizontalOffset,
        int maxHorizontalOffset, int minVerticalOffset, int maxVerticalOffset,
        int maxOffsetRadius) {
    mMinHorizontalBurnInOffset = minHorizontalOffset;
    mMaxHorizontalBurnInOffset = maxHorizontalOffset;
    mMinVerticalBurnInOffset = minVerticalOffset;
    mMaxVerticalBurnInOffset = maxVerticalOffset;
    if (maxOffsetRadius != BURN_IN_MAX_RADIUS_DEFAULT) {
        mBurnInRadiusMaxSquared = maxOffsetRadius * maxOffsetRadius;
    } else {
        mBurnInRadiusMaxSquared = BURN_IN_MAX_RADIUS_DEFAULT;
    }

    mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
    mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    context.registerReceiver(mBurnInProtectionReceiver,
            new IntentFilter(ACTION_BURN_IN_PROTECTION));
    Intent intent = new Intent(ACTION_BURN_IN_PROTECTION);
    intent.setPackage(context.getPackageName());
    intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
    mBurnInProtectionIntent = PendingIntent.getBroadcast(context, 0,
            intent, PendingIntent.FLAG_UPDATE_CURRENT);
    DisplayManager displayManager =
            (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
    mDisplay = displayManager.getDisplay(Display.DEFAULT_DISPLAY);
    displayManager.registerDisplayListener(this, null /* handler */);

    mCenteringAnimator = ValueAnimator.ofFloat(1f, 0f);
    mCenteringAnimator.setDuration(CENTERING_ANIMATION_DURATION_MS);
    mCenteringAnimator.setInterpolator(new LinearInterpolator());
    mCenteringAnimator.addListener(this);
    mCenteringAnimator.addUpdateListener(this);
}
 
Example 9
Source File: WallpaperService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
void attach(IWallpaperEngineWrapper wrapper) {
    if (DEBUG) Log.v(TAG, "attach: " + this + " wrapper=" + wrapper);
    if (mDestroyed) {
        return;
    }
    
    mIWallpaperEngine = wrapper;
    mCaller = wrapper.mCaller;
    mConnection = wrapper.mConnection;
    mWindowToken = wrapper.mWindowToken;
    mSurfaceHolder.setSizeFromLayout();
    mInitializing = true;
    mSession = WindowManagerGlobal.getWindowSession();
    
    mWindow.setSession(mSession);

    mLayout.packageName = getPackageName();

    mDisplayManager = (DisplayManager)getSystemService(Context.DISPLAY_SERVICE);
    mDisplayManager.registerDisplayListener(mDisplayListener, mCaller.getHandler());
    mDisplay = mDisplayManager.getDisplay(Display.DEFAULT_DISPLAY);
    mDisplayState = mDisplay.getState();

    if (DEBUG) Log.v(TAG, "onCreate(): " + this);
    onCreate(mSurfaceHolder);
    
    mInitializing = false;
    mReportedVisible = false;
    updateSurface(false, false, false);
}
 
Example 10
Source File: ScreenRecordActivity.java    From grafika with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.M)
private void startRecording() {
  DisplayManager dm = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
  Display defaultDisplay;
  if (dm != null) {
    defaultDisplay = dm.getDisplay(Display.DEFAULT_DISPLAY);
  } else {
    throw new IllegalStateException("Cannot display manager?!?");
  }
  if (defaultDisplay == null) {
    throw new RuntimeException("No display found.");
  }

  // Get the display size and density.
  DisplayMetrics metrics = getResources().getDisplayMetrics();
  int screenWidth = metrics.widthPixels;
  int screenHeight = metrics.heightPixels;
  int screenDensity = metrics.densityDpi;

  prepareVideoEncoder(screenWidth, screenHeight);

  try {
    File outputFile = new File(Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES) + "/grafika", "Screen-record-" +
            Long.toHexString(System.currentTimeMillis()) + ".mp4");
    if (!outputFile.getParentFile().exists()) {
      outputFile.getParentFile().mkdirs();
    }
    muxer = new MediaMuxer(outputFile.getCanonicalPath(), MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
  } catch (IOException ioe) {
    throw new RuntimeException("MediaMuxer creation failed", ioe);
  }


  // Start the video input.
  mediaProjection.createVirtualDisplay("Recording Display", screenWidth,
          screenHeight, screenDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR/* flags */, inputSurface,
          null /* callback */, null /* handler */);
}
 
Example 11
Source File: ActivityManagerShellCommand.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
int runGetConfig(PrintWriter pw) throws RemoteException {
    int days = -1;
    boolean asProto = false;
    boolean inclDevice = false;

    String opt;
    while ((opt=getNextOption()) != null) {
        if (opt.equals("--days")) {
            days = Integer.parseInt(getNextArgRequired());
            if (days <= 0) {
                throw new IllegalArgumentException("--days must be a positive integer");
            }
        } else if (opt.equals("--proto")) {
            asProto = true;
        } else if (opt.equals("--device")) {
            inclDevice = true;
        } else {
            getErrPrintWriter().println("Error: Unknown option: " + opt);
            return -1;
        }
    }

    Configuration config = mInterface.getConfiguration();
    if (config == null) {
        getErrPrintWriter().println("Activity manager has no configuration");
        return -1;
    }

    DisplayManager dm = mInternal.mContext.getSystemService(DisplayManager.class);
    Display display = dm.getDisplay(Display.DEFAULT_DISPLAY);
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);

    if (asProto) {
        final ProtoOutputStream proto = new ProtoOutputStream(getOutFileDescriptor());
        config.writeResConfigToProto(proto, GlobalConfigurationProto.RESOURCES, metrics);
        if (inclDevice) {
            writeDeviceConfig(proto, GlobalConfigurationProto.DEVICE, null, config, dm);
        }
        proto.flush();

    } else {
        pw.println("config: " + Configuration.resourceQualifierString(config, metrics));
        pw.println("abi: " + TextUtils.join(",", Build.SUPPORTED_ABIS));
        if (inclDevice) {
            writeDeviceConfig(null, -1, pw, config, dm);
        }

        if (days >= 0) {
            final List<Configuration> recentConfigs = getRecentConfigurations(days);
            final int recentConfigSize = recentConfigs.size();
            if (recentConfigSize > 0) {
                pw.println("recentConfigs:");
                for (int i = 0; i < recentConfigSize; i++) {
                    pw.println("  config: " + Configuration.resourceQualifierString(
                            recentConfigs.get(i)));
                }
            }
        }

    }
    return 0;
}