1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.rotationresolver; 18 19 import android.annotation.DurationMillisLong; 20 import android.annotation.NonNull; 21 import android.os.CancellationSignal; 22 import android.service.rotationresolver.RotationResolverService; 23 import android.view.Surface; 24 25 /** 26 * Internal service for resolving screen rotation. 27 * 28 * @hide Only for use within the system server. 29 */ 30 public abstract class RotationResolverInternal { 31 32 /** 33 * Returns {@code true} if rotation resolver service is supported on the current device. 34 */ isRotationResolverSupported()35 public abstract boolean isRotationResolverSupported(); 36 37 /** 38 * Queries the appropriate screen orientation. 39 * 40 * <p> The screen rotation that's proposed by the system may not be accurate enough. This method 41 * is available for the system to request a screen rotation resolution from the {@link 42 * RotationResolverService}, which can intelligently determine the appropriate screen rotation 43 * based on various sensors. 44 * 45 * @param callback the callback that will be called when the result is computed or an 46 * error is captured. {@link RotationResolverCallbackInternal} 47 * @param packageName the package name of the fore ground activity. 48 * @param proposedRotation the screen rotation that is proposed by the system. 49 * @param currentRotation the current screen rotation. 50 * @param timeoutMillis the timeout in millisecond for the query. If the query doesn't get 51 * fulfilled within this amount of time. It will be discarded and the 52 * callback will receive a failure result code {@link 53 * RotationResolverService#ROTATION_RESULT_FAILURE_TIMED_OUT}. 54 * @param cancellationSignal a cancellation signal that notifies the rotation resolver manger 55 */ resolveRotation(@onNull RotationResolverCallbackInternal callback, String packageName, @Surface.Rotation int proposedRotation, @Surface.Rotation int currentRotation, @DurationMillisLong long timeoutMillis, @NonNull CancellationSignal cancellationSignal)56 public abstract void resolveRotation(@NonNull RotationResolverCallbackInternal callback, 57 String packageName, @Surface.Rotation int proposedRotation, 58 @Surface.Rotation int currentRotation, @DurationMillisLong long timeoutMillis, 59 @NonNull CancellationSignal cancellationSignal); 60 61 62 /** 63 * Internal interfaces for the rotation resolver callback. 64 */ 65 public interface RotationResolverCallbackInternal { 66 /** 67 * Gets called when the screen rotation is calculated successfully. 68 * 69 * @param result the resolved screen rotation. 70 */ onSuccess(@urface.Rotation int result)71 void onSuccess(@Surface.Rotation int result); 72 73 /** 74 * Gets called when it fails to resolve the screen rotation. 75 * 76 * @param error the reason of the failure. 77 */ onFailure(@otationResolverService.FailureCodes int error)78 void onFailure(@RotationResolverService.FailureCodes int error); 79 } 80 } 81