Merge changes from topic 'refcount' into oc-dev
* changes: storaged: stop binder threads before exiting storaged: exit if batteryproperties service is dead. storaged: use sp<> to keep refcount for storaged_t object
This commit is contained in:
commit
f4c0dcae69
4 changed files with 27 additions and 10 deletions
|
|
@ -27,6 +27,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include <batteryservice/IBatteryPropertiesListener.h>
|
||||
#include <batteryservice/IBatteryPropertiesRegistrar.h>
|
||||
|
||||
#include "storaged_info.h"
|
||||
#include "storaged_uid_monitor.h"
|
||||
|
|
@ -245,7 +246,8 @@ struct storaged_config {
|
|||
int event_time_check_usec; // check how much cputime spent in event loop
|
||||
};
|
||||
|
||||
class storaged_t : public BnBatteryPropertiesListener {
|
||||
class storaged_t : public BnBatteryPropertiesListener,
|
||||
public IBinder::DeathRecipient {
|
||||
private:
|
||||
time_t mTimer;
|
||||
storaged_config mConfig;
|
||||
|
|
@ -253,6 +255,7 @@ private:
|
|||
disk_stats_monitor mDsm;
|
||||
uid_monitor mUidm;
|
||||
time_t mStarttime;
|
||||
sp<IBatteryPropertiesRegistrar> battery_properties;
|
||||
public:
|
||||
storaged_t(void);
|
||||
~storaged_t() {}
|
||||
|
|
@ -281,6 +284,7 @@ public:
|
|||
|
||||
void init_battery_service();
|
||||
virtual void batteryPropertiesChanged(struct BatteryProperties props);
|
||||
void binderDied(const wp<IBinder>& who);
|
||||
};
|
||||
|
||||
// Eventlog tag
|
||||
|
|
|
|||
|
|
@ -42,11 +42,11 @@
|
|||
#include <storaged_service.h>
|
||||
#include <storaged_utils.h>
|
||||
|
||||
storaged_t storaged;
|
||||
sp<storaged_t> storaged;
|
||||
|
||||
// Function of storaged's main thread
|
||||
void* storaged_main(void* s) {
|
||||
storaged_t* storaged = (storaged_t*)s;
|
||||
void* storaged_main(void* /* unused */) {
|
||||
storaged = new storaged_t();
|
||||
|
||||
storaged->init_battery_service();
|
||||
|
||||
|
|
@ -116,7 +116,7 @@ int main(int argc, char** argv) {
|
|||
report_storage_health();
|
||||
// Start the main thread of storaged
|
||||
pthread_t storaged_main_thread;
|
||||
errno = pthread_create(&storaged_main_thread, NULL, storaged_main, &storaged);
|
||||
errno = pthread_create(&storaged_main_thread, NULL, storaged_main, NULL);
|
||||
if (errno != 0) {
|
||||
PLOG_TO(SYSTEM, ERROR) << "Failed to create main thread";
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include <android-base/logging.h>
|
||||
#include <batteryservice/BatteryServiceConstants.h>
|
||||
#include <batteryservice/IBatteryPropertiesRegistrar.h>
|
||||
#include <binder/IPCThreadState.h>
|
||||
#include <binder/IServiceManager.h>
|
||||
#include <cutils/properties.h>
|
||||
#include <log/log.h>
|
||||
|
|
@ -173,7 +174,7 @@ void storaged_t::init_battery_service() {
|
|||
if (!mConfig.proc_uid_io_available)
|
||||
return;
|
||||
|
||||
sp<IBatteryPropertiesRegistrar> battery_properties = get_battery_properties_service();
|
||||
battery_properties = get_battery_properties_service();
|
||||
if (battery_properties == NULL) {
|
||||
LOG_TO(SYSTEM, WARNING) << "failed to find batteryproperties service";
|
||||
return;
|
||||
|
|
@ -185,6 +186,18 @@ void storaged_t::init_battery_service() {
|
|||
|
||||
// register listener after init uid_monitor
|
||||
battery_properties->registerListener(this);
|
||||
IInterface::asBinder(battery_properties)->linkToDeath(this);
|
||||
}
|
||||
|
||||
void storaged_t::binderDied(const wp<IBinder>& who) {
|
||||
if (battery_properties != NULL &&
|
||||
IInterface::asBinder(battery_properties) == who) {
|
||||
LOG_TO(SYSTEM, ERROR) << "batteryproperties service died, exiting";
|
||||
IPCThreadState::self()->stopProcess();
|
||||
exit(1);
|
||||
} else {
|
||||
LOG_TO(SYSTEM, ERROR) << "unknown service died";
|
||||
}
|
||||
}
|
||||
|
||||
/* storaged_t */
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
using namespace android::base;
|
||||
|
||||
extern storaged_t storaged;
|
||||
extern sp<storaged_t> storaged;
|
||||
|
||||
std::vector<struct uid_info> BpStoraged::dump_uids(const char* /*option*/) {
|
||||
Parcel data, reply;
|
||||
|
|
@ -74,7 +74,7 @@ status_t BnStoraged::onTransact(uint32_t code, const Parcel& data, Parcel* reply
|
|||
|
||||
std::vector<struct uid_info> Storaged::dump_uids(const char* /* option */) {
|
||||
std::vector<struct uid_info> uids_v;
|
||||
std::unordered_map<uint32_t, struct uid_info> uids_m = storaged.get_uids();
|
||||
std::unordered_map<uint32_t, struct uid_info> uids_m = storaged->get_uids();
|
||||
|
||||
for (const auto& it : uids_m) {
|
||||
uids_v.push_back(it.second);
|
||||
|
|
@ -127,7 +127,7 @@ status_t Storaged::dump(int fd, const Vector<String16>& args) {
|
|||
|
||||
uint64_t last_ts = 0;
|
||||
const std::map<uint64_t, struct uid_records>& records =
|
||||
storaged.get_uid_records(hours, threshold, force_report);
|
||||
storaged->get_uid_records(hours, threshold, force_report);
|
||||
for (const auto& it : records) {
|
||||
if (last_ts != it.second.start_ts) {
|
||||
dprintf(fd, "%llu", (unsigned long long)it.second.start_ts);
|
||||
|
|
@ -150,7 +150,7 @@ status_t Storaged::dump(int fd, const Vector<String16>& args) {
|
|||
}
|
||||
|
||||
if (time_window) {
|
||||
storaged.update_uid_io_interval(time_window);
|
||||
storaged->update_uid_io_interval(time_window);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue