Merge "Revert "Revert "Delete CtsUiDeviceTestCases"""
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
index d32ebc0..247e4ea 100644
--- a/PREUPLOAD.cfg
+++ b/PREUPLOAD.cfg
@@ -24,3 +24,5 @@
                       tests/tests/view/
                       tests/tests/widget/
                       common/device-side/util/
+
+ktlint_hook = ${REPO_ROOT}/prebuilts/ktlint/ktlint.py -f ${PREUPLOAD_FILES}
diff --git a/tests/AlarmManager/AndroidTest.xml b/tests/AlarmManager/AndroidTest.xml
index a8c8955..f44ae93 100644
--- a/tests/AlarmManager/AndroidTest.xml
+++ b/tests/AlarmManager/AndroidTest.xml
@@ -17,6 +17,8 @@
 <configuration description="Config for CTS Alarm Manager test cases">
     <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="framework" />
+    <option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" />
+    <option name="config-descriptor:metadata" key="parameter" value="instant_app" />
 
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/AlarmManager/src/android/alarmmanager/cts/AppStandbyTests.java b/tests/AlarmManager/src/android/alarmmanager/cts/AppStandbyTests.java
index ecd9792..e528968 100644
--- a/tests/AlarmManager/src/android/alarmmanager/cts/AppStandbyTests.java
+++ b/tests/AlarmManager/src/android/alarmmanager/cts/AppStandbyTests.java
@@ -32,6 +32,7 @@
 import android.content.IntentFilter;
 import android.os.BatteryManager;
 import android.os.SystemClock;
+import android.platform.test.annotations.AppModeFull;
 import android.support.test.InstrumentationRegistry;
 import android.support.test.filters.LargeTest;
 import android.support.test.runner.AndroidJUnit4;
@@ -54,6 +55,7 @@
 /**
  * Tests that app standby imposes the appropriate restrictions on alarms
  */
