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

Commit 2efb018f authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 11227258 from c321fe2a to 24Q2-release

Change-Id: I22b36fbc2b463afd34d0051df0840ac281fd0021
parents 522b7268 c321fe2a
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -1035,8 +1035,6 @@ static void DoLogcat() {
        CommandOptions::WithTimeoutInMs(timeout_ms).Build(), true /* verbose_duration */);
    DoRadioLogcat();

    RunCommand("LOG STATISTICS", {"logcat", "-b", "all", "-S"});

    /* kernels must set CONFIG_PSTORE_PMSG, slice up pstore with device tree */
    RunCommand("LAST LOGCAT", {"logcat", "-L", "-b", "all", "-v", "threadtime", "-v", "printable",
                               "-v", "uid", "-d", "*:v"});
@@ -1243,7 +1241,7 @@ static void DumpPacketStats() {

static void DumpIpAddrAndRules() {
    /* The following have a tendency to get wedged when wifi drivers/fw goes belly-up. */
    RunCommand("NETWORK INTERFACES", {"ip", "link"});
    RunCommand("NETWORK INTERFACES", {"ip", "-s", "link"});
    RunCommand("IPv4 ADDRESSES", {"ip", "-4", "addr", "show"});
    RunCommand("IPv6 ADDRESSES", {"ip", "-6", "addr", "show"});
    RunCommand("IP RULES", {"ip", "rule", "show"});
@@ -1526,7 +1524,7 @@ static void DumpExternalFragmentationInfo() {
}

static void DumpstateLimitedOnly() {
    // Trimmed-down version of dumpstate to only include a whitelisted
    // Trimmed-down version of dumpstate to only include a allowlisted
    // set of logs (system log, event log, and system server / system app
    // crashes, and networking logs). See b/136273873 and b/138459828
    // for context.
+29 −9
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ use std::io;
use std::io::{BufRead, Write};
use std::path::PathBuf;

use clap::Parser;
use clap::{Parser, ValueEnum};
use nix::sys::time::TimeVal;

mod evdev;
@@ -39,6 +39,19 @@ struct Args {
    device: Option<PathBuf>,
    /// The file to save the recording to. Defaults to standard output.
    output_file: Option<PathBuf>,

    /// The base time that timestamps should be relative to (Android-specific extension)
    #[arg(long, value_enum, default_value_t = TimestampBase::FirstEvent)]
    timestamp_base: TimestampBase,
}

#[derive(Clone, Debug, ValueEnum)]
enum TimestampBase {
    /// The first event received from the device.
    FirstEvent,

    /// The time when the system booted.
    Boot,
}

fn get_choice(max: u32) -> u32 {
@@ -149,7 +162,11 @@ fn print_device_description(
    Ok(())
}

fn print_events(device: &evdev::Device, output: &mut impl Write) -> Result<(), Box<dyn Error>> {
fn print_events(
    device: &evdev::Device,
    output: &mut impl Write,
    timestamp_base: TimestampBase,
) -> Result<(), Box<dyn Error>> {
    fn print_event(output: &mut impl Write, event: &evdev::InputEvent) -> Result<(), io::Error> {
        // TODO(b/302297266): Translate events into human-readable names and add those as comments.
        writeln!(
@@ -164,12 +181,15 @@ fn print_events(device: &evdev::Device, output: &mut impl Write) -> Result<(), B
        Ok(())
    }
    let event = device.read_event()?;
    // Due to a bug in the C implementation of evemu-play [0] that has since become part of the API,
    // the timestamp of the first event in a recording shouldn't be exactly 0.0 seconds, so offset
    // it by 1µs.
    let start_time = match timestamp_base {
        // Due to a bug in the C implementation of evemu-play [0] that has since become part of the
        // API, the timestamp of the first event in a recording shouldn't be exactly 0.0 seconds,
        // so offset it by 1µs.
        //
        // [0]: https://gitlab.freedesktop.org/libevdev/evemu/-/commit/eba96a4d2be7260b5843e65c4b99c8b06a1f4c9d
    let start_time = event.time - TimeVal::new(0, 1);
        TimestampBase::FirstEvent => event.time - TimeVal::new(0, 1),
        TimestampBase::Boot => TimeVal::new(0, 0),
    };
    print_event(output, &event.offset_time_by(start_time))?;
    loop {
        let event = device.read_event()?;
@@ -188,6 +208,6 @@ fn main() -> Result<(), Box<dyn Error>> {
        None => Box::new(io::stdout().lock()),
    };
    print_device_description(&device, &mut output)?;
    print_events(&device, &mut output)?;
    print_events(&device, &mut output, args.timestamp_base)?;
    Ok(())
}
+23 −8
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
#include <fstream>
#include <functional>
#include <regex>
#include <thread>
#include <unordered_set>

#include <android-base/file.h>
@@ -555,12 +556,14 @@ static int restorecon_app_data_lazy(const std::string& path, const std::string&
    // If the initial top-level restorecon above changed the label, then go
    // back and restorecon everything recursively
    if (inProgress || before != after) {
        ScopedTrace tracer("label-change");
        if (existing) {
            LOG(DEBUG) << "Detected label change from " << before << " to " << after << " at "
                       << path << "; running recursive restorecon";
        }

        auto restorecon = [path, seInfo, uid]() {
            ScopedTrace tracer("label-change");

            // Temporary mark the folder as "in-progress" to resume in case of reboot/other failure.
            RestoreconInProgress fence(path);

@@ -569,6 +572,18 @@ static int restorecon_app_data_lazy(const std::string& path, const std::string&
                PLOG(ERROR) << "Failed recursive restorecon for " << path;
                return -1;
            }
            return 0;
        };
        if (inProgress) {
            // The previous restorecon was interrupted. It's either crashed (unlikely), or the phone
            // was rebooted. Possibly because it took too much time. This time let's move it to a
            // separate thread - so it won't block the rest of the OS.
            std::thread(restorecon).detach();
        } else {
            if (int result = restorecon(); result) {
                return result;
            }
        }
    }

    return 0;

cmds/ip-up-vpn/ip-up-vpn.c

deleted100644 → 0
+0 −139
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 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 LOG_TAG "ip-up-vpn"

#include <arpa/inet.h>
#include <errno.h>
#include <linux/if.h>
#include <linux/route.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>

#include <log/log.h>

#define DIR "/data/misc/vpn/"

static const char *env(const char *name) {
    const char *value = getenv(name);
    return value ? value : "";
}

static int set_address(struct sockaddr *sa, const char *address) {
    sa->sa_family = AF_INET;
    errno = EINVAL;
    return inet_pton(AF_INET, address, &((struct sockaddr_in *)sa)->sin_addr);
}

/*
 * The primary goal is to create a file with VPN parameters. Currently they
 * are interface, addresses, routes, DNS servers, and search domains and VPN
 * server address. Each parameter occupies one line in the file, and it can be
 * an empty string or space-separated values. The order and the format must be
 * consistent with com.android.server.connectivity.Vpn. Here is an example.
 *
 *   ppp0
 *   192.168.1.100/24
 *   0.0.0.0/0
 *   192.168.1.1 192.168.1.2
 *   example.org
 *   192.0.2.1
 *
 * The secondary goal is to unify the outcome of VPN. The current baseline
 * is to have an interface configured with the given address and netmask
 * and maybe add a host route to protect the tunnel. PPP-based VPN already
 * does this, but others might not. Routes, DNS servers, and search domains
 * are handled by the framework since they can be overridden by the users.
 */
int main(int argc, char **argv)
{
    FILE *state = fopen(DIR ".tmp", "wb");
    if (!state) {
        ALOGE("Cannot create state: %s", strerror(errno));
        return 1;
    }

    if (argc >= 6) {
        /* Invoked by pppd. */
        fprintf(state, "%s\n", argv[1]);
        fprintf(state, "%s/32\n", argv[4]);
        fprintf(state, "0.0.0.0/0\n");
        fprintf(state, "%s %s\n", env("DNS1"), env("DNS2"));
        fprintf(state, "\n");
        fprintf(state, "\n");
    } else if (argc == 2) {
        /* Invoked by racoon. */
        const char *interface = env("INTERFACE");
        const char *address = env("INTERNAL_ADDR4");
        const char *routes = env("SPLIT_INCLUDE_CIDR");

        int s = socket(AF_INET, SOCK_DGRAM, 0);
        struct ifreq ifr;
        memset(&ifr, 0, sizeof(ifr));

        /* Bring up the interface. */
        ifr.ifr_flags = IFF_UP;
        strncpy(ifr.ifr_name, interface, IFNAMSIZ);
        if (ioctl(s, SIOCSIFFLAGS, &ifr)) {
            ALOGE("Cannot bring up %s: %s", interface, strerror(errno));
            fclose(state);
            return 1;
        }

        /* Set the address. */
        if (!set_address(&ifr.ifr_addr, address) ||
                ioctl(s, SIOCSIFADDR, &ifr)) {
            ALOGE("Cannot set address: %s", strerror(errno));
            fclose(state);
            return 1;
        }

        /* Set the netmask. */
        if (set_address(&ifr.ifr_netmask, env("INTERNAL_NETMASK4"))) {
            if (ioctl(s, SIOCSIFNETMASK, &ifr)) {
                ALOGE("Cannot set netmask: %s", strerror(errno));
                fclose(state);
                return 1;
            }
        }

        /* TODO: Send few packets to trigger phase 2? */

        fprintf(state, "%s\n", interface);
        fprintf(state, "%s/%s\n", address, env("INTERNAL_CIDR4"));
        fprintf(state, "%s\n", routes[0] ? routes : "0.0.0.0/0");
        fprintf(state, "%s\n", env("INTERNAL_DNS4_LIST"));
        fprintf(state, "%s\n", env("DEFAULT_DOMAIN"));
        fprintf(state, "%s\n", env("REMOTE_ADDR"));
    } else {
        ALOGE("Cannot parse parameters");
        fclose(state);
        return 1;
    }

    fclose(state);
    if (chmod(DIR ".tmp", 0444) || rename(DIR ".tmp", DIR "state")) {
        ALOGE("Cannot write state: %s", strerror(errno));
        return 1;
    }
    return 0;
}
+114 −12
Original line number Diff line number Diff line
@@ -60,6 +60,27 @@ __BEGIN_DECLS

struct APerformanceHintManager;
struct APerformanceHintSession;
struct AWorkDuration;

/**
 * {@link AWorkDuration} is an opaque type that represents the breakdown of the
 * actual workload duration in each component internally.
 *
 * A new {@link AWorkDuration} can be obtained using
 * {@link AWorkDuration_create()}, when the client finishes using
 * {@link AWorkDuration}, {@link AWorkDuration_release()} must be
 * called to destroy and free up the resources associated with
 * {@link AWorkDuration}.
 *
 * This file provides a set of functions to allow clients to set the measured
 * work duration of each component on {@link AWorkDuration}.
 *
 * - AWorkDuration_setWorkPeriodStartTimestampNanos()
 * - AWorkDuration_setActualTotalDurationNanos()
 * - AWorkDuration_setActualCpuDurationNanos()
 * - AWorkDuration_setActualGpuDurationNanos()
 */
typedef struct AWorkDuration AWorkDuration;

/**
 * An opaque type representing a handle to a performance hint manager.
@@ -102,7 +123,7 @@ typedef struct APerformanceHintSession APerformanceHintSession;
  *
  * @return APerformanceHintManager instance on success, nullptr on failure.
  */
APerformanceHintManager* APerformanceHint_getManager() __INTRODUCED_IN(__ANDROID_API_T__);
APerformanceHintManager* _Nullable APerformanceHint_getManager() __INTRODUCED_IN(__ANDROID_API_T__);

/**
 * Creates a session for the given set of threads and sets their initial target work
@@ -116,9 +137,9 @@ APerformanceHintManager* APerformanceHint_getManager() __INTRODUCED_IN(__ANDROID
 *     This must be positive if using the work duration API, or 0 otherwise.
 * @return APerformanceHintManager instance on success, nullptr on failure.
 */
APerformanceHintSession* APerformanceHint_createSession(
        APerformanceHintManager* manager,
        const int32_t* threadIds, size_t size,
APerformanceHintSession* _Nullable APerformanceHint_createSession(
        APerformanceHintManager* _Nonnull manager,
        const int32_t* _Nonnull threadIds, size_t size,
        int64_t initialTargetWorkDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__);

/**
@@ -128,7 +149,7 @@ APerformanceHintSession* APerformanceHint_createSession(
 * @return the preferred update rate supported by device software.
 */
int64_t APerformanceHint_getPreferredUpdateRateNanos(
        APerformanceHintManager* manager) __INTRODUCED_IN(__ANDROID_API_T__);
        APerformanceHintManager* _Nonnull manager) __INTRODUCED_IN(__ANDROID_API_T__);

/**
 * Updates this session's target duration for each cycle of work.
@@ -140,7 +161,7 @@ int64_t APerformanceHint_getPreferredUpdateRateNanos(
 *         EPIPE if communication with the system service has failed.
 */
int APerformanceHint_updateTargetWorkDuration(
        APerformanceHintSession* session,
        APerformanceHintSession* _Nonnull session,
        int64_t targetDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__);

/**
@@ -157,7 +178,7 @@ int APerformanceHint_updateTargetWorkDuration(
 *         EPIPE if communication with the system service has failed.
 */
int APerformanceHint_reportActualWorkDuration(
        APerformanceHintSession* session,
        APerformanceHintSession* _Nonnull session,
        int64_t actualDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__);

/**
@@ -167,7 +188,7 @@ int APerformanceHint_reportActualWorkDuration(
 * @param session The performance hint session instance to release.
 */
void APerformanceHint_closeSession(
        APerformanceHintSession* session) __INTRODUCED_IN(__ANDROID_API_T__);
        APerformanceHintSession* _Nonnull session) __INTRODUCED_IN(__ANDROID_API_T__);

/**
 * Set a list of threads to the performance hint session. This operation will replace
@@ -184,8 +205,8 @@ void APerformanceHint_closeSession(
 *         EPERM if any thread id doesn't belong to the application.
 */
int APerformanceHint_setThreads(
        APerformanceHintSession* session,
        const pid_t* threadIds,
        APerformanceHintSession* _Nonnull session,
        const pid_t* _Nonnull threadIds,
        size_t size) __INTRODUCED_IN(__ANDROID_API_U__);

/**
@@ -198,9 +219,90 @@ int APerformanceHint_setThreads(
 *         EPIPE if communication with the system service has failed.
 */
int APerformanceHint_setPreferPowerEfficiency(
        APerformanceHintSession* session,
        APerformanceHintSession* _Nonnull session,
        bool enabled) __INTRODUCED_IN(__ANDROID_API_V__);

/**
 * Reports the durations for the last cycle of work.
 *
 * The system will attempt to adjust the scheduling and performance of the
 * threads within the thread group to bring the actual duration close to the target duration.
 *
 * @param session The {@link APerformanceHintSession} instance to update.
 * @param workDuration The {@link AWorkDuration} structure of times the thread group took to
 *     complete its last task in nanoseconds breaking down into different components.
 *
 *     The work period start timestamp, actual total duration and actual CPU duration must be
 *     positive.
 *
 *     The actual GPU duration must be non-negative. If the actual GPU duration is 0, it means
 *     the actual GPU duration is not measured.
 *
 * @return 0 on success.
 *         EINVAL if session is nullptr or any duration is an invalid number.
 *         EPIPE if communication with the system service has failed.
 */
int APerformanceHint_reportActualWorkDuration2(
        APerformanceHintSession* _Nonnull session,
        AWorkDuration* _Nonnull workDuration) __INTRODUCED_IN(__ANDROID_API_V__);

/**
 * Creates a new AWorkDuration. When the client finishes using {@link AWorkDuration}, it should
 * call {@link AWorkDuration_release()} to destroy {@link AWorkDuration} and release all resources
 * associated with it.
 *
 * @return AWorkDuration on success and nullptr otherwise.
 */
AWorkDuration* _Nonnull AWorkDuration_create() __INTRODUCED_IN(__ANDROID_API_V__);

/**
 * Destroys {@link AWorkDuration} and free all resources associated to it.
 *
 * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}
 */
void AWorkDuration_release(AWorkDuration* _Nonnull WorkDuration) __INTRODUCED_IN(__ANDROID_API_V__);

/**
 * Sets the work period start timestamp in nanoseconds.
 *
 * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}
 * @param workPeriodStartTimestampNanos The work period start timestamp in nanoseconds based on
 *        CLOCK_MONOTONIC about when the work starts, the timestamp must be positive.
 */
void AWorkDuration_setWorkPeriodStartTimestampNanos(AWorkDuration* _Nonnull aWorkDuration,
        int64_t workPeriodStartTimestampNanos) __INTRODUCED_IN(__ANDROID_API_V__);

/**
 * Sets the actual total work duration in nanoseconds.
 *
 * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}
 * @param actualTotalDurationNanos The actual total work duration in nanoseconds, the number must be
 *        positive.
 */
void AWorkDuration_setActualTotalDurationNanos(AWorkDuration* _Nonnull aWorkDuration,
        int64_t actualTotalDurationNanos) __INTRODUCED_IN(__ANDROID_API_V__);

/**
 * Sets the actual CPU work duration in nanoseconds.
 *
 * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}
 * @param actualCpuDurationNanos The actual CPU work duration in nanoseconds, the number must be
 *        positive.
 */
void AWorkDuration_setActualCpuDurationNanos(AWorkDuration* _Nonnull aWorkDuration,
        int64_t actualCpuDurationNanos) __INTRODUCED_IN(__ANDROID_API_V__);

/**
 * Sets the actual GPU work duration in nanoseconds.
 *
 * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()}.
 * @param actualGpuDurationNanos The actual GPU work duration in nanoseconds, the number must be
 *        non-negative. If the actual GPU duration is 0, it means the actual GPU duration is
 *        measured.
 */
void AWorkDuration_setActualGpuDurationNanos(AWorkDuration* _Nonnull aWorkDuration,
        int64_t actualGpuDurationNanos) __INTRODUCED_IN(__ANDROID_API_V__);

__END_DECLS

#endif // ANDROID_NATIVE_PERFORMANCE_HINT_H
Loading