1 /*
2  * Copyright (C) 2017 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.server.audio;
18 
19 import android.annotation.NonNull;
20 
21 public interface PlayerFocusEnforcer {
22 
23     /**
24      * Ducks the players associated with the "loser" focus owner (i.e. same UID). Returns true if
25      * at least one active player was found and ducked, false otherwise.
26      * @param winner
27      * @param loser
28      * @return
29      */
duckPlayers(@onNull FocusRequester winner, @NonNull FocusRequester loser, boolean forceDuck)30     boolean duckPlayers(@NonNull FocusRequester winner, @NonNull FocusRequester loser,
31                                boolean forceDuck);
32 
33     /**
34      * Restore the initial state of any players that had had a volume ramp applied as the result
35      * of a duck or fade out through {@link #duckPlayers(FocusRequester, FocusRequester, boolean)}
36      * or {@link #fadeOutPlayers(FocusRequester, FocusRequester)}
37      * @param winner
38      */
restoreVShapedPlayers(@onNull FocusRequester winner)39     void restoreVShapedPlayers(@NonNull FocusRequester winner);
40 
41     /**
42      * Mute players at the beginning of a call
43      * @param usagesToMute array of {@link android.media.AudioAttributes} usages to mute
44      */
mutePlayersForCall(int[] usagesToMute)45     void mutePlayersForCall(int[] usagesToMute);
46 
47     /**
48      * Unmute players at the end of a call
49      */
unmutePlayersForCall()50     void unmutePlayersForCall();
51 
52     /**
53      * Fade out whatever is still playing after the non-transient focus change
54      * @param winner the new non-transient focus owner
55      * @param loser the previous focus owner
56      * @return true if there were any active players for the loser that qualified for being
57      *         faded out (because of audio attributes, or player types), and as such were faded
58      *         out.
59      */
fadeOutPlayers(@onNull FocusRequester winner, @NonNull FocusRequester loser)60     boolean fadeOutPlayers(@NonNull FocusRequester winner, @NonNull FocusRequester loser);
61 
62     /**
63      * Mark this UID as no longer playing a role in focus enforcement
64      * @param uid
65      */
forgetUid(int uid)66     void forgetUid(int uid);
67 }