Merge "Fix link-type warning on CtsDrmTestCases"
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index 45d1c42..0b2ffa3 100755
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -3037,7 +3037,7 @@
         Check that \'Dummy Input method\', along with all other non-system apps, are not enabled in Settings. Then disallow \'Dummy Input method\' from permitted input methods by turning on the switch below.
     </string>
     <string name="set_permitted_input_methods_action">
-        Enabling \'Dummy Input method\' in the list of accessibility services
+        Enabling \'Dummy Input method\' in the list of input methods
     </string>
     <string name="set_permitted_input_methods_widget_label">
         Allow only system input methods:
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleScannerPowerLevelActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleScannerPowerLevelActivity.java
index ce68dbd..4bab4f1 100755
--- a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleScannerPowerLevelActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleScannerPowerLevelActivity.java
@@ -47,6 +47,7 @@
     private int[] mPowerLevel;
 
     private static final int[] POWER_DBM = {-21, -15, -7, 1, 9};
+    private static final int ADV_TX_POWER_LEVEL_ALLOWANCE = 5;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -156,7 +157,9 @@
                         .setText(intent.getStringExtra(BleScannerService.EXTRA_MAC_ADDRESS));
                     mRssiText.get(powerLevelBit)
                         .setText(intent.getStringExtra(BleScannerService.EXTRA_RSSI));
-                    if (Math.abs(POWER_DBM[powerLevelBit] - powerLevel) < 2) {
+
+                    if ((POWER_DBM[powerLevelBit] >= powerLevel) &&
+                        ((POWER_DBM[powerLevelBit] - ADV_TX_POWER_LEVEL_ALLOWANCE) <= powerLevel)) {
                         mSetPowerText.get(powerLevelBit).setText("Valid power level");
                     } else {
                         mSetPowerText.get(powerLevelBit)
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/CommandReceiverActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/CommandReceiverActivity.java
index 1d4d13a..c51ea0a 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/CommandReceiverActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/CommandReceiverActivity.java
@@ -36,6 +36,8 @@
 import android.provider.MediaStore;
 import android.provider.Settings;
 import android.util.Log;
+import android.view.inputmethod.InputMethodInfo;
+import android.view.inputmethod.InputMethodManager;
 import android.widget.Toast;
 
 import com.android.cts.verifier.R;
@@ -48,6 +50,7 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 public class CommandReceiverActivity extends Activity {
     private static final String TAG = "CommandReceiverActivity";
@@ -222,7 +225,8 @@
                 } break;
                 case COMMAND_ALLOW_ONLY_SYSTEM_INPUT_METHODS: {
                     boolean enforced = intent.getBooleanExtra(EXTRA_ENFORCED, false);
-                    mDpm.setPermittedInputMethods(mAdmin, enforced ? new ArrayList() : null);
+                    mDpm.setPermittedInputMethods(mAdmin,
+                            enforced ? getEnabledNonSystemImes() : null);
                 } break;
                 case COMMAND_ALLOW_ONLY_SYSTEM_ACCESSIBILITY_SERVICES: {
                     boolean enforced = intent.getBooleanExtra(EXTRA_ENFORCED, false);
@@ -562,4 +566,19 @@
             mDpm.removeUser(mAdmin, userHandle);
         }
     }
+
+    private List<String> getEnabledNonSystemImes() {
+        InputMethodManager inputMethodManager = getSystemService(InputMethodManager.class);
+        final List<InputMethodInfo> inputMethods = inputMethodManager.getEnabledInputMethodList();
+        return inputMethods.stream()
+                .filter(inputMethodInfo -> !isSystemInputMethodInfo(inputMethodInfo))
+                .map(inputMethodInfo -> inputMethodInfo.getPackageName())
+                .filter(packageName -> !packageName.equals(getPackageName()))
+                .distinct()
+                .collect(Collectors.toList());
+    }
+
+    private boolean isSystemInputMethodInfo(InputMethodInfo inputMethodInfo) {
+        return inputMethodInfo.getServiceInfo().applicationInfo.isSystemApp();
+    }
 }
