Add a new special app access screen for long background tasks.
This new screen shows apps that hold the new RUN_LONG_JOBS permission. Also add a reference to this screen in an app's info page under the "Advanced" section for apps that have requested this permission. Bug: 255821578 Test: atest AppFilterRegistryTest Test: make -j RunSettingsRoboTests \ ROBOTTEST_FILTER="LongBackgroundTasksDetailsTest| LongBackgroundTasksDetailsPreferenceControllerTest" Test: visually via the Settings page Change-Id: Idc498e52d29abc6df757c35e8bc91f00de92ba4a
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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.applications.appinfo;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class LongBackgroundTasksDetailsPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private AppInfoDashboardFragment mFragment;
|
||||
@Mock
|
||||
private Preference mPreference;
|
||||
|
||||
private Context mContext;
|
||||
private LongBackgroundTasksDetailsPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mController = spy(new LongBackgroundTasksDetailsPreferenceController(mContext, "test_key"));
|
||||
mController.setPackageName("Package1");
|
||||
mController.setParentFragment(mFragment);
|
||||
final String key = mController.getPreferenceKey();
|
||||
when(mPreference.getKey()).thenReturn(key);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_notCandidate_shouldReturnUnavailable() {
|
||||
doReturn(false).when(mController).isCandidate();
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_isCandidate_shouldReturnAvailable() {
|
||||
doReturn(true).when(mController).isCandidate();
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDetailFragmentClass_shouldReturnAlarmsAndRemindersDetails() {
|
||||
assertThat(mController.getDetailFragmentClass())
|
||||
.isEqualTo(LongBackgroundTasksDetails.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_shouldSetSummary() {
|
||||
final String summary = "test summary";
|
||||
doReturn(summary).when(mController).getPreferenceSummary();
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setSummary(summary);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isCandidate_nullPackageInfo_shouldNotCrash() {
|
||||
mController.isCandidate();
|
||||
// no crash
|
||||
}
|
||||
}
|
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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.applications.appinfo;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
|
||||
import com.android.settings.applications.AppStateLongBackgroundTasksBridge;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class LongBackgroundTasksDetailsTest {
|
||||
|
||||
@Mock
|
||||
private RestrictedSwitchPreference mSwitchPref;
|
||||
@Mock
|
||||
private PackageInfo mPackageInfo;
|
||||
@Mock
|
||||
private AppStateLongBackgroundTasksBridge mAppStateBridge;
|
||||
@Mock
|
||||
private AppStateLongBackgroundTasksBridge.LongBackgroundTasksState mPermissionState;
|
||||
|
||||
private LongBackgroundTasksDetails mFragment = new LongBackgroundTasksDetails();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
ReflectionHelpers.setField(mFragment, "mSwitchPref", mSwitchPref);
|
||||
ReflectionHelpers.setField(mFragment, "mAppBridge", mAppStateBridge);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshUi_noPackageInfo_shouldReturnFalseAndNoCrash() {
|
||||
mFragment.refreshUi();
|
||||
|
||||
assertThat(mFragment.refreshUi()).isFalse();
|
||||
// should not crash
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshUi_noApplicationInfo_shouldReturnFalseAndNoCrash() {
|
||||
ReflectionHelpers.setField(mFragment, "mPackageInfo", mPackageInfo);
|
||||
|
||||
mFragment.refreshUi();
|
||||
|
||||
assertThat(mFragment.refreshUi()).isFalse();
|
||||
// should not crash
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshUi_hasApplicationInfo_shouldReturnTrue() {
|
||||
ReflectionHelpers.setField(mFragment, "mPackageInfo", mPackageInfo);
|
||||
mPackageInfo.applicationInfo = new ApplicationInfo();
|
||||
when(mAppStateBridge.createPermissionState(nullable(String.class), anyInt()))
|
||||
.thenReturn(mPermissionState);
|
||||
|
||||
mFragment.refreshUi();
|
||||
|
||||
assertThat(mFragment.refreshUi()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshUi_switchPreferenceEnabled() {
|
||||
ReflectionHelpers.setField(mFragment, "mPackageInfo", mPackageInfo);
|
||||
mPackageInfo.applicationInfo = new ApplicationInfo();
|
||||
when(mAppStateBridge.createPermissionState(nullable(String.class), anyInt()))
|
||||
.thenReturn(mPermissionState);
|
||||
when(mPermissionState.shouldBeVisible()).thenReturn(false);
|
||||
|
||||
mFragment.refreshUi();
|
||||
verify(mSwitchPref).setEnabled(false);
|
||||
|
||||
when(mPermissionState.shouldBeVisible()).thenReturn(true);
|
||||
|
||||
mFragment.refreshUi();
|
||||
verify(mSwitchPref).setEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshUi_switchPreferenceChecked() {
|
||||
ReflectionHelpers.setField(mFragment, "mPackageInfo", mPackageInfo);
|
||||
mPackageInfo.applicationInfo = new ApplicationInfo();
|
||||
when(mAppStateBridge.createPermissionState(nullable(String.class), anyInt()))
|
||||
.thenReturn(mPermissionState);
|
||||
|
||||
when(mPermissionState.isAllowed()).thenReturn(true);
|
||||
mFragment.refreshUi();
|
||||
verify(mSwitchPref).setChecked(true);
|
||||
|
||||
when(mPermissionState.isAllowed()).thenReturn(false);
|
||||
mFragment.refreshUi();
|
||||
verify(mSwitchPref).setChecked(false);
|
||||
}
|
||||
}
|
@@ -26,10 +26,12 @@ import static com.android.settings.applications.manageapplications.AppFilterRegi
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_USAGE_ACCESS;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_WITH_OVERLAY;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_WRITE_SETTINGS;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_LONG_BACKGROUND_TASKS;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_ALARMS_AND_REMINDERS;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_BATTERY_OPTIMIZATION;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_GAMES;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_HIGH_POWER;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_LONG_BACKGROUND_TASKS;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_MAIN;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_MANAGE_SOURCES;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_MEDIA_MANAGEMENT_APPS;
|
||||
@@ -77,5 +79,8 @@ public class AppFilterRegistryTest {
|
||||
assertThat(registry.getDefaultFilterType(LIST_TYPE_STORAGE)).isEqualTo(FILTER_APPS_ALL);
|
||||
|
||||
assertThat(registry.getDefaultFilterType(LIST_TYPE_GAMES)).isEqualTo(FILTER_APPS_ALL);
|
||||
|
||||
assertThat(registry.getDefaultFilterType(LIST_TYPE_LONG_BACKGROUND_TASKS))
|
||||
.isEqualTo(FILTER_LONG_BACKGROUND_TASKS);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user