summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java2
-rw-r--r--apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java40
-rw-r--r--core/java/android/app/ActivityManagerInternal.java10
-rw-r--r--core/java/android/app/admin/DevicePolicyManager.java5
-rw-r--r--packages/SystemUI/accessibility/accessibilitymenu/res/values/strings.xml6
-rw-r--r--packages/SystemUI/accessibility/accessibilitymenu/res/xml/accessibilitymenu_preferences.xml2
-rw-r--r--packages/SystemUI/accessibility/accessibilitymenu/src/com/android/systemui/accessibility/accessibilitymenu/activity/A11yMenuSettingsActivity.java2
-rw-r--r--packages/SystemUI/res/values/config.xml1
-rw-r--r--packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt51
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt11
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/accessibility/fontscaling/FontScalingDialogTest.kt39
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/tiles/FontScalingTileTest.kt1
-rw-r--r--services/core/java/android/app/usage/UsageStatsManagerInternal.java10
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java2
-rw-r--r--services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java38
-rw-r--r--services/usage/java/com/android/server/usage/UsageStatsService.java5
16 files changed, 207 insertions, 18 deletions
diff --git a/apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java b/apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java
index 9b64edf53d8c..f50a90248030 100644
--- a/apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java
+++ b/apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java
@@ -225,6 +225,8 @@ public interface AppStandbyInternal {
void setActiveAdminApps(Set<String> adminPkgs, int userId);
+ void setAdminProtectedPackages(Set<String> packageNames, int userId);
+
/**
* @return {@code true} if the given package is an active device admin app.
*/
diff --git a/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java b/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java
index c3118ff96413..ab0a8adb5daf 100644
--- a/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java
+++ b/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java
@@ -268,6 +268,10 @@ public class AppStandbyController
@GuardedBy("mActiveAdminApps")
private final SparseArray<Set<String>> mActiveAdminApps = new SparseArray<>();
+ /** List of admin protected packages. Can contain {@link android.os.UserHandle#USER_ALL}. */
+ @GuardedBy("mAdminProtectedPackages")
+ private final SparseArray<Set<String>> mAdminProtectedPackages = new SparseArray<>();
+
/**
* Set of system apps that are headless (don't have any "front door" activities, enabled or
* disabled). Presence in this map indicates that the app is a headless system app.
@@ -1380,6 +1384,9 @@ public class AppStandbyController
synchronized (mActiveAdminApps) {
mActiveAdminApps.remove(userId);
}
+ synchronized (mAdminProtectedPackages) {
+ mAdminProtectedPackages.remove(userId);
+ }
}
}
@@ -1469,6 +1476,10 @@ public class AppStandbyController
return STANDBY_BUCKET_EXEMPTED;
}
+ if (isAdminProtectedPackages(packageName, userId)) {
+ return STANDBY_BUCKET_EXEMPTED;
+ }
+
if (isActiveNetworkScorer(packageName)) {
return STANDBY_BUCKET_EXEMPTED;
}
@@ -1948,6 +1959,17 @@ public class AppStandbyController
}
}
+ private boolean isAdminProtectedPackages(String packageName, int userId) {
+ synchronized (mAdminProtectedPackages) {
+ if (mAdminProtectedPackages.contains(UserHandle.USER_ALL)
+ && mAdminProtectedPackages.get(UserHandle.USER_ALL).contains(packageName)) {
+ return true;
+ }
+ return mAdminProtectedPackages.contains(userId)
+ && mAdminProtectedPackages.get(userId).contains(packageName);
+ }
+ }
+
@Override
public void addActiveDeviceAdmin(String adminPkg, int userId) {
synchronized (mActiveAdminApps) {
@@ -1972,6 +1994,17 @@ public class AppStandbyController
}
@Override
+ public void setAdminProtectedPackages(Set<String> packageNames, int userId) {
+ synchronized (mAdminProtectedPackages) {
+ if (packageNames == null || packageNames.isEmpty()) {
+ mAdminProtectedPackages.remove(userId);
+ } else {
+ mAdminProtectedPackages.put(userId, packageNames);
+ }
+ }
+ }
+
+ @Override
public void onAdminDataAvailable() {
mAdminDataAvailableLatch.countDown();
}
@@ -1993,6 +2026,13 @@ public class AppStandbyController
}
}
+ @VisibleForTesting
+ Set<String> getAdminProtectedPackagesForTest(int userId) {
+ synchronized (mAdminProtectedPackages) {
+ return mAdminProtectedPackages.get(userId);
+ }
+ }
+
/**
* Returns {@code true} if the supplied package is the device provisioning app. Otherwise,
* returns {@code false}.
diff --git a/core/java/android/app/ActivityManagerInternal.java b/core/java/android/app/ActivityManagerInternal.java
index 90427cb51c26..b96f8c94aaa3 100644
--- a/core/java/android/app/ActivityManagerInternal.java
+++ b/core/java/android/app/ActivityManagerInternal.java
@@ -994,6 +994,16 @@ public abstract class ActivityManagerInternal {
*/
public abstract void logFgsApiEnd(int apiType, int uid, int pid);
+ /**
+ * Temporarily allow foreground service started by an uid to have while-in-use permission
+ * for durationMs.
+ *
+ * @param uid The UID of the app that starts the foreground service.
+ * @param durationMs elapsedRealTime duration in milliseconds.
+ * @hide
+ */
+ public abstract void tempAllowWhileInUsePermissionInFgs(int uid, long durationMs);
+
/**
* The list of the events about the {@link android.media.projection.IMediaProjection} itself.
*
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 6bbbfe1ef4b0..5be43fc8e8f7 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -15840,9 +15840,8 @@ public class DevicePolicyManager {
* Called by a device owner or a profile owner or holder of the permission
* {@link android.Manifest.permission#MANAGE_DEVICE_POLICY_APPS_CONTROL} to disable user
* control over apps. User will not be able to clear app data or force-stop packages. When
- * called by a device owner, applies to all users on the device. Starting from Android 13,
- * packages with user control disabled are exempted from being put in the "restricted" App
- * Standby Bucket.
+ * called by a device owner, applies to all users on the device. Packages with user control
+ * disabled are exempted from App Standby Buckets.
*
* @param admin Which {@link DeviceAdminReceiver} this request is associated with. Null if the
* caller is not a device admin.
diff --git a/packages/SystemUI/accessibility/accessibilitymenu/res/values/strings.xml b/packages/SystemUI/accessibility/accessibilitymenu/res/values/strings.xml
index 0747ef089a8d..81fa8e6bba21 100644
--- a/packages/SystemUI/accessibility/accessibilitymenu/res/values/strings.xml
+++ b/packages/SystemUI/accessibility/accessibilitymenu/res/values/strings.xml
@@ -49,7 +49,6 @@
<!-- Short summary of app that appears as subtext on the service preference in Settings -->
<string name="accessibility_menu_summary">Control device via large menu</string>
- <!-- TODO(b/113371047): string need to be reviewed -->
<!-- String defining the settings name -->
<string name="accessibility_menu_settings_name">Accessibility Menu Settings</string>
@@ -57,8 +56,6 @@
<string name="accessibility_menu_large_buttons_title">Large buttons</string>
<!-- String defining the summary of Large button setting -->
<string name="accessibility_menu_large_buttons_summary">Increase size of Accessibility Menu Buttons</string>
- <!-- String defining the title of the preference to show help and feedback menu [CHAR LIMIT=40] -->
- <string name="pref_help_and_feedback_title">Help &#38; feedback</string>
<!-- String defining the title of the preference to show help menu [CHAR LIMIT=40] -->
<string name="pref_help_title">Help</string>
@@ -67,7 +64,4 @@
<!-- The percentage of the music volume, and double "%" is required to represent the symbol "%" -->
<string name="music_volume_percentage_label">Music volume <xliff:g id="percentage">%1$s</xliff:g> %%</string>
- <!-- The label of a settings item that displays legal information about the licenses used in this app. [CHAR LIMIT=NONE] -->
- <string name="pref_item_licenses">Open Source Licenses</string>
-
</resources>
diff --git a/packages/SystemUI/accessibility/accessibilitymenu/res/xml/accessibilitymenu_preferences.xml b/packages/SystemUI/accessibility/accessibilitymenu/res/xml/accessibilitymenu_preferences.xml
index 3b79287ad202..e42c3cd5a368 100644
--- a/packages/SystemUI/accessibility/accessibilitymenu/res/xml/accessibilitymenu_preferences.xml
+++ b/packages/SystemUI/accessibility/accessibilitymenu/res/xml/accessibilitymenu_preferences.xml
@@ -28,6 +28,6 @@
<Preference
android:key="@string/pref_help"
- android:title="@string/pref_help_and_feedback_title"/>
+ android:title="@string/pref_help_title"/>
</androidx.preference.PreferenceScreen> \ No newline at end of file
diff --git a/packages/SystemUI/accessibility/accessibilitymenu/src/com/android/systemui/accessibility/accessibilitymenu/activity/A11yMenuSettingsActivity.java b/packages/SystemUI/accessibility/accessibilitymenu/src/com/android/systemui/accessibility/accessibilitymenu/activity/A11yMenuSettingsActivity.java
index 8f2934882ede..4b6f9a430390 100644
--- a/packages/SystemUI/accessibility/accessibilitymenu/src/com/android/systemui/accessibility/accessibilitymenu/activity/A11yMenuSettingsActivity.java
+++ b/packages/SystemUI/accessibility/accessibilitymenu/src/com/android/systemui/accessibility/accessibilitymenu/activity/A11yMenuSettingsActivity.java
@@ -71,8 +71,6 @@ public class A11yMenuSettingsActivity extends FragmentActivity {
private void initializeHelpAndFeedbackPreference() {
final Preference prefHelp = findPreference(getString(R.string.pref_help));
if (prefHelp != null) {
- prefHelp.setTitle(R.string.pref_help_title);
-
// Do not allow access to web during setup.
if (Settings.Secure.getInt(
getContext().getContentResolver(),
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
index e5cd0c55027b..082f3855affc 100644
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -99,6 +99,7 @@
<item>accessibility_display_daltonizer_enabled:color_correction</item>
<item>accessibility_display_inversion_enabled:inversion</item>
<item>one_handed_mode_enabled:onehanded</item>
+ <item>accessibility_font_scaling_has_been_changed:font_scaling</item>
</string-array>
<!-- Use collapsed layout for media player in landscape QQS -->
diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt b/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt
index 53a421d9eccc..1836ce857783 100644
--- a/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt
+++ b/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt
@@ -15,6 +15,7 @@
*/
package com.android.systemui.accessibility.fontscaling
+import android.annotation.WorkerThread
import android.content.Context
import android.content.pm.ActivityInfo
import android.content.res.Configuration
@@ -27,18 +28,26 @@ import android.widget.SeekBar.OnSeekBarChangeListener
import android.widget.TextView
import com.android.systemui.R
import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView
+import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.statusbar.phone.SystemUIDialog
+import com.android.systemui.util.settings.SecureSettings
import com.android.systemui.util.settings.SystemSettings
+import java.util.concurrent.Executor
import kotlin.math.roundToInt
/** The Dialog that contains a seekbar for changing the font size. */
-class FontScalingDialog(context: Context, private val systemSettings: SystemSettings) :
- SystemUIDialog(context) {
+class FontScalingDialog(
+ context: Context,
+ private val systemSettings: SystemSettings,
+ private val secureSettings: SecureSettings,
+ @Background private val backgroundExecutor: Executor
+) : SystemUIDialog(context) {
private val strEntryValues: Array<String> =
context.resources.getStringArray(com.android.settingslib.R.array.entryvalues_font_size)
private lateinit var title: TextView
private lateinit var doneButton: Button
private lateinit var seekBarWithIconButtonsView: SeekBarWithIconButtonsView
+ private var lastProgress: Int = -1
private val configuration: Configuration =
Configuration(context.getResources().getConfiguration())
@@ -70,12 +79,22 @@ class FontScalingDialog(context: Context, private val systemSettings: SystemSett
seekBarWithIconButtonsView.setMax((strEntryValues).size - 1)
val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, 1.0f)
- seekBarWithIconButtonsView.setProgress(fontSizeValueToIndex(currentScale))
+ lastProgress = fontSizeValueToIndex(currentScale)
+ seekBarWithIconButtonsView.setProgress(lastProgress)
seekBarWithIconButtonsView.setOnSeekBarChangeListener(
object : OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
- systemSettings.putString(Settings.System.FONT_SCALE, strEntryValues[progress])
+ if (progress != lastProgress) {
+ if (!fontSizeHasBeenChangedFromTile) {
+ backgroundExecutor.execute { updateSecureSettingsIfNeeded() }
+ fontSizeHasBeenChangedFromTile = true
+ }
+
+ backgroundExecutor.execute { updateFontScale(strEntryValues[progress]) }
+
+ lastProgress = progress
+ }
}
override fun onStartTrackingTouch(seekBar: SeekBar) {
@@ -115,4 +134,28 @@ class FontScalingDialog(context: Context, private val systemSettings: SystemSett
}
}
}
+
+ @WorkerThread
+ fun updateFontScale(newScale: String) {
+ systemSettings.putString(Settings.System.FONT_SCALE, newScale)
+ }
+
+ @WorkerThread
+ fun updateSecureSettingsIfNeeded() {
+ if (
+ secureSettings.getString(Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED) !=
+ ON
+ ) {
+ secureSettings.putString(
+ Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED,
+ ON
+ )
+ }
+ }
+
+ companion object {
+ private const val ON = "1"
+ private const val OFF = "0"
+ private var fontSizeHasBeenChangedFromTile = false
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt
index a915ddba4f1c..3f514344cee1 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt
@@ -17,6 +17,7 @@ package com.android.systemui.qs.tiles
import android.content.Intent
import android.os.Handler
+import android.os.HandlerExecutor
import android.os.Looper
import android.provider.Settings
import android.view.View
@@ -38,6 +39,7 @@ import com.android.systemui.qs.QSHost
import com.android.systemui.qs.logging.QSLogger
import com.android.systemui.qs.tileimpl.QSTileImpl
import com.android.systemui.statusbar.phone.SystemUIDialog
+import com.android.systemui.util.settings.SecureSettings
import com.android.systemui.util.settings.SystemSettings
import javax.inject.Inject
@@ -54,6 +56,7 @@ constructor(
qsLogger: QSLogger,
private val dialogLaunchAnimator: DialogLaunchAnimator,
private val systemSettings: SystemSettings,
+ private val secureSettings: SecureSettings,
private val featureFlags: FeatureFlags
) :
QSTileImpl<QSTile.State?>(
@@ -78,7 +81,13 @@ constructor(
override fun handleClick(view: View?) {
mUiHandler.post {
- val dialog: SystemUIDialog = FontScalingDialog(mContext, systemSettings)
+ val dialog: SystemUIDialog =
+ FontScalingDialog(
+ mContext,
+ systemSettings,
+ secureSettings,
+ HandlerExecutor(mHandler)
+ )
if (view != null) {
dialogLaunchAnimator.showFromView(
dialog,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/accessibility/fontscaling/FontScalingDialogTest.kt b/packages/SystemUI/tests/src/com/android/systemui/accessibility/fontscaling/FontScalingDialogTest.kt
index ca6f42618e2a..eb8295653199 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/fontscaling/FontScalingDialogTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/fontscaling/FontScalingDialogTest.kt
@@ -25,12 +25,19 @@ import androidx.test.filters.SmallTest
import com.android.systemui.R
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView
+import com.android.systemui.util.concurrency.FakeExecutor
import com.android.systemui.util.settings.FakeSettings
+import com.android.systemui.util.settings.SecureSettings
import com.android.systemui.util.settings.SystemSettings
+import com.android.systemui.util.time.FakeSystemClock
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
+import org.mockito.MockitoAnnotations
+
+private const val ON: Int = 1
+private const val OFF: Int = 0
/** Tests for [FontScalingDialog]. */
@SmallTest
@@ -39,6 +46,8 @@ import org.junit.runner.RunWith
class FontScalingDialogTest : SysuiTestCase() {
private lateinit var fontScalingDialog: FontScalingDialog
private lateinit var systemSettings: SystemSettings
+ private lateinit var secureSettings: SecureSettings
+ private lateinit var backgroundExecutor: FakeExecutor
private val fontSizeValueArray: Array<String> =
mContext
.getResources()
@@ -46,9 +55,13 @@ class FontScalingDialogTest : SysuiTestCase() {
@Before
fun setUp() {
+ MockitoAnnotations.initMocks(this)
val mainHandler = Handler(TestableLooper.get(this).getLooper())
systemSettings = FakeSettings()
- fontScalingDialog = FontScalingDialog(mContext, systemSettings as FakeSettings)
+ secureSettings = FakeSettings()
+ backgroundExecutor = FakeExecutor(FakeSystemClock())
+ fontScalingDialog =
+ FontScalingDialog(mContext, systemSettings, secureSettings, backgroundExecutor)
}
@Test
@@ -76,6 +89,7 @@ class FontScalingDialogTest : SysuiTestCase() {
seekBarWithIconButtonsView.setProgress(0)
iconEndFrame.performClick()
+ backgroundExecutor.runAllReady()
val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def = */ 1.0f)
assertThat(seekBar.getProgress()).isEqualTo(1)
@@ -96,6 +110,7 @@ class FontScalingDialogTest : SysuiTestCase() {
seekBarWithIconButtonsView.setProgress(fontSizeValueArray.size - 1)
iconStartFrame.performClick()
+ backgroundExecutor.runAllReady()
val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def = */ 1.0f)
assertThat(seekBar.getProgress()).isEqualTo(fontSizeValueArray.size - 2)
@@ -104,4 +119,26 @@ class FontScalingDialogTest : SysuiTestCase() {
fontScalingDialog.dismiss()
}
+
+ @Test
+ fun progressChanged_keyWasNotSetBefore_fontScalingHasBeenChangedIsOn() {
+ fontScalingDialog.show()
+
+ val seekBarWithIconButtonsView: SeekBarWithIconButtonsView =
+ fontScalingDialog.findViewById(R.id.font_scaling_slider)!!
+ secureSettings.putInt(Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED, OFF)
+
+ // Default seekbar progress for font size is 1, set it to another progress 0
+ seekBarWithIconButtonsView.setProgress(0)
+ backgroundExecutor.runAllReady()
+
+ val currentSettings =
+ secureSettings.getInt(
+ Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED,
+ /* def = */ OFF
+ )
+ assertThat(currentSettings).isEqualTo(ON)
+
+ fontScalingDialog.dismiss()
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/FontScalingTileTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/FontScalingTileTest.kt
index bd99cd482859..eeebd4fb7792 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/FontScalingTileTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/FontScalingTileTest.kt
@@ -84,6 +84,7 @@ class FontScalingTileTest : SysuiTestCase() {
qsLogger,
dialogLaunchAnimator,
FakeSettings(),
+ FakeSettings(),
featureFlags
)
fontScalingTile.initialize()
diff --git a/services/core/java/android/app/usage/UsageStatsManagerInternal.java b/services/core/java/android/app/usage/UsageStatsManagerInternal.java
index 70eeb7fecc8f..fc565111dbe8 100644
--- a/services/core/java/android/app/usage/UsageStatsManagerInternal.java
+++ b/services/core/java/android/app/usage/UsageStatsManagerInternal.java
@@ -203,6 +203,16 @@ public abstract class UsageStatsManagerInternal {
public abstract void setActiveAdminApps(Set<String> adminApps, int userId);
/**
+ * Called by DevicePolicyManagerService to inform about the protected packages for a user.
+ * User control will be disabled for protected packages.
+ *
+ * @param packageNames the set of protected packages for {@code userId}.
+ * @param userId the userId to which the protected packages belong.
+ */
+ public abstract void setAdminProtectedPackages(@Nullable Set<String> packageNames,
+ @UserIdInt int userId);
+
+ /**
* Called by DevicePolicyManagerService during boot to inform that admin data is loaded and
* pushed to UsageStatsService.
*/
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 321924c79c58..835c92348abc 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -3579,6 +3579,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
mInjector.binderWithCleanCallingIdentity(() ->
mInjector.getPackageManagerInternal().setOwnerProtectedPackages(
targetUserId, protectedPackages));
+ mUsageStatsManagerInternal.setAdminProtectedPackages(new ArraySet(protectedPackages),
+ targetUserId);
}
void handleUnlockUser(int userId) {
diff --git a/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java b/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
index 9570ff6323d2..86878c5384fd 100644
--- a/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
+++ b/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
@@ -160,6 +160,9 @@ public class AppStandbyControllerTests {
private static final String ADMIN_PKG2 = "com.android.admin2";
private static final String ADMIN_PKG3 = "com.android.admin3";
+ private static final String ADMIN_PROTECTED_PKG = "com.android.admin.protected";
+ private static final String ADMIN_PROTECTED_PKG2 = "com.android.admin.protected2";
+
private static final long MINUTE_MS = 60 * 1000;
private static final long HOUR_MS = 60 * MINUTE_MS;
private static final long DAY_MS = 24 * HOUR_MS;
@@ -1758,6 +1761,19 @@ public class AppStandbyControllerTests {
}
@Test
+ public void testSetAdminProtectedPackages() {
+ assertAdminProtectedPackagesForTest(USER_ID, (String[]) null);
+ assertAdminProtectedPackagesForTest(USER_ID2, (String[]) null);
+
+ setAdminProtectedPackages(USER_ID, ADMIN_PROTECTED_PKG, ADMIN_PROTECTED_PKG2);
+ assertAdminProtectedPackagesForTest(USER_ID, ADMIN_PROTECTED_PKG, ADMIN_PROTECTED_PKG2);
+ assertAdminProtectedPackagesForTest(USER_ID2, (String[]) null);
+
+ setAdminProtectedPackages(USER_ID, (String[]) null);
+ assertAdminProtectedPackagesForTest(USER_ID, (String[]) null);
+ }
+
+ @Test
@FlakyTest(bugId = 185169504)
public void testUserInteraction_CrossProfile() throws Exception {
mInjector.mRunningUsers = new int[] {USER_ID, USER_ID2, USER_ID3};
@@ -2195,6 +2211,28 @@ public class AppStandbyControllerTests {
mController.setActiveAdminApps(new ArraySet<>(Arrays.asList(admins)), userId);
}
+ private void setAdminProtectedPackages(int userId, String... packageNames) {
+ Set<String> adminProtectedPackages = packageNames != null ? new ArraySet<>(
+ Arrays.asList(packageNames)) : null;
+ mController.setAdminProtectedPackages(adminProtectedPackages, userId);
+ }
+
+ private void assertAdminProtectedPackagesForTest(int userId, String... packageNames) {
+ final Set<String> actualAdminProtectedPackages =
+ mController.getAdminProtectedPackagesForTest(userId);
+ if (packageNames == null) {
+ if (actualAdminProtectedPackages != null && !actualAdminProtectedPackages.isEmpty()) {
+ fail("Admin protected packages should be null; " + getAdminAppsStr(userId,
+ actualAdminProtectedPackages));
+ }
+ return;
+ }
+ assertEquals(packageNames.length, actualAdminProtectedPackages.size());
+ for (String adminProtectedPackage : packageNames) {
+ assertTrue(actualAdminProtectedPackages.contains(adminProtectedPackage));
+ }
+ }
+
private void setAndAssertBucket(String pkg, int user, int bucket, int reason) throws Exception {
rearmLatch(pkg);
mController.setAppStandbyBucket(pkg, user, bucket, reason);
diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java
index 7ff5b4a28f1b..8948e494d851 100644
--- a/services/usage/java/com/android/server/usage/UsageStatsService.java
+++ b/services/usage/java/com/android/server/usage/UsageStatsService.java
@@ -3129,6 +3129,11 @@ public class UsageStatsService extends SystemService implements
}
@Override
+ public void setAdminProtectedPackages(Set<String> packageNames, int userId) {
+ mAppStandby.setAdminProtectedPackages(packageNames, userId);
+ }
+
+ @Override
public void onAdminDataAvailable() {
mAppStandby.onAdminDataAvailable();
}