Merge "Add a feature flag for the special access to the long background task"

This commit is contained in:
Jing Ji
2023-01-13 01:10:15 +00:00
committed by Android (Google) Code Review
7 changed files with 83 additions and 4 deletions

View File

@@ -858,7 +858,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"
@@ -874,7 +874,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>

View File

@@ -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" />

View File

@@ -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.
*/

View File

@@ -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));
}
}

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -27,6 +27,7 @@ import android.content.Context;
import androidx.preference.Preference;
import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
@@ -44,6 +45,8 @@ public class LongBackgroundTasksDetailsPreferenceControllerTest {
private AppInfoDashboardFragment mFragment;
@Mock
private Preference mPreference;
@Mock
private ApplicationFeatureProvider mAppFeatureProvider;
private Context mContext;
private LongBackgroundTasksDetailsPreferenceController mController;
@@ -52,11 +55,13 @@ public class LongBackgroundTasksDetailsPreferenceControllerTest {
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