Merge "Update show4GForLTE config"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0f3b18d..4a2443a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5655,12 +5655,18 @@
     <string name="remove_and_uninstall_device_admin">Deactivate &amp; uninstall</string>
     <!-- Label for screen showing to select device admin apps -->
     <string name="select_device_admin_msg">Device admin apps</string>
+
     <!-- Message when there are no available device admin apps to display -->
     <string name="no_device_admins">No device admin apps available</string>
     <!-- Title for personal device admin apps on the list [CHAR_LIMIT=25] -->
     <string name="personal_device_admin_title">Personal</string>
     <!-- Title for managed device admin apps on the list [CHAR_LIMIT=25] -->
     <string name="managed_device_admin_title">Work</string>
+    <!-- Title for whether to enable SMS access restriction [CHAR LIMIT=50]-->
+    <string name="sms_access_restriction_enabled">Restrict SMS &amp; call log access</string>
+    <!-- Summary for whether to enable SMS access restriction [CHAR LIMIT=NONE]-->
+    <string name="sms_access_restriction_enabled_summary">Only default phone and messaging apps have SMS &amp; call log permissions</string>
+
 
     <!-- Message when there are no available trust agents to display -->
     <string name="no_trust_agents">No available trust agents</string>
diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml
index 3d08cd8..6528cf7 100644
--- a/res/xml/development_settings.xml
+++ b/res/xml/development_settings.xml
@@ -513,6 +513,11 @@
         <Preference
             android:key="reset_shortcut_manager_throttling"
             android:title="@string/reset_shortcut_manager_throttling" />
+
+        <SwitchPreference
+            android:key="sms_access_restriction_enabled"
+            android:title="@string/sms_access_restriction_enabled"
+            android:summary="@string/sms_access_restriction_enabled_summary" />
     </PreferenceCategory>
 
     <com.android.settings.development.autofill.AutofillPreferenceCategory
diff --git a/res/xml/installed_app_details.xml b/res/xml/installed_app_details.xml
deleted file mode 100644
index 42822c0..0000000
--- a/res/xml/installed_app_details.xml
+++ /dev/null
@@ -1,93 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  Copyright (C) 2016 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.
-  -->
-
-<PreferenceScreen
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    android:key="installed_app_detail_settings_screen"
-    app:initialExpandedChildrenCount="6">
-
-    <com.android.settings.applications.LayoutPreference
-        android:key="header_view"
-        android:layout="@layout/settings_entity_header"
-        android:selectable="false"
-        android:order="-10000"/>
-
-    <com.android.settings.applications.LayoutPreference
-        android:key="instant_app_buttons"
-        android:layout="@layout/instant_app_buttons"
-        android:selectable="false"
-        android:order="-9999"/>
-
-    <com.android.settings.widget.ActionButtonPreference
-        android:key="action_buttons"
-        android:order="-9998" />
-
-    <Preference
-        android:key="notification_settings"
-        android:title="@string/notifications_label"
-        android:selectable="true"/>
-
-    <com.android.settings.widget.FixedLineSummaryPreference
-        android:key="permission_settings"
-        android:title="@string/permissions_label"
-        android:summary="@string/summary_placeholder"
-        android:selectable="true"
-        app:summaryLineCount="1" />
-
-    <Preference
-        android:key="storage_settings"
-        android:title="@string/storage_settings"
-        android:summary="@string/summary_placeholder"
-        android:selectable="true"/>
-
-    <com.android.settings.applications.AppDomainsPreference
-        android:key="instant_app_launch_supported_domain_urls"
-        android:title="@string/app_launch_supported_domain_urls_title"
-        android:selectable="true" />
-
-    <Preference
-        android:key="data_settings"
-        android:title="@string/data_usage_summary_title"
-        android:summary="@string/summary_placeholder"
-        android:selectable="true"/>
-
-    <Preference
-        android:key="battery"
-        android:title="@string/power_usage_summary_title"
-        android:summary="@string/summary_placeholder"
-        android:selectable="true"/>
-
-    <Preference
-        android:key="preferred_settings"
-        android:title="@string/launch_by_default"
-        android:summary="@string/summary_placeholder"
-        android:selectable="true"/>
-
-    <Preference
-        android:key="memory"
-        android:title="@string/memory_settings_title"
-        android:summary="@string/summary_placeholder"
-        android:enabled="false"
-        android:selectable="true"/>
-
-    <Preference
-        android:key="app_version"
-        android:selectable="false"
-        android:order="9999"/>
-
-</PreferenceScreen>
\ No newline at end of file
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index dbcb389..82c9828 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -458,6 +458,7 @@
         controllers.add(new AllowAppsOnExternalPreferenceController(context));
         controllers.add(new ResizableActivityPreferenceController(context));
         controllers.add(new FreeformWindowsPreferenceController(context));
+        controllers.add(new SmsAccessRestrictionPreferenceController(context));
         controllers.add(new ShortcutManagerThrottlingPreferenceController(context));
         controllers.add(new EnableGnssRawMeasFullTrackingPreferenceController(context));
         controllers.add(new CbrsDataSwitchPreferenceController(context));