diff --git a/hostsidetests/appsecurity/test-apps/UsePermissionApp23/src/com/android/cts/usepermission/BasePermissionsTest.java b/hostsidetests/appsecurity/test-apps/UsePermissionApp23/src/com/android/cts/usepermission/BasePermissionsTest.java
index d0ca617..9d3626b 100755
--- a/hostsidetests/appsecurity/test-apps/UsePermissionApp23/src/com/android/cts/usepermission/BasePermissionsTest.java
+++ b/hostsidetests/appsecurity/test-apps/UsePermissionApp23/src/com/android/cts/usepermission/BasePermissionsTest.java
@@ -47,16 +47,13 @@
 import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
 import android.widget.ScrollView;
 import android.widget.Switch;
-
-import junit.framework.Assert;
-
-import org.junit.Before;
-import org.junit.runner.RunWith;
-
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.Callable;
 import java.util.concurrent.TimeoutException;
+import junit.framework.Assert;
+import org.junit.Before;
+import org.junit.runner.RunWith;
 
 @RunWith(AndroidJUnit4.class)
 public abstract class BasePermissionsTest {
@@ -69,67 +66,6 @@
     private static final String LOG_TAG = "BasePermissionsTest";
 
     private static Map<String, String> sPermissionToLabelResNameMap = new ArrayMap<>();
-    static {
-        // Contacts
-        sPermissionToLabelResNameMap.put(Manifest.permission.READ_CONTACTS,
-                "@android:string/permgrouplab_contacts");
-        sPermissionToLabelResNameMap.put(Manifest.permission.WRITE_CONTACTS,
-                "@android:string/permgrouplab_contacts");
-        // Calendar
-        sPermissionToLabelResNameMap.put(Manifest.permission.READ_CALENDAR,
-                "@android:string/permgrouplab_calendar");
-        sPermissionToLabelResNameMap.put(Manifest.permission.WRITE_CALENDAR,
-                "@android:string/permgrouplab_calendar");
-        // SMS
-        sPermissionToLabelResNameMap.put(Manifest.permission.SEND_SMS,
-                "@android:string/permgrouplab_sms");
-        sPermissionToLabelResNameMap.put(Manifest.permission.RECEIVE_SMS,
-                "@android:string/permgrouplab_sms");
-        sPermissionToLabelResNameMap.put(Manifest.permission.READ_SMS,
-                "@android:string/permgrouplab_sms");
-        sPermissionToLabelResNameMap.put(Manifest.permission.RECEIVE_WAP_PUSH,
-                "@android:string/permgrouplab_sms");
-        sPermissionToLabelResNameMap.put(Manifest.permission.RECEIVE_MMS,
-                "@android:string/permgrouplab_sms");
-        sPermissionToLabelResNameMap.put("android.permission.READ_CELL_BROADCASTS",
-                "@android:string/permgrouplab_sms");
-        // Storage
-        sPermissionToLabelResNameMap.put(Manifest.permission.READ_EXTERNAL_STORAGE,
-                "@android:string/permgrouplab_storage");
-        sPermissionToLabelResNameMap.put(Manifest.permission.WRITE_EXTERNAL_STORAGE,
-                "@android:string/permgrouplab_storage");
-        // Location
-        sPermissionToLabelResNameMap.put(Manifest.permission.ACCESS_FINE_LOCATION,
-                "@android:string/permgrouplab_location");
-        sPermissionToLabelResNameMap.put(Manifest.permission.ACCESS_COARSE_LOCATION,
-                "@android:string/permgrouplab_location");
-        // Phone
-        sPermissionToLabelResNameMap.put(Manifest.permission.READ_PHONE_STATE,
-                "@android:string/permgrouplab_phone");
-        sPermissionToLabelResNameMap.put(Manifest.permission.CALL_PHONE,
-                "@android:string/permgrouplab_phone");
-        sPermissionToLabelResNameMap.put("android.permission.ACCESS_IMS_CALL_SERVICE",
-                "@android:string/permgrouplab_phone");
-        sPermissionToLabelResNameMap.put(Manifest.permission.READ_CALL_LOG,
-                "@android:string/permgrouplab_phone");
-        sPermissionToLabelResNameMap.put(Manifest.permission.WRITE_CALL_LOG,
-                "@android:string/permgrouplab_phone");
-        sPermissionToLabelResNameMap.put(Manifest.permission.ADD_VOICEMAIL,
-                "@android:string/permgrouplab_phone");
-        sPermissionToLabelResNameMap.put(Manifest.permission.USE_SIP,
-                "@android:string/permgrouplab_phone");
-        sPermissionToLabelResNameMap.put(Manifest.permission.PROCESS_OUTGOING_CALLS,
-                "@android:string/permgrouplab_phone");
-        // Microphone
-        sPermissionToLabelResNameMap.put(Manifest.permission.RECORD_AUDIO,
-                "@android:string/permgrouplab_microphone");
-        // Camera
-        sPermissionToLabelResNameMap.put(Manifest.permission.CAMERA,
-                "@android:string/permgrouplab_camera");
-        // Body sensors
-        sPermissionToLabelResNameMap.put(Manifest.permission.BODY_SENSORS,
-                "@android:string/permgrouplab_sensors");
-    }
 
     private Context mContext;
     private Resources mPlatformResources;
@@ -168,6 +104,143 @@
         return activity;
     }
 
