Merge "Unexport all PackageInstaller receivers" into sc-qpr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d991ba31e3
@@ -31,7 +31,7 @@
|
|||||||
android:directBootAware="true">
|
android:directBootAware="true">
|
||||||
|
|
||||||
<receiver android:name=".TemporaryFileManager"
|
<receiver android:name=".TemporaryFileManager"
|
||||||
android:exported="true">
|
android:exported="false">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
|
|
||||||
<receiver android:name=".InstallEventReceiver"
|
<receiver android:name=".InstallEventReceiver"
|
||||||
android:permission="android.permission.INSTALL_PACKAGES"
|
android:permission="android.permission.INSTALL_PACKAGES"
|
||||||
android:exported="true">
|
android:exported="false">
|
||||||
<intent-filter android:priority="1">
|
<intent-filter android:priority="1">
|
||||||
<action android:name="com.android.packageinstaller.ACTION_INSTALL_COMMIT" />
|
<action android:name="com.android.packageinstaller.ACTION_INSTALL_COMMIT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
@@ -106,14 +106,14 @@
|
|||||||
|
|
||||||
<receiver android:name=".UninstallEventReceiver"
|
<receiver android:name=".UninstallEventReceiver"
|
||||||
android:permission="android.permission.INSTALL_PACKAGES"
|
android:permission="android.permission.INSTALL_PACKAGES"
|
||||||
android:exported="true">
|
android:exported="false">
|
||||||
<intent-filter android:priority="1">
|
<intent-filter android:priority="1">
|
||||||
<action android:name="com.android.packageinstaller.ACTION_UNINSTALL_COMMIT" />
|
<action android:name="com.android.packageinstaller.ACTION_UNINSTALL_COMMIT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<receiver android:name=".PackageInstalledReceiver"
|
<receiver android:name=".PackageInstalledReceiver"
|
||||||
android:exported="true">
|
android:exported="false">
|
||||||
<intent-filter android:priority="1">
|
<intent-filter android:priority="1">
|
||||||
<action android:name="android.intent.action.PACKAGE_ADDED" />
|
<action android:name="android.intent.action.PACKAGE_ADDED" />
|
||||||
<data android:scheme="package" />
|
<data android:scheme="package" />
|
||||||
|
|||||||
@@ -19,6 +19,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "CtsPackageUninstallTestCases"
|
"name": "CtsPackageUninstallTestCases"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "PackageInstallerTests"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
39
services/tests/PackageManager/packageinstaller/Android.bp
Normal file
39
services/tests/PackageManager/packageinstaller/Android.bp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
// Copyright (C) 2021 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: "PackageInstallerTests",
|
||||||
|
srcs: [
|
||||||
|
"src/**/*.java",
|
||||||
|
"src/**/*.kt",
|
||||||
|
],
|
||||||
|
static_libs: [
|
||||||
|
"androidx.test.rules",
|
||||||
|
"androidx.test.runner",
|
||||||
|
"junit",
|
||||||
|
"kotlin-test",
|
||||||
|
"truth-prebuilt",
|
||||||
|
],
|
||||||
|
platform_apis: true,
|
||||||
|
test_suites: ["device-tests"],
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (C) 2021 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="com.android.packageinstaller.test">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
|
||||||
|
|
||||||
|
<instrumentation
|
||||||
|
android:name="androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
android:targetPackage="com.android.packageinstaller.test"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</manifest>
|
||||||
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (C) 2021 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="Test module config for PackageInstallerTests">
|
||||||
|
<option name="test-tag" value="PackageInstallerTests" />
|
||||||
|
|
||||||
|
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
|
||||||
|
<option name="cleanup-apks" value="true" />
|
||||||
|
<option name="test-file-name" value="PackageInstallerTests.apk" />
|
||||||
|
</target_preparer>
|
||||||
|
|
||||||
|
<test class="com.android.tradefed.testtype.AndroidJUnitTest">
|
||||||
|
<option name="package" value="com.android.packageinstaller.test" />
|
||||||
|
</test>
|
||||||
|
</configuration>
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 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.packageinstaller.test
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.test.InstrumentationRegistry
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import com.google.common.truth.Truth.assertWithMessage
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class ExportedComponentTest {
|
||||||
|
|
||||||
|
private val context: Context = InstrumentationRegistry.getContext()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun verifyNoExportedReceivers() {
|
||||||
|
val intent = Intent(Intent.ACTION_INSTALL_PACKAGE).apply {
|
||||||
|
data = Uri.parse("content://mockForTest")
|
||||||
|
}
|
||||||
|
val packageInstallers = context.packageManager.queryIntentActivities(intent,
|
||||||
|
PackageManager.MATCH_DEFAULT_ONLY or PackageManager.MATCH_DISABLED_COMPONENTS)
|
||||||
|
.map { it.activityInfo.packageName }
|
||||||
|
.distinct()
|
||||||
|
.map { context.packageManager.getPackageInfo(it, PackageManager.GET_RECEIVERS) }
|
||||||
|
|
||||||
|
assertThat(packageInstallers).isNotEmpty()
|
||||||
|
|
||||||
|
packageInstallers.forEach {
|
||||||
|
val exported = it.receivers.filter { it.exported }
|
||||||
|
assertWithMessage("Receivers should not be exported").that(exported).isEmpty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user