Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 940921d0 authored by Dmitri Plotnikov's avatar Dmitri Plotnikov Committed by Android (Google) Code Review
Browse files

Merge "Enforce declared permissions on getCellularBatteryStats(),...

Merge "Enforce declared permissions on getCellularBatteryStats(), getWifiBatteryStats() and getGpsBatteryStats()" into sc-dev
parents d0595d18 84cededd
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.am;

import static android.content.pm.PackageManager.PERMISSION_DENIED;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED;
import static android.os.BatteryStats.POWER_DATA_UNAVAILABLE;

@@ -2524,6 +2525,12 @@ public final class BatteryStatsService extends IBatteryStats.Stub
     * @hide
     */
    public CellularBatteryStats getCellularBatteryStats() {
        if (mContext.checkCallingOrSelfPermission(
                android.Manifest.permission.UPDATE_DEVICE_STATS) == PERMISSION_DENIED) {
            mContext.enforceCallingOrSelfPermission(
                    android.Manifest.permission.BATTERY_STATS, null);
        }

        // Wait for the completion of pending works if there is any
        awaitCompletion();
        synchronized (mStats) {
@@ -2536,6 +2543,12 @@ public final class BatteryStatsService extends IBatteryStats.Stub
     * @hide
     */
    public WifiBatteryStats getWifiBatteryStats() {
        if (mContext.checkCallingOrSelfPermission(
                android.Manifest.permission.UPDATE_DEVICE_STATS) == PERMISSION_DENIED) {
            mContext.enforceCallingOrSelfPermission(
                    android.Manifest.permission.BATTERY_STATS, null);
        }

        // Wait for the completion of pending works if there is any
        awaitCompletion();
        synchronized (mStats) {
@@ -2548,6 +2561,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
     * @hide
     */
    public GpsBatteryStats getGpsBatteryStats() {
        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BATTERY_STATS, null);

        // Wait for the completion of pending works if there is any
        awaitCompletion();
        synchronized (mStats) {