Merge "Add receiver info to IncidentdDetails in statsd_config"
This commit is contained in:
committed by
Android (Google) Code Review
commit
55805af719
@@ -219,6 +219,7 @@ cc_test {
|
||||
"tests/anomaly/AnomalyTracker_test.cpp",
|
||||
"tests/ConfigManager_test.cpp",
|
||||
"tests/external/puller_util_test.cpp",
|
||||
"tests/external/IncidentReportArgs_test.cpp",
|
||||
"tests/external/StatsPuller_test.cpp",
|
||||
"tests/indexed_priority_queue_test.cpp",
|
||||
"tests/LogEntryMatcher_test.cpp",
|
||||
|
||||
@@ -324,6 +324,12 @@ message IncidentdDetails {
|
||||
EXPLICIT = 1;
|
||||
}
|
||||
optional Destination dest = 2;
|
||||
|
||||
// Package name of the incident report receiver.
|
||||
optional string receiver_pkg = 3;
|
||||
|
||||
// Class name of the incident report receiver.
|
||||
optional string receiver_cls = 4;
|
||||
}
|
||||
|
||||
message PerfettoDetails {
|
||||
|
||||
@@ -162,6 +162,10 @@ bool GenerateIncidentReport(const IncidentdDetails& config, int64_t rule_id, int
|
||||
}
|
||||
incidentReport.setDest(dest);
|
||||
|
||||
incidentReport.setReceiverPkg(config.receiver_pkg());
|
||||
|
||||
incidentReport.setReceiverCls(config.receiver_cls());
|
||||
|
||||
sp<IIncidentManager> service = interface_cast<IIncidentManager>(
|
||||
defaultServiceManager()->getService(android::String16("incident")));
|
||||
if (service == nullptr) {
|
||||
|
||||
72
cmds/statsd/tests/external/IncidentReportArgs_test.cpp
vendored
Normal file
72
cmds/statsd/tests/external/IncidentReportArgs_test.cpp
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
// Copyright (C) 2018 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <android/os/IncidentReportArgs.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace android {
|
||||
namespace os {
|
||||
namespace statsd {
|
||||
|
||||
TEST(IncidentReportArgsTest, testSerialization) {
|
||||
IncidentReportArgs args;
|
||||
args.setAll(0);
|
||||
args.addSection(1000);
|
||||
args.addSection(1001);
|
||||
|
||||
vector<uint8_t> header1;
|
||||
header1.push_back(0x1);
|
||||
header1.push_back(0x2);
|
||||
vector<uint8_t> header2;
|
||||
header1.push_back(0x22);
|
||||
header1.push_back(0x33);
|
||||
|
||||
args.addHeader(header1);
|
||||
args.addHeader(header2);
|
||||
|
||||
args.setDest(1);
|
||||
|
||||
args.setReceiverPkg("com.android.os");
|
||||
args.setReceiverCls("com.android.os.Receiver");
|
||||
|
||||
Parcel out;
|
||||
status_t err = args.writeToParcel(&out);
|
||||
EXPECT_EQ(NO_ERROR, err);
|
||||
|
||||
out.setDataPosition(0);
|
||||
|
||||
IncidentReportArgs args2;
|
||||
err = args2.readFromParcel(&out);
|
||||
EXPECT_EQ(NO_ERROR, err);
|
||||
|
||||
EXPECT_EQ(0, args2.all());
|
||||
set<int> sections;
|
||||
sections.insert(1000);
|
||||
sections.insert(1001);
|
||||
EXPECT_EQ(sections, args2.sections());
|
||||
EXPECT_EQ(1, args2.dest());
|
||||
|
||||
EXPECT_EQ(String16("com.android.os"), args2.receiverPkg());
|
||||
EXPECT_EQ(String16("com.android.os.Receiver"), args2.receiverCls());
|
||||
|
||||
vector<vector<uint8_t>> headers;
|
||||
headers.push_back(header1);
|
||||
headers.push_back(header2);
|
||||
EXPECT_EQ(headers, args2.headers());
|
||||
}
|
||||
|
||||
} // namespace statsd
|
||||
} // namespace os
|
||||
} // namespace android
|
||||
@@ -36,6 +36,8 @@ public final class IncidentReportArgs implements Parcelable {
|
||||
private final ArrayList<byte[]> mHeaders = new ArrayList<byte[]>();
|
||||
private boolean mAll;
|
||||
private int mPrivacyPolicy;
|
||||
private String mReceiverPkg;
|
||||
private String mReceiverCls;
|
||||
|
||||
/**
|
||||
* Construct an incident report args with no fields.
|
||||
@@ -73,6 +75,10 @@ public final class IncidentReportArgs implements Parcelable {
|
||||
}
|
||||
|
||||
out.writeInt(mPrivacyPolicy);
|
||||
|
||||
out.writeString(mReceiverPkg);
|
||||
|
||||
out.writeString(mReceiverCls);
|
||||
}
|
||||
|
||||
public void readFromParcel(Parcel in) {
|
||||
@@ -91,6 +97,10 @@ public final class IncidentReportArgs implements Parcelable {
|
||||
}
|
||||
|
||||
mPrivacyPolicy = in.readInt();
|
||||
|
||||
mReceiverPkg = in.readString();
|
||||
|
||||
mReceiverCls = in.readString();
|
||||
}
|
||||
|
||||
public static final @android.annotation.NonNull Parcelable.Creator<IncidentReportArgs> CREATOR
|
||||
@@ -126,6 +136,8 @@ public final class IncidentReportArgs implements Parcelable {
|
||||
sb.append(mHeaders.size());
|
||||
sb.append(" headers), ");
|
||||
sb.append("privacy: ").append(mPrivacyPolicy);
|
||||
sb.append("receiver pkg: ").append(mReceiverPkg);
|
||||
sb.append("receiver cls: ").append(mReceiverCls);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -47,12 +47,16 @@ public:
|
||||
void setAll(bool all);
|
||||
void setDest(int dest);
|
||||
void addSection(int section);
|
||||
void setReceiverPkg(const string& pkg);
|
||||
void setReceiverCls(const string& cls);
|
||||
void addHeader(const vector<uint8_t>& headerProto);
|
||||
|
||||
inline bool all() const { return mAll; }
|
||||
bool containsSection(int section) const;
|
||||
inline int dest() const { return mDest; }
|
||||
inline const set<int>& sections() const { return mSections; }
|
||||
inline const String16& receiverPkg() const { return mReceiverPkg; }
|
||||
inline const String16& receiverCls() const { return mReceiverCls; }
|
||||
inline const vector<vector<uint8_t>>& headers() const { return mHeaders; }
|
||||
|
||||
void merge(const IncidentReportArgs& that);
|
||||
@@ -62,6 +66,8 @@ private:
|
||||
vector<vector<uint8_t>> mHeaders;
|
||||
bool mAll;
|
||||
int mDest;
|
||||
String16 mReceiverPkg;
|
||||
String16 mReceiverCls;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -81,6 +81,16 @@ IncidentReportArgs::writeToParcel(Parcel* out) const
|
||||
return err;
|
||||
}
|
||||
|
||||
err = out->writeString16(mReceiverPkg);
|
||||
if (err != NO_ERROR) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = out->writeString16(mReceiverCls);
|
||||
if (err != NO_ERROR) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -134,6 +144,9 @@ IncidentReportArgs::readFromParcel(const Parcel* in)
|
||||
}
|
||||
mDest = dest;
|
||||
|
||||
mReceiverPkg = in->readString16();
|
||||
mReceiverCls = in->readString16();
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -160,6 +173,18 @@ IncidentReportArgs::addSection(int section)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
IncidentReportArgs::setReceiverPkg(const string& pkg)
|
||||
{
|
||||
mReceiverPkg = String16(pkg.c_str());
|
||||
}
|
||||
|
||||
void
|
||||
IncidentReportArgs::setReceiverCls(const string& cls)
|
||||
{
|
||||
mReceiverCls = String16(cls.c_str());
|
||||
}
|
||||
|
||||
void
|
||||
IncidentReportArgs::addHeader(const vector<uint8_t>& headerProto)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user