1 /*
2  * Copyright (C) 2023 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 package android.app.notification.extenders.cts.api34
17 
18 import android.app.Notification
19 import android.app.Notification.WearableExtender
20 import android.content.Context
21 import android.graphics.Bitmap
22 import android.graphics.Bitmap.Config
23 import androidx.test.ext.junit.runners.AndroidJUnit4
24 import androidx.test.platform.app.InstrumentationRegistry
25 import com.google.common.truth.Truth.assertThat
26 import org.junit.After
27 import org.junit.Before
28 import org.junit.Test
29 import org.junit.runner.RunWith
30 
31 @RunWith(AndroidJUnit4::class)
32 class WearableExtenderApi34Test {
33 
34     private lateinit var mContext: Context
35 
36     @Before
setUpnull37     fun setUp() {
38         mContext = InstrumentationRegistry.getInstrumentation().targetContext
39     }
40 
41     @After
tearDownnull42     fun tearDown() {
43         InstrumentationRegistry.getInstrumentation().uiAutomation.dropShellPermissionIdentity()
44     }
45 
46     @Test
wearableBackgroundBlockDisabled_wearableBackgroundSet_valueKeepsBitmapnull47     fun wearableBackgroundBlockDisabled_wearableBackgroundSet_valueKeepsBitmap() {
48         val extender = WearableExtender()
49         val bitmap = Bitmap.createBitmap(200, 200, Config.ARGB_8888)
50         extender.setBackground(bitmap)
51         val notif: Notification =
52                 Notification.Builder(mContext, "test id")
53                     .setSmallIcon(1)
54                     .setContentTitle("test_title")
55                     .extend(extender)
56                     .build()
57 
58         val result = WearableExtender(notif)
59         val background = result.getBackground()
60         assertThat(background).isNotNull()
61         assertThat(background).isEqualTo(bitmap)
62     }
63 }
64