Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c32e6dfb authored by Marco Nelissen's avatar Marco Nelissen Committed by Android Git Automerger
Browse files

am 6cbaa773: Merge "resolved conflicts for merge of 375e21f8 to...

am 6cbaa773: Merge "resolved conflicts for merge of 375e21f8 to mnc-dev-plus-aosp" into mnc-dev-plus-aosp

* commit '6cbaa773':
  Sometimes the application context is null
parents e1399152 6cbaa773
Loading
Loading
Loading
Loading
+48 −28
Original line number Diff line number Diff line
@@ -57,7 +57,8 @@ import java.util.Iterator;
 */
public class AudioManager {

    private final Context mApplicationContext;
    private Context mOriginalContext;
    private Context mApplicationContext;
    private long mVolumeKeyUpTime;
    private final boolean mUseVolumeKeySounds;
    private final boolean mUseFixedVolume;
@@ -621,14 +622,33 @@ public class AudioManager {
     * @hide
     */
    public AudioManager(Context context) {
        mApplicationContext = context;
        mUseVolumeKeySounds = mApplicationContext.getResources().getBoolean(
        setContext(context);
        mUseVolumeKeySounds = getContext().getResources().getBoolean(
                com.android.internal.R.bool.config_useVolumeKeySounds);
        mUseFixedVolume = mApplicationContext.getResources().getBoolean(
        mUseFixedVolume = getContext().getResources().getBoolean(
                com.android.internal.R.bool.config_useFixedVolume);
        sAudioPortEventHandler.init();
    }

    private Context getContext() {
        if (mApplicationContext == null) {
            setContext(mOriginalContext);
        }
        if (mApplicationContext != null) {
            return mApplicationContext;
        }
        return mOriginalContext;
    }

    private void setContext(Context context) {
        mApplicationContext = context.getApplicationContext();
        if (mApplicationContext != null) {
            mOriginalContext = null;
        } else {
            mOriginalContext = context;
        }
    }

    private static IAudioService getService()
    {
        if (sService != null) {
@@ -663,7 +683,7 @@ public class AudioManager {
     *     or {@link KeyEvent#KEYCODE_MEDIA_AUDIO_TRACK}.
     */
    public void dispatchMediaKeyEvent(KeyEvent keyEvent) {
        MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mApplicationContext);
        MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(getContext());
        helper.sendMediaButtonEvent(keyEvent, false);
    }

@@ -709,7 +729,7 @@ public class AudioManager {
                break;
            case KeyEvent.KEYCODE_VOLUME_MUTE:
                if (event.getRepeatCount() == 0) {
                    MediaSessionLegacyHelper.getHelper(mApplicationContext)
                    MediaSessionLegacyHelper.getHelper(getContext())
                            .sendVolumeKeyEvent(event, false);
                }
                break;
@@ -737,7 +757,7 @@ public class AudioManager {
                mVolumeKeyUpTime = SystemClock.uptimeMillis();
                break;
            case KeyEvent.KEYCODE_VOLUME_MUTE:
                MediaSessionLegacyHelper.getHelper(mApplicationContext)
                MediaSessionLegacyHelper.getHelper(getContext())
                        .sendVolumeKeyEvent(event, false);
                break;
        }
@@ -783,7 +803,7 @@ public class AudioManager {
        IAudioService service = getService();
        try {
            service.adjustStreamVolume(streamType, direction, flags,
                    mApplicationContext.getOpPackageName());
                    getContext().getOpPackageName());
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in adjustStreamVolume", e);
        }
@@ -813,7 +833,7 @@ public class AudioManager {
     * @see #isVolumeFixed()
     */
    public void adjustVolume(int direction, int flags) {
        MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mApplicationContext);
        MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(getContext());
        helper.sendAdjustVolumeBy(USE_DEFAULT_STREAM_TYPE, direction, flags);
    }

@@ -842,7 +862,7 @@ public class AudioManager {
     * @see #isVolumeFixed()
     */
    public void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags) {
        MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mApplicationContext);
        MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(getContext());
        helper.sendAdjustVolumeBy(suggestedStreamType, direction, flags);
    }

@@ -850,7 +870,7 @@ public class AudioManager {
    public void setMasterMute(boolean mute, int flags) {
        IAudioService service = getService();
        try {
            service.setMasterMute(mute, flags, mApplicationContext.getOpPackageName());
            service.setMasterMute(mute, flags, getContext().getOpPackageName());
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in setMasterMute", e);
        }
@@ -997,7 +1017,7 @@ public class AudioManager {
        }
        IAudioService service = getService();
        try {
            service.setRingerModeExternal(ringerMode, mApplicationContext.getOpPackageName());
            service.setRingerModeExternal(ringerMode, getContext().getOpPackageName());
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in setRingerMode", e);
        }
@@ -1018,7 +1038,7 @@ public class AudioManager {
    public void setStreamVolume(int streamType, int index, int flags) {
        IAudioService service = getService();
        try {
            service.setStreamVolume(streamType, index, flags, mApplicationContext.getOpPackageName());
            service.setStreamVolume(streamType, index, flags, getContext().getOpPackageName());
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in setStreamVolume", e);
        }
@@ -1331,7 +1351,7 @@ public class AudioManager {
     * @see #startBluetoothSco()
    */
    public boolean isBluetoothScoAvailableOffCall() {
        return mApplicationContext.getResources().getBoolean(
        return getContext().getResources().getBoolean(
               com.android.internal.R.bool.config_bluetooth_sco_off_call);
    }

@@ -1384,7 +1404,7 @@ public class AudioManager {
        IAudioService service = getService();
        try {
            service.startBluetoothSco(mICallBack,
                    mApplicationContext.getApplicationInfo().targetSdkVersion);
                    getContext().getApplicationInfo().targetSdkVersion);
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in startBluetoothSco", e);
        }
@@ -1532,7 +1552,7 @@ public class AudioManager {
    public void setMicrophoneMute(boolean on){
        IAudioService service = getService();
        try {
            service.setMicrophoneMute(on, mApplicationContext.getOpPackageName());
            service.setMicrophoneMute(on, getContext().getOpPackageName());
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in setMicrophoneMute", e);
        }
@@ -1963,7 +1983,7 @@ public class AudioManager {
     * Settings has an in memory cache, so this is fast.
     */
    private boolean querySoundEffectsEnabled(int user) {
        return Settings.System.getIntForUser(mApplicationContext.getContentResolver(),
        return Settings.System.getIntForUser(getContext().getContentResolver(),
                Settings.System.SOUND_EFFECTS_ENABLED, 0, user) != 0;
    }

@@ -2375,7 +2395,7 @@ public class AudioManager {
        try {
            status = service.requestAudioFocus(requestAttributes, durationHint, mICallBack,
                    mAudioFocusDispatcher, getIdForAudioFocusListener(l),
                    mApplicationContext.getOpPackageName() /* package name */, flags,
                    getContext().getOpPackageName() /* package name */, flags,
                    ap != null ? ap.cb() : null);
        } catch (RemoteException e) {
            Log.e(TAG, "Can't call requestAudioFocus() on AudioService:", e);
@@ -2400,7 +2420,7 @@ public class AudioManager {
                        .setInternalLegacyStreamType(streamType).build(),
                    durationHint, mICallBack, null,
                    AudioSystem.IN_VOICE_COMM_FOCUS_ID,
                    mApplicationContext.getOpPackageName(),
                    getContext().getOpPackageName(),
                    AUDIOFOCUS_FLAG_LOCK,
                    null /* policy token */);
        } catch (RemoteException e) {
@@ -2469,7 +2489,7 @@ public class AudioManager {
        if (eventReceiver == null) {
            return;
        }
        if (!eventReceiver.getPackageName().equals(mApplicationContext.getPackageName())) {
        if (!eventReceiver.getPackageName().equals(getContext().getPackageName())) {
            Log.e(TAG, "registerMediaButtonEventReceiver() error: " +
                    "receiver and context package names don't match");
            return;
@@ -2478,7 +2498,7 @@ public class AudioManager {
        Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
        //     the associated intent will be handled by the component being registered
        mediaButtonIntent.setComponent(eventReceiver);
        PendingIntent pi = PendingIntent.getBroadcast(mApplicationContext,
        PendingIntent pi = PendingIntent.getBroadcast(getContext(),
                0/*requestCode, ignored*/, mediaButtonIntent, 0/*flags*/);
        registerMediaButtonIntent(pi, eventReceiver);
    }
@@ -2512,8 +2532,8 @@ public class AudioManager {
            Log.e(TAG, "Cannot call registerMediaButtonIntent() with a null parameter");
            return;
        }
        MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mApplicationContext);
        helper.addMediaButtonListener(pi, eventReceiver, mApplicationContext);
        MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(getContext());
        helper.addMediaButtonListener(pi, eventReceiver, getContext());
    }

    /**
@@ -2531,7 +2551,7 @@ public class AudioManager {
        Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
        //     the associated intent will be handled by the component being registered
        mediaButtonIntent.setComponent(eventReceiver);
        PendingIntent pi = PendingIntent.getBroadcast(mApplicationContext,
        PendingIntent pi = PendingIntent.getBroadcast(getContext(),
                0/*requestCode, ignored*/, mediaButtonIntent, 0/*flags*/);
        unregisterMediaButtonIntent(pi);
    }
@@ -2554,7 +2574,7 @@ public class AudioManager {
     * @hide
     */
    public void unregisterMediaButtonIntent(PendingIntent pi) {
        MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mApplicationContext);
        MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(getContext());
        helper.removeMediaButtonListener(pi);
    }

@@ -2571,7 +2591,7 @@ public class AudioManager {
        if ((rcClient == null) || (rcClient.getRcMediaIntent() == null)) {
            return;
        }
        rcClient.registerWithSession(MediaSessionLegacyHelper.getHelper(mApplicationContext));
        rcClient.registerWithSession(MediaSessionLegacyHelper.getHelper(getContext()));
    }

    /**
@@ -2586,7 +2606,7 @@ public class AudioManager {
        if ((rcClient == null) || (rcClient.getRcMediaIntent() == null)) {
            return;
        }
        rcClient.unregisterWithSession(MediaSessionLegacyHelper.getHelper(mApplicationContext));
        rcClient.unregisterWithSession(MediaSessionLegacyHelper.getHelper(getContext()));
    }

    /**
@@ -3280,7 +3300,7 @@ public class AudioManager {
     */
    public void setRingerModeInternal(int ringerMode) {
        try {
            getService().setRingerModeInternal(ringerMode, mApplicationContext.getOpPackageName());
            getService().setRingerModeInternal(ringerMode, getContext().getOpPackageName());
        } catch (RemoteException e) {
            Log.w(TAG, "Error calling setRingerModeInternal", e);
        }