+    private void initPermissionToLabelMap(boolean permissionReviewMode) {
+        if (!permissionReviewMode) {
+            // Contacts
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.READ_CONTACTS, "@android:string/permgrouplab_contacts");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.WRITE_CONTACTS, "@android:string/permgrouplab_contacts");
+            // Calendar
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.READ_CALENDAR, "@android:string/permgrouplab_calendar");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.WRITE_CALENDAR, "@android:string/permgrouplab_calendar");
+            // SMS
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.SEND_SMS, "@android:string/permgrouplab_sms");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.RECEIVE_SMS, "@android:string/permgrouplab_sms");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.READ_SMS, "@android:string/permgrouplab_sms");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.RECEIVE_WAP_PUSH, "@android:string/permgrouplab_sms");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.RECEIVE_MMS, "@android:string/permgrouplab_sms");
+            sPermissionToLabelResNameMap.put(
+                    "android.permission.READ_CELL_BROADCASTS", "@android:string/permgrouplab_sms");
+            // Storage
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.READ_EXTERNAL_STORAGE,
+                    "@android:string/permgrouplab_storage");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
+                    "@android:string/permgrouplab_storage");
+            // Location
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.ACCESS_FINE_LOCATION,
+                    "@android:string/permgrouplab_location");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.ACCESS_COARSE_LOCATION,
+                    "@android:string/permgrouplab_location");
+            // Phone
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.READ_PHONE_STATE, "@android:string/permgrouplab_phone");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.CALL_PHONE, "@android:string/permgrouplab_phone");
+            sPermissionToLabelResNameMap.put(
+                    "android.permission.ACCESS_IMS_CALL_SERVICE",
+                    "@android:string/permgrouplab_phone");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.READ_CALL_LOG, "@android:string/permgrouplab_phone");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.WRITE_CALL_LOG, "@android:string/permgrouplab_phone");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.ADD_VOICEMAIL, "@android:string/permgrouplab_phone");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.USE_SIP, "@android:string/permgrouplab_phone");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.PROCESS_OUTGOING_CALLS,
+                    "@android:string/permgrouplab_phone");
+            // Microphone
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.RECORD_AUDIO, "@android:string/permgrouplab_microphone");
+            // Camera
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.CAMERA, "@android:string/permgrouplab_camera");
+            // Body sensors
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.BODY_SENSORS, "@android:string/permgrouplab_sensors");
+        } else {
+            // Contacts
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.READ_CONTACTS, "@android:string/permlab_readContacts");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.WRITE_CONTACTS, "@android:string/permlab_writeContacts");
+            // Calendar
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.READ_CALENDAR, "@android:string/permgrouplab_calendar");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.WRITE_CALENDAR, "@android:string/permgrouplab_calendar");
+            // SMS
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.SEND_SMS, "@android:string/permlab_sendSms");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.RECEIVE_SMS, "@android:string/permlab_receiveSms");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.READ_SMS, "@android:string/permlab_readSms");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.RECEIVE_WAP_PUSH, "@android:string/permlab_receiveWapPush");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.RECEIVE_MMS, "@android:string/permlab_receiveMms");
+            sPermissionToLabelResNameMap.put(
+                    "android.permission.READ_CELL_BROADCASTS",
+                    "@android:string/permlab_readCellBroadcasts");
+            // Storage
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.READ_EXTERNAL_STORAGE,
+                    "@android:string/permgrouplab_storage");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
+                    "@android:string/permgrouplab_storage");
+            // Location
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.ACCESS_FINE_LOCATION,
+                    "@android:string/permgrouplab_location");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.ACCESS_COARSE_LOCATION,
+                    "@android:string/permgrouplab_location");
+            // Phone
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.READ_PHONE_STATE, "@android:string/permlab_readPhoneState");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.CALL_PHONE, "@android:string/permlab_callPhone");
+            sPermissionToLabelResNameMap.put(
+                    "android.permission.ACCESS_IMS_CALL_SERVICE",
+                    "@android:string/permlab_accessImsCallService");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.READ_CALL_LOG, "@android:string/permlab_readCallLog");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.WRITE_CALL_LOG, "@android:string/permlab_writeCallLog");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.ADD_VOICEMAIL, "@android:string/permlab_addVoicemail");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.USE_SIP, "@android:string/permlab_use_sip");
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.PROCESS_OUTGOING_CALLS,
+                    "@android:string/permlab_processOutgoingCalls");
+            // Microphone
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.RECORD_AUDIO, "@android:string/permgrouplab_microphone");
+            // Camera
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.CAMERA, "@android:string/permgrouplab_camera");
+            // Body sensors
+            sPermissionToLabelResNameMap.put(
+                    Manifest.permission.BODY_SENSORS, "@android:string/permgrouplab_sensors");
+        }
+    }
+
     @Before
     public void beforeTest() {
         mContext = InstrumentationRegistry.getTargetContext();
@@ -178,7 +251,9 @@
             /* cannot happen */
         }
 