diff --git a/src/com/android/settings/development/SmsAccessRestrictionPreferenceController.java b/src/com/android/settings/development/SmsAccessRestrictionPreferenceController.java
new file mode 100644
index 0000000..b3f7b23
--- /dev/null
+++ b/src/com/android/settings/development/SmsAccessRestrictionPreferenceController.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2018 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 com.android.settings.development;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.development.DeveloperOptionsPreferenceController;
+
+import androidx.preference.Preference;
+import androidx.preference.SwitchPreference;
+
+// STOPSHIP b/118694572: remove the kill switch once the feature is tested and stable
+public class SmsAccessRestrictionPreferenceController extends DeveloperOptionsPreferenceController
+        implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
+
+    private static final String SMS_ACCESS_RESTRICTION_ENABLED_KEY
+            = "sms_access_restriction_enabled";
+
+    public SmsAccessRestrictionPreferenceController(Context context) {
+        super(context);
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return SMS_ACCESS_RESTRICTION_ENABLED_KEY;
+    }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        writeSetting((boolean) newValue);
+        return true;
+    }
+
+    private void writeSetting(boolean isEnabled) {
+        Settings.Global.putInt(mContext.getContentResolver(),
+                Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED,
+                isEnabled ? 1 : 0);
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        final int mode = Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, 0);
+        ((SwitchPreference) mPreference).setChecked(mode != 0);
+    }
+
+    @Override
+    protected void onDeveloperOptionsSwitchDisabled() {
+        super.onDeveloperOptionsSwitchDisabled();
+        writeSetting(false);
+        ((SwitchPreference) mPreference).setChecked(false);
+    }
+}
diff --git a/src/com/android/settings/homepage/contextualcards/CardDatabaseHelper.java b/src/com/android/settings/homepage/contextualcards/CardDatabaseHelper.java
index 11ab8d8..647d718 100644
--- a/src/com/android/settings/homepage/contextualcards/CardDatabaseHelper.java
+++ b/src/com/android/settings/homepage/contextualcards/CardDatabaseHelper.java
@@ -30,7 +30,7 @@
 public class CardDatabaseHelper extends SQLiteOpenHelper {
     private static final String TAG = "CardDatabaseHelper";
     private static final String DATABASE_NAME = "homepage_cards.db";
-    private static final int DATABASE_VERSION = 3;
+    private static final int DATABASE_VERSION = 4;
 
     public static final String CARD_TABLE = "cards";
 
@@ -56,7 +56,7 @@
         String SLICE_URI = "slice_uri";
 
         /**
-         * Category of the card. The value is between 0 to 3.
+         * Category of the card.
          */
         String CATEGORY = "category";
 
@@ -133,11 +133,7 @@
                     CardColumns.SLICE_URI +
                     " TEXT, " +
                     CardColumns.CATEGORY +
-                    " INTEGER DEFAULT 0 CHECK (" +
-                    CardColumns.CATEGORY +
-                    " >= 0 AND " +
-                    CardColumns.CATEGORY +
-                    " <= 3), " +
+                    " INTEGER DEFAULT 0, " +
                     CardColumns.LOCALIZED_TO_LOCALE +
                     " TEXT, " +
                     CardColumns.PACKAGE_NAME +
diff --git a/tests/robotests/src/com/android/settings/development/SmsAccessRestrictionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/SmsAccessRestrictionPreferenceControllerTest.java
new file mode 100644
index 0000000..7a0dd68
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/SmsAccessRestrictionPreferenceControllerTest.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2017 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 com.android.settings.development;
+
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class SmsAccessRestrictionPreferenceControllerTest {
+
+    @Mock
+    private SwitchPreference mPreference;
+    @Mock
+    private PreferenceScreen mPreferenceScreen;
+
+    private Context mContext;
+    private SmsAccessRestrictionPreferenceController mController;
+
+    @Before
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+        mContext = RuntimeEnvironment.application;
+        mController = new SmsAccessRestrictionPreferenceController(mContext);
+        when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
+            .thenReturn(mPreference);
+        mController.displayPreference(mPreferenceScreen);
+    }
+
+    @Test
+    public void onPreferenceChange_settingEnabled_enableSmsRestrictionShouldBeOn() {
+        mController.onPreferenceChange(mPreference, true /* new value */);
+
+        final int mode = Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, -1 /* default */);
+
+        assertThat(mode).isEqualTo(1);
+    }
+
+    @Test
+    public void onPreferenceChange_settingDisabled_enableSmsRestrictionShouldBeOff() {
+        mController.onPreferenceChange(mPreference, false /* new value */);
+
+        final int mode = Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, -1 /* default */);
+
+        assertThat(mode).isEqualTo(0);
+    }
+
+    @Test
+    public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
+        Settings.Global.putInt(mContext.getContentResolver(),
+                Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, 0);
+        mController.updateState(mPreference);
+
+        verify(mPreference).setChecked(false);
+    }
+
+    @Test
+    public void updateState_settingEnabled_preferenceShouldBeChecked() {
+        Settings.Global.putInt(mContext.getContentResolver(),
+                Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, 1);
+        mController.updateState(mPreference);
+
+        verify(mPreference).setChecked(true);
+    }
+
+    @Test
+    public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
+        mController.onDeveloperOptionsSwitchDisabled();
+
+        final int mode = Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, -1 /* default */);
+
+        assertThat(mode).isEqualTo(0);
+        verify(mPreference).setChecked(false);
+        verify(mPreference).setEnabled(false);
+    }
+}