From 36bcc77337814d4d36e2b10eb062ac417d91611e Mon Sep 17 00:00:00 2001 From: lumark Date: Mon, 10 Feb 2020 18:41:57 +0800 Subject: [PATCH 01/56] [RESTRICT AUTOMERGE] Restrict app transition maximum duration As WindowState#startAnimation for restricting window animation duration (currently is 10 secs), For security reason, we also need to restrict app transition animation duration as 3 secs to prevent malicious app may set a long duration or infinity repeat counts through ActivityOption#makeCustomAnimation or Activity#overridePendingTransition with custom animation set. Bug: 145728687 Test: manual as issue provided test app Change-Id: I39051d6e4d2b681ce2becbafe14aab3f3d8ebf6b --- .../java/com/android/server/wm/AppTransition.java | 1 + .../com/android/server/wm/WindowManagerService.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wm/AppTransition.java b/services/core/java/com/android/server/wm/AppTransition.java index b1ed35867dcf..1d87b74023e4 100644 --- a/services/core/java/com/android/server/wm/AppTransition.java +++ b/services/core/java/com/android/server/wm/AppTransition.java @@ -176,6 +176,7 @@ public class AppTransition implements Dump { private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420; private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336; private static final long APP_TRANSITION_TIMEOUT_MS = 5000; + static final int MAX_APP_TRANSITION_DURATION = 3 * 1000; // 3 secs. private final Context mContext; private final WindowManagerService mService; diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 8439669a2147..bf488132e253 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -68,6 +68,7 @@ import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; import static com.android.server.LockGuard.INDEX_WINDOW; import static com.android.server.LockGuard.installLock; +import static com.android.server.wm.AppTransition.MAX_APP_TRANSITION_DURATION; import static com.android.server.wm.AppTransition.TRANSIT_UNSET; import static com.android.server.wm.AppWindowAnimator.PROLONG_ANIMATION_AT_END; import static com.android.server.wm.AppWindowAnimator.PROLONG_ANIMATION_AT_START; @@ -2361,7 +2362,16 @@ public class WindowManagerService extends IWindowManager.Stub displayConfig.orientation, frame, displayFrame, insets, surfaceInsets, isVoiceInteraction, freeform, atoken.getTask().mTaskId); if (a != null) { - if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + atoken); + if (a != null) { + // Setup the maximum app transition duration to prevent malicious app may set a long + // animation duration or infinite repeat counts for the app transition through + // ActivityOption#makeCustomAnimation or WindowManager#overridePendingTransition. + a.restrictDuration(MAX_APP_TRANSITION_DURATION); + } + if (DEBUG_ANIM) { + logWithStack(TAG, "Loaded animation " + a + " for " + atoken + + ", duration: " + ((a != null) ? a.getDuration() : 0)); + } final int containingWidth = frame.width(); final int containingHeight = frame.height(); atoken.mAppAnimator.setAnimation(a, containingWidth, containingHeight, width, -- GitLab From 6de34f8ee714691dbc3c089245bf832006826ebe Mon Sep 17 00:00:00 2001 From: lumark Date: Mon, 10 Feb 2020 18:41:57 +0800 Subject: [PATCH 02/56] [RESTRICT AUTOMERGE] Restrict app transition maximum duration As WindowState#startAnimation for restricting window animation duration (currently is 10 secs), For security reason, we also need to restrict app transition animation duration as 3 secs to prevent malicious app may set a long duration or infinity repeat counts through ActivityOption#makeCustomAnimation or Activity#overridePendingTransition with custom animation set. Bug: 145728687 Test: manual as issue provided test app Change-Id: I39051d6e4d2b681ce2becbafe14aab3f3d8ebf6b --- .../java/com/android/server/wm/AppTransition.java | 1 + .../java/com/android/server/wm/AppWindowToken.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wm/AppTransition.java b/services/core/java/com/android/server/wm/AppTransition.java index e6a83dedded9..6aed41a4df3c 100644 --- a/services/core/java/com/android/server/wm/AppTransition.java +++ b/services/core/java/com/android/server/wm/AppTransition.java @@ -168,6 +168,7 @@ public class AppTransition implements Dump { private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420; private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336; private static final long APP_TRANSITION_TIMEOUT_MS = 5000; + static final int MAX_APP_TRANSITION_DURATION = 3 * 1000; // 3 secs. private final Context mContext; private final WindowManagerService mService; diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java index eab5e0dd270e..ebb8a9f35434 100644 --- a/services/core/java/com/android/server/wm/AppWindowToken.java +++ b/services/core/java/com/android/server/wm/AppWindowToken.java @@ -38,6 +38,7 @@ import static android.view.WindowManager.TRANSIT_WALLPAPER_OPEN; import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; +import static com.android.server.wm.AppTransition.MAX_APP_TRANSITION_DURATION; import static com.android.server.wm.AppWindowTokenProto.ALL_DRAWN; import static com.android.server.wm.AppWindowTokenProto.APP_STOPPED; import static com.android.server.wm.AppWindowTokenProto.CLIENT_HIDDEN; @@ -2679,7 +2680,16 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets, surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId); if (a != null) { - if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this); + if (a != null) { + // Setup the maximum app transition duration to prevent malicious app may set a long + // animation duration or infinite repeat counts for the app transition through + // ActivityOption#makeCustomAnimation or WindowManager#overridePendingTransition. + a.restrictDuration(MAX_APP_TRANSITION_DURATION); + } + if (DEBUG_ANIM) { + logWithStack(TAG, "Loaded animation " + a + " for " + this + + ", duration: " + ((a != null) ? a.getDuration() : 0)); + } final int containingWidth = frame.width(); final int containingHeight = frame.height(); a.initialize(containingWidth, containingHeight, width, height); -- GitLab From bfe15a139d866fc225cfdd2c151d07e2ec1c9600 Mon Sep 17 00:00:00 2001 From: Soonil Nagarkar Date: Tue, 21 Apr 2020 10:48:53 -0700 Subject: [PATCH 03/56] DO NOT MERGE Add location shell commands to R Test: manual Bug: 154624964 Change-Id: I60bb117c680d8ff8db0901b67f1d0ce8627091ea --- .../com/android/server/ServiceWatcher.java | 6 +- .../location/LocationManagerService.java | 9 ++ .../server/location/LocationShellCommand.java | 92 +++++++++++++++++++ 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 services/core/java/com/android/server/location/LocationShellCommand.java diff --git a/services/core/java/com/android/server/ServiceWatcher.java b/services/core/java/com/android/server/ServiceWatcher.java index cfb79aa3a210..b1b5ec01df6a 100644 --- a/services/core/java/com/android/server/ServiceWatcher.java +++ b/services/core/java/com/android/server/ServiceWatcher.java @@ -169,7 +169,11 @@ public class ServiceWatcher implements ServiceConnection { @Override public String toString() { - return component.toShortString() + "@" + version + "[u" + userId + "]"; + if (component == null) { + return "none"; + } else { + return component.toShortString() + "@" + version + "[u" + userId + "]"; + } } } diff --git a/services/core/java/com/android/server/location/LocationManagerService.java b/services/core/java/com/android/server/location/LocationManagerService.java index 4f8708a7599a..b2bf1fce0d07 100644 --- a/services/core/java/com/android/server/location/LocationManagerService.java +++ b/services/core/java/com/android/server/location/LocationManagerService.java @@ -69,6 +69,7 @@ import android.os.CancellationSignal; import android.os.Handler; import android.os.IBinder; import android.os.ICancellationSignal; +import android.os.ParcelFileDescriptor; import android.os.PowerManager; import android.os.PowerManager.ServiceType; import android.os.PowerManagerInternal; @@ -2599,6 +2600,14 @@ public class LocationManagerService extends ILocationManager.Stub { return manager.getMockProviderRequests(); } + @Override + public int handleShellCommand(ParcelFileDescriptor in, ParcelFileDescriptor out, + ParcelFileDescriptor err, String[] args) { + return new LocationShellCommand(this).exec( + this, in.getFileDescriptor(), out.getFileDescriptor(), err.getFileDescriptor(), + args); + } + @Override protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) { diff --git a/services/core/java/com/android/server/location/LocationShellCommand.java b/services/core/java/com/android/server/location/LocationShellCommand.java new file mode 100644 index 000000000000..909873f07993 --- /dev/null +++ b/services/core/java/com/android/server/location/LocationShellCommand.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2020 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.location; + +import android.os.BasicShellCommandHandler; +import android.os.UserHandle; + +import java.io.PrintWriter; +import java.util.Objects; + +/** + * Interprets and executes 'adb shell cmd location [args]'. + */ +class LocationShellCommand extends BasicShellCommandHandler { + + private final LocationManagerService mService; + + LocationShellCommand(LocationManagerService service) { + mService = Objects.requireNonNull(service); + } + + @Override + public int onCommand(String cmd) { + if (cmd == null) { + return handleDefaultCommands(null); + } + + switch (cmd) { + case "set-location-enabled": { + int userId = parseUserId(); + boolean enabled = Boolean.parseBoolean(getNextArgRequired()); + mService.setLocationEnabledForUser(enabled, userId); + return 0; + } + case "send-extra-command": { + String provider = getNextArgRequired(); + String command = getNextArgRequired(); + mService.sendExtraCommand(provider, command, null); + return 0; + } + default: + return handleDefaultCommands(cmd); + } + } + + private int parseUserId() { + final String option = getNextOption(); + if (option != null) { + if (option.equals("--user")) { + return UserHandle.parseUserArg(getNextArgRequired()); + } else { + throw new IllegalArgumentException( + "Expected \"--user\" option, but got \"" + option + "\" instead"); + } + } + + return UserHandle.USER_CURRENT_OR_SELF; + } + + @Override + public void onHelp() { + PrintWriter pw = getOutPrintWriter(); + pw.println("Location service commands:"); + pw.println(" help or -h"); + pw.println(" Print this help text."); + pw.println(" set-location-enabled [--user ] true|false"); + pw.println(" Sets the master location switch enabled state."); + pw.println(" send-extra-command "); + pw.println(" Sends the given extra command to the given provider."); + pw.println(); + pw.println(" Common commands that may be supported by the gps provider, depending on"); + pw.println(" hardware and software configurations:"); + pw.println(" delete_aiding_data - requests deletion of any predictive aiding data"); + pw.println(" force_time_injection - requests NTP time injection to chipset"); + pw.println(" force_psds_injection - " + + "requests predictive aiding data injection to chipset"); + } +} -- GitLab From 7d7ce5135ccc3d08c03b31fd69b9101c081ec439 Mon Sep 17 00:00:00 2001 From: Collin Fijalkovich Date: Thu, 2 Apr 2020 13:32:32 -0700 Subject: [PATCH 04/56] Cache getActiveDataSubscriptionId Binder calls Use PropertyInvalidatedCache to avoid redundant calls to SubscriptionController.getActiveDataSubscriptionId. Bug: 151953109 Test: Verified cache operated correctly when phone process is killed. Test: atest SubscriptionControllerTest Test: atest android.telephony.cts.SubscriptionManagerTest Merged-In: I45d1abf15e4b105c966d4a786a4dc33aa67b20aa Change-Id: I45d1abf15e4b105c966d4a786a4dc33aa67b20aa --- .../telephony/SubscriptionManager.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 45dc7afc3dc0..a254f240a20b 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -139,6 +139,10 @@ public class SubscriptionManager { public static final String CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY = "cache_key.telephony.get_default_data_sub_id"; + /** @hide */ + public static final String CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY = + "cache_key.telephony.get_active_data_sub_id"; + private static final int MAX_CACHE_SIZE = 4; private static PropertyInvalidatedCache sDefaultSubIdCache = @@ -157,6 +161,14 @@ public class SubscriptionManager { return getDefaultDataSubscriptionIdInternal(); }}; + private static PropertyInvalidatedCache sActiveDataSubIdCache = + new PropertyInvalidatedCache( + MAX_CACHE_SIZE, CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY) { + @Override + protected Integer recompute(Void query) { + return getActiveDataSubscriptionIdInternal(); + }}; + /** * Generates a content {@link Uri} used to receive updates on simInfo change * on the given subscriptionId @@ -3285,6 +3297,10 @@ public class SubscriptionManager { * SubscriptionManager.INVALID_SUBSCRIPTION_ID if not. */ public static int getActiveDataSubscriptionId() { + return sActiveDataSubIdCache.query(null); + } + + private static int getActiveDataSubscriptionIdInternal() { try { ISub iSub = TelephonyManager.getSubscriptionService(); if (iSub != null) { @@ -3320,6 +3336,11 @@ public class SubscriptionManager { PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY); } + /** @hide */ + public static void invalidateActiveDataSubIdCaches() { + PropertyInvalidatedCache.invalidateCache(CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY); + } + /** * Clears all process-local binder caches. * @@ -3328,5 +3349,17 @@ public class SubscriptionManager { public static void clearCaches() { sDefaultSubIdCache.clear(); sDefaultDataSubIdCache.clear(); + sActiveDataSubIdCache.clear(); + } + + /** + * Allows a test process to disable client-side caching operations. + * + * @hide + */ + public static void disableCaching() { + sDefaultSubIdCache.disableLocal(); + sDefaultDataSubIdCache.disableLocal(); + sActiveDataSubIdCache.disableLocal(); } } -- GitLab From 02e5c590c3658023e32754cbac4433f92738b2b3 Mon Sep 17 00:00:00 2001 From: Collin Fijalkovich Date: Mon, 6 Apr 2020 10:54:28 -0700 Subject: [PATCH 05/56] Cache getDefaultSmsSubscriptionId Binder calls Use PropertyInvalidatedCache to avoid redundant calls to SubscriptionController.getDefaultSmsSubscriptionId. Bug: 151953109 Test: Verified cache operated correctly when phone process is killed. Test: atest SubscriptionControllerTest Test: atest android.telephony.cts.SubscriptionManagerTest Merged-In: Iadb6a42b256013021903f75ed72bb5f046bfa2cc Change-Id: Iadb6a42b256013021903f75ed72bb5f046bfa2cc --- .../telephony/SubscriptionManager.java | 50 ++++++++----------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index a254f240a20b..958ec08ea95a 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -139,6 +139,10 @@ public class SubscriptionManager { public static final String CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY = "cache_key.telephony.get_default_data_sub_id"; + /** @hide */ + public static final String CACHE_KEY_DEFAULT_SMS_SUB_ID_PROPERTY = + "cache_key.telephony.get_default_sms_sub_id"; + /** @hide */ public static final String CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY = "cache_key.telephony.get_active_data_sub_id"; @@ -161,13 +165,15 @@ public class SubscriptionManager { return getDefaultDataSubscriptionIdInternal(); }}; + private static PropertyInvalidatedCache sDefaultSmsSubIdCache = + new SubscriptionPropertyInvalidatedCache<>(ISub::getDefaultSmsSubId, + CACHE_KEY_DEFAULT_SMS_SUB_ID_PROPERTY, + INVALID_SUBSCRIPTION_ID); + private static PropertyInvalidatedCache sActiveDataSubIdCache = - new PropertyInvalidatedCache( - MAX_CACHE_SIZE, CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY) { - @Override - protected Integer recompute(Void query) { - return getActiveDataSubscriptionIdInternal(); - }}; + new SubscriptionPropertyInvalidatedCache<>(ISub::getActiveDataSubscriptionId, + CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY, + INVALID_SUBSCRIPTION_ID); /** * Generates a content {@link Uri} used to receive updates on simInfo change @@ -1984,19 +1990,7 @@ public class SubscriptionManager { * @return the default SMS subscription Id. */ public static int getDefaultSmsSubscriptionId() { - int subId = INVALID_SUBSCRIPTION_ID; - - try { - ISub iSub = TelephonyManager.getSubscriptionService(); - if (iSub != null) { - subId = iSub.getDefaultSmsSubId(); - } - } catch (RemoteException ex) { - // ignore it - } - - if (VDBG) logd("getDefaultSmsSubscriptionId, sub id = " + subId); - return subId; + return sDefaultSmsSubIdCache.query(null); } /** @@ -3300,17 +3294,6 @@ public class SubscriptionManager { return sActiveDataSubIdCache.query(null); } - private static int getActiveDataSubscriptionIdInternal() { - try { - ISub iSub = TelephonyManager.getSubscriptionService(); - if (iSub != null) { - return iSub.getActiveDataSubscriptionId(); - } - } catch (RemoteException ex) { - } - return SubscriptionManager.INVALID_SUBSCRIPTION_ID; - } - /** * Helper method that puts a subscription id on an intent with the constants: * PhoneConstant.SUBSCRIPTION_KEY and SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX. @@ -3336,6 +3319,11 @@ public class SubscriptionManager { PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY); } + /** @hide */ + public static void invalidateDefaultSmsSubIdCaches() { + PropertyInvalidatedCache.invalidateCache(CACHE_KEY_DEFAULT_SMS_SUB_ID_PROPERTY); + } + /** @hide */ public static void invalidateActiveDataSubIdCaches() { PropertyInvalidatedCache.invalidateCache(CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY); @@ -3350,6 +3338,7 @@ public class SubscriptionManager { sDefaultSubIdCache.clear(); sDefaultDataSubIdCache.clear(); sActiveDataSubIdCache.clear(); + sDefaultSmsSubIdCache.clear(); } /** @@ -3361,5 +3350,6 @@ public class SubscriptionManager { sDefaultSubIdCache.disableLocal(); sDefaultDataSubIdCache.disableLocal(); sActiveDataSubIdCache.disableLocal(); + sDefaultSmsSubIdCache.disableLocal(); } } -- GitLab From 29b1874ffc19a3e520573b345eb306efe6248870 Mon Sep 17 00:00:00 2001 From: Hall Liu Date: Tue, 7 Apr 2020 18:23:09 -0700 Subject: [PATCH 06/56] Refactor SubscriptionManager caching code Create a genericized class to use for SubscriptionManager caching calls in order to avoid duplicating logic that fetches values from ISub. Bug: 151953109 Test: atest android.telephony.cts.SubscriptionManagerTest Merged-In: I6682ded8aec8cb3e50521584c177df6d5dae8c49 Change-Id: I6682ded8aec8cb3e50521584c177df6d5dae8c49 --- Android.bp | 1 + .../telephony/SubscriptionManager.java | 91 +++++++++---------- 2 files changed, 45 insertions(+), 47 deletions(-) diff --git a/Android.bp b/Android.bp index 935b2bb478bb..ee381a42d728 100644 --- a/Android.bp +++ b/Android.bp @@ -1121,6 +1121,7 @@ filegroup { "core/java/com/android/internal/os/SomeArgs.java", "core/java/com/android/internal/util/BitwiseInputStream.java", "core/java/com/android/internal/util/BitwiseOutputStream.java", + "core/java/com/android/internal/util/FunctionalUtils.java", "core/java/com/android/internal/util/HexDump.java", "core/java/com/android/internal/util/IndentingPrintWriter.java", "core/java/com/android/internal/util/Preconditions.java", diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 958ec08ea95a..ce5412f0fbcc 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -63,6 +63,7 @@ import com.android.internal.telephony.ISetOpportunisticDataCallback; import com.android.internal.telephony.ISub; import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.util.HandlerExecutor; +import com.android.internal.util.FunctionalUtils; import com.android.internal.util.Preconditions; import com.android.telephony.Rlog; @@ -149,21 +150,49 @@ public class SubscriptionManager { private static final int MAX_CACHE_SIZE = 4; - private static PropertyInvalidatedCache sDefaultSubIdCache = - new PropertyInvalidatedCache( - MAX_CACHE_SIZE, CACHE_KEY_DEFAULT_SUB_ID_PROPERTY) { - @Override - protected Integer recompute(Void query) { - return getDefaultSubscriptionIdInternal(); - }}; - - private static PropertyInvalidatedCache sDefaultDataSubIdCache = - new PropertyInvalidatedCache( - MAX_CACHE_SIZE, CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY) { - @Override - protected Integer recompute(Void query) { - return getDefaultDataSubscriptionIdInternal(); - }}; + private static class SubscriptionPropertyInvalidatedCache + extends PropertyInvalidatedCache { + private final FunctionalUtils.ThrowingFunction mSubscriptionInterfaceMethod; + private final String mCacheKeyProperty; + private final T mDefaultValue; + + SubscriptionPropertyInvalidatedCache( + FunctionalUtils.ThrowingFunction subscriptionInterfaceMethod, + String cacheKeyProperty, + T defaultValue) { + super(MAX_CACHE_SIZE, cacheKeyProperty); + mSubscriptionInterfaceMethod = subscriptionInterfaceMethod; + mCacheKeyProperty = cacheKeyProperty; + mDefaultValue = defaultValue; + } + + @Override + protected T recompute(Void aVoid) { + T result = mDefaultValue; + + try { + ISub iSub = TelephonyManager.getSubscriptionService(); + if (iSub != null) { + result = mSubscriptionInterfaceMethod.applyOrThrow(iSub); + } + } catch (Exception ex) { + Rlog.w(LOG_TAG, "Failed to recompute cache key for " + mCacheKeyProperty); + } + + if (VDBG) logd("recomputing " + mCacheKeyProperty + ", result = " + result); + return result; + } + } + + private static SubscriptionPropertyInvalidatedCache sDefaultSubIdCache = + new SubscriptionPropertyInvalidatedCache<>(ISub::getDefaultSubId, + CACHE_KEY_DEFAULT_SUB_ID_PROPERTY, + INVALID_SUBSCRIPTION_ID); + + private static SubscriptionPropertyInvalidatedCache sDefaultDataSubIdCache = + new SubscriptionPropertyInvalidatedCache<>(ISub::getDefaultDataSubId, + CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY, + INVALID_SUBSCRIPTION_ID); private static PropertyInvalidatedCache sDefaultSmsSubIdCache = new SubscriptionPropertyInvalidatedCache<>(ISub::getDefaultSmsSubId, @@ -1888,22 +1917,6 @@ public class SubscriptionManager { return sDefaultSubIdCache.query(null); } - private static int getDefaultSubscriptionIdInternal() { - int subId = INVALID_SUBSCRIPTION_ID; - - try { - ISub iSub = TelephonyManager.getSubscriptionService(); - if (iSub != null) { - subId = iSub.getDefaultSubId(); - } - } catch (RemoteException ex) { - // ignore it - } - - if (VDBG) logd("getDefaultSubId=" + subId); - return subId; - } - /** * Returns the system's default voice subscription id. * @@ -2045,22 +2058,6 @@ public class SubscriptionManager { return sDefaultDataSubIdCache.query(null); } - private static int getDefaultDataSubscriptionIdInternal() { - int subId = INVALID_SUBSCRIPTION_ID; - - try { - ISub iSub = TelephonyManager.getSubscriptionService(); - if (iSub != null) { - subId = iSub.getDefaultDataSubId(); - } - } catch (RemoteException ex) { - // ignore it - } - - if (VDBG) logd("getDefaultDataSubscriptionId, sub id = " + subId); - return subId; - } - /** * Set the subscription which will be used by default for data, with the subscription which * the supplied subscription ID corresponds to; or throw a RuntimeException if the supplied -- GitLab From 41f94629c9f84f9fc1f81bcdc2a2653e732e25b2 Mon Sep 17 00:00:00 2001 From: Collin Fijalkovich Date: Fri, 10 Apr 2020 14:01:42 -0700 Subject: [PATCH 07/56] Cache getPhoneId and getSlotIndex binder calls. Use PropertyInvalidatedCache to avoid redundant calls to SubscriptionController getSlotIndex and getPhoneId. Bug: 151953109 Test: Verified cache operated correctly when phone process is killed. Test: atest SubscriptionControllerTest Test: atest android.telephony.cts.SubscriptionManagerTest Change-Id: I70552537af44f3e05b156cd190ebb28f0d940bf6 --- .../internal/util/FunctionalUtils.java | 27 ++++ .../telephony/SubscriptionManager.java | 146 ++++++++++-------- 2 files changed, 109 insertions(+), 64 deletions(-) diff --git a/core/java/com/android/internal/util/FunctionalUtils.java b/core/java/com/android/internal/util/FunctionalUtils.java index 9168438dc2bf..05ecdf905623 100644 --- a/core/java/com/android/internal/util/FunctionalUtils.java +++ b/core/java/com/android/internal/util/FunctionalUtils.java @@ -21,6 +21,7 @@ import android.os.RemoteException; import android.util.ExceptionUtils; import java.util.function.BiConsumer; +import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; @@ -195,6 +196,32 @@ public class FunctionalUtils { } } + /** + * A {@link BiFunction} that allows throwing checked exceptions from its single abstract method. + * + * Can be used together with {@link #uncheckExceptions} to effectively turn a lambda expression + * that throws a checked exception into a regular {@link BiFunction} + * + * @param see {@link BiFunction} + * @param see {@link BiFunction} + * @param see {@link BiFunction} + */ + @FunctionalInterface + @SuppressWarnings("FunctionalInterfaceMethodChanged") + public interface ThrowingBiFunction extends BiFunction { + /** @see ThrowingFunction */ + R applyOrThrow(T t, U u) throws Exception; + + @Override + default R apply(T t, U u) { + try { + return applyOrThrow(t, u); + } catch (Exception ex) { + throw ExceptionUtils.propagate(ex); + } + } + } + /** * A {@link BiConsumer} that allows throwing checked exceptions from its single abstract method. * diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index ce5412f0fbcc..e9ee06c246ba 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -148,20 +148,24 @@ public class SubscriptionManager { public static final String CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY = "cache_key.telephony.get_active_data_sub_id"; + /** @hide */ + public static final String CACHE_KEY_SLOT_INDEX_PROPERTY = + "cache_key.telephony.get_slot_index"; + private static final int MAX_CACHE_SIZE = 4; - private static class SubscriptionPropertyInvalidatedCache + private static class VoidPropertyInvalidatedCache extends PropertyInvalidatedCache { - private final FunctionalUtils.ThrowingFunction mSubscriptionInterfaceMethod; + private final FunctionalUtils.ThrowingFunction mInterfaceMethod; private final String mCacheKeyProperty; private final T mDefaultValue; - SubscriptionPropertyInvalidatedCache( + VoidPropertyInvalidatedCache( FunctionalUtils.ThrowingFunction subscriptionInterfaceMethod, String cacheKeyProperty, T defaultValue) { super(MAX_CACHE_SIZE, cacheKeyProperty); - mSubscriptionInterfaceMethod = subscriptionInterfaceMethod; + mInterfaceMethod = subscriptionInterfaceMethod; mCacheKeyProperty = cacheKeyProperty; mDefaultValue = defaultValue; } @@ -173,7 +177,41 @@ public class SubscriptionManager { try { ISub iSub = TelephonyManager.getSubscriptionService(); if (iSub != null) { - result = mSubscriptionInterfaceMethod.applyOrThrow(iSub); + result = mInterfaceMethod.applyOrThrow(iSub); + } + } catch (Exception ex) { + Rlog.w(LOG_TAG, "Failed to recompute cache key for " + mCacheKeyProperty); + } + + if (VDBG) logd("recomputing " + mCacheKeyProperty + ", result = " + result); + return result; + } + } + + private static class IntegerPropertyInvalidatedCache + extends PropertyInvalidatedCache { + private final FunctionalUtils.ThrowingBiFunction mInterfaceMethod; + private final String mCacheKeyProperty; + private final T mDefaultValue; + + IntegerPropertyInvalidatedCache( + FunctionalUtils.ThrowingBiFunction subscriptionInterfaceMethod, + String cacheKeyProperty, + T defaultValue) { + super(MAX_CACHE_SIZE, cacheKeyProperty); + mInterfaceMethod = subscriptionInterfaceMethod; + mCacheKeyProperty = cacheKeyProperty; + mDefaultValue = defaultValue; + } + + @Override + protected T recompute(Integer query) { + T result = mDefaultValue; + + try { + ISub iSub = TelephonyManager.getSubscriptionService(); + if (iSub != null) { + result = mInterfaceMethod.applyOrThrow(iSub, query); } } catch (Exception ex) { Rlog.w(LOG_TAG, "Failed to recompute cache key for " + mCacheKeyProperty); @@ -184,26 +222,37 @@ public class SubscriptionManager { } } - private static SubscriptionPropertyInvalidatedCache sDefaultSubIdCache = - new SubscriptionPropertyInvalidatedCache<>(ISub::getDefaultSubId, + private static VoidPropertyInvalidatedCache sDefaultSubIdCache = + new VoidPropertyInvalidatedCache<>(ISub::getDefaultSubId, CACHE_KEY_DEFAULT_SUB_ID_PROPERTY, INVALID_SUBSCRIPTION_ID); - private static SubscriptionPropertyInvalidatedCache sDefaultDataSubIdCache = - new SubscriptionPropertyInvalidatedCache<>(ISub::getDefaultDataSubId, + private static VoidPropertyInvalidatedCache sDefaultDataSubIdCache = + new VoidPropertyInvalidatedCache<>(ISub::getDefaultDataSubId, CACHE_KEY_DEFAULT_DATA_SUB_ID_PROPERTY, INVALID_SUBSCRIPTION_ID); - private static PropertyInvalidatedCache sDefaultSmsSubIdCache = - new SubscriptionPropertyInvalidatedCache<>(ISub::getDefaultSmsSubId, + private static VoidPropertyInvalidatedCache sDefaultSmsSubIdCache = + new VoidPropertyInvalidatedCache<>(ISub::getDefaultSmsSubId, CACHE_KEY_DEFAULT_SMS_SUB_ID_PROPERTY, INVALID_SUBSCRIPTION_ID); - private static PropertyInvalidatedCache sActiveDataSubIdCache = - new SubscriptionPropertyInvalidatedCache<>(ISub::getActiveDataSubscriptionId, + private static VoidPropertyInvalidatedCache sActiveDataSubIdCache = + new VoidPropertyInvalidatedCache<>(ISub::getActiveDataSubscriptionId, CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY, INVALID_SUBSCRIPTION_ID); + private static IntegerPropertyInvalidatedCache sSlotIndexCache = + new IntegerPropertyInvalidatedCache<>(ISub::getSlotIndex, + CACHE_KEY_SLOT_INDEX_PROPERTY, + INVALID_SIM_SLOT_INDEX); + + /** Cache depends on getDefaultSubId, so we use the defaultSubId cache key */ + private static IntegerPropertyInvalidatedCache sPhoneIdCache = + new IntegerPropertyInvalidatedCache<>(ISub::getPhoneId, + CACHE_KEY_DEFAULT_SUB_ID_PROPERTY, + INVALID_PHONE_INDEX); + /** * Generates a content {@link Uri} used to receive updates on simInfo change * on the given subscriptionId @@ -1246,7 +1295,6 @@ public class SubscriptionManager { } return subInfo; - } /** @@ -1816,25 +1864,7 @@ public class SubscriptionManager { * subscriptionId doesn't have an associated slot index. */ public static int getSlotIndex(int subscriptionId) { - if (!isValidSubscriptionId(subscriptionId)) { - if (DBG) { - logd("[getSlotIndex]- supplied subscriptionId is invalid."); - } - } - - int result = INVALID_SIM_SLOT_INDEX; - - try { - ISub iSub = TelephonyManager.getSubscriptionService(); - if (iSub != null) { - result = iSub.getSlotIndex(subscriptionId); - } - } catch (RemoteException ex) { - // ignore it - } - - return result; - + return sSlotIndexCache.query(subscriptionId); } /** @@ -1873,27 +1903,7 @@ public class SubscriptionManager { /** @hide */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) public static int getPhoneId(int subId) { - if (!isValidSubscriptionId(subId)) { - if (DBG) { - logd("[getPhoneId]- fail"); - } - return INVALID_PHONE_INDEX; - } - - int result = INVALID_PHONE_INDEX; - - try { - ISub iSub = TelephonyManager.getSubscriptionService(); - if (iSub != null) { - result = iSub.getPhoneId(subId); - } - } catch (RemoteException ex) { - // ignore it - } - - if (VDBG) logd("[getPhoneId]- phoneId=" + result); - return result; - + return sPhoneIdCache.query(subId); } private static void logd(String msg) { @@ -3326,16 +3336,9 @@ public class SubscriptionManager { PropertyInvalidatedCache.invalidateCache(CACHE_KEY_ACTIVE_DATA_SUB_ID_PROPERTY); } - /** - * Clears all process-local binder caches. - * - * @hide - */ - public static void clearCaches() { - sDefaultSubIdCache.clear(); - sDefaultDataSubIdCache.clear(); - sActiveDataSubIdCache.clear(); - sDefaultSmsSubIdCache.clear(); + /** @hide */ + public static void invalidateSlotIndexCaches() { + PropertyInvalidatedCache.invalidateCache(CACHE_KEY_SLOT_INDEX_PROPERTY); } /** @@ -3348,5 +3351,20 @@ public class SubscriptionManager { sDefaultDataSubIdCache.disableLocal(); sActiveDataSubIdCache.disableLocal(); sDefaultSmsSubIdCache.disableLocal(); + sSlotIndexCache.disableLocal(); + sPhoneIdCache.disableLocal(); + } + + /** + * Clears all process-local binder caches. + * + * @hide */ + public static void clearCaches() { + sDefaultSubIdCache.clear(); + sDefaultDataSubIdCache.clear(); + sActiveDataSubIdCache.clear(); + sDefaultSmsSubIdCache.clear(); + sSlotIndexCache.clear(); + sPhoneIdCache.clear(); } } -- GitLab From ee11625bb707c3512d4e44a35cc85b0bd14a2478 Mon Sep 17 00:00:00 2001 From: lumark Date: Mon, 10 Feb 2020 18:41:57 +0800 Subject: [PATCH 08/56] [RESTRICT AUTOMERGE] Restrict app transition maximum duration As WindowState#startAnimation for restricting window animation duration (currently is 10 secs), For security reason, we also need to restrict app transition animation duration as 3 secs to prevent malicious app may set a long duration or infinity repeat counts through ActivityOption#makeCustomAnimation or Activity#overridePendingTransition with custom animation set. Bug: 145728687 Test: manual as issue provided test app Change-Id: I39051d6e4d2b681ce2becbafe14aab3f3d8ebf6b --- .../java/com/android/server/wm/AppTransition.java | 1 + .../java/com/android/server/wm/AppWindowToken.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wm/AppTransition.java b/services/core/java/com/android/server/wm/AppTransition.java index d73606f3003f..51b7279c97e8 100644 --- a/services/core/java/com/android/server/wm/AppTransition.java +++ b/services/core/java/com/android/server/wm/AppTransition.java @@ -161,6 +161,7 @@ public class AppTransition implements Dump { private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420; private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336; private static final long APP_TRANSITION_TIMEOUT_MS = 5000; + static final int MAX_APP_TRANSITION_DURATION = 3 * 1000; // 3 secs. private final Context mContext; private final WindowManagerService mService; diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java index bd5d35eae77d..23af7d6755cd 100644 --- a/services/core/java/com/android/server/wm/AppWindowToken.java +++ b/services/core/java/com/android/server/wm/AppWindowToken.java @@ -1843,7 +1843,16 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets, surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId); if (a != null) { - if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this); + if (a != null) { + // Setup the maximum app transition duration to prevent malicious app may set a long + // animation duration or infinite repeat counts for the app transition through + // ActivityOption#makeCustomAnimation or WindowManager#overridePendingTransition. + a.restrictDuration(MAX_APP_TRANSITION_DURATION); + } + if (DEBUG_ANIM) { + logWithStack(TAG, "Loaded animation " + a + " for " + this + + ", duration: " + ((a != null) ? a.getDuration() : 0)); + } final int containingWidth = frame.width(); final int containingHeight = frame.height(); a.initialize(containingWidth, containingHeight, width, height); -- GitLab From 6189fa4c800312fe5973ed7768ccf7d7b0c1d599 Mon Sep 17 00:00:00 2001 From: Ben Lin Date: Wed, 29 Apr 2020 14:59:16 -0700 Subject: [PATCH 09/56] Make PipTaskManager Injectable. Bug: 155328845 Test: Build Change-Id: I5e470824339af9cf605052f74e8f882a43de05d3 --- .../src/com/android/systemui/pip/PipBoundsHandler.java | 2 ++ .../src/com/android/systemui/pip/PipTaskOrganizer.java | 5 +++++ .../src/com/android/systemui/pip/phone/PipManager.java | 4 ++-- .../SystemUI/src/com/android/systemui/pip/tv/PipManager.java | 4 ++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java b/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java index 9d9e74abc38f..3eeadc367b0d 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java +++ b/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java @@ -43,11 +43,13 @@ import android.window.WindowContainerTransaction; import java.io.PrintWriter; import javax.inject.Inject; +import javax.inject.Singleton; /** * Handles bounds calculation for PIP on Phone and other form factors, it keeps tracking variant * state changes originated from Window Manager and is the source of truth for PiP window bounds. */ +@Singleton public class PipBoundsHandler { private static final String TAG = PipBoundsHandler.class.getSimpleName(); diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java b/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java index 9c8fb7c52eec..43e6df502621 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java +++ b/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java @@ -58,6 +58,9 @@ import java.util.Map; import java.util.Objects; import java.util.function.Consumer; +import javax.inject.Inject; +import javax.inject.Singleton; + /** * Manages PiP tasks such as resize and offset. * @@ -69,6 +72,7 @@ import java.util.function.Consumer; * This class is also responsible for general resize/offset PiP operations within SysUI component, * see also {@link com.android.systemui.pip.phone.PipMotionHelper}. */ +@Singleton public class PipTaskOrganizer extends TaskOrganizer { private static final String TAG = PipTaskOrganizer.class.getSimpleName(); @@ -191,6 +195,7 @@ public class PipTaskOrganizer extends TaskOrganizer { private PipSurfaceTransactionHelper.SurfaceControlTransactionFactory mSurfaceControlTransactionFactory; + @Inject public PipTaskOrganizer(Context context, @NonNull PipBoundsHandler boundsHandler, @NonNull PipSurfaceTransactionHelper surfaceTransactionHelper, @Nullable Divider divider) { diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java index a86a884c8016..0841bb70f205 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java @@ -200,6 +200,7 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio DeviceConfigProxy deviceConfig, PipBoundsHandler pipBoundsHandler, PipSnapAlgorithm pipSnapAlgorithm, + PipTaskOrganizer pipTaskOrganizer, PipSurfaceTransactionHelper surfaceTransactionHelper, Divider divider) { mContext = context; @@ -215,8 +216,7 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio final IActivityTaskManager activityTaskManager = ActivityTaskManager.getService(); mPipBoundsHandler = pipBoundsHandler; - mPipTaskOrganizer = new PipTaskOrganizer(context, pipBoundsHandler, - surfaceTransactionHelper, divider); + mPipTaskOrganizer = pipTaskOrganizer; mPipTaskOrganizer.registerPipTransitionCallback(this); mInputConsumerController = InputConsumerController.getPipInputConsumer(); mMediaController = new PipMediaController(context, mActivityManager, broadcastDispatcher); diff --git a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java index fae8af4f575a..f49732d98ae8 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java +++ b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java @@ -233,6 +233,7 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio @Inject public PipManager(Context context, BroadcastDispatcher broadcastDispatcher, PipBoundsHandler pipBoundsHandler, + PipTaskOrganizer pipTaskOrganizer, PipSurfaceTransactionHelper surfaceTransactionHelper, Divider divider) { if (mInitialized) { @@ -250,8 +251,7 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio mResizeAnimationDuration = context.getResources() .getInteger(R.integer.config_pipResizeAnimationDuration); - mPipTaskOrganizer = new PipTaskOrganizer(mContext, mPipBoundsHandler, - surfaceTransactionHelper, divider); + mPipTaskOrganizer = pipTaskOrganizer; mPipTaskOrganizer.registerPipTransitionCallback(this); mActivityTaskManager = ActivityTaskManager.getService(); ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); -- GitLab From 5c3aa4d4121a21f14b44197ceacd43df30febd1c Mon Sep 17 00:00:00 2001 From: Ruslan Tkhakokhov Date: Thu, 30 Apr 2020 22:24:06 +0100 Subject: [PATCH 10/56] Remove MASTER_MONO from replaced settings Bug: 153940088 Test: build In ag/11078633 we added logic for special-casing B&R of temporarily replaced system settings. Remove Settings.System.MASTER_MONO from that list as it won't be replaced anymore. Change-Id: I27e519c58b9d621465c882d8ed2532bfda884d02 --- .../src/com/android/providers/settings/SettingsHelper.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java index d023d98f2b73..028c3041a50d 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java @@ -225,8 +225,7 @@ public class SettingsHelper { @VisibleForTesting public boolean isReplacedSystemSetting(String setting) { // This list should not be modified. - if (!Settings.System.MASTER_MONO.equals(setting) - && !Settings.System.SCREEN_OFF_TIMEOUT.equals(setting)) { + if (!Settings.System.SCREEN_OFF_TIMEOUT.equals(setting)) { return false; } // If this flag is set, values for the system settings from the list above have been -- GitLab From a61906457c647a49cda34aafebcff331b681f1a5 Mon Sep 17 00:00:00 2001 From: Kevin Han Date: Thu, 30 Apr 2020 15:22:16 -0700 Subject: [PATCH 11/56] Don't throw exception for inflation after removal There are some cases where we seem to be inflating after the removal of a notification, most likely related to a re-entrant call where we remove a notification as part of a notification update listener. This throws an exception since we assume a removed notification doesn't need to inflate anything. Until we fix the underlying issue, we loosen the guarantee and remove the exception and instead just return early. Bug: 155324756 Test: builds Change-Id: I702391311e9d06319f4d93dd584ecc2a4dd78a36 --- .../systemui/statusbar/notification/row/BindStage.java | 9 +++++++-- .../statusbar/notification/row/NotifBindPipeline.java | 8 +++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/BindStage.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/BindStage.java index 29447caa1240..cc917dda2a80 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/BindStage.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/BindStage.java @@ -18,6 +18,7 @@ package com.android.systemui.statusbar.notification.row; import android.annotation.MainThread; import android.util.ArrayMap; +import android.util.Log; import androidx.annotation.NonNull; @@ -66,8 +67,10 @@ public abstract class BindStage extends BindRequester { public final Params getStageParams(@NonNull NotificationEntry entry) { Params params = mContentParams.get(entry); if (params == null) { - throw new IllegalStateException( - String.format("Entry does not have any stage parameters. key: %s", + // TODO: This should throw an exception but there are some cases of re-entrant calls + // in NotificationEntryManager (e.g. b/155324756) that cause removal in update that + // lead to inflation after the notification is "removed". + Log.wtf(TAG, String.format("Entry does not have any stage parameters. key: %s", entry.getKey())); } return params; @@ -92,6 +95,8 @@ public abstract class BindStage extends BindRequester { */ protected abstract Params newStageParams(); + private static final String TAG = "BindStage"; + /** * Interface for callback. */ diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotifBindPipeline.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotifBindPipeline.java index e4e3ebcf7671..3ee267362bc0 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotifBindPipeline.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotifBindPipeline.java @@ -115,6 +115,9 @@ public final class NotifBindPipeline { mLogger.logManagedRow(entry.getKey()); final BindEntry bindEntry = getBindEntry(entry); + if (bindEntry == null) { + return; + } bindEntry.row = row; if (bindEntry.invalidated) { requestPipelineRun(entry); @@ -223,11 +226,6 @@ public final class NotifBindPipeline { private @NonNull BindEntry getBindEntry(NotificationEntry entry) { final BindEntry bindEntry = mBindEntries.get(entry); - if (bindEntry == null) { - throw new IllegalStateException( - String.format("Attempting bind on an inactive notification. key: %s", - entry.getKey())); - } return bindEntry; } -- GitLab From 7fb4030829ea5212a0ed1c9da5d3f8e2457c8c66 Mon Sep 17 00:00:00 2001 From: Will Brockman Date: Fri, 1 May 2020 10:42:43 -0400 Subject: [PATCH 12/56] Statsd testdrive: remove debug line. Oops, left the old output in the submitted CL that changed to a new output approach. Bug: 149914234 Test: atest --host frameworks/base/cmds/statsd/tools/localtools/test/com/android/statsd/shelltools/testdrive/*.java Test: statsd_testdrive 90 > /tmp/testdrive Change-Id: Ib9542e478a57ad56d9fe2a0e97cb18a05d5d2535 --- .../src/com/android/statsd/shelltools/testdrive/TestDrive.java | 1 - 1 file changed, 1 deletion(-) diff --git a/cmds/statsd/tools/localtools/src/com/android/statsd/shelltools/testdrive/TestDrive.java b/cmds/statsd/tools/localtools/src/com/android/statsd/shelltools/testdrive/TestDrive.java index a97f132a2d5f..6384fb12ca68 100644 --- a/cmds/statsd/tools/localtools/src/com/android/statsd/shelltools/testdrive/TestDrive.java +++ b/cmds/statsd/tools/localtools/src/com/android/statsd/shelltools/testdrive/TestDrive.java @@ -208,7 +208,6 @@ public class TestDrive { ConfigMetricsReport report = reportList.getReports(reportList.getReportsCount() - 1); for (StatsLogReport statsLog : report.getMetricsList()) { if (isTrackedMetric(statsLog.getMetricId())) { - LOGGER.info(statsLog.toString()); dumper.dump(statsLog); } } -- GitLab From 45922c965541ecc5f148b55f929f44ca75c7c42c Mon Sep 17 00:00:00 2001 From: Kevin Han Date: Fri, 1 May 2020 12:30:36 -0700 Subject: [PATCH 13/56] Actually inject TargetSdkResolver Dagger didn't create TargetSdkResolver since it was never used anywhere so we explicitly initialize it so that we actually set the targetSdk on notificattions. Bug: 155170086 Fix: 155170086 Test: Post remote view with wrap content and it correctly uses post P min height Change-Id: Iadcb4d47110de374663244116033ba0a74a1a8ee Change-Id: If27f62c8a795efea4f510f2fd3f7c645e884d31f --- .../statusbar/notification/collection/TargetSdkResolver.kt | 5 ++--- .../notification/init/NotificationsControllerImpl.kt | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/TargetSdkResolver.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/TargetSdkResolver.kt index 1c1b2bb087f0..a0f9dc91ce68 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/TargetSdkResolver.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/TargetSdkResolver.kt @@ -28,10 +28,9 @@ import javax.inject.Singleton @Singleton class TargetSdkResolver @Inject constructor( - private val context: Context, - private val collection: CommonNotifCollection + private val context: Context ) { - init { + fun initialize(collection: CommonNotifCollection) { collection.addCollectionListener(object : NotifCollectionListener { override fun onEntryBind(entry: NotificationEntry, sbn: StatusBarNotification) { entry.targetSdk = resolveNotificationSdk(sbn) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/init/NotificationsControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/init/NotificationsControllerImpl.kt index c9754048e1d1..6e4fcd5f97b1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/init/NotificationsControllerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/init/NotificationsControllerImpl.kt @@ -25,8 +25,10 @@ import com.android.systemui.statusbar.notification.NotificationActivityStarter import com.android.systemui.statusbar.notification.NotificationClicker import com.android.systemui.statusbar.notification.NotificationEntryManager import com.android.systemui.statusbar.notification.NotificationListController +import com.android.systemui.statusbar.notification.collection.NotifPipeline import com.android.systemui.statusbar.notification.collection.inflation.NotificationRowBinderImpl import com.android.systemui.statusbar.notification.collection.init.NotifPipelineInitializer +import com.android.systemui.statusbar.notification.collection.TargetSdkResolver import com.android.systemui.statusbar.notification.interruption.HeadsUpController import com.android.systemui.statusbar.notification.row.NotifBindPipelineInitializer import com.android.systemui.statusbar.notification.stack.NotificationListContainer @@ -56,6 +58,8 @@ class NotificationsControllerImpl @Inject constructor( private val featureFlags: FeatureFlags, private val notificationListener: NotificationListener, private val entryManager: NotificationEntryManager, + private val notifPipeline: Lazy, + private val targetSdkResolver: TargetSdkResolver, private val newNotifPipeline: Lazy, private val notifBindPipelineInitializer: NotifBindPipelineInitializer, private val deviceProvisionedController: DeviceProvisionedController, @@ -102,8 +106,10 @@ class NotificationsControllerImpl @Inject constructor( } if (featureFlags.isNewNotifPipelineRenderingEnabled) { + targetSdkResolver.initialize(notifPipeline.get()) // TODO } else { + targetSdkResolver.initialize(entryManager) remoteInputUriController.attach(entryManager) groupAlertTransferHelper.bind(entryManager, groupManager) headsUpManager.addListener(groupManager) -- GitLab From 8bdf7000885d0d01a377001423e06e6101fc27b6 Mon Sep 17 00:00:00 2001 From: Sunny Shao Date: Sun, 29 Mar 2020 11:52:52 +0800 Subject: [PATCH 14/56] Enable the settings_controller_loading_enhancement - Enable some settings pages to use paralleled loading approach. Bug: 137558156 Test: compilation Change-Id: I7302de2413c14a7573adf2f9949ac28866557e2f --- core/java/android/util/FeatureFlagUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/java/android/util/FeatureFlagUtils.java b/core/java/android/util/FeatureFlagUtils.java index cd20b357e2f1..6c619bb172a6 100644 --- a/core/java/android/util/FeatureFlagUtils.java +++ b/core/java/android/util/FeatureFlagUtils.java @@ -62,7 +62,7 @@ public class FeatureFlagUtils { DEFAULT_FLAGS.put("settings_wifi_details_datausage_header", "false"); DEFAULT_FLAGS.put("settings_skip_direction_mutable", "true"); DEFAULT_FLAGS.put(SETTINGS_WIFITRACKER2, "true"); - DEFAULT_FLAGS.put("settings_controller_loading_enhancement", "false"); + DEFAULT_FLAGS.put("settings_controller_loading_enhancement", "true"); DEFAULT_FLAGS.put("settings_conditionals", "false"); // This flags guards a feature introduced in R and will be removed in the next release // (b/148367230). -- GitLab From 98578b7e28cbd9ad2d4fae3fabc662bf242c9d3e Mon Sep 17 00:00:00 2001 From: Louis Chang Date: Tue, 28 Apr 2020 15:22:39 +0800 Subject: [PATCH 15/56] Reset Divider#mMinimized when dismiss split The divider view did not animate while minimizing dock stack because the mMinimized did not reset after split-screen dismissed. Bug: 153579514 Test: enter split-screen Change-Id: I4fa8d773df0a781aa718331fc70f7f94928fdb29 --- .../src/com/android/systemui/stackdivider/Divider.java | 5 +++++ .../systemui/stackdivider/SplitScreenTaskOrganizer.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java b/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java index 555202a2b02c..84de45f23b62 100644 --- a/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java +++ b/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java @@ -634,6 +634,11 @@ public class Divider extends SystemUI implements DividerView.DividerCallbacks, } } + void onSplitDismissed() { + mMinimized = false; + updateVisibility(false /* visible */); + } + /** Switch to minimized state if appropriate */ public void setMinimized(final boolean minimized) { if (DEBUG) Slog.d(TAG, "posting ext setMinimized " + minimized + " vis:" + mVisible); diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/SplitScreenTaskOrganizer.java b/packages/SystemUI/src/com/android/systemui/stackdivider/SplitScreenTaskOrganizer.java index 717edc591d7f..2862c836942f 100644 --- a/packages/SystemUI/src/com/android/systemui/stackdivider/SplitScreenTaskOrganizer.java +++ b/packages/SystemUI/src/com/android/systemui/stackdivider/SplitScreenTaskOrganizer.java @@ -201,7 +201,7 @@ class SplitScreenTaskOrganizer extends TaskOrganizer { + mPrimary.topActivityType + " " + mSecondary.topActivityType); } WindowManagerProxy.applyDismissSplit(this, true /* dismissOrMaximize */); - mDivider.updateVisibility(false /* visible */); + mDivider.onSplitDismissed(); } else if (!primaryIsEmpty && primaryWasEmpty && secondaryWasEmpty) { // Wasn't in split-mode (both were empty), but now that the primary split is // populated, we should fully enter split by moving everything else into secondary. -- GitLab From 8bf81dffa92879fda1d33e20806658e84f1a6614 Mon Sep 17 00:00:00 2001 From: Chi Zhang Date: Fri, 1 May 2020 11:23:28 -0700 Subject: [PATCH 16/56] Add dimension to VOICE_CALL_SESSION atom. Bug: 142026991 Bug: 141631489 Test: build Change-Id: I320611ee871c7feae53e3e67fcdf8cbab0be241b --- cmds/statsd/src/atoms.proto | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto index 3017ec024151..e6a96283eb76 100644 --- a/cmds/statsd/src/atoms.proto +++ b/cmds/statsd/src/atoms.proto @@ -9096,6 +9096,9 @@ message VoiceCallSession { // Whether the call was performed while roaming. optional bool is_roaming = 24; + + // A random number used as the dimension field to pull multiple atoms. + optional int32 dimension = 25; } /** -- GitLab From d1cb4404fe7e6751f29c9a40e0c50a815a7e6a78 Mon Sep 17 00:00:00 2001 From: Tony Huang Date: Mon, 27 Apr 2020 11:36:00 +0800 Subject: [PATCH 17/56] Start IME animation if its insets update after show Some IME might update its insets after showInsets callback, it should abnormal but we still should be robust to handle such case. Fix it by re-calling startAnimation. If it call while animation, it should cancel previous one and start new one. If animation end, it will run a new animation. Bug: 151628536 Test: force stop Gboard, enter split mode and click text filed on secondary split. Change-Id: I31d8e800ef9fc67406cd7c7902b1c597e9c8dcbe --- .../android/systemui/stackdivider/Divider.java | 16 +++++++++------- .../systemui/wm/DisplayImeController.java | 10 ++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java b/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java index 555202a2b02c..c02dd988b6c7 100644 --- a/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java +++ b/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java @@ -211,14 +211,16 @@ public class Divider extends SystemUI implements DividerView.DividerCallbacks, mTargetShown = imeShouldShow; if (mLastAdjustTop < 0) { mLastAdjustTop = imeShouldShow ? hiddenTop : shownTop; - } else { - // Check for an "interruption" of an existing animation. In this case, we need to - // fake-flip the last-known state direction so that the animation completes in the - // other direction. + } else if (mLastAdjustTop != (imeShouldShow ? mShownTop : mHiddenTop)) { if (mTargetAdjusted != targetAdjusted && targetAdjusted == mAdjusted) { - if (mLastAdjustTop != (imeShouldShow ? mShownTop : mHiddenTop)) { - mAdjusted = mTargetAdjusted; - } + // Check for an "interruption" of an existing animation. In this case, we + // need to fake-flip the last-known state direction so that the animation + // completes in the other direction. + mAdjusted = mTargetAdjusted; + } else if (targetAdjusted && mTargetAdjusted && mAdjusted) { + // Already fully adjusted for IME, but IME height has changed; so, force-start + // an async animation to the new IME height. + mAdjusted = false; } } if (mPaused) { diff --git a/packages/SystemUI/src/com/android/systemui/wm/DisplayImeController.java b/packages/SystemUI/src/com/android/systemui/wm/DisplayImeController.java index c22b718fa50f..c7e9accce093 100644 --- a/packages/SystemUI/src/com/android/systemui/wm/DisplayImeController.java +++ b/packages/SystemUI/src/com/android/systemui/wm/DisplayImeController.java @@ -21,6 +21,7 @@ import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.content.res.Configuration; import android.graphics.Point; +import android.graphics.Rect; import android.os.Handler; import android.os.RemoteException; import android.util.Slog; @@ -188,7 +189,16 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged if (mInsetsState.equals(insetsState)) { return; } + + final InsetsSource newSource = insetsState.getSource(InsetsState.ITYPE_IME); + final Rect newFrame = newSource.getFrame(); + final Rect oldFrame = mInsetsState.getSource(InsetsState.ITYPE_IME).getFrame(); + mInsetsState.set(insetsState, true /* copySources */); + if (mImeShowing && !newFrame.equals(oldFrame) && newSource.isVisible()) { + if (DEBUG) Slog.d(TAG, "insetsChanged when IME showing, restart animation"); + startAnimation(mImeShowing, true /* forceRestart */); + } } @Override -- GitLab From 97104355c1b687f72e26669f425c4068b5a4c084 Mon Sep 17 00:00:00 2001 From: hughchen Date: Mon, 4 May 2020 13:51:06 +0800 Subject: [PATCH 18/56] Remove the check condition of connect device This CL remove check condition of connect device, we should send the callback even connect device is same as previously. Bug: 155594353 Test: make -j42 RunSettingsLibRoboTests Change-Id: I61d547cc4c33c1f031d76c513f9d544a53795110 --- .../src/com/android/settingslib/media/LocalMediaManager.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java b/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java index af691783e85d..f05f9108469c 100644 --- a/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java +++ b/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java @@ -465,10 +465,7 @@ public class LocalMediaManager implements BluetoothCallback { if (connectDevice != null) { connectDevice.setState(MediaDeviceState.STATE_CONNECTED); } - if (connectDevice == mCurrentConnectedDevice) { - Log.d(TAG, "onConnectedDeviceChanged() this device all ready connected!"); - return; - } + mCurrentConnectedDevice = connectDevice; dispatchSelectedDeviceStateChanged(mCurrentConnectedDevice, MediaDeviceState.STATE_CONNECTED); -- GitLab From bf9dfb6623185f924df7348103471084923a02ed Mon Sep 17 00:00:00 2001 From: Tony Mak Date: Mon, 4 May 2020 16:10:47 +0100 Subject: [PATCH 19/56] TCMS should bind the TCS when onSelectionEvent/onTextClassifierEvent ... is called If the system TC (e.g. AiAi) only depends on the default system TC (i.e. ExtService) for logging purposes (i.e. onSelectionEvent() and onTextClassifierEvent()), the TCS in ExtServices will never be bound and the log events will never be delivered to the system default TC. BUG: 155636992 Test: Enable verbose logging and check the logcat Change-Id: I5b77761b8fb0d12906e205200c11e26833b81c1c --- .../textclassifier/TextClassificationManagerService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/textclassifier/TextClassificationManagerService.java b/services/core/java/com/android/server/textclassifier/TextClassificationManagerService.java index 5657c74ce3ad..e675f4e8a46c 100644 --- a/services/core/java/com/android/server/textclassifier/TextClassificationManagerService.java +++ b/services/core/java/com/android/server/textclassifier/TextClassificationManagerService.java @@ -241,7 +241,7 @@ public final class TextClassificationManagerService extends ITextClassifierServi handleRequest( event.getSystemTextClassifierMetadata(), /* verifyCallingPackage= */ true, - /* attemptToBind= */ false, + /* attemptToBind= */ true, service -> service.onSelectionEvent(sessionId, event), "onSelectionEvent", NO_OP_CALLBACK); @@ -260,7 +260,7 @@ public final class TextClassificationManagerService extends ITextClassifierServi handleRequest( systemTcMetadata, /* verifyCallingPackage= */ true, - /* attemptToBind= */ false, + /* attemptToBind= */ true, service -> service.onTextClassifierEvent(sessionId, event), "onTextClassifierEvent", NO_OP_CALLBACK); -- GitLab From 4429ee6d93b955ec492b618ebf1fffe96f12bf4a Mon Sep 17 00:00:00 2001 From: Fabian Kozynski Date: Mon, 4 May 2020 12:44:41 -0400 Subject: [PATCH 20/56] Fix redlines and strings in Controls dialog Also, make sure that it appears on top of the app Fixes: 155205745 Test: manual Change-Id: I56ebae4ef6bdf1c89850a4ad70be05b37e3cd0cb --- packages/SystemUI/AndroidManifest.xml | 2 +- packages/SystemUI/res/layout/controls_dialog.xml | 2 -- packages/SystemUI/res/values/dimens.xml | 2 +- packages/SystemUI/res/values/strings.xml | 6 +++--- packages/SystemUI/res/values/styles.xml | 6 +++++- .../systemui/controls/management/ControlsRequestReceiver.kt | 1 + 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index 1306657ae403..393674372d81 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -718,7 +718,7 @@ android:finishOnCloseSystemDialogs="true" android:showForAllUsers="true" android:clearTaskOnLaunch="true" - android:launchMode="singleTask" + android:launchMode="singleInstance" android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboard|keyboardHidden" android:excludeFromRecents="true" android:visibleToInstantApps="true"/> diff --git a/packages/SystemUI/res/layout/controls_dialog.xml b/packages/SystemUI/res/layout/controls_dialog.xml index 3effaf5fac5b..5ce9916b0489 100644 --- a/packages/SystemUI/res/layout/controls_dialog.xml +++ b/packages/SystemUI/res/layout/controls_dialog.xml @@ -18,8 +18,6 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:padding="@dimen/controls_dialog_padding" - android:layout_margin="@dimen/controls_dialog_padding" > 2dp 15 - 8dp + 32dp 200dp diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 2b3e661c4f7e..96843f187f72 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -2710,9 +2710,9 @@ Add to device controls - Add to favorites - - %s suggested this control to add to your favorites. + Add + + Suggested by %s Controls updated diff --git a/packages/SystemUI/res/values/styles.xml b/packages/SystemUI/res/values/styles.xml index 6e25625d3b88..b5e7f4bc061e 100644 --- a/packages/SystemUI/res/values/styles.xml +++ b/packages/SystemUI/res/values/styles.xml @@ -768,6 +768,10 @@ 16sp -