Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50490a35 authored by Jing Ji's avatar Jing Ji
Browse files

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
parent d54c9cab
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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>
+2 −1
Original line number Diff line number Diff line
@@ -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" />
+6 −0
Original line number Diff line number Diff line
@@ -92,6 +92,12 @@ public interface ApplicationFeatureProvider {
        return "";
    }

    /**
     * @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.
     */
+9 −0
Original line number Diff line number Diff line
@@ -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 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
        }
        throw new IllegalStateException("Missing ComponentInfo!");
    }

    @Override
    public boolean isLongBackgroundTaskPermissionToggleSupported() {
        return TextUtils.equals(RUN_LONG_JOBS, opToPermission(OP_RUN_LONG_JOBS));
    }
}
+16 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import androidx.preference.Preference;

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 @@ import com.android.settings.applications.AppStateLongBackgroundTasksBridge;
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;
    }

Loading