Grabs foreground activity's package name

Passes the foreground activity's package name to Rotation Reosolver.

Test: printed package name locally and it correctly shows the foreground
package.

Bug:181151868
Bug:181150530

Change-Id: Ib6e6504f784283b2d4255da8e54929c6a26cb207
This commit is contained in:
Yi Jiang
2021-03-15 16:25:33 -07:00
parent a9bb9e1b53
commit 6ea16de99d
4 changed files with 36 additions and 9 deletions

View File

@@ -44,6 +44,7 @@ public abstract class RotationResolverInternal {
*
* @param callback the callback that will be called when the result is computed or an
* error is captured. {@link RotationResolverCallbackInternal}
* @param packageName the package name of the fore ground activity.
* @param proposedRotation the screen rotation that is proposed by the system.
* @param currentRotation the current screen rotation.
* @param timeoutMillis the timeout in millisecond for the query. If the query doesn't get
@@ -53,8 +54,10 @@ public abstract class RotationResolverInternal {
* @param cancellationSignal a cancellation signal that notifies the rotation resolver manger
*/
public abstract void resolveRotation(@NonNull RotationResolverCallbackInternal callback,
@Surface.Rotation int proposedRotation, @Surface.Rotation int currentRotation,
@DurationMillisLong long timeoutMillis, @NonNull CancellationSignal cancellationSignal);
String packageName, @Surface.Rotation int proposedRotation,
@Surface.Rotation int currentRotation, @DurationMillisLong long timeoutMillis,
@NonNull CancellationSignal cancellationSignal);
/**
* Internal interfaces for the rotation resolver callback.

View File

@@ -153,8 +153,8 @@ public class RotationResolverManagerService extends
@Override
public void resolveRotation(
@NonNull RotationResolverCallbackInternal callbackInternal, int proposedRotation,
int currentRotation, long timeout,
@NonNull RotationResolverCallbackInternal callbackInternal, String packageName,
int proposedRotation, int currentRotation, long timeout,
@NonNull CancellationSignal cancellationSignalInternal) {
Objects.requireNonNull(callbackInternal);
Objects.requireNonNull(cancellationSignalInternal);
@@ -165,8 +165,16 @@ public class RotationResolverManagerService extends
final RotationResolverManagerPerUserService service =
getServiceForUserLocked(
UserHandle.getCallingUserId());
final RotationResolutionRequest request = new RotationResolutionRequest("",
currentRotation, proposedRotation, true, timeout);
final RotationResolutionRequest request;
if (packageName == null) {
request = new RotationResolutionRequest(/* packageName */ "",
currentRotation, proposedRotation, /* shouldUseCamera */ true,
timeout);
} else {
request = new RotationResolutionRequest(packageName, currentRotation,
proposedRotation, /* shouldUseCamera */ true, timeout);
}
service.resolveRotationLocked(callbackInternal, request,
cancellationSignalInternal);
} else {

View File

@@ -1079,10 +1079,13 @@ public abstract class WindowOrientationListener {
private int mDesiredRotation = -1;
private boolean mRotationEvaluationScheduled;
private long mRotationResolverTimeoutMillis;
private final ActivityTaskManagerInternal mActivityTaskManagerInternal;
OrientationSensorJudge() {
super();
setupRotationResolverParameters();
mActivityTaskManagerInternal =
LocalServices.getService(ActivityTaskManagerInternal.class);
}
private void setupRotationResolverParameters() {
@@ -1149,6 +1152,18 @@ public abstract class WindowOrientationListener {
}
final CancellationSignal cancellationSignal = new CancellationSignal();
String packageName = null;
if (mActivityTaskManagerInternal != null) {
final WindowProcessController controller =
mActivityTaskManagerInternal.getTopApp();
if (controller != null
&& controller.mInfo != null
&& controller.mInfo.packageName != null) {
packageName = controller.mInfo.packageName;
}
}
mRotationResolverService.resolveRotation(
new RotationResolverInternal.RotationResolverCallbackInternal() {
@Override
@@ -1161,6 +1176,7 @@ public abstract class WindowOrientationListener {
finalizeRotation(reportedRotation);
}
},
packageName,
reportedRotation,
mCurrentRotation,
mRotationResolverTimeoutMillis,

View File

@@ -106,8 +106,8 @@ public class WindowOrientationListenerTest {
@Override
public void resolveRotation(@NonNull RotationResolverCallbackInternal callback,
@Surface.Rotation int proposedRotation, @Surface.Rotation int currentRotation,
@DurationMillisLong long timeoutMillis,
String packageName, @Surface.Rotation int proposedRotation,
@Surface.Rotation int currentRotation, @DurationMillisLong long timeoutMillis,
@NonNull CancellationSignal cancellationSignal) {
callback.onSuccess(mResult);
}