Merge "[Provider Model] Update airplane mode icon" into sc-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 6dfae4b..01c38d8 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -10522,6 +10522,9 @@
     <string name="admin_device_owner_message">Your admin can monitor and manage apps and data
         associated with this device, including settings, permissions, corporate access,
         network activity, and the device\'s location information.</string>
+    <!-- Shown in admin details page to warn user about policies the admin can set on a financed device. [CHAR LIMIT=NONE] -->
+    <string name="admin_financed_message">Your device admin may be able to access data associated
+        with this device and change this device\’s settings.</string>
 
     <!-- Turn off a conditional state of the device (e.g. airplane mode, or hotspot) [CHAR LIMIT=30] -->
     <string name="condition_turn_off">Turn off</string>
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index d510ac7..6b629ac 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -16,7 +16,7 @@
 
 package com.android.settings.accessibility;
 
-import static com.android.settingslib.TwoTargetPreference.ICON_SIZE_MEDIUM;
+import static com.android.settingslib.widget.TwoTargetPreference.ICON_SIZE_MEDIUM;
 
 import android.accessibilityservice.AccessibilityServiceInfo;
 import android.accessibilityservice.AccessibilityShortcutInfo;
diff --git a/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceController.java b/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceController.java
index 73d80a3..8e8e072 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceController.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceController.java
@@ -16,7 +16,7 @@
 
 package com.android.settings.applications.defaultapps;
 
-import static com.android.settingslib.TwoTargetPreference.ICON_SIZE_MEDIUM;
+import static com.android.settingslib.widget.TwoTargetPreference.ICON_SIZE_MEDIUM;
 
 import android.content.Context;
 import android.content.Intent;
@@ -33,9 +33,9 @@
 import com.android.settings.Utils;
 import com.android.settings.core.PreferenceControllerMixin;
 import com.android.settings.widget.GearPreference;
-import com.android.settingslib.TwoTargetPreference;
 import com.android.settingslib.applications.DefaultAppInfo;
 import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.widget.TwoTargetPreference;
 
 public abstract class DefaultAppPreferenceController extends AbstractPreferenceController
         implements PreferenceControllerMixin {
diff --git a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java
index 7c8b96f..1fe3f17 100644
--- a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java
+++ b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java
@@ -16,6 +16,8 @@
 
 package com.android.settings.applications.specialaccess.deviceadmin;
 
+import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_FINANCED;
+
 import android.app.Activity;
 import android.app.ActivityManager;
 import android.app.AppOpsManager;
@@ -661,7 +663,11 @@
                     mAdminWarning.setText(R.string.admin_profile_owner_user_message);
                 } else {
                     // Show device owner description.
-                    mAdminWarning.setText(R.string.admin_device_owner_message);
+                    if (isFinancedDevice()) {
+                        mAdminWarning.setText(R.string.admin_financed_message);
+                    } else {
+                        mAdminWarning.setText(R.string.admin_device_owner_message);
+                    }
                 }
                 mActionButton.setText(R.string.remove_device_admin);
                 mActionButton.setEnabled(false);
@@ -759,6 +765,11 @@
         return info != null ? info.isManagedProfile() : false;
     }
 
