Snap for 8370649 from 5fd1f8fe4e03120f01634f657195e2461f4e1d2e to mainline-go-odp-release

Change-Id: I7eb51c7f06c09d4031f26295ce8fdf0ccd627085
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 26b79d8..129cb8f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4316,7 +4316,7 @@
     <!-- About phone settings screen, setting option name to see licensing info for WebView component. [CHAR LIMIT=35] -->
     <string name="webview_license_title">System WebView License</string>
     <!-- About phone settings screen, setting option name to see wallpapers attributions -->
-    <string name="wallpaper_attributions">Wallpapers</string>
+    <string name="wallpaper_attributions">Wallpaper credits</string>
     <!-- About phone settings screen, setting option name to see wallpapers attributions values -->
     <string name="wallpaper_attributions_values">Satellite imagery providers:\n©2014 CNES / Astrium, DigitalGlobe, Bluesky</string>
 
diff --git a/src/com/android/settings/accessibility/CaptionAppearanceFragment.java b/src/com/android/settings/accessibility/CaptionAppearanceFragment.java
index 7eceb7d..13055be 100644
--- a/src/com/android/settings/accessibility/CaptionAppearanceFragment.java
+++ b/src/com/android/settings/accessibility/CaptionAppearanceFragment.java
@@ -22,6 +22,8 @@
 import android.content.res.Resources;
 import android.graphics.Color;
 import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
 import android.provider.Settings;
 import android.view.View;
 import android.view.accessibility.CaptioningManager;
@@ -92,6 +94,7 @@
 
     private final List<Preference> mPreferenceList = new ArrayList<>();
 
+    private final Handler mHandler = new Handler(Looper.getMainLooper());
     private final View.OnLayoutChangeListener mLayoutChangeListener =
             new View.OnLayoutChangeListener() {
                 @Override
@@ -99,7 +102,7 @@
                         int oldLeft, int oldTop, int oldRight, int oldBottom) {
                     // Remove the listener once the callback is triggered.
                     mPreviewViewport.removeOnLayoutChangeListener(this);
-                    refreshPreviewText();
+                    mHandler.post(() ->refreshPreviewText());
                 }
             };
 
diff --git a/src/com/android/settings/network/NetworkProviderSettings.java b/src/com/android/settings/network/NetworkProviderSettings.java
index faf5010..ae030f4 100644
--- a/src/com/android/settings/network/NetworkProviderSettings.java
+++ b/src/com/android/settings/network/NetworkProviderSettings.java
@@ -34,9 +34,11 @@
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.PowerManager;
+import android.os.UserManager;
 import android.provider.Settings;
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
+import android.util.EventLog;
 import android.util.FeatureFlagUtils;
 import android.util.Log;
 import android.view.ContextMenu;
@@ -204,6 +206,8 @@
      * by the Test DPC tool in AFW mode.
      */
     protected boolean mIsRestricted;
+    @VisibleForTesting
+    boolean mIsAdmin = true;
 
     @VisibleForTesting
     AirplaneModeEnabler mAirplaneModeEnabler;
@@ -294,6 +298,13 @@
         addPreferences();
 
         mIsRestricted = isUiRestricted();
+        mIsAdmin = isAdminUser();
+    }
+
+    private boolean isAdminUser() {
+        final UserManager userManager = getSystemService(UserManager.class);
+        if (userManager == null) return true;
+        return userManager.isAdminUser();
     }
 
     private void addPreferences() {
@@ -566,7 +577,7 @@
 
         if (mSelectedWifiEntry.canDisconnect()) {
             if (mSelectedWifiEntry.canShare()) {
-                menu.add(Menu.NONE, MENU_ID_SHARE, 0 /* order */, R.string.share);
+                addShareMenuIfSuitable(menu);
             }
             menu.add(Menu.NONE, MENU_ID_DISCONNECT, 1 /* order */,
                     R.string.wifi_disconnect_button_text);
@@ -575,7 +586,7 @@
         // "forget" for normal saved network. And "disconnect" for ephemeral network because it
         // could only be disconnected and be put in blocklists so it won't be used again.
         if (canForgetNetwork()) {
-            menu.add(Menu.NONE, MENU_ID_FORGET, 0 /* order */, R.string.forget);
+            addForgetMenuIfSuitable(menu);
         }
 
         WifiConfiguration config = mSelectedWifiEntry.getWifiConfiguration();
@@ -590,6 +601,23 @@
         }
     }
 
