diff options
28 files changed, 486 insertions, 597 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index 6078712fa7d1..7b97a65cf738 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -8332,7 +8332,7 @@ package android.app.admin { field public static final int RESULT_FAILURE_STORAGE_LIMIT_REACHED = 3; // 0x3 field public static final int RESULT_FAILURE_UNKNOWN = -1; // 0xffffffff field public static final int RESULT_POLICY_CLEARED = 2; // 0x2 - field public static final int RESULT_SUCCESS = 0; // 0x0 + field public static final int RESULT_POLICY_SET = 0; // 0x0 } public final class PreferentialNetworkServiceConfig implements android.os.Parcelable { diff --git a/core/java/android/app/admin/PolicyUpdateReceiver.java b/core/java/android/app/admin/PolicyUpdateReceiver.java index b5d92862a436..be13988d7c76 100644 --- a/core/java/android/app/admin/PolicyUpdateReceiver.java +++ b/core/java/android/app/admin/PolicyUpdateReceiver.java @@ -238,7 +238,7 @@ public abstract class PolicyUpdateReceiver extends BroadcastReceiver { * needed. * @param targetUser The {@link TargetUser} which this policy relates to. * @param policyUpdateResult Indicates whether the policy has been set successfully - * ({@link PolicyUpdateResult#RESULT_SUCCESS}) or the reason it + * ({@link PolicyUpdateResult#RESULT_POLICY_SET}) or the reason it * failed to apply (e.g. * {@link PolicyUpdateResult#RESULT_FAILURE_CONFLICTING_ADMIN_POLICY}, * etc). @@ -271,8 +271,8 @@ public abstract class PolicyUpdateReceiver extends BroadcastReceiver { * needed. * @param targetUser The {@link TargetUser} which this policy relates to. * @param policyUpdateResult Indicates the reason the policy value has changed - * (e.g. {@link PolicyUpdateResult#RESULT_SUCCESS} if the policy has - * changed to the value set by the admin, + * (e.g. {@link PolicyUpdateResult#RESULT_POLICY_SET} if the policy + * has changed to the value set by the admin, * {@link PolicyUpdateResult#RESULT_FAILURE_CONFLICTING_ADMIN_POLICY} * if the policy has changed because another admin has set a * conflicting policy, etc) diff --git a/core/java/android/app/admin/PolicyUpdateResult.java b/core/java/android/app/admin/PolicyUpdateResult.java index 7d7d91ae442c..414c6ed81ab9 100644 --- a/core/java/android/app/admin/PolicyUpdateResult.java +++ b/core/java/android/app/admin/PolicyUpdateResult.java @@ -39,7 +39,7 @@ public final class PolicyUpdateResult { * Result code to indicate that the policy has been changed to the desired value set by * the admin. */ - public static final int RESULT_SUCCESS = 0; + public static final int RESULT_POLICY_SET = 0; /** * Result code to indicate that the policy has not been enforced or has changed because another @@ -82,7 +82,7 @@ public final class PolicyUpdateResult { @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = { "RESULT_" }, value = { RESULT_FAILURE_UNKNOWN, - RESULT_SUCCESS, + RESULT_POLICY_SET, RESULT_FAILURE_CONFLICTING_ADMIN_POLICY, RESULT_POLICY_CLEARED, RESULT_FAILURE_STORAGE_LIMIT_REACHED, diff --git a/core/java/android/os/Parcelable.java b/core/java/android/os/Parcelable.java index a2b0486c1df5..f2b60a4e3988 100644 --- a/core/java/android/os/Parcelable.java +++ b/core/java/android/os/Parcelable.java @@ -16,8 +16,8 @@ package android.os; -import android.annotation.NonNull; import android.annotation.IntDef; +import android.annotation.NonNull; import android.annotation.SystemApi; import java.lang.annotation.Retention; @@ -26,8 +26,9 @@ import java.lang.annotation.RetentionPolicy; /** * Interface for classes whose instances can be written to * and restored from a {@link Parcel}. Classes implementing the Parcelable - * interface must also have a non-null static field called <code>CREATOR</code> - * of a type that implements the {@link Parcelable.Creator} interface. + * interface must also have a non-null public static field called + * <code>CREATOR</code> of a type that implements the {@link Parcelable.Creator} + * interface. * * <p>A typical implementation of Parcelable is:</p> * diff --git a/core/java/com/android/internal/inputmethod/ImeTracing.java b/core/java/com/android/internal/inputmethod/ImeTracing.java index e6a9b543dae2..db950123ddf9 100644 --- a/core/java/com/android/internal/inputmethod/ImeTracing.java +++ b/core/java/com/android/internal/inputmethod/ImeTracing.java @@ -62,11 +62,7 @@ public abstract class ImeTracing { if (isSystemProcess()) { sInstance = new ImeTracingServerImpl(); } else { - try { - sInstance = new ImeTracingClientImpl(); - } catch (RuntimeException e) { - Log.e(TAG, "Exception while creating ImeTracingClientImpl instance", e); - } + sInstance = new ImeTracingClientImpl(); } } return sInstance; diff --git a/packages/SettingsLib/res/values/arrays.xml b/packages/SettingsLib/res/values/arrays.xml index 502296029e23..3e2b800d5a2c 100644 --- a/packages/SettingsLib/res/values/arrays.xml +++ b/packages/SettingsLib/res/values/arrays.xml @@ -572,7 +572,7 @@ <!-- BatteryMeterView parameters --> <array name="batterymeter_color_levels"> - <item>15</item> + <item>20</item> <item>100</item> </array> <array name="batterymeter_color_values"> diff --git a/packages/SettingsLib/res/values/colors.xml b/packages/SettingsLib/res/values/colors.xml index 6b7e918ee5db..67139b510d85 100644 --- a/packages/SettingsLib/res/values/colors.xml +++ b/packages/SettingsLib/res/values/colors.xml @@ -43,4 +43,6 @@ <color name="qr_focused_corner_line_color">#ff1a73e8</color> <color name="qr_background_color">#b3ffffff</color> <!-- 70% white transparency --> <!-- End of QR code scanner colors --> + + <color name="batterymeter_saver_color">#FBBC04</color> </resources> diff --git a/packages/SettingsLib/src/com/android/settingslib/graph/ThemedBatteryDrawable.kt b/packages/SettingsLib/src/com/android/settingslib/graph/ThemedBatteryDrawable.kt index faea5b2c3e71..a03acc3a078c 100644 --- a/packages/SettingsLib/src/com/android/settingslib/graph/ThemedBatteryDrawable.kt +++ b/packages/SettingsLib/src/com/android/settingslib/graph/ThemedBatteryDrawable.kt @@ -135,7 +135,7 @@ open class ThemedBatteryDrawable(private val context: Context, frameColor: Int) } private val errorPaint = Paint(Paint.ANTI_ALIAS_FLAG).also { p -> - p.color = Utils.getColorStateListDefaultColor(context, R.color.batterymeter_plus_color) + p.color = Utils.getColorStateListDefaultColor(context, R.color.batterymeter_saver_color) p.alpha = 255 p.isDither = true p.strokeWidth = 0f @@ -244,10 +244,11 @@ open class ThemedBatteryDrawable(private val context: Context, frameColor: Int) c.drawPath(scaledBolt, fillColorStrokeProtection) } } else if (powerSaveEnabled) { - // If power save is enabled draw the perimeter path with colorError - c.drawPath(scaledErrorPerimeter, errorPaint) + // If power save is enabled draw the level path with colorError + c.drawPath(levelPath, errorPaint) // And draw the plus sign on top of the fill - c.drawPath(scaledPlus, errorPaint) + fillPaint.color = fillColor + c.drawPath(scaledPlus, fillPaint) } c.restore() } @@ -414,7 +415,7 @@ open class ThemedBatteryDrawable(private val context: Context, frameColor: Int) companion object { const val WIDTH = 12f const val HEIGHT = 20f - private const val CRITICAL_LEVEL = 15 + private const val CRITICAL_LEVEL = 20 // On a 12x20 grid, how wide to make the fill protection stroke. // Scales when our size changes private const val PROTECTION_STROKE_WIDTH = 3f diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index e40f3e7255d4..e12cd8c9a43b 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -1887,6 +1887,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call ? mCdsi.getReduceBrightColorsStrength() : -1); mTempBrightnessEvent.setPowerFactor(mPowerRequest.screenLowPowerBrightnessFactor); mTempBrightnessEvent.setWasShortTermModelActive(wasShortTermModelActive); + mTempBrightnessEvent.setAutomaticBrightnessEnabled(mUseAutoBrightness); // Temporary is what we use during slider interactions. We avoid logging those so that // we don't spam logcat when the slider is being used. boolean tempToTempTransition = @@ -1895,9 +1896,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call == BrightnessReason.REASON_TEMPORARY; if ((!mTempBrightnessEvent.equalsMainData(mLastBrightnessEvent) && !tempToTempTransition) || brightnessAdjustmentFlags != 0) { - float lastBrightness = mLastBrightnessEvent.getBrightness(); - mTempBrightnessEvent.setInitialBrightness(lastBrightness); - mTempBrightnessEvent.setAutomaticBrightnessEnabled(mUseAutoBrightness); + mTempBrightnessEvent.setInitialBrightness(mLastBrightnessEvent.getBrightness()); mLastBrightnessEvent.copyFrom(mTempBrightnessEvent); BrightnessEvent newEvent = new BrightnessEvent(mTempBrightnessEvent); // Adjustment flags (and user-set flag) only get added after the equality checks since diff --git a/services/core/java/com/android/server/display/DisplayPowerController2.java b/services/core/java/com/android/server/display/DisplayPowerController2.java index 7b1a24680885..fbc354eb4c11 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController2.java +++ b/services/core/java/com/android/server/display/DisplayPowerController2.java @@ -1597,6 +1597,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal mTempBrightnessEvent.setWasShortTermModelActive(wasShortTermModelActive); mTempBrightnessEvent.setDisplayBrightnessStrategyName(displayBrightnessState .getDisplayBrightnessStrategyName()); + mTempBrightnessEvent.setAutomaticBrightnessEnabled(mUseAutoBrightness); // Temporary is what we use during slider interactions. We avoid logging those so that // we don't spam logcat when the slider is being used. boolean tempToTempTransition = @@ -1605,9 +1606,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal == BrightnessReason.REASON_TEMPORARY; if ((!mTempBrightnessEvent.equalsMainData(mLastBrightnessEvent) && !tempToTempTransition) || brightnessAdjustmentFlags != 0) { - float lastBrightness = mLastBrightnessEvent.getBrightness(); - mTempBrightnessEvent.setInitialBrightness(lastBrightness); - mTempBrightnessEvent.setAutomaticBrightnessEnabled(mUseAutoBrightness); + mTempBrightnessEvent.setInitialBrightness(mLastBrightnessEvent.getBrightness()); mLastBrightnessEvent.copyFrom(mTempBrightnessEvent); BrightnessEvent newEvent = new BrightnessEvent(mTempBrightnessEvent); // Adjustment flags (and user-set flag) only get added after the equality checks since diff --git a/services/core/java/com/android/server/display/brightness/BrightnessEvent.java b/services/core/java/com/android/server/display/brightness/BrightnessEvent.java index aff80de0011d..a3bca9accb81 100644 --- a/services/core/java/com/android/server/display/brightness/BrightnessEvent.java +++ b/services/core/java/com/android/server/display/brightness/BrightnessEvent.java @@ -142,8 +142,6 @@ public final class BrightnessEvent { && Float.floatToRawIntBits(mLux) == Float.floatToRawIntBits(that.mLux) && Float.floatToRawIntBits(mPreThresholdLux) == Float.floatToRawIntBits(that.mPreThresholdLux) - && Float.floatToRawIntBits(mInitialBrightness) - == Float.floatToRawIntBits(that.mInitialBrightness) && Float.floatToRawIntBits(mBrightness) == Float.floatToRawIntBits(that.mBrightness) && Float.floatToRawIntBits(mRecommendedBrightness) diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 53b03d58beae..c2e8df1dd70a 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -2055,8 +2055,8 @@ public class NotificationManagerService extends SystemService { // TODO - replace these methods with new fields in the VisibleForTesting constructor @VisibleForTesting - void setAudioManager(AudioManager audioMananger) { - mAudioManager = audioMananger; + void setAudioManager(AudioManager audioManager) { + mAudioManager = audioManager; } @VisibleForTesting @@ -5772,7 +5772,7 @@ public class NotificationManagerService extends SystemService { switch (report) { case REPORT_REMOTE_VIEWS: Slog.e(TAG, "pullStats REPORT_REMOTE_VIEWS from: " - + startMs + " wtih " + doAgg); + + startMs + " with " + doAgg); PulledStats stats = mUsageStats.remoteViewStats(startMs, doAgg); if (stats != null) { out.add(stats.toParcelFileDescriptor(report)); @@ -6470,7 +6470,7 @@ public class NotificationManagerService extends SystemService { } } - // Don't allow client applications to cancel foreground service notis or autobundled + // Don't allow client applications to cancel foreground service notifs or autobundled // summaries. final int mustNotHaveFlags = isCallingUidSystem() ? 0 : (FLAG_FOREGROUND_SERVICE | FLAG_AUTOGROUP_SUMMARY); @@ -8342,7 +8342,7 @@ public class NotificationManagerService extends SystemService { Thread.sleep(waitMs); } catch (InterruptedException e) { } // Notifications might be canceled before it actually vibrates due to waitMs, - // so need to check the notification still valide for vibrate. + // so need to check that the notification is still valid for vibrate. synchronized (mNotificationLock) { if (mNotificationsByKey.get(record.getKey()) != null) { if (record.getKey().equals(mVibrateNotificationKey)) { @@ -11696,7 +11696,7 @@ public class NotificationManagerService extends SystemService { } } else if (PRIORITY_ARG.equals(a)) { // Bugreport will call the service twice with priority arguments, first to dump - // critical sections and then non critical ones. Set approriate filters + // critical sections and then non critical ones. Set appropriate filters // to generate the desired data. if (ai < args.length - 1) { ai++; diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java index 59af58fb0dfb..4bafbc73a96b 100644 --- a/services/core/java/com/android/server/notification/PreferencesHelper.java +++ b/services/core/java/com/android/server/notification/PreferencesHelper.java @@ -135,7 +135,6 @@ public class PreferencesHelper implements RankingConfig { private static final String ATT_SHOW_BADGE = "show_badge"; private static final String ATT_APP_USER_LOCKED_FIELDS = "app_user_locked_fields"; private static final String ATT_ENABLED = "enabled"; - private static final String ATT_USER_ALLOWED = "allowed"; private static final String ATT_HIDE_SILENT = "hide_gentle"; private static final String ATT_SENT_INVALID_MESSAGE = "sent_invalid_msg"; private static final String ATT_SENT_VALID_MESSAGE = "sent_valid_msg"; @@ -363,15 +362,12 @@ public class PreferencesHelper implements RankingConfig { String delegateName = XmlUtils.readStringAttribute(parser, ATT_NAME); boolean delegateEnabled = parser.getAttributeBoolean( null, ATT_ENABLED, Delegate.DEFAULT_ENABLED); - boolean userAllowed = parser.getAttributeBoolean( - null, ATT_USER_ALLOWED, Delegate.DEFAULT_USER_ALLOWED); Delegate d = null; if (delegateId != UNKNOWN_UID && !TextUtils.isEmpty(delegateName)) { - d = new Delegate(delegateName, delegateId, delegateEnabled, userAllowed); + d = new Delegate(delegateName, delegateId, delegateEnabled); } r.delegate = d; } - } try { @@ -640,9 +636,6 @@ public class PreferencesHelper implements RankingConfig { if (r.delegate.mEnabled != Delegate.DEFAULT_ENABLED) { out.attributeBoolean(null, ATT_ENABLED, r.delegate.mEnabled); } - if (r.delegate.mUserAllowed != Delegate.DEFAULT_USER_ALLOWED) { - out.attributeBoolean(null, ATT_USER_ALLOWED, r.delegate.mUserAllowed); - } out.endTag(null, TAG_DELEGATE); } @@ -725,10 +718,17 @@ public class PreferencesHelper implements RankingConfig { @Override public void setShowBadge(String packageName, int uid, boolean showBadge) { + boolean changed = false; synchronized (mPackagePreferences) { - getOrCreatePackagePreferencesLocked(packageName, uid).showBadge = showBadge; + PackagePreferences pkgPrefs = getOrCreatePackagePreferencesLocked(packageName, uid); + if (pkgPrefs.showBadge != showBadge) { + pkgPrefs.showBadge = showBadge; + changed = true; + } + } + if (changed) { + updateConfig(); } - updateConfig(); } public boolean isInInvalidMsgState(String packageName, int uid) { @@ -985,7 +985,9 @@ public class PreferencesHelper implements RankingConfig { needsPolicyFileChange = true; } - updateConfig(); + if (needsPolicyFileChange) { + updateConfig(); + } if (needsPolicyFileChange && !wasUndeleted) { mNotificationChannelLogger.logNotificationChannelModified(existing, uid, pkg, previousLoggingImportance, false); @@ -1072,6 +1074,7 @@ public class PreferencesHelper implements RankingConfig { boolean fromUser) { Objects.requireNonNull(updatedChannel); Objects.requireNonNull(updatedChannel.getId()); + boolean changed = false; boolean needsDndChange = false; synchronized (mPackagePreferences) { PackagePreferences r = getOrCreatePackagePreferencesLocked(pkg, uid); @@ -1105,6 +1108,7 @@ public class PreferencesHelper implements RankingConfig { ? Notification.PRIORITY_MAX : Notification.PRIORITY_DEFAULT; r.visibility = updatedChannel.getLockscreenVisibility(); r.showBadge = updatedChannel.canShowBadge(); + changed = true; } if (!channel.equals(updatedChannel)) { @@ -1113,17 +1117,21 @@ public class PreferencesHelper implements RankingConfig { .setSubtype(fromUser ? 1 : 0)); mNotificationChannelLogger.logNotificationChannelModified(updatedChannel, uid, pkg, NotificationChannelLogger.getLoggingImportance(channel), fromUser); + changed = true; } if (updatedChannel.canBypassDnd() != mAreChannelsBypassingDnd || channel.getImportance() != updatedChannel.getImportance()) { needsDndChange = true; + changed = true; } } if (needsDndChange) { updateChannelsBypassingDnd(); } - updateConfig(); + if (changed) { + updateConfig(); + } } @Override @@ -1788,7 +1796,7 @@ public class PreferencesHelper implements RankingConfig { if (prefs == null || prefs.delegate == null) { return null; } - if (!prefs.delegate.mUserAllowed || !prefs.delegate.mEnabled) { + if (!prefs.delegate.mEnabled) { return null; } return prefs.delegate.mPkg; @@ -1802,46 +1810,20 @@ public class PreferencesHelper implements RankingConfig { String delegatePkg, int delegateUid) { synchronized (mPackagePreferences) { PackagePreferences prefs = getOrCreatePackagePreferencesLocked(sourcePkg, sourceUid); - - boolean userAllowed = prefs.delegate == null || prefs.delegate.mUserAllowed; - Delegate delegate = new Delegate(delegatePkg, delegateUid, true, userAllowed); - prefs.delegate = delegate; + prefs.delegate = new Delegate(delegatePkg, delegateUid, true); } - updateConfig(); } /** * Used by an app to turn off its notification delegate. */ public void revokeNotificationDelegate(String sourcePkg, int sourceUid) { - boolean changed = false; synchronized (mPackagePreferences) { PackagePreferences prefs = getPackagePreferencesLocked(sourcePkg, sourceUid); if (prefs != null && prefs.delegate != null) { prefs.delegate.mEnabled = false; - changed = true; - } - } - if (changed) { - updateConfig(); - } - } - - /** - * Toggles whether an app can have a notification delegate on behalf of a user. - */ - public void toggleNotificationDelegate(String sourcePkg, int sourceUid, boolean userAllowed) { - boolean changed = false; - synchronized (mPackagePreferences) { - PackagePreferences prefs = getPackagePreferencesLocked(sourcePkg, sourceUid); - if (prefs != null && prefs.delegate != null) { - prefs.delegate.mUserAllowed = userAllowed; - changed = true; } } - if (changed) { - updateConfig(); - } } /** @@ -2726,17 +2708,15 @@ public class PreferencesHelper implements RankingConfig { private static class Delegate { static final boolean DEFAULT_ENABLED = true; - static final boolean DEFAULT_USER_ALLOWED = true; - String mPkg; - int mUid = UNKNOWN_UID; - boolean mEnabled = DEFAULT_ENABLED; - boolean mUserAllowed = DEFAULT_USER_ALLOWED; - Delegate(String pkg, int uid, boolean enabled, boolean userAllowed) { + final String mPkg; + final int mUid; + boolean mEnabled; + + Delegate(String pkg, int uid, boolean enabled) { mPkg = pkg; mUid = uid; mEnabled = enabled; - mUserAllowed = userAllowed; } public boolean isAllowed(String pkg, int uid) { @@ -2745,7 +2725,7 @@ public class PreferencesHelper implements RankingConfig { } return pkg.equals(mPkg) && uid == mUid - && (mUserAllowed && mEnabled); + && mEnabled; } } } diff --git a/services/core/java/com/android/server/notification/ValidateNotificationPeople.java b/services/core/java/com/android/server/notification/ValidateNotificationPeople.java index 5e0a18039152..8417049bf297 100644 --- a/services/core/java/com/android/server/notification/ValidateNotificationPeople.java +++ b/services/core/java/com/android/server/notification/ValidateNotificationPeople.java @@ -62,7 +62,7 @@ import java.util.concurrent.TimeUnit; public class ValidateNotificationPeople implements NotificationSignalExtractor { // Using a shorter log tag since setprop has a limit of 32chars on variable name. private static final String TAG = "ValidateNoPeople"; - private static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE);; + private static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE); private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private static final boolean ENABLE_PEOPLE_VALIDATOR = true; @@ -105,12 +105,13 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor { private int mEvictionCount; private NotificationUsageStats mUsageStats; + @Override public void initialize(Context context, NotificationUsageStats usageStats) { if (DEBUG) Slog.d(TAG, "Initializing " + getClass().getSimpleName() + "."); mUserToContextMap = new ArrayMap<>(); mBaseContext = context; mUsageStats = usageStats; - mPeopleCache = new LruCache<String, LookupResult>(PEOPLE_CACHE_SIZE); + mPeopleCache = new LruCache<>(PEOPLE_CACHE_SIZE); mEnabled = ENABLE_PEOPLE_VALIDATOR && 1 == Settings.Global.getInt( mBaseContext.getContentResolver(), SETTING_ENABLE_PEOPLE_VALIDATOR, 1); if (mEnabled) { @@ -134,7 +135,7 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor { // For tests: just do the setting of various local variables without actually doing work @VisibleForTesting protected void initForTests(Context context, NotificationUsageStats usageStats, - LruCache peopleCache) { + LruCache<String, LookupResult> peopleCache) { mUserToContextMap = new ArrayMap<>(); mBaseContext = context; mUsageStats = usageStats; @@ -142,6 +143,7 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor { mEnabled = true; } + @Override public RankingReconsideration process(NotificationRecord record) { if (!mEnabled) { if (VERBOSE) Slog.i(TAG, "disabled"); @@ -272,7 +274,7 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor { } if (VERBOSE) Slog.i(TAG, "Validating: " + key + " for " + context.getUserId()); - final LinkedList<String> pendingLookups = new LinkedList<String>(); + final LinkedList<String> pendingLookups = new LinkedList<>(); int personIdx = 0; for (String handle : people) { if (TextUtils.isEmpty(handle)) continue; @@ -320,7 +322,6 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor { return Integer.toString(userId) + ":" + handle; } - // VisibleForTesting public static String[] getExtraPeople(Bundle extras) { String[] peopleList = getExtraPeopleForKey(extras, Notification.EXTRA_PEOPLE_LIST); String[] legacyPeople = getExtraPeopleForKey(extras, Notification.EXTRA_PEOPLE); @@ -417,101 +418,6 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor { return null; } - private LookupResult resolvePhoneContact(Context context, final String number) { - Uri phoneUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, - Uri.encode(number)); - return searchContacts(context, phoneUri); - } - - private LookupResult resolveEmailContact(Context context, final String email) { - Uri numberUri = Uri.withAppendedPath( - ContactsContract.CommonDataKinds.Email.CONTENT_LOOKUP_URI, - Uri.encode(email)); - return searchContacts(context, numberUri); - } - - @VisibleForTesting - LookupResult searchContacts(Context context, Uri lookupUri) { - LookupResult lookupResult = new LookupResult(); - final Uri corpLookupUri = - ContactsContract.Contacts.createCorpLookupUriFromEnterpriseLookupUri(lookupUri); - if (corpLookupUri == null) { - addContacts(lookupResult, context, lookupUri); - } else { - addWorkContacts(lookupResult, context, corpLookupUri); - } - return lookupResult; - } - - @VisibleForTesting - // Performs a contacts search using searchContacts, and then follows up by looking up - // any phone numbers associated with the resulting contact information and merge those - // into the lookup result as well. Will have no additional effect if the contact does - // not have any phone numbers. - LookupResult searchContactsAndLookupNumbers(Context context, Uri lookupUri) { - LookupResult lookupResult = searchContacts(context, lookupUri); - String phoneLookupKey = lookupResult.getPhoneLookupKey(); - if (phoneLookupKey != null) { - String selection = Contacts.LOOKUP_KEY + " = ?"; - String[] selectionArgs = new String[] { phoneLookupKey }; - try (Cursor cursor = context.getContentResolver().query( - ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PHONE_LOOKUP_PROJECTION, - selection, selectionArgs, /* sortOrder= */ null)) { - if (cursor == null) { - Slog.w(TAG, "Cursor is null when querying contact phone number."); - return lookupResult; - } - - while (cursor.moveToNext()) { - lookupResult.mergePhoneNumber(cursor); - } - } catch (Throwable t) { - Slog.w(TAG, "Problem getting content resolver or querying phone numbers.", t); - } - } - return lookupResult; - } - - private void addWorkContacts(LookupResult lookupResult, Context context, Uri corpLookupUri) { - final int workUserId = findWorkUserId(context); - if (workUserId == -1) { - Slog.w(TAG, "Work profile user ID not found for work contact: " + corpLookupUri); - return; - } - final Uri corpLookupUriWithUserId = - ContentProvider.maybeAddUserId(corpLookupUri, workUserId); - addContacts(lookupResult, context, corpLookupUriWithUserId); - } - - /** Returns the user ID of the managed profile or -1 if none is found. */ - private int findWorkUserId(Context context) { - final UserManager userManager = context.getSystemService(UserManager.class); - final int[] profileIds = - userManager.getProfileIds(context.getUserId(), /* enabledOnly= */ true); - for (int profileId : profileIds) { - if (userManager.isManagedProfile(profileId)) { - return profileId; - } - } - return -1; - } - - /** Modifies the given lookup result to add contacts found at the given URI. */ - private void addContacts(LookupResult lookupResult, Context context, Uri uri) { - try (Cursor c = context.getContentResolver().query( - uri, LOOKUP_PROJECTION, null, null, null)) { - if (c == null) { - Slog.w(TAG, "Null cursor from contacts query."); - return; - } - while (c.moveToNext()) { - lookupResult.mergeContact(c); - } - } catch (Throwable t) { - Slog.w(TAG, "Problem getting content resolver or performing contacts query.", t); - } - } - @VisibleForTesting protected static class LookupResult { private static final long CONTACT_REFRESH_MILLIS = 60 * 60 * 1000; // 1hr @@ -619,19 +525,18 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor { } } - private class PeopleRankingReconsideration extends RankingReconsideration { + @VisibleForTesting + class PeopleRankingReconsideration extends RankingReconsideration { private final LinkedList<String> mPendingLookups; private final Context mContext; - // Amount of time to wait for a result from the contacts db before rechecking affinity. - private static final long LOOKUP_TIME = 1000; private float mContactAffinity = NONE; private ArraySet<String> mPhoneNumbers = null; private NotificationRecord mRecord; private PeopleRankingReconsideration(Context context, String key, LinkedList<String> pendingLookups) { - super(key, LOOKUP_TIME); + super(key); mContext = context; mPendingLookups = pendingLookups; } @@ -642,7 +547,7 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor { long timeStartMs = System.currentTimeMillis(); for (final String handle: mPendingLookups) { final String cacheKey = getCacheKey(mContext.getUserId(), handle); - LookupResult lookupResult = null; + LookupResult lookupResult; boolean cacheHit = false; synchronized (mPeopleCache) { lookupResult = mPeopleCache.get(cacheKey); @@ -703,6 +608,102 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor { } } + private static LookupResult resolvePhoneContact(Context context, final String number) { + Uri phoneUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, + Uri.encode(number)); + return searchContacts(context, phoneUri); + } + + private static LookupResult resolveEmailContact(Context context, final String email) { + Uri numberUri = Uri.withAppendedPath( + ContactsContract.CommonDataKinds.Email.CONTENT_LOOKUP_URI, + Uri.encode(email)); + return searchContacts(context, numberUri); + } + + @VisibleForTesting + static LookupResult searchContacts(Context context, Uri lookupUri) { + LookupResult lookupResult = new LookupResult(); + final Uri corpLookupUri = + ContactsContract.Contacts.createCorpLookupUriFromEnterpriseLookupUri(lookupUri); + if (corpLookupUri == null) { + addContacts(lookupResult, context, lookupUri); + } else { + addWorkContacts(lookupResult, context, corpLookupUri); + } + return lookupResult; + } + + @VisibleForTesting + // Performs a contacts search using searchContacts, and then follows up by looking up + // any phone numbers associated with the resulting contact information and merge those + // into the lookup result as well. Will have no additional effect if the contact does + // not have any phone numbers. + static LookupResult searchContactsAndLookupNumbers(Context context, Uri lookupUri) { + LookupResult lookupResult = searchContacts(context, lookupUri); + String phoneLookupKey = lookupResult.getPhoneLookupKey(); + if (phoneLookupKey != null) { + String selection = Contacts.LOOKUP_KEY + " = ?"; + String[] selectionArgs = new String[] { phoneLookupKey }; + try (Cursor cursor = context.getContentResolver().query( + ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PHONE_LOOKUP_PROJECTION, + selection, selectionArgs, /* sortOrder= */ null)) { + if (cursor == null) { + Slog.w(TAG, "Cursor is null when querying contact phone number."); + return lookupResult; + } + + while (cursor.moveToNext()) { + lookupResult.mergePhoneNumber(cursor); + } + } catch (Throwable t) { + Slog.w(TAG, "Problem getting content resolver or querying phone numbers.", t); + } + } + return lookupResult; + } + + private static void addWorkContacts(LookupResult lookupResult, Context context, + Uri corpLookupUri) { + final int workUserId = findWorkUserId(context); + if (workUserId == -1) { + Slog.w(TAG, "Work profile user ID not found for work contact: " + corpLookupUri); + return; + } + final Uri corpLookupUriWithUserId = + ContentProvider.maybeAddUserId(corpLookupUri, workUserId); + addContacts(lookupResult, context, corpLookupUriWithUserId); + } + + /** Returns the user ID of the managed profile or -1 if none is found. */ + private static int findWorkUserId(Context context) { + final UserManager userManager = context.getSystemService(UserManager.class); + final int[] profileIds = + userManager.getProfileIds(context.getUserId(), /* enabledOnly= */ true); + for (int profileId : profileIds) { + if (userManager.isManagedProfile(profileId)) { + return profileId; + } + } + return -1; + } + + /** Modifies the given lookup result to add contacts found at the given URI. */ + private static void addContacts(LookupResult lookupResult, Context context, Uri uri) { + try (Cursor c = context.getContentResolver().query( + uri, LOOKUP_PROJECTION, null, null, null)) { + if (c == null) { + Slog.w(TAG, "Null cursor from contacts query."); + return; + } + while (c.moveToNext()) { + lookupResult.mergeContact(c); + } + } catch (Throwable t) { + Slog.w(TAG, "Problem getting content resolver or performing contacts query.", t); + } + } + @Override public void applyChangesLocked(NotificationRecord operand) { float affinityBound = operand.getContactAffinity(); diff --git a/services/core/java/com/android/server/wm/WindowManagerShellCommand.java b/services/core/java/com/android/server/wm/WindowManagerShellCommand.java index cfb3c6cc782b..8c2dd2d2f5e2 100644 --- a/services/core/java/com/android/server/wm/WindowManagerShellCommand.java +++ b/services/core/java/com/android/server/wm/WindowManagerShellCommand.java @@ -42,6 +42,7 @@ import android.provider.Settings; import android.util.DisplayMetrics; import android.util.Pair; import android.view.Display; +import android.view.IWindow; import android.view.IWindowManager; import android.view.ViewDebug; @@ -569,6 +570,22 @@ public class WindowManagerShellCommand extends ShellCommand { return 0; } + private void dumpLocalWindowAsync(IWindow client, ParcelFileDescriptor pfd) { + // Make it asynchronous to avoid writer from being blocked + // by waiting for the buffer to be consumed in the same process. + IoThread.getExecutor().execute(() -> { + synchronized (mInternal.mGlobalLock) { + try { + client.executeCommand(ViewDebug.REMOTE_COMMAND_DUMP_ENCODED, null, pfd); + } catch (Exception e) { + // Ignore RemoteException for local call. Just print trace for other + // exceptions caused by RC with tolerable low possibility. + e.printStackTrace(); + } + } + }); + } + private int runDumpVisibleWindowViews(PrintWriter pw) { if (!mInternal.checkCallingPermission(android.Manifest.permission.DUMP, "runDumpVisibleWindowViews()")) { @@ -591,16 +608,7 @@ public class WindowManagerShellCommand extends ShellCommand { pipe = new ByteTransferPipe(); final ParcelFileDescriptor pfd = pipe.getWriteFd(); if (w.isClientLocal()) { - // Make it asynchronous to avoid writer from being blocked - // by waiting for the buffer to be consumed in the same process. - IoThread.getExecutor().execute(() -> { - try { - w.mClient.executeCommand( - ViewDebug.REMOTE_COMMAND_DUMP_ENCODED, null, pfd); - } catch (RemoteException e) { - // Ignore for local call. - } - }); + dumpLocalWindowAsync(w.mClient, pfd); } else { w.mClient.executeCommand( ViewDebug.REMOTE_COMMAND_DUMP_ENCODED, null, pfd); diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyEngine.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyEngine.java index c7f99521f669..ec101cd0d1fb 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyEngine.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyEngine.java @@ -18,9 +18,9 @@ package com.android.server.devicepolicy; import static android.app.admin.PolicyUpdateResult.RESULT_FAILURE_CONFLICTING_ADMIN_POLICY; import static android.app.admin.PolicyUpdateResult.RESULT_POLICY_CLEARED; -import static android.app.admin.PolicyUpdateResult.RESULT_SUCCESS; import static android.app.admin.PolicyUpdateReceiver.EXTRA_POLICY_TARGET_USER_ID; import static android.app.admin.PolicyUpdateReceiver.EXTRA_POLICY_UPDATE_RESULT_KEY; +import static android.app.admin.PolicyUpdateResult.RESULT_POLICY_SET; import static android.content.pm.UserProperties.INHERIT_DEVICE_POLICY_FROM_PARENT; import static android.provider.DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER; @@ -167,7 +167,8 @@ final class DevicePolicyEngine { enforcingAdmin, policyDefinition, // TODO: we're always sending this for now, should properly handle errors. - policyEnforced ? RESULT_SUCCESS : RESULT_FAILURE_CONFLICTING_ADMIN_POLICY, + policyEnforced + ? RESULT_POLICY_SET : RESULT_FAILURE_CONFLICTING_ADMIN_POLICY, userId); } @@ -400,7 +401,7 @@ final class DevicePolicyEngine { enforcingAdmin, policyDefinition, // TODO: we're always sending this for now, should properly handle errors. - policyApplied ? RESULT_SUCCESS : RESULT_FAILURE_CONFLICTING_ADMIN_POLICY, + policyApplied ? RESULT_POLICY_SET : RESULT_FAILURE_CONFLICTING_ADMIN_POLICY, UserHandle.USER_ALL); } @@ -792,7 +793,7 @@ final class DevicePolicyEngine { int result = Objects.equals( policyState.getPoliciesSetByAdmins().get(admin), policyState.getCurrentResolvedPolicy()) - ? RESULT_SUCCESS : RESULT_FAILURE_CONFLICTING_ADMIN_POLICY; + ? RESULT_POLICY_SET : RESULT_FAILURE_CONFLICTING_ADMIN_POLICY; maybeSendOnPolicyChanged( admin, policyDefinition, result, userId); } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java index 79f69ee94a62..06bcb9134c07 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java @@ -63,6 +63,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -70,6 +71,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import android.app.AppOpsManager; @@ -161,7 +163,6 @@ public class PreferencesHelperTest extends UiServiceTestCase { private static final String SYSTEM_PKG = "android"; private static final int SYSTEM_UID = 1000; private static final UserHandle USER2 = UserHandle.of(10); - private static final String TEST_CHANNEL_ID = "test_channel_id"; private static final String TEST_AUTHORITY = "test"; private static final Uri SOUND_URI = Uri.parse("content://" + TEST_AUTHORITY + "/internal/audio/media/10"); @@ -284,9 +285,9 @@ public class PreferencesHelperTest extends UiServiceTestCase { anyString(), eq(null), anyString())).thenReturn(MODE_DEFAULT); ArrayMap<Pair<Integer, String>, Pair<Boolean, Boolean>> appPermissions = new ArrayMap<>(); - appPermissions.put(new Pair(UID_P, PKG_P), new Pair(true, false)); - appPermissions.put(new Pair(UID_O, PKG_O), new Pair(true, false)); - appPermissions.put(new Pair(UID_N_MR1, PKG_N_MR1), new Pair(true, false)); + appPermissions.put(new Pair<>(UID_P, PKG_P), new Pair<>(true, false)); + appPermissions.put(new Pair<>(UID_O, PKG_O), new Pair<>(true, false)); + appPermissions.put(new Pair<>(UID_N_MR1, PKG_N_MR1), new Pair<>(true, false)); when(mPermissionHelper.getNotificationPermissionValues(USER_SYSTEM)) .thenReturn(appPermissions); @@ -422,8 +423,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertTrue(mHelper.createNotificationChannel(package10, uid10, channel10, true, false)); ArrayMap<Pair<Integer, String>, Pair<Boolean, Boolean>> appPermissions = new ArrayMap<>(); - appPermissions.put(new Pair(uid0, package0), new Pair(false, false)); - appPermissions.put(new Pair(uid10, package10), new Pair(true, false)); + appPermissions.put(new Pair<>(uid0, package0), new Pair<>(false, false)); + appPermissions.put(new Pair<>(uid10, package10), new Pair<>(true, false)); when(mPermissionHelper.getNotificationPermissionValues(10)) .thenReturn(appPermissions); @@ -454,7 +455,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertTrue(mHelper.createNotificationChannel(package0, uid0, channel0, true, false)); ArrayMap<Pair<Integer, String>, Pair<Boolean, Boolean>> appPermissions = new ArrayMap<>(); - appPermissions.put(new Pair(uid0, package0), new Pair(true, false)); + appPermissions.put(new Pair<>(uid0, package0), new Pair<>(true, false)); when(mPermissionHelper.getNotificationPermissionValues(USER_SYSTEM)) .thenReturn(appPermissions); @@ -1009,11 +1010,11 @@ public class PreferencesHelperTest extends UiServiceTestCase { mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory, false); ArrayMap<Pair<Integer, String>, Pair<Boolean, Boolean>> appPermissions = new ArrayMap<>(); - appPermissions.put(new Pair(1, "first"), new Pair(true, false)); - appPermissions.put(new Pair(3, "third"), new Pair(false, false)); - appPermissions.put(new Pair(UID_P, PKG_P), new Pair(true, false)); - appPermissions.put(new Pair(UID_O, PKG_O), new Pair(false, false)); - appPermissions.put(new Pair(UID_N_MR1, PKG_N_MR1), new Pair(true, false)); + appPermissions.put(new Pair<>(1, "first"), new Pair<>(true, false)); + appPermissions.put(new Pair<>(3, "third"), new Pair<>(false, false)); + appPermissions.put(new Pair<>(UID_P, PKG_P), new Pair<>(true, false)); + appPermissions.put(new Pair<>(UID_O, PKG_O), new Pair<>(false, false)); + appPermissions.put(new Pair<>(UID_N_MR1, PKG_N_MR1), new Pair<>(true, false)); when(mPermissionHelper.getNotificationPermissionValues(USER_SYSTEM)) .thenReturn(appPermissions); @@ -1089,11 +1090,11 @@ public class PreferencesHelperTest extends UiServiceTestCase { mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory, false); ArrayMap<Pair<Integer, String>, Pair<Boolean, Boolean>> appPermissions = new ArrayMap<>(); - appPermissions.put(new Pair(1, "first"), new Pair(true, false)); - appPermissions.put(new Pair(3, "third"), new Pair(false, false)); - appPermissions.put(new Pair(UID_P, PKG_P), new Pair(true, false)); - appPermissions.put(new Pair(UID_O, PKG_O), new Pair(false, false)); - appPermissions.put(new Pair(UID_N_MR1, PKG_N_MR1), new Pair(true, false)); + appPermissions.put(new Pair<>(1, "first"), new Pair<>(true, false)); + appPermissions.put(new Pair<>(3, "third"), new Pair<>(false, false)); + appPermissions.put(new Pair<>(UID_P, PKG_P), new Pair<>(true, false)); + appPermissions.put(new Pair<>(UID_O, PKG_O), new Pair<>(false, false)); + appPermissions.put(new Pair<>(UID_N_MR1, PKG_N_MR1), new Pair<>(true, false)); when(mPermissionHelper.getNotificationPermissionValues(USER_SYSTEM)) .thenReturn(appPermissions); @@ -1175,8 +1176,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory, false); ArrayMap<Pair<Integer, String>, Pair<Boolean, Boolean>> appPermissions = new ArrayMap<>(); - appPermissions.put(new Pair(UID_P, PKG_P), new Pair(true, false)); - appPermissions.put(new Pair(UID_O, PKG_O), new Pair(false, false)); + appPermissions.put(new Pair<>(UID_P, PKG_P), new Pair<>(true, false)); + appPermissions.put(new Pair<>(UID_O, PKG_O), new Pair<>(false, false)); when(mPermissionHelper.getNotificationPermissionValues(USER_SYSTEM)) .thenReturn(appPermissions); @@ -1254,11 +1255,11 @@ public class PreferencesHelperTest extends UiServiceTestCase { mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory, false); ArrayMap<Pair<Integer, String>, Pair<Boolean, Boolean>> appPermissions = new ArrayMap<>(); - appPermissions.put(new Pair(1, "first"), new Pair(true, false)); - appPermissions.put(new Pair(3, "third"), new Pair(false, false)); - appPermissions.put(new Pair(UID_P, PKG_P), new Pair(true, false)); - appPermissions.put(new Pair(UID_O, PKG_O), new Pair(false, false)); - appPermissions.put(new Pair(UID_N_MR1, PKG_N_MR1), new Pair(true, false)); + appPermissions.put(new Pair<>(1, "first"), new Pair<>(true, false)); + appPermissions.put(new Pair<>(3, "third"), new Pair<>(false, false)); + appPermissions.put(new Pair<>(UID_P, PKG_P), new Pair<>(true, false)); + appPermissions.put(new Pair<>(UID_O, PKG_O), new Pair<>(false, false)); + appPermissions.put(new Pair<>(UID_N_MR1, PKG_N_MR1), new Pair<>(true, false)); when(mPermissionHelper.getNotificationPermissionValues(USER_SYSTEM)) .thenReturn(appPermissions); @@ -1372,7 +1373,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { @Test public void testBackupRestoreXml_withNullSoundUri() throws Exception { ArrayMap<Pair<Integer, String>, Pair<Boolean, Boolean>> appPermissions = new ArrayMap<>(); - appPermissions.put(new Pair(UID_N_MR1, PKG_N_MR1), new Pair(true, false)); + appPermissions.put(new Pair<>(UID_N_MR1, PKG_N_MR1), new Pair<>(true, false)); when(mPermissionHelper.getNotificationPermissionValues(USER_SYSTEM)) .thenReturn(appPermissions); @@ -2605,10 +2606,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { @Test public void testClearData() { - ArraySet<String> pkg = new ArraySet<>(); - pkg.add(PKG_O); ArraySet<Pair<String, Integer>> pkgPair = new ArraySet<>(); - pkgPair.add(new Pair(PKG_O, UID_O)); + pkgPair.add(new Pair<>(PKG_O, UID_O)); mHelper.createNotificationChannel(PKG_O, UID_O, getChannel(), true, false); mHelper.createNotificationChannelGroup( PKG_O, UID_O, new NotificationChannelGroup("1", "bye"), true); @@ -2879,10 +2878,10 @@ public class PreferencesHelperTest extends UiServiceTestCase { // package permissions map to be passed in ArrayMap<Pair<Integer, String>, Pair<Boolean, Boolean>> appPermissions = new ArrayMap<>(); - appPermissions.put(new Pair(1, "first"), new Pair(true, false)); // not in local prefs - appPermissions.put(new Pair(3, "third"), new Pair(false, false)); // not in local prefs - appPermissions.put(new Pair(UID_P, PKG_P), new Pair(true, false)); // in local prefs - appPermissions.put(new Pair(UID_O, PKG_O), new Pair(false, false)); // in local prefs + appPermissions.put(new Pair<>(1, "first"), new Pair<>(true, false)); // not in local prefs + appPermissions.put(new Pair<>(3, "third"), new Pair<>(false, false)); // not in local prefs + appPermissions.put(new Pair<>(UID_P, PKG_P), new Pair<>(true, false)); // in local prefs + appPermissions.put(new Pair<>(UID_O, PKG_O), new Pair<>(false, false)); // in local prefs NotificationChannel channel1 = new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH); @@ -2901,15 +2900,15 @@ public class PreferencesHelperTest extends UiServiceTestCase { ArrayMap<Pair<Integer, String>, String> expected = new ArrayMap<>(); // packages that only exist via the app permissions; should be present - expected.put(new Pair(UserHandle.getUserId(1), "first"), "DEFAULT"); - expected.put(new Pair(UserHandle.getUserId(3), "third"), "NONE"); + expected.put(new Pair<>(UserHandle.getUserId(1), "first"), "DEFAULT"); + expected.put(new Pair<>(UserHandle.getUserId(3), "third"), "NONE"); // packages that exist in both app permissions & local preferences - expected.put(new Pair(UserHandle.getUserId(UID_P), PKG_P), "DEFAULT"); - expected.put(new Pair(UserHandle.getUserId(UID_O), PKG_O), "NONE"); + expected.put(new Pair<>(UserHandle.getUserId(UID_P), PKG_P), "DEFAULT"); + expected.put(new Pair<>(UserHandle.getUserId(UID_O), PKG_O), "NONE"); // package that only exists in local preferences; expect no importance output - expected.put(new Pair(UserHandle.getUserId(UID_N_MR1), PKG_N_MR1), null); + expected.put(new Pair<>(UserHandle.getUserId(UID_N_MR1), PKG_N_MR1), null); JSONArray actual = (JSONArray) mHelper.dumpJson( new NotificationManagerService.DumpFilter(), appPermissions) @@ -2918,7 +2917,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { for (int i = 0; i < actual.length(); i++) { JSONObject pkgInfo = actual.getJSONObject(i); Pair<Integer, String> pkgKey = - new Pair(pkgInfo.getInt("userId"), pkgInfo.getString("packageName")); + new Pair<>(pkgInfo.getInt("userId"), pkgInfo.getString("packageName")); assertTrue(expected.containsKey(pkgKey)); if (pkgInfo.has("importance")) { assertThat(pkgInfo.getString("importance")).isEqualTo(expected.get(pkgKey)); @@ -2957,16 +2956,16 @@ public class PreferencesHelperTest extends UiServiceTestCase { // have their permission set to false, and not based on PackagePreferences importance ArrayMap<Pair<Integer, String>, Pair<Boolean, Boolean>> appPermissions = new ArrayMap<>(); - appPermissions.put(new Pair(1, "first"), new Pair(true, false)); // not in local prefs - appPermissions.put(new Pair(3, "third"), new Pair(false, false)); // not in local prefs - appPermissions.put(new Pair(UID_O, PKG_O), new Pair(false, false)); // in local prefs + appPermissions.put(new Pair<>(1, "first"), new Pair<>(true, false)); // not in local prefs + appPermissions.put(new Pair<>(3, "third"), new Pair<>(false, false)); // not in local prefs + appPermissions.put(new Pair<>(UID_O, PKG_O), new Pair<>(false, false)); // in local prefs mHelper.canShowBadge(PKG_O, UID_O); // expected output ArraySet<Pair<Integer, String>> expected = new ArraySet<>(); - expected.add(new Pair(UserHandle.getUserId(3), "third")); - expected.add(new Pair(UserHandle.getUserId(UID_O), PKG_O)); + expected.add(new Pair<>(UserHandle.getUserId(3), "third")); + expected.add(new Pair<>(UserHandle.getUserId(UID_O), PKG_O)); // make sure that's the only thing in the package ban output JSONArray actual = mHelper.dumpBansJson( @@ -2976,7 +2975,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { for (int i = 0; i < actual.length(); i++) { JSONObject ban = actual.getJSONObject(i); assertTrue(expected.contains( - new Pair(ban.getInt("userId"), ban.getString("packageName")))); + new Pair<>(ban.getInt("userId"), ban.getString("packageName")))); } } @@ -2994,9 +2993,9 @@ public class PreferencesHelperTest extends UiServiceTestCase { // confirm that the string resulting from dumpImpl contains only importances from permission ArrayMap<Pair<Integer, String>, Pair<Boolean, Boolean>> appPermissions = new ArrayMap<>(); - appPermissions.put(new Pair(1, "first"), new Pair(true, false)); // not in local prefs - appPermissions.put(new Pair(3, "third"), new Pair(false, true)); // not in local prefs - appPermissions.put(new Pair(UID_O, PKG_O), new Pair(false, false)); // in local prefs + appPermissions.put(new Pair<>(1, "first"), new Pair<>(true, false)); // not in local prefs + appPermissions.put(new Pair<>(3, "third"), new Pair<>(false, true)); // not in local prefs + appPermissions.put(new Pair<>(UID_O, PKG_O), new Pair<>(false, false)); // in local prefs // local package preferences mHelper.canShowBadge(PKG_O, UID_O); @@ -3055,9 +3054,9 @@ public class PreferencesHelperTest extends UiServiceTestCase { // permissions -- these should take precedence ArrayMap<Pair<Integer, String>, Pair<Boolean, Boolean>> appPermissions = new ArrayMap<>(); - appPermissions.put(new Pair(1, "first"), new Pair(true, false)); // not in local prefs - appPermissions.put(new Pair(3, "third"), new Pair(false, false)); // not in local prefs - appPermissions.put(new Pair(UID_O, PKG_O), new Pair(false, false)); // in local prefs + appPermissions.put(new Pair<>(1, "first"), new Pair<>(true, false)); // not in local prefs + appPermissions.put(new Pair<>(3, "third"), new Pair<>(false, false)); // not in local prefs + appPermissions.put(new Pair<>(UID_O, PKG_O), new Pair<>(false, false)); // in local prefs // local package preferences mHelper.canShowBadge(PKG_O, UID_O); @@ -3067,14 +3066,14 @@ public class PreferencesHelperTest extends UiServiceTestCase { // should have importance set (aka not PKG_P) // map format: (uid, package name) -> importance (int) ArrayMap<Pair<Integer, String>, Integer> expected = new ArrayMap<>(); - expected.put(new Pair(1, "first"), IMPORTANCE_DEFAULT); - expected.put(new Pair(3, "third"), IMPORTANCE_NONE); - expected.put(new Pair(UID_O, PKG_O), IMPORTANCE_NONE); + expected.put(new Pair<>(1, "first"), IMPORTANCE_DEFAULT); + expected.put(new Pair<>(3, "third"), IMPORTANCE_NONE); + expected.put(new Pair<>(UID_O, PKG_O), IMPORTANCE_NONE); // unfortunately, due to how nano protos work, there's no distinction between unset // fields and default-value fields, so we have no choice here but to check for a value of 0. // at least we can make sure the local importance for PKG_P in this test is not 0 (NONE). - expected.put(new Pair(UID_P, PKG_P), 0); + expected.put(new Pair<>(UID_P, PKG_P), 0); // get the proto output and inspect its contents ProtoOutputStream proto = new ProtoOutputStream(); @@ -3084,7 +3083,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertThat(actual.records.length).isEqualTo(expected.size()); for (int i = 0; i < actual.records.length; i++) { RankingHelperProto.RecordProto record = actual.records[i]; - Pair<Integer, String> pkgKey = new Pair(record.uid, record.package_); + Pair<Integer, String> pkgKey = new Pair<>(record.uid, record.package_); assertTrue(expected.containsKey(pkgKey)); assertThat(record.importance).isEqualTo(expected.get(pkgKey)); } @@ -3403,26 +3402,6 @@ public class PreferencesHelperTest extends UiServiceTestCase { } @Test - public void testToggleNotificationDelegate() { - mHelper.setNotificationDelegate(PKG_O, UID_O, "other", 53); - mHelper.toggleNotificationDelegate(PKG_O, UID_O, false); - - assertNull(mHelper.getNotificationDelegate(PKG_O, UID_O)); - - mHelper.toggleNotificationDelegate(PKG_O, UID_O, true); - assertEquals("other", mHelper.getNotificationDelegate(PKG_O, UID_O)); - } - - @Test - public void testToggleNotificationDelegate_noDelegateExistsNoCrash() { - mHelper.toggleNotificationDelegate(PKG_O, UID_O, false); - assertNull(mHelper.getNotificationDelegate(PKG_O, UID_O)); - - mHelper.toggleNotificationDelegate(PKG_O, UID_O, true); - assertNull(mHelper.getNotificationDelegate(PKG_O, UID_O)); - } - - @Test public void testIsDelegateAllowed_noSource() { assertFalse(mHelper.isDelegateAllowed("does not exist", -1, "whatever", 0)); } @@ -3451,14 +3430,6 @@ public class PreferencesHelperTest extends UiServiceTestCase { } @Test - public void testIsDelegateAllowed_delegateDisabledByUser() { - mHelper.setNotificationDelegate(PKG_O, UID_O, "other", 53); - mHelper.toggleNotificationDelegate(PKG_O, UID_O, false); - - assertFalse(mHelper.isDelegateAllowed(PKG_O, UID_O, "other", 53)); - } - - @Test public void testIsDelegateAllowed() { mHelper.setNotificationDelegate(PKG_O, UID_O, "other", 53); @@ -3503,46 +3474,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { loadStreamXml(baos, false, UserHandle.USER_ALL); assertNull(mHelper.getNotificationDelegate(PKG_O, UID_O)); - } - @Test - public void testDelegateXml_userDisabledDelegate() throws Exception { mHelper.setNotificationDelegate(PKG_O, UID_O, "other", 53); - mHelper.toggleNotificationDelegate(PKG_O, UID_O, false); - - ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL); - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, - mPermissionHelper, mLogger, - mAppOpsManager, mStatsEventBuilderFactory, false); - loadStreamXml(baos, false, UserHandle.USER_ALL); - - // appears disabled - assertNull(mHelper.getNotificationDelegate(PKG_O, UID_O)); - - // but was loaded and can be toggled back on - mHelper.toggleNotificationDelegate(PKG_O, UID_O, true); - assertEquals("other", mHelper.getNotificationDelegate(PKG_O, UID_O)); - } - - @Test - public void testDelegateXml_entirelyDisabledDelegate() throws Exception { - mHelper.setNotificationDelegate(PKG_O, UID_O, "other", 53); - mHelper.toggleNotificationDelegate(PKG_O, UID_O, false); - mHelper.revokeNotificationDelegate(PKG_O, UID_O); - - ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL); - mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, - mPermissionHelper, mLogger, - mAppOpsManager, mStatsEventBuilderFactory, false); - loadStreamXml(baos, false, UserHandle.USER_ALL); - - // appears disabled - assertNull(mHelper.getNotificationDelegate(PKG_O, UID_O)); - - mHelper.setNotificationDelegate(PKG_O, UID_O, "other", 53); - assertNull(mHelper.getNotificationDelegate(PKG_O, UID_O)); - - mHelper.toggleNotificationDelegate(PKG_O, UID_O, true); assertEquals("other", mHelper.getNotificationDelegate(PKG_O, UID_O)); } @@ -3686,7 +3619,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { @Test public void testUpdateNotificationChannel_defaultApp() { ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); - toAdd.add(new Pair(PKG_O, UID_O)); + toAdd.add(new Pair<>(PKG_O, UID_O)); mHelper.updateDefaultApps(0, null, toAdd); NotificationChannel a = new NotificationChannel("a", "a", IMPORTANCE_HIGH); mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); @@ -3820,7 +3753,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG_O, UserHandle.PER_USER_RANGE + 1, c, true, true); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); - toAdd.add(new Pair(PKG_O, UID_O)); + toAdd.add(new Pair<>(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); assertTrue(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false) @@ -3840,7 +3773,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, b, false, false); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); - toAdd.add(new Pair(PKG_O, UID_O)); + toAdd.add(new Pair<>(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); assertTrue(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false) @@ -3858,7 +3791,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG_O, UID_O, b, false, false); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); - toAdd.add(new Pair(PKG_O, UID_O)); + toAdd.add(new Pair<>(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); assertTrue(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false) @@ -3884,7 +3817,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, b, false, false); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); - toAdd.add(new Pair(PKG_O, UID_O)); + toAdd.add(new Pair<>(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); @@ -3897,7 +3830,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { ArraySet<String> toRemove = new ArraySet<>(); toRemove.add(PKG_O); toAdd = new ArraySet<>(); - toAdd.add(new Pair(PKG_N_MR1, UID_N_MR1)); + toAdd.add(new Pair<>(PKG_N_MR1, UID_N_MR1)); mHelper.updateDefaultApps(USER.getIdentifier(), toRemove, toAdd); assertFalse(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false) @@ -3909,7 +3842,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { @Test public void testUpdateDefaultApps_appDoesNotExist_noCrash() { ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); - toAdd.add(new Pair(PKG_O, UID_O)); + toAdd.add(new Pair<>(PKG_O, UID_O)); ArraySet<String> toRemove = new ArraySet<>(); toRemove.add(PKG_N_MR1); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), toRemove, toAdd); @@ -3922,7 +3855,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); - toAdd.add(new Pair(PKG_O, UID_O)); + toAdd.add(new Pair<>(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); assertTrue(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false) @@ -3938,7 +3871,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { NotificationChannel a = new NotificationChannel("a", "a", IMPORTANCE_HIGH); mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); - toAdd.add(new Pair(PKG_O, UID_O)); + toAdd.add(new Pair<>(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); NotificationChannel update = new NotificationChannel("a", "a", IMPORTANCE_NONE); @@ -3964,7 +3897,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { @Test public void testDefaultApp_appHasNoSettingsYet() { ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); - toAdd.add(new Pair(PKG_O, UID_O)); + toAdd.add(new Pair<>(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); NotificationChannel a = new NotificationChannel("a", "a", IMPORTANCE_HIGH); @@ -4004,7 +3937,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { @Test public void testUpdateDefaultApps_thenNotFixedPermission() { ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); - toAdd.add(new Pair(PKG_O, UID_O)); + toAdd.add(new Pair<>(PKG_O, UID_O)); mHelper.updateDefaultApps(0, null, toAdd); UserInfo user = new UserInfo(); @@ -4043,7 +3976,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { UID_O}); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); - toAdd.add(new Pair(PKG_O, UID_O)); + toAdd.add(new Pair<>(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); TypedXmlPullParser parser = Xml.newFastPullParser(); @@ -5041,9 +4974,9 @@ public class PreferencesHelperTest extends UiServiceTestCase { // build a collection of app permissions that should be passed in but ignored ArrayMap<Pair<Integer, String>, Pair<Boolean, Boolean>> appPermissions = new ArrayMap<>(); - appPermissions.put(new Pair(1, "first"), new Pair(true, false)); // not in local prefs - appPermissions.put(new Pair(3, "third"), new Pair(false, true)); // not in local prefs - appPermissions.put(new Pair(UID_O, PKG_O), new Pair(false, true)); // in local prefs + appPermissions.put(new Pair<>(1, "first"), new Pair<>(true, false)); // not in local prefs + appPermissions.put(new Pair<>(3, "third"), new Pair<>(false, true)); // not in local prefs + appPermissions.put(new Pair<>(UID_O, PKG_O), new Pair<>(false, true)); // in local prefs // local preferences mHelper.canShowBadge(PKG_O, UID_O); @@ -5052,10 +4985,10 @@ public class PreferencesHelperTest extends UiServiceTestCase { // expected output. format: uid -> importance, as only uid (and not package name) // is in PackageNotificationPreferences ArrayMap<Integer, Pair<Integer, Boolean>> expected = new ArrayMap<>(); - expected.put(1, new Pair(IMPORTANCE_DEFAULT, false)); - expected.put(3, new Pair(IMPORTANCE_NONE, true)); - expected.put(UID_O, new Pair(IMPORTANCE_NONE, true)); // banned by permissions - expected.put(UID_P, new Pair(IMPORTANCE_NONE, false)); // defaults to none, false + expected.put(1, new Pair<>(IMPORTANCE_DEFAULT, false)); + expected.put(3, new Pair<>(IMPORTANCE_NONE, true)); + expected.put(UID_O, new Pair<>(IMPORTANCE_NONE, true)); // banned by permissions + expected.put(UID_P, new Pair<>(IMPORTANCE_NONE, false)); // defaults to none, false ArrayList<StatsEvent> events = new ArrayList<>(); mHelper.pullPackagePreferencesStats(events, appPermissions); @@ -5109,4 +5042,72 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertTrue((channelB.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0); assertTrue((channelC.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0); } + + @Test + public void createNotificationChannel_updateDifferent_requestsSort() { + NotificationChannel original = new NotificationChannel("id", "Bah", IMPORTANCE_DEFAULT); + mHelper.createNotificationChannel(PKG_P, 0, original, true, false); + clearInvocations(mHandler); + + NotificationChannel updated = new NotificationChannel("id", "Wow", IMPORTANCE_DEFAULT); + mHelper.createNotificationChannel(PKG_P, 0, updated, true, false); + + verify(mHandler).requestSort(); + } + + @Test + public void createNotificationChannel_updateSame_doesNotRequestSort() { + NotificationChannel original = new NotificationChannel("id", "Bah", IMPORTANCE_DEFAULT); + mHelper.createNotificationChannel(PKG_P, 0, original, true, false); + clearInvocations(mHandler); + + NotificationChannel same = new NotificationChannel("id", "Bah", IMPORTANCE_DEFAULT); + mHelper.createNotificationChannel(PKG_P, 0, same, true, false); + + verifyZeroInteractions(mHandler); + } + + @Test + public void updateNotificationChannel_different_requestsSort() { + NotificationChannel original = new NotificationChannel("id", "Bah", IMPORTANCE_DEFAULT); + mHelper.createNotificationChannel(PKG_P, 0, original, true, false); + clearInvocations(mHandler); + + NotificationChannel updated = new NotificationChannel("id", "Wow", IMPORTANCE_DEFAULT); + mHelper.updateNotificationChannel(PKG_P, 0, updated, false); + + verify(mHandler).requestSort(); + } + + @Test + public void updateNotificationChannel_same_doesNotRequestSort() { + NotificationChannel original = new NotificationChannel("id", "Bah", IMPORTANCE_DEFAULT); + mHelper.createNotificationChannel(PKG_P, 0, original, true, false); + clearInvocations(mHandler); + // Note: Creating a NotificationChannel identical to the original is not equals(), because + // of mOriginalImportance. So we create a "true copy" instead. + Parcel parcel = Parcel.obtain(); + original.writeToParcel(parcel, 0); + parcel.setDataPosition(0); + NotificationChannel same = NotificationChannel.CREATOR.createFromParcel(parcel); + parcel.recycle(); + + mHelper.updateNotificationChannel(PKG_P, 0, same, false); + + verifyZeroInteractions(mHandler); + } + + @Test + public void setShowBadge_update_requestsSort() { + mHelper.setShowBadge(PKG_P, 0, false); + + verify(mHandler).requestSort(); + } + + @Test + public void setShowBadge_same_doesNotRequestSort() { + mHelper.setShowBadge(PKG_P, 0, true); // true == DEFAULT_SHOW_BADGE + + verifyZeroInteractions(mHandler); + } } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ValidateNotificationPeopleTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ValidateNotificationPeopleTest.java index d72cfc70fc02..0564a73bf3fc 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/ValidateNotificationPeopleTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/ValidateNotificationPeopleTest.java @@ -15,6 +15,8 @@ */ package com.android.server.notification; +import static com.google.common.truth.Truth.assertThat; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -51,6 +53,8 @@ import android.util.LruCache; import androidx.test.runner.AndroidJUnit4; import com.android.server.UiServiceTestCase; +import com.android.server.notification.ValidateNotificationPeople.LookupResult; +import com.android.server.notification.ValidateNotificationPeople.PeopleRankingReconsideration; import org.junit.Test; import org.junit.runner.RunWith; @@ -60,6 +64,7 @@ import org.mockito.stubbing.Answer; import java.util.ArrayList; import java.util.Arrays; +import java.util.concurrent.TimeUnit; @SmallTest @RunWith(AndroidJUnit4.class) @@ -215,7 +220,7 @@ public class ValidateNotificationPeopleTest extends UiServiceTestCase { ContactsContract.Contacts.CONTENT_LOOKUP_URI, ContactsContract.Contacts.ENTERPRISE_CONTACT_LOOKUP_PREFIX + contactId); - new ValidateNotificationPeople().searchContacts(mockContext, lookupUri); + PeopleRankingReconsideration.searchContacts(mockContext, lookupUri); ArgumentCaptor<Uri> queryUri = ArgumentCaptor.forClass(Uri.class); verify(mockContentResolver).query( @@ -242,7 +247,7 @@ public class ValidateNotificationPeopleTest extends UiServiceTestCase { final Uri lookupUri = Uri.withAppendedPath( ContactsContract.Contacts.CONTENT_LOOKUP_URI, String.valueOf(contactId)); - new ValidateNotificationPeople().searchContacts(mockContext, lookupUri); + PeopleRankingReconsideration.searchContacts(mockContext, lookupUri); ArgumentCaptor<Uri> queryUri = ArgumentCaptor.forClass(Uri.class); verify(mockContentResolver).query( @@ -277,7 +282,7 @@ public class ValidateNotificationPeopleTest extends UiServiceTestCase { // call searchContacts and then mergePhoneNumbers, make sure we never actually // query the content resolver for a phone number - new ValidateNotificationPeople().searchContactsAndLookupNumbers(mockContext, lookupUri); + PeopleRankingReconsideration.searchContactsAndLookupNumbers(mockContext, lookupUri); verify(mockContentResolver, never()).query( eq(ContactsContract.CommonDataKinds.Phone.CONTENT_URI), eq(ValidateNotificationPeople.PHONE_LOOKUP_PROJECTION), @@ -320,7 +325,7 @@ public class ValidateNotificationPeopleTest extends UiServiceTestCase { // call searchContacts and then mergePhoneNumbers, and check that we query // once for the - new ValidateNotificationPeople().searchContactsAndLookupNumbers(mockContext, lookupUri); + PeopleRankingReconsideration.searchContactsAndLookupNumbers(mockContext, lookupUri); verify(mockContentResolver, times(1)).query( eq(ContactsContract.CommonDataKinds.Phone.CONTENT_URI), eq(ValidateNotificationPeople.PHONE_LOOKUP_PROJECTION), @@ -339,7 +344,7 @@ public class ValidateNotificationPeopleTest extends UiServiceTestCase { // Create validator with empty cache ValidateNotificationPeople vnp = new ValidateNotificationPeople(); - LruCache cache = new LruCache<String, ValidateNotificationPeople.LookupResult>(5); + LruCache<String, LookupResult> cache = new LruCache<>(5); vnp.initForTests(mockContext, mockNotificationUsageStats, cache); NotificationRecord record = getNotificationRecord(); @@ -366,9 +371,8 @@ public class ValidateNotificationPeopleTest extends UiServiceTestCase { float affinity = 0.7f; // Create a fake LookupResult for the data we'll pass in - LruCache cache = new LruCache<String, ValidateNotificationPeople.LookupResult>(5); - ValidateNotificationPeople.LookupResult lr = - mock(ValidateNotificationPeople.LookupResult.class); + LruCache<String, LookupResult> cache = new LruCache<>(5); + LookupResult lr = mock(LookupResult.class); when(lr.getAffinity()).thenReturn(affinity); when(lr.getPhoneNumbers()).thenReturn(new ArraySet<>(new String[]{lookupTel})); when(lr.isExpired()).thenReturn(false); @@ -392,6 +396,23 @@ public class ValidateNotificationPeopleTest extends UiServiceTestCase { assertTrue(record.getPhoneNumbers().contains(lookupTel)); } + @Test + public void validatePeople_reconsiderationWillNotBeDelayed() { + final Context mockContext = mock(Context.class); + final ContentResolver mockContentResolver = mock(ContentResolver.class); + when(mockContext.getContentResolver()).thenReturn(mockContentResolver); + ValidateNotificationPeople vnp = new ValidateNotificationPeople(); + vnp.initForTests(mockContext, mock(NotificationUsageStats.class), new LruCache<>(5)); + NotificationRecord record = getNotificationRecord(); + String[] callNumber = new String[]{"tel:12345678910"}; + setNotificationPeople(record, callNumber); + + RankingReconsideration rr = vnp.validatePeople(mockContext, record); + + assertThat(rr).isNotNull(); + assertThat(rr.getDelay(TimeUnit.MILLISECONDS)).isEqualTo(0); + } + // Creates a cursor that points to one item of Contacts data with the specified // columns. private Cursor makeMockCursor(int id, String lookupKey, int starred, int hasPhone) { diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeOnStartWhenLaunchingAppCfArmTest.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeOnAppStartWhenLaunchingAppCfArmTest.kt index 194c86be3207..03f21f95e61e 100644 --- a/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeOnStartWhenLaunchingAppCfArmTest.kt +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeOnAppStartWhenLaunchingAppCfArmTest.kt @@ -26,5 +26,5 @@ import org.junit.runners.Parameterized @RunWith(Parameterized::class) @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) -class ShowImeOnStartWhenLaunchingAppCfArmTest(flicker: FlickerTest) : +class ShowImeOnAppStartWhenLaunchingAppCfArmTest(flicker: FlickerTest) : ShowImeOnAppStartWhenLaunchingAppTest(flicker) diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeOnAppStartWhenLaunchingAppFromOverviewTestCfArm.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeOnAppStartWhenLaunchingAppFromOverviewTestCfArm.kt new file mode 100644 index 000000000000..efda0fffd3cd --- /dev/null +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeOnAppStartWhenLaunchingAppFromOverviewTestCfArm.kt @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2023 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.server.wm.flicker.ime + +import android.tools.common.Rotation +import android.tools.device.flicker.junit.FlickerParametersRunnerFactory +import android.tools.device.flicker.legacy.FlickerTest +import android.tools.device.flicker.legacy.FlickerTestFactory +import org.junit.FixMethodOrder +import org.junit.runner.RunWith +import org.junit.runners.MethodSorters +import org.junit.runners.Parameterized + +@RunWith(Parameterized::class) +@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +class ShowImeOnAppStartWhenLaunchingAppFromOverviewTestCfArm(flicker: FlickerTest) : + ShowImeOnAppStartWhenLaunchingAppFromOverviewTest(flicker) { + + companion object { + @Parameterized.Parameters(name = "{0}") + @JvmStatic + fun getParams(): Collection<FlickerTest> { + return FlickerTestFactory.nonRotationTests( + supportedRotations = listOf(Rotation.ROTATION_0) + ) + } + } +}
\ No newline at end of file diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeOnAppStartWhenLaunchingAppFromQuickSwitchTest.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeOnAppStartWhenLaunchingAppFromQuickSwitchTest.kt index 954f589ffa7f..daee3322b15a 100644 --- a/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeOnAppStartWhenLaunchingAppFromQuickSwitchTest.kt +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeOnAppStartWhenLaunchingAppFromQuickSwitchTest.kt @@ -16,13 +16,11 @@ package com.android.server.wm.flicker.ime -import android.platform.test.annotations.FlakyTest import android.platform.test.annotations.Presubmit import android.tools.common.NavBar import android.tools.common.Rotation import android.tools.common.datatypes.component.ComponentNameMatcher import com.android.server.wm.flicker.helpers.ImeShownOnAppStartHelper -import android.tools.device.flicker.isShellTransitionsEnabled import android.tools.device.flicker.junit.FlickerParametersRunnerFactory import android.tools.device.flicker.legacy.FlickerBuilder import android.tools.device.flicker.legacy.FlickerTest @@ -31,8 +29,6 @@ import androidx.test.filters.RequiresDevice import com.android.server.wm.flicker.BaseTest import com.android.server.wm.flicker.helpers.SimpleAppHelper import com.android.server.wm.flicker.helpers.setRotation -import org.junit.Assume -import org.junit.Before import org.junit.FixMethodOrder import org.junit.Test import org.junit.runner.RunWith @@ -54,11 +50,6 @@ open class ShowImeOnAppStartWhenLaunchingAppFromQuickSwitchTest(flicker: Flicker private val imeTestApp = ImeShownOnAppStartHelper(instrumentation, flicker.scenario.startRotation) - @Before - open fun before() { - Assume.assumeFalse(isShellTransitionsEnabled) - } - /** {@inheritDoc} */ override val transition: FlickerBuilder.() -> Unit = { setup { @@ -95,7 +86,7 @@ open class ShowImeOnAppStartWhenLaunchingAppFromQuickSwitchTest(flicker: Flicker } } /** {@inheritDoc} */ - @FlakyTest(bugId = 265016201) + @Presubmit @Test override fun entireScreenCovered() = super.entireScreenCovered() @@ -115,7 +106,7 @@ open class ShowImeOnAppStartWhenLaunchingAppFromQuickSwitchTest(flicker: Flicker } } - @FlakyTest(bugId = 244414110) + @Presubmit @Test open fun imeLayerIsVisibleWhenSwitchingToImeApp() { flicker.assertLayersStart { isVisible(ComponentNameMatcher.IME) } diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeOnAppStartWhenLaunchingAppFromQuickSwitchTestShellTransit.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeOnAppStartWhenLaunchingAppFromQuickSwitchTestShellTransit.kt deleted file mode 100644 index a927102f2a08..000000000000 --- a/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeOnAppStartWhenLaunchingAppFromQuickSwitchTestShellTransit.kt +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2021 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.server.wm.flicker.ime - -import android.platform.test.annotations.Presubmit -import android.tools.device.flicker.isShellTransitionsEnabled -import android.tools.device.flicker.junit.FlickerParametersRunnerFactory -import android.tools.device.flicker.legacy.FlickerTest -import androidx.test.filters.RequiresDevice -import org.junit.Assume -import org.junit.Before -import org.junit.FixMethodOrder -import org.junit.Ignore -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.MethodSorters -import org.junit.runners.Parameterized - -/** - * Test IME windows switching with 2-Buttons or gestural navigation. To run this test: `atest - * FlickerTests:SwitchImeWindowsFromGestureNavTest` - */ -@RequiresDevice -@RunWith(Parameterized::class) -@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -class ShowImeOnAppStartWhenLaunchingAppFromQuickSwitchTestShellTransit(flicker: FlickerTest) : - ShowImeOnAppStartWhenLaunchingAppFromQuickSwitchTest(flicker) { - @Before - override fun before() { - Assume.assumeTrue(isShellTransitionsEnabled) - } - - @Presubmit @Test override fun entireScreenCovered() = super.entireScreenCovered() - - @Presubmit - @Test - override fun imeLayerIsVisibleWhenSwitchingToImeApp() = - super.imeLayerIsVisibleWhenSwitchingToImeApp() - - @Presubmit - @Test - override fun visibleLayersShownMoreThanOneConsecutiveEntry() = - super.visibleLayersShownMoreThanOneConsecutiveEntry() - - @Presubmit - @Test - override fun visibleWindowsShownMoreThanOneConsecutiveEntry() = - super.visibleWindowsShownMoreThanOneConsecutiveEntry() - - /** {@inheritDoc} */ - @Ignore("Nav bar window becomes invisible during quick switch") - @Test - override fun navBarWindowIsAlwaysVisible() = super.navBarWindowIsAlwaysVisible() -} diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeWhileDismissingThemedPopupDialogTest.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeWhileDismissingThemedPopupDialogTest.kt index 99b9bd2bfc66..a57aa5bc745c 100644 --- a/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeWhileDismissingThemedPopupDialogTest.kt +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeWhileDismissingThemedPopupDialogTest.kt @@ -45,7 +45,7 @@ import org.junit.runners.Parameterized @RunWith(Parameterized::class) @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) -class ShowImeWhileDismissingThemedPopupDialogTest(flicker: FlickerTest) : BaseTest(flicker) { +open class ShowImeWhileDismissingThemedPopupDialogTest(flicker: FlickerTest) : BaseTest(flicker) { private val testApp = ImeShownOnAppStartHelper(instrumentation, flicker.scenario.startRotation) /** {@inheritDoc} */ diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeWhileDismissingThemedPopupDialogTestCfArm.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeWhileDismissingThemedPopupDialogTestCfArm.kt new file mode 100644 index 000000000000..cffc05d7d0b7 --- /dev/null +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/ShowImeWhileDismissingThemedPopupDialogTestCfArm.kt @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2023 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.server.wm.flicker.ime + +import android.tools.common.Rotation +import android.tools.device.flicker.junit.FlickerParametersRunnerFactory +import android.tools.device.flicker.legacy.FlickerTest +import android.tools.device.flicker.legacy.FlickerTestFactory +import org.junit.FixMethodOrder +import org.junit.runner.RunWith +import org.junit.runners.MethodSorters +import org.junit.runners.Parameterized + +@RunWith(Parameterized::class) +@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +class ShowImeWhileDismissingThemedPopupDialogTestCfArm(flicker: FlickerTest) : + ShowImeWhileDismissingThemedPopupDialogTest(flicker) { + companion object { + /** + * Creates the test configurations. + * + * See [FlickerTestFactory.nonRotationTests] for configuring screen orientation and + * navigation modes. + */ + @Parameterized.Parameters(name = "{0}") + @JvmStatic + fun getParams(): Collection<FlickerTest> { + return FlickerTestFactory.nonRotationTests( + supportedRotations = listOf(Rotation.ROTATION_0) + ) + } + } +}
\ No newline at end of file diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/quickswitch/QuickSwitchBetweenTwoAppsBackTest.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/quickswitch/QuickSwitchBetweenTwoAppsBackTest.kt index 78cee3c4e71c..eadeef5bf3e6 100644 --- a/tests/FlickerTests/src/com/android/server/wm/flicker/quickswitch/QuickSwitchBetweenTwoAppsBackTest.kt +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/quickswitch/QuickSwitchBetweenTwoAppsBackTest.kt @@ -16,11 +16,11 @@ package com.android.server.wm.flicker.quickswitch +import android.platform.test.annotations.FlakyTest import android.platform.test.annotations.Presubmit import android.tools.common.NavBar import android.tools.common.datatypes.Rect import android.tools.common.datatypes.component.ComponentNameMatcher -import android.tools.device.flicker.isShellTransitionsEnabled import android.tools.device.flicker.junit.FlickerParametersRunnerFactory import android.tools.device.flicker.legacy.FlickerBuilder import android.tools.device.flicker.legacy.FlickerTest @@ -29,9 +29,8 @@ import androidx.test.filters.RequiresDevice import com.android.server.wm.flicker.BaseTest import com.android.server.wm.flicker.helpers.NonResizeableAppHelper import com.android.server.wm.flicker.helpers.SimpleAppHelper -import org.junit.Assume -import org.junit.Before import org.junit.FixMethodOrder +import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.MethodSorters @@ -57,11 +56,6 @@ open class QuickSwitchBetweenTwoAppsBackTest(flicker: FlickerTest) : BaseTest(fl private val testApp1 = SimpleAppHelper(instrumentation) private val testApp2 = NonResizeableAppHelper(instrumentation) - @Before - open fun before() { - Assume.assumeFalse(isShellTransitionsEnabled) - } - /** {@inheritDoc} */ override val transition: FlickerBuilder.() -> Unit = { setup { @@ -102,7 +96,7 @@ open class QuickSwitchBetweenTwoAppsBackTest(flicker: FlickerTest) : BaseTest(fl * Checks that the transition starts with [testApp2]'s layers filling/covering exactly the * entirety of the display. */ - @Presubmit + @FlakyTest(bugId = 250520840) @Test open fun startsWithApp2LayersCoverFullScreen() { flicker.assertLayersStart { this.visibleRegion(testApp2).coversExactly(startDisplayBounds) } @@ -230,6 +224,20 @@ open class QuickSwitchBetweenTwoAppsBackTest(flicker: FlickerTest) : BaseTest(fl } } + /** {@inheritDoc} */ + @Ignore("Nav bar window becomes invisible during quick switch") + @Test + override fun navBarWindowIsAlwaysVisible() = super.navBarWindowIsAlwaysVisible() + + @FlakyTest(bugId = 246284708) + @Test + override fun visibleLayersShownMoreThanOneConsecutiveEntry() = + super.visibleLayersShownMoreThanOneConsecutiveEntry() + + @FlakyTest(bugId = 250518877) + @Test + override fun navBarLayerPositionAtStartAndEnd() = super.navBarLayerPositionAtStartAndEnd() + companion object { private var startDisplayBounds = Rect.EMPTY diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/quickswitch/QuickSwitchBetweenTwoAppsBackTest_ShellTransit.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/quickswitch/QuickSwitchBetweenTwoAppsBackTest_ShellTransit.kt deleted file mode 100644 index 2b69e9b7d258..000000000000 --- a/tests/FlickerTests/src/com/android/server/wm/flicker/quickswitch/QuickSwitchBetweenTwoAppsBackTest_ShellTransit.kt +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2021 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.server.wm.flicker.quickswitch - -import android.platform.test.annotations.FlakyTest -import android.tools.device.flicker.isShellTransitionsEnabled -import android.tools.device.flicker.junit.FlickerParametersRunnerFactory -import android.tools.device.flicker.legacy.FlickerTest -import androidx.test.filters.RequiresDevice -import org.junit.Assume -import org.junit.Before -import org.junit.FixMethodOrder -import org.junit.Ignore -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.MethodSorters -import org.junit.runners.Parameterized - -/** - * Test quick switching back to previous app from last opened app - * - * To run this test: `atest FlickerTests:QuickSwitchBetweenTwoAppsBackTest` - * - * Actions: - * ``` - * Launch an app [testApp1] - * Launch another app [testApp2] - * Swipe right from the bottom of the screen to quick switch back to the first app [testApp1] - * ``` - */ -@RequiresDevice -@RunWith(Parameterized::class) -@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -open class QuickSwitchBetweenTwoAppsBackTest_ShellTransit(flicker: FlickerTest) : - QuickSwitchBetweenTwoAppsBackTest(flicker) { - @Before - override fun before() { - Assume.assumeTrue(isShellTransitionsEnabled) - } - - /** {@inheritDoc} */ - @Ignore("Nav bar window becomes invisible during quick switch") - @Test - override fun navBarWindowIsAlwaysVisible() = super.navBarWindowIsAlwaysVisible() - - /** {@inheritDoc} */ - @FlakyTest(bugId = 250520840) - @Test - override fun startsWithApp2LayersCoverFullScreen() = super.startsWithApp2LayersCoverFullScreen() - - @FlakyTest(bugId = 246284708) - @Test - override fun visibleLayersShownMoreThanOneConsecutiveEntry() = - super.visibleLayersShownMoreThanOneConsecutiveEntry() - - @FlakyTest(bugId = 250518877) - @Test - override fun navBarLayerPositionAtStartAndEnd() = super.navBarLayerPositionAtStartAndEnd() -} diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/quickswitch/QuickSwitchBetweenTwoAppsForwardTest.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/quickswitch/QuickSwitchBetweenTwoAppsForwardTest.kt index cd7d6fac0e9c..136049533350 100644 --- a/tests/FlickerTests/src/com/android/server/wm/flicker/quickswitch/QuickSwitchBetweenTwoAppsForwardTest.kt +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/quickswitch/QuickSwitchBetweenTwoAppsForwardTest.kt @@ -16,11 +16,11 @@ package com.android.server.wm.flicker.quickswitch +import android.platform.test.annotations.FlakyTest import android.platform.test.annotations.Presubmit import android.tools.common.NavBar import android.tools.common.datatypes.Rect import android.tools.common.datatypes.component.ComponentNameMatcher -import android.tools.device.flicker.isShellTransitionsEnabled import android.tools.device.flicker.junit.FlickerParametersRunnerFactory import android.tools.device.flicker.legacy.FlickerBuilder import android.tools.device.flicker.legacy.FlickerTest @@ -29,9 +29,8 @@ import androidx.test.filters.RequiresDevice import com.android.server.wm.flicker.BaseTest import com.android.server.wm.flicker.helpers.NonResizeableAppHelper import com.android.server.wm.flicker.helpers.SimpleAppHelper -import org.junit.Assume -import org.junit.Before import org.junit.FixMethodOrder +import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.MethodSorters @@ -58,11 +57,6 @@ open class QuickSwitchBetweenTwoAppsForwardTest(flicker: FlickerTest) : BaseTest private val testApp1 = SimpleAppHelper(instrumentation) private val testApp2 = NonResizeableAppHelper(instrumentation) - @Before - open fun before() { - Assume.assumeFalse(isShellTransitionsEnabled) - } - /** {@inheritDoc} */ override val transition: FlickerBuilder.() -> Unit = { setup { @@ -113,7 +107,7 @@ open class QuickSwitchBetweenTwoAppsForwardTest(flicker: FlickerTest) : BaseTest * Checks that the transition starts with [testApp1]'s layers filling/covering exactly the * entirety of the display. */ - @Presubmit + @FlakyTest(bugId = 250522691) @Test open fun startsWithApp1LayersCoverFullScreen() { flicker.assertLayersStart { this.visibleRegion(testApp1).coversExactly(startDisplayBounds) } @@ -248,6 +242,20 @@ open class QuickSwitchBetweenTwoAppsForwardTest(flicker: FlickerTest) : BaseTest @Test override fun taskBarLayerIsVisibleAtStartAndEnd() = super.taskBarLayerIsVisibleAtStartAndEnd() + /** {@inheritDoc} */ + @Ignore("Nav bar window becomes invisible during quick switch") + @Test + override fun navBarWindowIsAlwaysVisible() = super.navBarWindowIsAlwaysVisible() + + @FlakyTest(bugId = 246284708) + @Test + override fun visibleLayersShownMoreThanOneConsecutiveEntry() = + super.visibleLayersShownMoreThanOneConsecutiveEntry() + + @FlakyTest(bugId = 250518877) + @Test + override fun navBarLayerPositionAtStartAndEnd() = super.navBarLayerPositionAtStartAndEnd() + companion object { private var startDisplayBounds = Rect.EMPTY diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/quickswitch/QuickSwitchBetweenTwoAppsForwardTest_ShellTransit.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/quickswitch/QuickSwitchBetweenTwoAppsForwardTest_ShellTransit.kt deleted file mode 100644 index b0d4e2753758..000000000000 --- a/tests/FlickerTests/src/com/android/server/wm/flicker/quickswitch/QuickSwitchBetweenTwoAppsForwardTest_ShellTransit.kt +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2021 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.server.wm.flicker.quickswitch - -import android.platform.test.annotations.FlakyTest -import android.tools.device.flicker.isShellTransitionsEnabled -import android.tools.device.flicker.junit.FlickerParametersRunnerFactory -import android.tools.device.flicker.legacy.FlickerTest -import androidx.test.filters.RequiresDevice -import org.junit.Assume -import org.junit.Before -import org.junit.FixMethodOrder -import org.junit.Ignore -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.MethodSorters -import org.junit.runners.Parameterized - -/** - * Test quick switching back to previous app from last opened app - * - * To run this test: `atest FlickerTests:QuickSwitchBetweenTwoAppsForwardTest` - * - * Actions: - * ``` - * Launch an app [testApp1] - * Launch another app [testApp2] - * Swipe right from the bottom of the screen to quick switch back to the first app [testApp1] - * Swipe left from the bottom of the screen to quick switch forward to the second app [testApp2] - * ``` - */ -@RequiresDevice -@RunWith(Parameterized::class) -@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -open class QuickSwitchBetweenTwoAppsForwardTest_ShellTransit(flicker: FlickerTest) : - QuickSwitchBetweenTwoAppsForwardTest(flicker) { - @Before - override fun before() { - Assume.assumeTrue(isShellTransitionsEnabled) - } - - /** {@inheritDoc} */ - @Ignore("Nav bar window becomes invisible during quick switch") - @Test - override fun navBarWindowIsAlwaysVisible() = super.navBarWindowIsAlwaysVisible() - - @FlakyTest(bugId = 246284708) - @Test - override fun visibleLayersShownMoreThanOneConsecutiveEntry() = - super.visibleLayersShownMoreThanOneConsecutiveEntry() - - @FlakyTest(bugId = 250518877) - @Test - override fun navBarLayerPositionAtStartAndEnd() = super.navBarLayerPositionAtStartAndEnd() - - @FlakyTest(bugId = 250522691) - @Test - override fun startsWithApp1LayersCoverFullScreen() = super.startsWithApp1LayersCoverFullScreen() -} |