+    private boolean isFinancedDevice() {
+        return mDPM.isDeviceManaged() && mDPM.getDeviceOwnerType(
+                mDPM.getDeviceOwnerComponentOnAnyUser()) == DEVICE_OWNER_TYPE_FINANCED;
+    }
+
     /**
      * @return an {@link Optional} containing the admin with a given package name, if it exists,
      *         or {@link Optional#empty()} otherwise.
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java b/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java
index 3e0591f..5e6f7e9 100644
--- a/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java
@@ -63,8 +63,8 @@
 import com.android.settingslib.RestrictedLockUtils;
 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
 import com.android.settingslib.RestrictedLockUtilsInternal;
-import com.android.settingslib.TwoTargetPreference;
 import com.android.settingslib.widget.FooterPreference;
+import com.android.settingslib.widget.TwoTargetPreference;
 
 import java.util.HashMap;
 import java.util.List;
diff --git a/src/com/android/settings/core/BasePreferenceController.java b/src/com/android/settings/core/BasePreferenceController.java
index 95c94ce..c90fe48 100644
--- a/src/com/android/settings/core/BasePreferenceController.java
+++ b/src/com/android/settings/core/BasePreferenceController.java
@@ -30,7 +30,6 @@
 import android.util.Log;
 
 import androidx.annotation.Nullable;
-import androidx.lifecycle.LifecycleObserver;
 import androidx.preference.Preference;
 import androidx.preference.PreferenceScreen;
 
@@ -39,7 +38,6 @@
 import com.android.settings.slices.SliceData;
 import com.android.settings.slices.Sliceable;
 import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.core.lifecycle.Lifecycle;
 import com.android.settingslib.search.SearchIndexableRaw;
 
 import java.lang.annotation.Retention;
@@ -52,9 +50,6 @@
  * Abstract class to consolidate utility between preference controllers and act as an interface
  * for Slices. The abstract classes that inherit from this class will act as the direct interfaces
  * for each type when plugging into Slices.
- * <p>
- * Controllers defined in xml are automatically {@link Lifecycle#addObserver(LifecycleObserver)
- * wired up} to the settings lifecycle if they implement {@link LifecycleObserver}.
  */
 public abstract class BasePreferenceController extends AbstractPreferenceController implements
         Sliceable {
diff --git a/src/com/android/settings/dashboard/DashboardFragment.java b/src/com/android/settings/dashboard/DashboardFragment.java
index 7acbd19..1b2be80 100644
--- a/src/com/android/settings/dashboard/DashboardFragment.java
+++ b/src/com/android/settings/dashboard/DashboardFragment.java
@@ -27,7 +27,6 @@
 
 import androidx.annotation.CallSuper;
 import androidx.annotation.VisibleForTesting;
-import androidx.lifecycle.LifecycleObserver;
 import androidx.preference.Preference;
 import androidx.preference.PreferenceGroup;
 import androidx.preference.PreferenceManager;
@@ -45,6 +44,7 @@
 import com.android.settings.widget.PrimarySwitchPreference;
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
 import com.android.settingslib.drawer.CategoryKey;
 import com.android.settingslib.drawer.DashboardCategory;
 import com.android.settingslib.drawer.ProviderTile;
diff --git a/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java b/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
index cf23c94..1140291 100644
--- a/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
+++ b/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
@@ -141,17 +141,14 @@
     }
 
     private boolean isNotCurrentUserOrProfile(ComponentName admin, int userId) {
-        return !isFinancedDevice()
-                && (!RestrictedLockUtilsInternal.isAdminInCurrentUserOrProfile(mActivity, admin)
-                        || !RestrictedLockUtils.isCurrentUserOrProfile(mActivity, userId));
+        return !RestrictedLockUtilsInternal.isAdminInCurrentUserOrProfile(mActivity, admin)
+                || !RestrictedLockUtils.isCurrentUserOrProfile(mActivity, userId);
     }
 
     @VisibleForTesting
     void setAdminSupportIcon(View root, ComponentName admin, int userId) {
         ImageView supportIconView = root.requireViewById(R.id.admin_support_icon);
-        if (isFinancedDevice()) {
-            supportIconView.setVisibility(View.GONE);
-        } else if (isNotCurrentUserOrProfile(admin, userId)) {
+        if (isNotCurrentUserOrProfile(admin, userId)) {
             supportIconView.setImageDrawable(
                     mActivity.getDrawable(com.android.internal.R.drawable.ic_info));
 
diff --git a/src/com/android/settings/network/PrivateDnsModeDialogPreference.java b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
index ea29a1d..822aad0 100644
--- a/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
+++ b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
@@ -160,7 +160,7 @@
         final Context context = getContext();
         final ContentResolver contentResolver = context.getContentResolver();
 
-        mMode = ConnectivityManager.getPrivateDnsMode(contentResolver);
+        mMode = ConnectivityManager.getPrivateDnsMode(context);
 
         mEditText = view.findViewById(R.id.private_dns_mode_provider_hostname);
         mEditText.addTextChangedListener(this);
diff --git a/src/com/android/settings/network/PrivateDnsPreferenceController.java b/src/com/android/settings/network/PrivateDnsPreferenceController.java
index 3136040..4aa92f4 100644
--- a/src/com/android/settings/network/PrivateDnsPreferenceController.java
+++ b/src/com/android/settings/network/PrivateDnsPreferenceController.java
@@ -118,7 +118,7 @@
     public CharSequence getSummary() {
         final Resources res = mContext.getResources();
         final ContentResolver cr = mContext.getContentResolver();
-        final String mode = ConnectivityManager.getPrivateDnsMode(cr);
+        final String mode = ConnectivityManager.getPrivateDnsMode(mContext);
         final LinkProperties lp = mLatestLinkProperties;
         final List<InetAddress> dnses = (lp == null) ? null : lp.getValidatedPrivateDnsServers();
         final boolean dnsesResolved = !ArrayUtils.isEmpty(dnses);
diff --git a/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java b/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java
index bab0d5f..5396be5 100644
--- a/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java
+++ b/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java
@@ -46,10 +46,10 @@
 import com.android.settings.core.SubSettingLauncher;
 import com.android.settings.notification.app.AppNotificationSettings;
 import com.android.settings.widget.PrimarySwitchPreference;
-import com.android.settingslib.TwoTargetPreference;
 import com.android.settingslib.applications.ApplicationsState;
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.utils.StringUtil;
+import com.android.settingslib.widget.TwoTargetPreference;
 
 import java.util.ArrayList;
 import java.util.Calendar;
diff --git a/src/com/android/settings/notification/app/RecentConversationPreference.java b/src/com/android/settings/notification/app/RecentConversationPreference.java
index 49e2c02..167fdd6 100644
--- a/src/com/android/settings/notification/app/RecentConversationPreference.java
+++ b/src/com/android/settings/notification/app/RecentConversationPreference.java
@@ -21,7 +21,7 @@
 import androidx.preference.PreferenceViewHolder;
 
 import com.android.settings.R;
-import com.android.settingslib.TwoTargetPreference;
+import com.android.settingslib.widget.TwoTargetPreference;
 
 import com.google.common.annotations.VisibleForTesting;
 
diff --git a/src/com/android/settings/notification/zen/ZenRulePreference.java b/src/com/android/settings/notification/zen/ZenRulePreference.java
index 1f1283d..b8c8354 100644
--- a/src/com/android/settings/notification/zen/ZenRulePreference.java
+++ b/src/com/android/settings/notification/zen/ZenRulePreference.java
@@ -33,8 +33,8 @@
 import com.android.settings.R;
 import com.android.settings.utils.ManagedServiceSettings;
 import com.android.settings.utils.ZenServiceListing;
-import com.android.settingslib.TwoTargetPreference;
 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+import com.android.settingslib.widget.TwoTargetPreference;
 
 import java.util.Map;
 
diff --git a/src/com/android/settings/wfd/WifiDisplaySettings.java b/src/com/android/settings/wfd/WifiDisplaySettings.java
index 21352b7..19b6c54 100755
--- a/src/com/android/settings/wfd/WifiDisplaySettings.java
+++ b/src/com/android/settings/wfd/WifiDisplaySettings.java
@@ -64,9 +64,9 @@
 import com.android.settings.R;
 import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settingslib.TwoTargetPreference;
 import com.android.settingslib.search.Indexable;
 import com.android.settingslib.search.SearchIndexable;
+import com.android.settingslib.widget.TwoTargetPreference;
 
 /**
  * The Settings screen for WifiDisplay configuration and connection management.
diff --git a/src/com/android/settings/widget/PrimaryCheckBoxPreference.java b/src/com/android/settings/widget/PrimaryCheckBoxPreference.java
index a784d5d..c90f198 100644
--- a/src/com/android/settings/widget/PrimaryCheckBoxPreference.java
+++ b/src/com/android/settings/widget/PrimaryCheckBoxPreference.java
@@ -25,7 +25,7 @@
 import androidx.preference.PreferenceViewHolder;
 
 import com.android.settings.R;
-import com.android.settingslib.TwoTargetPreference;
+import com.android.settingslib.widget.TwoTargetPreference;
 
 /**
  * A custom preference that provides inline checkbox. It has a mandatory field for title, and
diff --git a/src/com/android/settings/widget/SettingsMainSwitchBar.java b/src/com/android/settings/widget/SettingsMainSwitchBar.java
index 733be0a..ce2dde5 100644
--- a/src/com/android/settings/widget/SettingsMainSwitchBar.java
+++ b/src/com/android/settings/widget/SettingsMainSwitchBar.java
@@ -84,9 +84,8 @@
     }
 
     /**
-     * If admin is not null, disables the text and switch but keeps the view clickable.
-     * Otherwise, calls setEnabled which will enables the entire view including
-     * the text and switch.
+     * If admin is not null, disables the text and switch but keeps the view clickable (unless the
+     * switch is disabled for other reasons). Otherwise, calls setEnabled.
      */
     public void setDisabledByAdmin(RestrictedLockUtils.EnforcedAdmin admin) {
         mEnforcedAdmin = admin;
@@ -101,7 +100,7 @@
             mDisabledByAdmin = false;
             mSwitch.setVisibility(View.VISIBLE);
             mRestrictedIcon.setVisibility(View.GONE);
-            setEnabled(true);
+            setEnabled(isEnabled());
         }
     }
 
diff --git a/src/com/android/settings/widget/SettingsMainSwitchPreference.java b/src/com/android/settings/widget/SettingsMainSwitchPreference.java
index 80a0021..f627e31 100644
--- a/src/com/android/settings/widget/SettingsMainSwitchPreference.java
+++ b/src/com/android/settings/widget/SettingsMainSwitchPreference.java
@@ -186,6 +186,7 @@
      * Enable or disable the text and switch.
      */
     public void setSwitchBarEnabled(boolean enabled) {
+        setEnabled(enabled);
         if (mMainSwitchBar != null) {
             mMainSwitchBar.setEnabled(enabled);
         }
diff --git a/tests/robotests/src/com/android/settings/accounts/ProviderPreferenceTest.java b/tests/robotests/src/com/android/settings/accounts/ProviderPreferenceTest.java
index 6ed266f..8725a0c 100644
--- a/tests/robotests/src/com/android/settings/accounts/ProviderPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/ProviderPreferenceTest.java
@@ -16,7 +16,7 @@
 
 package com.android.settings.accounts;
 
-import static com.android.settingslib.TwoTargetPreference.ICON_SIZE_MEDIUM;
+import static com.android.settingslib.widget.TwoTargetPreference.ICON_SIZE_MEDIUM;
 
 import static com.google.common.truth.Truth.assertThat;
 
diff --git a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceControllerTest.java
index 31c00ec..e78a394 100644
--- a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceControllerTest.java
@@ -16,7 +16,7 @@
 
 package com.android.settings.applications.defaultapps;
 
-import static com.android.settingslib.TwoTargetPreference.ICON_SIZE_MEDIUM;
+import static com.android.settingslib.widget.TwoTargetPreference.ICON_SIZE_MEDIUM;
 
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -28,8 +28,8 @@
 import androidx.preference.Preference;
 
 import com.android.settings.R;
-import com.android.settingslib.TwoTargetPreference;
 import com.android.settingslib.applications.DefaultAppInfo;
+import com.android.settingslib.widget.TwoTargetPreference;
 
 import org.junit.Before;
 import org.junit.Test;
diff --git a/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java
index b245017..5c3dacd 100644
--- a/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java
@@ -36,10 +36,8 @@
 import android.os.Process;
 import android.os.UserHandle;
 import android.os.UserManager;
-import android.view.View;
 import android.view.ViewGroup;
 import android.widget.FrameLayout;
-import android.widget.ImageView;
 import android.widget.TextView;
 
 import androidx.appcompat.app.AlertDialog;
@@ -109,20 +107,6 @@
     }
 
     @Test
-    public void testSetAdminSupportIconForFinancedDevice_adminSupportIconIsGone() {
-        final ShadowDevicePolicyManager dpmShadow = ShadowDevicePolicyManager.getShadow();
-        final ViewGroup view = new FrameLayout(mActivity);
-        final ImageView supportIconImageView = createAdminSupportIconImageView(view, mActivity);
-        final ComponentName component = new ComponentName("some.package.name",
-                "some.package.name.SomeClass");
-        setupFinancedDevice(dpmShadow);
-
-        mHelper.setAdminSupportIcon(view, component, 123);
-
-        assertEquals(View.GONE, supportIconImageView.getVisibility());
-    }
-
-    @Test
     public void testSetAdminSupportTitle() {
         final ViewGroup view = new FrameLayout(mActivity);
         final TextView textView = createAdminSupportDialogTitleTextView(view, mActivity);
@@ -260,14 +244,6 @@
         verify(builder, never()).setNeutralButton(anyInt(), any());
     }
 
-    private static ImageView createAdminSupportIconImageView(final ViewGroup view,
-            final Activity activity) {
-        final ImageView supportIconView = new ImageView(activity);
-        supportIconView.setId(R.id.admin_support_icon);
-        view.addView(supportIconView);
-        return supportIconView;
-    }
-
     private static TextView createAdminSupportDialogTitleTextView(final ViewGroup view,
             final Activity activity) {
         final TextView textView = new TextView(activity);