Let Cts Verifier get authority string at run time.

Change-Id: If9bcdfac244193f4e28f6108cf54d4918d3be2b1
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java b/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java
index 2c3d35d..8e4e63c 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java
@@ -328,8 +328,7 @@
         ContentResolver resolver = activity.getContentResolver();
         Cursor cursor = null;
         try {
-            cursor = resolver.query(
-                    TestResultsProvider.getTestNameUri(activity.getClass().getName()),
+            cursor = resolver.query(TestResultsProvider.getTestNameUri(activity),
                     new String[] {TestResultsProvider.COLUMN_TEST_INFO_SEEN}, null, null, null);
             return cursor.moveToFirst() && cursor.getInt(0) > 0;
         } finally {
@@ -392,10 +391,9 @@
         values.put(TestResultsProvider.COLUMN_TEST_NAME, activity.getClass().getName());
         values.put(TestResultsProvider.COLUMN_TEST_INFO_SEEN, 1);
         int numUpdated = resolver.update(
-                TestResultsProvider.getTestNameUri(activity.getClass().getName()),
-                values, null, null);
+                TestResultsProvider.getTestNameUri(activity), values, null, null);
         if (numUpdated == 0) {
-            resolver.insert(TestResultsProvider.RESULTS_CONTENT_URI, values);
+            resolver.insert(TestResultsProvider.getResultContentUri(activity), values);
         }
     }
 
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/TestListAdapter.java b/apps/CtsVerifier/src/com/android/cts/verifier/TestListAdapter.java
index ce092cc..642b951 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/TestListAdapter.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/TestListAdapter.java
@@ -163,7 +163,7 @@
 
         TestResultContentObserver observer = new TestResultContentObserver();
         ContentResolver resolver = context.getContentResolver();