+    @VisibleForTesting
+    void addShareMenuIfSuitable(ContextMenu menu) {
+        if (mIsAdmin) {
+            menu.add(Menu.NONE, MENU_ID_SHARE, 0 /* order */, R.string.share);
+            return;
+        }
+        Log.w(TAG, "Don't add the Wi-Fi share menu because the user is not an admin.");
+        EventLog.writeEvent(0x534e4554, "206986392", -1 /* UID */, "User is not an admin");
+    }
+
+    @VisibleForTesting
+    void addForgetMenuIfSuitable(ContextMenu menu) {
+        if (mIsAdmin) {
+            menu.add(Menu.NONE, MENU_ID_FORGET, 0 /* order */, R.string.forget);
+        }
+    }
+
     private boolean canForgetNetwork() {
         return mSelectedWifiEntry.canForget() && !WifiUtils.isNetworkLockedDown(getActivity(),
                 mSelectedWifiEntry.getWifiConfiguration());
diff --git a/src/com/android/settings/safetycenter/BiometricsSafetySource.java b/src/com/android/settings/safetycenter/BiometricsSafetySource.java
index e6f25fc..cb3ad35 100644
--- a/src/com/android/settings/safetycenter/BiometricsSafetySource.java
+++ b/src/com/android/settings/safetycenter/BiometricsSafetySource.java
@@ -25,7 +25,6 @@
 import android.os.UserHandle;
 import android.safetycenter.SafetyEvent;
 import android.safetycenter.SafetySourceData;
-import android.safetycenter.SafetySourceSeverity;
 import android.safetycenter.SafetySourceStatus;
 
 import com.android.settings.R;
@@ -122,8 +121,8 @@
             Intent clickIntent, boolean enabled, boolean hasEnrolled, SafetyEvent safetyEvent) {
         final PendingIntent pendingIntent = createPendingIntent(context, clickIntent);
         final int severityLevel =
-                enabled && hasEnrolled ? SafetySourceSeverity.LEVEL_INFORMATION
-                        : SafetySourceSeverity.LEVEL_UNSPECIFIED;
+                enabled && hasEnrolled ? SafetySourceData.SEVERITY_LEVEL_INFORMATION
+                        : SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED;
 
         final SafetySourceStatus status = new SafetySourceStatus.Builder(title, summary,
                 severityLevel).setPendingIntent(pendingIntent).setEnabled(enabled).build();
diff --git a/src/com/android/settings/safetycenter/LockScreenSafetySource.java b/src/com/android/settings/safetycenter/LockScreenSafetySource.java
index 91e9773..80a1323 100644
--- a/src/com/android/settings/safetycenter/LockScreenSafetySource.java
+++ b/src/com/android/settings/safetycenter/LockScreenSafetySource.java
@@ -26,7 +26,6 @@
 import android.safetycenter.SafetyEvent;
 import android.safetycenter.SafetySourceData;
 import android.safetycenter.SafetySourceIssue;
-import android.safetycenter.SafetySourceSeverity;
 import android.safetycenter.SafetySourceStatus;
 import android.safetycenter.SafetySourceStatus.IconAction;
 
@@ -71,9 +70,9 @@
         final boolean isLockPatternSecure = screenLockPreferenceDetailsUtils.isLockPatternSecure();
         final int severityLevel = enabled
                 ? isLockPatternSecure
-                        ? SafetySourceSeverity.LEVEL_INFORMATION
-                        : SafetySourceSeverity.LEVEL_RECOMMENDATION
-                : SafetySourceSeverity.LEVEL_UNSPECIFIED;
+                        ? SafetySourceData.SEVERITY_LEVEL_INFORMATION
+                        : SafetySourceData.SEVERITY_LEVEL_RECOMMENDATION
+                : SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED;
 
 
         final SafetySourceStatus status = new SafetySourceStatus.Builder(
@@ -138,7 +137,7 @@
                 NO_SCREEN_LOCK_ISSUE_ID,
                 context.getString(R.string.no_screen_lock_issue_title),
                 context.getString(R.string.no_screen_lock_issue_summary),
-                SafetySourceSeverity.LEVEL_RECOMMENDATION,
+                SafetySourceData.SEVERITY_LEVEL_RECOMMENDATION,
                 NO_SCREEN_LOCK_ISSUE_TYPE_ID)
                 .setIssueCategory(SafetySourceIssue.ISSUE_CATEGORY_DEVICE)
                 .addAction(action).build();
diff --git a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
index 6f26826..dd0c20a 100644
--- a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
+++ b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
@@ -100,6 +100,7 @@
     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
+        setIfOnlyAvailableForAdmins(true);
         mIsUiRestricted = isUiRestricted();
     }
 
