am b0512c37: Merge "Fix check for required features" into honeycomb

* commit 'b0512c372587f366f0b0bd859b22a344a5d5a520':
  Fix check for required features
This commit is contained in:
Kenny Root
2011-01-09 07:16:50 -08:00
committed by Android Git Automerger
6 changed files with 65 additions and 18 deletions

View File

@@ -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_uses_feature
include $(BUILD_PACKAGE)

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2010 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_uses_feature">
<uses-feature android:name="com.android.frameworks.coretests.nonexistent" />
<application android:hasCode="false">
</application>
</manifest>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Just need this dummy file to have something to build. -->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="dummy">dummy</string>
</resources>

Binary file not shown.

View File

@@ -23,6 +23,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
@@ -215,7 +216,7 @@ public class PackageManagerTests extends AndroidTestCase {
}
}
public void invokeInstallPackageFail(Uri packageURI, int flags, int result) {
public void invokeInstallPackageFail(Uri packageURI, int flags, int expectedResult) {
PackageInstallObserver observer = new PackageInstallObserver();
try {
// Wait on observer
@@ -233,7 +234,7 @@ public class PackageManagerTests extends AndroidTestCase {
if(!observer.isDone()) {
fail("Timed out waiting for packageInstalled callback");
}
assertEquals(observer.returnCode, result);
assertEquals(expectedResult, observer.returnCode);
}
} finally {
}
@@ -2838,6 +2839,13 @@ public class PackageManagerTests extends AndroidTestCase {
installFromRawResource("install.apk", rapk2, PackageManager.INSTALL_REPLACE_EXISTING, true,
fail, retCode, PackageInfo.INSTALL_LOCATION_UNSPECIFIED);
}
@LargeTest
public void testUsesFeatureMissingFeature() {
int retCode = PackageManager.INSTALL_FAILED_MISSING_FEATURE;
installFromRawResource("install.apk", R.raw.install_uses_feature, 0, true, true, retCode,
PackageInfo.INSTALL_LOCATION_UNSPECIFIED);
}
/*---------- Recommended install location tests ----*/
/*
* TODO's

View File

@@ -2927,24 +2927,23 @@ class PackageManagerService extends IPackageManager.Stub {
System.arraycopy(mTmpSharedLibraries, 0,
pkg.usesLibraryFiles, 0, num);
}
}
if (pkg.reqFeatures != null) {
N = pkg.reqFeatures.size();
for (int i=0; i<N; i++) {
FeatureInfo fi = pkg.reqFeatures.get(i);
if ((fi.flags&FeatureInfo.FLAG_REQUIRED) == 0) {
// Don't care.
continue;
}
if (pkg.reqFeatures != null) {
int N = pkg.reqFeatures.size();
for (int i = 0; i < N; i++) {
FeatureInfo fi = pkg.reqFeatures.get(i);
if ((fi.flags & FeatureInfo.FLAG_REQUIRED) == 0) {
// Don't care.
continue;
}
if (fi.name != null) {
if (mAvailableFeatures.get(fi.name) == null) {
Slog.e(TAG, "Package " + pkg.packageName
+ " requires unavailable feature "
+ fi.name + "; failing!");
mLastScanError = PackageManager.INSTALL_FAILED_MISSING_FEATURE;
return null;
}
if (fi.name != null) {
if (mAvailableFeatures.get(fi.name) == null) {
Slog.e(TAG, "Package " + pkg.packageName
+ " requires unavailable feature " + fi.name + "; failing!");
mLastScanError = PackageManager.INSTALL_FAILED_MISSING_FEATURE;
return null;
}
}
}