blob: d9dc035dc0f362ea537a3da3a66ab2537ab2f725 [file] [log] [blame]
/*
* 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.security.cts.CVE_2023_21129;
import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
import static org.junit.Assert.assertFalse;
import static org.junit.Assume.assumeNoException;
import static org.junit.Assume.assumeTrue;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class DeviceTest {
@Test
public void testBubbleNotification() {
try {
Context context = getInstrumentation().getContext();
Semaphore broadcastReceived = new Semaphore(0);
final int timeoutMs = 9000;
// Register a broadcast receiver to receive broadcast from BubbleActivity indicating
// presence of vulnerability
BroadcastReceiver broadcastReceiver =
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
try {
if (intent.getAction()
.equals(
context.getString(
R.string.nameBroadcastActionString))) {
broadcastReceived.release();
}
} catch (Exception ignored) {
// ignore any exceptions
}
}
};
IntentFilter filter =
new IntentFilter(context.getString(R.string.nameBroadcastActionString));
context.registerReceiver(broadcastReceiver, filter);
// Create a notification manager
NotificationManager notificationManager =
context.getSystemService(NotificationManager.class);
// Check if bubble notifications are enabled or disabled on the device
assumeTrue(
context.getString(R.string.bubbleNotificDisabled),
notificationManager.getBubblePreference() == BUBBLE_PREFERENCE_ALL);
// Launching BubbleActivity
Intent intent = new Intent(context, BubbleActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent);
assertFalse(
context.getString(R.string.msgFailure),
broadcastReceived.tryAcquire(timeoutMs, TimeUnit.MILLISECONDS));
} catch (Exception e) {
assumeNoException(e);
}
}
}