1 /* 2 * Copyright 2022 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.media.codec.cts; 17 18 import android.app.Notification; 19 import android.app.NotificationChannel; 20 import android.app.NotificationManager; 21 import android.app.Service; 22 import android.content.Intent; 23 import android.os.Binder; 24 import android.os.IBinder; 25 import android.os.Process; 26 27 public class MediaCodecResourceTestLowPriorityService extends Service { 28 public static final String ACTION_LOW_PRIORITY_SERVICE_READY = 29 "android.media.codec.cts.LOW_PRIORITY_SERVICE_READY"; 30 31 public static final String NOTIFICATION_CHANNEL_ID = 32 "cts/MediaCodecResourceTestLowPriorityService"; 33 34 private final IBinder mBinder = new LocalBinder(); 35 public class LocalBinder extends Binder { getService()36 MediaCodecResourceTestLowPriorityService getService() { 37 return MediaCodecResourceTestLowPriorityService.this; 38 } 39 } 40 @Override onBind(Intent intent)41 public IBinder onBind(Intent intent) { 42 return mBinder; 43 } 44 45 private int mNotificationId = 1; 46 47 @Override onStartCommand(Intent otherIntent, int flags, int startId)48 public int onStartCommand(Intent otherIntent, int flags, int startId) { 49 Notification notification = showNotification(); 50 startForeground(mNotificationId++, notification); 51 52 Intent intent = new Intent(); 53 intent.setAction(ACTION_LOW_PRIORITY_SERVICE_READY); 54 intent.putExtra("pid", Process.myPid()); 55 intent.putExtra("uid", Process.myUid()); 56 sendBroadcast(intent); 57 58 return START_NOT_STICKY; 59 } 60 showNotification()61 private Notification showNotification() { 62 NotificationManager notificationManager = getSystemService(NotificationManager.class); 63 notificationManager.createNotificationChannel(new NotificationChannel( 64 NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_ID, 65 NotificationManager.IMPORTANCE_DEFAULT)); 66 return new Notification.Builder(getApplicationContext(), NOTIFICATION_CHANNEL_ID) 67 .setContentTitle("MediaCodecResourceTestLowPriorityService") 68 .setSmallIcon(R.drawable.icon_black) 69 .build(); 70 } 71 } 72