Skip to content

Commit f2f1b6c

Browse files
Martin Wallgrenjredestig
authored andcommitted
Adding test cases for getInstalledPackages
There was an earlier fix for a case where the binder heap would run out of space when calling the getInstalledPackages. This could happen when there were a lot of installed packages. This change adds some test cases to verify that fix. Change-Id: I8e0c5f674bf2098adcff6d40893f94162961031f
1 parent 0748a56 commit f2f1b6c

File tree

7 files changed

+322
-0
lines changed

7 files changed

+322
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
LOCAL_PATH:= $(call my-dir)
2+
include $(CLEAR_VARS)
3+
4+
LOCAL_MODULE_TAGS := tests
5+
6+
LOCAL_SRC_FILES := $(call all-subdir-java-files)
7+
8+
LOCAL_PACKAGE_NAME := FrameworkCoreTests_install_complete_package_info
9+
10+
include $(BUILD_PACKAGE)
11+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2011 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<manifest
17+
xmlns:android="http://schemas.android.com/apk/res/android"
18+
package="com.android.frameworks.coretests.install_complete_package_info">
19+
20+
<!--
21+
This manifest declares at least one of each of the components that
22+
can be retrieved by PackageManager.getInstalledPackages.
23+
All the implementing classes are empty implementations
24+
-->
25+
26+
<uses-feature
27+
android:name="com.android.frameworks.coretests.nonexistent" />
28+
<uses-configuration
29+
android:reqFiveWayNav="false" />
30+
31+
<instrumentation
32+
android:name="android.test.InstrumentationTestRunner"
33+
android:targetPackage="com.android.frameworks.coretests"
34+
android:label="Frameworks Core Tests" />
35+
36+
<permission
37+
android:label="test permission"
38+
android:name="test_permission"
39+
android:protectionLevel="normal" />
40+
41+
<application
42+
android:hasCode="true">
43+
<activity
44+
android:name="com.android.frameworks.coretests.TestActivity">
45+
</activity>
46+
<provider
47+
android:name="com.android.frameworks.coretests.TestProvider"
48+
android:authorities="com.android.frameworks.coretests.testprovider" />
49+
<receiver
50+
android:name="com.android.frameworks.coretests.TestReceiver" />
51+
<service
52+
android:name="com.android.frameworks.coretests.TestService" />
53+
</application>
54+
</manifest>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (C) 2011 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package com.android.frameworks.coretests;
19+
20+
import android.app.Activity;
21+
22+
public class TestActivity extends Activity {
23+
24+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (C) 2011 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package com.android.frameworks.coretests;
19+
20+
import android.content.ContentProvider;
21+
import android.content.ContentValues;
22+
import android.database.Cursor;
23+
import android.net.Uri;
24+
25+
public class TestProvider extends ContentProvider {
26+
27+
@Override
28+
public boolean onCreate() {
29+
return false;
30+
}
31+
32+
@Override
33+
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
34+
String sortOrder) {
35+
return null;
36+
}
37+
38+
@Override
39+
public String getType(Uri uri) {
40+
return null;
41+
}
42+
43+
@Override
44+
public Uri insert(Uri uri, ContentValues values) {
45+
return null;
46+
}
47+
48+
@Override
49+
public int delete(Uri uri, String selection, String[] selectionArgs) {
50+
return 0;
51+
}
52+
53+
@Override
54+
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
55+
return 0;
56+
}
57+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (C) 2011 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package com.android.frameworks.coretests;
19+
20+
import android.content.ContentProvider;
21+
import android.content.ContentValues;
22+
import android.database.Cursor;
23+
import android.net.Uri;
24+
25+
public class TestReceiver extends ContentProvider {
26+
27+
@Override
28+
public boolean onCreate() {
29+
return false;
30+
}
31+
32+
@Override
33+
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
34+
String sortOrder) {
35+
return null;
36+
}
37+
38+
@Override
39+
public String getType(Uri uri) {
40+
return null;
41+
}
42+
43+
@Override
44+
public Uri insert(Uri uri, ContentValues values) {
45+
return null;
46+
}
47+
48+
@Override
49+
public int delete(Uri uri, String selection, String[] selectionArgs) {
50+
return 0;
51+
}
52+
53+
@Override
54+
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
55+
return 0;
56+
}
57+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2011 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package com.android.frameworks.coretests;
19+
20+
import android.app.Service;
21+
import android.content.Intent;
22+
import android.os.IBinder;
23+
24+
public class TestService extends Service {
25+
26+
@Override
27+
public IBinder onBind(Intent intent) {
28+
return null;
29+
}
30+
}

core/tests/coretests/src/android/content/pm/PackageManagerTests.java

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.content.Context;
2424
import android.content.Intent;
2525
import android.content.IntentFilter;
26+
import android.content.pm.PackageInfo;
2627
import android.content.pm.PackageManager;
2728
import android.content.pm.PackageManager.NameNotFoundException;
2829
import android.content.res.Resources;
@@ -50,6 +51,8 @@
5051
import java.io.IOException;
5152
import java.io.InputStream;
5253

