Use ROOT locale while using String.format

Test: atest StableUrisTest
Bug: 235632329
Change-Id: I02530fc3c1919ce05afd336189560e0aa5a25ccf
diff --git a/src/com/android/providers/media/DatabaseHelper.java b/src/com/android/providers/media/DatabaseHelper.java
index a5c2511..e4700b0 100644
--- a/src/com/android/providers/media/DatabaseHelper.java
+++ b/src/com/android/providers/media/DatabaseHelper.java
@@ -87,6 +87,7 @@
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Locale;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
@@ -499,30 +500,29 @@
 
     @Override
     public void onDowngrade(final SQLiteDatabase db, final int oldV, final int newV) {
-        Log.w(TAG,
-                String.format(
-                        "onDowngrade() for %s from %s to %s. Deleting database:%s in case of a "
-                                + "downgrade.",
-                        mName, oldV, newV, mName));
+        Log.w(TAG, String.format(Locale.ROOT,
+                "onDowngrade() for %s from %s to %s. Deleting database:%s in case of a "
+                        + "downgrade.", mName, oldV, newV, mName));
         deleteDatabaseFiles();
         throw new IllegalStateException(
-                String.format("Crashing MP process on database downgrade of %s.", mName));
+                String.format(Locale.ROOT, "Crashing MP process on database downgrade of %s.",
+                        mName));
     }
 
     private void deleteDatabaseFiles() {
         File dbDir = mContext.getDatabasePath(mName).getParentFile();
         File[] files = dbDir.listFiles();
         if (files == null) {
-            Log.w(TAG,
-                    String.format("No database files found on path:%s.", dbDir.getAbsolutePath()));
+            Log.w(TAG, String.format(Locale.ROOT, "No database files found on path:%s.",
+                    dbDir.getAbsolutePath()));
             return;
         }
 
         for (File file : files) {
             if (file.getName().startsWith(mName)) {
                 file.delete();
-                Log.w(TAG,
-                        String.format("Database file:%s deleted.", file.getAbsolutePath()));
+                Log.w(TAG, String.format(Locale.ROOT, "Database file:%s deleted.",
+                        file.getAbsolutePath()));
             }
         }
     }
@@ -547,17 +547,17 @@
             boolean isLastUsedDatabaseSession = isLastUsedDatabaseSession(db);
             Optional<Long> nextRowIdFromXattrOptional = getNextRowIdFromXattr();
             if (isLastUsedDatabaseSession && nextRowIdFromXattrOptional.isPresent()) {
-                Log.i(TAG, String.format("No database change across sequential open calls for %s.",
-                        mName));
+                Log.i(TAG, String.format(Locale.ROOT,
+                        "No database change across sequential open calls for %s.", mName));
                 mNextRowIdBackup.set(nextRowIdFromXattrOptional.get());
                 updateSessionIdInDatabaseAndExternalStorage(db);
                 return;
             }
 
-            Log.w(TAG, String.format(
+            Log.w(TAG, String.format(Locale.ROOT,
                     "%s database inconsistent: isLastUsedDatabaseSession:%b, "
-                            + "nextRowIdOptionalPresent:%b",
-                    mName, isLastUsedDatabaseSession, nextRowIdFromXattrOptional.isPresent()));
+                            + "nextRowIdOptionalPresent:%b", mName, isLastUsedDatabaseSession,
+                    nextRowIdFromXattrOptional.isPresent()));
             // TODO(b/222313219): Add an assert to ensure that next row id xattr is always
             // present when DB session id matches across sequential open calls.
             updateNextRowIdInDatabaseAndExternalStorage(db);
@@ -585,8 +585,8 @@
         boolean setOnExternalStorage = setXattr(DATA_MEDIA_XATTR_DIRECTORY_PATH,
                 getSessionIdXattrKeyForDatabase(), uuid);
         if (setOnDatabase && setOnExternalStorage) {
-            Log.i(TAG, String.format("SessionId set to %s on paths %s and %s.", uuid, db.getPath(),
-                    DATA_MEDIA_XATTR_DIRECTORY_PATH));
+            Log.i(TAG, String.format(Locale.ROOT, "SessionId set to %s on paths %s and %s.", uuid,
+                    db.getPath(), DATA_MEDIA_XATTR_DIRECTORY_PATH));
         }
     }
 
