Merge "[Settings] Code refactor for combining TelephonyCallback with Lifecycle" into tm-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 4d3b6d0..762d84d 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1789,6 +1789,18 @@
android:value="true" />
</activity>
+ <activity android:name="Settings$PrivacyControlsActivity"
+ android:label="@string/privacy_controls_title"
+ android:exported="true"
+ android:icon="@drawable/ic_settings_privacy">
+ <intent-filter android:priority="1">
+ <action android:name="android.settings.PRIVACY_CONTROLS" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.privacy.PrivacyControlsFragment" />
+ </activity>
+
<activity android:name=".development.tare.TareHomePage"
android:label="@string/tare_settings"
android:exported="false" />
diff --git a/res/color-night/accent_select_primary_text.xml b/res/color-night/accent_select_primary_text.xml
new file mode 100644
index 0000000..049ddf6
--- /dev/null
+++ b/res/color-night/accent_select_primary_text.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2022 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.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:color="?android:attr/textColorPrimaryInverse" />
+</selector>
\ No newline at end of file
diff --git a/res/color-night/accent_select_secondary_text.xml b/res/color-night/accent_select_secondary_text.xml
new file mode 100644
index 0000000..6b7b4f2
--- /dev/null
+++ b/res/color-night/accent_select_secondary_text.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2022 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.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:color="?android:attr/textColorSecondaryInverse" />
+</selector>
\ No newline at end of file
diff --git a/res/color/accent_select_background.xml b/res/color/accent_select_background.xml
new file mode 100644
index 0000000..5dab723
--- /dev/null
+++ b/res/color/accent_select_background.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2022 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.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:color="@android:color/system_accent2_500" android:lStar="80" />
+</selector>
\ No newline at end of file
diff --git a/res/color/accent_select_primary_text.xml b/res/color/accent_select_primary_text.xml
new file mode 100644
index 0000000..f790d42
--- /dev/null
+++ b/res/color/accent_select_primary_text.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2022 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.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:color="?android:attr/textColorPrimary" />
+</selector>
\ No newline at end of file
diff --git a/res/color/accent_select_secondary_text.xml b/res/color/accent_select_secondary_text.xml
new file mode 100644
index 0000000..25d24a8
--- /dev/null
+++ b/res/color/accent_select_secondary_text.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2022 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.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:color="?android:attr/textColorSecondary" />
+</selector>
\ No newline at end of file
diff --git a/res/drawable/homepage_highlighted_item_background.xml b/res/drawable/homepage_highlighted_item_background.xml
index d54ff60..7e0dea5 100644
--- a/res/drawable/homepage_highlighted_item_background.xml
+++ b/res/drawable/homepage_highlighted_item_background.xml
@@ -17,7 +17,7 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
- android:color="?android:attr/textColorPrimary" />
+ android:color="@color/accent_select_background" />
<corners
android:radius="@dimen/homepage_preference_corner_radius" />
</shape>
\ No newline at end of file
diff --git a/res/drawable/user_select_background.xml b/res/drawable/user_select_background.xml
new file mode 100644
index 0000000..777bff9
--- /dev/null
+++ b/res/drawable/user_select_background.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2022 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.
+-->
+<ripple
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
+ android:color="@color/settingslib_ripple_color">
+ <item android:id="@android:id/mask">
+ <shape android:shape="rectangle">
+ <solid android:color="?androidprv:attr/colorSurface"/>
+ <corners android:radius="20dp"/>
+ </shape>
+ </item>
+ <item android:id="@android:id/background">
+ <shape android:shape="rectangle">
+ <stroke android:color="?androidprv:attr/colorAccentPrimaryVariant" android:width="1dp"/>
+ <corners android:radius="20dp"/>
+ </shape>
+ </item>
+</ripple>
diff --git a/res/layout/user_select.xml b/res/layout/user_select.xml
new file mode 100644
index 0000000..8c8c37a
--- /dev/null
+++ b/res/layout/user_select.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2022 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.
+-->
+<FrameLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingTop="40dp"
+ android:paddingBottom="40dp">
+
+ <com.android.internal.widget.RecyclerView
+ android:id="@+id/list"
+ android:overScrollMode="never"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"/>
+</FrameLayout>
diff --git a/res/layout/user_select_item.xml b/res/layout/user_select_item.xml
new file mode 100644
index 0000000..fa0c91a
--- /dev/null
+++ b/res/layout/user_select_item.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2022 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.
+-->
+<RelativeLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/widget_frame"
+ android:layout_width="120dp"
+ android:layout_height="112dp">
+
+ <FrameLayout
+ android:id="@+id/button"
+ android:layout_width="82dp"
+ android:layout_height="82dp"
+ android:layout_alignParentTop="true"
+ android:layout_centerHorizontal="true"
+ android:background="@drawable/user_select_background">
+
+ <ImageView
+ android:id="@android:id/icon"
+ android:layout_width="32dp"
+ android:layout_height="32dp"
+ android:layout_gravity="center"
+ android:scaleType="fitCenter"/>
+ </FrameLayout>
+
+ <TextView
+ android:id="@android:id/title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_centerHorizontal="true"
+ android:labelFor="@android:id/icon"
+ android:textSize="14sp"
+ style="@style/TextAppearance.PreferenceTitle.SettingsLib"/>
+</RelativeLayout>
diff --git a/res/layout/user_select_title.xml b/res/layout/user_select_title.xml
new file mode 100644
index 0000000..e01ca22
--- /dev/null
+++ b/res/layout/user_select_title.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2022 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.
+-->
+<com.android.internal.widget.DialogTitle
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ style="?android:attr/windowTitleStyle"
+ android:id="@android:id/title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:paddingTop="24dp"
+ android:ellipsize="end"
+ android:singleLine="true"
+ android:textAlignment="center"
+ android:textSize="24sp"/>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 5e4e5a4..e2a8423 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -579,6 +579,9 @@
<!-- Padding for indeterminate progress bar -->
<item name="progressBarStartPadding">12dp</item>
<item name="progressBarEndPadding">16dp</item>
+
+ <!-- Title icon size -->
+ <item name="iconSize">25dp</item>
</style>
<style name="SliceRow.Slider.LargeIcon">
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index c7375a3..9f191f6 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -224,6 +224,7 @@
}
}
}
+ public static class PrivacyControlsActivity extends SettingsActivity { /* empty */ }
public static class PrivacySettingsActivity extends SettingsActivity { /* empty */ }
public static class FactoryResetActivity extends SettingsActivity {
@Override
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 2988ddc..f996444 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -85,7 +85,6 @@
import android.text.format.DateUtils;
import android.text.style.TtsSpan;
import android.util.ArraySet;
-import android.util.FeatureFlagUtils;
import android.util.IconDrawableFactory;
import android.util.Log;
import android.view.LayoutInflater;
@@ -1220,7 +1219,7 @@
*/
@ColorInt
public static int getHomepageIconColor(Context context) {
- return getColorAttrDefaultColor(context, android.R.attr.textColorSecondary);
+ return getColorAttrDefaultColor(context, android.R.attr.textColorPrimary);
}
/**
@@ -1228,6 +1227,6 @@
*/
@ColorInt
public static int getHomepageIconColorHighlight(Context context) {
- return getColorAttrDefaultColor(context, android.R.attr.textColorSecondaryInverse);
+ return context.getColor(R.color.accent_select_primary_text);
}
}
diff --git a/src/com/android/settings/accessibility/AccessibilityDetailsSettingsFragment.java b/src/com/android/settings/accessibility/AccessibilityDetailsSettingsFragment.java
index 911e2fc..c3359e4 100644
--- a/src/com/android/settings/accessibility/AccessibilityDetailsSettingsFragment.java
+++ b/src/com/android/settings/accessibility/AccessibilityDetailsSettingsFragment.java
@@ -163,7 +163,9 @@
try {
final int mode = mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_RESTRICTED_SETTINGS,
uid, packageName);
- return mode != AppOpsManager.MODE_ERRORED && mode != AppOpsManager.MODE_IGNORED;
+ final boolean ecmEnabled = getContext().getResources().getBoolean(
+ com.android.internal.R.bool.config_enhancedConfirmationModeEnabled);
+ return !ecmEnabled || mode == AppOpsManager.MODE_ALLOWED;
} catch (Exception e) {
// Fallback in case if app ops is not available in testing.
return true;
diff --git a/src/com/android/settings/accessibility/RestrictedPreferenceHelper.java b/src/com/android/settings/accessibility/RestrictedPreferenceHelper.java
index 3e42e21..4344acc 100644
--- a/src/com/android/settings/accessibility/RestrictedPreferenceHelper.java
+++ b/src/com/android/settings/accessibility/RestrictedPreferenceHelper.java
@@ -233,7 +233,9 @@
final int mode = mAppOps.noteOpNoThrow(
AppOpsManager.OP_ACCESS_RESTRICTED_SETTINGS,
preference.getUid(), preference.getPackageName());
- appOpsAllowed = mode == AppOpsManager.MODE_ALLOWED;
+ final boolean ecmEnabled = mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_enhancedConfirmationModeEnabled);
+ appOpsAllowed = !ecmEnabled || mode == AppOpsManager.MODE_ALLOWED;
serviceAllowed = appOpsAllowed;
} catch (Exception e) {
// Allow service in case if app ops is not available in testing.
diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
index d9a02c0..a6aeb89 100644
--- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
@@ -470,9 +470,7 @@
mShortcutPreference.setKey(getShortcutPreferenceKey());
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
mShortcutPreference.setOnClickCallback(this);
-
- final CharSequence title = getString(R.string.accessibility_shortcut_title, mPackageName);
- mShortcutPreference.setTitle(title);
+ mShortcutPreference.setTitle(getShortcutTitle());
final PreferenceCategory generalCategory = findPreference(KEY_GENERAL_CATEGORY);
generalCategory.addPreference(mShortcutPreference);
diff --git a/src/com/android/settings/accounts/AccountPreferenceController.java b/src/com/android/settings/accounts/AccountPreferenceController.java
index 29198fb..1458988 100644
--- a/src/com/android/settings/accounts/AccountPreferenceController.java
+++ b/src/com/android/settings/accounts/AccountPreferenceController.java
@@ -623,6 +623,12 @@
if (action.equals(Intent.ACTION_MANAGED_PROFILE_REMOVED)
|| action.equals(Intent.ACTION_MANAGED_PROFILE_ADDED)) {
if (mFragment instanceof AccountWorkProfileDashboardFragment) {
+ new SubSettingLauncher(context)
+ .setDestination(AccountDashboardFragment.class.getName())
+ .setSourceMetricsCategory(mFragment.getMetricsCategory())
+ .setTitleRes(-1)
+ .setIsSecondLayerPage(true)
+ .launch();
mFragment.getActivity().finish();
} else {
// Clean old state
diff --git a/src/com/android/settings/core/SliderPreferenceController.java b/src/com/android/settings/core/SliderPreferenceController.java
index 0a7ece2..8c936f2 100644
--- a/src/com/android/settings/core/SliderPreferenceController.java
+++ b/src/com/android/settings/core/SliderPreferenceController.java
@@ -17,6 +17,7 @@
import android.content.Context;
import androidx.preference.Preference;
+import androidx.slice.builders.SliceAction;
import com.android.settings.slices.SliceData;
@@ -70,4 +71,11 @@
public int getSliceType() {
return SliceData.SliceType.SLIDER;
}
+
+ /**
+ * @return the SliceAction for the end item of the slice.
+ */
+ public SliceAction getSliceEndItem(Context context) {
+ return null;
+ }
}
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 81de756..11ceeaf 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -152,6 +152,7 @@
import com.android.settings.password.ChooseLockPattern;
import com.android.settings.print.PrintJobSettingsFragment;
import com.android.settings.print.PrintSettingsFragment;
+import com.android.settings.privacy.PrivacyControlsFragment;
import com.android.settings.privacy.PrivacyDashboardFragment;
import com.android.settings.security.LockscreenDashboardFragment;
import com.android.settings.security.SecurityAdvancedSettings;
@@ -218,6 +219,7 @@
LocationSettings.class.getName(),
WifiScanningFragment.class.getName(),
PrivacyDashboardFragment.class.getName(),
+ PrivacyControlsFragment.class.getName(),
LocationServices.class.getName(),
SecuritySettings.class.getName(),
SecurityAdvancedSettings.class.getName(),
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
index d3234dd..f82694c 100644
--- a/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
@@ -20,7 +20,6 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
-import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnShowListener;
import android.content.Intent;
@@ -28,17 +27,27 @@
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
+import com.android.internal.widget.DialogTitle;
+import com.android.internal.widget.LinearLayoutManager;
+import com.android.internal.widget.RecyclerView;
+import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.drawer.Tile;
import java.util.List;
-public class ProfileSelectDialog extends DialogFragment implements OnClickListener {
+/**
+ * A {@link DialogFragment} that can select one of the different profiles.
+ */
+public class ProfileSelectDialog extends DialogFragment implements UserAdapter.OnClickListener {
private static final String TAG = "ProfileSelectDialog";
private static final String ARG_SELECTED_TILE = "selectedTile";
@@ -53,12 +62,13 @@
/**
* Display the profile select dialog, adding the fragment to the given FragmentManager.
- * @param manager The FragmentManager this fragment will be added to.
- * @param tile The tile for this fragment.
+ *
+ * @param manager The FragmentManager this fragment will be added to.
+ * @param tile The tile for this fragment.
* @param sourceMetricCategory The source metric category.
- * @param onShowListener The listener listens to the dialog showing event.
- * @param onDismissListener The listener listens to the dialog dismissing event.
- * @param onCancelListener The listener listens to the dialog cancelling event.
+ * @param onShowListener The listener listens to the dialog showing event.
+ * @param onDismissListener The listener listens to the dialog dismissing event.
+ * @param onCancelListener The listener listens to the dialog cancelling event.
*/
public static void show(FragmentManager manager, Tile tile, int sourceMetricCategory,
OnShowListener onShowListener, OnDismissListener onDismissListener,
@@ -77,32 +87,53 @@
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mSelectedTile = getArguments().getParcelable(ARG_SELECTED_TILE);
- mSourceMetricCategory = getArguments().getInt(ARG_SOURCE_METRIC_CATEGORY);
+ Bundle arguments = requireArguments();
+ mSelectedTile = arguments.getParcelable(ARG_SELECTED_TILE, Tile.class);
+ mSourceMetricCategory = arguments.getInt(ARG_SOURCE_METRIC_CATEGORY);
}
+ @NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
- final Context context = getActivity();
- final AlertDialog.Builder builder = new AlertDialog.Builder(context);
- final UserAdapter adapter = UserAdapter.createUserAdapter(UserManager.get(context), context,
- mSelectedTile.userHandle);
- builder.setTitle(com.android.settingslib.R.string.choose_profile)
- .setAdapter(adapter, this);
+ return createDialog(getContext(), mSelectedTile.userHandle, this);
+ }
- return builder.create();
+ /**
+ * Creates the profile select dialog.
+ */
+ public static Dialog createDialog(Context context, List<UserHandle> userProfiles,
+ UserAdapter.OnClickListener onClickListener) {
+ LayoutInflater layoutInflater = context.getSystemService(LayoutInflater.class);
+
+ DialogTitle titleView =
+ (DialogTitle) layoutInflater.inflate(R.layout.user_select_title, null);
+ titleView.setText(com.android.settingslib.R.string.choose_profile);
+
+ View contentView = layoutInflater.inflate(R.layout.user_select, null);
+
+ RecyclerView listView = contentView.findViewById(R.id.list);
+ listView.setAdapter(
+ UserAdapter.createUserRecycleViewAdapter(context, userProfiles, onClickListener));
+ listView.setLayoutManager(
+ new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
+
+ return new AlertDialog.Builder(context)
+ .setCustomTitle(titleView)
+ .setView(contentView)
+ .create();
}
@Override
- public void onClick(DialogInterface dialog, int which) {
- final UserHandle user = mSelectedTile.userHandle.get(which);
+ public void onClick(int position) {
+ final UserHandle user = mSelectedTile.userHandle.get(position);
// Show menu on top level items.
final Intent intent = new Intent(mSelectedTile.getIntent());
FeatureFactory.getFactory(getContext()).getMetricsFeatureProvider()
.logStartedIntentWithProfile(intent, mSourceMetricCategory,
- which == 1 /* isWorkProfile */);
+ position == 1 /* isWorkProfile */);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
getActivity().startActivityAsUser(intent, user);
+ dismiss();
}
@Override
diff --git a/src/com/android/settings/dashboard/profileselector/UserAdapter.java b/src/com/android/settings/dashboard/profileselector/UserAdapter.java
index ae5351e..2573d11 100644
--- a/src/com/android/settings/dashboard/profileselector/UserAdapter.java
+++ b/src/com/android/settings/dashboard/profileselector/UserAdapter.java
@@ -18,188 +18,156 @@
import static android.app.admin.DevicePolicyResources.Strings.Settings.PERSONAL_CATEGORY_HEADER;
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_CATEGORY_HEADER;
-import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_USER_LABEL;
import android.app.ActivityManager;
import android.app.admin.DevicePolicyManager;
+import android.app.admin.DevicePolicyResourcesManager;
import android.content.Context;
import android.content.pm.UserInfo;
-import android.database.DataSetObserver;
-import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.UserHandle;
import android.os.UserManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.BaseAdapter;
import android.widget.ImageView;
-import android.widget.ListAdapter;
-import android.widget.SpinnerAdapter;
import android.widget.TextView;
import com.android.internal.util.UserIcons;
+import com.android.internal.widget.RecyclerView;
import com.android.settingslib.R;
-import com.android.settingslib.drawable.UserIconDrawable;
+import com.android.settingslib.Utils;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
/**
* Adapter for a spinner that shows a list of users.
*/
-public class UserAdapter implements SpinnerAdapter, ListAdapter {
+public class UserAdapter extends BaseAdapter {
+
/** Holder for user details */
public static class UserDetails {
private final UserHandle mUserHandle;
- private final String mName;
private final Drawable mIcon;
+ private final String mTitle;
public UserDetails(UserHandle userHandle, UserManager um, Context context) {
mUserHandle = userHandle;
UserInfo userInfo = um.getUserInfo(mUserHandle.getIdentifier());
- Drawable icon;
+ int tintColor = Utils.getColorAttrDefaultColor(context,
+ com.android.internal.R.attr.colorAccentPrimaryVariant);
if (userInfo.isManagedProfile()) {
- mName = context.getSystemService(DevicePolicyManager.class).getResources()
- .getString(WORK_PROFILE_USER_LABEL,
- () -> context.getString(R.string.managed_user_title));
- icon = context.getPackageManager().getUserBadgeForDensityNoBackground(
+ mIcon = context.getPackageManager().getUserBadgeForDensityNoBackground(
userHandle, /* density= */ 0);
+ mIcon.setTint(tintColor);
} else {
- mName = userInfo.name;
- final int userId = userInfo.id;
- if (um.getUserIcon(userId) != null) {
- icon = new BitmapDrawable(context.getResources(), um.getUserIcon(userId));
- } else {
- icon = UserIcons.getDefaultUserIcon(
- context.getResources(), userId, /* light= */ false);
- }
+ mIcon = UserIcons.getDefaultUserIconInColor(context.getResources(), tintColor);
}
- this.mIcon = encircle(context, icon);
+ mTitle = getTitle(context);
}
- private static Drawable encircle(Context context, Drawable icon) {
- return new UserIconDrawable(UserIconDrawable.getDefaultSize(context))
- .setIconDrawable(icon).bake();
+ private String getTitle(Context context) {
+ DevicePolicyManager devicePolicyManager =
+ Objects.requireNonNull(context.getSystemService(DevicePolicyManager.class));
+ DevicePolicyResourcesManager resources = devicePolicyManager.getResources();
+ int userHandle = mUserHandle.getIdentifier();
+ if (userHandle == UserHandle.USER_CURRENT
+ || userHandle == ActivityManager.getCurrentUser()) {
+ return resources.getString(PERSONAL_CATEGORY_HEADER,
+ () -> context.getString(R.string.category_personal));
+ } else {
+ return resources.getString(WORK_CATEGORY_HEADER,
+ () -> context.getString(R.string.category_work));
+ }
}
}
- private ArrayList<UserDetails> data;
- private final Context mContext;
+ private final ArrayList<UserDetails> mUserDetails;
private final LayoutInflater mInflater;
- private final DevicePolicyManager mDevicePolicyManager;
public UserAdapter(Context context, ArrayList<UserDetails> users) {
if (users == null) {
throw new IllegalArgumentException("A list of user details must be provided");
}
- mContext = context;
- this.data = users;
- mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- mDevicePolicyManager = context.getSystemService(DevicePolicyManager.class);
+ mUserDetails = users;
+ mInflater = context.getSystemService(LayoutInflater.class);
}
public UserHandle getUserHandle(int position) {
- if (position < 0 || position >= data.size()) {
+ if (position < 0 || position >= mUserDetails.size()) {
return null;
}
- return data.get(position).mUserHandle;
- }
-
- @Override
- public View getDropDownView(int position, View convertView, ViewGroup parent) {
- final View row = convertView != null ? convertView : createUser(parent);
-
- UserDetails user = data.get(position);
- ((ImageView) row.findViewById(android.R.id.icon)).setImageDrawable(user.mIcon);
- ((TextView) row.findViewById(android.R.id.title)).setText(getTitle(user));
- return row;
- }
-
- private String getTitle(UserDetails user) {
- int userHandle = user.mUserHandle.getIdentifier();
- if (userHandle == UserHandle.USER_CURRENT
- || userHandle == ActivityManager.getCurrentUser()) {
- return mDevicePolicyManager.getResources().getString(PERSONAL_CATEGORY_HEADER,
- () -> mContext.getString(R.string.category_personal));
- } else {
- return mDevicePolicyManager.getResources().getString(WORK_CATEGORY_HEADER,
- () -> mContext.getString(R.string.category_work));
- }
- }
-
- private View createUser(ViewGroup parent) {
- return mInflater.inflate(R.layout.user_preference, parent, false);
- }
-
- @Override
- public void registerDataSetObserver(DataSetObserver observer) {
- // We don't support observers
- }
-
- @Override
- public void unregisterDataSetObserver(DataSetObserver observer) {
- // We don't support observers
- }
-
- @Override
- public int getCount() {
- return data.size();
- }
-
- @Override
- public UserAdapter.UserDetails getItem(int position) {
- return data.get(position);
- }
-
- @Override
- public long getItemId(int position) {
- return data.get(position).mUserHandle.getIdentifier();
- }
-
- @Override
- public boolean hasStableIds() {
- return false;
+ return mUserDetails.get(position).mUserHandle;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
- return getDropDownView(position, convertView, parent);
+ ViewHolder holder;
+ if (convertView != null) {
+ holder = (ViewHolder) convertView.getTag();
+ } else {
+ convertView = mInflater.inflate(R.layout.user_preference, parent, false);
+ holder = new ViewHolder(convertView);
+ convertView.setTag(holder);
+ }
+ bindViewHolder(holder, position);
+ return convertView;
+ }
+
+ private void bindViewHolder(ViewHolder holder, int position) {
+ UserDetails userDetails = getItem(position);
+ holder.getIconView().setImageDrawable(userDetails.mIcon);
+ holder.getTitleView().setText(userDetails.mTitle);
}
@Override
- public int getItemViewType(int position) {
- return 0;
+ public int getCount() {
+ return mUserDetails.size();
}
@Override
- public int getViewTypeCount() {
- return 1;
+ public UserAdapter.UserDetails getItem(int position) {
+ return mUserDetails.get(position);
}
@Override
- public boolean isEmpty() {
- return data.isEmpty();
+ public long getItemId(int position) {
+ return mUserDetails.get(position).mUserHandle.getIdentifier();
}
- @Override
- public boolean areAllItemsEnabled() {
- return true;
- }
+ private RecyclerView.Adapter<ViewHolder> createRecyclerViewAdapter(
+ OnClickListener onClickListener) {
+ return new RecyclerView.Adapter<ViewHolder>() {
+ @Override
+ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+ View view = LayoutInflater.from(parent.getContext())
+ .inflate(R.layout.user_select_item, parent, false);
- @Override
- public boolean isEnabled(int position) {
- return true;
+ return new ViewHolder(view, onClickListener);
+ }
+
+ @Override
+ public void onBindViewHolder(ViewHolder holder, int position) {
+ UserAdapter.this.bindViewHolder(holder, position);
+ }
+
+ @Override
+ public int getItemCount() {
+ return getCount();
+ }
+ };
}
/**
- * Creates a {@link UserAdapter} if there is more than one
- * profile on the device.
+ * Creates a {@link UserAdapter} if there is more than one profile on the device.
*
- * <p> The adapter can be used to populate a spinner that switches between the Settings
- * app on the different profiles.
+ * <p> The adapter can be used to populate a spinner that switches between the different
+ * profiles.
*
- * @return a {@link UserAdapter} or null if there is only one
- * profile.
+ * @return a {@link UserAdapter} or null if there is only one profile.
*/
public static UserAdapter createUserSpinnerAdapter(UserManager userManager, Context context) {
List<UserHandle> userProfiles = userManager.getUserProfiles();
@@ -215,13 +183,60 @@
return createUserAdapter(userManager, context, userProfiles);
}
- public static UserAdapter createUserAdapter(
+ /**
+ * Creates a {@link RecyclerView} adapter which be used to populate a {@link RecyclerView} that
+ * select one of the different profiles.
+ */
+ public static RecyclerView.Adapter<ViewHolder> createUserRecycleViewAdapter(
+ Context context, List<UserHandle> userProfiles, OnClickListener onClickListener) {
+ UserManager systemService = context.getSystemService(UserManager.class);
+ return createUserAdapter(systemService, context, userProfiles)
+ .createRecyclerViewAdapter(onClickListener);
+ }
+
+ private static UserAdapter createUserAdapter(
UserManager userManager, Context context, List<UserHandle> userProfiles) {
ArrayList<UserDetails> userDetails = new ArrayList<>(userProfiles.size());
- final int count = userProfiles.size();
- for (int i = 0; i < count; i++) {
- userDetails.add(new UserDetails(userProfiles.get(i), userManager, context));
+ for (UserHandle userProfile : userProfiles) {
+ userDetails.add(new UserDetails(userProfile, userManager, context));
}
return new UserAdapter(context, userDetails);
}
+
+ static class ViewHolder extends RecyclerView.ViewHolder {
+ private final ImageView mIconView;
+ private final TextView mTitleView;
+
+ private ViewHolder(View view) {
+ super(view);
+ mIconView = view.findViewById(android.R.id.icon);
+ mTitleView = view.findViewById(android.R.id.title);
+ }
+
+ private ViewHolder(View view, OnClickListener onClickListener) {
+ this(view);
+ View button = view.findViewById(R.id.button);
+ if (button != null) {
+ button.setOnClickListener(v -> onClickListener.onClick(getAdapterPosition()));
+ }
+ }
+
+ private ImageView getIconView() {
+ return mIconView;
+ }
+
+ private TextView getTitleView() {
+ return mTitleView;
+ }
+ }
+
+ /**
+ * Interface definition for a callback to be invoked when a user is clicked.
+ */
+ public interface OnClickListener {
+ /**
+ * Called when a user has been clicked.
+ */
+ void onClick(int position);
+ }
}
diff --git a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
index 7e27414..dcd2bd8 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
@@ -234,7 +234,9 @@
// If isValidPrivateVolume() is true, these preferences will become visible at
// onLoadFinished.
- if (!isValidPrivateVolume()) {
+ if (isValidPrivateVolume()) {
+ mIsDocumentsPrefShown = isDocumentsPrefShown();
+ } else {
setPrivateStorageCategoryPreferencesVisibility(false);
}
}
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
index 6cadbda..f3085bc 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
@@ -38,6 +38,7 @@
import com.android.settings.R;
import com.android.settings.vpn2.VpnUtils;
+import com.android.settingslib.utils.WorkPolicyUtils;
import java.util.Date;
import java.util.List;
@@ -54,6 +55,7 @@
private final ConnectivityManager mCm;
private final VpnManager mVm;
private final Resources mResources;
+ private final WorkPolicyUtils mWorkPolicyUtils;
private static final int MY_USER_ID = UserHandle.myUserId();
@@ -67,6 +69,7 @@
mCm = cm;
mVm = vm;
mResources = resources;
+ mWorkPolicyUtils = new WorkPolicyUtils(mContext, mPm, mUm, mDpm);
}
@Override
@@ -228,25 +231,12 @@
@Override
public boolean hasWorkPolicyInfo() {
- return (getWorkPolicyInfoIntentDO() != null) || (getWorkPolicyInfoIntentPO() != null);
+ return mWorkPolicyUtils.hasWorkPolicy();
}
@Override
public boolean showWorkPolicyInfo(Context activityContext) {
- Intent intent = getWorkPolicyInfoIntentDO();
- if (intent != null) {
- activityContext.startActivity(intent);
- return true;
- }
-
- intent = getWorkPolicyInfoIntentPO();
- final UserInfo userInfo = getManagedProfileUserInfo();
- if (intent != null && userInfo != null) {
- activityContext.startActivityAsUser(intent, userInfo.getUserHandle());
- return true;
- }
-
- return false;
+ return mWorkPolicyUtils.showWorkPolicyInfo(activityContext);
}
@Override
@@ -301,47 +291,6 @@
return UserHandle.USER_NULL;
}
- private Intent getWorkPolicyInfoIntentDO() {
- final ComponentName ownerComponent = getDeviceOwnerComponent();
- if (ownerComponent == null) {
- return null;
- }
-
- // Only search for the required action in the Device Owner's package
- final Intent intent =
- new Intent(Settings.ACTION_SHOW_WORK_POLICY_INFO)
- .setPackage(ownerComponent.getPackageName());
- final List<ResolveInfo> activities = mPm.queryIntentActivities(intent, 0);
- if (activities.size() != 0) {
- return intent;
- }
-
- return null;
- }
-
- private Intent getWorkPolicyInfoIntentPO() {
- final int userId = getManagedProfileUserId();
- if (userId == UserHandle.USER_NULL) {
- return null;
- }
-
- final ComponentName ownerComponent = mDpm.getProfileOwnerAsUser(userId);
- if (ownerComponent == null) {
- return null;
- }
-
- // Only search for the required action in the Profile Owner's package
- final Intent intent =
- new Intent(Settings.ACTION_SHOW_WORK_POLICY_INFO)
- .setPackage(ownerComponent.getPackageName());
- final List<ResolveInfo> activities = mPm.queryIntentActivitiesAsUser(intent, 0, userId);
- if (activities.size() != 0) {
- return intent;
- }
-
- return null;
- }
-
protected static class EnterprisePrivacySpan extends ClickableSpan {
private final Context mContext;
diff --git a/src/com/android/settings/media/MediaOutputIndicatorWorker.java b/src/com/android/settings/media/MediaOutputIndicatorWorker.java
index ef3a7bc..a87b0ea 100644
--- a/src/com/android/settings/media/MediaOutputIndicatorWorker.java
+++ b/src/com/android/settings/media/MediaOutputIndicatorWorker.java
@@ -34,6 +34,7 @@
import com.android.settings.bluetooth.Utils;
import com.android.settings.slices.SliceBackgroundWorker;
import com.android.settingslib.bluetooth.BluetoothCallback;
+import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.media.LocalMediaManager;
import com.android.settingslib.media.MediaDevice;
@@ -126,7 +127,7 @@
}
@Nullable
- MediaController getActiveLocalMediaController() {
+ public MediaController getActiveLocalMediaController() {
return MediaOutputUtils.getActiveLocalMediaController(mContext.getSystemService(
MediaSessionManager.class));
}
@@ -156,7 +157,7 @@
return mMediaDevices;
}
- MediaDevice getCurrentConnectedMediaDevice() {
+ public MediaDevice getCurrentConnectedMediaDevice() {
return mLocalMediaManager.getCurrentConnectedDevice();
}
@@ -164,6 +165,15 @@
return mPackageName;
}
+ public boolean isDeviceBroadcasting() {
+ LocalBluetoothLeBroadcast broadcast =
+ mLocalBluetoothManager.getProfileManager().getLeAudioBroadcastProfile();
+ if (broadcast == null) {
+ return false;
+ }
+ return broadcast.isEnabled(null);
+ }
+
private class DevicesChangedBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
diff --git a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
index cb5b5d0..919913f 100644
--- a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
+++ b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
@@ -87,7 +87,8 @@
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(subId);
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
visible = false;
- } else if (carrierConfig == null) {
+ } else if (carrierConfig == null
+ || !CarrierConfigManager.isConfigForIdentifiedCarrier(carrierConfig)) {
visible = false;
} else if (carrierConfig.getBoolean(
CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)
diff --git a/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java b/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
index 2616a69..d348b24 100644
--- a/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
+++ b/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
@@ -326,7 +326,7 @@
/* Handles the enabling SIM action. */
private void showEnableSubDialog() {
- Log.i(TAG, "Handle subscription enabling.");
+ Log.d(TAG, "Handle subscription enabling.");
if (isDsdsConditionSatisfied()) {
showEnableDsdsConfirmDialog();
return;
@@ -452,7 +452,7 @@
}
private void showMepSwitchSimConfirmDialog() {
- Log.i(TAG, "showMepSwitchSimConfirmDialog");
+ Log.d(TAG, "showMepSwitchSimConfirmDialog");
final CharSequence displayName = SubscriptionUtil.getUniqueSubscriptionDisplayName(
mSubInfo, this);
String title = getString(R.string.sim_action_switch_sub_dialog_mep_title, displayName);
@@ -556,27 +556,35 @@
private boolean isDsdsConditionSatisfied() {
if (mTelMgr.isMultiSimEnabled()) {
- Log.i(TAG, "DSDS is already enabled. Condition not satisfied.");
+ Log.d(TAG, "DSDS is already enabled. Condition not satisfied.");
return false;
}
if (mTelMgr.isMultiSimSupported() != TelephonyManager.MULTISIM_ALLOWED) {
- Log.i(TAG, "Hardware does not support DSDS.");
+ Log.d(TAG, "Hardware does not support DSDS.");
return false;
}
+ boolean isActiveSim = SubscriptionUtil.getActiveSubscriptions(
+ mSubscriptionManager).size() > 0;
+ if (isMultipleEnabledProfilesSupported() && isActiveSim) {
+ Log.d(TAG,
+ "Device supports MEP and eSIM operation and eSIM profile is enabled."
+ + " DSDS condition satisfied.");
+ return true;
+ }
boolean isRemovableSimEnabled = isRemovableSimEnabled();
if (mIsEsimOperation && isRemovableSimEnabled) {
- Log.i(TAG, "eSIM operation and removable SIM is enabled. DSDS condition satisfied.");
+ Log.d(TAG, "eSIM operation and removable SIM is enabled. DSDS condition satisfied.");
return true;
}
boolean isEsimProfileEnabled =
SubscriptionUtil.getActiveSubscriptions(mSubscriptionManager).stream()
.anyMatch(SubscriptionInfo::isEmbedded);
if (!mIsEsimOperation && isEsimProfileEnabled) {
- Log.i(TAG, "Removable SIM operation and eSIM profile is enabled. DSDS condition"
+ Log.d(TAG, "Removable SIM operation and eSIM profile is enabled. DSDS condition"
+ " satisfied.");
return true;
}
- Log.i(TAG, "DSDS condition not satisfied.");
+ Log.d(TAG, "DSDS condition not satisfied.");
return false;
}
diff --git a/src/com/android/settings/nfc/NfcForegroundPreferenceController.java b/src/com/android/settings/nfc/NfcForegroundPreferenceController.java
index 246bdb9..611d3fc 100644
--- a/src/com/android/settings/nfc/NfcForegroundPreferenceController.java
+++ b/src/com/android/settings/nfc/NfcForegroundPreferenceController.java
@@ -93,7 +93,7 @@
return;
}
final ListPreference listPreference = (ListPreference) preference;
- listPreference.setIconSpaceReserved(true);
+ listPreference.setIconSpaceReserved(false);
listPreference.setValue(mListValues[mPaymentBackend.isForegroundMode() ? 1 : 0]);
}
diff --git a/src/com/android/settings/notification/MediaVolumePreferenceController.java b/src/com/android/settings/notification/MediaVolumePreferenceController.java
index e18d2e5..978a4b4 100644
--- a/src/com/android/settings/notification/MediaVolumePreferenceController.java
+++ b/src/com/android/settings/notification/MediaVolumePreferenceController.java
@@ -16,16 +16,32 @@
package com.android.settings.notification;
+import android.app.PendingIntent;
import android.content.Context;
+import android.content.Intent;
+import android.graphics.drawable.Drawable;
import android.media.AudioManager;
+import android.net.Uri;
import android.text.TextUtils;
+import android.util.Log;
+
+import androidx.core.graphics.drawable.IconCompat;
+import androidx.slice.builders.ListBuilder;
+import androidx.slice.builders.SliceAction;
import com.android.settings.R;
+import com.android.settings.Utils;
+import com.android.settings.media.MediaOutputIndicatorWorker;
+import com.android.settings.slices.CustomSliceRegistry;
+import com.android.settings.slices.SliceBackgroundWorker;
+import com.android.settingslib.media.MediaDevice;
public class MediaVolumePreferenceController extends VolumeSeekBarPreferenceController {
-
+ private static final String TAG = "MediaVolumePreCtrl";
private static final String KEY_MEDIA_VOLUME = "media_volume";
+ private MediaOutputIndicatorWorker mWorker;
+
public MediaVolumePreferenceController(Context context) {
super(context, KEY_MEDIA_VOLUME);
}
@@ -66,4 +82,66 @@
public int getMuteIcon() {
return R.drawable.ic_media_stream_off;
}
+
+ private boolean isSupportEndItem() {
+ return getWorker() != null
+ && getWorker().getActiveLocalMediaController() != null
+ && isConnectedBLEDevice();
+ }
+
+ private boolean isConnectedBLEDevice() {
+ final MediaDevice device = getWorker().getCurrentConnectedMediaDevice();
+ if (device != null) {
+ return device.isBLEDevice();
+ }
+ return false;
+ }
+
+ @Override
+ public SliceAction getSliceEndItem(Context context) {
+ if (!isSupportEndItem()) {
+ Log.d(TAG, "The slice doesn't support end item");
+ return null;
+ }
+
+ final Intent intent = new Intent();
+ if (getWorker().isDeviceBroadcasting()) {
+ // TODO(b/229577323) : Get the intent action for the Media Output Broadcast Dialog
+ // in SystemUI
+ } else {
+ // TODO(b/229577518) : Get the intent action of the Bluetooth Broadcast Dialog
+ // for user to choose the action
+ }
+ final PendingIntent pi = PendingIntent.getBroadcast(context, 0 /* requestCode */, intent,
+ PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
+ final IconCompat icon = getBroadcastIcon(context);
+
+ return SliceAction.createDeeplink(pi, icon, ListBuilder.ICON_IMAGE, getPreferenceKey());
+ }
+
+ private IconCompat getBroadcastIcon(Context context) {
+ final Drawable drawable = context.getDrawable(
+ com.android.settingslib.R.drawable.settings_input_antenna);
+ if (drawable != null) {
+ drawable.setTint(Utils.getColorAccentDefaultColor(context));
+ return Utils.createIconWithDrawable(drawable);
+ }
+ return null;
+ }
+
+ private MediaOutputIndicatorWorker getWorker() {
+ if (mWorker == null) {
+ mWorker = SliceBackgroundWorker.getInstance(getUri());
+ }
+ return mWorker;
+ }
+
+ private Uri getUri() {
+ return CustomSliceRegistry.VOLUME_MEDIA_URI;
+ }
+
+ @Override
+ public Class<? extends SliceBackgroundWorker> getBackgroundWorkerClass() {
+ return MediaOutputIndicatorWorker.class;
+ }
}
diff --git a/src/com/android/settings/panel/PanelSlicesAdapter.java b/src/com/android/settings/panel/PanelSlicesAdapter.java
index 2486361..9f5ffe9 100644
--- a/src/com/android/settings/panel/PanelSlicesAdapter.java
+++ b/src/com/android/settings/panel/PanelSlicesAdapter.java
@@ -143,6 +143,9 @@
sliceView.setVisibility(View.GONE);
}
+ // Add divider for the end icon
+ sliceView.setShowActionDividers(true);
+
// Log Panel interaction
sliceView.setOnSliceActionListener(
((eventInfo, sliceItem) -> {
diff --git a/src/com/android/settings/privacy/EnableContentCaptureWithServiceSettingsPreferenceController.java b/src/com/android/settings/privacy/EnableContentCaptureWithServiceSettingsPreferenceController.java
index c3878d5..fcb2347 100644
--- a/src/com/android/settings/privacy/EnableContentCaptureWithServiceSettingsPreferenceController.java
+++ b/src/com/android/settings/privacy/EnableContentCaptureWithServiceSettingsPreferenceController.java
@@ -19,19 +19,18 @@
import android.annotation.NonNull;
import android.content.ComponentName;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.os.UserManager;
+import android.text.TextUtils;
import android.util.Log;
-import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
-import com.android.settings.dashboard.profileselector.UserAdapter;
+import com.android.settings.dashboard.profileselector.ProfileSelectDialog;
import com.android.settings.utils.ContentCaptureUtils;
import java.util.ArrayList;
@@ -42,13 +41,9 @@
private static final String TAG = "ContentCaptureController";
- private final UserManager mUserManager;
-
public EnableContentCaptureWithServiceSettingsPreferenceController(@NonNull Context context,
@NonNull String key) {
super(context, key);
-
- mUserManager = UserManager.get(context);
}
@Override
@@ -74,11 +69,6 @@
Log.w(TAG, "No component name for custom service settings");
preference.setSelectable(false);
}
-
- preference.setOnPreferenceClickListener((pref) -> {
- ProfileSelectDialog.show(mContext, pref);
- return true;
- });
}
@Override
@@ -93,32 +83,30 @@
return R.string.menu_key_privacy;
}
- private static final class ProfileSelectDialog {
- public static void show(Context context, Preference pref) {
- final UserManager userManager = UserManager.get(context);
- final List<UserInfo> userInfos = userManager.getUsers();
- final ArrayList<UserHandle> userHandles = new ArrayList<>(userInfos.size());
- for (UserInfo info: userInfos) {
- userHandles.add(info.getUserHandle());
- }
- if (userHandles.size() == 1) {
- final Intent intent = pref.getIntent().addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
- context.startActivityAsUser(intent, userHandles.get(0));
- } else {
- AlertDialog.Builder builder = new AlertDialog.Builder(context);
- UserAdapter adapter = UserAdapter.createUserAdapter(userManager, context,
- userHandles);
- builder.setTitle(com.android.settingslib.R.string.choose_profile)
- .setAdapter(adapter, (DialogInterface dialog, int which) -> {
- final UserHandle user = userHandles.get(which);
- // Show menu on top level items.
- final Intent intent = pref.getIntent()
- .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
- context.startActivityAsUser(intent, user);
- })
- .show();
- }
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
+ return false;
}
+ show(preference);
+ return true;
}
+ private void show(Preference preference) {
+ final UserManager userManager = UserManager.get(mContext);
+ final List<UserInfo> userInfos = userManager.getUsers();
+ final ArrayList<UserHandle> userHandles = new ArrayList<>(userInfos.size());
+ for (UserInfo info : userInfos) {
+ userHandles.add(info.getUserHandle());
+ }
+ final Intent intent = preference.getIntent().addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ if (userHandles.size() == 1) {
+ mContext.startActivityAsUser(intent, userHandles.get(0));
+ return;
+ }
+ ProfileSelectDialog.createDialog(mContext, userHandles, (int position) -> {
+ // Show menu on top level items.
+ mContext.startActivityAsUser(intent, userHandles.get(position));
+ }).show();
+ }
}
diff --git a/src/com/android/settings/security/TopLevelSecurityEntryPreferenceController.java b/src/com/android/settings/security/TopLevelSecurityEntryPreferenceController.java
index 3cf40a0..f83a909 100644
--- a/src/com/android/settings/security/TopLevelSecurityEntryPreferenceController.java
+++ b/src/com/android/settings/security/TopLevelSecurityEntryPreferenceController.java
@@ -58,6 +58,7 @@
new SubSettingLauncher(mContext)
.setDestination(alternativeFragmentClassname)
.setSourceMetricsCategory(getMetricsCategory())
+ .setIsSecondLayerPage(true)
.launch();
return true;
}
diff --git a/src/com/android/settings/slices/SliceBuilderUtils.java b/src/com/android/settings/slices/SliceBuilderUtils.java
index ce5384f..8d5a0b4 100644
--- a/src/com/android/settings/slices/SliceBuilderUtils.java
+++ b/src/com/android/settings/slices/SliceBuilderUtils.java
@@ -339,6 +339,11 @@
inputRangeBuilder.setSubtitle(subtitleText);
}
+ SliceAction endItemAction = sliderController.getSliceEndItem(context);
+ if (endItemAction != null) {
+ inputRangeBuilder.addEndItem(endItemAction);
+ }
+
return new ListBuilder(context, sliceData.getUri(), ListBuilder.INFINITY)
.setAccentColor(color)
.addInputRange(inputRangeBuilder)
diff --git a/src/com/android/settings/widget/HighlightableTopLevelPreferenceAdapter.java b/src/com/android/settings/widget/HighlightableTopLevelPreferenceAdapter.java
index 338be48..3cc7ef2 100644
--- a/src/com/android/settings/widget/HighlightableTopLevelPreferenceAdapter.java
+++ b/src/com/android/settings/widget/HighlightableTopLevelPreferenceAdapter.java
@@ -78,12 +78,10 @@
Context context = preferenceGroup.getContext();
mTitleColorNormal = Utils.getColorAttrDefaultColor(context,
android.R.attr.textColorPrimary);
- mTitleColorHighlight = Utils.getColorAttrDefaultColor(context,
- android.R.attr.textColorPrimaryInverse);
+ mTitleColorHighlight = context.getColor(R.color.accent_select_primary_text);
mSummaryColorNormal = Utils.getColorAttrDefaultColor(context,
android.R.attr.textColorSecondary);
- mSummaryColorHighlight = Utils.getColorAttrDefaultColor(context,
- android.R.attr.textColorSecondaryInverse);
+ mSummaryColorHighlight = context.getColor(R.color.accent_select_secondary_text);
mIconColorNormal = Utils.getHomepageIconColor(context);
mIconColorHighlight = Utils.getHomepageIconColorHighlight(context);
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java b/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java
index 53cddb1..e1cf52b 100644
--- a/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java
@@ -23,21 +23,29 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.app.Dialog;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.os.UserManager;
+import android.widget.TextView;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.R;
import com.android.settingslib.drawer.ActivityTile;
import com.android.settingslib.drawer.CategoryKey;
import com.android.settingslib.drawer.Tile;
+import com.google.android.collect.Lists;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
@@ -46,8 +54,9 @@
private static final UserHandle NORMAL_USER = new UserHandle(1111);
private static final UserHandle REMOVED_USER = new UserHandle(2222);
- @Mock
- private Context mContext;
+ @Spy
+ private Context mContext = ApplicationProvider.getApplicationContext();
+
@Mock
private UserManager mUserManager;
@@ -91,4 +100,18 @@
verify(mUserManager, times(1)).getUserInfo(NORMAL_USER.getIdentifier());
verify(mUserManager, times(2)).getUserInfo(REMOVED_USER.getIdentifier());
}
+
+ @Test
+ public void createDialog_showsCorrectTitle() {
+ mContext.setTheme(R.style.Theme_AppCompat);
+
+ Dialog dialog = ProfileSelectDialog.createDialog(mContext, Lists.newArrayList(NORMAL_USER),
+ (position) -> {
+ });
+ dialog.show();
+
+ TextView titleView = dialog.findViewById(R.id.topPanel).findViewById(android.R.id.title);
+ assertThat(titleView.getText().toString()).isEqualTo(
+ mContext.getText(com.android.settingslib.R.string.choose_profile).toString());
+ }
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/profileselector/UserAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/profileselector/UserAdapterTest.java
new file mode 100644
index 0000000..aa7e30a
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/dashboard/profileselector/UserAdapterTest.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2022 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.dashboard.profileselector;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.UserInfo;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.widget.FrameLayout;
+import android.widget.TextView;
+
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.internal.widget.RecyclerView;
+import com.android.settingslib.R;
+
+import com.google.android.collect.Lists;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import org.robolectric.RobolectricTestRunner;
+
+import java.util.ArrayList;
+
+@RunWith(RobolectricTestRunner.class)
+public class UserAdapterTest {
+ @Rule
+ public MockitoRule mRule = MockitoJUnit.rule();
+
+ private final int mPersonalUserId = UserHandle.myUserId();
+ private static final int WORK_USER_ID = 1;
+
+ @Mock
+ private UserManager mUserManager;
+
+ @Mock
+ private UserInfo mPersonalUserInfo;
+
+ @Mock
+ private UserInfo mWorkUserInfo;
+
+ @Mock
+ private UserAdapter.OnClickListener mOnClickListener;
+
+ @Spy
+ private Context mContext = ApplicationProvider.getApplicationContext();
+
+ @Before
+ public void setUp() {
+ when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
+ when(mUserManager.getUserInfo(mPersonalUserId)).thenReturn(mPersonalUserInfo);
+ when(mUserManager.getUserInfo(WORK_USER_ID)).thenReturn(mWorkUserInfo);
+ }
+
+ @Test
+ public void createUserSpinnerAdapter_singleProfile_returnsNull() {
+ when(mUserManager.getUserProfiles()).thenReturn(
+ Lists.newArrayList(UserHandle.of(mPersonalUserId)));
+
+ UserAdapter userSpinnerAdapter =
+ UserAdapter.createUserSpinnerAdapter(mUserManager, mContext);
+
+ assertThat(userSpinnerAdapter).isNull();
+ }
+
+ @Test
+ public void createUserSpinnerAdapter_twoProfiles_succeed() {
+ when(mUserManager.getUserProfiles()).thenReturn(
+ Lists.newArrayList(UserHandle.of(mPersonalUserId), UserHandle.of(WORK_USER_ID)));
+
+ UserAdapter userSpinnerAdapter =
+ UserAdapter.createUserSpinnerAdapter(mUserManager, mContext);
+
+ assertThat(userSpinnerAdapter.getCount()).isEqualTo(2);
+ assertThat(userSpinnerAdapter.getUserHandle(0).getIdentifier()).isEqualTo(mPersonalUserId);
+ assertThat(userSpinnerAdapter.getUserHandle(1).getIdentifier()).isEqualTo(WORK_USER_ID);
+ }
+
+ @Test
+ public void createUserRecycleViewAdapter_canBindViewHolderCorrectly() {
+ ArrayList<UserHandle> userHandles =
+ Lists.newArrayList(UserHandle.of(mPersonalUserId), UserHandle.of(WORK_USER_ID));
+ FrameLayout parent = new FrameLayout(mContext);
+
+ RecyclerView.Adapter<UserAdapter.ViewHolder> adapter =
+ UserAdapter.createUserRecycleViewAdapter(mContext, userHandles, mOnClickListener);
+ UserAdapter.ViewHolder holder = adapter.createViewHolder(parent, 0);
+ adapter.bindViewHolder(holder, 0);
+ holder.itemView.findViewById(R.id.button).performClick();
+
+ assertThat(adapter.getItemCount()).isEqualTo(2);
+ TextView textView = holder.itemView.findViewById(android.R.id.title);
+ assertThat(textView.getText().toString()).isEqualTo("Personal");
+ verify(mOnClickListener).onClick(anyInt());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
index 2b64c19..0005e71 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
@@ -377,10 +377,22 @@
}
@Test
- public void workPolicyInfo_profileOwner_shouldResolveIntent() {
+ public void workPolicyInfo_profileOwner_shouldResolveIntent()
+ throws PackageManager.NameNotFoundException {
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(null);
- mProfiles.add(new UserInfo(mManagedProfileUserId, "", "", UserInfo.FLAG_MANAGED_PROFILE));
- when(mDevicePolicyManager.getProfileOwnerAsUser(mManagedProfileUserId)).thenReturn(mOwner);
+ List<UserHandle> mAllProfiles = new ArrayList<>();
+ mAllProfiles.add(new UserHandle(mManagedProfileUserId));
+ when(mUserManager.getAllProfiles()).thenReturn(mAllProfiles);
+ when(mUserManager.isManagedProfile(mManagedProfileUserId)).thenReturn(true);
+ when(mContext.getPackageName()).thenReturn("somePackageName");
+ when(mContext.createPackageContextAsUser(
+ eq(mContext.getPackageName()),
+ anyInt(),
+ any(UserHandle.class))
+ ).thenReturn(mContext);
+ when(mContext.getSystemService(Context.DEVICE_POLICY_SERVICE))
+ .thenReturn(mDevicePolicyManager);
+ when(mDevicePolicyManager.getProfileOwner()).thenReturn(mOwner);
// If the intent is not resolved, then there's no info to show for PO
assertThat(mProvider.hasWorkPolicyInfo()).isFalse();
@@ -441,7 +453,7 @@
}
if (profileOwner) {
when(mPackageManager.queryIntentActivitiesAsUser(
- intentEquals(intent), anyInt(), eq(mManagedProfileUserId)))
+ intentEquals(intent), anyInt(), eq(UserHandle.of(mManagedProfileUserId))))
.thenReturn(activities);
}
diff --git a/tests/unit/src/com/android/settings/network/EnabledNetworkModePreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/EnabledNetworkModePreferenceControllerTest.java
index 5672df7..c945206 100644
--- a/tests/unit/src/com/android/settings/network/EnabledNetworkModePreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/EnabledNetworkModePreferenceControllerTest.java
@@ -106,6 +106,7 @@
mPersistableBundle = new PersistableBundle();
doReturn(mPersistableBundle).when(mCarrierConfigCache).getConfig();
doReturn(mPersistableBundle).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
+ mPersistableBundle.putBoolean(CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, true);
mPreference = new ListPreference(mContext);
mController = new EnabledNetworkModePreferenceController(mContext, KEY);
mockAllowedNetworkTypes(ALLOWED_ALL_NETWORK_TYPE);
@@ -147,6 +148,14 @@
@UiThreadTest
@Test
+ public void getAvailabilityStatus_carrierConfigNotReady_returnUnavailable() {
+ mPersistableBundle.putBoolean(CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, false);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @UiThreadTest
+ @Test
public void getAvailabilityStatus_notWorldPhone_returnAvailable() {
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL,
false);