In Android 11 and higher versions, when using any kind of File Explorer, users may encounter the granting of read-write permissions to access folders. Subsequently, a user interaction prompt appears to select the intended folder by pressing the 'Use This Folder' button. However, when selecting the 'android/data' or 'android/obb' folder, the button turns gray, making it impossible to press. So why?, what happen?
This is related to the built-in Android DocumentUI, namely com.google.android.documentsui.apk or com.android.documentsui.apk or DocumentsUIGoogle.apk, and if looked onto Apps Manager its seen as File.
For instance, previously, the 'Use This Folder' option could still be used or pressed, but after a while of using the folder permission function, it suddenly becomes grayed out and impossible to select. This might be because the application has automatically updated. So check in Settings > App Manager in list of installed apps, look for 'File' and press to see if its updated. By uninstalling the update might resolve this kind of situation.
However, it's possible that in the future, Android will completely prohibit this action by default on the 'android/data' or 'android/obb' folder choices. But users might modify the application, so let's dig deeper.
When users use this method, they interact with the Intent#ACTION_OPEN_DOCUMENT_TREE.
So, when interacting with Android Intent#ACTION_OPEN_DOCUMENT_TREE, it is handled by com.android.documentsui.
When utilizing Intent#ACTION_OPEN_DOCUMENT_TREE, specific restrictions are applied to the selection of certain folders, such as 'android/data' and 'android/obb,' which often contain sensitive data or relate to application configurations. This is a method aims to enhance security and user experience.
In this application, there is a function inside the file PickFragment.java to make the button should be grayed out or not.
Code snippet as follows:
packages/apps/DocumentsUI/src/com/android/documentsui/picker/PickFragment.java private void updateView() { if (mPickTarget != null && ( mAction == State.ACTION_OPEN_TREE || mPickTarget.isCreateSupported())) { mContainer.setVisibility(View.VISIBLE); } else { mContainer.setVisibility(View.GONE); return; } switch (mAction) { case State.ACTION_OPEN_TREE: mPick.setText(getString(R.string.open_tree_button)); mPick.setWidth(Integer.MAX_VALUE); mCancel.setVisibility(View.GONE); mPick.setEnabled(!(mPickTarget.isBlockedFromTree() && mRestrictScopeStorage)); mPickOverlay.setVisibility( mPickTarget.isBlockedFromTree() && mRestrictScopeStorage ? View.VISIBLE : View.GONE); break; case State.ACTION_PICK_COPY_DESTINATION: int titleId; switch (mCopyOperationSubType) { case OPERATION_COPY: titleId = R.string.button_copy; break; case OPERATION_COMPRESS: titleId = R.string.button_compress; break; case OPERATION_EXTRACT: titleId = R.string.button_extract; break; case OPERATION_MOVE: titleId = R.string.button_move; break; default: throw new UnsupportedOperationException(); } mPick.setText(titleId); mCancel.setVisibility(View.VISIBLE); break; default: mContainer.setVisibility(View.GONE); return; } }
There is a code that says:
mPick.setEnabled(!(mPickTarget.isBlockedFromTree() && mRestrictScopeStorage));
From the above code snippet, we can infer that the folder is blocked or restricted. In the Smali code snippet, we can observe something like:
.method private updateView()V ... //Another Smali Code :goto_0 invoke-virtual {v0, v4}, Landroid/widget/Button;->setEnabled(Z)V ... //Another Smali Code .end method
So, it is possible to change its value to always enable, regardless of the previous boolean value, like:
.method private updateView()V ... //Another Smali Code :goto_0 const/4 v4, 0x1 invoke-virtual {v0, v4}, Landroid/widget/Button;->setEnabled(Z)V ... //Another Smali Code .end method
In this context, the code introduces the instruction 'const/4 v4, 0x1,' which sets the value to 1 (indicating enable). Subsequently, v4 is utilized in the 'invoke-virtual {v0, v4}' operation.
Conclusion:
Implementing folder restrictions in the Android DocumentsUI enhances the security of sensitive directories. Developers can adapt this approach to tailor folder access based on specific application requirements and security considerations.
Implementing folder restrictions in the Android DocumentsUI enhances the security of sensitive directories. Developers can adapt this approach to tailor folder access based on specific application requirements and security considerations.