1 /* 2 * Copyright 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 @file:Suppress("UnstableApiUsage") 18 19 package androidx.build.lint 20 21 import org.junit.Test 22 import org.junit.runner.RunWith 23 import org.junit.runners.JUnit4 24 25 @RunWith(JUnit4::class) 26 class AndroidManifestServiceExportedDetectorTest : 27 AbstractLintDetectorTest( 28 useDetector = AndroidManifestServiceExportedDetector(), 29 useIssues = listOf(AndroidManifestServiceExportedDetector.ISSUE), 30 ) { 31 32 @Test Detect missing exported=true declaration in service tagnull33 fun `Detect missing exported=true declaration in service tag`() { 34 val input = arrayOf(manifestSample()) 35 36 val expected = 37 """ 38 AndroidManifest.xml:21: Error: Missing exported=true in <service> tag [MissingServiceExportedEqualsTrue] 39 <service android:name="androidx.core.app.JobIntentService"> 40 ^ 41 1 errors, 0 warnings 42 """ 43 .trimIndent() 44 45 check(*input).expect(expected) 46 } 47 48 @Test Detect present exported=true declaration in service tagnull49 fun `Detect present exported=true declaration in service tag`() { 50 val input = 51 xml( 52 "AndroidManifest.xml", 53 """ 54 <manifest xmlns:android="http://schemas.android.com/apk/res/android"> 55 <application> 56 <service 57 android:name="androidx.service" 58 android:exported="true" /> 59 </application> 60 </manifest> 61 """ 62 .trimIndent() 63 ) 64 65 check(input).expectClean() 66 } 67 } 68