diff options
7 files changed, 38 insertions, 26 deletions
diff --git a/core/java/com/android/internal/statusbar/IStatusBar.aidl b/core/java/com/android/internal/statusbar/IStatusBar.aidl index 85655a5dfc6b..e097362a3fe8 100644 --- a/core/java/com/android/internal/statusbar/IStatusBar.aidl +++ b/core/java/com/android/internal/statusbar/IStatusBar.aidl @@ -115,7 +115,7 @@ oneway interface IStatusBar /** * Notifies the status bar that a new rotation suggestion is available. */ - void onProposedRotationChanged(int rotation); + void onProposedRotationChanged(int rotation, boolean isValid); /** * Set whether the top app currently hides the statusbar. diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 6437903bd12a..99ba36965231 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -1702,12 +1702,14 @@ <item>Clipboard</item> <item>Keycode</item> <item>Keyboard switcher</item> + <item>Rotation suggestion</item> <item>None</item> </string-array> <string-array name="nav_bar_button_values" translatable="false"> <item>clipboard</item> <item>key</item> <item>menu_ime</item> + <item>rotate</item> <item>space</item> </string-array> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java index 657b9534f3a8..c6abcf272722 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java @@ -144,7 +144,7 @@ public class CommandQueue extends IStatusBar.Stub { default void handleShowGlobalActionsMenu() { } default void handleShowShutdownUi(boolean isReboot, String reason) { } - default void onRotationProposal(int rotation) { } + default void onRotationProposal(int rotation, boolean isValid) { } } @VisibleForTesting @@ -462,10 +462,10 @@ public class CommandQueue extends IStatusBar.Stub { } @Override - public void onProposedRotationChanged(int rotation) { + public void onProposedRotationChanged(int rotation, boolean isValid) { synchronized (mLock) { mHandler.removeMessages(MSG_ROTATION_PROPOSAL); - mHandler.obtainMessage(MSG_ROTATION_PROPOSAL, rotation, 0, + mHandler.obtainMessage(MSG_ROTATION_PROPOSAL, rotation, isValid ? 1 : 0, null).sendToTarget(); } } @@ -668,7 +668,7 @@ public class CommandQueue extends IStatusBar.Stub { break; case MSG_ROTATION_PROPOSAL: for (int i = 0; i < mCallbacks.size(); i++) { - mCallbacks.get(i).onRotationProposal(msg.arg1); + mCallbacks.get(i).onRotationProposal(msg.arg1, msg.arg2 != 0); } break; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java index 70ec45e4cdb4..42258439190e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java @@ -335,9 +335,16 @@ public class NavigationBarFragment extends Fragment implements Callbacks { } @Override - public void onRotationProposal(final int rotation) { - // This method will only be called if rotation is valid but will include proposals for the - // current system rotation + public void onRotationProposal(final int rotation, boolean isValid) { + // This method will be called on rotation suggestion changes even if the proposed rotation + // is not valid for the top app. Use invalid rotation choices as a signal to remove the + // rotate button if shown. + + if (!isValid) { + setRotateSuggestionButtonState(false); + return; + } + Handler h = getView().getHandler(); if (rotation == mWindowManager.getDefaultDisplay().getRotation()) { // Use this as a signal to remove any current suggestions diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index 63449976587e..a03658622c7a 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -66,7 +66,6 @@ import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; import static android.view.WindowManager.LayoutParams.LAST_SYSTEM_WINDOW; import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT; -import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER; import static android.view.WindowManager.LayoutParams.MATCH_PARENT; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND; @@ -163,13 +162,10 @@ import android.app.StatusBarManager; import android.app.UiModeManager; import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; -import android.content.ComponentCallbacks; -import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.ServiceConnection; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; @@ -202,7 +198,6 @@ import android.os.IBinder; import android.os.IDeviceIdleController; import android.os.Looper; import android.os.Message; -import android.os.Messenger; import android.os.PowerManager; import android.os.PowerManagerInternal; import android.os.Process; @@ -1030,8 +1025,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { public void run() { // send interaction hint to improve redraw performance mPowerManagerInternal.powerHint(PowerHint.INTERACTION, 0); - if (showRotationChoice(mCurrentAppOrientation, mRotation)) { - sendProposedRotationChangeToStatusBarInternal(mRotation); + if (isRotationChoiceEnabled()) { + final boolean isValid = isValidRotationChoice(mCurrentAppOrientation, + mRotation); + sendProposedRotationChangeToStatusBarInternal(mRotation, isValid); } else { updateRotation(false); } @@ -6193,10 +6190,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { /** * Notify the StatusBar that system rotation suggestion has changed. */ - private void sendProposedRotationChangeToStatusBarInternal(int rotation) { + private void sendProposedRotationChangeToStatusBarInternal(int rotation, boolean isValid) { StatusBarManagerInternal statusBar = getStatusBarManagerInternal(); if (statusBar != null) { - statusBar.onProposedRotationChanged(rotation); + statusBar.onProposedRotationChanged(rotation, isValid); } } @@ -7142,15 +7139,14 @@ public class PhoneWindowManager implements WindowManagerPolicy { mOrientationListener.setCurrentRotation(rotation); } - public boolean showRotationChoice(int orientation, final int preferredRotation) { + public boolean isRotationChoiceEnabled() { // Rotation choice is only shown when the user is in locked mode. if (mUserRotationMode != WindowManagerPolicy.USER_ROTATION_LOCKED) return false; - // We should only show a rotation choice if: - // 1. The rotation isn't forced by the lid, dock, demo, hdmi, vr, etc mode - // 2. The user choice won't be ignored due to screen orientation settings + // We should only enable rotation choice if the rotation isn't forced by the lid, dock, + // demo, hdmi, vr, etc mode - // Determine if the rotation currently forced + // Determine if the rotation is currently forced if (mForceDefaultOrientation) { return false; // Rotation is forced to default orientation @@ -7183,7 +7179,14 @@ public class PhoneWindowManager implements WindowManagerPolicy { return false; } - // Determine if the orientation will ignore user choice + // Rotation isn't forced, enable choice + return true; + } + + public boolean isValidRotationChoice(int orientation, final int preferredRotation) { + // Determine if the given app orientation can be chosen and, if so, if it is compatible + // with the provided rotation choice + switch (orientation) { case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: diff --git a/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java b/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java index b5d0c60efae8..95006ffb2ed6 100644 --- a/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java +++ b/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java @@ -95,7 +95,7 @@ public interface StatusBarManagerInternal { * * @param rotation rotation suggestion */ - void onProposedRotationChanged(int rotation); + void onProposedRotationChanged(int rotation, boolean isValid); public interface GlobalActionsListener { /** diff --git a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java index 79d3dbbe8c83..c58c208dea81 100644 --- a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java +++ b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java @@ -408,10 +408,10 @@ public class StatusBarManagerService extends IStatusBarService.Stub { } @Override - public void onProposedRotationChanged(int rotation) { + public void onProposedRotationChanged(int rotation, boolean isValid) { if (mBar != null){ try { - mBar.onProposedRotationChanged(rotation); + mBar.onProposedRotationChanged(rotation, isValid); } catch (RemoteException ex) {} } } |