Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 437654eb authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "camera-mute-api"

* changes:
  Camera: camera service implementation of camera audio restriction API
  Camera: add camera audio restriction API
parents db53f73f 3eb79d63
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -16904,6 +16904,10 @@ package android.hardware.camera2 {
    method public abstract void createReprocessableCaptureSessionByConfigurations(@NonNull android.hardware.camera2.params.InputConfiguration, @NonNull java.util.List<android.hardware.camera2.params.OutputConfiguration>, @NonNull android.hardware.camera2.CameraCaptureSession.StateCallback, @Nullable android.os.Handler) throws android.hardware.camera2.CameraAccessException;
    method @NonNull public abstract String getId();
    method public boolean isSessionConfigurationSupported(@NonNull android.hardware.camera2.params.SessionConfiguration) throws android.hardware.camera2.CameraAccessException;
    method public int setCameraAudioRestriction(int) throws android.hardware.camera2.CameraAccessException;
    field public static final int AUDIO_RESTRICTION_NONE = 0; // 0x0
    field public static final int AUDIO_RESTRICTION_VIBRATION = 1; // 0x1
    field public static final int AUDIO_RESTRICTION_VIBRATION_SOUND = 3; // 0x3
    field public static final int TEMPLATE_MANUAL = 6; // 0x6
    field public static final int TEMPLATE_PREVIEW = 1; // 0x1
    field public static final int TEMPLATE_RECORD = 3; // 0x3
+7 −0
Original line number Diff line number Diff line
@@ -2168,6 +2168,13 @@ public class Camera {
        return p;
    }

    /**
     * Setting camera audio restriction mode.
     *
     * @hide
     */
    public native final int setAudioRestriction(int mode);

    /**
     * Image size (width and height dimensions).
     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
+62 −0
Original line number Diff line number Diff line
@@ -164,6 +164,37 @@ public abstract class CameraDevice implements AutoCloseable {
          TEMPLATE_MANUAL})
     public @interface RequestTemplate {};

     /**
      * No vibration or sound muting for this camera device. This is the default
      * mode for all camera devices.
      *
      * @see #setCameraAudioRestriction
      */
     public static final int AUDIO_RESTRICTION_NONE = 0;

     /**
      * Mute vibration from ringtones, alarms or notifications while this camera device is in use.
      *
      * @see #setCameraAudioRestriction
      */
     public static final int AUDIO_RESTRICTION_VIBRATION = 1;

     /**
      * Mute vibration and sound from ringtones, alarms or notifications while this camera device is
      * in use.
      *
      * @see #setCameraAudioRestriction
      */
     public static final int AUDIO_RESTRICTION_VIBRATION_SOUND = 3;

     /** @hide */
     @Retention(RetentionPolicy.SOURCE)
     @IntDef(prefix = {"AUDIO_RESTRICTION_"}, value =
         {AUDIO_RESTRICTION_NONE,
          AUDIO_RESTRICTION_VIBRATION,
          AUDIO_RESTRICTION_VIBRATION_SOUND})
     public @interface CAMERA_AUDIO_RESTRICTION {};

    /**
     * Get the ID of this camera device.
     *
@@ -1207,6 +1238,37 @@ public abstract class CameraDevice implements AutoCloseable {
                @ErrorCode int error); // Must implement
    }

    /**
     * Set audio restriction mode when this CameraDevice is being used.
     *
     * <p>Some camera hardware (e.g. devices with optical image stabilization support)
     * are sensitive to device vibration and video recordings can be ruined by unexpected sounds.
     * Applications can use this method to suppress vibration or sounds coming from
     * ringtones, alarms or notifications.
     * Other vibration or sounds (e.g. media playback or accessibility) will not be muted.</p>
     *
     * <p>The mute mode is a system-wide setting. When multiple CameraDevice objects
     * are setting different modes, the system will pick a the mode that's union of
     * all modes set by CameraDevice.</p>
     *
     * <p>The mute settings will be automatically removed when the CameraDevice is closed or
     * the application is disconnected from the camera.</p>
     *
     * @param mode An enumeration selecting the audio restriction mode for this camera device.
     *
     * @return The system-wide mute mode setting resulting from this call
     *
     * @throws IllegalArgumentException if the mode is not supported
     *
     * @throws CameraAccessException if the camera device is no longer connected or has
     *                               encountered a fatal error
     * @throws IllegalStateException if the camera device has been closed
     */
    public @CAMERA_AUDIO_RESTRICTION int setCameraAudioRestriction(
            @CAMERA_AUDIO_RESTRICTION int mode) throws CameraAccessException {
        throw new UnsupportedOperationException("Subclasses must override this method");
    }

    /**
     * To be inherited by android.hardware.camera2.* code only.
     * @hide
+9 −0
Original line number Diff line number Diff line
@@ -2568,4 +2568,13 @@ public class CameraDeviceImpl extends CameraDevice
            Binder.restoreCallingIdentity(ident);
        }
    }

    @Override
    public @CAMERA_AUDIO_RESTRICTION int setCameraAudioRestriction(
            @CAMERA_AUDIO_RESTRICTION int mode) throws CameraAccessException {
        synchronized(mInterfaceLock) {
            checkIfCameraClosedOrInError();
            return mRemoteDevice.setCameraAudioRestriction(mode);
        }
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -258,4 +258,13 @@ public class ICameraDeviceUserWrapper {
        }
    }

    public int setCameraAudioRestriction(int mode) throws CameraAccessException {
        try {
            return mRemoteDevice.setCameraAudioRestriction(mode);
        } catch (Throwable t) {
            CameraManager.throwAsPublicException(t);
            throw new UnsupportedOperationException("Unexpected exception", t);
        }
    }

}
Loading