+@AppModeFull
 @LargeTest
 @RunWith(AndroidJUnit4.class)
 public class AppStandbyTests {
diff --git a/tests/AlarmManager/src/android/alarmmanager/cts/BackgroundRestrictedAlarmsTest.java b/tests/AlarmManager/src/android/alarmmanager/cts/BackgroundRestrictedAlarmsTest.java
index f36b07f..524508c 100644
--- a/tests/AlarmManager/src/android/alarmmanager/cts/BackgroundRestrictedAlarmsTest.java
+++ b/tests/AlarmManager/src/android/alarmmanager/cts/BackgroundRestrictedAlarmsTest.java
@@ -19,8 +19,8 @@
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import android.alarmmanager.alarmtestapp.cts.TestAlarmScheduler;
 import android.alarmmanager.alarmtestapp.cts.TestAlarmReceiver;
+import android.alarmmanager.alarmtestapp.cts.TestAlarmScheduler;
 import android.app.AlarmManager;
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
@@ -28,6 +28,7 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.os.SystemClock;
+import android.platform.test.annotations.AppModeFull;
 import android.support.test.InstrumentationRegistry;
 import android.support.test.filters.LargeTest;
 import android.support.test.runner.AndroidJUnit4;
@@ -45,6 +46,7 @@
  * Tests that apps put in forced app standby by the user do not get to run alarms while in the
  * background
  */
+@AppModeFull
 @LargeTest
 @RunWith(AndroidJUnit4.class)
 public class BackgroundRestrictedAlarmsTest {
diff --git a/tests/AlarmManager/src/android/alarmmanager/cts/InstantAppsTests.java b/tests/AlarmManager/src/android/alarmmanager/cts/InstantAppsTests.java
new file mode 100644
index 0000000..959df85
--- /dev/null
+++ b/tests/AlarmManager/src/android/alarmmanager/cts/InstantAppsTests.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+package android.alarmmanager.cts;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+import android.app.AlarmManager;
+import android.content.Context;
+import android.os.SystemClock;
+import android.platform.test.annotations.AppModeInstant;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
+
+import com.android.compatibility.common.util.SystemUtil;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Tests that alarm manager works as expected with instant apps
+ */
+@AppModeInstant
+@RunWith(AndroidJUnit4.class)
+public class InstantAppsTests {
+    private static final String TAG = "AlarmManagerInstantTests";
+
+    private AlarmManager mAlarmManager;
+    private Context mContext;
+
+    @Before
+    public void setUp() {
+        mContext = InstrumentationRegistry.getTargetContext();
+        mAlarmManager = mContext.getSystemService(AlarmManager.class);
+        assumeTrue(mContext.getPackageManager().isInstantApp());
+        updateAlarmManagerSettings();
+    }
+
+    @Test
+    public void elapsedRealtimeAlarm() throws Exception {
+        final long futurity = 2500;
+        final long triggerElapsed = SystemClock.elapsedRealtime() + futurity;
+        final CountDownLatch latch = new CountDownLatch(1);
+        mAlarmManager.setExact(AlarmManager.ELAPSED_REALTIME, triggerElapsed, TAG,
+                () -> latch.countDown(), null);
+        Thread.sleep(futurity);
+        assertTrue("Alarm did not fire as expected", latch.await(500, TimeUnit.MILLISECONDS));
+    }
+
+    @Test
+    public void rtcAlarm() throws Exception {
+        final long futurity = 2500;
+        final long triggerRtc = System.currentTimeMillis() + futurity;
+        final CountDownLatch latch = new CountDownLatch(1);
+        mAlarmManager.setExact(AlarmManager.RTC, triggerRtc, TAG, () -> latch.countDown(), null);
+        Thread.sleep(futurity);
+        assertTrue("Alarm did not fire as expected", latch.await(500, TimeUnit.MILLISECONDS));
+    }
+
+    @After
+    public void deleteAlarmManagerSettings() {
+        SystemUtil.runShellCommand("settings delete global alarm_manager_constants");
+    }
+
+    private void updateAlarmManagerSettings() {
+        final StringBuffer cmd = new StringBuffer("settings put global alarm_manager_constants ");
+        cmd.append("min_futurity=0");
+        SystemUtil.runShellCommand(cmd.toString());
+    }
+}
diff --git a/tests/app/src/android/app/cts/AdjustmentTest.java b/tests/app/src/android/app/cts/AdjustmentTest.java
new file mode 100644
index 0000000..8d65d3d
--- /dev/null
+++ b/tests/app/src/android/app/cts/AdjustmentTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+package android.app.cts;
+
+
+import android.os.Bundle;
+import android.os.Parcel;
+import android.service.notification.Adjustment;
+import android.test.AndroidTestCase;
+import android.util.Log;
+
+public class AdjustmentTest extends AndroidTestCase {
+    private static final String ADJ_PACKAGE = "com.foo.bar";
+    private static final String ADJ_KEY = "foo_key";
+    private static final String ADJ_EXPLANATION = "I just feel like adjusting this";
+    private static final int ADJ_USER = 47;
+
+    private final Bundle mSignals = new Bundle();
+
+    private Adjustment mAdjustment;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        mSignals.putString("foobar", "Hello, world!");
+        mSignals.putInt("chirp", 47);
+        mAdjustment = new Adjustment(ADJ_PACKAGE, ADJ_KEY, mSignals, ADJ_EXPLANATION, ADJ_USER);
+    }
+
+    public void testGetPackage() {
+        assertEquals(ADJ_PACKAGE, mAdjustment.getPackage());
+    }
+
+    public void testGetKey() {
+        assertEquals(ADJ_KEY, mAdjustment.getKey());
+    }
+
+    public void testGetExplanation() {
+        assertEquals(ADJ_EXPLANATION, mAdjustment.getExplanation());
+    }
+
+    public void testGetUser() {
+        assertEquals(ADJ_USER, mAdjustment.getUser());
+    }
+
+    public void testGetSignals() {
+        assertEquals(mSignals, mAdjustment.getSignals());
+        assertEquals("Hello, world!", mAdjustment.getSignals().getString("foobar"));
+        assertEquals(47, mAdjustment.getSignals().getInt("chirp"));
+    }
+
+    public void testDescribeContents() {
+        assertEquals(0, mAdjustment.describeContents());
+    }
+
+    public void testParcelling() {
+        final Parcel outParcel = Parcel.obtain();
+        mAdjustment.writeToParcel(outParcel, 0);
+        outParcel.setDataPosition(0);
+        final Adjustment unparceled = Adjustment.CREATOR.createFromParcel(outParcel);
+
+        assertEquals(mAdjustment.getPackage(), unparceled.getPackage());
+        assertEquals(mAdjustment.getKey(), unparceled.getKey());
+        assertEquals(mAdjustment.getExplanation(), unparceled.getExplanation());
+        assertEquals(mAdjustment.getUser(), unparceled.getUser());
+
+        assertEquals("Hello, world!", unparceled.getSignals().getString("foobar"));
+        assertEquals(47, unparceled.getSignals().getInt("chirp"));
+    }
+}
diff --git a/tests/app/src/android/app/cts/NotificationCarExtenderTest.java b/tests/app/src/android/app/cts/NotificationCarExtenderTest.java
new file mode 100644
index 0000000..20bf336
--- /dev/null
+++ b/tests/app/src/android/app/cts/NotificationCarExtenderTest.java
@@ -0,0 +1,138 @@
+ /*
+ * Copyright (C) 2019 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.
+ */
+package android.app.cts;
+
+import android.app.Notification;
+import android.app.Notification.CarExtender;
+import android.app.Notification.CarExtender.Builder;
+import android.app.Notification.CarExtender.UnreadConversation;
+import android.app.PendingIntent;
+import android.app.RemoteInput;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.Bitmap.Config;
+import android.test.AndroidTestCase;
+
+public class NotificationCarExtenderTest extends AndroidTestCase {
+
+    private Context mContext;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mContext = getContext();
+    }
+
+    public void testCarExtender_EmptyConstructor() {
+        CarExtender extender = new Notification.CarExtender();
+        assertNotNull(extender);
+        assertEquals(Notification.COLOR_DEFAULT, extender.getColor());
+        assertEquals(null, extender.getLargeIcon());
+        assertEquals(null, extender.getUnreadConversation());
+    }
+
+    public void testCarExtender_Constructor() {
+        Notification notification = new Notification();
+        CarExtender extender = new Notification.CarExtender(notification);
+        assertNotNull(extender);
+        assertEquals(Notification.COLOR_DEFAULT, extender.getColor());
+        assertEquals(null, extender.getLargeIcon());
+        assertEquals(null, extender.getUnreadConversation());
+    }
+
+    public void testCarExtender() {
+        final int testColor = 11;
+        final Bitmap testIcon = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
+        final UnreadConversation testConversation =
+            new Builder("testParticipant")
+                .addMessage("testMessage")
+                .setLatestTimestamp(System.currentTimeMillis())
+                .build();
+
+        CarExtender extender = new Notification.CarExtender()
+            .setColor(testColor)
+            .setLargeIcon(testIcon)
+            .setUnreadConversation(testConversation);
+
+        assertEquals(testColor, extender.getColor());
+        assertEquals(testIcon, extender.getLargeIcon());
+        assertEquals(testConversation, extender.getUnreadConversation());
+    }
+
+    public void testCarExtender_extend() {
+        final int testColor = 11;
+        final Bitmap testIcon = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
+        final UnreadConversation testConversation =
+            new Builder("testParticipant")
+                .addMessage("testMessage")
+                .setLatestTimestamp(System.currentTimeMillis())
+                .build();
+        Notification.Builder notifBuilder = new Notification.Builder(mContext, "test id")
+            .setSmallIcon(1);
+        CarExtender extender = new Notification.CarExtender()
+            .setColor(testColor)
+            .setLargeIcon(testIcon)
+            .setUnreadConversation(testConversation);
+
+        extender.extend(notifBuilder);
+
+        Notification notification = notifBuilder.build();
+
+        CarExtender receiveCarExtender = new CarExtender(notification);
+
+        assertNotNull(receiveCarExtender);
+        assertEquals(testColor, receiveCarExtender.getColor());
+        assertEquals(testIcon, receiveCarExtender.getLargeIcon());
+        assertEquals(1, receiveCarExtender.getUnreadConversation().getMessages().length);
+        assertEquals(testConversation.getMessages().length,
+            receiveCarExtender.getUnreadConversation().getMessages().length);
+        assertEquals(testConversation.getMessages()[0],
+            receiveCarExtender.getUnreadConversation().getMessages()[0]);
+    }
+
+    public void testCarExtender_UnreadConversationAndBuilder() {
+        final long testTime = System.currentTimeMillis();
+        final String testMessage = "testMessage";
+        final String testParticipant = "testParticipant";
+        final Intent testIntent = new Intent("testIntent");
+        final PendingIntent testPendingIntent =
+            PendingIntent.getBroadcast(mContext, 0, testIntent,
+            PendingIntent.FLAG_CANCEL_CURRENT);
+        final PendingIntent testReplyPendingIntent =
+            PendingIntent.getBroadcast(mContext, 0, testIntent,
+                PendingIntent.FLAG_UPDATE_CURRENT);
+        final RemoteInput testRemoteInput = new RemoteInput.Builder("key").build();
+
+        final UnreadConversation testConversation =
+            new Builder(testParticipant)
+                .setLatestTimestamp(testTime)
+                .addMessage(testMessage)
+                .setReadPendingIntent(testPendingIntent)
+                .setReplyAction(testReplyPendingIntent, testRemoteInput)
+                .build();
+
+        assertEquals(testTime, testConversation.getLatestTimestamp());
+        assertEquals(1, testConversation.getMessages().length);
+        assertEquals(testMessage, testConversation.getMessages()[0]);
+        assertEquals(testParticipant, testConversation.getParticipant());
+        assertEquals(1, testConversation.getParticipants().length);
+        assertEquals(testParticipant, testConversation.getParticipants()[0]);
+        assertEquals(testPendingIntent, testConversation.getReadPendingIntent());
+        assertEquals(testRemoteInput, testConversation.getRemoteInput());
+        assertEquals(testPendingIntent, testConversation.getReplyPendingIntent());
+    }
+}
diff --git a/tests/autofillservice/src/android/autofillservice/cts/AutoFillServiceTestCase.java b/tests/autofillservice/src/android/autofillservice/cts/AutoFillServiceTestCase.java
index 6997453..40d1e4e 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/AutoFillServiceTestCase.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/AutoFillServiceTestCase.java
@@ -19,7 +19,6 @@
 import static android.autofillservice.cts.Helper.getContext;
 import static android.autofillservice.cts.InstrumentedAutoFillService.SERVICE_NAME;
 import static android.content.Context.CLIPBOARD_SERVICE;
