Merge changes from topic "tm-qpr-proc-start-triggers" into tm-qpr-dev

* changes:
  Add trigger type job for logging process starts
  Add push messaging as a trigger for proc start
  Cleaning up duplicate proto for ProcessStartTime
This commit is contained in:
TreeHugger Robot
2022-10-04 22:16:32 +00:00
committed by Android (Google) Code Review
6 changed files with 99 additions and 117 deletions

View File

@@ -528,6 +528,28 @@ public class BroadcastOptions extends ComponentOptions {
return mIsAlarmBroadcast; 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} */ /** {@hide} */
public long getRequireCompatChangeId() { public long getRequireCompatChangeId() {
return mRequireCompatChangeId; return mRequireCompatChangeId;

View File

@@ -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;
}

View File

@@ -4219,7 +4219,8 @@ public final class ActiveServices {
final String procName = r.processName; final String procName = r.processName;
HostingRecord hostingRecord = new HostingRecord( HostingRecord hostingRecord = new HostingRecord(
HostingRecord.HOSTING_TYPE_SERVICE, r.instanceName, HostingRecord.HOSTING_TYPE_SERVICE, r.instanceName,
r.definingPackageName, r.definingUid, r.serviceInfo.processName); r.definingPackageName, r.definingUid, r.serviceInfo.processName,
getHostingRecordTriggerType(r));
ProcessRecord app; ProcessRecord app;
if (!isolated) { if (!isolated) {
@@ -4323,6 +4324,14 @@ public final class ActiveServices {
return null; 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) private final void requestServiceBindingsLocked(ServiceRecord r, boolean execInFg)
throws TransactionTooLargeException { throws TransactionTooLargeException {
for (int i=r.bindings.size()-1; i>=0; i--) { for (int i=r.bindings.size()-1; i>=0; i--) {

View File

@@ -1921,8 +1921,7 @@ public final class BroadcastQueue {
info.activityInfo.applicationInfo, true, info.activityInfo.applicationInfo, true,
r.intent.getFlags() | Intent.FLAG_FROM_BACKGROUND, r.intent.getFlags() | Intent.FLAG_FROM_BACKGROUND,
new HostingRecord(HostingRecord.HOSTING_TYPE_BROADCAST, r.curComponent, new HostingRecord(HostingRecord.HOSTING_TYPE_BROADCAST, r.curComponent,
r.intent.getAction(), (r.alarm ? HostingRecord.TRIGGER_TYPE_ALARM r.intent.getAction(), getHostingRecordTriggerType(r)),
: HostingRecord.TRIGGER_TYPE_UNKNOWN)),
isActivityCapable ? ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE : ZYGOTE_POLICY_FLAG_EMPTY, isActivityCapable ? ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE : ZYGOTE_POLICY_FLAG_EMPTY,
(r.intent.getFlags() & Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0, false); (r.intent.getFlags() & Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0, false);
if (r.curApp == null) { if (r.curApp == null) {
@@ -1945,6 +1944,16 @@ public final class BroadcastQueue {
mPendingBroadcastRecvIndex = recIdx; 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 @Nullable
private String getTargetPackage(BroadcastRecord r) { private String getTargetPackage(BroadcastRecord r) {

View File

@@ -71,6 +71,8 @@ final class BroadcastRecord extends Binder {
final boolean ordered; // serialize the send to receivers? final boolean ordered; // serialize the send to receivers?
final boolean sticky; // originated from existing sticky data? final boolean sticky; // originated from existing sticky data?
final boolean alarm; // originated from an alarm triggering? 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 boolean initialSticky; // initial broadcast from register to sticky?
final int userId; // user id this broadcast was for final int userId; // user id this broadcast was for
final String resolvedType; // the resolved data type final String resolvedType; // the resolved data type
@@ -309,6 +311,8 @@ final class BroadcastRecord extends Binder {
mBackgroundActivityStartsToken = backgroundActivityStartsToken; mBackgroundActivityStartsToken = backgroundActivityStartsToken;
this.timeoutExempt = timeoutExempt; this.timeoutExempt = timeoutExempt;
alarm = options != null && options.isAlarmBroadcast(); 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; mBackgroundActivityStartsToken = from.mBackgroundActivityStartsToken;
timeoutExempt = from.timeoutExempt; timeoutExempt = from.timeoutExempt;
alarm = from.alarm; alarm = from.alarm;
pushMessage = from.pushMessage;
pushMessageOverQuota = from.pushMessageOverQuota;
} }
/** /**

View File

@@ -16,12 +16,30 @@
package com.android.server.am; 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.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.content.ComponentName; import android.content.ComponentName;
import android.os.ProcessStartTime;
import com.android.internal.util.FrameworkStatsLog;
/** /**
* This class describes various information required to start a process. * This class describes various information required to start a process.
@@ -78,6 +96,9 @@ public final class HostingRecord {
public static final String TRIGGER_TYPE_UNKNOWN = "unknown"; public static final String TRIGGER_TYPE_UNKNOWN = "unknown";
public static final String TRIGGER_TYPE_ALARM = "alarm"; 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; @NonNull private final String mHostingType;
private final String mHostingName; private final String mHostingName;
@@ -107,10 +128,11 @@ public final class HostingRecord {
} }
public HostingRecord(@NonNull String hostingType, ComponentName hostingName, 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, this(hostingType, hostingName.toShortString(), REGULAR_ZYGOTE, definingPackageName,
definingUid, false /* isTopApp */, definingProcessName, null /* action */, definingUid, false /* isTopApp */, definingProcessName, null /* action */,
TRIGGER_TYPE_UNKNOWN); triggerType);
} }
public HostingRecord(@NonNull String hostingType, ComponentName hostingName, boolean isTopApp) { public HostingRecord(@NonNull String hostingType, ComponentName hostingName, boolean isTopApp) {
@@ -252,35 +274,35 @@ public final class HostingRecord {
public static int getHostingTypeIdStatsd(@NonNull String hostingType) { public static int getHostingTypeIdStatsd(@NonNull String hostingType) {
switch(hostingType) { switch(hostingType) {
case HOSTING_TYPE_ACTIVITY: case HOSTING_TYPE_ACTIVITY:
return ProcessStartTime.HOSTING_TYPE_ACTIVITY; return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_ACTIVITY;
case HOSTING_TYPE_ADDED_APPLICATION: 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: case HOSTING_TYPE_BACKUP:
return ProcessStartTime.HOSTING_TYPE_BACKUP; return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_BACKUP;
case HOSTING_TYPE_BROADCAST: case HOSTING_TYPE_BROADCAST:
return ProcessStartTime.HOSTING_TYPE_BROADCAST; return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_BROADCAST;
case HOSTING_TYPE_CONTENT_PROVIDER: 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: 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: 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: 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: 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: case HOSTING_TYPE_RESTART:
return ProcessStartTime.HOSTING_TYPE_RESTART; return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_RESTART;
case HOSTING_TYPE_SERVICE: case HOSTING_TYPE_SERVICE:
return ProcessStartTime.HOSTING_TYPE_SERVICE; return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_SERVICE;
case HOSTING_TYPE_SYSTEM: case HOSTING_TYPE_SYSTEM:
return ProcessStartTime.HOSTING_TYPE_SYSTEM; return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_SYSTEM;
case HOSTING_TYPE_TOP_ACTIVITY: 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: case HOSTING_TYPE_EMPTY:
return ProcessStartTime.HOSTING_TYPE_EMPTY; return PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_EMPTY;
default: default:
return ProcessStartTime.HOSTING_TYPE_UNKNOWN; return PROCESS_START_TIME__TYPE__UNKNOWN;
} }
} }
@@ -292,9 +314,15 @@ public final class HostingRecord {
public static int getTriggerTypeForStatsd(@NonNull String triggerType) { public static int getTriggerTypeForStatsd(@NonNull String triggerType) {
switch(triggerType) { switch(triggerType) {
case TRIGGER_TYPE_ALARM: case TRIGGER_TYPE_ALARM:
return FrameworkStatsLog.PROCESS_START_TIME__TRIGGER_TYPE__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: default:
return FrameworkStatsLog.PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_TYPE_UNKNOWN; return PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_TYPE_UNKNOWN;
} }
} }
} }