That fuck shit the fascists are using
at master 38 lines 1.4 kB view raw
1package androidx.documentfile.provider; 2 3import android.content.Context; 4import android.net.Uri; 5import android.provider.DocumentsContract; 6 7import org.signal.core.util.logging.Log; 8 9/** 10 * Located in androidx package as {@link TreeDocumentFile} is package protected. 11 */ 12public class DocumentFileHelper { 13 14 private static final String TAG = Log.tag(DocumentFileHelper.class); 15 16 /** 17 * System implementation swallows the exception and we are having problems with the rename. This inlines the 18 * same call and logs the exception. Note this implementation does not update the passed in document file like 19 * the system implementation. Do not use the provided document file after calling this method. 20 * 21 * @return true if rename successful 22 */ 23 public static boolean renameTo(Context context, DocumentFile documentFile, String displayName) { 24 if (documentFile instanceof TreeDocumentFile) { 25 Log.d(TAG, "Renaming document directly"); 26 try { 27 final Uri result = DocumentsContract.renameDocument(context.getContentResolver(), documentFile.getUri(), displayName); 28 return result != null; 29 } catch (Exception e) { 30 Log.w(TAG, "Unable to rename document file", e); 31 return false; 32 } 33 } else { 34 Log.d(TAG, "Letting OS rename document: " + documentFile.getClass().getSimpleName()); 35 return documentFile.renameTo(displayName); 36 } 37 } 38}