Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d7d1487e authored by Ben Lin's avatar Ben Lin
Browse files

Docsui-level work for implementing Eject on Roots list.

1. Added Eject Icon for Roots that support eject
2. Added Context Menu for RootsFragment (Settings and Eject)

Bug: 29584653
Change-Id: I97f582de05763e3f0327bc0d2dc6d4e2222e047c
(cherry picked from commit d96661f8b0f613b40f2bdfc178bbe06022b5f76c)
parent ae76412b
Loading
Loading
Loading
Loading
+17 −13
Original line number Diff line number Diff line
@@ -730,6 +730,23 @@ public abstract class DocumentsProvider extends ContentProvider {
            throws FileNotFoundException {

        final Context context = getContext();
        final Bundle out = new Bundle();

        if (METHOD_EJECT_ROOT.equals(method)) {
            // Given that certain system apps can hold MOUNT_UNMOUNT permission, but only apps
            // signed with platform signature can hold MANAGE_DOCUMENTS, we are going to check for
            // MANAGE_DOCUMENTS here instead
            getContext().enforceCallingPermission(
                    android.Manifest.permission.MANAGE_DOCUMENTS, null);
            final Uri rootUri = extras.getParcelable(DocumentsContract.EXTRA_URI);
            final String rootId = DocumentsContract.getRootId(rootUri);
            final boolean ejected = ejectRoot(rootId);

            out.putBoolean(DocumentsContract.EXTRA_RESULT, ejected);

            return out;
        }

        final Uri documentUri = extras.getParcelable(DocumentsContract.EXTRA_URI);
        final String authority = documentUri.getAuthority();
        final String documentId = DocumentsContract.getDocumentId(documentUri);
@@ -739,8 +756,6 @@ public abstract class DocumentsProvider extends ContentProvider {
                    "Requested authority " + authority + " doesn't match provider " + mAuthority);
        }

        final Bundle out = new Bundle();

        // If the URI is a tree URI performs some validation.
        enforceTree(documentUri);

@@ -858,17 +873,6 @@ public abstract class DocumentsProvider extends ContentProvider {

            // It's responsibility of the provider to revoke any grants, as the document may be
            // still attached to another parents.
        } else if (METHOD_EJECT_ROOT.equals(method)) {
            // Given that certain system apps can hold MOUNT_UNMOUNT permission, but only apps
            // signed with platform signature can hold MANAGE_DOCUMENTS, we are going to check for
            // MANAGE_DOCUMENTS here instead
            getContext().enforceCallingPermission(
                    android.Manifest.permission.MANAGE_DOCUMENTS, null);
            final Uri rootUri = extras.getParcelable(DocumentsContract.EXTRA_URI);
            final String rootId = DocumentsContract.getRootId(rootUri);
            final boolean ejected = ejectRoot(rootId);

            out.putBoolean(DocumentsContract.EXTRA_RESULT, ejected);
        } else {
            throw new UnsupportedOperationException("Method not supported " + method);
        }
+20 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:alpha="@*android:dimen/disabled_alpha_material_light" android:color="@*android:color/primary_text_default_material_light" />
    <item android:color="@*android:color/primary_text_default_material_light" />
</selector>
+24 −0
Original line number Diff line number Diff line
<!--
Copyright (C) 2016 The Android Open Source Project

   Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FF737373"
        android:pathData="M5 17h14v2H5zm7-12L5.33 15h13.34z"/>
</vector>
+17 −1
Original line number Diff line number Diff line
@@ -46,7 +46,8 @@
        android:layout_height="wrap_content"
        android:paddingTop="8dp"
        android:paddingBottom="8dp"
        android:orientation="vertical">
        android:orientation="vertical"
        android:layout_weight="1">

        <TextView
            android:id="@android:id/title"
@@ -70,4 +71,19 @@

    </LinearLayout>

     <FrameLayout
        android:layout_width="@dimen/icon_size"
        android:layout_height="@dimen/icon_size"
        android:duplicateParentState="true">

        <ImageView
            android:id="@+id/unmount_icon"
            android:layout_width="@dimen/root_icon_size"
            android:layout_height="match_parent"
            android:scaleType="centerInside"
            android:contentDescription="@string/menu_eject_root"
            android:visibility="gone" />

    </FrameLayout>

</com.android.documentsui.RootItemView>
+24 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/menu_eject_root"
        android:title="@string/menu_eject_root" />
    <item
        android:id="@+id/menu_settings"
        android:title="@string/menu_settings" />
</menu>
Loading