1 /* 2 * Copyright 2020 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.media; 18 19 import android.annotation.IntDef; 20 import android.annotation.NonNull; 21 import android.content.Context; 22 import android.media.session.MediaSession; 23 24 import java.lang.annotation.Retention; 25 import java.lang.annotation.RetentionPolicy; 26 27 /** 28 * Abstract class for customizing how {@link MediaSessionService} handles sessions. 29 * 30 * Note: When instantiating this class, {@link MediaSessionService} will only use the constructor 31 * without any parameters. 32 */ 33 // TODO: Move this class to apex/media/ 34 public abstract class MediaSessionPolicyProvider { 35 @IntDef(value = { 36 SESSION_POLICY_IGNORE_BUTTON_RECEIVER, 37 SESSION_POLICY_IGNORE_BUTTON_SESSION 38 }) 39 @Retention(RetentionPolicy.SOURCE) 40 @interface SessionPolicy {} 41 42 /** 43 * Policy to ignore media button receiver, to not revive the media app when its media session is 44 * released or the app is dead. 45 * 46 * @see MediaSession#setMediaButtonReceiver 47 */ 48 static final int SESSION_POLICY_IGNORE_BUTTON_RECEIVER = 1 << 0; 49 50 /** 51 * Policy to ignore sessions that should not respond to media key events via 52 * {@link MediaSessionService}. A typical use case is to explicitly 53 * ignore sessions that should not respond to media key events even if their playback state has 54 * changed most recently. 55 */ 56 static final int SESSION_POLICY_IGNORE_BUTTON_SESSION = 1 << 1; 57 MediaSessionPolicyProvider(Context context)58 public MediaSessionPolicyProvider(Context context) { 59 // Constructor used for reflection 60 } 61 62 /** 63 * Use this to statically set policies for sessions when they are created. 64 * Use android.media.session.MediaSessionManager#setSessionPolicies(MediaSession.Token, int) 65 * to dynamically change policies at runtime. 66 * 67 * @param uid 68 * @param packageName 69 * @return list of policies 70 */ getSessionPoliciesForApplication(int uid, @NonNull String packageName)71 @SessionPolicy int getSessionPoliciesForApplication(int uid, @NonNull String packageName) { 72 return 0; 73 } 74 } 75