diff --git a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
index 3182cd0..5ee9676 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
@@ -15,6 +15,9 @@
  */
 package com.android.settings.network;
 
+import static com.android.settings.network.NetworkProviderSettings.MENU_ID_DISCONNECT;
+import static com.android.settings.network.NetworkProviderSettings.MENU_ID_FORGET;
+import static com.android.settings.network.NetworkProviderSettings.MENU_ID_SHARE;
 import static com.android.settings.wifi.WifiConfigUiBase2.MODE_CONNECT;
 import static com.android.settings.wifi.WifiConfigUiBase2.MODE_MODIFY;
 
@@ -77,6 +80,7 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
+import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.RuntimeEnvironment;
@@ -118,6 +122,8 @@
     @Mock
     private LayoutPreference mResetInternetPreference;
     @Mock
+    private ContextMenu mContextMenu;
+    @Mock
     private MenuItem mMenuItem;
     @Mock
     InternetUpdater mInternetUpdater;
@@ -321,12 +327,10 @@
         final View view = mock(View.class);
         when(view.getTag()).thenReturn(connectedWifiEntryPreference);
 
-        final ContextMenu menu = mock(ContextMenu.class);
-        mNetworkProviderSettings.onCreateContextMenu(menu, view, null /* info */);
+        mNetworkProviderSettings.onCreateContextMenu(mContextMenu, view, null /* info */);
 
-        verify(menu).add(anyInt(), eq(NetworkProviderSettings.MENU_ID_FORGET), anyInt(), anyInt());
-        verify(menu).add(anyInt(), eq(NetworkProviderSettings.MENU_ID_DISCONNECT), anyInt(),
-                anyInt());
+        verify(mContextMenu).add(anyInt(), eq(MENU_ID_FORGET), anyInt(), anyInt());
+        verify(mContextMenu).add(anyInt(), eq(MENU_ID_DISCONNECT), anyInt(), anyInt());
     }
 
     @Test
@@ -346,10 +350,9 @@
         final View view = mock(View.class);
         when(view.getTag()).thenReturn(connectedWifiEntryPreference);
 
-        final ContextMenu menu = mock(ContextMenu.class);
-        mNetworkProviderSettings.onCreateContextMenu(menu, view, null /* info */);
+        mNetworkProviderSettings.onCreateContextMenu(mContextMenu, view, null /* info */);
 
-        verify(menu).add(anyInt(), eq(NetworkProviderSettings.MENU_ID_SHARE), anyInt(), anyInt());
+        verify(mContextMenu).add(anyInt(), eq(MENU_ID_SHARE), anyInt(), anyInt());
     }
 
     @Test
@@ -369,11 +372,9 @@
         final View view = mock(View.class);
         when(view.getTag()).thenReturn(connectedWifiEntryPreference);
 
-        final ContextMenu menu = mock(ContextMenu.class);
-        mNetworkProviderSettings.onCreateContextMenu(menu, view, null /* info */);
+        mNetworkProviderSettings.onCreateContextMenu(mContextMenu, view, null /* info */);
 
-        verify(menu, never())
-                .add(anyInt(), eq(NetworkProviderSettings.MENU_ID_SHARE), anyInt(), anyInt());
+        verify(mContextMenu, never()).add(anyInt(), eq(MENU_ID_SHARE), anyInt(), anyInt());
     }
 
     @Test
