summaryrefslogtreecommitdiffstats
path: root/src/org/cyanogenmod/audiofx/audiofx/receiver/ServiceDispatcher.java
blob: 7581ba2478fbe130632d705a17d4a46c63c18332 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

package com.cyngn.audiofx.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.audiofx.AudioEffect;
import android.util.Log;

import com.cyngn.audiofx.service.AudioFxService;

import cyanogenmod.media.AudioSessionInfo;
import cyanogenmod.media.CMAudioManager;

public class ServiceDispatcher extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

        Intent service = new Intent(context.getApplicationContext(), AudioFxService.class);
        String action = intent.getAction();

        // We can also get AUDIO_BECOMING_NOISY, which means a device change is
        // coming and we should wake up to handle it.
        if (action.equals(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION) ||
                action.equals(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION)) {
            int sessionId = intent.getIntExtra(AudioEffect.EXTRA_AUDIO_SESSION, 0);
            String pkg = intent.getStringExtra(AudioEffect.EXTRA_PACKAGE_NAME);
            service.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, sessionId);
            service.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, pkg);

        } else if (action.equals(CMAudioManager.ACTION_AUDIO_SESSIONS_CHANGED)) {

            // callback from CMAudioService
            final AudioSessionInfo info = (AudioSessionInfo) intent.getParcelableExtra(
                    CMAudioManager.EXTRA_SESSION_INFO);
            boolean added = intent.getBooleanExtra(CMAudioManager.EXTRA_SESSION_ADDED, false);
            service.putExtra(CMAudioManager.EXTRA_SESSION_INFO, info);
            service.putExtra(CMAudioManager.EXTRA_SESSION_ADDED, added);
        }

        service.setAction(action);
        context.startService(service);
        if (AudioFxService.DEBUG) {
            Log.d("AudioFX-Dispatcher", "Received " + action);
        }

    }
}