-import static android.provider.Settings.Global.AUTOFILL_SMART_SUGGESTION_EMULATION_FLAGS;
 
 import static com.android.compatibility.common.util.ShellUtils.runShellCommand;
 
@@ -39,9 +38,7 @@
 import com.android.compatibility.common.util.RequiredFeatureRule;
 import com.android.compatibility.common.util.RetryRule;
 import com.android.compatibility.common.util.SafeCleanerRule;
-import com.android.compatibility.common.util.SettingsStateChangerRule;
 import com.android.compatibility.common.util.SettingsStateKeeperRule;
-import com.android.compatibility.common.util.SettingsUtils;
 import com.android.compatibility.common.util.TestNameUtils;
 
 import org.junit.Before;
@@ -205,10 +202,11 @@
                 // mRetryRule should be closest to the main test as possible
                 .around(mRetryRule)
                 //
-                // Augmented Autofill should be disabled by default
-                .around(new SettingsStateChangerRule(sContext, SettingsUtils.NAMESPACE_GLOBAL,
-                        AUTOFILL_SMART_SUGGESTION_EMULATION_FLAGS,
-                        Integer.toString(getSmartSuggestionMode())))
+                // TODO(b/124006095): must use DeviceConfig rule
+//                // Augmented Autofill should be disabled by default
+//                .around(new SettingsStateChangerRule(sContext, SettingsUtils.NAMESPACE_GLOBAL,
+//                        AUTOFILL_SMART_SUGGESTION_EMULATION_FLAGS,
+//                        Integer.toString(getSmartSuggestionMode())))
                 //
                 // Finally, let subclasses add their own rules (like ActivityTestRule)
                 .around(getMainTestRule());
