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

Commit 44a39fe4 authored by Abel Tesfaye's avatar Abel Tesfaye
Browse files

Fail early in RotationResolverService if camera lock is enabled

Test: locally with flame

Bug: 177462182
Change-Id: I29d84790cfb00a0285ff8dc044daddcdce228ea1
parent dfd02710
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.Manifest;
import android.annotation.NonNull;
import android.annotation.UserIdInt;
import android.content.Context;
import android.hardware.SensorPrivacyManager;
import android.os.Binder;
import android.os.CancellationSignal;
import android.os.ResultReceiver;
@@ -79,6 +80,7 @@ public class RotationResolverManagerService extends
            FrameworkStatsLog.AUTO_ROTATE_REPORTED__PROPOSED_ORIENTATION__FAILURE;

    private final Context mContext;
    private final SensorPrivacyManager mPrivacyManager;
    boolean mIsServiceEnabled;

    public RotationResolverManagerService(Context context) {
@@ -89,6 +91,7 @@ public class RotationResolverManagerService extends
                PACKAGE_UPDATE_POLICY_REFRESH_EAGER
                        | /*To avoid high rotation latency*/ PACKAGE_RESTART_POLICY_REFRESH_EAGER);
        mContext = context;
        mPrivacyManager = SensorPrivacyManager.getInstance(context);
    }

    @Override
@@ -156,15 +159,22 @@ public class RotationResolverManagerService extends
            Objects.requireNonNull(callbackInternal);
            Objects.requireNonNull(cancellationSignalInternal);
            synchronized (mLock) {
                if (mIsServiceEnabled) {
                    final RotationResolverManagerPerUserService service = getServiceForUserLocked(
                final boolean isCameraAvailable = !mPrivacyManager.isSensorPrivacyEnabled(
                        SensorPrivacyManager.Sensors.CAMERA);
                if (mIsServiceEnabled && isCameraAvailable) {
                    final RotationResolverManagerPerUserService service =
                            getServiceForUserLocked(
                                    UserHandle.getCallingUserId());
                    final RotationResolutionRequest request = new RotationResolutionRequest("",
                            currentRotation, proposedRotation, true, timeout);
                    service.resolveRotationLocked(callbackInternal, request,
                            cancellationSignalInternal);
                } else {
                    if (isCameraAvailable) {
                        Slog.w(TAG, "Rotation Resolver service is disabled.");
                    } else {
                        Slog.w(TAG, "Camera is locked by a toggle.");
                    }
                    callbackInternal.onFailure(ROTATION_RESULT_FAILURE_CANCELLED);
                    logRotationStats(proposedRotation, currentRotation, RESOLUTION_DISABLED);
                }