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

Commit 51d8516b authored by Yin-Chia Yeh's avatar Yin-Chia Yeh
Browse files

Camera: add camera audio restriction API

Test: new CTS tests
Bug: 135676184
Change-Id: I4f28d28972b9ced0fee0afe996ef1c4f68d0d2c9
parent 2ff45bfa
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 void 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
+60 −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,35 @@ 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.
     *
     * @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 void 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
+6 −0
Original line number Diff line number Diff line
@@ -2568,4 +2568,10 @@ public class CameraDeviceImpl extends CameraDevice
            Binder.restoreCallingIdentity(ident);
        }
    }

    @Override
    public void setCameraAudioRestriction(@CAMERA_AUDIO_RESTRICTION int mode) {
        // To be implemented.
        return;
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ interface IAppOpsService {
    void noteAsyncOp(String callingPackageName, int uid, String packageName, int opCode,
            String message);
    boolean shouldCollectNotes(int opCode);
    void setCameraAudioRestriction(int mode);
    // End of methods also called by native code.
    // Any new method exposed to native must be added after the last one, do not reorder

+1 −0
Original line number Diff line number Diff line
@@ -166,6 +166,7 @@
    <assign-permission name="android.permission.GET_PROCESS_STATE_AND_OOM_SCORE" uid="cameraserver" />
    <assign-permission name="android.permission.PACKAGE_USAGE_STATS" uid="cameraserver" />
    <assign-permission name="android.permission.WATCH_APPOPS" uid="cameraserver" />
    <assign-permission name="android.permission.MANAGE_APP_OPS_MODES" uid="cameraserver" />

    <assign-permission name="android.permission.ACCESS_SURFACE_FLINGER" uid="graphics" />

Loading