diff options
author | Kenny Root <kroot@android.com> | 2012-06-15 16:43:29 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2012-06-15 16:43:29 -0700 |
commit | 535d3b3f3363af6a5f2acb620542baec4cb96b45 (patch) | |
tree | 89ed717ca1368b506e06d7254e2d185d2e5abf92 /core | |
parent | 15635728a4ff00da6cc3d6468c02d39e5631f124 (diff) | |
parent | 0cf342184e030ee6f65d87eeba48484725910a8b (diff) | |
download | frameworks_base-535d3b3f3363af6a5f2acb620542baec4cb96b45.zip frameworks_base-535d3b3f3363af6a5f2acb620542baec4cb96b45.tar.gz frameworks_base-535d3b3f3363af6a5f2acb620542baec4cb96b45.tar.bz2 |
am 0cf34218: Merge "Adding test cases for getInstalledPackages"
* commit '0cf342184e030ee6f65d87eeba48484725910a8b':
Adding test cases for getInstalledPackages
Diffstat (limited to 'core')
7 files changed, 322 insertions, 0 deletions
diff --git a/core/tests/coretests/apks/install_complete_package_info/Android.mk b/core/tests/coretests/apks/install_complete_package_info/Android.mk new file mode 100644 index 0000000..1edccb4 --- /dev/null +++ b/core/tests/coretests/apks/install_complete_package_info/Android.mk @@ -0,0 +1,11 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := tests + +LOCAL_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_PACKAGE_NAME := FrameworkCoreTests_install_complete_package_info + +include $(BUILD_PACKAGE) + diff --git a/core/tests/coretests/apks/install_complete_package_info/AndroidManifest.xml b/core/tests/coretests/apks/install_complete_package_info/AndroidManifest.xml new file mode 100644 index 0000000..4b01736 --- /dev/null +++ b/core/tests/coretests/apks/install_complete_package_info/AndroidManifest.xml @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2011 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<manifest + xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.frameworks.coretests.install_complete_package_info"> + +<!-- + This manifest declares at least one of each of the components that + can be retrieved by PackageManager.getInstalledPackages. + All the implementing classes are empty implementations +--> + + <uses-feature + android:name="com.android.frameworks.coretests.nonexistent" /> + <uses-configuration + android:reqFiveWayNav="false" /> + + <instrumentation + android:name="android.test.InstrumentationTestRunner" + android:targetPackage="com.android.frameworks.coretests" + android:label="Frameworks Core Tests" /> + + <permission + android:label="test permission" + android:name="test_permission" + android:protectionLevel="normal" /> + + <application + android:hasCode="true"> + <activity + android:name="com.android.frameworks.coretests.TestActivity"> + </activity> + <provider + android:name="com.android.frameworks.coretests.TestProvider" + android:authorities="com.android.frameworks.coretests.testprovider" /> + <receiver + android:name="com.android.frameworks.coretests.TestReceiver" /> + <service + android:name="com.android.frameworks.coretests.TestService" /> + </application> +</manifest> diff --git a/core/tests/coretests/apks/install_complete_package_info/src/com/android/frameworks/coretests/TestActivity.java b/core/tests/coretests/apks/install_complete_package_info/src/com/android/frameworks/coretests/TestActivity.java new file mode 100644 index 0000000..10d0551 --- /dev/null +++ b/core/tests/coretests/apks/install_complete_package_info/src/com/android/frameworks/coretests/TestActivity.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.android.frameworks.coretests; + +import android.app.Activity; + +public class TestActivity extends Activity { + +} diff --git a/core/tests/coretests/apks/install_complete_package_info/src/com/android/frameworks/coretests/TestProvider.java b/core/tests/coretests/apks/install_complete_package_info/src/com/android/frameworks/coretests/TestProvider.java new file mode 100644 index 0000000..59f9f10 --- /dev/null +++ b/core/tests/coretests/apks/install_complete_package_info/src/com/android/frameworks/coretests/TestProvider.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.android.frameworks.coretests; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.database.Cursor; +import android.net.Uri; + +public class TestProvider extends ContentProvider { + + @Override + public boolean onCreate() { + return false; + } + + @Override + public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, + String sortOrder) { + return null; + } + + @Override + public String getType(Uri uri) { + return null; + } + + @Override + public Uri insert(Uri uri, ContentValues values) { + return null; + } + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + return 0; + } + + @Override + public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { + return 0; + } +} diff --git a/core/tests/coretests/apks/install_complete_package_info/src/com/android/frameworks/coretests/TestReceiver.java b/core/tests/coretests/apks/install_complete_package_info/src/com/android/frameworks/coretests/TestReceiver.java new file mode 100644 index 0000000..21f6263 --- /dev/null +++ b/core/tests/coretests/apks/install_complete_package_info/src/com/android/frameworks/coretests/TestReceiver.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.android.frameworks.coretests; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.database.Cursor; +import android.net.Uri; + +public class TestReceiver extends ContentProvider { + + @Override + public boolean onCreate() { + return false; + } + + @Override + public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, + String sortOrder) { + return null; + } + + @Override + public String getType(Uri uri) { + return null; + } + + @Override + public Uri insert(Uri uri, ContentValues values) { + return null; + } + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + return 0; + } + + @Override + public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { + return 0; + } +} diff --git a/core/tests/coretests/apks/install_complete_package_info/src/com/android/frameworks/coretests/TestService.java b/core/tests/coretests/apks/install_complete_package_info/src/com/android/frameworks/coretests/TestService.java new file mode 100644 index 0000000..b330e75 --- /dev/null +++ b/core/tests/coretests/apks/install_complete_package_info/src/com/android/frameworks/coretests/TestService.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.android.frameworks.coretests; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; + +public class TestService extends Service { + + @Override + public IBinder onBind(Intent intent) { + return null; + } +} diff --git a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java index 77e4986..6e1b9d6 100755 --- a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java +++ b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java @@ -23,6 +23,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources; @@ -50,6 +51,8 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.util.List; + public class PackageManagerTests extends AndroidTestCase { private static final boolean localLOGV = true; public static final String TAG="PackageManagerTests"; @@ -3162,6 +3165,92 @@ public class PackageManagerTests extends AndroidTestCase { assertNotNull("Verifier device identity should not be null", id); } + public void testGetInstalledPackages() { + List<PackageInfo> packages = getPm().getInstalledPackages(0); + assertNotNull("installed packages cannot be null", packages); + assertTrue("installed packages cannot be empty", packages.size() > 0); + } + + public void testGetUnInstalledPackages() { + List<PackageInfo> packages = getPm().getInstalledPackages( + PackageManager.GET_UNINSTALLED_PACKAGES); + assertNotNull("installed packages cannot be null", packages); + assertTrue("installed packages cannot be empty", packages.size() > 0); + } + + /** + * Test that getInstalledPackages returns all the data specified in + * flags. + */ + public void testGetInstalledPackagesAll() { + int flags = PackageManager.GET_ACTIVITIES | PackageManager.GET_GIDS + | PackageManager.GET_CONFIGURATIONS | PackageManager.GET_INSTRUMENTATION + | PackageManager.GET_PERMISSIONS | PackageManager.GET_PROVIDERS + | PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES + | PackageManager.GET_SIGNATURES | PackageManager.GET_UNINSTALLED_PACKAGES; + + List<PackageInfo> packages = getPm().getInstalledPackages(flags); + assertNotNull("installed packages cannot be null", packages); + assertTrue("installed packages cannot be empty", packages.size() > 0); + + PackageInfo packageInfo = null; + + // Find the package with all components specified in the AndroidManifest + // to ensure no null values + for (PackageInfo pi : packages) { + if ("com.android.frameworks.coretests.install_complete_package_info" + .equals(pi.packageName)) { + packageInfo = pi; + break; + } + } + assertNotNull("activities should not be null", packageInfo.activities); + assertNotNull("configPreferences should not be null", packageInfo.configPreferences); + assertNotNull("instrumentation should not be null", packageInfo.instrumentation); + assertNotNull("permissions should not be null", packageInfo.permissions); + assertNotNull("providers should not be null", packageInfo.providers); + assertNotNull("receivers should not be null", packageInfo.receivers); + assertNotNull("services should not be null", packageInfo.services); + assertNotNull("signatures should not be null", packageInfo.signatures); + } + + /** + * Test that getInstalledPackages returns all the data specified in + * flags when the GET_UNINSTALLED_PACKAGES flag is set. + */ + public void testGetUnInstalledPackagesAll() { + int flags = PackageManager.GET_UNINSTALLED_PACKAGES + | PackageManager.GET_ACTIVITIES | PackageManager.GET_GIDS + | PackageManager.GET_CONFIGURATIONS | PackageManager.GET_INSTRUMENTATION + | PackageManager.GET_PERMISSIONS | PackageManager.GET_PROVIDERS + | PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES + | PackageManager.GET_SIGNATURES | PackageManager.GET_UNINSTALLED_PACKAGES; + + List<PackageInfo> packages = getPm().getInstalledPackages(flags); + assertNotNull("installed packages cannot be null", packages); + assertTrue("installed packages cannot be empty", packages.size() > 0); + + PackageInfo packageInfo = null; + + // Find the package with all components specified in the AndroidManifest + // to ensure no null values + for (PackageInfo pi : packages) { + if ("com.android.frameworks.coretests.install_complete_package_info" + .equals(pi.packageName)) { + packageInfo = pi; + break; + } + } + assertNotNull("activities should not be null", packageInfo.activities); + assertNotNull("configPreferences should not be null", packageInfo.configPreferences); + assertNotNull("instrumentation should not be null", packageInfo.instrumentation); + assertNotNull("permissions should not be null", packageInfo.permissions); + assertNotNull("providers should not be null", packageInfo.providers); + assertNotNull("receivers should not be null", packageInfo.receivers); + assertNotNull("services should not be null", packageInfo.services); + assertNotNull("signatures should not be null", packageInfo.signatures); + } + /*---------- Recommended install location tests ----*/ /* * TODO's |