54+
import java.util.List;
55+
5356
public class PackageManagerTests extends AndroidTestCase {
5457
private static final boolean localLOGV = true;
5558
public static final String TAG="PackageManagerTests";
@@ -3130,6 +3133,92 @@ public void testGetVerifierDeviceIdentity() {
31303133
assertNotNull("Verifier device identity should not be null", id);
31313134
}
31323135

3136+
public void testGetInstalledPackages() {
3137+
List<PackageInfo> packages = getPm().getInstalledPackages(0);
3138+
assertNotNull("installed packages cannot be null", packages);
3139+
assertTrue("installed packages cannot be empty", packages.size() > 0);
3140+
}
3141+
3142+
public void testGetUnInstalledPackages() {
3143+
List<PackageInfo> packages = getPm().getInstalledPackages(
3144+
PackageManager.GET_UNINSTALLED_PACKAGES);
3145+
assertNotNull("installed packages cannot be null", packages);
3146+
assertTrue("installed packages cannot be empty", packages.size() > 0);
3147+
}
3148+
3149+
/**
3150+
* Test that getInstalledPackages returns all the data specified in
3151+
* flags.
3152+
*/
3153+
public void testGetInstalledPackagesAll() {
3154+
int flags = PackageManager.GET_ACTIVITIES | PackageManager.GET_GIDS
3155+
| PackageManager.GET_CONFIGURATIONS | PackageManager.GET_INSTRUMENTATION
3156+
| PackageManager.GET_PERMISSIONS | PackageManager.GET_PROVIDERS
3157+
| PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES
3158+
| PackageManager.GET_SIGNATURES | PackageManager.GET_UNINSTALLED_PACKAGES;
3159+
3160+
List<PackageInfo> packages = getPm().getInstalledPackages(flags);
3161+
assertNotNull("installed packages cannot be null", packages);
3162+
assertTrue("installed packages cannot be empty", packages.size() > 0);
3163+
3164+
PackageInfo packageInfo = null;
3165+
3166+
// Find the package with all components specified in the AndroidManifest
3167+
// to ensure no null values
3168+
for (PackageInfo pi : packages) {
3169+
if ("com.android.frameworks.coretests.install_complete_package_info"
3170+
.equals(pi.packageName)) {
3171+
packageInfo = pi;
3172+
break;
3173+
}
3174+
}
3175+
assertNotNull("activities should not be null", packageInfo.activities);
3176+
assertNotNull("configPreferences should not be null", packageInfo.configPreferences);
3177+
assertNotNull("instrumentation should not be null", packageInfo.instrumentation);
3178+
assertNotNull("permissions should not be null", packageInfo.permissions);
3179+
assertNotNull("providers should not be null", packageInfo.providers);
3180+
assertNotNull("receivers should not be null", packageInfo.receivers);
3181+
assertNotNull("services should not be null", packageInfo.services);
3182+
assertNotNull("signatures should not be null", packageInfo.signatures);
3183+
}
3184+
3185+
/**
3186+
* Test that getInstalledPackages returns all the data specified in
3187+
* flags when the GET_UNINSTALLED_PACKAGES flag is set.
3188+
*/
3189+
public void testGetUnInstalledPackagesAll() {
3190+
int flags = PackageManager.GET_UNINSTALLED_PACKAGES
3191+
| PackageManager.GET_ACTIVITIES | PackageManager.GET_GIDS
3192+
| PackageManager.GET_CONFIGURATIONS | PackageManager.GET_INSTRUMENTATION
3193+
| PackageManager.GET_PERMISSIONS | PackageManager.GET_PROVIDERS
3194+
| PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES
3195+
| PackageManager.GET_SIGNATURES | PackageManager.GET_UNINSTALLED_PACKAGES;
3196+
3197+
List<PackageInfo> packages = getPm().getInstalledPackages(flags);
3198+
assertNotNull("installed packages cannot be null", packages);
3199+
assertTrue("installed packages cannot be empty", packages.size() > 0);
3200+
3201+
PackageInfo packageInfo = null;
3202+
3203+
// Find the package with all components specified in the AndroidManifest
3204+
// to ensure no null values
3205+
for (PackageInfo pi : packages) {
3206+
if ("com.android.frameworks.coretests.install_complete_package_info"
3207+
.equals(pi.packageName)) {
3208+
packageInfo = pi;
3209+
break;
3210+
}
3211+
}
3212+
assertNotNull("activities should not be null", packageInfo.activities);
3213+
assertNotNull("configPreferences should not be null", packageInfo.configPreferences);
3214+
assertNotNull("instrumentation should not be null", packageInfo.instrumentation);
3215+
assertNotNull("permissions should not be null", packageInfo.permissions);
3216+
assertNotNull("providers should not be null", packageInfo.providers);
3217+
assertNotNull("receivers should not be null", packageInfo.receivers);
3218+
assertNotNull("services should not be null", packageInfo.services);
3219+
assertNotNull("signatures should not be null", packageInfo.signatures);
3220+
}
3221+
31333222
/*---------- Recommended install location tests ----*/
31343223
/*
31353224
* TODO's

0 commit comments

Comments
 (0)