Skip to content

Commit e15bdc2

Browse files
committed
Add test for failed dexopt
Bug: 7010829 Change-Id: Ie0616ff2c3739ad73733857de6d04243b2be2fca
1 parent 306df86 commit e15bdc2

File tree

7 files changed

+82
-4
lines changed

7 files changed

+82
-4
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
LOCAL_PATH:= $(call my-dir)
2+
include $(CLEAR_VARS)
3+
4+
LOCAL_SRC_FILES := $(call all-subdir-java-files)
5+
6+
LOCAL_PACKAGE_NAME := install_bad_dex
7+
8+
LOCAL_JAVA_RESOURCE_FILES := $(LOCAL_PATH)/classes.dex
9+
10+
include $(FrameworkCoreTests_BUILD_PACKAGE)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2010 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 xmlns:android="http://schemas.android.com/apk/res/android"
17+
package="com.android.frameworks.coretests.install_loc">
18+
19+
<application android:hasCode="true">
20+
<activity
21+
android:name="com.android.frameworks.coretests.TestActivity">
22+
</activity>
23+
</application>
24+
</manifest>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a bad dex
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<!-- Just need this dummy file to have something to build. -->
4+
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
5+
<string name="dummy">dummy</string>
6+
</resources>
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+
}

core/tests/coretests/apks/install_jni_lib/Android.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ LOCAL_SHARED_LIBRARIES := \
2323
libnativehelper
2424

2525
LOCAL_MODULE := libframeworks_coretests_jni
26-
LOCAL_MODULE_TAGS := optional
26+
LOCAL_MODULE_TAGS := tests
2727

2828
include $(BUILD_SHARED_LIBRARY)

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import android.os.ServiceManager;
4040
import android.os.StatFs;
4141
import android.os.SystemClock;
42+
import android.os.UserManager;
4243
import android.os.storage.IMountService;
4344
import android.os.storage.StorageListener;
4445
import android.os.storage.StorageManager;
@@ -562,6 +563,14 @@ private void assertNotInstalled(String pkgName) {
562563
fail(pkgName + " shouldnt be installed");
563564
} catch (NameNotFoundException e) {
564565
}
566+
567+
UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
568+
List<UserInfo> users = um.getUsers();
569+
for (UserInfo user : users) {
570+
String dataDir = PackageManager.getDataDirForUser(user.id, pkgName);
571+
assertFalse("Application data directory should not exist: " + dataDir,
572+
new File(dataDir).exists());
573+
}
565574
}
566575

567576
class InstallParams {
@@ -707,9 +716,7 @@ private void installFromRawResource(InstallParams ip, int flags, boolean cleanUp
707716
PackageManager.GET_UNINSTALLED_PACKAGES);
708717
GenericReceiver receiver = new DeleteReceiver(pkg.packageName);
709718
invokeDeletePackage(pkg.packageName, 0, receiver);
710-
} catch (NameNotFoundException e1) {
711-
} catch (Exception e) {
712-
failStr(e);
719+
} catch (NameNotFoundException e) {
713720
}
714721
}
715722
try {
@@ -3476,6 +3483,12 @@ public void testGetUnInstalledPackagesAll() throws Exception {
34763483
assertNotNull("signatures should not be null", packageInfo.signatures);
34773484
}
34783485

3486+
public void testInstall_BadDex_CleanUp() throws Exception {
3487+
int retCode = PackageManager.INSTALL_FAILED_DEXOPT;
3488+
installFromRawResource("install.apk", R.raw.install_bad_dex, 0, true, true, retCode,
3489+
PackageInfo.INSTALL_LOCATION_UNSPECIFIED);
3490+
}
3491+
34793492
/*---------- Recommended install location tests ----*/
34803493
/*
34813494
* TODO's

0 commit comments

Comments
 (0)