am 0cf34218: Merge "Adding test cases for getInstalledPackages"
* commit '0cf342184e030ee6f65d87eeba48484725910a8b': Adding test cases for getInstalledPackages
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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>
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user