Merge "Remove IStatsd reference from StatsLog.java" into rvc-dev

This commit is contained in:
Jeffrey Huang
2020-04-22 00:08:44 +00:00
committed by Android (Google) Code Review
4 changed files with 22 additions and 97 deletions

View File

@@ -181,12 +181,6 @@ interface IStatsd {
*/ */
void unsetBroadcastSubscriber(long configId, long subscriberId, int callingUid); void unsetBroadcastSubscriber(long configId, long subscriberId, int callingUid);
/**
* Apps can send an atom via this application breadcrumb with the specified label and state for
* this label. This allows building custom metrics and predicates.
*/
void sendAppBreadcrumbAtom(int label, int state);
/** /**
* Tell the stats daemon that all the pullers registered during boot have been sent. * Tell the stats daemon that all the pullers registered during boot have been sent.
*/ */

View File

@@ -25,8 +25,7 @@ import android.annotation.RequiresPermission;
import android.annotation.SystemApi; import android.annotation.SystemApi;
import android.content.Context; import android.content.Context;
import android.os.IStatsd; import android.os.IStatsd;
import android.os.RemoteException; import android.os.Process;
import android.os.StatsFrameworkInitializer;
import android.util.proto.ProtoOutputStream; import android.util.proto.ProtoOutputStream;
import com.android.internal.util.StatsdStatsLog; import com.android.internal.util.StatsdStatsLog;
@@ -45,10 +44,6 @@ public final class StatsLog {
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private static final int EXPERIMENT_IDS_FIELD_ID = 1; private static final int EXPERIMENT_IDS_FIELD_ID = 1;
private static IStatsd sService;
private static Object sLogLock = new Object();
private StatsLog() { private StatsLog() {
} }
@@ -59,26 +54,13 @@ public final class StatsLog {
* @return True if the log request was sent to statsd. * @return True if the log request was sent to statsd.
*/ */
public static boolean logStart(int label) { public static boolean logStart(int label) {
synchronized (sLogLock) { int callingUid = Process.myUid();
try { StatsdStatsLog.write(
IStatsd service = getIStatsdLocked(); StatsdStatsLog.APP_BREADCRUMB_REPORTED,
if (service == null) { callingUid,
if (DEBUG) { label,
Log.d(TAG, "Failed to find statsd when logging start");
}
return false;
}
service.sendAppBreadcrumbAtom(label,
StatsdStatsLog.APP_BREADCRUMB_REPORTED__STATE__START); StatsdStatsLog.APP_BREADCRUMB_REPORTED__STATE__START);
return true; return true;
} catch (RemoteException e) {
sService = null;
if (DEBUG) {
Log.d(TAG, "Failed to connect to statsd when logging start");
}
return false;
}
}
} }
/** /**
@@ -88,26 +70,13 @@ public final class StatsLog {
* @return True if the log request was sent to statsd. * @return True if the log request was sent to statsd.
*/ */
public static boolean logStop(int label) { public static boolean logStop(int label) {
synchronized (sLogLock) { int callingUid = Process.myUid();
try { StatsdStatsLog.write(
IStatsd service = getIStatsdLocked(); StatsdStatsLog.APP_BREADCRUMB_REPORTED,
if (service == null) { callingUid,
if (DEBUG) { label,
Log.d(TAG, "Failed to find statsd when logging stop"); StatsdStatsLog.APP_BREADCRUMB_REPORTED__STATE__STOP);
}
return false;
}
service.sendAppBreadcrumbAtom(
label, StatsdStatsLog.APP_BREADCRUMB_REPORTED__STATE__STOP);
return true; return true;
} catch (RemoteException e) {
sService = null;
if (DEBUG) {
Log.d(TAG, "Failed to connect to statsd when logging stop");
}
return false;
}
}
} }
/** /**
@@ -117,26 +86,13 @@ public final class StatsLog {
* @return True if the log request was sent to statsd. * @return True if the log request was sent to statsd.
*/ */
public static boolean logEvent(int label) { public static boolean logEvent(int label) {
synchronized (sLogLock) { int callingUid = Process.myUid();
try { StatsdStatsLog.write(
IStatsd service = getIStatsdLocked(); StatsdStatsLog.APP_BREADCRUMB_REPORTED,
if (service == null) { callingUid,
if (DEBUG) { label,
Log.d(TAG, "Failed to find statsd when logging event"); StatsdStatsLog.APP_BREADCRUMB_REPORTED__STATE__UNSPECIFIED);
}
return false;
}
service.sendAppBreadcrumbAtom(
label, StatsdStatsLog.APP_BREADCRUMB_REPORTED__STATE__UNSPECIFIED);
return true; return true;
} catch (RemoteException e) {
sService = null;
if (DEBUG) {
Log.d(TAG, "Failed to connect to statsd when logging event");
}
return false;
}
}
} }
/** /**
@@ -181,17 +137,6 @@ public final class StatsLog {
return true; return true;
} }
private static IStatsd getIStatsdLocked() throws RemoteException {
if (sService != null) {
return sService;
}
sService = IStatsd.Stub.asInterface(StatsFrameworkInitializer
.getStatsServiceManager()
.getStatsdServiceRegisterer()
.get());
return sService;
}
/** /**
* Write an event to stats log using the raw format. * Write an event to stats log using the raw format.
* *

View File

@@ -1222,15 +1222,6 @@ Status StatsService::unsetBroadcastSubscriber(int64_t configId,
return Status::ok(); return Status::ok();
} }
Status StatsService::sendAppBreadcrumbAtom(int32_t label, int32_t state) {
// Permission check not necessary as it's meant for applications to write to
// statsd.
android::os::statsd::util::stats_write(android::os::statsd::util::APP_BREADCRUMB_REPORTED,
(int32_t) AIBinder_getCallingUid(), label,
state);
return Status::ok();
}
Status StatsService::allPullersFromBootRegistered() { Status StatsService::allPullersFromBootRegistered() {
ENFORCE_UID(AID_SYSTEM); ENFORCE_UID(AID_SYSTEM);

View File

@@ -161,11 +161,6 @@ public:
/** Inform statsCompanion that statsd is ready. */ /** Inform statsCompanion that statsd is ready. */
virtual void sayHiToStatsCompanion(); virtual void sayHiToStatsCompanion();
/**
* Binder call to get AppBreadcrumbReported atom.
*/
virtual Status sendAppBreadcrumbAtom(int32_t label, int32_t state) override;
/** /**
* Binder call to notify statsd that all pullers from boot have been registered. * Binder call to notify statsd that all pullers from boot have been registered.
*/ */