Merge "[DO NOT MERGE] Check Sdk level before calling the DeviceConfig API" into tm-mainline-prod
This commit is contained in:
committed by
Android (Google) Code Review
commit
ff60f77664
@@ -22,6 +22,8 @@ import android.provider.DeviceConfig;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.android.internal.annotations.GuardedBy;
|
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;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
@@ -46,6 +48,12 @@ public class NearbyConfiguration {
|
|||||||
*/
|
*/
|
||||||
public static final String NEARBY_SUPPORT_TEST_APP = "nearby_support_test_app";
|
public static final String NEARBY_SUPPORT_TEST_APP = "nearby_support_test_app";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag to control which version of DiscoveryProviderManager should be used.
|
||||||
|
*/
|
||||||
|
public static final String NEARBY_REFACTOR_DISCOVERY_MANAGER =
|
||||||
|
"nearby_refactor_discovery_manager";
|
||||||
|
|
||||||
private static final boolean IS_USER_BUILD = "user".equals(Build.TYPE);
|
private static final boolean IS_USER_BUILD = "user".equals(Build.TYPE);
|
||||||
|
|
||||||
private final DeviceConfigListener mDeviceConfigListener = new DeviceConfigListener();
|
private final DeviceConfigListener mDeviceConfigListener = new DeviceConfigListener();
|
||||||
@@ -57,11 +65,39 @@ public class NearbyConfiguration {
|
|||||||
private int mNanoAppMinVersion;
|
private int mNanoAppMinVersion;
|
||||||
@GuardedBy("mDeviceConfigLock")
|
@GuardedBy("mDeviceConfigLock")
|
||||||
private boolean mSupportTestApp;
|
private boolean mSupportTestApp;
|
||||||
|
@GuardedBy("mDeviceConfigLock")
|
||||||
|
private boolean mRefactorDiscoveryManager;
|
||||||
|
|
||||||
public NearbyConfiguration() {
|
public NearbyConfiguration() {
|
||||||
mDeviceConfigListener.start();
|
mDeviceConfigListener.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the DeviceConfig namespace for Nearby. The DeviceConfig#NAMESPACE_NEARBY was
|
||||||
|
* added in UpsideDownCake, in Tiramisu, we use {@link DeviceConfig#NAMESPACE_TETHERING}.
|
||||||
|
*/
|
||||||
|
public static String getNamespace() {
|
||||||
|
if (SdkLevel.isAtLeastU()) {
|
||||||
|
// DeviceConfig.NAMESPACE_NEARBY
|
||||||
|
return "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;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getDeviceConfigInt(final String name, final int defaultValue) {
|
||||||
|
final String value = getDeviceConfigProperty(name);
|
||||||
|
return value != null ? Integer.parseInt(value) : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getDeviceConfigProperty(String name) {
|
||||||
|
return DeviceConfig.getProperty(getNamespace(), name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether broadcasting legacy presence spec is enabled.
|
* Returns whether broadcasting legacy presence spec is enabled.
|
||||||
*/
|
*/
|
||||||
@@ -86,11 +122,21 @@ public class NearbyConfiguration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@code true} if use {@link DiscoveryProviderManager} or use
|
||||||
|
* DiscoveryProviderManagerLegacy if {@code false}.
|
||||||
|
*/
|
||||||
|
public boolean refactorDiscoveryManager() {
|
||||||
|
synchronized (mDeviceConfigLock) {
|
||||||
|
return mRefactorDiscoveryManager;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class DeviceConfigListener implements DeviceConfig.OnPropertiesChangedListener {
|
private class DeviceConfigListener implements DeviceConfig.OnPropertiesChangedListener {
|
||||||
public void start() {
|
public void start() {
|
||||||
DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_TETHERING,
|
DeviceConfig.addOnPropertiesChangedListener(getNamespace(),
|
||||||
Executors.newSingleThreadExecutor(), this);
|
Executors.newSingleThreadExecutor(), this);
|
||||||
onPropertiesChanged(DeviceConfig.getProperties(DeviceConfig.NAMESPACE_TETHERING));
|
onPropertiesChanged(DeviceConfig.getProperties(getNamespace()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -102,21 +148,9 @@ public class NearbyConfiguration {
|
|||||||
NEARBY_MAINLINE_NANO_APP_MIN_VERSION, 0 /* defaultValue */);
|
NEARBY_MAINLINE_NANO_APP_MIN_VERSION, 0 /* defaultValue */);
|
||||||
mSupportTestApp = !IS_USER_BUILD && getDeviceConfigBoolean(
|
mSupportTestApp = !IS_USER_BUILD && getDeviceConfigBoolean(
|
||||||
NEARBY_SUPPORT_TEST_APP, false /* defaultValue */);
|
NEARBY_SUPPORT_TEST_APP, false /* defaultValue */);
|
||||||
|
mRefactorDiscoveryManager = getDeviceConfigBoolean(
|
||||||
|
NEARBY_REFACTOR_DISCOVERY_MANAGER, false /* defaultValue */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean getDeviceConfigBoolean(final String name, final boolean defaultValue) {
|
|
||||||
final String value = getDeviceConfigProperty(name);
|
|
||||||
return value != null ? Boolean.parseBoolean(value) : defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getDeviceConfigInt(final String name, final int defaultValue) {
|
|
||||||
final String value = getDeviceConfigProperty(name);
|
|
||||||
return value != null ? Integer.parseInt(value) : defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getDeviceConfigProperty(String name) {
|
|
||||||
return DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TETHERING, name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package com.android.server.nearby;
|
|||||||
|
|
||||||
import static android.Manifest.permission.READ_DEVICE_CONFIG;
|
import static android.Manifest.permission.READ_DEVICE_CONFIG;
|
||||||
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
|
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
|
||||||
import static android.provider.DeviceConfig.NAMESPACE_TETHERING;
|
|
||||||
|
|
||||||
import static com.android.server.nearby.NearbyConfiguration.NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY;
|
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;
|
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 {
|
public final class NearbyConfigurationTest {
|
||||||
|
|
||||||
|
private static final String NAMESPACE = NearbyConfiguration.getNamespace();
|
||||||
private NearbyConfiguration mNearbyConfiguration;
|
private NearbyConfiguration mNearbyConfiguration;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -48,11 +48,11 @@ public final class NearbyConfigurationTest {
|
|||||||
public void testDeviceConfigChanged() throws InterruptedException {
|
public void testDeviceConfigChanged() throws InterruptedException {
|
||||||
mNearbyConfiguration = new NearbyConfiguration();
|
mNearbyConfiguration = new NearbyConfiguration();
|
||||||
|
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_SUPPORT_TEST_APP,
|
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP,
|
||||||
"false", false);
|
"false", false);
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY,
|
DeviceConfig.setProperty(NAMESPACE, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY,
|
||||||
"false", false);
|
"false", false);
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_MAINLINE_NANO_APP_MIN_VERSION,
|
DeviceConfig.setProperty(NAMESPACE, NEARBY_MAINLINE_NANO_APP_MIN_VERSION,
|
||||||
"1", false);
|
"1", false);
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
|
|
||||||
@@ -60,11 +60,11 @@ public final class NearbyConfigurationTest {
|
|||||||
assertThat(mNearbyConfiguration.isPresenceBroadcastLegacyEnabled()).isFalse();
|
assertThat(mNearbyConfiguration.isPresenceBroadcastLegacyEnabled()).isFalse();
|
||||||
assertThat(mNearbyConfiguration.getNanoAppMinVersion()).isEqualTo(1);
|
assertThat(mNearbyConfiguration.getNanoAppMinVersion()).isEqualTo(1);
|
||||||
|
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_SUPPORT_TEST_APP,
|
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP,
|
||||||
"true", false);
|
"true", false);
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY,
|
DeviceConfig.setProperty(NAMESPACE, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY,
|
||||||
"true", false);
|
"true", false);
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_MAINLINE_NANO_APP_MIN_VERSION,
|
DeviceConfig.setProperty(NAMESPACE, NEARBY_MAINLINE_NANO_APP_MIN_VERSION,
|
||||||
"3", false);
|
"3", false);
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
|
|
||||||
@@ -76,11 +76,11 @@ public final class NearbyConfigurationTest {
|
|||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
// Sets DeviceConfig values back to default
|
// Sets DeviceConfig values back to default
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_SUPPORT_TEST_APP,
|
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP,
|
||||||
"false", true);
|
"false", true);
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY,
|
DeviceConfig.setProperty(NAMESPACE, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY,
|
||||||
"false", true);
|
"false", true);
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_MAINLINE_NANO_APP_MIN_VERSION,
|
DeviceConfig.setProperty(NAMESPACE, NEARBY_MAINLINE_NANO_APP_MIN_VERSION,
|
||||||
"0", true);
|
"0", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package com.android.server.nearby;
|
|||||||
import static android.Manifest.permission.BLUETOOTH_PRIVILEGED;
|
import static android.Manifest.permission.BLUETOOTH_PRIVILEGED;
|
||||||
import static android.Manifest.permission.READ_DEVICE_CONFIG;
|
import static android.Manifest.permission.READ_DEVICE_CONFIG;
|
||||||
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
|
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
|
||||||
import static android.provider.DeviceConfig.NAMESPACE_TETHERING;
|
|
||||||
|
|
||||||
import static com.android.server.nearby.NearbyConfiguration.NEARBY_SUPPORT_TEST_APP;
|
import static com.android.server.nearby.NearbyConfiguration.NEARBY_SUPPORT_TEST_APP;
|
||||||
|
|
||||||
@@ -36,6 +35,7 @@ import android.app.UiAutomation;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.nearby.IScanListener;
|
import android.nearby.IScanListener;
|
||||||
import android.nearby.ScanRequest;
|
import android.nearby.ScanRequest;
|
||||||
|
import android.os.IBinder;
|
||||||
import android.provider.DeviceConfig;
|
import android.provider.DeviceConfig;
|
||||||
|
|
||||||
import androidx.test.platform.app.InstrumentationRegistry;
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
@@ -50,6 +50,7 @@ import org.mockito.Mock;
|
|||||||
|
|
||||||
public final class NearbyServiceTest {
|
public final class NearbyServiceTest {
|
||||||
|
|
||||||
|
private static final String NAMESPACE = NearbyConfiguration.getNamespace();
|
||||||
private static final String PACKAGE_NAME = "android.nearby.test";
|
private static final String PACKAGE_NAME = "android.nearby.test";
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private NearbyService mService;
|
private NearbyService mService;
|
||||||
@@ -61,10 +62,14 @@ public final class NearbyServiceTest {
|
|||||||
private IScanListener mScanListener;
|
private IScanListener mScanListener;
|
||||||
@Mock
|
@Mock
|
||||||
private AppOpsManager mMockAppOpsManager;
|
private AppOpsManager mMockAppOpsManager;
|
||||||
|
@Mock
|
||||||
|
private IBinder mIBinder;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
initMocks(this);
|
initMocks(this);
|
||||||
|
when(mScanListener.asBinder()).thenReturn(mIBinder);
|
||||||
|
|
||||||
mUiAutomation.adoptShellPermissionIdentity(
|
mUiAutomation.adoptShellPermissionIdentity(
|
||||||
READ_DEVICE_CONFIG, WRITE_DEVICE_CONFIG, BLUETOOTH_PRIVILEGED);
|
READ_DEVICE_CONFIG, WRITE_DEVICE_CONFIG, BLUETOOTH_PRIVILEGED);
|
||||||
mContext = InstrumentationRegistry.getInstrumentation().getContext();
|
mContext = InstrumentationRegistry.getInstrumentation().getContext();
|
||||||
@@ -86,7 +91,7 @@ public final class NearbyServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_register_noPrivilegedPermission_throwsException() {
|
public void test_register_noPrivilegedPermission_throwsException() {
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_SUPPORT_TEST_APP,
|
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP,
|
||||||
"false", false);
|
"false", false);
|
||||||
mUiAutomation.dropShellPermissionIdentity();
|
mUiAutomation.dropShellPermissionIdentity();
|
||||||
assertThrows(java.lang.SecurityException.class,
|
assertThrows(java.lang.SecurityException.class,
|
||||||
@@ -96,7 +101,7 @@ public final class NearbyServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_unregister_noPrivilegedPermission_throwsException() {
|
public void test_unregister_noPrivilegedPermission_throwsException() {
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_SUPPORT_TEST_APP,
|
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP,
|
||||||
"false", false);
|
"false", false);
|
||||||
mUiAutomation.dropShellPermissionIdentity();
|
mUiAutomation.dropShellPermissionIdentity();
|
||||||
assertThrows(java.lang.SecurityException.class,
|
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.READ_DEVICE_CONFIG;
|
||||||
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
|
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
|
||||||
import static android.provider.DeviceConfig.NAMESPACE_TETHERING;
|
|
||||||
|
|
||||||
import static com.android.server.nearby.NearbyConfiguration.NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY;
|
import static com.android.server.nearby.NearbyConfiguration.NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY;
|
||||||
import static com.android.server.nearby.NearbyConfiguration.NEARBY_SUPPORT_TEST_APP;
|
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.core.app.ApplicationProvider;
|
||||||
import androidx.test.platform.app.InstrumentationRegistry;
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
|
|
||||||
|
import com.android.server.nearby.NearbyConfiguration;
|
||||||
import com.android.server.nearby.provider.BleBroadcastProvider;
|
import com.android.server.nearby.provider.BleBroadcastProvider;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
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}.
|
* Unit test for {@link com.android.server.nearby.managers.BroadcastProviderManager}.
|
||||||
*/
|
*/
|
||||||
public class BroadcastProviderManagerTest {
|
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 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 int MEDIUM_TYPE_BLE = 0;
|
||||||
private static final byte[] SALT = {2, 3};
|
private static final byte[] SALT = {2, 3};
|
||||||
@@ -82,8 +83,8 @@ public class BroadcastProviderManagerTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mUiAutomation.adoptShellPermissionIdentity(WRITE_DEVICE_CONFIG, READ_DEVICE_CONFIG);
|
mUiAutomation.adoptShellPermissionIdentity(WRITE_DEVICE_CONFIG, READ_DEVICE_CONFIG);
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY,
|
DeviceConfig.setProperty(
|
||||||
"true", false);
|
NAMESPACE, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY, "true", false);
|
||||||
|
|
||||||
mContext = ApplicationProvider.getApplicationContext();
|
mContext = ApplicationProvider.getApplicationContext();
|
||||||
mBroadcastProviderManager = new BroadcastProviderManager(
|
mBroadcastProviderManager = new BroadcastProviderManager(
|
||||||
@@ -116,10 +117,10 @@ public class BroadcastProviderManagerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStartAdvertising_featureDisabled() throws Exception {
|
public void testStartAdvertising_featureDisabled() throws Exception {
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY,
|
DeviceConfig.setProperty(
|
||||||
"false", false);
|
NAMESPACE, NEARBY_ENABLE_PRESENCE_BROADCAST_LEGACY, "false", false);
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_SUPPORT_TEST_APP,
|
DeviceConfig.setProperty(
|
||||||
"false", false);
|
NAMESPACE, NEARBY_SUPPORT_TEST_APP, "false", false);
|
||||||
|
|
||||||
mBroadcastProviderManager = new BroadcastProviderManager(MoreExecutors.directExecutor(),
|
mBroadcastProviderManager = new BroadcastProviderManager(MoreExecutors.directExecutor(),
|
||||||
mBleBroadcastProvider);
|
mBleBroadcastProvider);
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package com.android.server.nearby.provider;
|
|||||||
|
|
||||||
import static android.Manifest.permission.READ_DEVICE_CONFIG;
|
import static android.Manifest.permission.READ_DEVICE_CONFIG;
|
||||||
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
|
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
|
||||||
import static android.provider.DeviceConfig.NAMESPACE_TETHERING;
|
|
||||||
|
|
||||||
import static com.android.server.nearby.NearbyConfiguration.NEARBY_MAINLINE_NANO_APP_MIN_VERSION;
|
import static com.android.server.nearby.NearbyConfiguration.NEARBY_MAINLINE_NANO_APP_MIN_VERSION;
|
||||||
|
|
||||||
@@ -40,6 +39,7 @@ import android.provider.DeviceConfig;
|
|||||||
|
|
||||||
import androidx.test.platform.app.InstrumentationRegistry;
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
|
|
||||||
|
import com.android.server.nearby.NearbyConfiguration;
|
||||||
import com.android.server.nearby.injector.Injector;
|
import com.android.server.nearby.injector.Injector;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -54,6 +54,8 @@ import java.util.List;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
public class ChreCommunicationTest {
|
public class ChreCommunicationTest {
|
||||||
|
private static final String NAMESPACE = NearbyConfiguration.getNamespace();
|
||||||
|
|
||||||
@Mock Injector mInjector;
|
@Mock Injector mInjector;
|
||||||
@Mock Context mContext;
|
@Mock Context mContext;
|
||||||
@Mock ContextHubManager mManager;
|
@Mock ContextHubManager mManager;
|
||||||
@@ -71,8 +73,8 @@ public class ChreCommunicationTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
InstrumentationRegistry.getInstrumentation().getUiAutomation()
|
InstrumentationRegistry.getInstrumentation().getUiAutomation()
|
||||||
.adoptShellPermissionIdentity(WRITE_DEVICE_CONFIG, READ_DEVICE_CONFIG);
|
.adoptShellPermissionIdentity(WRITE_DEVICE_CONFIG, READ_DEVICE_CONFIG);
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_MAINLINE_NANO_APP_MIN_VERSION,
|
DeviceConfig.setProperty(
|
||||||
"1", false);
|
NAMESPACE, NEARBY_MAINLINE_NANO_APP_MIN_VERSION, "1", false);
|
||||||
|
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
when(mInjector.getContextHubManager()).thenReturn(mManager);
|
when(mInjector.getContextHubManager()).thenReturn(mManager);
|
||||||
@@ -111,8 +113,7 @@ public class ChreCommunicationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotReachMinVersion() {
|
public void testNotReachMinVersion() {
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_MAINLINE_NANO_APP_MIN_VERSION,
|
DeviceConfig.setProperty(NAMESPACE, NEARBY_MAINLINE_NANO_APP_MIN_VERSION, "3", false);
|
||||||
"3", false);
|
|
||||||
mChreCommunication.start(
|
mChreCommunication.start(
|
||||||
mChreCallback, Collections.singleton(ChreDiscoveryProvider.NANOAPP_ID));
|
mChreCallback, Collections.singleton(ChreDiscoveryProvider.NANOAPP_ID));
|
||||||
verify(mTransaction).setOnCompleteListener(mOnQueryCompleteListenerCaptor.capture(), any());
|
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.READ_DEVICE_CONFIG;
|
||||||
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
|
import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
|
||||||
import static android.provider.DeviceConfig.NAMESPACE_TETHERING;
|
|
||||||
|
|
||||||
import static com.android.server.nearby.NearbyConfiguration.NEARBY_SUPPORT_TEST_APP;
|
import static com.android.server.nearby.NearbyConfiguration.NEARBY_SUPPORT_TEST_APP;
|
||||||
|
|
||||||
@@ -61,6 +60,7 @@ public class ChreDiscoveryProviderTest {
|
|||||||
@Captor ArgumentCaptor<ChreCommunication.ContextHubCommsCallback> mChreCallbackCaptor;
|
@Captor ArgumentCaptor<ChreCommunication.ContextHubCommsCallback> mChreCallbackCaptor;
|
||||||
@Captor ArgumentCaptor<NearbyDeviceParcelable> mNearbyDevice;
|
@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_CONNECTION_STATUS_KEY = 10;
|
||||||
private static final int DATA_TYPE_BATTERY_KEY = 11;
|
private static final int DATA_TYPE_BATTERY_KEY = 11;
|
||||||
private static final int DATA_TYPE_TX_POWER_KEY = 5;
|
private static final int DATA_TYPE_TX_POWER_KEY = 5;
|
||||||
@@ -130,7 +130,7 @@ public class ChreDiscoveryProviderTest {
|
|||||||
boolean isSupportedTestApp = getDeviceConfigBoolean(
|
boolean isSupportedTestApp = getDeviceConfigBoolean(
|
||||||
NEARBY_SUPPORT_TEST_APP, false /* defaultValue */);
|
NEARBY_SUPPORT_TEST_APP, false /* defaultValue */);
|
||||||
if (isSupportedTestApp) {
|
if (isSupportedTestApp) {
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_SUPPORT_TEST_APP, "false", false);
|
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP, "false", false);
|
||||||
}
|
}
|
||||||
assertThat(new NearbyConfiguration().isTestAppSupported()).isFalse();
|
assertThat(new NearbyConfiguration().isTestAppSupported()).isFalse();
|
||||||
|
|
||||||
@@ -215,7 +215,7 @@ public class ChreDiscoveryProviderTest {
|
|||||||
assertThat(extendedProperties).containsExactlyElementsIn(expectedExtendedProperties);
|
assertThat(extendedProperties).containsExactlyElementsIn(expectedExtendedProperties);
|
||||||
// Reverts the setting of test app support
|
// Reverts the setting of test app support
|
||||||
if (isSupportedTestApp) {
|
if (isSupportedTestApp) {
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_SUPPORT_TEST_APP, "true", false);
|
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP, "true", false);
|
||||||
assertThat(new NearbyConfiguration().isTestAppSupported()).isTrue();
|
assertThat(new NearbyConfiguration().isTestAppSupported()).isTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,7 +227,7 @@ public class ChreDiscoveryProviderTest {
|
|||||||
boolean isSupportedTestApp = getDeviceConfigBoolean(
|
boolean isSupportedTestApp = getDeviceConfigBoolean(
|
||||||
NEARBY_SUPPORT_TEST_APP, false /* defaultValue */);
|
NEARBY_SUPPORT_TEST_APP, false /* defaultValue */);
|
||||||
if (!isSupportedTestApp) {
|
if (!isSupportedTestApp) {
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_SUPPORT_TEST_APP, "true", false);
|
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP, "true", false);
|
||||||
}
|
}
|
||||||
assertThat(new NearbyConfiguration().isTestAppSupported()).isTrue();
|
assertThat(new NearbyConfiguration().isTestAppSupported()).isTrue();
|
||||||
|
|
||||||
@@ -316,7 +316,7 @@ public class ChreDiscoveryProviderTest {
|
|||||||
assertThat(extendedProperties).containsExactlyElementsIn(expectedExtendedProperties);
|
assertThat(extendedProperties).containsExactlyElementsIn(expectedExtendedProperties);
|
||||||
// Reverts the setting of test app support
|
// Reverts the setting of test app support
|
||||||
if (!isSupportedTestApp) {
|
if (!isSupportedTestApp) {
|
||||||
DeviceConfig.setProperty(NAMESPACE_TETHERING, NEARBY_SUPPORT_TEST_APP, "false", false);
|
DeviceConfig.setProperty(NAMESPACE, NEARBY_SUPPORT_TEST_APP, "false", false);
|
||||||
assertThat(new NearbyConfiguration().isTestAppSupported()).isFalse();
|
assertThat(new NearbyConfiguration().isTestAppSupported()).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -327,7 +327,7 @@ public class ChreDiscoveryProviderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getDeviceConfigProperty(String name) {
|
private String getDeviceConfigProperty(String name) {
|
||||||
return DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TETHERING, name);
|
return DeviceConfig.getProperty(NAMESPACE, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class InLineExecutor implements Executor {
|
private static class InLineExecutor implements Executor {
|
||||||
|
|||||||
Reference in New Issue
Block a user