-        mWatch = mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH);
+        PackageManager packageManager = mContext.getPackageManager();
+        mWatch = packageManager.hasSystemFeature(PackageManager.FEATURE_WATCH);
+        initPermissionToLabelMap(packageManager.isPermissionReviewModeEnabled());
 
         UiObject2 button = getUiDevice().findObject(By.text("Close"));
         if (button != null) {
diff --git a/hostsidetests/sustainedperf/shadertoy_android/Android.mk b/hostsidetests/sustainedperf/shadertoy_android/Android.mk
index ba6bf64..2e1bbdd 100644
--- a/hostsidetests/sustainedperf/shadertoy_android/Android.mk
+++ b/hostsidetests/sustainedperf/shadertoy_android/Android.mk
@@ -24,7 +24,7 @@
 # Include both the 32 and 64 bit versions
 LOCAL_MULTILIB := both
 
-LOCAL_JNI_SHARED_LIBRARIES := libgltest libc++
+LOCAL_JNI_SHARED_LIBRARIES := libgltest
 #LOCAL_SHARED_LIBRARIES := libc++
 #LOCAL_STATIC_LIBRARIES := libc++_static
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/tests/openglperf2/jni/Android.mk b/tests/openglperf2/jni/Android.mk
index b1981ec..283bc18 100644
--- a/tests/openglperf2/jni/Android.mk
+++ b/tests/openglperf2/jni/Android.mk
@@ -30,10 +30,7 @@
 
 LOCAL_SHARED_LIBRARIES := libEGL libGLESv2 libandroid liblog
 
-LOCAL_CXX_STL := libc++_static
-
-# TODO (dimitry): replace LOCAL_CXX_STL with LOCAL_SDK_VERSION+LOCAL_NDK_STL_VARIANT
-# LOCAL_SDK_VERSION := 23
-# LOCAL_NDK_STL_VARIANT := c++_static
+LOCAL_SDK_VERSION := current
+LOCAL_NDK_STL_VARIANT := c++_static
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/opengl/libopengltest/Android.mk b/tests/tests/opengl/libopengltest/Android.mk
index 8c45c38..aed011a 100755
--- a/tests/tests/opengl/libopengltest/Android.mk
+++ b/tests/tests/opengl/libopengltest/Android.mk
@@ -36,7 +36,8 @@
 
 LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
 
-LOCAL_CXX_STL := libc++_static
+LOCAL_SDK_VERSION := current
+LOCAL_NDK_STL_VARIANT := none
 
 LOCAL_SHARED_LIBRARIES := libGLESv2 liblog
 
diff --git a/tests/tests/telephony/src/android/telephony/cts/VisualVoicemailServiceTest.java b/tests/tests/telephony/src/android/telephony/cts/VisualVoicemailServiceTest.java
index 01f926b..cfd31d3 100644
--- a/tests/tests/telephony/src/android/telephony/cts/VisualVoicemailServiceTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/VisualVoicemailServiceTest.java
@@ -678,6 +678,9 @@
     }
 
     private boolean hasDataSms() {
+        if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
+            return false;
+        }
         String mccmnc = mTelephonyManager.getSimOperator();
         return !CarrierCapability.UNSUPPORT_DATA_SMS_MESSAGES.contains(mccmnc);
     }