diff --git a/tests/tests/role/CtsRoleTestApp/AndroidManifest.xml b/tests/tests/role/CtsRoleTestApp/AndroidManifest.xml
index 03f9513..7f096cc 100644
--- a/tests/tests/role/CtsRoleTestApp/AndroidManifest.xml
+++ b/tests/tests/role/CtsRoleTestApp/AndroidManifest.xml
@@ -38,14 +38,6 @@
                 <data android:scheme="tel" />
             </intent-filter>
         </activity>
-        <service
-            android:name=".DialerInCallService"
-            android:permission="android.permission.BIND_INCALL_SERVICE">
-            <intent-filter>
-                <action android:name="android.telecom.InCallService" />
-            </intent-filter>
-            <meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" />
-        </service>
 
         <!-- Sms -->
         <activity android:name=".SmsSendToActivity">
diff --git a/tests/tests/telephony/current/src/android/telephony/cts/AvailableNetworkInfoTest.java b/tests/tests/telephony/current/src/android/telephony/cts/AvailableNetworkInfoTest.java
new file mode 100644
index 0000000..1af3391
--- /dev/null
+++ b/tests/tests/telephony/current/src/android/telephony/cts/AvailableNetworkInfoTest.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+package android.telephony.cts;
+
+import android.os.Parcel;
+import android.telephony.AvailableNetworkInfo;
+import android.test.AndroidTestCase;
+import java.util.ArrayList;
+import java.util.List;
+
+public class AvailableNetworkInfoTest extends AndroidTestCase {
+    private static final String OPERATOR_MCCMNC_1 = "123456";
+    private static final String OPERATOR_MCCMNC_2 = "246135";
+    private static final int SUB_ID = 123;
+
+    public void testAvailableNetworkInfo() {
+        List<String> mccMncs = new ArrayList<String>();
+        mccMncs.add(OPERATOR_MCCMNC_1);
+        mccMncs.add(OPERATOR_MCCMNC_2);
+
+        AvailableNetworkInfo availableNetworkInfo = new AvailableNetworkInfo(SUB_ID,
+                AvailableNetworkInfo.PRIORITY_HIGH, mccMncs);
+        assertEquals(0, availableNetworkInfo.describeContents());
+        assertEquals(SUB_ID, availableNetworkInfo.getSubId());
+        assertEquals(AvailableNetworkInfo.PRIORITY_HIGH, availableNetworkInfo.getPriority());
+        assertEquals(mccMncs, availableNetworkInfo.getMccMncs());
+
+        Parcel availableNetworkInfoParcel = Parcel.obtain();
+        availableNetworkInfo.writeToParcel(availableNetworkInfoParcel, 0);
+        availableNetworkInfoParcel.setDataPosition(0);
+        AvailableNetworkInfo tempAvailableNetworkInfo =
+                AvailableNetworkInfo.CREATOR.createFromParcel(availableNetworkInfoParcel);
+        assertTrue(tempAvailableNetworkInfo.equals(availableNetworkInfo));
+    }
+}
diff --git a/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java b/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java
index 7081b8b..698b885 100644
--- a/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java
+++ b/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java
@@ -39,6 +39,7 @@
 import android.telecom.PhoneAccountHandle;
 import android.telecom.TelecomManager;
 import android.telephony.AccessNetworkConstants;
