diff options
| author | 2024-01-10 04:50:18 +0000 | |
|---|---|---|
| committer | 2024-01-10 04:50:18 +0000 | |
| commit | 48ad4d4dffeac8c2590f11846e3c20c6b9b1f0de (patch) | |
| tree | 5aa25c923f217101af2c4e37f941073b0bdbf83c | |
| parent | e396926772a5b6266e5830d50959e40e09e22710 (diff) | |
| parent | a3d6b06102bc4d5f06cc59e8e9d3bff1343c4c52 (diff) | |
Merge "Add PermissionServicePerfTests" into main
6 files changed, 739 insertions, 0 deletions
diff --git a/apct-tests/perftests/permission/Android.bp b/apct-tests/perftests/permission/Android.bp new file mode 100644 index 000000000000..b80a6af612ec --- /dev/null +++ b/apct-tests/perftests/permission/Android.bp @@ -0,0 +1,87 @@ +// Copyright (C) 2024 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 { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "frameworks_base_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["frameworks_base_license"], +} + +android_test { + name: "PermissionServicePerfTests", + + srcs: [ + "src/**/*.java", + "src/**/*.kt", + ], + + static_libs: [ + "platform-compat-test-rules", + "androidx.appcompat_appcompat", + "androidx.test.rules", + "androidx.test.ext.junit", + "androidx.annotation_annotation", + "apct-perftests-utils", + "androidx.benchmark_benchmark-common", + "androidx.benchmark_benchmark-junit4", + "collector-device-lib-platform", + "cts-install-lib-java", + ], + + libs: ["android.test.base"], + + platform_apis: true, + + test_suites: ["device-tests"], + + data: [ + ":UsePermissionApp0", + ":UsePermissionApp1", + ":UsePermissionApp2", + ":UsePermissionApp3", + ":UsePermissionApp4", + ":UsePermissionApp5", + ":UsePermissionApp6", + ":UsePermissionApp7", + ":UsePermissionApp8", + ":UsePermissionApp9", + ":UsePermissionApp10", + ":UsePermissionApp11", + ":UsePermissionApp12", + ":UsePermissionApp13", + ":UsePermissionApp14", + ":UsePermissionApp15", + ":UsePermissionApp16", + ":UsePermissionApp17", + ":UsePermissionApp18", + ":UsePermissionApp19", + ":UsePermissionApp20", + ":UsePermissionApp21", + ":UsePermissionApp22", + ":UsePermissionApp23", + ":UsePermissionApp24", + ":UsePermissionApp25", + ":UsePermissionApp26", + ":UsePermissionApp27", + ":UsePermissionApp28", + ":UsePermissionApp29", + ":perfetto_artifacts", + ], + + certificate: "platform", + +} diff --git a/apct-tests/perftests/permission/AndroidManifest.xml b/apct-tests/perftests/permission/AndroidManifest.xml new file mode 100644 index 000000000000..fa29ad0404da --- /dev/null +++ b/apct-tests/perftests/permission/AndroidManifest.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2024 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. + --> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="android.perftests.permission"> + + <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/> + + <application> + <uses-library android:name="android.test.runner" /> + <activity android:name="android.perftests.utils.PerfTestActivity" + android:exported="true"> + <intent-filter> + <action android:name="android.perftests.permission.PERFTEST" /> + </intent-filter> + </activity> + </application> + + <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" + android:targetPackage="android.perftests.permission"/> + +</manifest> diff --git a/apct-tests/perftests/permission/AndroidTest.xml b/apct-tests/perftests/permission/AndroidTest.xml new file mode 100644 index 000000000000..07558deafb6c --- /dev/null +++ b/apct-tests/perftests/permission/AndroidTest.xml @@ -0,0 +1,180 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2020 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 PermissionServicePerfTests 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="PermissionServicePerfTests.apk"/> + </target_preparer> + <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller"> + <option name="cleanup-apks" value="true"/> + <option name="force-queryable" value="false"/> + <option name="test-file-name" value="UsePermissionApp0.apk"/> + <option name="test-file-name" value="UsePermissionApp1.apk"/> + <option name="test-file-name" value="UsePermissionApp2.apk"/> + <option name="test-file-name" value="UsePermissionApp3.apk"/> + <option name="test-file-name" value="UsePermissionApp4.apk"/> + <option name="test-file-name" value="UsePermissionApp5.apk"/> + <option name="test-file-name" value="UsePermissionApp6.apk"/> + <option name="test-file-name" value="UsePermissionApp7.apk"/> + <option name="test-file-name" value="UsePermissionApp8.apk"/> + <option name="test-file-name" value="UsePermissionApp9.apk"/> + <option name="test-file-name" value="UsePermissionApp10.apk"/> + <option name="test-file-name" value="UsePermissionApp11.apk"/> + <option name="test-file-name" value="UsePermissionApp12.apk"/> + <option name="test-file-name" value="UsePermissionApp13.apk"/> + <option name="test-file-name" value="UsePermissionApp14.apk"/> + <option name="test-file-name" value="UsePermissionApp15.apk"/> + <option name="test-file-name" value="UsePermissionApp16.apk"/> + <option name="test-file-name" value="UsePermissionApp17.apk"/> + <option name="test-file-name" value="UsePermissionApp18.apk"/> + <option name="test-file-name" value="UsePermissionApp19.apk"/> + <option name="test-file-name" value="UsePermissionApp20.apk"/> + <option name="test-file-name" value="UsePermissionApp21.apk"/> + <option name="test-file-name" value="UsePermissionApp22.apk"/> + <option name="test-file-name" value="UsePermissionApp23.apk"/> + <option name="test-file-name" value="UsePermissionApp24.apk"/> + <option name="test-file-name" value="UsePermissionApp25.apk"/> + <option name="test-file-name" value="UsePermissionApp26.apk"/> + <option name="test-file-name" value="UsePermissionApp27.apk"/> + <option name="test-file-name" value="UsePermissionApp28.apk"/> + <option name="test-file-name" value="UsePermissionApp29.apk"/> + </target_preparer> + + <test class="com.android.tradefed.testtype.AndroidJUnitTest"> + <option name="package" value="android.perftests.permission"/> + <option name="hidden-api-checks" value="false"/> + </test> + + <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector"> + <option name="directory-keys" value="/data/local/PermissionServicePerfTests"/> + <option name="collect-on-run-ended-only" value="true"/> + </metrics_collector> + + <!-- Needed for pushing the trace config file --> + <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer"/> + <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer"> + <option name="push-file" key="trace_config_detailed.textproto" + value="/data/misc/perfetto-traces/trace_config.textproto"/> + <!--Install the content provider automatically when we push some file in sdcard folder.--> + <!--Needed to avoid the installation during the test suite.--> + <option name="push-file" key="trace_config_detailed.textproto" + value="/sdcard/sample.textproto"/> + <option name="push-file" key="UsePermissionApp0.apk" + value="/data/local/tmp/perftests/UsePermissionApp0.apk" /> + <option name="push-file" key="UsePermissionApp1.apk" + value="/data/local/tmp/perftests/UsePermissionApp1.apk" /> + <option name="push-file" key="UsePermissionApp2.apk" + value="/data/local/tmp/perftests/UsePermissionApp2.apk" /> + <option name="push-file" key="UsePermissionApp3.apk" + value="/data/local/tmp/perftests/UsePermissionApp3.apk" /> + <option name="push-file" key="UsePermissionApp4.apk" + value="/data/local/tmp/perftests/UsePermissionApp4.apk" /> + <option name="push-file" key="UsePermissionApp5.apk" + value="/data/local/tmp/perftests/UsePermissionApp5.apk" /> + <option name="push-file" key="UsePermissionApp6.apk" + value="/data/local/tmp/perftests/UsePermissionApp6.apk" /> + <option name="push-file" key="UsePermissionApp7.apk" + value="/data/local/tmp/perftests/UsePermissionApp7.apk" /> + <option name="push-file" key="UsePermissionApp8.apk" + value="/data/local/tmp/perftests/UsePermissionApp8.apk" /> + <option name="push-file" key="UsePermissionApp9.apk" + value="/data/local/tmp/perftests/UsePermissionApp9.apk" /> + <option name="push-file" key="UsePermissionApp10.apk" + value="/data/local/tmp/perftests/UsePermissionApp10.apk" /> + <option name="push-file" key="UsePermissionApp11.apk" + value="/data/local/tmp/perftests/UsePermissionApp11.apk" /> + <option name="push-file" key="UsePermissionApp12.apk" + value="/data/local/tmp/perftests/UsePermissionApp12.apk" /> + <option name="push-file" key="UsePermissionApp13.apk" + value="/data/local/tmp/perftests/UsePermissionApp13.apk" /> + <option name="push-file" key="UsePermissionApp14.apk" + value="/data/local/tmp/perftests/UsePermissionApp14.apk" /> + <option name="push-file" key="UsePermissionApp15.apk" + value="/data/local/tmp/perftests/UsePermissionApp15.apk" /> + <option name="push-file" key="UsePermissionApp16.apk" + value="/data/local/tmp/perftests/UsePermissionApp16.apk" /> + <option name="push-file" key="UsePermissionApp17.apk" + value="/data/local/tmp/perftests/UsePermissionApp17.apk" /> + <option name="push-file" key="UsePermissionApp18.apk" + value="/data/local/tmp/perftests/UsePermissionApp18.apk" /> + <option name="push-file" key="UsePermissionApp19.apk" + value="/data/local/tmp/perftests/UsePermissionApp19.apk" /> + <option name="push-file" key="UsePermissionApp20.apk" + value="/data/local/tmp/perftests/UsePermissionApp20.apk" /> + <option name="push-file" key="UsePermissionApp21.apk" + value="/data/local/tmp/perftests/UsePermissionApp21.apk" /> + <option name="push-file" key="UsePermissionApp22.apk" + value="/data/local/tmp/perftests/UsePermissionApp22.apk" /> + <option name="push-file" key="UsePermissionApp23.apk" + value="/data/local/tmp/perftests/UsePermissionApp23.apk" /> + <option name="push-file" key="UsePermissionApp24.apk" + value="/data/local/tmp/perftests/UsePermissionApp24.apk" /> + <option name="push-file" key="UsePermissionApp25.apk" + value="/data/local/tmp/perftests/UsePermissionApp25.apk" /> + <option name="push-file" key="UsePermissionApp26.apk" + value="/data/local/tmp/perftests/UsePermissionApp26.apk" /> + <option name="push-file" key="UsePermissionApp27.apk" + value="/data/local/tmp/perftests/UsePermissionApp27.apk" /> + <option name="push-file" key="UsePermissionApp28.apk" + value="/data/local/tmp/perftests/UsePermissionApp28.apk" /> + <option name="push-file" key="UsePermissionApp29.apk" + value="/data/local/tmp/perftests/UsePermissionApp29.apk" /> + </target_preparer> + + <!-- Needed for pulling the collected trace config on to the host --> + <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector"> + <option name="pull-pattern-keys" value="perfetto_file_path"/> + </metrics_collector> + + <!-- Needed for storing the perfetto trace files in the sdcard/test_results --> + <option name="isolated-storage" value="false"/> + + <test class="com.android.tradefed.testtype.AndroidJUnitTest"> + <option name="package" value="android.perftests.permission"/> + <option name="hidden-api-checks" value="false"/> + + <!-- Listener related args for collecting the traces and waiting for the device to + stabilize. --> + <option name="device-listeners" + value="android.device.collectors.ProcLoadListener,android.device.collectors.PerfettoListener"/> + <!-- Guarantee that user defined RunListeners will be running before any of the default + listeners defined in this runner. --> + <option name="instrumentation-arg" key="newRunListenerMode" value="true"/> + + <!-- ProcLoadListener related arguments --> + <!-- Wait for device last minute threshold to reach 3 with 2 minute timeout before starting + the test run --> + <option name="instrumentation-arg" key="procload-collector:per_run" value="true"/> + <option name="instrumentation-arg" key="proc-loadavg-threshold" value="3"/> + <option name="instrumentation-arg" key="proc-loadavg-timeout" value="120000"/> + <option name="instrumentation-arg" key="proc-loadavg-interval" value="10000"/> + + <!-- PerfettoListener related arguments --> + <option name="instrumentation-arg" key="perfetto_config_text_proto" value="true"/> + <option name="instrumentation-arg" key="perfetto_config_file" + value="trace_config.textproto"/> + + <!-- + PackageInstallerBenchmark will break for 5 minutes time out so it changes to 10 minutes + --> + <option name="test-timeout" value="600000" /> + </test> + + +</configuration> diff --git a/apct-tests/perftests/permission/apps/usepermissionapp/Android.bp b/apct-tests/perftests/permission/apps/usepermissionapp/Android.bp new file mode 100644 index 000000000000..1ad20b6fff6c --- /dev/null +++ b/apct-tests/perftests/permission/apps/usepermissionapp/Android.bp @@ -0,0 +1,232 @@ +// Copyright (C) 2024 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 { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "frameworks_base_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["frameworks_base_license"], +} + +android_test_helper_app { + name: "UsePermissionApp0", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration0", + ], +} + +android_test_helper_app { + name: "UsePermissionApp1", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration1", + ], +} + +android_test_helper_app { + name: "UsePermissionApp2", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration2", + ], +} + +android_test_helper_app { + name: "UsePermissionApp3", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration3", + ], +} + +android_test_helper_app { + name: "UsePermissionApp4", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration4", + ], +} + +android_test_helper_app { + name: "UsePermissionApp5", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration5", + ], +} + +android_test_helper_app { + name: "UsePermissionApp6", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration6", + ], +} + +android_test_helper_app { + name: "UsePermissionApp7", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration7", + ], +} + +android_test_helper_app { + name: "UsePermissionApp8", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration8", + ], +} + +android_test_helper_app { + name: "UsePermissionApp9", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration9", + ], +} + +android_test_helper_app { + name: "UsePermissionApp10", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration10", + ], +} + +android_test_helper_app { + name: "UsePermissionApp11", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration11", + ], +} + +android_test_helper_app { + name: "UsePermissionApp12", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration12", + ], +} + +android_test_helper_app { + name: "UsePermissionApp13", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration13", + ], +} + +android_test_helper_app { + name: "UsePermissionApp14", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration14", + ], +} + +android_test_helper_app { + name: "UsePermissionApp15", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration15", + ], +} + +android_test_helper_app { + name: "UsePermissionApp16", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration16", + ], +} + +android_test_helper_app { + name: "UsePermissionApp17", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration17", + ], +} + +android_test_helper_app { + name: "UsePermissionApp18", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration18", + ], +} + +android_test_helper_app { + name: "UsePermissionApp19", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration19", + ], +} + +android_test_helper_app { + name: "UsePermissionApp20", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration20", + ], +} + +android_test_helper_app { + name: "UsePermissionApp21", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration21", + ], +} + +android_test_helper_app { + name: "UsePermissionApp22", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration22", + ], +} + +android_test_helper_app { + name: "UsePermissionApp23", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration23", + ], +} + +android_test_helper_app { + name: "UsePermissionApp24", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration24", + ], +} + +android_test_helper_app { + name: "UsePermissionApp25", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration25", + ], +} + +android_test_helper_app { + name: "UsePermissionApp26", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration26", + ], +} + +android_test_helper_app { + name: "UsePermissionApp27", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration27", + ], +} + +android_test_helper_app { + name: "UsePermissionApp28", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration28", + ], +} + +android_test_helper_app { + name: "UsePermissionApp29", + aaptflags: [ + "--rename-manifest-package android.perftests.appenumeration29", + ], +} diff --git a/apct-tests/perftests/permission/apps/usepermissionapp/AndroidManifest.xml b/apct-tests/perftests/permission/apps/usepermissionapp/AndroidManifest.xml new file mode 100644 index 000000000000..3bccefd24b49 --- /dev/null +++ b/apct-tests/perftests/permission/apps/usepermissionapp/AndroidManifest.xml @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2024 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. + --> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="android.perftests.appenumeration"> + + <uses-permission android:name="android.permission.RECORD_AUDIO"/> + <uses-permission android:name="android.permission.CAMERA"/> + <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> + <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" /> + <uses-permission android:name="android.permission.RECORD_BACKGROUND_AUDIO" /> + <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" /> + <uses-permission android:name="android.permission.BACKGROUND_CAMERA" /> + <uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS" /> + <uses-permission android:name="android.permission.BODY_SENSORS" /> + <uses-permission android:name="android.permission.USE_BIOMETRIC" /> + <uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> + <uses-permission android:name="android.permission.SET_WALLPAPER" /> + <uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" /> + + <queries> + <package android:name="android.perftests.appenumeration0" /> + <package android:name="android.perftests.appenumeration1" /> + <package android:name="android.perftests.appenumeration2" /> + <package android:name="android.perftests.appenumeration3" /> + <package android:name="android.perftests.appenumeration4" /> + <package android:name="android.perftests.appenumeration5" /> + <package android:name="android.perftests.appenumeration6" /> + <package android:name="android.perftests.appenumeration7" /> + <package android:name="android.perftests.appenumeration8" /> + <package android:name="android.perftests.appenumeration9" /> + <package android:name="android.perftests.appenumeration10" /> + <package android:name="android.perftests.appenumeration11" /> + <package android:name="android.perftests.appenumeration12" /> + <package android:name="android.perftests.appenumeration13" /> + <package android:name="android.perftests.appenumeration14" /> + <package android:name="android.perftests.appenumeration15" /> + <package android:name="android.perftests.appenumeration16" /> + <package android:name="android.perftests.appenumeration17" /> + <package android:name="android.perftests.appenumeration18" /> + <package android:name="android.perftests.appenumeration19" /> + <package android:name="android.perftests.appenumeration20" /> + <package android:name="android.perftests.appenumeration21" /> + <package android:name="android.perftests.appenumeration22" /> + <package android:name="android.perftests.appenumeration23" /> + <package android:name="android.perftests.appenumeration24" /> + <package android:name="android.perftests.appenumeration25" /> + <package android:name="android.perftests.appenumeration26" /> + <package android:name="android.perftests.appenumeration27" /> + <package android:name="android.perftests.appenumeration28" /> + <package android:name="android.perftests.appenumeration29" /> + </queries> + + <application android:hasCode="false" > + <activity android:name="android.perftests.utils.PerfTestActivity" + android:exported="true"> + <intent-filter> + <action android:name="android.perftests.permission.PERFTEST" /> + </intent-filter> + </activity> + </application> + +</manifest> diff --git a/apct-tests/perftests/permission/src/android/perftests/permission/PermissionServicePerfTest.kt b/apct-tests/perftests/permission/src/android/perftests/permission/PermissionServicePerfTest.kt new file mode 100644 index 000000000000..13e67e34a8d9 --- /dev/null +++ b/apct-tests/perftests/permission/src/android/perftests/permission/PermissionServicePerfTest.kt @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2023 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 android.perftests.permission + +import android.Manifest +import android.os.ParcelFileDescriptor +import android.os.Trace +import android.perftests.utils.PerfManualStatusReporter +import android.perftests.utils.TraceMarkParser +import android.util.Log +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import com.android.compatibility.common.util.AdoptShellPermissionsRule +import com.android.compatibility.common.util.SystemUtil.eventually +import com.android.compatibility.common.util.SystemUtil.runShellCommand +import com.google.common.truth.Truth.assertThat +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import java.io.BufferedReader +import java.io.IOException +import java.io.InputStreamReader +import java.util.concurrent.TimeUnit +import java.util.function.BiConsumer + +@RunWith(AndroidJUnit4::class) +class PermissionServicePerfTest { + @get:Rule val mPerfManualStatusReporter = PerfManualStatusReporter() + @get:Rule val mAdoptShellPermissionsRule = AdoptShellPermissionsRule( + InstrumentationRegistry.getInstrumentation().getUiAutomation(), + Manifest.permission.INSTALL_PACKAGES, + Manifest.permission.DELETE_PACKAGES + ) + val mUiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation() + + @Test + fun testInstallPackages() { + mUiAutomation.executeShellCommand(COMMAND_TRACE_START) + eventually { assertThat(Trace.isTagEnabled(TRACE_TAG)).isTrue() } + val benchmarkState = mPerfManualStatusReporter.benchmarkState + val durations = ArrayList<Long>() + + while (benchmarkState.keepRunning(durations)) { + uninstallAllTestApps() + installAllTestApps() + + val parser = TraceMarkParser { line -> line.name.contains(PKG_INSTALL_TRACE_PREFIX) } + dumpResult(parser) { _, slices -> + slices.forEachIndexed { _, slice -> + durations.add(TimeUnit.MICROSECONDS.toNanos(slice.durationInMicroseconds)) + } + } + } + + mUiAutomation.executeShellCommand(COMMAND_TRACE_END) + } + + private fun installAllTestApps() { + for (i in 0..29) { + installTestApp(i) + } + } + + private fun installTestApp(appId: Int) { + val apkPath = "$APK_DIR$APK_NAME$appId.apk" + runShellCommand("pm install -t $apkPath") + } + + private fun uninstallAllTestApps() { + for (i in 0..29) { + uninstallTestApp(i) + } + } + + private fun uninstallTestApp(appId: Int) { + val packageName = "$PKG_NAME$appId" + runShellCommand("pm uninstall $packageName") + } + + private fun dumpResult( + parser: TraceMarkParser, + handler: BiConsumer<String, List<TraceMarkParser.TraceMarkSlice>> + ) { + parser.reset() + try { + val inputStream = ParcelFileDescriptor.AutoCloseInputStream( + mUiAutomation.executeShellCommand(COMMAND_TRACE_DUMP) + ) + val reader = BufferedReader(InputStreamReader(inputStream)) + var line = reader.readLine() + while (line != null) { + parser.visit(line) + line = reader.readLine() + } + } catch (e: IOException) { + Log.e(LOG_TAG, "IO error while reading trace dump file.") + } + parser.forAllSlices(handler) + } + + companion object { + private val LOG_TAG = PermissionServicePerfTest::class.java.simpleName + private const val TRACE_TAG = Trace.TRACE_TAG_PACKAGE_MANAGER + private const val PKG_INSTALL_TRACE_PREFIX = + "TaggedTracingPermissionManagerServiceImpl#onPackageInstalled" + private const val COMMAND_TRACE_START = "atrace --async_start -b 16000 pm" + private const val COMMAND_TRACE_END = "atrace --async_stop" + private const val COMMAND_TRACE_DUMP = "atrace --async_dump" + private const val APK_DIR = "/data/local/tmp/perftests/" + private const val APK_NAME = "UsePermissionApp" + private const val PKG_NAME = "android.perftests.appenumeration" + } +} |