Resolve CTS apk can't get PackageInstaller's widget.
Bug 29084996
Change-Id: Ic2ac0ff8cc662ce11f51e6dd3d5346ecaff93235
diff --git a/hostsidetests/devicepolicy/app/PackageInstaller/src/com/android/cts/packageinstaller/BasePackageInstallTest.java b/hostsidetests/devicepolicy/app/PackageInstaller/src/com/android/cts/packageinstaller/BasePackageInstallTest.java
old mode 100644
new mode 100755
index f994e9e..1d1760d
--- a/hostsidetests/devicepolicy/app/PackageInstaller/src/com/android/cts/packageinstaller/BasePackageInstallTest.java
+++ b/hostsidetests/devicepolicy/app/PackageInstaller/src/com/android/cts/packageinstaller/BasePackageInstallTest.java
@@ -15,6 +15,7 @@
*/
package com.android.cts.packageinstaller;
+import android.net.Uri;
import android.app.PendingIntent;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
@@ -57,6 +58,7 @@
protected boolean mCallbackReceived;
protected int mCallbackStatus;
protected Intent mCallbackIntent;
+ public static String instllerPkgName="";
protected final Object mPackageInstallerTimeoutLock = new Object();
@@ -88,6 +90,10 @@
mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
mPackageManager = mContext.getPackageManager();
mPackageInstaller = mPackageManager.getPackageInstaller();
+ Intent intent=new Intent("android.intent.action.INSTALL_PACKAGE");
+ intent.setData(Uri.parse("package:"));
+ instllerPkgName = mPackageManager.queryIntentActivities(
+ intent, PackageManager.MATCH_DEFAULT_ONLY).get(0).activityInfo.packageName;
assertNotNull(mPackageInstaller);
// check that app is not already installed
diff --git a/hostsidetests/devicepolicy/app/PackageInstaller/src/com/android/cts/packageinstaller/ManualPackageInstallTest.java b/hostsidetests/devicepolicy/app/PackageInstaller/src/com/android/cts/packageinstaller/ManualPackageInstallTest.java
old mode 100644
new mode 100755
index 96affae..438a7e2
--- a/hostsidetests/devicepolicy/app/PackageInstaller/src/com/android/cts/packageinstaller/ManualPackageInstallTest.java
+++ b/hostsidetests/devicepolicy/app/PackageInstaller/src/com/android/cts/packageinstaller/ManualPackageInstallTest.java
@@ -30,18 +30,9 @@
private static final int AUTOMATOR_WAIT_TIMEOUT = 5000;
private static final int INSTALL_WAIT_TIME = 5000;
- private static final BySelector POPUP_BUTTON_SELECTOR = By
- .clazz(android.widget.Button.class.getName())
- .res("android:id/button1")
- .pkg("com.google.android.packageinstaller");
- private static final BySelector POPUP_TEXT_SELECTOR = By
- .clazz(android.widget.TextView.class.getName())
- .res("android:id/alertTitle")
- .pkg("com.google.android.packageinstaller");
- private static final BySelector INSTALL_BUTTON_SELECTOR = By
- .clazz(android.widget.Button.class.getName())
- .res("com.android.packageinstaller:id/ok_button")
- .pkg("com.google.android.packageinstaller");
+ private static BySelector POPUP_BUTTON_SELECTOR = null;
+ private static BySelector POPUP_TEXT_SELECTOR = null;
+ private static BySelector INSTALL_BUTTON_SELECTOR = null;
public void testManualInstallSucceeded() throws Exception {
assertInstallPackage();
@@ -99,6 +90,10 @@
}
private void automateInstallClick() {
+ if(null == INSTALL_BUTTON_SELECTOR)INSTALL_BUTTON_SELECTOR = By
+ .clazz(android.widget.Button.class.getName())
+ .res("com.android.packageinstaller:id/ok_button")
+ .pkg(instllerPkgName);
mDevice.wait(Until.hasObject(INSTALL_BUTTON_SELECTOR), AUTOMATOR_WAIT_TIMEOUT);
UiObject2 button = mDevice.findObject(INSTALL_BUTTON_SELECTOR);
assertNotNull("Install button not found", button);
@@ -106,10 +101,18 @@
}
private void automateDismissInstallBlockedDialog() {
+ if(null == POPUP_TEXT_SELECTOR)POPUP_TEXT_SELECTOR = By
+ .clazz(android.widget.TextView.class.getName())
+ .res("android:id/alertTitle")
+ .pkg(instllerPkgName);
mDevice.wait(Until.hasObject(POPUP_TEXT_SELECTOR), AUTOMATOR_WAIT_TIMEOUT);
UiObject2 text = mDevice.findObject(POPUP_TEXT_SELECTOR);
assertNotNull("Alert dialog not found", text);
// "OK" button only present in the dialog if it is blocked by policy.
+ if(null == POPUP_BUTTON_SELECTOR)POPUP_BUTTON_SELECTOR = By
+ .clazz(android.widget.Button.class.getName())
+ .res("android:id/button1")
+ .pkg(instllerPkgName);
UiObject2 button = mDevice.findObject(POPUP_BUTTON_SELECTOR);
assertNotNull("OK button not found", button);
button.click();