+import android.telephony.AvailableNetworkInfo;
 import android.telephony.CellLocation;
 import android.telephony.NetworkRegistrationState;
 import android.telephony.PhoneStateListener;
@@ -59,6 +60,7 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
@@ -1036,6 +1038,90 @@
         assertThat(raf).isNotEqualTo(TelephonyManager.NETWORK_TYPE_BITMASK_UNKNOWN);
     }
 
+    /**
+     * Tests {@link TelephonyManager#setPreferredOpportunisticDataSubscription} and
+     * {@link TelephonyManager#getPreferredOpportunisticDataSubscription}
+     */
+    @Test
+    public void testPreferredOpportunisticDataSubscription() {
+        int randomSubId = 1;
+        if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
+            return;
+        }
+        int subId =
+            ShellIdentityUtils.invokeMethodWithShellPermissions(mTelephonyManager,
+                (tm) -> tm.getPreferredOpportunisticDataSubscription());
+        assertThat(subId).isEqualTo(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID);
+        List<SubscriptionInfo> subscriptionInfoList =
+                    ShellIdentityUtils.invokeMethodWithShellPermissions(mSubscriptionManager,
+                            (tm) -> tm.getOpportunisticSubscriptions());
+        if (subscriptionInfoList == null || subscriptionInfoList.size() == 0) {
+            boolean res = ShellIdentityUtils.invokeMethodWithShellPermissions(mTelephonyManager,
+                    (tm) -> tm.setPreferredOpportunisticDataSubscription(randomSubId));
+            assertThat(res).isEqualTo(false);
+            subId = ShellIdentityUtils.invokeMethodWithShellPermissions(mTelephonyManager,
+                    (tm) -> tm.getPreferredOpportunisticDataSubscription());
+            assertThat(subId).isEqualTo(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID);
+
+        } else {
+            boolean res = ShellIdentityUtils.invokeMethodWithShellPermissions(mTelephonyManager,
+                    (tm) -> tm.setPreferredOpportunisticDataSubscription(
+                            subscriptionInfoList.get(0).getSubscriptionId()));
+            assertThat(res).isEqualTo(true);
+            ShellIdentityUtils.invokeMethodWithShellPermissions(mTelephonyManager,
+                (tm) -> tm.getPreferredOpportunisticDataSubscription());
+            assertThat(subId).isEqualTo(subscriptionInfoList.get(0).getSubscriptionId());
+        }
+
+        boolean result = ShellIdentityUtils.invokeMethodWithShellPermissions(mTelephonyManager,
+                (tm) -> tm.setPreferredOpportunisticDataSubscription(
+                        SubscriptionManager.DEFAULT_SUBSCRIPTION_ID));
+        assertThat(result).isEqualTo(true);
+        subId = ShellIdentityUtils.invokeMethodWithShellPermissions(mTelephonyManager,
+            (tm) -> tm.getPreferredOpportunisticDataSubscription());
+        assertThat(subId).isEqualTo(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID);
+    }
+
+    /**
+     * Tests {@link TelephonyManager#updateAvailableNetworks}
+     */
+    @Test
+    public void testUpdateAvailableNetworks() {
+        int randomSubId = 1;
+        if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
+            return;
+        }
+
+        List<SubscriptionInfo> subscriptionInfoList =
+            ShellIdentityUtils.invokeMethodWithShellPermissions(mSubscriptionManager,
+                (tm) -> tm.getOpportunisticSubscriptions());
+        List<String> mccMncs = new ArrayList<String>();
+        List<AvailableNetworkInfo> availableNetworkInfos = new ArrayList<AvailableNetworkInfo>();
+        if (subscriptionInfoList == null || subscriptionInfoList.size() == 0
+                || !mSubscriptionManager.isActiveSubscriptionId(
+                        subscriptionInfoList.get(0).getSubscriptionId())) {
+            AvailableNetworkInfo availableNetworkInfo = new AvailableNetworkInfo(randomSubId,
+                    AvailableNetworkInfo.PRIORITY_HIGH, mccMncs);
+            availableNetworkInfos.add(availableNetworkInfo);
+            boolean res = ShellIdentityUtils.invokeMethodWithShellPermissions(mTelephonyManager,
+                    (tm) -> tm.updateAvailableNetworks(availableNetworkInfos));
+            assertThat(res).isEqualTo(false);
+        } else {
+            AvailableNetworkInfo availableNetworkInfo = new AvailableNetworkInfo(
+                    subscriptionInfoList.get(0).getSubscriptionId(),
+                    AvailableNetworkInfo.PRIORITY_HIGH, mccMncs);
+            availableNetworkInfos.add(availableNetworkInfo);
+            boolean res = ShellIdentityUtils.invokeMethodWithShellPermissions(mTelephonyManager,
+                (tm) -> tm.updateAvailableNetworks(availableNetworkInfos));
+            assertThat(res).isEqualTo(true);
+            availableNetworkInfos.clear();
+            res = ShellIdentityUtils.invokeMethodWithShellPermissions(mTelephonyManager,
+                (tm) -> tm.updateAvailableNetworks(availableNetworkInfos));
+            assertThat(res).isEqualTo(true);
+        }
+    }
+
+
     public static void waitForMs(long ms) {
         try {
             Thread.sleep(ms);
diff --git a/tests/tests/view/AndroidManifest.xml b/tests/tests/view/AndroidManifest.xml
index 925f3e2..2c03228 100644
--- a/tests/tests/view/AndroidManifest.xml
+++ b/tests/tests/view/AndroidManifest.xml
@@ -33,7 +33,7 @@
 
         <activity android:name="android.app.Activity"
                   android:label="Empty Activity"
-                  android:theme="@style/ViewStyleTestTheme">
+                  android:theme="@style/ViewAttributeTestTheme">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN"/>
                 <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
diff --git a/tests/tests/view/res/layout/view_style_layout.xml b/tests/tests/view/res/layout/view_attribute_layout.xml
similarity index 100%
rename from tests/tests/view/res/layout/view_style_layout.xml
rename to tests/tests/view/res/layout/view_attribute_layout.xml
diff --git a/tests/tests/view/res/values/styles.xml b/tests/tests/view/res/values/styles.xml
index ab984e8..5b832c6 100644
--- a/tests/tests/view/res/values/styles.xml
+++ b/tests/tests/view/res/values/styles.xml
@@ -188,7 +188,7 @@
         <item name="android:windowAnimationStyle">@null</item>
     </style>
 
-    <style name="ViewStyleTestTheme" parent="@android:Theme.Material">
+    <style name="ViewAttributeTestTheme" parent="@android:Theme.Material">
         <item name="android:buttonStyle">@style/MyButtonStyle</item>
     </style>
 
diff --git a/tests/tests/view/src/android/view/cts/ViewStyleTest.java b/tests/tests/view/src/android/view/cts/ViewAttributeTest.java
similarity index 82%
rename from tests/tests/view/src/android/view/cts/ViewStyleTest.java
rename to tests/tests/view/src/android/view/cts/ViewAttributeTest.java
index 866e8b6..02766d9 100644
--- a/tests/tests/view/src/android/view/cts/ViewStyleTest.java
+++ b/tests/tests/view/src/android/view/cts/ViewAttributeTest.java
@@ -42,7 +42,7 @@
 
 @MediumTest
 @RunWith(AndroidJUnit4.class)
-public class ViewStyleTest {
+public class ViewAttributeTest {
 
     @Rule
     public ActivityTestRule<Activity> mActivityRule =
@@ -72,7 +72,8 @@
     public void testGetExplicitStyle() {
         Context context = InstrumentationRegistry.getTargetContext();
         LayoutInflater inflater = LayoutInflater.from(context);
-        LinearLayout rootView = (LinearLayout) inflater.inflate(R.layout.view_style_layout, null);
+        LinearLayout rootView =
+                (LinearLayout) inflater.inflate(R.layout.view_attribute_layout, null);
         View view1 = rootView.findViewById(R.id.view1);
         assertEquals(R.style.ExplicitStyle1, view1.getExplicitStyle());
 
@@ -89,12 +90,17 @@
     @Test
     public void testGetAttributeResolutionStack() {
         LayoutInflater inflater = LayoutInflater.from(mActivityRule.getActivity());
-        LinearLayout rootView = (LinearLayout) inflater.inflate(R.layout.view_style_layout, null);
+        LinearLayout rootView =
+                (LinearLayout) inflater.inflate(R.layout.view_attribute_layout, null);
+        List<Integer> stackRootView = rootView.getAttributeResolutionStack();
+        assertEquals(1, stackRootView.size());
+        assertEquals(R.layout.view_attribute_layout, stackRootView.get(0).intValue());
+
         // View that has an explicit style ExplicitStyle1 set via style = ...
         View view1 = rootView.findViewById(R.id.view1);
         List<Integer> stackView1 = view1.getAttributeResolutionStack();
         assertEquals(3, stackView1.size());
-        assertEquals(R.layout.view_style_layout, stackView1.get(0).intValue());
+        assertEquals(R.layout.view_attribute_layout, stackView1.get(0).intValue());
         assertEquals(R.style.ExplicitStyle1, stackView1.get(1).intValue());
         assertEquals(R.style.ParentOfExplicitStyle1, stackView1.get(2).intValue());
 
@@ -103,7 +109,7 @@
         Button button1 = rootView.findViewById(R.id.button1);
         List<Integer> stackButton1 = button1.getAttributeResolutionStack();
         assertEquals(3, stackButton1.size());
-        assertEquals(R.layout.view_style_layout, stackButton1.get(0).intValue());
+        assertEquals(R.layout.view_attribute_layout, stackButton1.get(0).intValue());
         assertEquals(R.style.MyButtonStyle, stackButton1.get(1).intValue());
         assertEquals(R.style.MyButtonStyleParent, stackButton1.get(2).intValue());
 
@@ -112,7 +118,7 @@
         Button button2 = rootView.findViewById(R.id.button2);
         List<Integer> stackButton2 = button2.getAttributeResolutionStack();
         assertEquals(5, stackButton2.size());
-        assertEquals(R.layout.view_style_layout, stackButton2.get(0).intValue());
+        assertEquals(R.layout.view_attribute_layout, stackButton2.get(0).intValue());
         assertEquals(R.style.ExplicitStyle1, stackButton2.get(1).intValue());
         assertEquals(R.style.ParentOfExplicitStyle1, stackButton2.get(2).intValue());
         assertEquals(R.style.MyButtonStyle, stackButton2.get(3).intValue());
@@ -122,16 +128,20 @@
     @Test
     public void testGetAttributeSourceResourceMap() {
         LayoutInflater inflater = LayoutInflater.from(mActivityRule.getActivity());
-        LinearLayout rootView = (LinearLayout) inflater.inflate(R.layout.view_style_layout, null);
+        LinearLayout rootView =
+                (LinearLayout) inflater.inflate(R.layout.view_attribute_layout, null);
+        Map<Integer, Integer> attributeMapRootView = rootView.getAttributeSourceResourceMap();
+        assertEquals(R.layout.view_attribute_layout,
+                (attributeMapRootView.get(android.R.attr.orientation)).intValue());
+
         // View that has an explicit style ExplicitStyle1 set via style = ...
         View view1 = rootView.findViewById(R.id.view1);
         Map<Integer, Integer> attributeMapView1 = view1.getAttributeSourceResourceMap();
-        assertEquals(9, attributeMapView1.size());
         assertEquals(R.style.ExplicitStyle1,
                 (attributeMapView1.get(android.R.attr.padding)).intValue());
         assertEquals(R.style.ParentOfExplicitStyle1,
                 (attributeMapView1.get(android.R.attr.paddingLeft)).intValue());
-        assertEquals(R.layout.view_style_layout,
+        assertEquals(R.layout.view_attribute_layout,
                 (attributeMapView1.get(android.R.attr.paddingTop)).intValue());
     }
 }
diff --git a/tests/tests/widget/AndroidManifest.xml b/tests/tests/widget/AndroidManifest.xml
index e7929e0..df712eb 100644
--- a/tests/tests/widget/AndroidManifest.xml
+++ b/tests/tests/widget/AndroidManifest.xml
@@ -558,6 +558,15 @@
             </intent-filter>
         </activity>
 
+        <activity android:name="android.app.Activity"
+                  android:label="Activity"
+                  android:theme="@style/WidgetAttributeTestTheme">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
+            </intent-filter>
+        </activity>
+
         <activity android:name="android.app.ActivityGroup"
             android:label="ActivityGroup" />
 
diff --git a/tests/tests/widget/res/layout/widget_attribute_layout.xml b/tests/tests/widget/res/layout/widget_attribute_layout.xml
new file mode 100644
index 0000000..f858548
--- /dev/null
+++ b/tests/tests/widget/res/layout/widget_attribute_layout.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright (C) 2019 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
+  -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:orientation="vertical"
+              android:layout_width="match_parent"
+              android:layout_height="match_parent">
+    <ProgressBar
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:id="@+id/progress_bar"
+        android:minWidth="7dp"
+        android:maxWidth="10dp"
+        android:progressTint="#ff00ff"
+        style="@style/ExplicitStyle1" />
+
+    <Switch android:layout_width="match_parent"
+          android:layout_height="match_parent"
+          android:id="@+id/switch_view"
+          android:switchPadding="5dp"
+          style="@style/ExplicitStyle2" />
+
+    <Toolbar android:layout_width="match_parent"
+          android:layout_height="match_parent"
+          android:id="@+id/toolbar_view" />
+
+    <View android:layout_width="match_parent"
+          android:layout_height="match_parent"
+          android:id="@+id/view4"
+          style="?android:attr/textAppearanceLarge"/>
+
+    <Button android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:id="@+id/button1" />
+
+    <Button android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:id="@+id/button2"
+            style="@style/ExplicitStyle1" />
+</LinearLayout>
\ No newline at end of file
diff --git a/tests/tests/widget/res/values/styles.xml b/tests/tests/widget/res/values/styles.xml
index b35ba64..3966207 100644
--- a/tests/tests/widget/res/values/styles.xml
+++ b/tests/tests/widget/res/values/styles.xml
@@ -416,4 +416,29 @@
     <style name="TextView_FontXmlResource">
         <item name="android:fontFamily">@font/samplexmlfont</item>
     </style>
+
+    <style name="WidgetAttributeTestTheme" parent="@android:Theme.Material">
+        <item name="android:toolbarStyle">@style/MyToolbarStyle</item>
+    </style>
+
+    <style name="MyToolbarStyle" parent="@style/MyToolbarStyleParent">
+        <item name="android:titleMarginEnd">3dp</item>
+    </style>
+
+    <style name="MyToolbarStyleParent">
+        <item name="android:titleMarginStart">6dp</item>
+    </style>
+
+    <style name="ExplicitStyle1" parent="@style/ParentOfExplicitStyle1">
+        <item name="android:padding">1dp</item>
+        <item name="android:progress">5</item>
+        <item name="android:max">50</item>
+    </style>
+
+    <style name="ParentOfExplicitStyle1">
+        <item name="android:paddingLeft">2dp</item>
+        <item name="android:mirrorForRtl">true</item>
+    </style>
+
+    <style name="ExplicitStyle2" />
 </resources>
diff --git a/tests/tests/widget/src/android/widget/cts/WidgetAttributeTest.kt b/tests/tests/widget/src/android/widget/cts/WidgetAttributeTest.kt
new file mode 100644
index 0000000..071a0ae
--- /dev/null
+++ b/tests/tests/widget/src/android/widget/cts/WidgetAttributeTest.kt
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2019 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
+ */
+
+package android.widget.cts
+
+import android.app.Activity
+import android.support.test.InstrumentationRegistry
+import android.support.test.filters.MediumTest
+import android.support.test.rule.ActivityTestRule
+import android.support.test.runner.AndroidJUnit4
+import android.support.test.uiautomator.UiDevice
+import android.view.LayoutInflater
+import android.widget.LinearLayout
+import android.widget.ProgressBar
+import android.widget.Switch
+import android.widget.Toolbar
+import org.junit.After
+import org.junit.Assert.assertEquals
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@MediumTest
+@RunWith(AndroidJUnit4::class)
+class WidgetAttributeTest {
+    companion object {
+        const val DISABLE_SHELL_COMMAND =
+                "settings delete global debug_view_attributes_application_package"
+        const val ENABLE_SHELL_COMMAND =
+                "settings put global debug_view_attributes_application_package android.widget.cts"
+    }
+
+    @get:Rule
+    val activityRule = ActivityTestRule<Activity>(Activity::class.java, true, false)
+    private lateinit var uiDevice: UiDevice
+
+    @Before
+    fun setUp() {
+        uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
+        uiDevice.executeShellCommand(ENABLE_SHELL_COMMAND)
+        activityRule.launchActivity(null)
+    }
+
+    @After
+    fun tearDown() {
+        uiDevice.executeShellCommand(DISABLE_SHELL_COMMAND)
+    }
+
+    @Test
+    fun testGetAttributeSourceResourceMap() {
+        val inflater = LayoutInflater.from(activityRule.getActivity())
+        val rootView = inflater.inflate(R.layout.widget_attribute_layout, null) as LinearLayout
+
+        // ProgressBar that has an explicit style ExplicitStyle1 set via style = ...
+        val progressBar = rootView.findViewById<ProgressBar>(R.id.progress_bar)
+        val attributeMapProgressBar = progressBar!!.attributeSourceResourceMap
+        assertEquals(R.layout.widget_attribute_layout,
+                attributeMapProgressBar[android.R.attr.minWidth]!!.toInt())
+        assertEquals(R.layout.widget_attribute_layout,
+                attributeMapProgressBar[android.R.attr.maxWidth]!!.toInt())
+        assertEquals(R.layout.widget_attribute_layout,
+                attributeMapProgressBar[android.R.attr.progressTint]!!.toInt())
+        assertEquals(R.style.ExplicitStyle1,
+                attributeMapProgressBar[android.R.attr.progress]!!.toInt())
+        assertEquals(R.style.ExplicitStyle1,
+                attributeMapProgressBar[android.R.attr.padding]!!.toInt())
+        assertEquals(R.style.ExplicitStyle1,
+                attributeMapProgressBar[android.R.attr.max]!!.toInt())
+        assertEquals(R.style.ParentOfExplicitStyle1,
+                attributeMapProgressBar[android.R.attr.mirrorForRtl]!!.toInt())
+
+        // Switch that has an explicit style ExplicitStyle2 set via style = ...
+        val switch = rootView.findViewById<Switch>(R.id.switch_view)
+        val attributeMapSwitch = switch!!.attributeSourceResourceMap
+        assertEquals(R.layout.widget_attribute_layout,
+                attributeMapSwitch[android.R.attr.switchPadding]!!.toInt())
+
+        // Toolbar that has MyToolbarStyle set via the theme android:toolbarStyle = ...
+        val toolbar = rootView.findViewById<Toolbar>(R.id.toolbar_view)
+        val attributeMapToobar = toolbar!!.attributeSourceResourceMap
+        assertEquals(R.style.MyToolbarStyle,
+                attributeMapToobar[android.R.attr.titleMarginEnd]!!.toInt())
+        assertEquals(R.style.MyToolbarStyleParent,
+                attributeMapToobar[android.R.attr.titleMarginStart]!!.toInt())
+    }
+}
\ No newline at end of file