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 0000000000000..1edccb4b288b8 --- /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 0000000000000..4b01736d67c4f --- /dev/null +++ b/core/tests/coretests/apks/install_complete_package_info/AndroidManifest.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + 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 0000000000000..10d0551a3a6f1 --- /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 0000000000000..59f9f10c6efe6 --- /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 0000000000000..21f6263a38bc5 --- /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 0000000000000..b330e75308f97 --- /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 9575cedb9b664..276f4f3c9a11f 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"; @@ -3130,6 +3133,92 @@ public class PackageManagerTests extends AndroidTestCase { assertNotNull("Verifier device identity should not be null", id); } + public void testGetInstalledPackages() { + List packages = getPm().getInstalledPackages(0); + assertNotNull("installed packages cannot be null", packages); + assertTrue("installed packages cannot be empty", packages.size() > 0); + } + + public void testGetUnInstalledPackages() { + List 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 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 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