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 17 package com.android.musicfx; 18 19 import android.app.Service; 20 import android.content.Intent; 21 import android.os.Binder; 22 import android.os.IBinder; 23 import android.util.Log; 24 25 /** 26 * This Service provides a way for client to bind to MusicFx, so that MusicFx can run at same 27 * Process State (see @ProcessStateEnum) as the client. 28 * 29 * Currently, MusicFx does not run in a high priority state (often in CACHED_EMPTY) and can be 30 * easily killed by the LowMemoryKiller. However, its users (music apps, for example) are usually 31 * in a higher priority state, which means they are less likely to be killed. This can lead to 32 * MusicFx and its users being out of sync. To avoid this, framework side will keep record of all 33 * active MusicFx audio sessions, promote the procstate of MusicFx to foreground with the first 34 * audio session open, and remove the foreground procstate delegate with the last audio session 35 * close, or the last user of MusicFx is gone. 36 * 37 * MusicFx user APPs do not need to do anything. 38 * 39 */ 40 public class KeepAliveService extends Service { 41 private final String TAG = "MusicFxKeepAliveService"; 42 43 // Binder given to clients with onBind() callback, the client app receive it as IBinder 44 // parameter of onServiceConnected which can not be used. 45 private final IBinder mBinder = new Binder(); 46 47 @Override onBind(Intent intent)48 public IBinder onBind(Intent intent) { 49 Log.i(TAG, "onBind with intent " + intent); 50 return mBinder; 51 } 52 } 53