CTS: android.text.method.cts related tests failing
Fixed the following failing cases due to new permission change in
M by setting appops to allow android:write_settings during test
before operation is executed.
PasswordTransformationMethodTest#testConstructor
PasswordTransformationMethodTest#testGetInstance
PasswordTransformationMethodTest#testGetTransformation
PasswordTransformationMethodTest#testOnFocusChanged
PasswordTransformationMethodTest#testTextChangedCallBacks
Change-Id: I17e0b78f3e104ba02ff3fc236ffec9c7bb5e3306
Signed-off-by: Dou,lilix <lilix.dou@intel.com>
diff --git a/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java b/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java
index 4262a31..72a8e72 100644
--- a/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java
@@ -19,6 +19,7 @@
import android.cts.util.PollingCheck;
import android.graphics.Rect;
+import android.os.ParcelFileDescriptor;
import android.provider.Settings.SettingNotFoundException;
import android.provider.Settings.System;
import android.test.ActivityInstrumentationTestCase2;
@@ -31,6 +32,10 @@
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Scanner;
+
/**
* Test {@link PasswordTransformationMethod}.
*/
@@ -97,10 +102,39 @@
mEditText = (EditText) getActivity().findViewById(EDIT_TXT_ID);
assertTrue(mEditText.isFocused());
+ enableAppOps();
savePasswordPref();
switchShowPassword(true);
}
+ private void enableAppOps() {
+ StringBuilder cmd = new StringBuilder();
+ cmd.append("appops set ");
+ cmd.append(getInstrumentation().getContext().getPackageName());
+ cmd.append(" android:write_settings allow");
+ getInstrumentation().getUiAutomation().executeShellCommand(cmd.toString());
+
+ StringBuilder query = new StringBuilder();
+ query.append("appops get ");
+ query.append(getInstrumentation().getContext().getPackageName());
+ query.append(" android:write_settings");
+ String queryStr = query.toString();
+
+ String result = "No operations.";
+ while (result.contains("No operations")) {
+ ParcelFileDescriptor pfd = getInstrumentation().getUiAutomation().executeShellCommand(
+ queryStr);
+ InputStream inputStream = new FileInputStream(pfd.getFileDescriptor());
+ result = convertStreamToString(inputStream);
+ }
+ }
+
+ private String convertStreamToString(InputStream is) {
+ try (Scanner scanner = new Scanner(is).useDelimiter("\\A")) {
+ return scanner.hasNext() ? scanner.next() : "";
+ }
+ }
+
@Override
protected void tearDown() throws Exception {
resumePasswordPref();