Move SystemConfig to services.jar

Migrates getDefaultVrComponents used by SettingsProvider and
adds a flag for hidden API enforcement to ApplicationInfo.

This removes any dependency on SystemConfig from core/ and
so it can be moved into services/core and exposed as a
mainline API.

This was done instead of exposing all of the methods through
SystemConfigManager, as that is designed for use across
processes, and it's more efficient to expose SystemConfig
directly for modules running in the server process.

Although VrManager is a nullable service, so getDefaultVrComponents
had to live there to simplify the logic and maintain the existing
behavior.

Bug: 236389629

Change-Id: I4c2b14e1d34aaf439ceb1a3f9c8207e5d39fa6c2
This commit is contained in:
Winson Chiu
2022-09-30 17:51:20 +00:00
parent 2ae0de31d3
commit 9efbc1352b
10 changed files with 59 additions and 13 deletions

View File

@@ -31,8 +31,6 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import com.android.server.SystemConfig;
import java.util.List;
/**
@@ -50,7 +48,7 @@ import java.util.List;
* <overlayable name="OverlayableResourcesName" actor="overlay://namespace/actorName">
* }</pre></p>
*
* <p>Actors are defined through {@link SystemConfig}. Only system packages can be used.
* <p>Actors are defined through SystemConfig. Only system packages can be used.
* The namespace "android" is reserved for use by AOSP and any "android" definitions must
* have an implementation on device that fulfill their intended functionality.</p>
*

View File

@@ -45,7 +45,6 @@ import android.window.OnBackInvokedCallback;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.Parcelling;
import com.android.internal.util.Parcelling.BuiltIn.ForBoolean;
import com.android.server.SystemConfig;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -803,7 +802,6 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
*/
public static final int PRIVATE_FLAG_EXT_ATTRIBUTIONS_ARE_USER_VISIBLE = 1 << 2;
/**
* If false, {@link android.view.KeyEvent#KEYCODE_BACK} related events will be forwarded to
* the Activities, Dialogs and Views and {@link android.app.Activity#onBackPressed()},
@@ -815,12 +813,24 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
*/
public static final int PRIVATE_FLAG_EXT_ENABLE_ON_BACK_INVOKED_CALLBACK = 1 << 3;
/**
* Whether or not this package is allowed to access hidden APIs. Replacement for legacy
* implementation of {@link #isPackageWhitelistedForHiddenApis()}.
*
* This is an internal flag and should never be used outside of this class. The real API for
* the hidden API enforcement policy is {@link #getHiddenApiEnforcementPolicy()}.
*
* @hide
*/
public static final int PRIVATE_FLAG_EXT_ALLOWLISTED_FOR_HIDDEN_APIS = 1 << 4;
/** @hide */
@IntDef(flag = true, prefix = { "PRIVATE_FLAG_EXT_" }, value = {
PRIVATE_FLAG_EXT_PROFILEABLE,
PRIVATE_FLAG_EXT_REQUEST_FOREGROUND_SERVICE_EXEMPTION,
PRIVATE_FLAG_EXT_ATTRIBUTIONS_ARE_USER_VISIBLE,
PRIVATE_FLAG_EXT_ENABLE_ON_BACK_INVOKED_CALLBACK,
PRIVATE_FLAG_EXT_ALLOWLISTED_FOR_HIDDEN_APIS,
})
@Retention(RetentionPolicy.SOURCE)
public @interface ApplicationInfoPrivateFlagsExt {}
@@ -2222,7 +2232,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
}
private boolean isPackageWhitelistedForHiddenApis() {
return SystemConfig.getInstance().getHiddenApiWhitelistedApps().contains(packageName);
return (privateFlagsExt & PRIVATE_FLAG_EXT_ALLOWLISTED_FOR_HIDDEN_APIS) != 0;
}
/**

View File

@@ -47,4 +47,9 @@ interface ISystemConfig {
* @see SystemConfigManager#getEnabledComponentOverrides
*/
List<ComponentName> getEnabledComponentOverrides(String packageName);
/**
* @see SystemConfigManager#getDefaultVrComponents
*/
List<ComponentName> getDefaultVrComponents();
}

View File

@@ -147,4 +147,18 @@ public class SystemConfigManager {
throw e.rethrowFromSystemServer();
}
}
/**
* Return the components that are enabled by default as VR mode listener services.
* @hide
*/
@RequiresPermission(android.Manifest.permission.QUERY_ALL_PACKAGES)
public List<ComponentName> getDefaultVrComponents() {
try {
return mInterface.getDefaultVrComponents();
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
return Collections.emptyList();
}
}

View File

@@ -4,6 +4,7 @@
android:sharedUserId="android.uid.system">
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
<application android:allowClearUserData="false"
android:label="@string/app_label"

View File

