1 package com.android.onboarding.bedsteadonboarding.providers 2 3 import android.content.ContentResolver 4 import android.content.Context 5 import android.net.Uri 6 7 /** 8 * Utility class for [TestContentProvider]. This contains constants representing content provider 9 * paths and also functions on creating uri using those. 10 */ 11 object ConfigProviderUtil { 12 /** 13 * The relative path for content provider representing all test configurations. This should be 14 * used to delete all the configs at once. 15 */ 16 internal const val TEST_CONFIG_PATH = "test_config" 17 18 /** The base path for content provider for querying fake activity node configs. */ 19 private const val FAKE_ACTIVITY_NODE_CONFIG_QUERY_BASE_PATH = "fake_activity_node_config" 20 21 /** The relative path of the content provider for querying fake activity node configs. */ 22 internal const val FAKE_ACTIVITY_NODE_CONFIG_QUERY_PATH = 23 "$FAKE_ACTIVITY_NODE_CONFIG_QUERY_BASE_PATH/*" 24 25 /** The relative path of the content provider for inserting fake activity node configs. */ 26 internal const val FAKE_ACTIVITY_NODE_CONFIG_INSERT_PATH = "fake_activity_node_config" 27 28 /** The projection/ column name representing one single allowed node in a test. */ 29 const val TEST_NODE_CLASS_COLUMN = "allowed_node" 30 31 /** 32 * Returns the base content provider [Uri]. Eg: content://authority 33 * 34 * @param authority the content provider authority to use for constructing Uri 35 * @return the base content provider path. 36 */ getBaseContentUrinull37 fun getBaseContentUri(authority: String): Uri = 38 Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(authority).build() 39 40 /** 41 * Returns the uri for all the test configuration Eg: content://authority/test_config 42 * 43 * @param authority the content provider authority to use for constructing Uri 44 */ 45 fun getTestConfigUri(authority: String): Uri = 46 getBaseContentUri(authority).buildUpon().path(TEST_CONFIG_PATH).build() 47 48 /** 49 * Returns the uri for all the test configuration Eg: content://authority/test_config 50 * 51 * @param context context of the application being executed 52 */ 53 fun getTestConfigUri(context: Context): Uri = getTestConfigUri(getAuthority(context.packageName)) 54 55 /** 56 * Returns the uri for fetching the fake activity node configs for node identified by 57 * [contractIdentifier]. 58 */ 59 fun getFakeActivityNodeConfigQueryUri(context: Context, contractIdentifier: String): Uri = 60 getBaseContentUri(getAuthority(context.packageName)) 61 .buildUpon() 62 .path(FAKE_ACTIVITY_NODE_CONFIG_QUERY_BASE_PATH) 63 .appendPath(contractIdentifier) 64 .build() 65 66 /** 67 * Returns the uri for inserting the fake activity node config. This will be stored using the 68 * content provider of the app with given [packageName]. 69 */ 70 fun getFakeActivityNodeConfigInsertionUri(packageName: String): Uri = 71 getBaseContentUri(getAuthority(packageName)) 72 .buildUpon() 73 .path(FAKE_ACTIVITY_NODE_CONFIG_INSERT_PATH) 74 .build() 75 76 // LINT.IfChange(authority) 77 /** 78 * Given app package name it returns content provider authority for a given package 79 * 80 * @param packageName the app package name 81 * @return the content provider authority for a given package 82 */ 83 fun getAuthority(packageName: String): String = "$packageName.testprovider" 84 // LINT.ThenChange(java/com/android/onboarding/bedsteadonboarding/AndroidManifest.xml:authority) 85 } 86