Remove BatteryStatsService.getStatistics*() methods

The format of the returned stream was a parcel. Since BatteryStatsImpl
has been removed from the Framework, it is no longer possible to
unparcel that stream.

Bug: 237123658
Test: atest FrameworksServicesTests:BatteryStatsTests
NoNonSdkCheck: BatteryStatsImpl has being permanently moved to a different package, making it impossible to maintain the implementations of getStatistics or getStatisticsStream.  Any data returned by these methods is available via `dumpsys batterystats`
Change-Id: I4e547f5ab4a44a379dcc19463345cc815b4085c7
This commit is contained in:
Dmitri Plotnikov
2022-06-24 17:13:10 -07:00
parent aff9c4ff94
commit 0dc1126af7
2 changed files with 0 additions and 58 deletions

View File

@@ -68,13 +68,6 @@ interface IBatteryStats {
@EnforcePermission("BATTERY_STATS")
List<BatteryUsageStats> getBatteryUsageStats(in List<BatteryUsageStatsQuery> queries);
@UnsupportedAppUsage
@EnforcePermission("BATTERY_STATS")
byte[] getStatistics();
@EnforcePermission("BATTERY_STATS")
ParcelFileDescriptor getStatisticsStream(boolean updateAll);
// Return true if we see the battery as currently charging.
@UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
@RequiresNoPermission

View File

@@ -56,7 +56,6 @@ import android.os.HandlerThread;
import android.os.IBinder;
import android.os.INetworkManagementService;
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFormatException;
import android.os.PowerManager.ServiceType;
import android.os.PowerManagerInternal;
@@ -728,56 +727,6 @@ public final class BatteryStatsService extends IBatteryStats.Stub
return mBatteryUsageStatsProvider.getBatteryUsageStats(queries);
}
@Override
@EnforcePermission(BATTERY_STATS)
public byte[] getStatistics() {
//Slog.i("foo", "SENDING BATTERY INFO:");
//mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM));
Parcel out = Parcel.obtain();
// Drain the handler queue to make sure we've handled all pending works, so we'll get
// an accurate stats.
awaitCompletion();
syncStats("get-stats", BatteryExternalStatsWorker.UPDATE_ALL);
synchronized (mStats) {
mStats.writeToParcel(out, 0);
}
byte[] data = out.marshall();
out.recycle();
return data;
}
/**
* Returns parceled BatteryStats as a MemoryFile.
*
* @param forceUpdate If true, runs a sync to get fresh battery stats. Otherwise,
* returns the current values.
*/
@Override
@EnforcePermission(BATTERY_STATS)
public ParcelFileDescriptor getStatisticsStream(boolean forceUpdate) {
//Slog.i("foo", "SENDING BATTERY INFO:");
//mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM));
Parcel out = Parcel.obtain();
if (forceUpdate) {
// Drain the handler queue to make sure we've handled all pending works, so we'll get
// an accurate stats.
awaitCompletion();
syncStats("get-stats", BatteryExternalStatsWorker.UPDATE_ALL);
}
synchronized (mStats) {
mStats.writeToParcel(out, 0);
}
byte[] data = out.marshall();
if (DBG) Slog.d(TAG, "getStatisticsStream parcel size is:" + data.length);
out.recycle();
try {
return ParcelFileDescriptor.fromData(data, "battery-stats");
} catch (IOException e) {
Slog.w(TAG, "Unable to create shared memory", e);
return null;
}
}
/** Register callbacks for statsd pulled atoms. */
private void registerStatsCallbacks() {
final StatsManager statsManager = mContext.getSystemService(StatsManager.class);