diff options
Diffstat (limited to 'packages/ExternalStorageProvider')
10 files changed, 171 insertions, 20 deletions
diff --git a/packages/ExternalStorageProvider/Android.bp b/packages/ExternalStorageProvider/Android.bp new file mode 100644 index 000000000000..973fef3e666d --- /dev/null +++ b/packages/ExternalStorageProvider/Android.bp @@ -0,0 +1,19 @@ +android_app { + name: "ExternalStorageProvider", + + manifest: "AndroidManifest.xml", + + resource_dirs: [ + "res", + ], + + srcs: [ + "src/**/*.java", + ], + + platform_apis: true, + + certificate: "platform", + + privileged: true, +} diff --git a/packages/ExternalStorageProvider/Android.mk b/packages/ExternalStorageProvider/Android.mk deleted file mode 100644 index 9e99313cd03a..000000000000 --- a/packages/ExternalStorageProvider/Android.mk +++ /dev/null @@ -1,13 +0,0 @@ -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := optional - -LOCAL_SRC_FILES := $(call all-subdir-java-files) - -LOCAL_PACKAGE_NAME := ExternalStorageProvider -LOCAL_PRIVATE_PLATFORM_APIS := true -LOCAL_CERTIFICATE := platform -LOCAL_PRIVILEGED_MODULE := true - -include $(BUILD_PACKAGE) diff --git a/packages/ExternalStorageProvider/AndroidManifest.xml b/packages/ExternalStorageProvider/AndroidManifest.xml index 1072f95371a0..484dbccca9a8 100644 --- a/packages/ExternalStorageProvider/AndroidManifest.xml +++ b/packages/ExternalStorageProvider/AndroidManifest.xml @@ -17,6 +17,10 @@ <intent-filter> <action android:name="android.content.action.DOCUMENTS_PROVIDER" /> </intent-filter> + <!-- Stub that allows MediaProvider to make incoming calls --> + <path-permission + android:path="/media_internal" + android:permission="android.permission.WRITE_MEDIA_STORAGE" /> </provider> <receiver android:name=".MountReceiver"> diff --git a/packages/ExternalStorageProvider/res/values-mr/strings.xml b/packages/ExternalStorageProvider/res/values-mr/strings.xml index 2bf3000a9b52..79274404230f 100644 --- a/packages/ExternalStorageProvider/res/values-mr/strings.xml +++ b/packages/ExternalStorageProvider/res/values-mr/strings.xml @@ -17,7 +17,7 @@ <resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <string name="app_label" msgid="7123375275748530234">"बाह्य संचयन"</string> - <string name="storage_description" msgid="8541974407321172792">"स्थानिक संचय"</string> + <string name="storage_description" msgid="8541974407321172792">"स्थानिक स्टोरेज"</string> <string name="root_internal_storage" msgid="827844243068584127">"अंतर्गत स्टोरेज"</string> <string name="root_documents" msgid="4051252304075469250">"दस्तऐवज"</string> </resources> diff --git a/packages/ExternalStorageProvider/res/values-or/strings.xml b/packages/ExternalStorageProvider/res/values-or/strings.xml index 034d8a4ae5f7..5387dc7d7663 100644 --- a/packages/ExternalStorageProvider/res/values-or/strings.xml +++ b/packages/ExternalStorageProvider/res/values-or/strings.xml @@ -17,8 +17,7 @@ <resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <string name="app_label" msgid="7123375275748530234">"ଏକ୍ସଟର୍ନଲ୍ ଷ୍ଟୋରେଜ୍"</string> - <!-- no translation found for storage_description (8541974407321172792) --> - <skip /> + <string name="storage_description" msgid="8541974407321172792">"ଲୋକାଲ୍ ଷ୍ଟୋରେଜ୍"</string> <string name="root_internal_storage" msgid="827844243068584127">"ଇଣ୍ଟର୍ନଲ୍ ଷ୍ଟୋରେଜ୍"</string> <string name="root_documents" msgid="4051252304075469250">"ଡକ୍ୟୁମେଣ୍ଟ"</string> </resources> diff --git a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java index 4a9c35615131..4abcf73af109 100644 --- a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java +++ b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java @@ -37,6 +37,7 @@ import android.provider.DocumentsContract; import android.provider.DocumentsContract.Document; import android.provider.DocumentsContract.Path; import android.provider.DocumentsContract.Root; +import android.provider.MediaStore; import android.provider.Settings; import android.system.ErrnoException; import android.system.Os; @@ -145,6 +146,7 @@ public class ExternalStorageProvider extends FileSystemProvider { } } + @GuardedBy("mRootsLock") private void updateVolumesLocked() { mRoots.clear(); @@ -606,11 +608,16 @@ public class ExternalStorageProvider extends FileSystemProvider { } break; } - case "getDocumentId": { - final String path = arg; - final List<UriPermission> accessUriPermissions = - extras.getParcelableArrayList(AUTHORITY + ".extra.uriPermissions"); + case MediaStore.GET_DOCUMENT_URI_CALL: { + // All callers must go through MediaProvider + getContext().enforceCallingPermission( + android.Manifest.permission.WRITE_MEDIA_STORAGE, TAG); + + final Uri fileUri = extras.getParcelable(DocumentsContract.EXTRA_URI); + final List<UriPermission> accessUriPermissions = extras + .getParcelableArrayList(DocumentsContract.EXTRA_URI_PERMISSIONS); + final String path = fileUri.getPath(); try { final Bundle out = new Bundle(); final Uri uri = getDocumentUri(path, accessUriPermissions); @@ -619,7 +626,22 @@ public class ExternalStorageProvider extends FileSystemProvider { } catch (FileNotFoundException e) { throw new IllegalStateException("File in " + path + " is not found.", e); } + } + case MediaStore.GET_MEDIA_URI_CALL: { + // All callers must go through MediaProvider + getContext().enforceCallingPermission( + android.Manifest.permission.WRITE_MEDIA_STORAGE, TAG); + final Uri documentUri = extras.getParcelable(DocumentsContract.EXTRA_URI); + final String docId = DocumentsContract.getDocumentId(documentUri); + try { + final Bundle out = new Bundle(); + final Uri uri = Uri.fromFile(getFileForDocId(docId)); + out.putParcelable(DocumentsContract.EXTRA_URI, uri); + return out; + } catch (FileNotFoundException e) { + throw new IllegalStateException(e); + } } default: Log.w(TAG, "unknown method passed to call(): " + method); diff --git a/packages/ExternalStorageProvider/tests/Android.bp b/packages/ExternalStorageProvider/tests/Android.bp new file mode 100644 index 000000000000..83427d4ebf00 --- /dev/null +++ b/packages/ExternalStorageProvider/tests/Android.bp @@ -0,0 +1,25 @@ +android_test { + name: "ExternalStorageProviderTests", + + manifest: "AndroidManifest.xml", + + srcs: [ + "src/**/*.java", + ], + + libs: [ + "android.test.base", + "android.test.mock", + "android.test.runner", + ], + + static_libs: [ + "android-support-test", + "mockito-target", + "truth-prebuilt", + ], + + certificate: "platform", + + instrumentation_for: "ExternalStorageProvider", +} diff --git a/packages/ExternalStorageProvider/tests/AndroidManifest.xml b/packages/ExternalStorageProvider/tests/AndroidManifest.xml new file mode 100644 index 000000000000..58b6e86dfc77 --- /dev/null +++ b/packages/ExternalStorageProvider/tests/AndroidManifest.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.externalstorage.tests"> + + <application android:label="ExternalStorageProvider Tests"> + <uses-library android:name="android.test.runner" /> + </application> + + <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner" + android:targetPackage="com.android.externalstorage" + android:label="ExternalStorageProvider Tests" /> +</manifest> + diff --git a/packages/ExternalStorageProvider/tests/AndroidTest.xml b/packages/ExternalStorageProvider/tests/AndroidTest.xml new file mode 100644 index 000000000000..e5fa73f59836 --- /dev/null +++ b/packages/ExternalStorageProvider/tests/AndroidTest.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2018 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. +--> +<configuration description="Runs Tests for ExternalStorageProvider."> + <target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup"> + <option name="test-file-name" value="ExternalStorageProviderTests.apk" /> + </target_preparer> + + <option name="test-suite-tag" value="apct" /> + <option name="test-suite-tag" value="framework-base-presubmit" /> + <option name="test-tag" value="ExternalStorageProviderTests" /> + <test class="com.android.tradefed.testtype.AndroidJUnitTest" > + <option name="package" value="com.android.externalstorage.tests" /> + <option name="runner" value="android.support.test.runner.AndroidJUnitRunner" /> + <option name="hidden-api-checks" value="false"/> + </test> +</configuration> diff --git a/packages/ExternalStorageProvider/tests/src/com/android/externalstorage/ExternalStorageProviderTest.java b/packages/ExternalStorageProvider/tests/src/com/android/externalstorage/ExternalStorageProviderTest.java new file mode 100644 index 000000000000..a88b3e146ea1 --- /dev/null +++ b/packages/ExternalStorageProvider/tests/src/com/android/externalstorage/ExternalStorageProviderTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2018 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. + */ + +package com.android.externalstorage; + +import static com.android.externalstorage.ExternalStorageProvider.AUTHORITY; + +import static org.mockito.Mockito.atLeast; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; + +import android.content.pm.ProviderInfo; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +public class ExternalStorageProviderTest { + @Test + public void onCreate_shouldUpdateVolumes() throws Exception { + ExternalStorageProvider externalStorageProvider = new ExternalStorageProvider(); + ExternalStorageProvider spyProvider = spy(externalStorageProvider); + ProviderInfo providerInfo = new ProviderInfo(); + providerInfo.authority = AUTHORITY; + providerInfo.grantUriPermissions = true; + providerInfo.exported = true; + + InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() { + @Override + public void run() { + spyProvider.attachInfoForTesting( + InstrumentationRegistry.getTargetContext(), providerInfo); + } + }); + + verify(spyProvider, atLeast(1)).updateVolumes(); + } +} |