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

Commit 585422a5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fixes the bug that can occur when StatsCompanionService calls...

Merge "Fixes the bug that can occur when StatsCompanionService calls StatsService to update UID data and overflows kernel transfer buffer." into qt-dev
parents beff33a3 11e0d40b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ cc_defaults {
        ":statsd_aidl",
        "src/active_config_list.proto",
        "src/statsd_config.proto",
        "src/uid_data.proto",
        "src/FieldValue.cpp",
        "src/hash.cpp",
        "src/stats_log_util.cpp",
+43 −9
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include <cutils/multiuser.h>
#include <dirent.h>
#include <frameworks/base/cmds/statsd/src/statsd_config.pb.h>
#include <frameworks/base/cmds/statsd/src/uid_data.pb.h>
#include <private/android_filesystem_config.h>
#include <statslog.h>
#include <stdio.h>
@@ -953,16 +954,49 @@ bool StatsService::getUidFromString(const char* s, int32_t& uid) {
            || (callingUid == AID_ROOT && goodUid == AID_SHELL); // ROOT can impersonate SHELL.
}

Status StatsService::informAllUidData(const vector<int32_t>& uid, const vector<int64_t>& version,
                                      const vector<String16>& version_string,
                                      const vector<String16>& app,
                                      const vector<String16>& installer) {
Status StatsService::informAllUidData(const ParcelFileDescriptor& fd) {
    ENFORCE_UID(AID_SYSTEM);
    // Read stream into buffer.
    string buffer;
    if (!android::base::ReadFdToString(fd.get(), &buffer)) {
        return exception(Status::EX_ILLEGAL_ARGUMENT, "Failed to read all data from the pipe.");
    }

    VLOG("StatsService::informAllUidData was called");
    mUidMap->updateMap(getElapsedRealtimeNs(), uid, version, version_string, app, installer);
    VLOG("StatsService::informAllUidData succeeded");

    // Parse buffer.
    UidData uidData;
    if (!uidData.ParseFromString(buffer)) {
        return exception(Status::EX_ILLEGAL_ARGUMENT, "Error parsing proto stream for UidData.");
    }

    vector<String16> versionStrings;
    vector<String16> installers;
    vector<String16> packageNames;
    vector<int32_t> uids;
    vector<int64_t> versions;

    const auto numEntries = uidData.app_info_size();
    versionStrings.reserve(numEntries);
    installers.reserve(numEntries);
    packageNames.reserve(numEntries);
    uids.reserve(numEntries);
    versions.reserve(numEntries);

    for (const auto& appInfo: uidData.app_info()) {
        packageNames.emplace_back(String16(appInfo.package_name().c_str()));
        uids.push_back(appInfo.uid());
        versions.push_back(appInfo.version());
        versionStrings.emplace_back(String16(appInfo.version_string().c_str()));
        installers.emplace_back(String16(appInfo.installer().c_str()));
    }

    mUidMap->updateMap(getElapsedRealtimeNs(),
                       uids,
                       versions,
                       versionStrings,
                       packageNames,
                       installers);

    VLOG("StatsService::informAllUidData UidData proto parsed successfully.");
    return Status::ok();
}

+2 −3
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include <android/os/IStatsCompanionService.h>
#include <android/os/IStatsManager.h>
#include <binder/IResultReceiver.h>
#include <binder/ParcelFileDescriptor.h>
#include <utils/Looper.h>

#include <deque>
@@ -72,9 +73,7 @@ public:
    virtual Status informPollAlarmFired();
    virtual Status informAlarmForSubscriberTriggeringFired();

    virtual Status informAllUidData(const vector<int32_t>& uid, const vector<int64_t>& version,
                                    const vector<String16>& version_string,
                                    const vector<String16>& app, const vector<String16>& installer);
    virtual Status informAllUidData(const ParcelFileDescriptor& fd);
    virtual Status informOnePackage(const String16& app, int32_t uid, int64_t version,
                                    const String16& version_string, const String16& installer);
    virtual Status informOnePackageRemoved(const String16& app, int32_t uid);
+36 −0
Original line number Diff line number Diff line
/*
 * 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.
 */

syntax = "proto2";

package android.os.statsd;

option java_package = "com.android.internal.os";
option java_outer_classname = "UidDataProto";

message ApplicationInfo {
  optional int32 uid = 1;
  optional int64 version = 2;
  optional string version_string = 3;
  optional string package_name = 4;
  optional string installer = 5;
}

// StatsServiceCompanion uses the proto to supply statsd with uid-package
// mapping updates.
message UidData {
  repeated ApplicationInfo app_info = 1;
}
+6 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.os;

import android.os.IStatsPullerCallback;
import android.os.ParcelFileDescriptor;

/**
  * Binder interface to communicate with the statistics management service.
@@ -61,11 +62,12 @@ interface IStatsManager {
    void informDeviceShutdown();

    /**
     * Inform statsd what the version and package are for each uid. Note that each array should
     * have the same number of elements, and version[i] and package[i] correspond to uid[i].
     * Inform statsd about a file descriptor for a pipe through which we will pipe version
     * and package information for each uid.
     * Versions and package information are supplied via UidData proto where info for each app
     * is captured in its own element of a repeated ApplicationInfo message.
     */
    oneway void informAllUidData(in int[] uid, in long[] version, in String[] version_string,
        in String[] app, in String[] installer);
    oneway void informAllUidData(in ParcelFileDescriptor fd);

    /**
     * Inform statsd what the uid, version, version_string, and installer are for one app that was
Loading