@@ -680,6 +681,46 @@
         verify(mAirplaneModeEnabler).stop();
     }
 
+    @Test
+    public void addShareMenuIfSuitable_isAdmin_addMenu() {
+        mNetworkProviderSettings.mIsAdmin = true;
+        Mockito.reset(mContextMenu);
+
+        mNetworkProviderSettings.addShareMenuIfSuitable(mContextMenu);
+
+        verify(mContextMenu).add(anyInt(), eq(MENU_ID_SHARE), anyInt(), anyInt());
+    }
+
+    @Test
+    public void addShareMenuIfSuitable_isNotAdmin_notAddMenu() {
+        mNetworkProviderSettings.mIsAdmin = false;
+        Mockito.reset(mContextMenu);
+
+        mNetworkProviderSettings.addShareMenuIfSuitable(mContextMenu);
+
+        verify(mContextMenu, never()).add(anyInt(), eq(MENU_ID_SHARE), anyInt(), anyInt());
+    }
+
+    @Test
+    public void addForgetMenuIfSuitable_isAdmin_addMenu() {
+        mNetworkProviderSettings.mIsAdmin = true;
+        Mockito.reset(mContextMenu);
+
+        mNetworkProviderSettings.addForgetMenuIfSuitable(mContextMenu);
+
+        verify(mContextMenu).add(anyInt(), eq(MENU_ID_FORGET), anyInt(), anyInt());
+    }
+
+    @Test
+    public void addForgetMenuIfSuitable_isNotAdmin_notAddMenu() {
+        mNetworkProviderSettings.mIsAdmin = false;
+        Mockito.reset(mContextMenu);
+
+        mNetworkProviderSettings.addForgetMenuIfSuitable(mContextMenu);
+
+        verify(mContextMenu, never()).add(anyInt(), eq(MENU_ID_FORGET), anyInt(), anyInt());
+    }
+
     @Implements(PreferenceFragmentCompat.class)
     public static class ShadowPreferenceFragmentCompat {
 
diff --git a/tests/unit/src/com/android/settings/safetycenter/BiometricsSafetySourceTest.java b/tests/unit/src/com/android/settings/safetycenter/BiometricsSafetySourceTest.java
index addb491..7ff407d 100644
--- a/tests/unit/src/com/android/settings/safetycenter/BiometricsSafetySourceTest.java
+++ b/tests/unit/src/com/android/settings/safetycenter/BiometricsSafetySourceTest.java
@@ -40,7 +40,6 @@
 import android.os.UserHandle;
 import android.safetycenter.SafetyEvent;
 import android.safetycenter.SafetySourceData;
-import android.safetycenter.SafetySourceSeverity;
 import android.safetycenter.SafetySourceStatus;
 
 import androidx.test.core.app.ApplicationProvider;
@@ -442,7 +441,7 @@
                 any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
         SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
         assertThat(safetySourceStatus.getSeverityLevel())
-                .isEqualTo(SafetySourceSeverity.LEVEL_INFORMATION);
+                .isEqualTo(SafetySourceData.SEVERITY_LEVEL_INFORMATION);
     }
 
     @Test
@@ -460,7 +459,7 @@
                 any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
         SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
         assertThat(safetySourceStatus.getSeverityLevel())
-                .isEqualTo(SafetySourceSeverity.LEVEL_INFORMATION);
+                .isEqualTo(SafetySourceData.SEVERITY_LEVEL_INFORMATION);
     }
 
     @Test
@@ -478,7 +477,7 @@
                 any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
         SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
         assertThat(safetySourceStatus.getSeverityLevel())
-                .isEqualTo(SafetySourceSeverity.LEVEL_UNSPECIFIED);
+                .isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
     }
 
     @Test
@@ -495,7 +494,7 @@
                 any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
         SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
         assertThat(safetySourceStatus.getSeverityLevel())
-                .isEqualTo(SafetySourceSeverity.LEVEL_INFORMATION);
+                .isEqualTo(SafetySourceData.SEVERITY_LEVEL_INFORMATION);
     }
 
     @Test
@@ -512,7 +511,7 @@
                 any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
         SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
         assertThat(safetySourceStatus.getSeverityLevel())