-        resolver.registerContentObserver(TestResultsProvider.RESULTS_CONTENT_URI, true, observer);
+        resolver.registerContentObserver(TestResultsProvider.getResultContentUri(context), true, observer);
     }
 
     public void loadTestResults() {
@@ -236,7 +236,7 @@
         ContentResolver resolver = mContext.getContentResolver();
         Cursor cursor = null;
         try {
-            cursor = resolver.query(TestResultsProvider.RESULTS_CONTENT_URI, REFRESH_PROJECTION,
+            cursor = resolver.query(TestResultsProvider.getResultContentUri(mContext), REFRESH_PROJECTION,
                     null, null, null);
             if (cursor.moveToFirst()) {
                 do {
@@ -262,7 +262,7 @@
         @Override
         protected Void doInBackground(Void... params) {
             ContentResolver resolver = mContext.getContentResolver();
-            resolver.delete(TestResultsProvider.RESULTS_CONTENT_URI, "1", null);
+            resolver.delete(TestResultsProvider.getResultContentUri(mContext), "1", null);
             return null;
         }
     }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/TestResultsBackupHelper.java b/apps/CtsVerifier/src/com/android/cts/verifier/TestResultsBackupHelper.java
index 45e528f..2527d57 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/TestResultsBackupHelper.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/TestResultsBackupHelper.java
@@ -53,7 +53,7 @@
         ContentResolver resolver = mContext.getContentResolver();
         Cursor cursor = null;
         try {
-            cursor = resolver.query(TestResultsProvider.RESULTS_CONTENT_URI,
+            cursor = resolver.query(TestResultsProvider.getResultContentUri(mContext),
                     null, null, null, null);
             int nameIndex = cursor.getColumnIndex(TestResultsProvider.COLUMN_TEST_NAME);
             int resultIndex = cursor.getColumnIndex(TestResultsProvider.COLUMN_TEST_RESULT);
@@ -128,7 +128,7 @@
                 }
 
                 ContentResolver resolver = mContext.getContentResolver();
-                resolver.bulkInsert(TestResultsProvider.RESULTS_CONTENT_URI, values);
+                resolver.bulkInsert(TestResultsProvider.getResultContentUri(mContext), values);
             } else {
                 Log.e(TAG, "Skipping key: " + data.getKey());
             }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/TestResultsProvider.java b/apps/CtsVerifier/src/com/android/cts/verifier/TestResultsProvider.java
index a9f672e..64c04eb 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/TestResultsProvider.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/TestResultsProvider.java
@@ -39,13 +39,26 @@
 
     private static final String RESULTS_PATH = "results";
 
-    public static final String AUTHORITY = "com.android.cts.verifier.testresultsprovider";
-    public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY);
-    public static final Uri RESULTS_CONTENT_URI =
-            Uri.withAppendedPath(CONTENT_URI, RESULTS_PATH);
+    /**
+     * Get the URI from the result content.
+     * @param context
+     * @return Uri
+     */
+    public static Uri getResultContentUri(Context context) {
+        final String packageName = context.getPackageName();
+        final Uri contentUri = Uri.parse("content://" + packageName + ".testresultsprovider");
+        return Uri.withAppendedPath(contentUri, RESULTS_PATH);
+    }
 
-    public static Uri getTestNameUri(String testName) {
-        return Uri.withAppendedPath(RESULTS_CONTENT_URI, testName);
+    /**
+     * Get the URI from the test name.
+     * @param context
+     * @param testName
+     * @return Uri
+     */
+    public static Uri getTestNameUri(Context context) {
+        final String testName = context.getClass().getName();
+        return Uri.withAppendedPath(getResultContentUri(context), testName);
     }
 
     static final String _ID = "_id";
@@ -69,11 +82,6 @@
     private static final int RESULTS_ALL = 1;
     private static final int RESULTS_ID = 2;
     private static final int RESULTS_TEST_NAME = 3;
-    static {
-        URI_MATCHER.addURI(AUTHORITY, RESULTS_PATH, RESULTS_ALL);
-        URI_MATCHER.addURI(AUTHORITY, RESULTS_PATH + "/#", RESULTS_ID);
-        URI_MATCHER.addURI(AUTHORITY, RESULTS_PATH + "/*", RESULTS_TEST_NAME);
-    }
 
     private static final String TABLE_NAME = "results";
 
@@ -83,6 +91,12 @@
 
     @Override
     public boolean onCreate() {
+        final String authority = getContext().getPackageName() + ".testresultsprovider";
+
+        URI_MATCHER.addURI(authority, RESULTS_PATH, RESULTS_ALL);
+        URI_MATCHER.addURI(authority, RESULTS_PATH + "/#", RESULTS_ID);
+        URI_MATCHER.addURI(authority, RESULTS_PATH + "/*", RESULTS_TEST_NAME);
+
         mOpenHelper = new TestResultsOpenHelper(getContext());
         mBackupManager = new BackupManager(getContext());
         return false;
@@ -153,7 +167,7 @@
         long id = db.insert(TABLE_NAME, null, values);
         getContext().getContentResolver().notifyChange(uri, null);
         mBackupManager.dataChanged();
-        return Uri.withAppendedPath(RESULTS_CONTENT_URI, "" + id);
+        return Uri.withAppendedPath(getResultContentUri(getContext()), "" + id);
     }
 
     @Override
@@ -219,13 +233,14 @@
         values.put(TestResultsProvider.COLUMN_TEST_DETAILS, testDetails);
         values.put(TestResultsProvider.COLUMN_TEST_METRICS, serialize(reportLog));
 
+        final Uri uri = getResultContentUri(context);
         ContentResolver resolver = context.getContentResolver();
-        int numUpdated = resolver.update(TestResultsProvider.RESULTS_CONTENT_URI, values,
+        int numUpdated = resolver.update(uri, values,
                 TestResultsProvider.COLUMN_TEST_NAME + " = ?",
                 new String[] {testName});
 
         if (numUpdated == 0) {
-            resolver.insert(TestResultsProvider.RESULTS_CONTENT_URI, values);
+            resolver.insert(uri, values);
         }
     }