@@ -86,6 +86,7 @@ import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.SELinux;
import android.os.ServiceManager;
import android.os.SystemConfigManager;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
@@ -110,12 +111,11 @@ import com.android.internal.content.PackageMonitor;
import com.android.internal.os.BackgroundThread;
import com.android.internal.util.FrameworkStatsLog;
import com.android.providers.settings.SettingsState.Setting;
import com.android.server.SystemConfig;
import com.google.android.collect.Sets;
import libcore.util.HexEncoding;
import com.google.android.collect.Sets;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
@@ -368,6 +368,8 @@ public class SettingsProvider extends ContentProvider {
// We have to call in the package manager with no lock held,
private volatile IPackageManager mPackageManager;
private volatile SystemConfigManager mSysConfigManager;
@GuardedBy("mLock")
private boolean mSyncConfigDisabledUntilReboot;
@@ -397,6 +399,7 @@ public class SettingsProvider extends ContentProvider {
synchronized (mLock) {
mUserManager = UserManager.get(getContext());
mPackageManager = AppGlobals.getPackageManager();
mSysConfigManager = getContext().getSystemService(SystemConfigManager.class);
mHandlerThread = new HandlerThread(LOG_TAG,
Process.THREAD_PRIORITY_BACKGROUND);
mHandlerThread.start();
@@ -3875,8 +3878,7 @@ public class SettingsProvider extends ContentProvider {
Setting currentSetting = secureSettings.getSettingLocked(
Settings.Secure.ENABLED_VR_LISTENERS);
if (currentSetting.isNull()) {
ArraySet<ComponentName> l =
SystemConfig.getInstance().getDefaultVrComponents();
List<ComponentName> l = mSysConfigManager.getDefaultVrComponents();
if (l != null && !l.isEmpty()) {
StringBuilder b = new StringBuilder();

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 The Android Open Source Project
* 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.
@@ -72,6 +72,8 @@ import java.util.Set;
* Loads global system configuration info.
* Note: Initializing this class hits the disk and is slow. This class should generally only be
* accessed by the system_server process.
*
* @hide
*/
public class SystemConfig {
static final String TAG = "SystemConfig";

View File

@@ -54,6 +54,7 @@ import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
import com.android.server.SystemConfig;
import com.android.server.pm.parsing.pkg.AndroidPackageUtils;
import com.android.server.pm.parsing.pkg.PackageImpl;
import com.android.server.pm.pkg.AndroidPackage;
@@ -1005,11 +1006,14 @@ public class PackageInfoUtils {
/** @see ApplicationInfo#privateFlagsExt */
public static int appInfoPrivateFlagsExt(AndroidPackage pkg,
@Nullable PackageStateInternal pkgSetting) {
var isAllowlistedForHiddenApis = SystemConfig.getInstance().getHiddenApiWhitelistedApps()
.contains(pkg.getPackageName());
// @formatter:off
int pkgWithoutStateFlags = flag(pkg.isProfileable(), ApplicationInfo.PRIVATE_FLAG_EXT_PROFILEABLE)
| flag(pkg.hasRequestForegroundServiceExemption(), ApplicationInfo.PRIVATE_FLAG_EXT_REQUEST_FOREGROUND_SERVICE_EXEMPTION)
| flag(pkg.areAttributionsUserVisible(), ApplicationInfo.PRIVATE_FLAG_EXT_ATTRIBUTIONS_ARE_USER_VISIBLE)
| flag(pkg.isOnBackInvokedCallbackEnabled(), ApplicationInfo.PRIVATE_FLAG_EXT_ENABLE_ON_BACK_INVOKED_CALLBACK);
| flag(pkg.isOnBackInvokedCallbackEnabled(), ApplicationInfo.PRIVATE_FLAG_EXT_ENABLE_ON_BACK_INVOKED_CALLBACK)
| flag(isAllowlistedForHiddenApis, ApplicationInfo.PRIVATE_FLAG_EXT_ALLOWLISTED_FOR_HIDDEN_APIS);
return appInfoPrivateFlagsExt(pkgWithoutStateFlags, pkgSetting);
// @formatter:on
}

View File

@@ -101,6 +101,13 @@ public class SystemConfigService extends SystemService {
}
return enabledComponent;
}
@Override
public List<ComponentName> getDefaultVrComponents() {
getContext().enforceCallingOrSelfPermission(Manifest.permission.QUERY_ALL_PACKAGES,
"Caller must hold " + Manifest.permission.QUERY_ALL_PACKAGES);
return new ArrayList<>(SystemConfig.getInstance().getDefaultVrComponents());
}
};
public SystemConfigService(Context context) {

View File

@@ -38,6 +38,7 @@ import android.os.UserManager
import android.os.incremental.IncrementalManager
import android.provider.DeviceConfig
import android.util.ArrayMap
import android.util.ArraySet
import android.util.DisplayMetrics
import android.util.EventLog
import android.view.Display
@@ -294,6 +295,8 @@ class MockSystem(withSession: (StaticMockitoSessionBuilder) -> Unit = {}) {
wheneverStatic { SystemConfig.getInstance() }.thenReturn(mocks.systemConfig)
whenever(mocks.systemConfig.availableFeatures).thenReturn(DEFAULT_AVAILABLE_FEATURES_MAP)
whenever(mocks.systemConfig.sharedLibraries).thenReturn(DEFAULT_SHARED_LIBRARIES_LIST)
whenever(mocks.systemConfig.defaultVrComponents).thenReturn(ArraySet())
whenever(mocks.systemConfig.hiddenApiWhitelistedApps).thenReturn(ArraySet())
wheneverStatic { SystemProperties.getBoolean("fw.free_cache_v2", true) }.thenReturn(true)
wheneverStatic { Environment.getPackageCacheDirectory() }.thenReturn(packageCacheDirectory)
wheneverStatic { SystemProperties.digestOf("ro.build.fingerprint") }.thenReturn("cacheName")