-                .isEqualTo(SafetySourceSeverity.LEVEL_UNSPECIFIED);
+                .isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
     }
 
     @Test
@@ -529,7 +528,7 @@
                 any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
         SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
         assertThat(safetySourceStatus.getSeverityLevel())
-                .isEqualTo(SafetySourceSeverity.LEVEL_INFORMATION);
+                .isEqualTo(SafetySourceData.SEVERITY_LEVEL_INFORMATION);
     }
 
     @Test
@@ -546,7 +545,7 @@
                 any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
         SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
         assertThat(safetySourceStatus.getSeverityLevel())
-                .isEqualTo(SafetySourceSeverity.LEVEL_UNSPECIFIED);
+                .isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
     }
 
     private void assertSafetySourceDisabledDataSetWithSingularSummary(String expectedTitleResName,
@@ -606,7 +605,7 @@
         assertThat(safetySourceStatus.getSummary().toString()).isEqualTo(expectedSummary);
         assertThat(safetySourceStatus.isEnabled()).isFalse();
         assertThat(safetySourceStatus.getSeverityLevel())
-                .isEqualTo(SafetySourceSeverity.LEVEL_UNSPECIFIED);
+                .isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
 
         final Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
         assertThat(clickIntent).isNotNull();
diff --git a/tests/unit/src/com/android/settings/safetycenter/LockScreenSafetySourceTest.java b/tests/unit/src/com/android/settings/safetycenter/LockScreenSafetySourceTest.java
index 53f4e7c..e7ce002 100644
--- a/tests/unit/src/com/android/settings/safetycenter/LockScreenSafetySourceTest.java
+++ b/tests/unit/src/com/android/settings/safetycenter/LockScreenSafetySourceTest.java
@@ -32,7 +32,6 @@
 import android.safetycenter.SafetyEvent;
 import android.safetycenter.SafetySourceData;
 import android.safetycenter.SafetySourceIssue;
-import android.safetycenter.SafetySourceSeverity;
 import android.safetycenter.SafetySourceStatus;
 import android.safetycenter.SafetySourceStatus.IconAction;
 
@@ -179,7 +178,7 @@
         SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
 
         assertThat(safetySourceStatus.getSeverityLevel())
-                .isEqualTo(SafetySourceSeverity.LEVEL_INFORMATION);
+                .isEqualTo(SafetySourceData.SEVERITY_LEVEL_INFORMATION);
     }
 
     @Test
@@ -200,7 +199,7 @@
         SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
 
         assertThat(safetySourceStatus.getSeverityLevel())
-                .isEqualTo(SafetySourceSeverity.LEVEL_RECOMMENDATION);
+                .isEqualTo(SafetySourceData.SEVERITY_LEVEL_RECOMMENDATION);
     }
 
     @Test
@@ -221,7 +220,7 @@
         SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
 
         assertThat(safetySourceStatus.getSeverityLevel())
-                .isEqualTo(SafetySourceSeverity.LEVEL_UNSPECIFIED);
+                .isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
     }
 
     @Test
@@ -242,7 +241,7 @@
         SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
 
         assertThat(safetySourceStatus.getSeverityLevel())
-                .isEqualTo(SafetySourceSeverity.LEVEL_UNSPECIFIED);
+                .isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
     }
 
     @Test
@@ -289,7 +288,8 @@
         assertThat(issue.getSummary().toString()).isEqualTo(
                 ResourcesUtils.getResourcesString(mApplicationContext,
                         "no_screen_lock_issue_summary"));
-        assertThat(issue.getSeverityLevel()).isEqualTo(SafetySourceSeverity.LEVEL_RECOMMENDATION);
+        assertThat(issue.getSeverityLevel()).isEqualTo(
+                SafetySourceData.SEVERITY_LEVEL_RECOMMENDATION);
         assertThat(issue.getIssueTypeId()).isEqualTo(
                 LockScreenSafetySource.NO_SCREEN_LOCK_ISSUE_TYPE_ID);
         assertThat(issue.getIssueCategory()).isEqualTo(SafetySourceIssue.ISSUE_CATEGORY_DEVICE);