Register device config service

Test: manual

Bug: 265948913

Change-Id: Ieefaeb911745902f633eaab0cafbe7202177b43a
This commit is contained in:
Pedro Loureiro
2023-01-13 18:16:16 +00:00
parent c9ea074e38
commit c980022cc0
4 changed files with 233 additions and 1 deletions

View File

@@ -462,6 +462,25 @@ package android.provider {
method @NonNull @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) public static java.util.Map<java.lang.String,java.util.List<android.content.ContentValues>> queryRawContactEntity(@NonNull android.content.ContentResolver, long);
}
public class DeviceConfigInitializer {
method @Nullable public static android.provider.DeviceConfigServiceManager getDeviceConfigServiceManager();
method public static void setDeviceConfigServiceManager(@NonNull android.provider.DeviceConfigServiceManager);
}
public class DeviceConfigServiceManager {
method @NonNull public android.provider.DeviceConfigServiceManager.ServiceRegisterer getDeviceConfigUpdatableServiceRegisterer();
}
public static class DeviceConfigServiceManager.ServiceNotFoundException extends java.lang.Exception {
}
public static final class DeviceConfigServiceManager.ServiceRegisterer {
method @Nullable public android.os.IBinder get();
method @NonNull public android.os.IBinder getOrThrow() throws android.provider.DeviceConfigServiceManager.ServiceNotFoundException;
method public void register(@NonNull android.os.IBinder);
method @Nullable public android.os.IBinder tryGet();
}
public final class Settings {
field public static final int RESET_MODE_PACKAGE_DEFAULTS = 1; // 0x1
field public static final int RESET_MODE_TRUSTED_DEFAULTS = 4; // 0x4

View File

@@ -151,6 +151,8 @@ import android.provider.BlockedNumberContract;
import android.provider.CalendarContract;
import android.provider.CallLog;
import android.provider.ContactsContract;
import android.provider.DeviceConfigInitializer;
import android.provider.DeviceConfigServiceManager;
import android.provider.Downloads;
import android.provider.FontsContract;
import android.provider.Settings;
@@ -8136,8 +8138,11 @@ public final class ActivityThread extends ClientTransactionHandler
MediaFrameworkInitializer.setMediaServiceManager(new MediaServiceManager());
BluetoothFrameworkInitializer.setBluetoothServiceManager(new BluetoothServiceManager());
BluetoothFrameworkInitializer.setBinderCallsStatsInitializer(context -> {
BinderCallsStats.startForBluetooth(context); });
BinderCallsStats.startForBluetooth(context);
});
NfcFrameworkInitializer.setNfcServiceManager(new NfcServiceManager());
DeviceConfigInitializer.setDeviceConfigServiceManager(new DeviceConfigServiceManager());
}
private void purgePendingResources() {

View File

@@ -0,0 +1,67 @@
/*
* Copyright (C) 2023 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 android.provider;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import java.util.Objects;
/**
* Class that will hold an instance of {@link DeviceConfigServiceManager}
* which is used by {@link DeviceConfig} to retrieve an instance of the service.
*
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public class DeviceConfigInitializer {
private static DeviceConfigServiceManager sDeviceConfigServiceManager;
private static final Object sLock = new Object();
private DeviceConfigInitializer() {
// fully static class
}
/**
* Setter for {@link DeviceConfigServiceManager}. Should be called only once.
*
*/
public static void setDeviceConfigServiceManager(
@NonNull DeviceConfigServiceManager serviceManager) {
synchronized (sLock) {
if (sDeviceConfigServiceManager != null) {
throw new IllegalStateException("setDeviceConfigServiceManager called twice!");
}
Objects.requireNonNull(serviceManager, "serviceManager must not be null");
sDeviceConfigServiceManager = serviceManager;
}
}
/**
* Getter for {@link DeviceConfigServiceManager}.
*
*/
@Nullable
public static DeviceConfigServiceManager getDeviceConfigServiceManager() {
synchronized (sLock) {
return sDeviceConfigServiceManager;
}
}
}

View File

@@ -0,0 +1,141 @@
/*
* Copyright (C) 2023 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 android.provider;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.IBinder;
import android.os.ServiceManager;
/**
* Service Manager for the {@code android.provider.DeviceConfig} service.
*
* <p>Used to be able to get an instance of the service in places that don't have access to a
* {@code Context}
*
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public class DeviceConfigServiceManager {
/**
* @hide
*/
public DeviceConfigServiceManager() {
}
/**
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public static final class ServiceRegisterer {
private final String mServiceName;
/**
* @hide
*/
public ServiceRegisterer(String serviceName) {
mServiceName = serviceName;
}
/**
* Register a system server binding object for a service.
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public void register(@NonNull IBinder service) {
ServiceManager.addService(mServiceName, service);
}
/**
* Get the system server binding object for a service.
*
* <p>This blocks until the service instance is ready,
* or a timeout happens, in which case it returns null.
*
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
@Nullable
public IBinder get() {
return ServiceManager.getService(mServiceName);
}
/**
* Get the system server binding object for a service.
*
* <p>This blocks until the service instance is ready,
* or a timeout happens, in which case it throws {@link ServiceNotFoundException}.
*
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
@NonNull
public IBinder getOrThrow() throws ServiceNotFoundException {
try {
return ServiceManager.getServiceOrThrow(mServiceName);
} catch (ServiceManager.ServiceNotFoundException e) {
throw new ServiceNotFoundException(mServiceName);
}
}
/**
* Get the system server binding object for a service. If the specified service is
* not available, it returns null.
*
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
@Nullable
public IBinder tryGet() {
return ServiceManager.checkService(mServiceName);
}
}
/**
* See {@link ServiceRegisterer#getOrThrow}.
*
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public static class ServiceNotFoundException extends ServiceManager.ServiceNotFoundException {
/**
* Constructor.
*
* @param name the name of the binder service that cannot be found.
*
* @hide
*/
public ServiceNotFoundException(@NonNull String name) {
super(name);
}
}
/**
* Returns {@link ServiceRegisterer} for the device config service that
* is updatable via mainline.
*
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
@NonNull
public ServiceRegisterer getDeviceConfigUpdatableServiceRegisterer() {
return new ServiceRegisterer("device_config_updatable");
}
}