Retain the selected filter even after the device orientation change.
The selected filter should be retained displaying the list even after the device orientation change. Bug: 36380176 Test: atest packages/apps/Settings/tests/uitests/src/com/android/settings/ui/AppsSettingsRetainFilterTests.java Change-Id: I7830b525343ce597929771ad4db55a803f893432
This commit is contained in:
@@ -155,6 +155,7 @@ public class ManageApplications extends InstrumentedFragment
|
||||
private static final String EXTRA_SHOW_SYSTEM = "showSystem";
|
||||
private static final String EXTRA_HAS_ENTRIES = "hasEntries";
|
||||
private static final String EXTRA_HAS_BRIDGE = "hasBridge";
|
||||
private static final String EXTRA_FILTER_TYPE = "filterType";
|
||||
|
||||
// attributes used as keys when passing values to AppInfoDashboardFragment activity
|
||||
public static final String APP_CHG = "chg";
|
||||
@@ -231,6 +232,7 @@ public class ManageApplications extends InstrumentedFragment
|
||||
private boolean mIsWorkOnly;
|
||||
private int mWorkUserId;
|
||||
private View mEmptyView;
|
||||
private int mFilterType;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -311,6 +313,8 @@ public class ManageApplications extends InstrumentedFragment
|
||||
if (savedInstanceState != null) {
|
||||
mSortOrder = savedInstanceState.getInt(EXTRA_SORT_ORDER, mSortOrder);
|
||||
mShowSystem = savedInstanceState.getBoolean(EXTRA_SHOW_SYSTEM, mShowSystem);
|
||||
mFilterType =
|
||||
savedInstanceState.getInt(EXTRA_FILTER_TYPE, AppFilterRegistry.FILTER_APPS_ALL);
|
||||
}
|
||||
|
||||
mInvalidSizeStr = activity.getText(R.string.invalid_size_value);
|
||||
@@ -493,6 +497,7 @@ public class ManageApplications extends InstrumentedFragment
|
||||
outState.putBoolean(EXTRA_SHOW_SYSTEM, mShowSystem);
|
||||
outState.putBoolean(EXTRA_HAS_ENTRIES, mApplications.mHasReceivedLoadEntries);
|
||||
outState.putBoolean(EXTRA_HAS_BRIDGE, mApplications.mHasReceivedBridgeCallback);
|
||||
outState.putInt(EXTRA_FILTER_TYPE, mFilter.getFilterType());
|
||||
if (mApplications != null) {
|
||||
mApplications.onSaveInstanceState(outState);
|
||||
}
|
||||
@@ -789,6 +794,16 @@ public class ManageApplications extends InstrumentedFragment
|
||||
mManageApplications.mFilterSpinner.setSelection(0);
|
||||
mManageApplications.onItemSelected(null, null, 0, 0);
|
||||
}
|
||||
if (mFilterOptions.size() > 1) {
|
||||
if (filterType == mManageApplications.mFilterType) {
|
||||
int index = mFilterOptions.indexOf(filter);
|
||||
if (index != -1) {
|
||||
mManageApplications.mFilterSpinner.setSelection(index);
|
||||
mManageApplications.onItemSelected(null, null, index, 0);
|
||||
mManageApplications.mFilterType = AppFilterRegistry.FILTER_APPS_ALL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void disableFilter(@AppFilterRegistry.FilterType int filterType) {
|
||||
|
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.ui;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.RemoteException;
|
||||
import android.provider.Settings;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.support.test.uiautomator.By;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
import android.support.test.uiautomator.UiObject2;
|
||||
import android.support.test.uiautomator.Until;
|
||||
import android.system.helpers.ActivityHelper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class AppsSettingsRetainFilterTests {
|
||||
private static final int TIMEOUT = 2000;
|
||||
private UiDevice mDevice;
|
||||
private ActivityHelper mActivityHelper = null;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
|
||||
mActivityHelper = ActivityHelper.getInstance();
|
||||
|
||||
try {
|
||||
mDevice.setOrientationNatural();
|
||||
} catch (RemoteException e) {
|
||||
throw new RuntimeException("failed to freeze device orientation", e);
|
||||
}
|
||||
|
||||
mDevice.pressHome();
|
||||
mDevice.waitForIdle(TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisablingSystemAppAndRotateDevice() throws Exception {
|
||||
launchAppsSettings();
|
||||
|
||||
UiObject2 calculator = mDevice.wait(
|
||||
Until.findObject(By.text("Calculator")), TIMEOUT);
|
||||
assertThat(calculator).isNotNull();
|
||||
calculator.click();
|
||||
mDevice.waitForIdle(TIMEOUT);
|
||||
|
||||
UiObject2 disableButton = mDevice.wait(
|
||||
Until.findObject(By.text("DISABLE")), TIMEOUT);
|
||||
assertThat(disableButton).isNotNull();
|
||||
disableButton.click();
|
||||
mDevice.waitForIdle(TIMEOUT);
|
||||
|
||||
// Click on "Disable App" on dialog.
|
||||
UiObject2 dialogDisableButton = mDevice.wait(
|
||||
Until.findObject(By.text("DISABLE APP")), TIMEOUT);
|
||||
assertThat(dialogDisableButton).isNotNull();
|
||||
dialogDisableButton.click();
|
||||
mDevice.waitForIdle(TIMEOUT);
|
||||
|
||||
UiObject2 enableButton = mDevice.wait(
|
||||
Until.findObject(By.text("ENABLE")), TIMEOUT);
|
||||
assertThat(enableButton).isNotNull();
|
||||
|
||||
mDevice.pressBack();
|
||||
mDevice.waitForIdle(TIMEOUT);
|
||||
|
||||
UiObject2 spinnerHeader = mDevice.wait(
|
||||
Until.findObject(By.text("All apps")), TIMEOUT);
|
||||
assertThat(spinnerHeader).isNotNull();
|
||||
spinnerHeader.click();
|
||||
|
||||
UiObject2 optionDisabledApps = mDevice.wait(
|
||||
Until.findObject(By.text("Disabled apps")), TIMEOUT);
|
||||
assertThat(optionDisabledApps).isNotNull();
|
||||
optionDisabledApps.click();
|
||||
mDevice.waitForIdle(TIMEOUT);
|
||||
|
||||
try {
|
||||
mDevice.setOrientationLeft();
|
||||
mDevice.waitForIdle(TIMEOUT);
|
||||
} catch (RemoteException e) {
|
||||
throw new RuntimeException("Failed to freeze device orientation", e);
|
||||
}
|
||||
|
||||
try {
|
||||
mDevice.unfreezeRotation();
|
||||
mDevice.waitForIdle(TIMEOUT);
|
||||
} catch (RemoteException e) {
|
||||
throw new RuntimeException("Failed to un-freeze device orientation", e);
|
||||
}
|
||||
|
||||
UiObject2 spinnerDisabledApps = mDevice.wait(
|
||||
Until.findObject(By.text("Disabled apps")), TIMEOUT);
|
||||
assertThat(spinnerDisabledApps).isNotNull();
|
||||
}
|
||||
|
||||
private void launchAppsSettings() throws Exception {
|
||||
Intent appsSettingsIntent = new
|
||||
Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
|
||||
mActivityHelper.launchIntent(appsSettingsIntent);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user