]>
Commit | Line | Data |
---|---|---|
7cb8f570 TB |
1 | /* |
2 | * Copyright (C) 2013 Tobias Brunner | |
3 | * Copyright (C) 2012 Christoph Buehler | |
4 | * Copyright (C) 2012 Patrick Loetscher | |
5 | * Hochschule fuer Technik Rapperswil | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2 of the License, or (at your | |
10 | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
14 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | * for more details. | |
16 | */ | |
17 | ||
18 | package org.strongswan.android.logic.imc.collectors; | |
19 | ||
20 | import java.util.List; | |
21 | ||
22 | import org.strongswan.android.logic.imc.attributes.Attribute; | |
23 | import org.strongswan.android.logic.imc.attributes.InstalledPackagesAttribute; | |
24 | ||
25 | import android.content.Context; | |
26 | import android.content.pm.ApplicationInfo; | |
27 | import android.content.pm.PackageInfo; | |
28 | import android.content.pm.PackageManager; | |
29 | ||
30 | public class InstalledPackagesCollector implements Collector | |
31 | { | |
32 | private final PackageManager mPackageManager; | |
33 | ||
34 | public InstalledPackagesCollector(Context context) | |
35 | { | |
36 | mPackageManager = context.getPackageManager(); | |
37 | } | |
38 | ||
39 | @Override | |
40 | public Attribute getMeasurement() | |
41 | { | |
42 | InstalledPackagesAttribute attribute = new InstalledPackagesAttribute(); | |
43 | List<PackageInfo> packages = mPackageManager.getInstalledPackages(0); | |
44 | for (PackageInfo info : packages) | |
45 | { | |
46 | if ((info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 || | |
47 | info.packageName == null || info.versionName == null) | |
48 | { /* ignore packages installed in the system image */ | |
49 | continue; | |
50 | } | |
51 | attribute.addPackage(info.packageName, info.versionName); | |
52 | } | |
53 | return attribute; | |
54 | } | |
55 | } |