Merge "Create MobileNetworkSummaryRepository" into main
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index fd40e90..cc4d898 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -5362,6 +5362,14 @@
</intent-filter>
</receiver>
+ <receiver
+ android:name=".shortcut.ShortcutsUpdateReceiver"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED"/>
+ </intent-filter>
+ </receiver>
+
<!-- This is the longest AndroidManifest.xml ever. -->
</application>
</manifest>
diff --git a/aconfig/Android.bp b/aconfig/Android.bp
index c1afd6a..8be93f0 100644
--- a/aconfig/Android.bp
+++ b/aconfig/Android.bp
@@ -9,6 +9,7 @@
container: "system",
srcs: [
"*.aconfig",
+ "catalyst/*.aconfig",
],
}
@@ -77,4 +78,4 @@
java_aconfig_library {
name: "keyboard_flags_lib",
aconfig_declarations: "keyboard_flags",
-}
\ No newline at end of file
+}
diff --git a/aconfig/catalyst/about_phone.aconfig b/aconfig/catalyst/about_phone.aconfig
new file mode 100644
index 0000000..0863041
--- /dev/null
+++ b/aconfig/catalyst/about_phone.aconfig
@@ -0,0 +1,9 @@
+package: "com.android.settings.flags"
+container: "system"
+
+flag {
+ name: "catalyst_legal_information"
+ namespace: "android_settings"
+ description: "Flag for Legal information"
+ bug: "323791114"
+}
diff --git a/aconfig/settings_flag_declarations.aconfig b/aconfig/settings_flag_declarations.aconfig
index b8cb4d9..a9c7bd5 100644
--- a/aconfig/settings_flag_declarations.aconfig
+++ b/aconfig/settings_flag_declarations.aconfig
@@ -51,15 +51,15 @@
}
flag {
- name: "catalyst_legal_information"
- namespace: "android_settings"
- description: "This flag controls the About phone > Legal information page migration"
- bug: "323791114"
-}
-
-flag {
name: "updated_suggestion_card_aosp"
namespace: "android_settings"
description: "Use updated suggestion card(s) in AOSP Settings"
bug: "323258154"
}
+
+flag {
+ name: "catalyst"
+ namespace: "android_settings"
+ description: "Flag for all screens"
+ bug: "323791114"
+}
diff --git a/color-check-baseline.xml b/color-check-baseline.xml
index 4c47607..75d4aba 100644
--- a/color-check-baseline.xml
+++ b/color-check-baseline.xml
@@ -6973,4 +6973,103 @@
column="5"/>
</issue>
-</issues>
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" android:color="@color/accessibility_feature_background"/>"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/drawable/ic_pointer_and_touchpad.xml"
+ line="22"
+ column="13"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="pointer_fill_outline_color">#FFFFFF</color>"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values-night/colors.xml"
+ line="81"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="pointer_fill_outline_color">#000000</color>"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values/colors.xml"
+ line="223"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" android:color="@color/pointer_fill_outline_color" />"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+
+ <location
+ file="res/drawable/pointer_icon_fill_color_foreground.xml"
+ line="25"
+ column="25"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" android:color="@color/pointer_fill_outline_color" />"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+
+ <location
+ file="res/drawable/pointer_icon_fill_color_foreground.xml"
+ line="47"
+ column="25"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" android:color="@color/pointer_fill_outline_color" />"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+
+ <location
+ file="res/drawable/pointer_icon_fill_color_foreground.xml"
+ line="64"
+ column="25"/>
+ </issue>
+
+</issues>
\ No newline at end of file
diff --git a/res/drawable/ic_android_satellite_24px.xml b/res/drawable/ic_android_satellite_24px.xml
index 15f2884..b08f19b 100644
--- a/res/drawable/ic_android_satellite_24px.xml
+++ b/res/drawable/ic_android_satellite_24px.xml
@@ -3,7 +3,7 @@
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
- android:tint="?attr/colorControlNormal">
+ android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M487,600L392,505L346,551L376,580Q399,603 399,637Q399,671 376,694L333,737Q310,760 276.5,760Q243,760 220,737L103,620Q80,597 80,563.5Q80,530 103,507L146,464Q169,441 203,441Q237,441 260,464L289,494L335,448L160,273L273,160L448,335L493,290L464,260Q441,237 441,203Q441,169 464,146L507,103Q530,80 563.5,80Q597,80 620,103L737,220Q760,243 760,276.5Q760,310 737,333L694,376Q671,399 637,399Q603,399 580,376L550,347L505,392L600,487L487,600ZM520,880L520,800Q637,800 718.5,718.5Q800,637 800,520L880,520Q880,595 851.5,660.5Q823,726 774.5,774.5Q726,823 660.5,851.5Q595,880 520,880ZM520,720L520,640Q570,640 605,605Q640,570 640,520L720,520Q720,603 661.5,661.5Q603,720 520,720ZM520,203L550,233L593,190L563,160Q563,160 563,160Q563,160 563,160L520,203Q520,203 520,203Q520,203 520,203ZM160,563L190,593L233,550L203,520Q203,520 203,520Q203,520 203,520L160,563Q160,563 160,563Q160,563 160,563ZM637,320L680,277Q680,277 680,277Q680,277 680,277L650,247L607,290L637,320Q637,320 637,320Q637,320 637,320ZM277,680L320,637Q320,637 320,637Q320,637 320,637L290,607L247,650L277,680Q277,680 277,680Q277,680 277,680Z"/>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index df49451..cd847f7 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1763,10 +1763,13 @@
<string name="lockpassword_password_recently_used">Device admin doesn\'t allow using a recent
password</string>
- <!-- [CHAR_LIMIT=NONE] Error shown when the user tries to set an ascending or descending sequence of digits -->
+ <!-- [CHAR_LIMIT=NONE] Error shown when the user tries to set an ascending or descending sequence of digits as PIN -->
<string name="lockpassword_pin_no_sequential_digits">Ascending, descending, or repeated sequence
of digits isn\'t allowed</string>
+ <!-- Error shown when the user tries to set an ascending or descending sequence of alphanumeric characters in the password [CHAR_LIMIT=NONE] -->
+ <string name="lockpassword_password_no_sequential_characters">Ascending, descending, or repeated sequence of characters isn\'t allowed</string>
+
<!-- Label for Confirm button when entering PIN / password the second time. [CHAR LIMIT=30] -->
<string name="lockpassword_confirm_label">Confirm</string>
@@ -12126,7 +12129,7 @@
<!-- Summary for _satellite_setting_preference_layout. [CHAR LIMIT=NONE]-->
<string name="satellite_setting_enabled_summary">Send and receive text messages by satellite. Included with your account.</string>
<!-- Summary for _satellite_setting_preference_layout. [CHAR LIMIT=NONE]-->
- <string name="satellite_setting_disabled_summary">Send and receive text messages by satellite. Non included with your account.</string>
+ <string name="satellite_setting_disabled_summary">Send and receive text messages by satellite. Not included with your account.</string>
<!-- Search keywords for "_satellite_setting_preference_layout" [CHAR_LIMIT=NONE] -->
<string name="keywords_satellite_setting">Satellite messaging</string>
<!-- Category name "About satellite messaging" [CHAR_LIMIT=NONE] -->
diff --git a/src/com/android/settings/ResetNetwork.java b/src/com/android/settings/ResetNetwork.java
index ad9f35e..f86e29f 100644
--- a/src/com/android/settings/ResetNetwork.java
+++ b/src/com/android/settings/ResetNetwork.java
@@ -18,8 +18,11 @@
import android.app.Activity;
import android.app.settings.SettingsEnums;
+import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.content.res.Resources;
import android.os.Bundle;
import android.provider.Settings;
@@ -66,7 +69,7 @@
* prompt, followed by a keyguard pattern trace if the user has defined one, followed by a final
* strongly-worded "THIS WILL RESET EVERYTHING" prompt. If at any time the phone is allowed to go
* to sleep, is locked, et cetera, then the confirmation sequence is abandoned.
- *
+ * <p>
* This is the initial screen.
*/
public class ResetNetwork extends InstrumentedFragment {
@@ -81,8 +84,20 @@
private View mContentView;
private Spinner mSubscriptionSpinner;
private Button mInitiateButton;
- @VisibleForTesting View mEsimContainer;
- @VisibleForTesting CheckBox mEsimCheckbox;
+ @VisibleForTesting
+ View mEsimContainer;
+ @VisibleForTesting
+ CheckBox mEsimCheckbox;
+
+ private BroadcastReceiver mDefaultSubChangeReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction() != SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED) {
+ return;
+ }
+ establishInitialState(getActiveSubscriptionInfoList());
+ }
+ };
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
@@ -97,6 +112,7 @@
/**
* Keyguard validation is run using the standard {@link ConfirmLockPattern}
* component as a subactivity
+ *
* @param request the request code to be returned once confirmation finishes
* @return true if confirmation launched
*/
@@ -139,7 +155,7 @@
SubscriptionInfo subscription = mSubscriptions.get(selectedIndex);
int subId = subscription.getSubscriptionId();
request.setResetTelephonyAndNetworkPolicyManager(subId)
- .setResetApn(subId);
+ .setResetApn(subId);
if (Flags.resetMobileNetworkSettings()) {
request.setResetImsSubId(subId);
}
@@ -215,7 +231,6 @@
}
int selectedIndex = 0;
- int size = mSubscriptions.size();
List<String> subscriptionNames = new ArrayList<>();
for (SubscriptionInfo record : mSubscriptions) {
if (record.getSubscriptionId() == defaultSubscription) {
@@ -281,6 +296,8 @@
@Override
public void onResume() {
super.onResume();
+ getContext().registerReceiver(mDefaultSubChangeReceiver,
+ new IntentFilter(SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED));
if (mContentView == null) {
return;
@@ -297,6 +314,12 @@
establishInitialState(updatedSubscriptions);
}
+ @Override
+ public void onPause() {
+ super.onPause();
+ getContext().unregisterReceiver(mDefaultSubChangeReceiver);
+ }
+
private boolean showEuiccSettings(Context context) {
if (!SubscriptionUtil.isSimHardwareVisible(context)) {
return false;
diff --git a/src/com/android/settings/SettingsApplication.java b/src/com/android/settings/SettingsApplication.java
index 7e008e4..b1177dd 100644
--- a/src/com/android/settings/SettingsApplication.java
+++ b/src/com/android/settings/SettingsApplication.java
@@ -16,8 +16,6 @@
package com.android.settings;
-import static com.android.settingslib.flags.Flags.settingsCatalyst;
-
import android.app.Application;
import android.content.Context;
import android.content.pm.PackageManager;
@@ -73,7 +71,7 @@
public void onCreate() {
super.onCreate();
- if (settingsCatalyst()) {
+ if (Flags.catalyst()) {
PreferenceScreenRegistry.INSTANCE.setPreferenceScreensSupplier(
this::getPreferenceScreens);
}
diff --git a/src/com/android/settings/backup/SettingsBackupHelper.java b/src/com/android/settings/backup/SettingsBackupHelper.java
index 73760a4..5fdbb00 100644
--- a/src/com/android/settings/backup/SettingsBackupHelper.java
+++ b/src/com/android/settings/backup/SettingsBackupHelper.java
@@ -16,17 +16,19 @@
package com.android.settings.backup;
-
import android.app.backup.BackupAgentHelper;
+import android.util.Log;
import com.android.settings.flags.Flags;
import com.android.settings.onboarding.OnboardingFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.shortcut.CreateShortcutPreferenceController;
+import com.android.settings.shortcut.ShortcutsUpdater;
import com.android.settingslib.datastore.BackupRestoreStorageManager;
/** Backup agent for Settings APK */
public class SettingsBackupHelper extends BackupAgentHelper {
+ private static final String TAG = "SettingsBackupHelper";
+
public static final String SOUND_BACKUP_HELPER = "SoundSettingsBackup";
public static final String ACCESSIBILITY_APPEARANCE_BACKUP_HELPER =
"AccessibilityAppearanceSettingsBackup";
@@ -58,6 +60,10 @@
public void onRestoreFinished() {
super.onRestoreFinished();
BackupRestoreStorageManager.getInstance(this).onRestoreFinished();
- CreateShortcutPreferenceController.updateRestoredShortcuts(this);
+ try {
+ ShortcutsUpdater.updatePinnedShortcuts(this);
+ } catch (Exception e) {
+ Log.e(TAG, "Error updating shortcuts after restoring backup", e);
+ }
}
}
diff --git a/src/com/android/settings/dashboard/DashboardFragment.java b/src/com/android/settings/dashboard/DashboardFragment.java
index 220856a..6333f22 100644
--- a/src/com/android/settings/dashboard/DashboardFragment.java
+++ b/src/com/android/settings/dashboard/DashboardFragment.java
@@ -15,8 +15,6 @@
*/
package com.android.settings.dashboard;
-import static com.android.settingslib.flags.Flags.settingsCatalyst;
-
import android.app.Activity;
import android.app.settings.SettingsEnums;
import android.content.ContentResolver;
@@ -390,7 +388,7 @@
/** Returns if catalyst is enabled on current screen. */
protected final boolean isCatalystEnabled() {
- if (!settingsCatalyst()) {
+ if (!Flags.catalyst()) {
return false;
}
Context context = getContext();
diff --git a/src/com/android/settings/localepicker/LocaleDragAndDropAdapter.java b/src/com/android/settings/localepicker/LocaleDragAndDropAdapter.java
index ef129ff..907fe7b 100644
--- a/src/com/android/settings/localepicker/LocaleDragAndDropAdapter.java
+++ b/src/com/android/settings/localepicker/LocaleDragAndDropAdapter.java
@@ -16,6 +16,8 @@
package com.android.settings.localepicker;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.graphics.Canvas;
@@ -41,7 +43,8 @@
import com.android.internal.app.LocaleStore;
import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.shortcut.ShortcutsUpdateTask;
+import com.android.settings.shortcut.ShortcutsUpdater;
+import com.android.settingslib.utils.ThreadUtils;
import java.text.NumberFormat;
import java.util.ArrayList;
@@ -96,7 +99,7 @@
LocaleDragAndDropAdapter(LocaleListEditor parent, List<LocaleStore.LocaleInfo> feedItemList) {
mFeedItemList = feedItemList;
mCacheItemList = new ArrayList<>(feedItemList);
- mContext = parent.getContext();
+ mContext = checkNotNull(parent.getContext());
final float dragElevation = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
mContext.getResources().getDisplayMetrics());
@@ -350,7 +353,8 @@
LocalePicker.updateLocales(mLocalesToSetNext);
mLocalesSetLast = mLocalesToSetNext;
- new ShortcutsUpdateTask(mContext).execute();
+ ThreadUtils.postOnBackgroundThread(
+ () -> ShortcutsUpdater.updatePinnedShortcuts(mContext));
mLocalesToSetNext = null;
diff --git a/src/com/android/settings/password/ChooseLockPassword.java b/src/com/android/settings/password/ChooseLockPassword.java
index bcf1795..aba9edd 100644
--- a/src/com/android/settings/password/ChooseLockPassword.java
+++ b/src/com/android/settings/password/ChooseLockPassword.java
@@ -927,7 +927,9 @@
: R.string.lockpassword_pin_too_long));
break;
case CONTAINS_SEQUENCE:
- messages.add(getString(R.string.lockpassword_pin_no_sequential_digits));
+ messages.add(getString(mIsAlphaMode
+ ? R.string.lockpassword_password_no_sequential_characters
+ : R.string.lockpassword_pin_no_sequential_digits));
break;
case RECENTLY_USED:
DevicePolicyManager devicePolicyManager =
diff --git a/src/com/android/settings/shortcut/CreateShortcutPreferenceController.java b/src/com/android/settings/shortcut/CreateShortcutPreferenceController.java
index 8f74bd9..0e2e6bc 100644
--- a/src/com/android/settings/shortcut/CreateShortcutPreferenceController.java
+++ b/src/com/android/settings/shortcut/CreateShortcutPreferenceController.java
@@ -16,27 +16,19 @@
package com.android.settings.shortcut;
+import static com.android.settings.shortcut.Shortcuts.SHORTCUT_PROBE;
+
import android.app.Activity;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
-import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.drawable.Drawable;
-import android.graphics.drawable.Icon;
-import android.graphics.drawable.LayerDrawable;
import android.net.ConnectivityManager;
import android.util.Log;
-import android.view.ContextThemeWrapper;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.ImageView;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
@@ -48,7 +40,6 @@
import com.android.settings.Settings.DataUsageSummaryActivity;
import com.android.settings.Settings.TetherSettingsActivity;
import com.android.settings.Settings.WifiTetherSettingsActivity;
-import com.android.settings.activityembedding.ActivityEmbeddingUtils;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.gestures.OneHandedSettingsUtils;
import com.android.settings.network.SubscriptionUtil;
@@ -69,11 +60,6 @@
private static final String TAG = "CreateShortcutPrefCtrl";
- static final String SHORTCUT_ID_PREFIX = "component-shortcut-";
- static final Intent SHORTCUT_PROBE = new Intent(Intent.ACTION_MAIN)
- .addCategory("com.android.settings.SHORTCUT")
- .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
private final ShortcutManager mShortcutManager;
private final PackageManager mPackageManager;
private final ConnectivityManager mConnectivityManager;
@@ -132,9 +118,7 @@
if (mHost == null) {
return false;
}
- final Intent shortcutIntent = createResultIntent(
- buildShortcutIntent(uiContext, info),
- info, clickTarget.getTitle());
+ final Intent shortcutIntent = createResultIntent(info);
mHost.setResult(Activity.RESULT_OK, shortcutIntent);
logCreateShortcut(info);
mHost.finish();
@@ -149,21 +133,20 @@
* launcher widget using this intent.
*/
@VisibleForTesting
- Intent createResultIntent(Intent shortcutIntent, ResolveInfo resolveInfo,
- CharSequence label) {
- ShortcutInfo info = createShortcutInfo(mContext, shortcutIntent, resolveInfo, label);
+ Intent createResultIntent(ResolveInfo resolveInfo) {
+ ShortcutInfo info = Shortcuts.createShortcutInfo(mContext, resolveInfo);
Intent intent = mShortcutManager.createShortcutResultIntent(info);
if (intent == null) {
intent = new Intent();
}
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(mContext, R.mipmap.ic_launcher_settings))
- .putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent)
- .putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
+ .putExtra(Intent.EXTRA_SHORTCUT_INTENT, info.getIntent())
+ .putExtra(Intent.EXTRA_SHORTCUT_NAME, info.getShortLabel());
final ActivityInfo activityInfo = resolveInfo.activityInfo;
if (activityInfo.icon != 0) {
- intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, createIcon(
+ intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, Shortcuts.createIcon(
mContext,
activityInfo.applicationInfo,
activityInfo.icon,
@@ -239,87 +222,6 @@
info.activityInfo.name);
}
- private static Intent buildShortcutIntent(Context context, ResolveInfo info) {
- Intent intent = new Intent(SHORTCUT_PROBE)
- .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP)
- .setClassName(info.activityInfo.packageName, info.activityInfo.name);
- if (ActivityEmbeddingUtils.isEmbeddingActivityEnabled(context)) {
- intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
- }
- return intent;
- }
-
- private static ShortcutInfo createShortcutInfo(Context context, Intent shortcutIntent,
- ResolveInfo resolveInfo, CharSequence label) {
- final ActivityInfo activityInfo = resolveInfo.activityInfo;
-
- final Icon maskableIcon;
- if (activityInfo.icon != 0 && activityInfo.applicationInfo != null) {
- maskableIcon = Icon.createWithAdaptiveBitmap(createIcon(
- context,
- activityInfo.applicationInfo, activityInfo.icon,
- R.layout.shortcut_badge_maskable,
- context.getResources().getDimensionPixelSize(R.dimen.shortcut_size_maskable)));
- } else {
- maskableIcon = Icon.createWithResource(context, R.drawable.ic_launcher_settings);
- }
- final String shortcutId = SHORTCUT_ID_PREFIX +
- shortcutIntent.getComponent().flattenToShortString();
- return new ShortcutInfo.Builder(context, shortcutId)
- .setShortLabel(label)
- .setIntent(shortcutIntent)
- .setIcon(maskableIcon)
- .build();
- }
-
- private static Bitmap createIcon(Context context, ApplicationInfo app, int resource,
- int layoutRes, int size) {
- final Context themedContext = new ContextThemeWrapper(context,
- android.R.style.Theme_Material);
- final View view = LayoutInflater.from(themedContext).inflate(layoutRes, null);
- final int spec = View.MeasureSpec.makeMeasureSpec(size, View.MeasureSpec.EXACTLY);
- view.measure(spec, spec);
- final Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),
- Bitmap.Config.ARGB_8888);
- final Canvas canvas = new Canvas(bitmap);
-
- Drawable iconDrawable;
- try {
- iconDrawable = context.getPackageManager().getResourcesForApplication(app)
- .getDrawable(resource, themedContext.getTheme());
- if (iconDrawable instanceof LayerDrawable) {
- iconDrawable = ((LayerDrawable) iconDrawable).getDrawable(1);
- }
- ((ImageView) view.findViewById(android.R.id.icon)).setImageDrawable(iconDrawable);
- } catch (PackageManager.NameNotFoundException e) {
- Log.w(TAG, "Cannot load icon from app " + app + ", returning a default icon");
- Icon icon = Icon.createWithResource(context, R.drawable.ic_launcher_settings);
- ((ImageView) view.findViewById(android.R.id.icon)).setImageIcon(icon);
- }
-
- view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
- view.draw(canvas);
- return bitmap;
- }
-
- public static void updateRestoredShortcuts(Context context) {
- ShortcutManager sm = context.getSystemService(ShortcutManager.class);
- List<ShortcutInfo> updatedShortcuts = new ArrayList<>();
- for (ShortcutInfo si : sm.getPinnedShortcuts()) {
- if (si.getId().startsWith(SHORTCUT_ID_PREFIX)) {
- ResolveInfo ri = context.getPackageManager().resolveActivity(si.getIntent(), 0);
-
- if (ri != null) {
- updatedShortcuts.add(createShortcutInfo(context,
- buildShortcutIntent(context, ri), ri, si.getShortLabel()));
- }
- }
- }
- if (!updatedShortcuts.isEmpty()) {
- sm.updateShortcuts(updatedShortcuts);
- }
- }
-
private static final Comparator<ResolveInfo> SHORTCUT_COMPARATOR =
(i1, i2) -> i1.priority - i2.priority;
}
diff --git a/src/com/android/settings/shortcut/Shortcuts.java b/src/com/android/settings/shortcut/Shortcuts.java
new file mode 100644
index 0000000..53544eb
--- /dev/null
+++ b/src/com/android/settings/shortcut/Shortcuts.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2024 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.shortcut;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ShortcutInfo;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.Icon;
+import android.graphics.drawable.LayerDrawable;
+import android.util.Log;
+import android.view.ContextThemeWrapper;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ImageView;
+
+import com.android.settings.R;
+import com.android.settings.activityembedding.ActivityEmbeddingUtils;
+
+class Shortcuts {
+
+ private static final String TAG = "Shortcuts";
+
+ static final String SHORTCUT_ID_PREFIX = "component-shortcut-";
+ static final Intent SHORTCUT_PROBE = new Intent(Intent.ACTION_MAIN)
+ .addCategory("com.android.settings.SHORTCUT")
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+ static ShortcutInfo createShortcutInfo(Context context, ResolveInfo target) {
+ checkArgument(target.activityInfo != null);
+ String shortcutId = SHORTCUT_ID_PREFIX
+ + target.activityInfo.getComponentName().flattenToShortString();
+
+ return createShortcutInfo(context, shortcutId, target);
+ }
+
+ static ShortcutInfo createShortcutInfo(Context context, String id, ResolveInfo target) {
+ Intent intent = new Intent(SHORTCUT_PROBE)
+ .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP)
+ .setClassName(target.activityInfo.packageName, target.activityInfo.name);
+ if (ActivityEmbeddingUtils.isEmbeddingActivityEnabled(context)) {
+ intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
+ }
+
+ CharSequence label = target.loadLabel(context.getPackageManager());
+ Icon maskableIcon = getMaskableIcon(context, target.activityInfo);
+
+ return new ShortcutInfo.Builder(context, id)
+ .setIntent(intent)
+ .setShortLabel(label)
+ .setIcon(maskableIcon)
+ .build();
+ }
+
+ private static Icon getMaskableIcon(Context context, ActivityInfo activityInfo) {
+ if (activityInfo.icon != 0 && activityInfo.applicationInfo != null) {
+ return Icon.createWithAdaptiveBitmap(createIcon(
+ context,
+ activityInfo.applicationInfo, activityInfo.icon,
+ R.layout.shortcut_badge_maskable,
+ context.getResources().getDimensionPixelSize(R.dimen.shortcut_size_maskable)));
+ } else {
+ return Icon.createWithResource(context, R.drawable.ic_launcher_settings);
+ }
+ }
+
+ static Bitmap createIcon(Context context, ApplicationInfo app, int resource, int layoutRes,
+ int size) {
+ final Context themedContext = new ContextThemeWrapper(context,
+ android.R.style.Theme_Material);
+ final View view = LayoutInflater.from(themedContext).inflate(layoutRes, null);
+ final int spec = View.MeasureSpec.makeMeasureSpec(size, View.MeasureSpec.EXACTLY);
+ view.measure(spec, spec);
+ final Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),
+ Bitmap.Config.ARGB_8888);
+ final Canvas canvas = new Canvas(bitmap);
+
+ Drawable iconDrawable;
+ try {
+ iconDrawable = context.getPackageManager().getResourcesForApplication(app)
+ .getDrawable(resource, themedContext.getTheme());
+ if (iconDrawable instanceof LayerDrawable) {
+ iconDrawable = ((LayerDrawable) iconDrawable).getDrawable(1);
+ }
+ ((ImageView) view.findViewById(android.R.id.icon)).setImageDrawable(iconDrawable);
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.w(TAG, "Cannot load icon from app " + app + ", returning a default icon");
+ Icon icon = Icon.createWithResource(context, R.drawable.ic_launcher_settings);
+ ((ImageView) view.findViewById(android.R.id.icon)).setImageIcon(icon);
+ }
+
+ view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
+ view.draw(canvas);
+ return bitmap;
+ }
+}
diff --git a/src/com/android/settings/shortcut/ShortcutsUpdateReceiver.java b/src/com/android/settings/shortcut/ShortcutsUpdateReceiver.java
new file mode 100644
index 0000000..657af5b
--- /dev/null
+++ b/src/com/android/settings/shortcut/ShortcutsUpdateReceiver.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2024 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.shortcut;
+
+import android.app.Flags;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+
+import com.android.settingslib.utils.ThreadUtils;
+
+public class ShortcutsUpdateReceiver extends BroadcastReceiver {
+
+ private static final String TAG = "ShortcutsUpdateReceiver";
+
+ @Override
+ public void onReceive(@NonNull Context context, @NonNull Intent intent) {
+ if (!Flags.modesApi() || !Flags.modesUi()) {
+ return;
+ }
+
+ if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
+ PendingResult pendingResult = goAsync();
+
+ ThreadUtils.getBackgroundExecutor().execute(() -> {
+ try {
+ ShortcutsUpdater.updatePinnedShortcuts(context);
+ } catch (Exception e) {
+ Log.e(TAG, "Error trying to update Settings shortcuts", e);
+ } finally {
+ pendingResult.finish();
+ }
+ });
+ }
+ }
+}
diff --git a/src/com/android/settings/shortcut/ShortcutsUpdateTask.java b/src/com/android/settings/shortcut/ShortcutsUpdateTask.java
deleted file mode 100644
index 54f7d1c..0000000
--- a/src/com/android/settings/shortcut/ShortcutsUpdateTask.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.shortcut;
-
-import static com.android.settings.shortcut.CreateShortcutPreferenceController.SHORTCUT_ID_PREFIX;
-import static com.android.settings.shortcut.CreateShortcutPreferenceController.SHORTCUT_PROBE;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.pm.ShortcutInfo;
-import android.content.pm.ShortcutManager;
-import android.os.AsyncTask;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class ShortcutsUpdateTask extends AsyncTask<Void, Void, Void> {
-
- private final Context mContext;
-
- public ShortcutsUpdateTask(Context context) {
- mContext = context;
- }
-
- @Override
- public Void doInBackground(Void... params) {
- ShortcutManager sm = mContext.getSystemService(ShortcutManager.class);
- PackageManager pm = mContext.getPackageManager();
-
- List<ShortcutInfo> updates = new ArrayList<>();
- for (ShortcutInfo info : sm.getPinnedShortcuts()) {
- if (!info.getId().startsWith(SHORTCUT_ID_PREFIX)) {
- continue;
- }
- ComponentName cn = ComponentName.unflattenFromString(
- info.getId().substring(SHORTCUT_ID_PREFIX.length()));
- ResolveInfo ri = pm.resolveActivity(new Intent(SHORTCUT_PROBE).setComponent(cn), 0);
- if (ri == null) {
- continue;
- }
- updates.add(new ShortcutInfo.Builder(mContext, info.getId())
- .setShortLabel(ri.loadLabel(pm)).build());
- }
- if (!updates.isEmpty()) {
- sm.updateShortcuts(updates);
- }
- return null;
- }
-}
diff --git a/src/com/android/settings/shortcut/ShortcutsUpdater.java b/src/com/android/settings/shortcut/ShortcutsUpdater.java
new file mode 100644
index 0000000..90a60fd
--- /dev/null
+++ b/src/com/android/settings/shortcut/ShortcutsUpdater.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.shortcut;
+
+import static com.android.settings.shortcut.Shortcuts.SHORTCUT_ID_PREFIX;
+import static com.android.settings.shortcut.Shortcuts.SHORTCUT_PROBE;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import android.app.Flags;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ShortcutInfo;
+import android.content.pm.ShortcutManager;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.android.settings.Settings;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ShortcutsUpdater {
+
+ /**
+ * Update label, icon, and intent of pinned shortcuts to Settings subpages.
+ *
+ * <p>Should be called whenever any of those could have changed, such as after changing locale,
+ * restoring a backup from a different device, or when flags controlling available features
+ * may have flipped.
+ */
+ public static void updatePinnedShortcuts(Context context) {
+ ShortcutManager sm = checkNotNull(context.getSystemService(ShortcutManager.class));
+
+ List<ShortcutInfo> updates = new ArrayList<>();
+ for (ShortcutInfo info : sm.getPinnedShortcuts()) {
+ ResolveInfo resolvedActivity = resolveActivity(context, info);
+ if (resolvedActivity != null) {
+ // Id is preserved to update an existing shortcut, but the activity it opens might
+ // be different, according to maybeGetReplacingComponent.
+ updates.add(Shortcuts.createShortcutInfo(context, info.getId(), resolvedActivity));
+ }
+ }
+ if (!updates.isEmpty()) {
+ sm.updateShortcuts(updates);
+ }
+ }
+
+ @Nullable
+ private static ResolveInfo resolveActivity(Context context, ShortcutInfo shortcut) {
+ if (!shortcut.getId().startsWith(SHORTCUT_ID_PREFIX)) {
+ return null;
+ }
+
+ ComponentName cn = ComponentName.unflattenFromString(
+ shortcut.getId().substring(SHORTCUT_ID_PREFIX.length()));
+ if (cn == null) {
+ return null;
+ }
+
+ // Check if the componentName is obsolete and has been replaced by a different one.
+ cn = maybeGetReplacingComponent(context, cn);
+ PackageManager pm = context.getPackageManager();
+ return pm.resolveActivity(new Intent(SHORTCUT_PROBE).setComponent(cn), 0);
+ }
+
+ @NonNull
+ private static ComponentName maybeGetReplacingComponent(Context context, ComponentName cn) {
+ // ZenModeSettingsActivity is replaced by ModesSettingsActivity and will be deleted
+ // soon (so we shouldn't use ZenModeSettingsActivity.class).
+ if (Flags.modesApi() && Flags.modesUi()
+ && cn.getClassName().endsWith("Settings$ZenModeSettingsActivity")) {
+ return new ComponentName(context, Settings.ModesSettingsActivity.class);
+ }
+
+ return cn;
+ }
+}
diff --git a/src/com/android/settings/sound/AudioSwitchPreferenceController.java b/src/com/android/settings/sound/AudioSwitchPreferenceController.java
index 5938362..e9787a7 100644
--- a/src/com/android/settings/sound/AudioSwitchPreferenceController.java
+++ b/src/com/android/settings/sound/AudioSwitchPreferenceController.java
@@ -45,6 +45,7 @@
import com.android.settings.bluetooth.Utils;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.FeatureFlags;
+import com.android.settings.sounde.AudioSwitchUtils;
import com.android.settingslib.bluetooth.A2dpProfile;
import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
@@ -68,7 +69,8 @@
* updating the current status of switcher entry. Subclasses must overwrite
*/
public abstract class AudioSwitchPreferenceController extends BasePreferenceController
- implements BluetoothCallback, LifecycleObserver, OnStart, OnStop {
+ implements BluetoothCallback, LifecycleObserver, OnStart, OnStop,
+ LocalBluetoothProfileManager.ServiceListener {
private static final String TAG = "AudioSwitchPrefCtrl";
@@ -149,6 +151,11 @@
return;
}
mLocalBluetoothManager.setForegroundActivity(mContext);
+ if (!AudioSwitchUtils.isLeAudioProfileReady(mProfileManager)) {
+ if (mProfileManager != null) {
+ mProfileManager.addServiceListener(this);
+ }
+ }
register();
}
@@ -159,6 +166,9 @@
return;
}
mLocalBluetoothManager.setForegroundActivity(null);
+ if (mProfileManager != null) {
+ mProfileManager.removeServiceListener(this);
+ }
unregister();
}
@@ -193,6 +203,20 @@
updateState(mPreference);
}
+ @Override
+ public void onServiceConnected() {
+ Log.d(TAG, "onServiceConnected");
+ if (AudioSwitchUtils.isLeAudioProfileReady(mProfileManager)) {
+ updateState(mPreference);
+ }
+ }
+
+ @Override
+ public void onServiceDisconnected() {
+ Log.d(TAG, "onServiceDisconnected()");
+ // Do nothing.
+ }
+
public void setCallback(AudioSwitchCallback callback) {
mAudioSwitchPreferenceCallback = callback;
}
diff --git a/src/com/android/settings/sound/AudioSwitchUtils.kt b/src/com/android/settings/sound/AudioSwitchUtils.kt
new file mode 100644
index 0000000..de36bb1
--- /dev/null
+++ b/src/com/android/settings/sound/AudioSwitchUtils.kt
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2024 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.sounde
+
+import com.android.settingslib.bluetooth.LocalBluetoothProfileManager
+
+/**
+ * Utilities class for audio switcher controllers
+ */
+class AudioSwitchUtils {
+ companion object {
+
+ /** Check if LE Audio profile is ready. */
+ @JvmStatic
+ fun isLeAudioProfileReady(profileManager: LocalBluetoothProfileManager?): Boolean =
+ profileManager?.getLeAudioProfile()?.isProfileReady() ?: false
+ }
+}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java
index 1e81ec0..2559618 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java
@@ -71,7 +71,6 @@
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
-import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowDrawable;
@@ -314,7 +313,7 @@
/* minComplexity= */ PASSWORD_COMPLEXITY_NONE,
/* passwordType= */ PASSWORD_QUALITY_ALPHABETIC,
/* userEnteredPassword= */ LockscreenCredential.createPassword("12345678"),
- "Ascending, descending, or repeated sequence of digits isn't allowed");
+ "Ascending, descending, or repeated sequence of characters isn't allowed");
}
@Test
@@ -356,7 +355,7 @@
/* minComplexity= */ PASSWORD_COMPLEXITY_LOW,
/* passwordType= */ PASSWORD_QUALITY_ALPHABETIC,
/* userEnteredPassword= */ LockscreenCredential.createPassword("12345678"),
- "Ascending, descending, or repeated sequence of digits isn't allowed");
+ "Ascending, descending, or repeated sequence of characters isn't allowed");
}
@Test
diff --git a/tests/robotests/src/com/android/settings/shortcut/CreateShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/shortcut/CreateShortcutPreferenceControllerTest.java
index 9727dd1..8442a37 100644
--- a/tests/robotests/src/com/android/settings/shortcut/CreateShortcutPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/shortcut/CreateShortcutPreferenceControllerTest.java
@@ -16,7 +16,7 @@
package com.android.settings.shortcut;
-import static com.android.settings.shortcut.CreateShortcutPreferenceController.SHORTCUT_ID_PREFIX;
+import static com.android.settings.shortcut.Shortcuts.SHORTCUT_ID_PREFIX;
import static com.google.common.truth.Truth.assertThat;
@@ -101,10 +101,10 @@
when(mShortcutManager.createShortcutResultIntent(any(ShortcutInfo.class)))
.thenReturn(new Intent().putExtra("d1", "d2"));
- final Intent intent = new Intent(CreateShortcutPreferenceController.SHORTCUT_PROBE)
+ final Intent intent = new Intent(Shortcuts.SHORTCUT_PROBE)
.setClass(mContext, Settings.ManageApplicationsActivity.class);
final ResolveInfo ri = mContext.getPackageManager().resolveActivity(intent, 0);
- final Intent result = mController.createResultIntent(intent, ri, "mock");
+ final Intent result = mController.createResultIntent(ri);
assertThat(result.getStringExtra("d1")).isEqualTo("d2");
assertThat((Object) result.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT)).isNotNull();
@@ -131,7 +131,7 @@
ri2.activityInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
mPackageManager.setResolveInfosForIntent(
- new Intent(CreateShortcutPreferenceController.SHORTCUT_PROBE),
+ new Intent(Shortcuts.SHORTCUT_PROBE),
Arrays.asList(ri1, ri2));
doReturn(false).when(mController).canShowWifiHotspot();
@@ -158,7 +158,7 @@
ri2.activityInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
mPackageManager.setResolveInfosForIntent(
- new Intent(CreateShortcutPreferenceController.SHORTCUT_PROBE),
+ new Intent(Shortcuts.SHORTCUT_PROBE),
Arrays.asList(ri1, ri2));
doReturn(false).when(mController).canShowWifiHotspot();
@@ -276,7 +276,7 @@
ri.activityInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
mPackageManager.setResolveInfosForIntent(
- new Intent(CreateShortcutPreferenceController.SHORTCUT_PROBE),
+ new Intent(Shortcuts.SHORTCUT_PROBE),
Arrays.asList(ri));
}
}
diff --git a/tests/robotests/src/com/android/settings/shortcut/ShortcutsTest.java b/tests/robotests/src/com/android/settings/shortcut/ShortcutsTest.java
new file mode 100644
index 0000000..a347ff9
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/shortcut/ShortcutsTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2024 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.shortcut;
+
+import static com.android.settings.shortcut.Shortcuts.SHORTCUT_PROBE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ShortcutInfo;
+
+import com.android.settings.Settings;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class ShortcutsTest {
+
+ private Context mContext;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.getApplication();
+ }
+
+ @Test
+ public void shortcutsUpdateTask() {
+ final Intent intent = new Intent(SHORTCUT_PROBE)
+ .setClass(mContext, Settings.ManageApplicationsActivity.class);
+ final ResolveInfo ri = mContext.getPackageManager().resolveActivity(intent, 0);
+ assertThat(ri).isNotNull();
+
+ ShortcutInfo shortcut = Shortcuts.createShortcutInfo(mContext, ri);
+
+ assertThat(shortcut.getLabel()).isNotNull();
+ assertThat(shortcut.getLabel().toString()).isEqualTo("App info");
+
+ assertThat(shortcut.getIntent()).isNotNull();
+ assertThat(shortcut.getIntent().getAction()).isEqualTo(Intent.ACTION_MAIN);
+ assertThat(shortcut.getIntent().getCategories()).contains("com.android.settings.SHORTCUT");
+ assertThat(shortcut.getIntent().getComponent()).isEqualTo(
+ new ComponentName(mContext, Settings.ManageApplicationsActivity.class));
+ assertThat(shortcut.getIcon()).isNotNull();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/shortcut/ShortcutsUpdateTaskTest.java b/tests/robotests/src/com/android/settings/shortcut/ShortcutsUpdateTaskTest.java
deleted file mode 100644
index 8352e7a..0000000
--- a/tests/robotests/src/com/android/settings/shortcut/ShortcutsUpdateTaskTest.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.shortcut;
-
-import static com.android.settings.shortcut.CreateShortcutPreferenceController.SHORTCUT_ID_PREFIX;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.pm.ShortcutInfo;
-import android.content.pm.ShortcutManager;
-
-import com.android.settings.Settings;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.shadow.api.Shadow;
-import org.robolectric.shadows.ShadowPackageManager;
-
-import java.util.Arrays;
-import java.util.List;
-
-@RunWith(RobolectricTestRunner.class)
-public class ShortcutsUpdateTaskTest {
-
- private Context mContext;
- private ShadowPackageManager mPackageManager;
-
- @Mock
- private ShortcutManager mShortcutManager;
- @Captor
- private ArgumentCaptor<List<ShortcutInfo>> mListCaptor;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
- mContext = RuntimeEnvironment.application;
- mPackageManager = Shadow.extract(mContext.getPackageManager());
- }
-
- @Test
- public void shortcutsUpdateTask() {
- mContext = spy(RuntimeEnvironment.application);
- doReturn(mShortcutManager).when(mContext).getSystemService(eq(Context.SHORTCUT_SERVICE));
- final Intent shortcut1 = new Intent(CreateShortcutPreferenceController.SHORTCUT_PROBE)
- .setComponent(new ComponentName(
- mContext, Settings.ManageApplicationsActivity.class));
- final ResolveInfo ri1 = mock(ResolveInfo.class);
- ri1.nonLocalizedLabel = "label1";
-
- final Intent shortcut2 = new Intent(CreateShortcutPreferenceController.SHORTCUT_PROBE)
- .setComponent(new ComponentName(
- mContext, Settings.SoundSettingsActivity.class));
- final ResolveInfo ri2 = mock(ResolveInfo.class);
- ri2.nonLocalizedLabel = "label2";
-
- mPackageManager.addResolveInfoForIntent(shortcut1, ri1);
- mPackageManager.addResolveInfoForIntent(shortcut2, ri2);
-
- final List<ShortcutInfo> pinnedShortcuts = Arrays.asList(
- makeShortcut("d1"),
- makeShortcut("d2"),
- makeShortcut(Settings.ManageApplicationsActivity.class),
- makeShortcut("d3"),
- makeShortcut(Settings.SoundSettingsActivity.class));
- when(mShortcutManager.getPinnedShortcuts()).thenReturn(pinnedShortcuts);
-
- new ShortcutsUpdateTask(mContext).doInBackground();
-
- verify(mShortcutManager, times(1)).updateShortcuts(mListCaptor.capture());
-
- final List<ShortcutInfo> updates = mListCaptor.getValue();
-
- assertThat(updates).hasSize(2);
- assertThat(pinnedShortcuts.get(2).getId()).isEqualTo(updates.get(0).getId());
- assertThat(pinnedShortcuts.get(4).getId()).isEqualTo(updates.get(1).getId());
- }
-
- private ShortcutInfo makeShortcut(Class<?> className) {
- ComponentName cn = new ComponentName(mContext, className);
- return makeShortcut(SHORTCUT_ID_PREFIX + cn.flattenToShortString());
- }
-
- private ShortcutInfo makeShortcut(String id) {
- return new ShortcutInfo.Builder(mContext, id).build();
- }
-}
diff --git a/tests/robotests/src/com/android/settings/shortcut/ShortcutsUpdaterTest.java b/tests/robotests/src/com/android/settings/shortcut/ShortcutsUpdaterTest.java
new file mode 100644
index 0000000..5324ff5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/shortcut/ShortcutsUpdaterTest.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.shortcut;
+
+import static com.android.settings.shortcut.Shortcuts.SHORTCUT_ID_PREFIX;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.Flags;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.ShortcutInfo;
+import android.content.pm.ShortcutManager;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
+
+import com.android.settings.Settings;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+import java.util.Arrays;
+import java.util.List;
+
+@RunWith(RobolectricTestRunner.class)
+public class ShortcutsUpdaterTest {
+
+ private Context mContext;
+
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
+ @Mock
+ private ShortcutManager mShortcutManager;
+ @Captor
+ private ArgumentCaptor<List<ShortcutInfo>> mListCaptor;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ doReturn(mShortcutManager).when(mContext).getSystemService(eq(Context.SHORTCUT_SERVICE));
+ }
+
+ @Test
+ public void updatePinnedShortcuts_updatesAllShortcuts() {
+ final List<ShortcutInfo> pinnedShortcuts = Arrays.asList(
+ makeShortcut("d1"),
+ makeShortcut("d2"),
+ makeShortcut(Settings.ManageApplicationsActivity.class),
+ makeShortcut("d3"),
+ makeShortcut(Settings.SoundSettingsActivity.class));
+ when(mShortcutManager.getPinnedShortcuts()).thenReturn(pinnedShortcuts);
+
+ ShortcutsUpdater.updatePinnedShortcuts(mContext);
+
+ verify(mShortcutManager, times(1)).updateShortcuts(mListCaptor.capture());
+
+ final List<ShortcutInfo> updates = mListCaptor.getValue();
+
+ assertThat(updates).hasSize(2);
+ assertThat(pinnedShortcuts.get(2).getId()).isEqualTo(updates.get(0).getId());
+ assertThat(pinnedShortcuts.get(4).getId()).isEqualTo(updates.get(1).getId());
+ assertThat(updates.get(0).getShortLabel().toString()).isEqualTo("App info");
+ assertThat(updates.get(1).getShortLabel().toString()).isEqualTo("Sound & vibration");
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_MODES_UI)
+ public void updatePinnedShortcuts_withModesFlag_replacesDndByModes() {
+ List<ShortcutInfo> shortcuts = List.of(
+ makeShortcut(Settings.ZenModeSettingsActivity.class));
+ when(mShortcutManager.getPinnedShortcuts()).thenReturn(shortcuts);
+
+ ShortcutsUpdater.updatePinnedShortcuts(mContext);
+
+ verify(mShortcutManager, times(1)).updateShortcuts(mListCaptor.capture());
+ final List<ShortcutInfo> updates = mListCaptor.getValue();
+ assertThat(updates).hasSize(1);
+
+ // Id hasn't changed, but intent and label has.
+ ComponentName zenCn = new ComponentName(mContext, Settings.ZenModeSettingsActivity.class);
+ ComponentName modesCn = new ComponentName(mContext, Settings.ModesSettingsActivity.class);
+ assertThat(updates.get(0).getId()).isEqualTo(
+ SHORTCUT_ID_PREFIX + zenCn.flattenToShortString());
+ assertThat(updates.get(0).getIntent().getComponent()).isEqualTo(modesCn);
+ assertThat(updates.get(0).getShortLabel().toString()).isEqualTo("Modes");
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_MODES_UI)
+ public void updatePinnedShortcuts_withoutModesFlag_leavesDndAlone() {
+ List<ShortcutInfo> shortcuts = List.of(
+ makeShortcut(Settings.ZenModeSettingsActivity.class));
+ when(mShortcutManager.getPinnedShortcuts()).thenReturn(shortcuts);
+
+ ShortcutsUpdater.updatePinnedShortcuts(mContext);
+
+ verify(mShortcutManager, times(1)).updateShortcuts(mListCaptor.capture());
+ final List<ShortcutInfo> updates = mListCaptor.getValue();
+ assertThat(updates).hasSize(1);
+
+ // Nothing has changed.
+ ComponentName zenCn = new ComponentName(mContext, Settings.ZenModeSettingsActivity.class);
+ assertThat(updates.get(0).getId()).isEqualTo(
+ SHORTCUT_ID_PREFIX + zenCn.flattenToShortString());
+ assertThat(updates.get(0).getIntent().getComponent()).isEqualTo(zenCn);
+ assertThat(updates.get(0).getShortLabel().toString()).isEqualTo("Do Not Disturb");
+
+ }
+
+ private ShortcutInfo makeShortcut(Class<?> className) {
+ ComponentName cn = new ComponentName(mContext, className);
+ return makeShortcut(SHORTCUT_ID_PREFIX + cn.flattenToShortString());
+ }
+
+ private ShortcutInfo makeShortcut(String id) {
+ return new ShortcutInfo.Builder(mContext, id).build();
+ }
+}
diff --git a/tests/spa_unit/src/com/android/settings/spa/network/SimOnboardingLabelSimTest.kt b/tests/spa_unit/src/com/android/settings/spa/network/SimOnboardingLabelSimTest.kt
index 1910153..60686c9 100644
--- a/tests/spa_unit/src/com/android/settings/spa/network/SimOnboardingLabelSimTest.kt
+++ b/tests/spa_unit/src/com/android/settings/spa/network/SimOnboardingLabelSimTest.kt
@@ -39,6 +39,7 @@
import com.android.settings.network.SimOnboardingService
import com.android.settingslib.spa.testutils.waitUntilExists
import org.junit.Assert.assertEquals
+import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -129,6 +130,7 @@
}
@Test
+ @Ignore
fun simOnboardingLabelSimImpl_showItem_show3Items() {
preSetupContent()
diff --git a/tests/spa_unit/src/com/android/settings/spa/network/SimOnboardingSelectSimTest.kt b/tests/spa_unit/src/com/android/settings/spa/network/SimOnboardingSelectSimTest.kt
index 385bc42..4655a87 100644
--- a/tests/spa_unit/src/com/android/settings/spa/network/SimOnboardingSelectSimTest.kt
+++ b/tests/spa_unit/src/com/android/settings/spa/network/SimOnboardingSelectSimTest.kt
@@ -35,6 +35,7 @@
import com.android.settings.R
import com.android.settings.network.SimOnboardingService
import com.android.settingslib.spa.testutils.waitUntilExists
+import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -142,6 +143,7 @@
}
@Test
+ @Ignore
fun simOnboardingSelectSimImpl_showItem_show3Items() {
mockSimOnboardingService.stub {
on { targetSubId }.doReturn(SUB_ID_1)
@@ -168,9 +170,6 @@
SimOnboardingSelectSimImpl(nextAction, cancelAction, mockSimOnboardingService)
}
}
-// composeTestRule.setContent {
-// SimOnboardingSelectSimImpl(nextAction, cancelAction, mockSimOnboardingService)
-// }
composeTestRule.onNodeWithText(DISPLAY_NAME_1).assertIsDisplayed()
composeTestRule.waitUntilExists(hasText(NUMBER_1))