Incorrect panel layout after rotation
-Handle onConfigurationChanged and force to update layout
-Add test case
Bug: 144751509
Test: make -j42 RunSettingsRoboTests
Change-Id: Ic170d4f6f045299c0520e899e06b5b4e9f009643
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index b494d35..18cf866 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3180,6 +3180,7 @@
android:theme="@style/Theme.Panel"
android:launchMode="singleInstance"
android:excludeFromRecents="true"
+ android:configChanges="orientation|keyboardHidden|screenSize"
android:exported="true">
<intent-filter>
<action android:name="android.settings.panel.action.INTERNET_CONNECTIVITY" />
diff --git a/src/com/android/settings/panel/SettingsPanelActivity.java b/src/com/android/settings/panel/SettingsPanelActivity.java
index ce437bb..da46564 100644
--- a/src/com/android/settings/panel/SettingsPanelActivity.java
+++ b/src/com/android/settings/panel/SettingsPanelActivity.java
@@ -19,12 +19,14 @@
import static com.android.settingslib.media.MediaOutputSliceConstants.EXTRA_PACKAGE_NAME;
import android.content.Intent;
+import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
@@ -43,6 +45,8 @@
@VisibleForTesting
final Bundle mBundle = new Bundle();
+ @VisibleForTesting
+ boolean mForceCreation = false;
/**
* Key specifying which Panel the app is requesting.
@@ -59,8 +63,6 @@
*/
public static final String KEY_MEDIA_PACKAGE_NAME = "PANEL_MEDIA_PACKAGE_NAME";
- private boolean mForceCreation = false;
-
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -87,6 +89,12 @@
mForceCreation = true;
}
+ @Override
+ public void onConfigurationChanged(@NonNull Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ mForceCreation = true;
+ }
+
private void createOrUpdatePanel(boolean shouldForceCreation) {
final Intent callingIntent = getIntent();
if (callingIntent == null) {
diff --git a/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java b/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java
index 44e5eefc..833d510 100644
--- a/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java
+++ b/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java
@@ -31,6 +31,7 @@
import static org.mockito.Mockito.when;
import android.content.Intent;
+import android.content.res.Configuration;
import android.os.Build;
import android.view.Window;
import android.view.WindowManager;
@@ -139,4 +140,12 @@
assertThat(paramCaptor.getValue().privateFlags
& SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS).isEqualTo(0);
}
+
+ @Test
+ public void onConfigurationChanged_shouldForceUpdate() {
+ mSettingsPanelActivity.mForceCreation = false;
+ mSettingsPanelActivity.onConfigurationChanged(new Configuration());
+
+ assertThat(mSettingsPanelActivity.mForceCreation).isTrue();
+ }
}