diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-10-06 04:34:10 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-10-06 04:34:10 +0000 |
commit | 31aa22cee9c187addd912b320304e609735984d6 (patch) | |
tree | ffff021958dabcfbcfe07f6f712b266e05c8cf49 | |
parent | eec01732751bfc8b8caac4bb8a2869bf48b480d8 (diff) | |
parent | 6f2282196a2274e3b7f80882e70da5b1534169ff (diff) | |
download | base-31aa22cee9c187addd912b320304e609735984d6.tar.gz |
Merge cherrypicks of [20102054, 20111318, 20112890, 20112181] into tm-qpr1-release.
Change-Id: I5f64396d7269ab1d58d9d96db7792c71729606fe
7 files changed, 136 insertions, 122 deletions
diff --git a/core/java/android/app/BroadcastOptions.java b/core/java/android/app/BroadcastOptions.java index f0e14483d98a..aa5fa5b19117 100644 --- a/core/java/android/app/BroadcastOptions.java +++ b/core/java/android/app/BroadcastOptions.java @@ -528,6 +528,28 @@ public class BroadcastOptions extends ComponentOptions { return mIsAlarmBroadcast; } + /** + * Did this broadcast originate from a push message from the server? + * + * @return true if this broadcast is a push message, false otherwise. + * @hide + */ + public boolean isPushMessagingBroadcast() { + return mTemporaryAppAllowlistReasonCode == PowerExemptionManager.REASON_PUSH_MESSAGING; + } + + /** + * Did this broadcast originate from a push message from the server which was over the allowed + * quota? + * + * @return true if this broadcast is a push message over quota, false otherwise. + * @hide + */ + public boolean isPushMessagingOverQuotaBroadcast() { + return mTemporaryAppAllowlistReasonCode + == PowerExemptionManager.REASON_PUSH_MESSAGING_OVER_QUOTA; + } + /** {@hide} */ public long getRequireCompatChangeId() { return mRequireCompatChangeId; diff --git a/core/proto/android/os/processstarttime.proto b/core/proto/android/os/processstarttime.proto deleted file mode 100644 index d0f8baee7da2..000000000000 --- a/core/proto/android/os/processstarttime.proto +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -syntax = "proto2"; -package android.os; - -option java_multiple_files = true; - -// This message is used for statsd logging and should be kept in sync with -// frameworks/proto_logging/stats/atoms.proto -/** - * Logs information about process start time. - * - * Logged from: - * frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java - */ -message ProcessStartTime { - // The uid of the ProcessRecord. - optional int32 uid = 1; - - // The process pid. - optional int32 pid = 2; - - // The process name. - // Usually package name, "system" for system server. - // Provided by ActivityManagerService. - optional string process_name = 3; - - enum StartType { - UNKNOWN = 0; - WARM = 1; - HOT = 2; - COLD = 3; - } - - // The start type. - optional StartType type = 4; - - // The elapsed realtime at the start of the process. - optional int64 process_start_time_millis = 5; - - // Number of milliseconds it takes to reach bind application. - optional int32 bind_application_delay_millis = 6; - - // Number of milliseconds it takes to finish start of the process. - optional int32 process_start_delay_millis = 7; - - // hostingType field in ProcessRecord, the component type such as "activity", - // "service", "content provider", "broadcast" or other strings. - optional string hosting_type = 8; - - // hostingNameStr field in ProcessRecord. The component class name that runs - // in this process. - optional string hosting_name = 9; - - // Broadcast action name. - optional string broadcast_action_name = 10; - - enum HostingTypeId { - HOSTING_TYPE_UNKNOWN = 0; - HOSTING_TYPE_ACTIVITY = 1; - HOSTING_TYPE_ADDED_APPLICATION = 2; - HOSTING_TYPE_BACKUP = 3; - HOSTING_TYPE_BROADCAST = 4; - HOSTING_TYPE_CONTENT_PROVIDER = 5; - HOSTING_TYPE_LINK_FAIL = 6; - HOSTING_TYPE_ON_HOLD = 7; - HOSTING_TYPE_NEXT_ACTIVITY = 8; - HOSTING_TYPE_NEXT_TOP_ACTIVITY = 9; - HOSTING_TYPE_RESTART = 10; - HOSTING_TYPE_SERVICE = 11; - HOSTING_TYPE_SYSTEM = 12; - HOSTING_TYPE_TOP_ACTIVITY = 13; - HOSTING_TYPE_EMPTY = 14; - } - - optional HostingTypeId hosting_type_id = 11; -} - diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index 9840e0ff90ce..9669c060b716 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -4219,7 +4219,8 @@ public final class ActiveServices { final String procName = r.processName; HostingRecord hostingRecord = new HostingRecord( HostingRecord.HOSTING_TYPE_SERVICE, r.instanceName, - r.definingPackageName, r.definingUid, r.serviceInfo.processName); + r.definingPackageName, r.definingUid, r.serviceInfo.processName, + getHostingRecordTriggerType(r)); ProcessRecord app; if (!isolated) { @@ -4323,6 +4324,14 @@ public final class ActiveServices { return null; } + private String getHostingRecordTriggerType(ServiceRecord r) { + if (Manifest.permission.BIND_JOB_SERVICE.equals(r.permission) + && r.mRecentCallingUid == SYSTEM_UID) { + return HostingRecord.TRIGGER_TYPE_JOB; + } + return HostingRecord.TRIGGER_TYPE_UNKNOWN; + } + private final void requestServiceBindingsLocked(ServiceRecord r, boolean execInFg) throws TransactionTooLargeException { for (int i=r.bindings.size()-1; i>=0; i--) { diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index d4b760f3866f..df5113b16f49 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -5008,7 +5008,8 @@ public class ActivityManagerService extends IActivityManager.Stub hostingRecord.getType(), hostingRecord.getName(), shortAction, - HostingRecord.getHostingTypeIdStatsd(hostingRecord.getType())); + HostingRecord.getHostingTypeIdStatsd(hostingRecord.getType()), + HostingRecord.getTriggerTypeForStatsd(hostingRecord.getTriggerType())); return true; } diff --git a/services/core/java/com/android/server/am/BroadcastQueue.java b/services/core/java/com/android/server/am/BroadcastQueue.java index 58569495f70d..f366cec96f9d 100644 --- a/services/core/java/com/android/server/am/BroadcastQueue.java +++ b/services/core/java/com/android/server/am/BroadcastQueue.java @@ -1921,7 +1921,7 @@ public final class BroadcastQueue { info.activityInfo.applicationInfo, true, r.intent.getFlags() | Intent.FLAG_FROM_BACKGROUND, new HostingRecord(HostingRecord.HOSTING_TYPE_BROADCAST, r.curComponent, - r.intent.getAction()), + r.intent.getAction(), getHostingRecordTriggerType(r)), isActivityCapable ? ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE : ZYGOTE_POLICY_FLAG_EMPTY, (r.intent.getFlags() & Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0, false); if (r.curApp == null) { @@ -1944,6 +1944,16 @@ public final class BroadcastQueue { mPendingBroadcastRecvIndex = recIdx; } + private String getHostingRecordTriggerType(BroadcastRecord r) { + if (r.alarm) { + return HostingRecord.TRIGGER_TYPE_ALARM; + } else if (r.pushMessage) { + return HostingRecord.TRIGGER_TYPE_PUSH_MESSAGE; + } else if (r.pushMessageOverQuota) { + return HostingRecord.TRIGGER_TYPE_PUSH_MESSAGE_OVER_QUOTA; + } + return HostingRecord.TRIGGER_TYPE_UNKNOWN; + } @Nullable private String getTargetPackage(BroadcastRecord r) { diff --git a/services/core/java/com/android/server/am/BroadcastRecord.java b/services/core/java/com/android/server/am/BroadcastRecord.java index ce4528bca887..baaae1d7a555 100644 --- a/services/core/java/com/android/server/am/BroadcastRecord.java +++ b/services/core/java/com/android/server/am/BroadcastRecord.java @@ -71,6 +71,8 @@ final class BroadcastRecord extends Binder { final boolean ordered; // serialize the send to receivers? final boolean sticky; // originated from existing sticky data? final boolean alarm; // originated from an alarm triggering? + final boolean pushMessage; // originated from a push message? + final boolean pushMessageOverQuota; // originated from a push message which was over quota? final boolean initialSticky; // initial broadcast from register to sticky? final int userId; // user id this broadcast was for final String resolvedType; // the resolved data type @@ -309,6 +311,8 @@ final class BroadcastRecord extends Binder { mBackgroundActivityStartsToken = backgroundActivityStartsToken; this.timeoutExempt = timeoutExempt; alarm = options != null && options.isAlarmBroadcast(); + pushMessage = options != null && options.isPushMessagingBroadcast(); + pushMessageOverQuota = options != null && options.isPushMessagingOverQuotaBroadcast(); } /** @@ -362,6 +366,8 @@ final class BroadcastRecord extends Binder { mBackgroundActivityStartsToken = from.mBackgroundActivityStartsToken; timeoutExempt = from.timeoutExempt; alarm = from.alarm; + pushMessage = from.pushMessage; + pushMessageOverQuota = from.pushMessageOverQuota; } /** diff --git a/services/core/java/com/android/server/am/HostingRecord.java b/services/core/java/com/android/server/am/HostingRecord.java index f88a8ce83d02..30811a175bac 100644 --- a/services/core/java/com/android/server/am/HostingRecord.java +++ b/services/core/java/com/android/server/am/HostingRecord.java @@ -16,10 +16,30 @@ package com.android.server.am; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_ACTIVITY; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_ADDED_APPLICATION; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_BACKUP; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_BROADCAST; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_CONTENT_PROVIDER; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_EMPTY; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_LINK_FAIL; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_NEXT_ACTIVITY; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_NEXT_TOP_ACTIVITY; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_ON_HOLD; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_RESTART; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_SERVICE; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_SYSTEM; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_TOP_ACTIVITY; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_TYPE_ALARM; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_TYPE_JOB; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_TYPE_PUSH_MESSAGE; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_TYPE_PUSH_MESSAGE_OVER_QUOTA; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_TYPE_UNKNOWN; +import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__TYPE__UNKNOWN; + import android.annotation.NonNull; import android.annotation.Nullable; import android.content.ComponentName; -import android.os.ProcessStartTime; /** * This class describes various information required to start a process. @@ -32,6 +52,9 @@ import android.os.ProcessStartTime; * * The {@code mHostingZygote} field describes from which Zygote the new process should be spawned. * + * The {@code mTriggerType} field describes the trigger that started this processs. This could be + * an alarm or a push-message for a broadcast, for example. This is purely for logging and stats. + * * {@code mDefiningPackageName} contains the packageName of the package that defines the * component we want to start; this can be different from the packageName and uid in the * ApplicationInfo that we're creating the process with, in case the service is a @@ -71,7 +94,13 @@ public final class HostingRecord { public static final String HOSTING_TYPE_TOP_ACTIVITY = "top-activity"; public static final String HOSTING_TYPE_EMPTY = ""; - private @NonNull final String mHostingType; + public static final String TRIGGER_TYPE_UNKNOWN = "unknown"; + public static final String TRIGGER_TYPE_ALARM = "alarm"; + public static final String TRIGGER_TYPE_PUSH_MESSAGE = "push_message"; + public static final String TRIGGER_TYPE_PUSH_MESSAGE_OVER_QUOTA = "push_message_over_quota"; + public static final String TRIGGER_TYPE_JOB = "job"; + + @NonNull private final String mHostingType; private final String mHostingName; private final int mHostingZygote; private final String mDefiningPackageName; @@ -79,11 +108,12 @@ public final class HostingRecord { private final boolean mIsTopApp; private final String mDefiningProcessName; @Nullable private final String mAction; + @NonNull private final String mTriggerType; public HostingRecord(@NonNull String hostingType) { this(hostingType, null /* hostingName */, REGULAR_ZYGOTE, null /* definingPackageName */, -1 /* mDefiningUid */, false /* isTopApp */, null /* definingProcessName */, - null /* action */); + null /* action */, TRIGGER_TYPE_UNKNOWN); } public HostingRecord(@NonNull String hostingType, ComponentName hostingName) { @@ -91,22 +121,24 @@ public final class HostingRecord { } public HostingRecord(@NonNull String hostingType, ComponentName hostingName, - @Nullable String action) { + @Nullable String action, @Nullable String triggerType) { this(hostingType, hostingName.toShortString(), REGULAR_ZYGOTE, null /* definingPackageName */, -1 /* mDefiningUid */, false /* isTopApp */, - null /* definingProcessName */, action); + null /* definingProcessName */, action, triggerType); } public HostingRecord(@NonNull String hostingType, ComponentName hostingName, - String definingPackageName, int definingUid, String definingProcessName) { + String definingPackageName, int definingUid, String definingProcessName, + String triggerType) { this(hostingType, hostingName.toShortString(), REGULAR_ZYGOTE, definingPackageName, - definingUid, false /* isTopApp */, definingProcessName, null /* action */); + definingUid, false /* isTopApp */, definingProcessName, null /* action */, + triggerType); } public HostingRecord(@NonNull String hostingType, ComponentName hostingName, boolean isTopApp) { this(hostingType, hostingName.toShortString(), REGULAR_ZYGOTE, null /* definingPackageName */, -1 /* mDefiningUid */, isTopApp /* isTopApp */, - null /* definingProcessName */, null /* action */); + null /* definingProcessName */, null /* action */, TRIGGER_TYPE_UNKNOWN); } public HostingRecord(@NonNull String hostingType, String hostingName) { @@ -121,12 +153,12 @@ public final class HostingRecord { private HostingRecord(@NonNull String hostingType, String hostingName, int hostingZygote) { this(hostingType, hostingName, hostingZygote, null /* definingPackageName */, -1 /* mDefiningUid */, false /* isTopApp */, null /* definingProcessName */, - null /* action */); + null /* action */, TRIGGER_TYPE_UNKNOWN); } private HostingRecord(@NonNull String hostingType, String hostingName, int hostingZygote, String definingPackageName, int definingUid, boolean isTopApp, - String definingProcessName, @Nullable String action) { + String definingProcessName, @Nullable String action, String triggerType) { mHostingType = hostingType; mHostingName = hostingName; mHostingZygote = hostingZygote; @@ -135,6 +167,7 @@ public final class HostingRecord { mIsTopApp = isTopApp; mDefiningProcessName = definingProcessName; mAction = action; + mTriggerType = triggerType; } public @NonNull String getType() { @@ -188,6 +221,11 @@ public final class HostingRecord { return mAction; } + /** Returns the type of trigger that led to this process start. */ + public @NonNull String getTriggerType() { + return mTriggerType; + } + /** * Creates a HostingRecord for a process that must spawn from the webview zygote * @param hostingName name of the component to be hosted in this process @@ -197,7 +235,7 @@ public final class HostingRecord { String definingPackageName, int definingUid, String definingProcessName) { return new HostingRecord(HostingRecord.HOSTING_TYPE_EMPTY, hostingName.toShortString(), WEBVIEW_ZYGOTE, definingPackageName, definingUid, false /* isTopApp */, - definingProcessName, null /* action */); + definingProcessName, null /* action */, TRIGGER_TYPE_UNKNOWN); } /** @@ -211,7 +249,7 @@ public final class HostingRecord { int definingUid, String definingProcessName) { return new HostingRecord(HostingRecord.HOSTING_TYPE_EMPTY, hostingName.toShortString(), APP_ZYGOTE, definingPackageName, definingUid, false /* isTopApp */, - definingProcessName, null /* action */); + definingProcessName, null /* action */, TRIGGER_TYPE_UNKNOWN); } /** @@ -236,35 +274,55 @@ public final class HostingRecord { public static int getHostingTypeIdStatsd(@NonNull String hostingType) { switch(hostingType) { case HOSTING_TYPE_ACTIVITY: - return ProcessStartTime.HOSTING_TYPE_ACTIVITY; + return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_ACTIVITY; case HOSTING_TYPE_ADDED_APPLICATION: - return ProcessStartTime.HOSTING_TYPE_ADDED_APPLICATION; + return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_ADDED_APPLICATION; case HOSTING_TYPE_BACKUP: - return ProcessStartTime.HOSTING_TYPE_BACKUP; + return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_BACKUP; case HOSTING_TYPE_BROADCAST: - return ProcessStartTime.HOSTING_TYPE_BROADCAST; + return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_BROADCAST; case HOSTING_TYPE_CONTENT_PROVIDER: - return ProcessStartTime.HOSTING_TYPE_CONTENT_PROVIDER; + return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_CONTENT_PROVIDER; case HOSTING_TYPE_LINK_FAIL: - return ProcessStartTime.HOSTING_TYPE_LINK_FAIL; + return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_LINK_FAIL; case HOSTING_TYPE_ON_HOLD: - return ProcessStartTime.HOSTING_TYPE_ON_HOLD; + return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_ON_HOLD; case HOSTING_TYPE_NEXT_ACTIVITY: - return ProcessStartTime.HOSTING_TYPE_NEXT_ACTIVITY; + return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_NEXT_ACTIVITY; case HOSTING_TYPE_NEXT_TOP_ACTIVITY: - return ProcessStartTime.HOSTING_TYPE_NEXT_TOP_ACTIVITY; + return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_NEXT_TOP_ACTIVITY; case HOSTING_TYPE_RESTART: - return ProcessStartTime.HOSTING_TYPE_RESTART; + return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_RESTART; case HOSTING_TYPE_SERVICE: - return ProcessStartTime.HOSTING_TYPE_SERVICE; + return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_SERVICE; case HOSTING_TYPE_SYSTEM: - return ProcessStartTime.HOSTING_TYPE_SYSTEM; + return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_SYSTEM; case HOSTING_TYPE_TOP_ACTIVITY: - return ProcessStartTime.HOSTING_TYPE_TOP_ACTIVITY; + return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_TOP_ACTIVITY; case HOSTING_TYPE_EMPTY: - return ProcessStartTime.HOSTING_TYPE_EMPTY; + return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_EMPTY; + default: + return PROCESS_START_TIME__TYPE__UNKNOWN; + } + } + + /** + * Map the string triggerType to enum TriggerType defined in ProcessStartTime proto. + * @param triggerType + * @return enum TriggerType defined in ProcessStartTime proto + */ + public static int getTriggerTypeForStatsd(@NonNull String triggerType) { + switch(triggerType) { + case TRIGGER_TYPE_ALARM: + return PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_TYPE_ALARM; + case TRIGGER_TYPE_PUSH_MESSAGE: + return PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_TYPE_PUSH_MESSAGE; + case TRIGGER_TYPE_PUSH_MESSAGE_OVER_QUOTA: + return PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_TYPE_PUSH_MESSAGE_OVER_QUOTA; + case TRIGGER_TYPE_JOB: + return PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_TYPE_JOB; default: - return ProcessStartTime.HOSTING_TYPE_UNKNOWN; + return PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_TYPE_UNKNOWN; } } } |