summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-07-15 00:05:19 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-07-15 00:05:19 +0000
commit4d6ff18d933dc32c7d9613a04b448d43a61a6a24 (patch)
treec2f876e790df9f3bf1faa6a1355bd5a516649c11
parente0297ce1af405adb83121d3dad98488b52812f25 (diff)
parent96e6a679e90fb08a4698b4ab07f2b61a70bf76f0 (diff)
downloadMtp-4d6ff18d933dc32c7d9613a04b448d43a61a6a24.tar.gz
Change-Id: I7c688b277e4a5802c9e03ed09def3e4620f667d9
-rw-r--r--Android.bp4
-rw-r--r--AndroidManifest.xml76
-rw-r--r--perf_tests/Android.bp14
-rw-r--r--perf_tests/Android.mk13
-rw-r--r--perf_tests/AndroidTest.xml4
-rw-r--r--src/com/android/mtp/MtpManager.java28
-rw-r--r--src/com/android/mtp/MtpService.java8
-rw-r--r--tests/Android.bp18
-rw-r--r--tests/Android.mk14
-rw-r--r--tests/AndroidManifest.xml20
-rw-r--r--tests/AndroidTest.xml6
11 files changed, 121 insertions, 84 deletions
diff --git a/Android.bp b/Android.bp
index b01f444..8b8d2d5 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,3 +1,7 @@
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
android_app {
name: "MtpService",
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index fc3b7cb..0647979 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1,65 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.mtp"
- android:sharedUserId="android.media">
- <uses-feature android:name="android.hardware.usb.host" />
- <uses-permission android:name="android.permission.ACCESS_MTP" />
+ package="com.android.mtp"
+ android:sharedUserId="android.media">
+ <uses-feature android:name="android.hardware.usb.host"/>
+ <uses-permission android:name="android.permission.ACCESS_MTP"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
- <uses-permission android:name="android.permission.MANAGE_USB" />
- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
- <uses-permission android:name="android.permission.MANAGE_USERS" />
- <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
- <uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" />
- <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.MANAGE_USB"/>
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
+ <uses-permission android:name="android.permission.MANAGE_USERS"/>
+ <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/>
+ <uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE"/>
+ <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
- <application
- android:process="android.process.media"
- android:label="@string/app_label"
- android:allowBackup="false"
- android:usesCleartextTraffic="true">
- <provider
- android:name=".MtpDocumentsProvider"
- android:authorities="com.android.mtp.documents"
- android:grantUriPermissions="true"
- android:exported="true"
- android:permission="android.permission.MANAGE_DOCUMENTS">
+ <application android:process="android.process.media"
+ android:label="@string/app_label"
+ android:allowBackup="false"
+ android:usesCleartextTraffic="true">
+ <provider android:name=".MtpDocumentsProvider"
+ android:authorities="com.android.mtp.documents"
+ android:grantUriPermissions="true"
+ android:exported="true"
+ android:permission="android.permission.MANAGE_DOCUMENTS">
<intent-filter>
- <action android:name="android.content.action.DOCUMENTS_PROVIDER" />
+ <action android:name="android.content.action.DOCUMENTS_PROVIDER"/>
</intent-filter>
</provider>
- <service android:name=".MtpDocumentsService" />
+ <service android:name=".MtpDocumentsService"/>
<activity android:name=".ReceiverActivity"
- android:label="@string/downloads_app_label"
- android:icon="@mipmap/ic_launcher_download"
- android:theme="@android:style/Theme.NoDisplay"
- android:excludeFromRecents="true">
+ android:label="@string/downloads_app_label"
+ android:icon="@mipmap/ic_launcher_download"
+ android:theme="@android:style/Theme.NoDisplay"
+ android:excludeFromRecents="true"
+ android:exported="true">
<intent-filter>
- <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
+ <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
- android:resource="@xml/device_filter" />
+ android:resource="@xml/device_filter"/>
</activity>
- <receiver android:name=".UsbIntentReceiver" android:exported="true">
+ <receiver android:name=".UsbIntentReceiver"
+ android:exported="true">
<intent-filter>
- <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
- <action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
+ <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
+ <action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED"/>
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
- android:resource="@xml/device_filter" />
+ android:resource="@xml/device_filter"/>
</receiver>
- <receiver android:name=".MtpReceiver">
+ <receiver android:name=".MtpReceiver"
+ android:exported="true">
<intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED" />
+ <action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
<intent-filter>
- <action android:name="android.hardware.usb.action.USB_STATE" />
+ <action android:name="android.hardware.usb.action.USB_STATE"/>
</intent-filter>
</receiver>
- <service android:name="MtpService" />
+ <service android:name="MtpService"/>
</application>
</manifest>
diff --git a/perf_tests/Android.bp b/perf_tests/Android.bp
new file mode 100644
index 0000000..a49949a
--- /dev/null
+++ b/perf_tests/Android.bp
@@ -0,0 +1,14 @@
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_test {
+ name: "MtpServicePerfTests",
+ srcs: ["src/**/*.java"],
+ static_libs: ["androidx.test.rules"],
+ platform_apis: true,
+ instrumentation_for: "MtpService",
+ certificate: "media",
+ test_suites: ["device-tests"],
+
+}
diff --git a/perf_tests/Android.mk b/perf_tests/Android.mk
deleted file mode 100644
index 9713cd4..0000000
--- a/perf_tests/Android.mk
+++ /dev/null
@@ -1,13 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-LOCAL_STATIC_JAVA_LIBRARIES := androidx.test.rules
-LOCAL_PACKAGE_NAME := MtpServicePerfTests
-LOCAL_PRIVATE_PLATFORM_APIS := true
-LOCAL_INSTRUMENTATION_FOR := MtpService
-LOCAL_CERTIFICATE := media
-LOCAL_COMPATIBILITY_SUITE += device-tests
-
-include $(BUILD_PACKAGE)
diff --git a/perf_tests/AndroidTest.xml b/perf_tests/AndroidTest.xml
index 8b7292b..8d1b349 100644
--- a/perf_tests/AndroidTest.xml
+++ b/perf_tests/AndroidTest.xml
@@ -13,12 +13,12 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<configuration description="Runs MtpDocumentsProviderPerfTests metric instrumentation.">
+<configuration description="Runs MtpServicePerfTests metric instrumentation.">
<option name="test-suite-tag" value="apct" />
<option name="test-suite-tag" value="apct-metric-instrumentation" />
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true" />
- <option name="test-file-name" value="MtpDocumentsProviderPerfTests.apk" />
+ <option name="test-file-name" value="MtpServicePerfTests.apk" />
</target_preparer>
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
diff --git a/src/com/android/mtp/MtpManager.java b/src/com/android/mtp/MtpManager.java
index a7de631..6b211e4 100644
--- a/src/com/android/mtp/MtpManager.java
+++ b/src/com/android/mtp/MtpManager.java
@@ -29,6 +29,7 @@ import android.mtp.MtpDeviceInfo;
import android.mtp.MtpEvent;
import android.mtp.MtpObjectInfo;
import android.mtp.MtpStorageInfo;
+import android.os.Build;
import android.os.CancellationSignal;
import android.os.ParcelFileDescriptor;
import android.util.Log;
@@ -108,6 +109,9 @@ class MtpManager {
"Not found MTP storages in the device.");
mDevices.put(deviceId, device);
+
+ setInitVersion(rawDevice);
+
return createDeviceRecord(rawDevice);
}
@@ -263,6 +267,28 @@ class MtpManager {
}
}
+ private void setInitVersion(UsbDevice device) {
+ final MtpDevice mtpDevice = mDevices.get(device.getDeviceId());
+ final boolean opened = mtpDevice != null;
+ final String name = device.getProductName();
+ int[] devicePropertySupported = null;
+
+ if (opened) {
+ final MtpDeviceInfo info = mtpDevice.getDeviceInfo();
+
+ if (info != null) {
+ devicePropertySupported = info.getDevicePropertySupported();
+
+ if (MtpDeviceRecord.isSupported(devicePropertySupported,
+ MtpConstants.DEVICE_PROPERTY_SESSION_INITIATOR_VERSION_INFO)) {
+ mtpDevice.setDevicePropertyInitVersion("Android/"
+ + Build.VERSION.RELEASE
+ + " Build/" + Build.VERSION.INCREMENTAL);
+ }
+ }
+ }
+ }
+
private MtpDeviceRecord createDeviceRecord(UsbDevice device) {
final MtpDevice mtpDevice = mDevices.get(device.getDeviceId());
final boolean opened = mtpDevice != null;
@@ -270,6 +296,8 @@ class MtpManager {
MtpRoot[] roots;
int[] operationsSupported = null;
int[] eventsSupported = null;
+ int[] devicePropertySupported = null;
+
if (opened) {
try {
roots = getRoots(device.getDeviceId());
diff --git a/src/com/android/mtp/MtpService.java b/src/com/android/mtp/MtpService.java
index 035c0f4..7301f4d 100644
--- a/src/com/android/mtp/MtpService.java
+++ b/src/com/android/mtp/MtpService.java
@@ -204,12 +204,8 @@ public class MtpService extends Service {
// Add currently mounted and enabled storages to the server
if (mUnlocked) {
- if (mPtpMode) {
- addStorage(primary);
- } else {
- for (StorageVolume v : mVolumeMap.values()) {
- addStorage(v);
- }
+ for (StorageVolume v : mVolumeMap.values()) {
+ addStorage(v);
}
}
server.start();
diff --git a/tests/Android.bp b/tests/Android.bp
new file mode 100644
index 0000000..1d96b6e
--- /dev/null
+++ b/tests/Android.bp
@@ -0,0 +1,18 @@
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_test {
+ name: "MtpServiceTests",
+ srcs: ["src/**/*.java"],
+ libs: [
+ "android.test.runner",
+ "android.test.base",
+ "android.test.mock",
+ ],
+ static_libs: ["junit"],
+ platform_apis: true,
+ instrumentation_for: "MtpService",
+ certificate: "media",
+ test_suites: ["device-tests"],
+}
diff --git a/tests/Android.mk b/tests/Android.mk
deleted file mode 100644
index af32953..0000000
--- a/tests/Android.mk
+++ /dev/null
@@ -1,14 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-LOCAL_JAVA_LIBRARIES := android.test.runner android.test.base android.test.mock
-LOCAL_STATIC_JAVA_LIBRARIES := junit
-LOCAL_PACKAGE_NAME := MtpServiceTests
-LOCAL_PRIVATE_PLATFORM_APIS := true
-LOCAL_INSTRUMENTATION_FOR := MtpService
-LOCAL_CERTIFICATE := media
-LOCAL_COMPATIBILITY_SUITE := device-tests
-
-include $(BUILD_PACKAGE)
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index e1307e9..a064e50 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -1,21 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.mtp.tests"
- android:sharedUserId="android.media">
+ package="com.android.mtp.tests"
+ android:sharedUserId="android.media">
<application>
- <uses-library android:name="android.test.runner" />
+ <uses-library android:name="android.test.runner"/>
<activity android:name="com.android.mtp.TestResultActivity"
- android:screenOrientation="locked"
- android:launchMode="singleInstance">
+ android:screenOrientation="locked"
+ android:launchMode="singleInstance"
+ android:exported="true">
<intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
<instrumentation android:name="com.android.mtp.TestResultInstrumentation"
- android:targetPackage="com.android.mtp"
- android:label="Tests for MtpDocumentsProvider with the UI for output." />
+ android:targetPackage="com.android.mtp"
+ android:label="Tests for MtpDocumentsProvider with the UI for output."/>
</manifest>
diff --git a/tests/AndroidTest.xml b/tests/AndroidTest.xml
index f84131c..83b287a 100644
--- a/tests/AndroidTest.xml
+++ b/tests/AndroidTest.xml
@@ -13,13 +13,13 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<configuration description="Runs Tests for MtpDocumentsProvider with the UI for output.">
+<configuration description="Runs Tests for MtpService with the UI for output.">
<target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup">
- <option name="test-file-name" value="MtpDocumentsProviderTests.apk" />
+ <option name="test-file-name" value="MtpServiceTests.apk" />
</target_preparer>
<option name="test-suite-tag" value="apct" />
- <option name="test-tag" value="MtpDocumentsProviderTests" />
+ <option name="test-tag" value="MtpServiceTests" />
<test class="com.android.tradefed.testtype.InstrumentationTest" >
<option name="package" value="com.android.mtp.tests" />
<option name="runner" value="com.android.mtp.TestResultInstrumentation" />