10212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi/* 20212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * Copyright (C) 2014 The Android Open Source Project 30212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * 40212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * Licensed under the Apache License, Version 2.0 (the "License"); 50212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * you may not use this file except in compliance with the License. 60212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * You may obtain a copy of the License at 70212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * 80212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * http://www.apache.org/licenses/LICENSE-2.0 90212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * 100212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * Unless required by applicable law or agreed to in writing, software 110212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * distributed under the License is distributed on an "AS IS" BASIS, 120212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * See the License for the specific language governing permissions and 140212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * limitations under the License. 150212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi */ 160212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 170212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivipackage android.media; 180212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 190212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Triviimport android.annotation.SystemApi; 200212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Triviimport android.os.Parcel; 210212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Triviimport android.os.Parcelable; 220212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 230212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Triviimport java.util.Objects; 240212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 250212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi/** 260212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * @hide 270212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * A class to encapsulate information about an audio focus owner or request. 280212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi */ 290212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi@SystemApi 300212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivipublic final class AudioFocusInfo implements Parcelable { 310212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 3299489ccf740d369193a8ffc7eeb4bbde6919bd65Jean-Michel Trivi private final AudioAttributes mAttributes; 3399489ccf740d369193a8ffc7eeb4bbde6919bd65Jean-Michel Trivi private final int mClientUid; 3499489ccf740d369193a8ffc7eeb4bbde6919bd65Jean-Michel Trivi private final String mClientId; 3599489ccf740d369193a8ffc7eeb4bbde6919bd65Jean-Michel Trivi private final String mPackageName; 36461922fcfc8572415aa39c43c06afce685bd998dJean-Michel Trivi private final int mSdkTarget; 370212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi private int mGainRequest; 380212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi private int mLossReceived; 390212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi private int mFlags; 400212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 410212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 420212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi /** 430212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * Class constructor 440212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * @param aa 450212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * @param clientId 460212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * @param packageName 470212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * @param gainRequest 480212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * @param lossReceived 490212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * @param flags 506156017c2217d0fbbbb03434986250ec6bbd69d8John Spurlock * @hide 510212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi */ 5299489ccf740d369193a8ffc7eeb4bbde6919bd65Jean-Michel Trivi public AudioFocusInfo(AudioAttributes aa, int clientUid, String clientId, String packageName, 53461922fcfc8572415aa39c43c06afce685bd998dJean-Michel Trivi int gainRequest, int lossReceived, int flags, int sdk) { 540212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi mAttributes = aa == null ? new AudioAttributes.Builder().build() : aa; 5599489ccf740d369193a8ffc7eeb4bbde6919bd65Jean-Michel Trivi mClientUid = clientUid; 560212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi mClientId = clientId == null ? "" : clientId; 570212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi mPackageName = packageName == null ? "" : packageName; 580212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi mGainRequest = gainRequest; 590212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi mLossReceived = lossReceived; 600212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi mFlags = flags; 61461922fcfc8572415aa39c43c06afce685bd998dJean-Michel Trivi mSdkTarget = sdk; 620212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi } 630212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 640212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 650212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi /** 660212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * The audio attributes for the audio focus request. 670212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * @return non-null {@link AudioAttributes}. 680212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi */ 690212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi @SystemApi 700212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi public AudioAttributes getAttributes() { return mAttributes; } 710212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 720212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi @SystemApi 7399489ccf740d369193a8ffc7eeb4bbde6919bd65Jean-Michel Trivi public int getClientUid() { return mClientUid; } 7499489ccf740d369193a8ffc7eeb4bbde6919bd65Jean-Michel Trivi 7599489ccf740d369193a8ffc7eeb4bbde6919bd65Jean-Michel Trivi @SystemApi 760212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi public String getClientId() { return mClientId; } 770212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 780212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi @SystemApi 790212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi public String getPackageName() { return mPackageName; } 800212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 810212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi /** 820212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * The type of audio focus gain request. 830212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * @return one of {@link AudioManager#AUDIOFOCUS_GAIN}, 840212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT}, 850212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK}, 860212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE}. 870212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi */ 880212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi @SystemApi 890212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi public int getGainRequest() { return mGainRequest; } 900212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 910212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi /** 920212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * The type of audio focus loss that was received by the 930212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * {@link AudioManager.OnAudioFocusChangeListener} if one was set. 940212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * @return 0 if focus wasn't lost, or one of {@link AudioManager#AUDIOFOCUS_LOSS}, 950212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * {@link AudioManager#AUDIOFOCUS_LOSS_TRANSIENT} or 960212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * {@link AudioManager#AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK}. 970212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi */ 980212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi @SystemApi 990212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi public int getLossReceived() { return mLossReceived; } 1000212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 1010212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi /** @hide */ 102461922fcfc8572415aa39c43c06afce685bd998dJean-Michel Trivi public int getSdkTarget() { return mSdkTarget; } 103461922fcfc8572415aa39c43c06afce685bd998dJean-Michel Trivi 104461922fcfc8572415aa39c43c06afce685bd998dJean-Michel Trivi /** @hide */ 1056156017c2217d0fbbbb03434986250ec6bbd69d8John Spurlock public void clearLossReceived() { mLossReceived = 0; } 1060212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 1070212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi /** 1080212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * The flags set in the audio focus request. 1090212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * @return 0 or a combination of {link AudioManager#AUDIOFOCUS_FLAG_DELAY_OK}, 1100212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * {@link AudioManager#AUDIOFOCUS_FLAG_PAUSES_ON_DUCKABLE_LOSS}, and 1110212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi * {@link AudioManager#AUDIOFOCUS_FLAG_LOCK}. 1120212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi */ 1130212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi @SystemApi 1140212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi public int getFlags() { return mFlags; } 1150212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 1160212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi @Override 1170212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi public int describeContents() { 1180212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi return 0; 1190212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi } 1200212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 1210212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi @Override 1220212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi public void writeToParcel(Parcel dest, int flags) { 1230212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi mAttributes.writeToParcel(dest, flags); 12499489ccf740d369193a8ffc7eeb4bbde6919bd65Jean-Michel Trivi dest.writeInt(mClientUid); 1250212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi dest.writeString(mClientId); 1260212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi dest.writeString(mPackageName); 1270212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi dest.writeInt(mGainRequest); 1280212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi dest.writeInt(mLossReceived); 1290212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi dest.writeInt(mFlags); 130461922fcfc8572415aa39c43c06afce685bd998dJean-Michel Trivi dest.writeInt(mSdkTarget); 1310212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi } 1320212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 1330212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi @SystemApi 1340212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi @Override 1350212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi public int hashCode() { 13699489ccf740d369193a8ffc7eeb4bbde6919bd65Jean-Michel Trivi return Objects.hash(mAttributes, mClientUid, mClientId, mPackageName, mGainRequest, mFlags); 1370212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi } 1380212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 1390212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi @SystemApi 1400212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi @Override 1410212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi public boolean equals(Object obj) { 1420212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi if (this == obj) 1430212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi return true; 1440212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi if (obj == null) 1450212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi return false; 1460212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi if (getClass() != obj.getClass()) 1470212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi return false; 1480212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi AudioFocusInfo other = (AudioFocusInfo) obj; 1490212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi if (!mAttributes.equals(other.mAttributes)) { 1500212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi return false; 1510212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi } 15299489ccf740d369193a8ffc7eeb4bbde6919bd65Jean-Michel Trivi if (mClientUid != other.mClientUid) { 15399489ccf740d369193a8ffc7eeb4bbde6919bd65Jean-Michel Trivi return false; 15499489ccf740d369193a8ffc7eeb4bbde6919bd65Jean-Michel Trivi } 1550212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi if (!mClientId.equals(other.mClientId)) { 1560212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi return false; 1570212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi } 1580212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi if (!mPackageName.equals(other.mPackageName)) { 1590212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi return false; 1600212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi } 1610212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi if (mGainRequest != other.mGainRequest) { 1620212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi return false; 1630212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi } 1640212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi if (mLossReceived != other.mLossReceived) { 1650212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi return false; 1660212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi } 1670212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi if (mFlags != other.mFlags) { 1680212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi return false; 1690212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi } 170461922fcfc8572415aa39c43c06afce685bd998dJean-Michel Trivi if (mSdkTarget != other.mSdkTarget) { 171461922fcfc8572415aa39c43c06afce685bd998dJean-Michel Trivi return false; 172461922fcfc8572415aa39c43c06afce685bd998dJean-Michel Trivi } 1730212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi return true; 1740212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi } 1750212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 1760212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi public static final Parcelable.Creator<AudioFocusInfo> CREATOR 1770212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi = new Parcelable.Creator<AudioFocusInfo>() { 1780212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 1790212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi public AudioFocusInfo createFromParcel(Parcel in) { 1800212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi return new AudioFocusInfo( 1810212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi AudioAttributes.CREATOR.createFromParcel(in), //AudioAttributes aa 18299489ccf740d369193a8ffc7eeb4bbde6919bd65Jean-Michel Trivi in.readInt(), // int clientUid 1830212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi in.readString(), //String clientId 1840212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi in.readString(), //String packageName 1850212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi in.readInt(), //int gainRequest 1860212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi in.readInt(), //int lossReceived 187461922fcfc8572415aa39c43c06afce685bd998dJean-Michel Trivi in.readInt(), //int flags 188461922fcfc8572415aa39c43c06afce685bd998dJean-Michel Trivi in.readInt() //int sdkTarget 1890212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi ); 1900212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi } 1910212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi 1920212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi public AudioFocusInfo[] newArray(int size) { 1930212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi return new AudioFocusInfo[size]; 1940212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi } 1950212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi }; 1960212be5150fb9fb3c340f3c7e51f6126372cc6f9Jean-Michel Trivi} 197