diff options
9 files changed, 53 insertions, 23 deletions
diff --git a/packages/DocumentsUI/res/menu/activity.xml b/packages/DocumentsUI/res/menu/activity.xml index 95c6f1f357dd..85e7a7ae004c 100644 --- a/packages/DocumentsUI/res/menu/activity.xml +++ b/packages/DocumentsUI/res/menu/activity.xml @@ -86,6 +86,10 @@ android:showAsAction="never" android:visible="false" /> <item + android:id="@+id/menu_advanced" + android:showAsAction="never" + android:visible="false" /> + <item android:id="@+id/menu_settings" android:title="@string/menu_settings" android:showAsAction="never" diff --git a/packages/DocumentsUI/res/values/config.xml b/packages/DocumentsUI/res/values/config.xml index 765211d70fa8..6590bbeda892 100644 --- a/packages/DocumentsUI/res/values/config.xml +++ b/packages/DocumentsUI/res/values/config.xml @@ -24,8 +24,9 @@ <!-- Indicates if the home directory should be hidden in the roots list, that is presented in the drawer/left side panel ) --> <bool name="home_root_hidden">true</bool> - <!-- Indicates if the advanced roots like internal storage should be hidden in the roots list) --> - <bool name="advanced_roots_hidden">true</bool> + <!-- Indicates if the advanced roots like internal storage should be shown in the roots list. + When enabled there is no menu option to toggle internal storage visibility. --> + <bool name="advanced_roots_shown">false</bool> <!-- Indicates if search view is taking the whole toolbar space --> <bool name="full_bar_search_view">true</bool> </resources> diff --git a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java index 69315f7b84eb..2d051e467ec3 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java +++ b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java @@ -18,6 +18,11 @@ package com.android.documentsui; import static com.android.documentsui.Shared.DEBUG; import static com.android.documentsui.Shared.EXTRA_BENCHMARK; +import static com.android.documentsui.State.ACTION_CREATE; +import static com.android.documentsui.State.ACTION_OPEN; +import static com.android.documentsui.State.ACTION_OPEN_TREE; +import static com.android.documentsui.State.ACTION_GET_CONTENT; +import static com.android.documentsui.State.ACTION_PICK_COPY_DESTINATION; import static com.android.documentsui.State.MODE_GRID; import android.app.Activity; @@ -165,6 +170,7 @@ public abstract class BaseActivity extends Activity final MenuItem sortSize = menu.findItem(R.id.menu_sort_size); final MenuItem grid = menu.findItem(R.id.menu_grid); final MenuItem list = menu.findItem(R.id.menu_list); + final MenuItem advanced = menu.findItem(R.id.menu_advanced); final MenuItem fileSize = menu.findItem(R.id.menu_file_size); // Search uses backend ranking; no sorting, recents doesn't support sort. @@ -176,6 +182,9 @@ public abstract class BaseActivity extends Activity grid.setVisible(mState.derivedMode != State.MODE_GRID); list.setVisible(mState.derivedMode != State.MODE_LIST); + advanced.setVisible(mState.showAdvancedOption); + advanced.setTitle(mState.showAdvancedOption && mState.showAdvanced + ? R.string.menu_advanced_hide : R.string.menu_advanced_show); fileSize.setTitle(LocalPreferences.getDisplayFileSize(this) ? R.string.menu_file_size_hide : R.string.menu_file_size_show); @@ -195,25 +204,30 @@ public abstract class BaseActivity extends Activity return state; } - State state = createSharedState(); - includeState(state); - if (DEBUG) Log.d(mTag, "Created new state object: " + state); - return state; - } - - private State createSharedState() { State state = new State(); final Intent intent = getIntent(); state.localOnly = intent.getBooleanExtra(Intent.EXTRA_LOCAL_ONLY, false); - state.forceSize = intent.getBooleanExtra(DocumentsContract.EXTRA_SHOW_FILESIZE, false); state.showSize = state.forceSize || LocalPreferences.getDisplayFileSize(this); - state.initAcceptMimes(intent); state.excludedAuthorities = getExcludedAuthorities(); + includeState(state); + + // Advanced roots are shown by deafult without menu option if forced by config or intent. + state.showAdvanced = getResources().getBoolean(R.bool.advanced_roots_shown) + || intent.getBooleanExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, false); + // Menu option is shown for whitelisted intents if advanced roots are not shown by default. + state.showAdvancedOption = !state.showAdvanced && + (state.action == ACTION_OPEN || + state.action == ACTION_CREATE || + state.action == ACTION_OPEN_TREE || + state.action == ACTION_GET_CONTENT); + + if (DEBUG) Log.d(mTag, "Created new state object: " + state); + return state; } @@ -287,6 +301,10 @@ public abstract class BaseActivity extends Activity } return true; + case R.id.menu_advanced: + setDisplayAdvancedDevices(!mState.showAdvanced); + return true; + case R.id.menu_file_size: setDisplayFileSize(!LocalPreferences.getDisplayFileSize(this)); return true; @@ -452,6 +470,12 @@ public abstract class BaseActivity extends Activity ? DocumentsContract.buildRootUri("com.android.providers.downloads.documents", "downloads") : DocumentsContract.buildHomeUri(); + } + + void setDisplayAdvancedDevices(boolean display) { + mState.showAdvanced = display; + RootsFragment.get(getFragmentManager()).onDisplayStateChanged(); + invalidateOptionsMenu(); } void setDisplayFileSize(boolean display) { diff --git a/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java b/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java index 6efe9c8fae83..f789dd679d38 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java +++ b/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java @@ -493,6 +493,11 @@ public class RootsCache { continue; } + if (!state.showAdvanced && root.isAdvanced()) { + if (DEBUG) Log.d(TAG, "Excluding root because: unwanted advanced device."); + continue; + } + if (state.localOnly && !root.isLocalOnly()) { if (DEBUG) Log.d(TAG, "Excluding root because: unwanted non-local device."); continue; diff --git a/packages/DocumentsUI/src/com/android/documentsui/RootsFragment.java b/packages/DocumentsUI/src/com/android/documentsui/RootsFragment.java index 8b4f40ef38be..5f665c0e4dd5 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/RootsFragment.java +++ b/packages/DocumentsUI/src/com/android/documentsui/RootsFragment.java @@ -321,9 +321,6 @@ public class RootsFragment extends Fragment { if (root.isHome() && Shared.isHomeRootHidden(context)) { continue; - } else if (root.isAdvanced() - && Shared.areAdvancedRootsHidden(context, state)) { - continue; } else if (root.isLibrary()) { if (DEBUG) Log.d(TAG, "Adding " + root + " as library."); libraries.add(item); diff --git a/packages/DocumentsUI/src/com/android/documentsui/Shared.java b/packages/DocumentsUI/src/com/android/documentsui/Shared.java index 655359a70c24..2c60d4a3212f 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/Shared.java +++ b/packages/DocumentsUI/src/com/android/documentsui/Shared.java @@ -181,12 +181,4 @@ public final class Shared { return context.getResources().getBoolean(R.bool.home_root_hidden); } - /* - * Indicates if the advanced roots should be hidden. - */ - public static boolean areAdvancedRootsHidden(Context context, State state) { - return context.getResources().getBoolean(R.bool.advanced_roots_hidden) - && state.action != ACTION_OPEN_TREE; - } - } diff --git a/packages/DocumentsUI/src/com/android/documentsui/State.java b/packages/DocumentsUI/src/com/android/documentsui/State.java index 534a483474d3..c7d60e3d1133 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/State.java +++ b/packages/DocumentsUI/src/com/android/documentsui/State.java @@ -93,6 +93,8 @@ public class State implements android.os.Parcelable { public boolean forceSize; public boolean showSize; public boolean localOnly; + public boolean showAdvancedOption; + public boolean showAdvanced; public boolean restored; /* * Indicates handler was an external app, like photos. @@ -194,6 +196,8 @@ public class State implements android.os.Parcelable { out.writeInt(forceSize ? 1 : 0); out.writeInt(showSize ? 1 : 0); out.writeInt(localOnly ? 1 : 0); + out.writeInt(showAdvancedOption ? 1 : 0); + out.writeInt(showAdvanced ? 1 : 0); out.writeInt(restored ? 1 : 0); out.writeInt(external ? 1 : 0); DurableUtils.writeToParcel(out, stack); @@ -223,6 +227,8 @@ public class State implements android.os.Parcelable { state.forceSize = in.readInt() != 0; state.showSize = in.readInt() != 0; state.localOnly = in.readInt() != 0; + state.showAdvancedOption = in.readInt() != 0; + state.showAdvanced = in.readInt() != 0; state.restored = in.readInt() != 0; state.external = in.readInt() != 0; DurableUtils.readFromParcel(in, state.stack); diff --git a/packages/DocumentsUI/tests/src/com/android/documentsui/RootsCacheTest.java b/packages/DocumentsUI/tests/src/com/android/documentsui/RootsCacheTest.java index e73dd8cdfec2..2e81545e8e54 100644 --- a/packages/DocumentsUI/tests/src/com/android/documentsui/RootsCacheTest.java +++ b/packages/DocumentsUI/tests/src/com/android/documentsui/RootsCacheTest.java @@ -55,6 +55,7 @@ public class RootsCacheTest extends AndroidTestCase { mState = new State(); mState.action = State.ACTION_OPEN; + mState.showAdvanced = true; mState.localOnly = false; } diff --git a/packages/Shell/src/com/android/shell/BugreportStorageProvider.java b/packages/Shell/src/com/android/shell/BugreportStorageProvider.java index 49759c5f6ee1..814aa8cb8c06 100644 --- a/packages/Shell/src/com/android/shell/BugreportStorageProvider.java +++ b/packages/Shell/src/com/android/shell/BugreportStorageProvider.java @@ -56,7 +56,7 @@ public class BugreportStorageProvider extends DocumentsProvider { final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection)); final RowBuilder row = result.newRow(); row.add(Root.COLUMN_ROOT_ID, DOC_ID_ROOT); - row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY); + row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED); row.add(Root.COLUMN_ICON, android.R.mipmap.sym_def_app_icon); row.add(Root.COLUMN_TITLE, getContext().getString(R.string.bugreport_storage_title)); row.add(Root.COLUMN_DOCUMENT_ID, DOC_ID_ROOT); |