private void createCameraSource() {
    int screenWidth;
    int screenHeight;
    if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB_MR2) {
      Point size = new Point();
      getWindowManager().getDefaultDisplay().getSize(size);
      screenHeight = size.y;
      screenWidth = size.x;
    } else {
      Display display = getWindowManager().getDefaultDisplay();
      screenHeight = display.getHeight();
      screenWidth = display.getWidth();
    }

    if (screenWidth > screenHeight) {
      int tmp = screenWidth;
      screenWidth = screenHeight;
      screenHeight = tmp;
    }

    // There are devices that don't have a rear camera, like a version of the Nexus 7. Here we
    // check if the device has a rear camera, and if not, try to use the front camera instead.
    int cameraFacing = CameraSource.CAMERA_FACING_BACK;
    PackageManager packageManager = getPackageManager();
    if (!packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)
        && packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
      cameraFacing = CameraSource.CAMERA_FACING_FRONT;
    }

    // A barcode detector is created to track barcodes.  An associated focussing processor instance
    // is set with a barcode tracker to receive the barcode detection results, track the barcodes,
    // filter out the barcodes that are not inside the square rectangle and return the callback
    // when a valid barcode is detected.
    final AuthenticatorApplication application =
        (AuthenticatorApplication) getApplicationContext();
    BarcodeDetector barcodeDetector = application.getBarcodeDetector();
    BarcodeTracker barcodeTracker = new BarcodeTracker();
    barcodeTracker.setDetectionListener(mDetectionListener);
    // We disable central filter for front-facing camera as it is hard for users to place the
    // barcode completely inside the square with a front-facing camera.
    barcodeDetector.setProcessor(
        new BarcodeCentralFocusingProcessor(barcodeDetector, barcodeTracker,
            cameraFacing == CameraSource.CAMERA_FACING_BACK /* centralFilterEnabled */));

    CameraSource.Builder builder
        = new CameraSource.Builder(getApplicationContext(), barcodeDetector)
        .setFacing(cameraFacing)
        // TODO: Consider removing autofocus. For Pixel 2 phones, scanning the QR Code becomes
        // difficult.
        .setAutoFocusEnabled(true)
        .setRequestedPreviewSize(screenHeight, screenWidth)
        .setRequestedFps(PREFERRED_FRAMERATE);

    mCameraSource = builder.build();
  }
Handles the requesting of the camera permission.  This includes showing a "Snackbar" message of
why the permission is needed then sending the request.
java/com/google/android/apps/authenticator/barcode/BarcodeCaptureActivity.java