iorap: Add handler for package update by dexopt service. am: 4aa58f0560 am: dff17ce1f6 am: 398e72f264
Change-Id: I1ec8bd20108425610108eeb58e32f53858ef708a
diff --git a/binder/com/google/android/startop/iorap/DexOptEvent.aidl b/binder/com/google/android/startop/iorap/DexOptEvent.aidl
new file mode 100644
index 0000000..a4e175b
--- /dev/null
+++ b/binder/com/google/android/startop/iorap/DexOptEvent.aidl
@@ -0,0 +1,20 @@
+/*
+ * 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.google.android.startop.iorap;
+
+/** @hide */
+parcelable DexOptEvent cpp_header "binder/dexopt_event.h";
diff --git a/binder/com/google/android/startop/iorap/IIorap.aidl b/binder/com/google/android/startop/iorap/IIorap.aidl
index 63d5477..05faefe 100644
--- a/binder/com/google/android/startop/iorap/IIorap.aidl
+++ b/binder/com/google/android/startop/iorap/IIorap.aidl
@@ -20,6 +20,7 @@
import com.google.android.startop.iorap.AppIntentEvent;
import com.google.android.startop.iorap.AppLaunchEvent;
+import com.google.android.startop.iorap.DexOptEvent;
import com.google.android.startop.iorap.JobScheduledEvent;
import com.google.android.startop.iorap.PackageEvent;
import com.google.android.startop.iorap.RequestId;
@@ -110,6 +111,7 @@
// void onActivityHintEvent(in RequestId request, in ActivityHintEvent event);
void onAppLaunchEvent(in RequestId request, in AppLaunchEvent event);
+ void onDexOptEvent(in RequestId request, in DexOptEvent event);
void onJobScheduledEvent(in RequestId request, in JobScheduledEvent event);
void onPackageEvent(in RequestId request, in PackageEvent event);
void onAppIntentEvent(in RequestId request, in AppIntentEvent event);
diff --git a/include/binder/dexopt_event.h b/include/binder/dexopt_event.h
new file mode 100644
index 0000000..cb506f4
--- /dev/null
+++ b/include/binder/dexopt_event.h
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+#ifndef IORAP_BINDER_DEXOPT_EVENT_H_
+#define IORAP_BINDER_DEXOPT_EVENT_H_
+
+#include "binder/common.h"
+#include "binder/auto_parcelable.h"
+#include "common/introspection.h"
+
+namespace iorap {
+namespace binder {
+
+struct DexOptEvent : public AutoParcelable<DexOptEvent> {
+ enum class Type : int32_t {
+ kPackageUpdate = 0,
+ };
+
+ Type type;
+ std::string package_name;
+};
+
+IORAP_INTROSPECT_ADAPT_STRUCT(DexOptEvent, type, package_name);
+
+}
+}
+IORAP_JAVA_NAMESPACE_BINDER_TYPEDEF(DexOptEvent)
+
+#endif // IORAP_BINDER_DEXOPT_EVENT_H_
diff --git a/src/binder/iiorap_def.h b/src/binder/iiorap_def.h
index 78414f9..5763380 100644
--- a/src/binder/iiorap_def.h
+++ b/src/binder/iiorap_def.h
@@ -42,6 +42,8 @@
FN(onSystemServiceUserEvent, \
(const ::com::google::android::startop::iorap::,RequestId,&,request), \
(const ::com::google::android::startop::iorap::,SystemServiceUserEvent,&,event))\
+FN(onDexOptEvent, (const ::com::google::android::startop::iorap::,RequestId,&,request), \
+ (const ::com::google::android::startop::iorap::,DexOptEvent,&,event)) \
FN_END() \
// Convenience macros to unpack the 2nd parameter from IIORAP_IFACE_DEF#FN calls.
diff --git a/src/binder/iiorap_impl.cc b/src/binder/iiorap_impl.cc
index 514d1be..478196c 100644
--- a/src/binder/iiorap_impl.cc
+++ b/src/binder/iiorap_impl.cc
@@ -177,6 +177,14 @@
return service_params_.event_manager_->OnAppLaunchEvent(request_id, event);
}
+ bool OnDexOptEvent(const RequestId& request_id, const DexOptEvent& event) {
+ if (MaybeHandleFakeBehavior(request_id)) {
+ return true;
+ }
+
+ return service_params_.event_manager_->OnDexOptEvent(request_id, event);
+ }
+
bool OnJobScheduledEvent(const RequestId& request_id,
const JobScheduledEvent& event) {
if (MaybeHandleFakeBehavior(request_id)) {
@@ -423,6 +431,23 @@
Status SendArgs(const char* function_name,
Impl* self,
const RequestId& request_id,
+ const DexOptEvent& event) {
+ DCHECK_EQ(std::string(function_name), "onDexOptEvent");
+ LOG(VERBOSE) << "IIorap::onDexOptEvent";
+
+ MAYBE_HAVE_FAKE_BEHAVIOR(self, request_id);
+
+ if (self->OnDexOptEvent(request_id, event)) {
+ return Status::ok();
+ } else {
+ return Status::fromStatusT(::android::BAD_VALUE);
+ }
+}
+
+template <typename ... Args>
+Status SendArgs(const char* function_name,
+ Impl* self,
+ const RequestId& request_id,
const JobScheduledEvent& event) {
DCHECK_EQ(std::string(function_name), "onJobScheduledEvent");
LOG(VERBOSE) << "IIorap::onJobScheduledEvent";
diff --git a/src/manager/event_manager.cc b/src/manager/event_manager.cc
index 80cfb35..44809fd 100644
--- a/src/manager/event_manager.cc
+++ b/src/manager/event_manager.cc
@@ -49,6 +49,7 @@
namespace iorap::manager {
using binder::AppLaunchEvent;
+using binder::DexOptEvent;
using binder::JobScheduledEvent;
using binder::RequestId;
using binder::TaskResult;
@@ -981,6 +982,16 @@
return false;
}
+ bool OnDexOptEvent(RequestId request_id,
+ const DexOptEvent& event) {
+ LOG(VERBOSE) << "EventManager::OnDexOptEvent("
+ << "request_id=" << request_id.request_id << ","
+ << event.package_name
+ << ")";
+
+ return PurgePackage(event.package_name);
+ }
+
bool OnJobScheduledEvent(RequestId request_id,
const JobScheduledEvent& event) {
LOG(VERBOSE) << "EventManager::OnJobScheduledEvent("
@@ -1230,11 +1241,13 @@
bool PurgePackage(::android::Printer& printer, const std::string& package_name) {
(void)printer;
+ return PurgePackage(package_name);
+ }
+ bool PurgePackage(const std::string& package_name) {
db::DbHandle db{db::SchemaModel::GetSingleton()};
db::CleanUpFilesForPackage(db, package_name);
LOG(DEBUG) << "PurgePackage: " << package_name;
-
return true;
}
@@ -1334,6 +1347,11 @@
return impl_->OnAppLaunchEvent(request_id, event);
}
+bool EventManager::OnDexOptEvent(RequestId request_id,
+ const DexOptEvent& event) {
+ return impl_->OnDexOptEvent(request_id, event);
+}
+
bool EventManager::OnJobScheduledEvent(RequestId request_id,
const JobScheduledEvent& event) {
return impl_->OnJobScheduledEvent(request_id, event);
diff --git a/src/manager/event_manager.h b/src/manager/event_manager.h
index 1a533bc..fa09eec 100644
--- a/src/manager/event_manager.h
+++ b/src/manager/event_manager.h
@@ -18,6 +18,7 @@
#define IORAP_MANAGER_EVENT_MANAGER_H_
#include "binder/app_launch_event.h"
+#include "binder/dexopt_event.h"
#include "binder/job_scheduled_event.h"
#include "binder/request_id.h"
#include "binder/task_result.h"
@@ -73,6 +74,13 @@
bool OnAppLaunchEvent(binder::RequestId request_id,
const binder::AppLaunchEvent& event);
+ // Handles a DexOptEvent:
+ //
+ // Clean up the invalidate traces after package is updated by dexopt.
+ bool OnDexOptEvent(binder::RequestId request_id,
+ const binder::DexOptEvent& event);
+
+
// Handles a JobScheduledEvent:
//
// * Start/stop background jobs (typically for idle maintenance).