Merge "Check Sdk level before calling the DeviceConfig API" into udc-dev
This commit is contained in:
commit
43529a075d
7 changed files with 52 additions and 36 deletions
|
|
@ -22,6 +22,7 @@ import android.provider.DeviceConfig;
|
|||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.modules.utils.build.SdkLevel;
|
||||
import com.android.server.nearby.managers.DiscoveryProviderManager;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
|
@ -71,6 +72,17 @@ public class NearbyConfiguration {
|
|||
mDeviceConfigListener.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the DeviceConfig namespace for Nearby. The {@link DeviceConfig#NAMESPACE_NEARBY} was
|
||||
* added in UpsideDownCake, in Tiramisu, we use {@link DeviceConfig#NAMESPACE_TETHERING}.
|
||||
*/
|
||||
public static String getNamespace() {
|
||||
if (SdkLevel.isAtLeastU()) {
|
||||
return DeviceConfig.NAMESPACE_NEARBY;
|
||||
}
|
||||
return DeviceConfig.NAMESPACE_TETHERING;
|
||||
}
|
||||
|
||||
private static boolean getDeviceConfigBoolean(final String name, final boolean defaultValue) {
|
||||
final String value = getDeviceConfigProperty(name);
|
||||
return value != null ? Boolean.parseBoolean(value) : defaultValue;
|
||||
|
|
@ -82,7 +94,7 @@ public class NearbyConfiguration {
|
|||
}
|
||||
|
||||
private static String getDeviceConfigProperty(String name) {
|
||||
return DeviceConfig.getProperty(DeviceConfig.NAMESPACE_NEARBY, name);
|
||||
return DeviceConfig.getProperty(getNamespace(), name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -121,9 +133,9 @@ public class NearbyConfiguration {
|
|||
|
||||
private class DeviceConfigListener implements DeviceConfig.OnPropertiesChangedListener {
|
||||
public void start() {
|
||||
DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_NEARBY,
|
||||
DeviceConfig.addOnPropertiesChangedListener(getNamespace(),
|
||||
Executors.newSingleThreadExecutor(), this);
|
||||
onPropertiesChanged(DeviceConfig.getProperties(DeviceConfig.NAMESPACE_NEARBY));
|
||||
onPropertiesChanged(DeviceConfig.getProperties(getNamespace()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import static android.Manifest.permission.READ_DEVICE_CONFIG;
|
|||
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
|
||||
import static android.nearby.PresenceCredential.IDENTITY_TYPE_PRIVATE;
|
||||
import static android.nearby.ScanCallback.ERROR_UNSUPPORTED;
|
||||
import static android.provider.DeviceConfig.NAMESPACE_NEARBY;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
|
|
@ -51,6 +50,8 @@ import androidx.test.InstrumentationRegistry;
|
|||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.filters.SdkSuppress;
|
||||
|
||||
import com.android.modules.utils.build.SdkLevel;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
|
@ -113,7 +114,9 @@ public class NearbyManagerTest {
|
|||
public void setUp() {
|
||||
mUiAutomation.adoptShellPermissionIdentity(READ_DEVICE_CONFIG, WRITE_DEVICE_CONFIG,
|
||||
BLUETOOTH_PRIVILEGED);
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY,
|
||||
String nameSpace = SdkLevel.isAtLeastU() ? DeviceConfig.NAMESPACE_NEARBY
|
||||
: DeviceConfig.NAMESPACE_TETHERING;
|
||||
DeviceConfig.setProperty(nameSpace,
|
||||
"nearby_enable_presence_broadcast_legacy",
|
||||
"true", false);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package com.android.server.nearby;
|
|||
|
||||
import static android.Manifest.permission.READ_DEVICE_CONFIG;
|
||||
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
|
||||
import static android.provider.DeviceConfig.NAMESPACE_NEARBY;
|
||||
|
||||
import static com.android.server.nearby.NearbyConfiguration.NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY;
|
||||
import static com.android.server.nearby.NearbyConfiguration.NEARBY_MAINLINE_NANO_APP_MIN_VERSION;
|
||||
|
|
@ -36,6 +35,7 @@ import org.junit.Test;
|
|||
|
||||
public final class NearbyConfigurationTest {
|
||||
|
||||
private static final String NAMESPACE = NearbyConfiguration.getNamespace();
|
||||
private NearbyConfiguration mNearbyConfiguration;
|
||||
|
||||
@Before
|
||||
|
|
@ -48,11 +48,11 @@ public final class NearbyConfigurationTest {
|
|||
public void testDeviceConfigChanged() throws InterruptedException {
|
||||
mNearbyConfiguration = new NearbyConfiguration();
|
||||
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_SUPPORT_TEST_APP,
|
||||
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP,
|
||||
"false", false);
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY,
|
||||
DeviceConfig.setProperty(NAMESPACE, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY,
|
||||
"false", false);
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_MAINLINE_NANO_APP_MIN_VERSION,
|
||||
DeviceConfig.setProperty(NAMESPACE, NEARBY_MAINLINE_NANO_APP_MIN_VERSION,
|
||||
"1", false);
|
||||
Thread.sleep(500);
|
||||
|
||||
|
|
@ -60,11 +60,11 @@ public final class NearbyConfigurationTest {
|
|||
assertThat(mNearbyConfiguration.isPresenceBroadcastLegacyEnabled()).isFalse();
|
||||
assertThat(mNearbyConfiguration.getNanoAppMinVersion()).isEqualTo(1);
|
||||
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_SUPPORT_TEST_APP,
|
||||
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP,
|
||||
"true", false);
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY,
|
||||
DeviceConfig.setProperty(NAMESPACE, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY,
|
||||
"true", false);
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_MAINLINE_NANO_APP_MIN_VERSION,
|
||||
DeviceConfig.setProperty(NAMESPACE, NEARBY_MAINLINE_NANO_APP_MIN_VERSION,
|
||||
"3", false);
|
||||
Thread.sleep(500);
|
||||
|
||||
|
|
@ -76,11 +76,11 @@ public final class NearbyConfigurationTest {
|
|||
@After
|
||||
public void tearDown() {
|
||||
// Sets DeviceConfig values back to default
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_SUPPORT_TEST_APP,
|
||||
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP,
|
||||
"false", true);
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY,
|
||||
DeviceConfig.setProperty(NAMESPACE, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY,
|
||||
"false", true);
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_MAINLINE_NANO_APP_MIN_VERSION,
|
||||
DeviceConfig.setProperty(NAMESPACE, NEARBY_MAINLINE_NANO_APP_MIN_VERSION,
|
||||
"0", true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package com.android.server.nearby;
|
|||
import static android.Manifest.permission.BLUETOOTH_PRIVILEGED;
|
||||
import static android.Manifest.permission.READ_DEVICE_CONFIG;
|
||||
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
|
||||
import static android.provider.DeviceConfig.NAMESPACE_NEARBY;
|
||||
|
||||
import static com.android.server.nearby.NearbyConfiguration.NEARBY_SUPPORT_TEST_APP;
|
||||
|
||||
|
|
@ -51,6 +50,7 @@ import org.mockito.Mock;
|
|||
|
||||
public final class NearbyServiceTest {
|
||||
|
||||
private static final String NAMESPACE = NearbyConfiguration.getNamespace();
|
||||
private static final String PACKAGE_NAME = "android.nearby.test";
|
||||
private Context mContext;
|
||||
private NearbyService mService;
|
||||
|
|
@ -91,7 +91,7 @@ public final class NearbyServiceTest {
|
|||
|
||||
@Test
|
||||
public void test_register_noPrivilegedPermission_throwsException() {
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_SUPPORT_TEST_APP,
|
||||
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP,
|
||||
"false", false);
|
||||
mUiAutomation.dropShellPermissionIdentity();
|
||||
assertThrows(java.lang.SecurityException.class,
|
||||
|
|
@ -101,7 +101,7 @@ public final class NearbyServiceTest {
|
|||
|
||||
@Test
|
||||
public void test_unregister_noPrivilegedPermission_throwsException() {
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_SUPPORT_TEST_APP,
|
||||
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP,
|
||||
"false", false);
|
||||
mUiAutomation.dropShellPermissionIdentity();
|
||||
assertThrows(java.lang.SecurityException.class,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package com.android.server.nearby.managers;
|
|||
|
||||
import static android.Manifest.permission.READ_DEVICE_CONFIG;
|
||||
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
|
||||
import static android.provider.DeviceConfig.NAMESPACE_NEARBY;
|
||||
|
||||
import static com.android.server.nearby.NearbyConfiguration.NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY;
|
||||
import static com.android.server.nearby.NearbyConfiguration.NEARBY_SUPPORT_TEST_APP;
|
||||
|
|
@ -40,6 +39,7 @@ import android.provider.DeviceConfig;
|
|||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
|
||||
import com.android.server.nearby.NearbyConfiguration;
|
||||
import com.android.server.nearby.provider.BleBroadcastProvider;
|
||||
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
|
|
@ -57,6 +57,7 @@ import java.util.Collections;
|
|||
* Unit test for {@link com.android.server.nearby.managers.BroadcastProviderManager}.
|
||||
*/
|
||||
public class BroadcastProviderManagerTest {
|
||||
private static final String NAMESPACE = NearbyConfiguration.getNamespace();
|
||||
private static final byte[] IDENTITY = new byte[]{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
|
||||
private static final int MEDIUM_TYPE_BLE = 0;
|
||||
private static final byte[] SALT = {2, 3};
|
||||
|
|
@ -82,8 +83,8 @@ public class BroadcastProviderManagerTest {
|
|||
@Before
|
||||
public void setUp() {
|
||||
mUiAutomation.adoptShellPermissionIdentity(WRITE_DEVICE_CONFIG, READ_DEVICE_CONFIG);
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY,
|
||||
"true", false);
|
||||
DeviceConfig.setProperty(
|
||||
NAMESPACE, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY, "true", false);
|
||||
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
mBroadcastProviderManager = new BroadcastProviderManager(
|
||||
|
|
@ -116,10 +117,10 @@ public class BroadcastProviderManagerTest {
|
|||
|
||||
@Test
|
||||
public void testStartAdvertising_featureDisabled() throws Exception {
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY,
|
||||
"false", false);
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_SUPPORT_TEST_APP,
|
||||
"false", false);
|
||||
DeviceConfig.setProperty(
|
||||
NAMESPACE, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY, "false", false);
|
||||
DeviceConfig.setProperty(
|
||||
NAMESPACE, NEARBY_SUPPORT_TEST_APP, "false", false);
|
||||
|
||||
mBroadcastProviderManager = new BroadcastProviderManager(MoreExecutors.directExecutor(),
|
||||
mBleBroadcastProvider);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package com.android.server.nearby.provider;
|
|||
|
||||
import static android.Manifest.permission.READ_DEVICE_CONFIG;
|
||||
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
|
||||
import static android.provider.DeviceConfig.NAMESPACE_NEARBY;
|
||||
|
||||
import static com.android.server.nearby.NearbyConfiguration.NEARBY_MAINLINE_NANO_APP_MIN_VERSION;
|
||||
import static com.android.server.nearby.provider.ChreCommunication.INVALID_NANO_APP_VERSION;
|
||||
|
|
@ -43,6 +42,7 @@ import android.provider.DeviceConfig;
|
|||
import androidx.test.filters.SdkSuppress;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
|
||||
import com.android.server.nearby.NearbyConfiguration;
|
||||
import com.android.server.nearby.injector.Injector;
|
||||
|
||||
import org.junit.Before;
|
||||
|
|
@ -57,6 +57,7 @@ import java.util.List;
|
|||
import java.util.concurrent.Executor;
|
||||
|
||||
public class ChreCommunicationTest {
|
||||
private static final String NAMESPACE = NearbyConfiguration.getNamespace();
|
||||
private static final int APP_VERSION = 1;
|
||||
|
||||
@Mock Injector mInjector;
|
||||
|
|
@ -76,8 +77,8 @@ public class ChreCommunicationTest {
|
|||
public void setUp() {
|
||||
InstrumentationRegistry.getInstrumentation().getUiAutomation()
|
||||
.adoptShellPermissionIdentity(WRITE_DEVICE_CONFIG, READ_DEVICE_CONFIG);
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_MAINLINE_NANO_APP_MIN_VERSION,
|
||||
"1", false);
|
||||
DeviceConfig.setProperty(
|
||||
NAMESPACE, NEARBY_MAINLINE_NANO_APP_MIN_VERSION, "1", false);
|
||||
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mInjector.getContextHubManager()).thenReturn(mManager);
|
||||
|
|
@ -119,8 +120,7 @@ public class ChreCommunicationTest {
|
|||
|
||||
@Test
|
||||
public void testNotReachMinVersion() {
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_MAINLINE_NANO_APP_MIN_VERSION,
|
||||
"3", false);
|
||||
DeviceConfig.setProperty(NAMESPACE, NEARBY_MAINLINE_NANO_APP_MIN_VERSION, "3", false);
|
||||
mChreCommunication.start(
|
||||
mChreCallback, Collections.singleton(ChreDiscoveryProvider.NANOAPP_ID));
|
||||
verify(mTransaction).setOnCompleteListener(mOnQueryCompleteListenerCaptor.capture(), any());
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package com.android.server.nearby.provider;
|
|||
|
||||
import static android.Manifest.permission.READ_DEVICE_CONFIG;
|
||||
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
|
||||
import static android.provider.DeviceConfig.NAMESPACE_NEARBY;
|
||||
|
||||
import static com.android.server.nearby.NearbyConfiguration.NEARBY_SUPPORT_TEST_APP;
|
||||
|
||||
|
|
@ -68,6 +67,7 @@ public class ChreDiscoveryProviderTest {
|
|||
@Captor ArgumentCaptor<ChreCommunication.ContextHubCommsCallback> mChreCallbackCaptor;
|
||||
@Captor ArgumentCaptor<NearbyDeviceParcelable> mNearbyDevice;
|
||||
|
||||
private static final String NAMESPACE = NearbyConfiguration.getNamespace();
|
||||
private static final int DATA_TYPE_CONNECTION_STATUS_KEY = 10;
|
||||
private static final int DATA_TYPE_BATTERY_KEY = 11;
|
||||
private static final int DATA_TYPE_TX_POWER_KEY = 5;
|
||||
|
|
@ -197,7 +197,7 @@ public class ChreDiscoveryProviderTest {
|
|||
boolean isSupportedTestApp = getDeviceConfigBoolean(
|
||||
NEARBY_SUPPORT_TEST_APP, false /* defaultValue */);
|
||||
if (isSupportedTestApp) {
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_SUPPORT_TEST_APP, "false", false);
|
||||
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP, "false", false);
|
||||
}
|
||||
assertThat(new NearbyConfiguration().isTestAppSupported()).isFalse();
|
||||
|
||||
|
|
@ -282,7 +282,7 @@ public class ChreDiscoveryProviderTest {
|
|||
assertThat(extendedProperties).containsExactlyElementsIn(expectedExtendedProperties);
|
||||
// Reverts the setting of test app support
|
||||
if (isSupportedTestApp) {
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_SUPPORT_TEST_APP, "true", false);
|
||||
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP, "true", false);
|
||||
assertThat(new NearbyConfiguration().isTestAppSupported()).isTrue();
|
||||
}
|
||||
}
|
||||
|
|
@ -294,7 +294,7 @@ public class ChreDiscoveryProviderTest {
|
|||
boolean isSupportedTestApp = getDeviceConfigBoolean(
|
||||
NEARBY_SUPPORT_TEST_APP, false /* defaultValue */);
|
||||
if (!isSupportedTestApp) {
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_SUPPORT_TEST_APP, "true", false);
|
||||
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP, "true", false);
|
||||
}
|
||||
assertThat(new NearbyConfiguration().isTestAppSupported()).isTrue();
|
||||
|
||||
|
|
@ -383,7 +383,7 @@ public class ChreDiscoveryProviderTest {
|
|||
assertThat(extendedProperties).containsExactlyElementsIn(expectedExtendedProperties);
|
||||
// Reverts the setting of test app support
|
||||
if (!isSupportedTestApp) {
|
||||
DeviceConfig.setProperty(NAMESPACE_NEARBY, NEARBY_SUPPORT_TEST_APP, "false", false);
|
||||
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP, "false", false);
|
||||
assertThat(new NearbyConfiguration().isTestAppSupported()).isFalse();
|
||||
}
|
||||
}
|
||||
|
|
@ -394,7 +394,7 @@ public class ChreDiscoveryProviderTest {
|
|||
}
|
||||
|
||||
private String getDeviceConfigProperty(String name) {
|
||||
return DeviceConfig.getProperty(DeviceConfig.NAMESPACE_NEARBY, name);
|
||||
return DeviceConfig.getProperty(NAMESPACE, name);
|
||||
}
|
||||
|
||||
private static class InLineExecutor implements Executor {
|
||||
|
|
|
|||
Loading…
Reference in a new issue