@@ -1809,7 +1809,8 @@
     }
 
     private void updateUserId(SQLiteDatabase db) {
-        db.execSQL(String.format("ALTER TABLE files ADD COLUMN _user_id INTEGER DEFAULT %d;",
+        db.execSQL(String.format(Locale.ROOT,
+                "ALTER TABLE files ADD COLUMN _user_id INTEGER DEFAULT %d;",
                 UserHandle.myUserId()));
     }
 
@@ -2271,10 +2272,10 @@
 
         backupNextRowId(nextRowId);
         // Insert and delete a row to update sqlite_sequence counter
-        db.execSQL(String.format("INSERT INTO files(_ID) VALUES (%d)", nextRowId));
-        db.execSQL(String.format("DELETE FROM files WHERE _ID=%d", nextRowId));
-        Log.i(TAG, String.format("Updated sqlite counter of Files table of %s to %d.", mName,
-                nextRowId));
+        db.execSQL(String.format(Locale.ROOT, "INSERT INTO files(_ID) VALUES (%d)", nextRowId));
+        db.execSQL(String.format(Locale.ROOT, "DELETE FROM files WHERE _ID=%d", nextRowId));
+        Log.i(TAG, String.format(Locale.ROOT, "Updated sqlite counter of Files table of %s to %d.",
+                mName, nextRowId));
     }
 
     /**
@@ -2288,8 +2289,8 @@
                 String.valueOf(backupId));
         if (setOnExternalStorage) {
             mNextRowIdBackup.set(backupId);
-            Log.i(TAG, String.format("Backed up next row id as:%d on path:%s for %s.", backupId,
-                    DATA_MEDIA_XATTR_DIRECTORY_PATH, mName));
+            Log.i(TAG, String.format(Locale.ROOT, "Backed up next row id as:%d on path:%s for %s.",
+                    backupId, DATA_MEDIA_XATTR_DIRECTORY_PATH, mName));
         }
     }
 
@@ -2299,7 +2300,7 @@
                     Os.getxattr(DATA_MEDIA_XATTR_DIRECTORY_PATH,
                             getNextRowIdXattrKeyForDatabase()))));
         } catch (Exception e) {
-            Log.e(TAG, String.format("Xattr:%s not found on external storage.",
+            Log.e(TAG, String.format(Locale.ROOT, "Xattr:%s not found on external storage.",
                     getNextRowIdXattrKeyForDatabase()), e);
             return Optional.empty();
         }
@@ -2312,7 +2313,8 @@
             return EXTERNAL_DB_NEXT_ROW_ID_XATTR_KEY;
         }
         throw new RuntimeException(
-                String.format("Next row id xattr key not defined for database:%s.", mName));
+                String.format(Locale.ROOT, "Next row id xattr key not defined for database:%s.",
+                        mName));
     }
 
     protected String getSessionIdXattrKeyForDatabase() {
@@ -2322,7 +2324,8 @@
             return EXTERNAL_DB_SESSION_ID_XATTR_KEY;
         }
         throw new RuntimeException(
-                String.format("Session id xattr key not defined for database:%s.", mName));
+                String.format(Locale.ROOT, "Session id xattr key not defined for database:%s.",
+                        mName));
     }
 
     protected static boolean setXattr(String path, String key, String value) {
@@ -2334,9 +2337,8 @@
             Log.d(TAG, String.format("xattr set to %s for key:%s on path: %s.", value, key, path));
             return true;
         } catch (Exception e) {
-            Log.e(TAG,
-                    String.format("Failed to set xattr:%s to %s for path: %s.", key, value, path),
-                    e);
+            Log.e(TAG, String.format(Locale.ROOT, "Failed to set xattr:%s to %s for path: %s.", key,
+                    value, path), e);
             return false;
         }
     }
@@ -2345,9 +2347,8 @@
         try {
             return Optional.of(Arrays.toString(Os.getxattr(path, key)));
         } catch (Exception e) {
-            Log.w(TAG,
-                    String.format("Exception encountered while reading xattr:%s from path:%s.", key,
-                            path));
+            Log.w(TAG, String.format(Locale.ROOT,
+                    "Exception encountered while reading xattr:%s from path:%s.", key, path));
             return Optional.empty();
         }
     }
@@ -2380,7 +2381,8 @@
         }
 
         if (!(new File(DATA_MEDIA_XATTR_DIRECTORY_PATH)).exists()) {
-            Log.w(TAG, String.format("Skipping row id recovery as path:%s does not exist.",
+            Log.w(TAG, String.format(Locale.ROOT,
+                    "Skipping row id recovery as path:%s does not exist.",
                     DATA_MEDIA_XATTR_DIRECTORY_PATH));
             return false;
         }
diff --git a/src/com/android/providers/media/MediaProvider.java b/src/com/android/providers/media/MediaProvider.java
index 3305fa6..680cde0 100644
--- a/src/com/android/providers/media/MediaProvider.java
+++ b/src/com/android/providers/media/MediaProvider.java
@@ -848,15 +848,16 @@
 
         Optional<Long> nextRowIdBackupOptional = helper.getNextRowId();
         if (!nextRowIdBackupOptional.isPresent()) {
-            throw new RuntimeException(String.format("Cannot find next row id xattr for %s.",
-                    helper.getDatabaseName()));
+            throw new RuntimeException(
+                    String.format(Locale.ROOT, "Cannot find next row id xattr for %s.",
+                            helper.getDatabaseName()));
         }
 
         if (id >= nextRowIdBackupOptional.get()) {
             helper.backupNextRowId(id);
         } else {
-            Log.v(TAG, String.format("Inserted id:%d less than next row id backup:%d.", id,
-                    nextRowIdBackupOptional.get()));
+            Log.v(TAG, String.format(Locale.ROOT, "Inserted id:%d less than next row id backup:%d.",
+                    id, nextRowIdBackupOptional.get()));
         }
     }