aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/android/org/inodes/gus/scummvm/PluginProvider.java
blob: 3c91d9f5dc86d5ffd2ed24f2af933f296bdca2e9 (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
49
50
51
52
53
54
package org.inodes.gus.scummvm;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

import java.util.ArrayList;

public class PluginProvider extends BroadcastReceiver {
	private final static String LOG_TAG = "ScummVM";

	public final static String META_UNPACK_LIB =
		"org.inodes.gus.scummvm.meta.UNPACK_LIB";

	public void onReceive(Context context, Intent intent) {
		if (!intent.getAction().equals(ScummVMApplication.ACTION_PLUGIN_QUERY))
			return;

		Bundle extras = getResultExtras(true);

		final ActivityInfo info;
		try {
			info = context.getPackageManager()
				.getReceiverInfo(new ComponentName(context, this.getClass()),
									PackageManager.GET_META_DATA);
		} catch (PackageManager.NameNotFoundException e) {
			Log.e(LOG_TAG, "Error finding my own info?", e);
			return;
		}

		String mylib = info.metaData.getString(META_UNPACK_LIB);
		if (mylib != null) {
			ArrayList<String> all_libs =
				extras.getStringArrayList(ScummVMApplication.EXTRA_UNPACK_LIBS);
			all_libs.add(new Uri.Builder()
							.scheme("plugin")
							.authority(context.getPackageName())
							.path(mylib)
							.toString());

			extras.putStringArrayList(ScummVMApplication.EXTRA_UNPACK_LIBS,
										all_libs);
		}

		setResultExtras(extras);
	}
}