From 67ad2e7a555c870ea01dc0eb522fa665bdce3ba6 Mon Sep 17 00:00:00 2001 From: Jeffrey Huang Date: Fri, 17 Jan 2020 13:28:27 -0800 Subject: [PATCH] Delete References to Statsd in StatsManager Test: adb shell cmd stats pull-source 10000 (chosen randomly) Change-Id: I9578f84213e6c2787da60ae7e2c20157087d5b6a --- apex/statsd/aidl/Android.bp | 1 - .../aidl/android/os/IStatsPullerCallback.aidl | 36 ----------- apex/statsd/aidl/android/os/IStatsd.aidl | 18 ------ cmds/statsd/Android.bp | 1 - cmds/statsd/src/StatsService.cpp | 18 ------ cmds/statsd/src/StatsService.h | 13 ---- .../StatsCallbackPullerDeprecated.cpp | 63 ------------------ .../external/StatsCallbackPullerDeprecated.h | 39 ----------- .../src/external/StatsPullerManager.cpp | 27 -------- cmds/statsd/src/external/StatsPullerManager.h | 6 -- cmds/statsd/src/guardrail/StatsdStats.h | 3 - core/java/android/app/StatsManager.java | 64 ------------------- 12 files changed, 289 deletions(-) delete mode 100644 apex/statsd/aidl/android/os/IStatsPullerCallback.aidl delete mode 100644 cmds/statsd/src/external/StatsCallbackPullerDeprecated.cpp delete mode 100644 cmds/statsd/src/external/StatsCallbackPullerDeprecated.h diff --git a/apex/statsd/aidl/Android.bp b/apex/statsd/aidl/Android.bp index f8325d47e2688..cc5172c6018ac 100644 --- a/apex/statsd/aidl/Android.bp +++ b/apex/statsd/aidl/Android.bp @@ -23,7 +23,6 @@ filegroup { "android/os/IPullAtomResultReceiver.aidl", "android/os/IStatsCompanionService.aidl", "android/os/IStatsd.aidl", - "android/os/IStatsPullerCallback.aidl", "android/util/StatsEventParcel.aidl", ], } diff --git a/apex/statsd/aidl/android/os/IStatsPullerCallback.aidl b/apex/statsd/aidl/android/os/IStatsPullerCallback.aidl deleted file mode 100644 index c3e1e55dde06e..0000000000000 --- a/apex/statsd/aidl/android/os/IStatsPullerCallback.aidl +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2019 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 android.os; - -import android.os.StatsLogEventWrapper; - -/** - * DEPRECATED - * Binder interface to pull atoms for the stats service. - * {@hide} - */ -interface IStatsPullerCallback { - /** - * Pull data for the specified atom tag. Returns an array of StatsLogEventWrapper containing - * the data. - * - * Note: These pulled atoms should not have uid/attribution chain. Additionally, the event - * timestamps will be truncated to the nearest 5 minutes. - */ - StatsLogEventWrapper[] pullData(int atomTag, long elapsedNanos, long wallClocknanos); - -} diff --git a/apex/statsd/aidl/android/os/IStatsd.aidl b/apex/statsd/aidl/android/os/IStatsd.aidl index 0ecf2f0b48517..a2564212366f0 100644 --- a/apex/statsd/aidl/android/os/IStatsd.aidl +++ b/apex/statsd/aidl/android/os/IStatsd.aidl @@ -16,7 +16,6 @@ package android.os; -import android.os.IStatsPullerCallback; import android.os.IPendingIntentRef; import android.os.IPullAtomCallback; import android.os.ParcelFileDescriptor; @@ -183,16 +182,6 @@ interface IStatsd { */ void sendAppBreadcrumbAtom(int label, int state); - /** - * Registers a puller callback function that, when invoked, pulls the data - * for the specified vendor atom tag. - * - * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS - * @deprecated please use registerPullAtomCallback. - */ - oneway void registerPullerCallback(int atomTag, IStatsPullerCallback pullerCallback, - String packageName); - /** * Registers a puller callback function that, when invoked, pulls the data * for the specified atom tag. @@ -207,13 +196,6 @@ interface IStatsd { oneway void registerNativePullAtomCallback(int atomTag, long coolDownNs, long timeoutNs, in int[] additiveFields, IPullAtomCallback pullerCallback); - /** - * Unregisters a puller callback function for the given vendor atom. - * - * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS - */ - oneway void unregisterPullerCallback(int atomTag, String packageName); - /** * Unregisters any pullAtomCallback for the given uid/atom. */ diff --git a/cmds/statsd/Android.bp b/cmds/statsd/Android.bp index 1c6867c397909..6eafbd8bb3f16 100644 --- a/cmds/statsd/Android.bp +++ b/cmds/statsd/Android.bp @@ -73,7 +73,6 @@ cc_defaults { "src/external/puller_util.cpp", "src/external/ResourceHealthManagerPuller.cpp", "src/external/StatsCallbackPuller.cpp", - "src/external/StatsCallbackPullerDeprecated.cpp", "src/external/StatsCompanionServicePuller.cpp", "src/external/StatsPuller.cpp", "src/external/StatsPullerManager.cpp", diff --git a/cmds/statsd/src/StatsService.cpp b/cmds/statsd/src/StatsService.cpp index ada2f2de28f42..c1a8d69191d21 100644 --- a/cmds/statsd/src/StatsService.cpp +++ b/cmds/statsd/src/StatsService.cpp @@ -1265,16 +1265,6 @@ Status StatsService::sendAppBreadcrumbAtom(int32_t label, int32_t state) { return Status::ok(); } -Status StatsService::registerPullerCallback(int32_t atomTag, - const sp& pullerCallback, - const String16& packageName) { - ENFORCE_DUMP_AND_USAGE_STATS(packageName); - - VLOG("StatsService::registerPullerCallback called."); - mPullerManager->RegisterPullerCallback(atomTag, pullerCallback); - return Status::ok(); -} - Status StatsService::registerPullAtomCallback(int32_t uid, int32_t atomTag, int64_t coolDownNs, int64_t timeoutNs, const std::vector& additiveFields, const sp& pullerCallback) { @@ -1297,14 +1287,6 @@ Status StatsService::registerNativePullAtomCallback(int32_t atomTag, int64_t coo return Status::ok(); } -Status StatsService::unregisterPullerCallback(int32_t atomTag, const String16& packageName) { - ENFORCE_DUMP_AND_USAGE_STATS(packageName); - - VLOG("StatsService::unregisterPullerCallback called."); - mPullerManager->UnregisterPullerCallback(atomTag); - return Status::ok(); -} - Status StatsService::unregisterPullAtomCallback(int32_t uid, int32_t atomTag) { ENFORCE_UID(AID_SYSTEM); VLOG("StatsService::unregisterPullAtomCallback called."); diff --git a/cmds/statsd/src/StatsService.h b/cmds/statsd/src/StatsService.h index 7990e5e7d018a..f2079d9f278f0 100644 --- a/cmds/statsd/src/StatsService.h +++ b/cmds/statsd/src/StatsService.h @@ -170,14 +170,6 @@ public: */ virtual Status sendAppBreadcrumbAtom(int32_t label, int32_t state) override; - /** - * Binder call to register a callback function for a vendor pulled atom. - * Note: this atom must NOT have uid as a field. - */ - virtual Status registerPullerCallback(int32_t atomTag, - const sp& pullerCallback, - const String16& packageName) override; - /** * Binder call to register a callback function for a pulled atom. */ @@ -192,11 +184,6 @@ public: int64_t timeoutNs, const std::vector& additiveFields, const sp& pullerCallback) override; - /** - * Binder call to unregister any existing callback function for a vendor pulled atom. - */ - virtual Status unregisterPullerCallback(int32_t atomTag, const String16& packageName) override; - /** * Binder call to unregister any existing callback for the given uid and atom. */ diff --git a/cmds/statsd/src/external/StatsCallbackPullerDeprecated.cpp b/cmds/statsd/src/external/StatsCallbackPullerDeprecated.cpp deleted file mode 100644 index 4f88a91f9ec61..0000000000000 --- a/cmds/statsd/src/external/StatsCallbackPullerDeprecated.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2019 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. - */ - -#define DEBUG false // STOPSHIP if true -#include "Log.h" - -#include "StatsCallbackPullerDeprecated.h" - -#include - -#include "logd/LogEvent.h" -#include "stats_log_util.h" - -using namespace android::binder; - -namespace android { -namespace os { -namespace statsd { - -StatsCallbackPullerDeprecated::StatsCallbackPullerDeprecated( - int tagId, const sp& callback) - : StatsPuller(tagId), mCallback(callback) { - VLOG("StatsCallbackPuller created for tag %d", tagId); -} - -bool StatsCallbackPullerDeprecated::PullInternal(vector>* data) { - VLOG("StatsCallbackPuller called for tag %d", mTagId) - if (mCallback == nullptr) { - ALOGW("No callback registered"); - return false; - } - int64_t wallClockTimeNs = getWallClockNs(); - int64_t elapsedTimeNs = getElapsedRealtimeNs(); - vector returned_value; - Status status = mCallback->pullData(mTagId, elapsedTimeNs, wallClockTimeNs, &returned_value); - if (!status.isOk()) { - ALOGW("StatsCallbackPuller::pull failed for %d", mTagId); - return false; - } - data->clear(); - for (const StatsLogEventWrapper& it : returned_value) { - LogEvent::createLogEvents(it, *data); - } - VLOG("StatsCallbackPuller::pull succeeded for %d", mTagId); - return true; -} - -} // namespace statsd -} // namespace os -} // namespace android diff --git a/cmds/statsd/src/external/StatsCallbackPullerDeprecated.h b/cmds/statsd/src/external/StatsCallbackPullerDeprecated.h deleted file mode 100644 index 0289029759231..0000000000000 --- a/cmds/statsd/src/external/StatsCallbackPullerDeprecated.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2019 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. - */ - -#pragma once - -#include -#include - -#include "StatsPuller.h" - -namespace android { -namespace os { -namespace statsd { - -class StatsCallbackPullerDeprecated : public StatsPuller { -public: - explicit StatsCallbackPullerDeprecated(int tagId, const sp& callback); - -private: - bool PullInternal(vector >* data) override; - const sp mCallback; -}; - -} // namespace statsd -} // namespace os -} // namespace android diff --git a/cmds/statsd/src/external/StatsPullerManager.cpp b/cmds/statsd/src/external/StatsPullerManager.cpp index d5cda85f412a2..daab1290615cc 100644 --- a/cmds/statsd/src/external/StatsPullerManager.cpp +++ b/cmds/statsd/src/external/StatsPullerManager.cpp @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -38,7 +37,6 @@ #include "PowerStatsPuller.h" #include "ResourceHealthManagerPuller.h" #include "StatsCallbackPuller.h" -#include "StatsCallbackPullerDeprecated.h" #include "StatsCompanionServicePuller.h" #include "SubsystemSleepStatePuller.h" #include "TrainInfoPuller.h" @@ -406,21 +404,6 @@ int StatsPullerManager::ClearPullerCacheIfNecessary(int64_t timestampNs) { return totalCleared; } -// Deprecated, remove after puller API is complete. -void StatsPullerManager::RegisterPullerCallback(int32_t atomTag, - const sp& callback) { - AutoMutex _l(mLock); - // Platform pullers cannot be changed. - if (!isVendorPulledAtom(atomTag)) { - VLOG("RegisterPullerCallback: atom tag %d is not vendor pulled", atomTag); - return; - } - VLOG("RegisterPullerCallback: adding puller for tag %d", atomTag); - StatsdStats::getInstance().notePullerCallbackRegistrationChanged(atomTag, /*registered=*/true); - kAllPullAtomInfo[{.atomTag = atomTag}] = { - .puller = new StatsCallbackPullerDeprecated(atomTag, callback)}; -} - void StatsPullerManager::RegisterPullAtomCallback(const int uid, const int32_t atomTag, const int64_t coolDownNs, const int64_t timeoutNs, const vector& additiveFields, @@ -437,16 +420,6 @@ void StatsPullerManager::RegisterPullAtomCallback(const int uid, const int32_t a }; } -void StatsPullerManager::UnregisterPullerCallback(int32_t atomTag) { - AutoMutex _l(mLock); - // Platform pullers cannot be changed. - if (!isVendorPulledAtom(atomTag)) { - return; - } - StatsdStats::getInstance().notePullerCallbackRegistrationChanged(atomTag, /*registered=*/false); - kAllPullAtomInfo.erase({.atomTag = atomTag}); -} - void StatsPullerManager::UnregisterPullAtomCallback(const int uid, const int32_t atomTag) { AutoMutex _l(mLock); StatsdStats::getInstance().notePullerCallbackRegistrationChanged(atomTag, /*registered=*/false); diff --git a/cmds/statsd/src/external/StatsPullerManager.h b/cmds/statsd/src/external/StatsPullerManager.h index 349fd47b6c9d7..4b6ab57b3bbea 100644 --- a/cmds/statsd/src/external/StatsPullerManager.h +++ b/cmds/statsd/src/external/StatsPullerManager.h @@ -18,7 +18,6 @@ #include #include -#include #include #include #include @@ -116,15 +115,10 @@ public: void SetStatsCompanionService(sp statsCompanionService); - // Deprecated, remove after puller API is complete. - void RegisterPullerCallback(int32_t atomTag, const sp& callback); - void RegisterPullAtomCallback(const int uid, const int32_t atomTag, const int64_t coolDownNs, const int64_t timeoutNs, const vector& additiveFields, const sp& callback); - void UnregisterPullerCallback(int32_t atomTag); - void UnregisterPullAtomCallback(const int uid, const int32_t atomTag); static std::map kAllPullAtomInfo; diff --git a/cmds/statsd/src/guardrail/StatsdStats.h b/cmds/statsd/src/guardrail/StatsdStats.h index 692d91e1a82f9..32827852ecadc 100644 --- a/cmds/statsd/src/guardrail/StatsdStats.h +++ b/cmds/statsd/src/guardrail/StatsdStats.h @@ -164,9 +164,6 @@ public: // Maximum number of pushed atoms statsd stats will track above kMaxPushedAtomId. static const int kMaxNonPlatformPushedAtoms = 100; - // Max platform atom tag number. - static const int32_t kMaxPlatformAtomTag = 100000; - // Vendor pulled atom start id. static const int32_t kVendorPulledAtomStartTag = 150000; diff --git a/core/java/android/app/StatsManager.java b/core/java/android/app/StatsManager.java index 0beceb0a1f089..0ea05d8f683c6 100644 --- a/core/java/android/app/StatsManager.java +++ b/core/java/android/app/StatsManager.java @@ -25,11 +25,9 @@ import android.annotation.RequiresPermission; import android.annotation.SystemApi; import android.content.Context; import android.os.Binder; -import android.os.IBinder; import android.os.IPullAtomCallback; import android.os.IPullAtomResultReceiver; import android.os.IStatsManagerService; -import android.os.IStatsPullerCallback; import android.os.IStatsd; import android.os.RemoteException; import android.os.ServiceManager; @@ -475,42 +473,6 @@ public final class StatsManager { } } - /** - * Registers a callback for an atom when that atom is to be pulled. The stats service will - * invoke pullData in the callback when the stats service determines that this atom needs to be - * pulled. Currently, this only works for atoms with tags above 100,000 that do not have a uid. - * - * @param atomTag The tag of the atom for this puller callback. Must be at least 100000. - * @param callback The callback to be invoked when the stats service pulls the atom. - * @throws StatsUnavailableException if unsuccessful due to failing to connect to stats service - * - * @hide - * @deprecated Please use registerPullAtomCallback - */ - @Deprecated - @RequiresPermission(allOf = { DUMP, PACKAGE_USAGE_STATS }) - public void setPullerCallback(int atomTag, IStatsPullerCallback callback) - throws StatsUnavailableException { - synchronized (sLock) { - try { - IStatsd service = getIStatsdLocked(); - if (callback == null) { - service.unregisterPullerCallback(atomTag, mContext.getOpPackageName()); - } else { - service.registerPullerCallback(atomTag, callback, - mContext.getOpPackageName()); - } - - } catch (RemoteException e) { - Slog.e(TAG, "Failed to connect to statsd when registering data listener."); - throw new StatsUnavailableException("could not connect", e); - } catch (SecurityException e) { - throw new StatsUnavailableException(e.getMessage(), e); - } - } - } - - /** * Temp registration for while the migration is in progress. * @@ -734,32 +696,6 @@ public final class StatsManager { int onPullAtom(int atomTag, @NonNull List data); } - private class StatsdDeathRecipient implements IBinder.DeathRecipient { - @Override - public void binderDied() { - synchronized (sLock) { - mService = null; - } - } - } - - @GuardedBy("sLock") - private IStatsd getIStatsdLocked() throws StatsUnavailableException { - if (mService != null) { - return mService; - } - mService = IStatsd.Stub.asInterface(ServiceManager.getService("stats")); - if (mService == null) { - throw new StatsUnavailableException("could not be found"); - } - try { - mService.asBinder().linkToDeath(new StatsdDeathRecipient(), 0); - } catch (RemoteException e) { - throw new StatsUnavailableException("could not connect when linkToDeath", e); - } - return mService; - } - @GuardedBy("sLock") private IStatsManagerService getIStatsManagerServiceLocked() { if (mStatsManagerService != null) {