Add a feature flag for the special access to the long background task
The entry should be hidden if the RUN_LONG_JOBS can't be toggled.
Bug: 255821578
Test: atest AppFilterRegistryTest
Test: make -j RunSettingsRoboTests \
ROBOTTEST_FILTER="LongBackgroundTasksDetailsTest|
LongBackgroundTasksDetailsPreferenceControllerTest"
Test: Manually check the Settings page
Change-Id: Ib1c58d93b40afefdf3ca666c661e213d01c542c6
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index a794d8e..03bcfe1 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -853,7 +853,7 @@
android:exported="true"
android:label="@string/long_background_tasks_label">
<intent-filter android:priority="1">
- <action android:name="android.settings.MANAGE_APP_LONG_JOBS" />
+ <action android:name="android.settings.MANAGE_APP_LONG_RUNNING_JOBS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
@@ -869,7 +869,7 @@
android:exported="true"
android:label="@string/long_background_tasks_label">
<intent-filter android:priority="1">
- <action android:name="android.settings.MANAGE_APP_LONG_JOBS" />
+ <action android:name="android.settings.MANAGE_APP_LONG_RUNNING_JOBS" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
diff --git a/res/xml/special_access.xml b/res/xml/special_access.xml
index 0d2ee51..1a8e431 100644
--- a/res/xml/special_access.xml
+++ b/res/xml/special_access.xml
@@ -111,7 +111,8 @@
android:key="long_background_tasks"
android:title="@string/long_background_tasks_title"
android:fragment="com.android.settings.applications.manageapplications.ManageApplications"
- settings:keywords="@string/keywords_long_background_tasks">
+ settings:keywords="@string/keywords_long_background_tasks"
+ settings:controller="com.android.settings.applications.specialaccess.applications.LongBackgroundTaskController">
<extra
android:name="classname"
android:value="com.android.settings.Settings$LongBackgroundTasksActivity" />
diff --git a/src/com/android/settings/applications/ApplicationFeatureProvider.java b/src/com/android/settings/applications/ApplicationFeatureProvider.java
index 8a9f000..9272b43 100644
--- a/src/com/android/settings/applications/ApplicationFeatureProvider.java
+++ b/src/com/android/settings/applications/ApplicationFeatureProvider.java
@@ -93,6 +93,12 @@
}
/**
+ * @return {@code true} if the device supports the toggling of the long background task
+ * permission.
+ */
+ boolean isLongBackgroundTaskPermissionToggleSupported();
+
+ /**
* Callback that receives the number of packages installed on the device.
*/
interface NumberOfAppsCallback {
diff --git a/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java b/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java
index 5b74a88..f2a3d6a 100644
--- a/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java
+++ b/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java
@@ -16,6 +16,10 @@
package com.android.settings.applications;
+import static android.Manifest.permission.RUN_LONG_JOBS;
+import static android.app.AppOpsManager.OP_RUN_LONG_JOBS;
+import static android.app.AppOpsManager.opToPermission;
+
import android.Manifest;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
@@ -338,4 +342,9 @@
}
throw new IllegalStateException("Missing ComponentInfo!");
}
+
+ @Override
+ public boolean isLongBackgroundTaskPermissionToggleSupported() {
+ return TextUtils.equals(RUN_LONG_JOBS, opToPermission(OP_RUN_LONG_JOBS));
+ }
}
diff --git a/src/com/android/settings/applications/appinfo/LongBackgroundTasksDetailsPreferenceController.java b/src/com/android/settings/applications/appinfo/LongBackgroundTasksDetailsPreferenceController.java
index a41280b..68f893c 100644
--- a/src/com/android/settings/applications/appinfo/LongBackgroundTasksDetailsPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/LongBackgroundTasksDetailsPreferenceController.java
@@ -24,6 +24,8 @@
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.applications.AppStateLongBackgroundTasksBridge;
+import com.android.settings.applications.ApplicationFeatureProvider;
+import com.android.settings.overlay.FeatureFactory;
/**
* Preference controller for
@@ -32,14 +34,28 @@
public class LongBackgroundTasksDetailsPreferenceController extends
AppInfoPreferenceControllerBase {
+ private final ApplicationFeatureProvider mAppFeatureProvider;
+
private String mPackageName;
public LongBackgroundTasksDetailsPreferenceController(Context context, String key) {
super(context, key);
+ mAppFeatureProvider = FeatureFactory.getFactory(context)
+ .getApplicationFeatureProvider(context);
+ }
+
+ @VisibleForTesting
+ LongBackgroundTasksDetailsPreferenceController(Context context, String key,
+ ApplicationFeatureProvider appFeatureProvider) {
+ super(context, key);
+ mAppFeatureProvider = appFeatureProvider;
}
@Override
public int getAvailabilityStatus() {
+ if (!mAppFeatureProvider.isLongBackgroundTaskPermissionToggleSupported()) {
+ return UNSUPPORTED_ON_DEVICE;
+ }
return isCandidate() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
diff --git a/src/com/android/settings/applications/specialaccess/applications/LongBackgroundTaskController.java b/src/com/android/settings/applications/specialaccess/applications/LongBackgroundTaskController.java
new file mode 100644
index 0000000..586980c
--- /dev/null
+++ b/src/com/android/settings/applications/specialaccess/applications/LongBackgroundTaskController.java
@@ -0,0 +1,42 @@
+/*
+ * 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.specialaccess.applications;
+
+import android.content.Context;
+
+import com.android.settings.applications.ApplicationFeatureProvider;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.overlay.FeatureFactory;
+
+/**
+ * The controller for the special access to the long background task.
+ */
+public class LongBackgroundTaskController extends BasePreferenceController {
+ private final ApplicationFeatureProvider mAppFeatureProvider;
+
+ public LongBackgroundTaskController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ mAppFeatureProvider = FeatureFactory.getFactory(context)
+ .getApplicationFeatureProvider(context);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mAppFeatureProvider.isLongBackgroundTaskPermissionToggleSupported()
+ ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/LongBackgroundTasksDetailsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/LongBackgroundTasksDetailsPreferenceControllerTest.java
index 1b361d2..cc42c84 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/LongBackgroundTasksDetailsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/LongBackgroundTasksDetailsPreferenceControllerTest.java
@@ -27,6 +27,7 @@
import androidx.preference.Preference;
+import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
@@ -44,6 +45,8 @@
private AppInfoDashboardFragment mFragment;
@Mock
private Preference mPreference;
+ @Mock
+ private ApplicationFeatureProvider mAppFeatureProvider;
private Context mContext;
private LongBackgroundTasksDetailsPreferenceController mController;
@@ -52,11 +55,13 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
- mController = spy(new LongBackgroundTasksDetailsPreferenceController(mContext, "test_key"));
+ mController = spy(new LongBackgroundTasksDetailsPreferenceController(mContext, "test_key",
+ mAppFeatureProvider));
mController.setPackageName("Package1");
mController.setParentFragment(mFragment);
final String key = mController.getPreferenceKey();
when(mPreference.getKey()).thenReturn(key);
+ when(mAppFeatureProvider.isLongBackgroundTaskPermissionToggleSupported()).thenReturn(true);
}
@Test