Merge "Add a feature flag for the special access to the long background task"
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
@@ -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));
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user