diff options
author | Derek Sollenberger <djsollen@google.com> | 2016-12-01 14:37:41 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-12-02 14:11:24 +0000 |
commit | 78b35230aaa2620f826266e3f2385bf06eb881ed (patch) | |
tree | 28104f2dff9cf0eaa2e8987b45269f6157c6e150 /platform_tools/android | |
parent | 9c77ea1ea5a1fa26f10d3bf83a6250008af78049 (diff) |
Archive or update unsupported Android scripts and third-party dependencies.
- nothing uses ashmem;
- cpufeatures and native_app_glue are now pulled from the NDK;
- no bots use the scripts in platform_tools/android/bin;
- update scripts to work with GN instead of GYP.
Change-Id: I14f47eeadb3047505e232dd10385f58ef12c73f4
Reviewed-on: https://skia-review.googlesource.com/5422
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Derek Sollenberger <djsollen@google.com>
Diffstat (limited to 'platform_tools/android')
27 files changed, 87 insertions, 3738 deletions
diff --git a/platform_tools/android/bin/adb_list_devices.py b/platform_tools/android/bin/adb_list_devices.py deleted file mode 100755 index f140484f4b..0000000000 --- a/platform_tools/android/bin/adb_list_devices.py +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/python -# -# Copyright (c) 2012 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -""" adb_list_devices: list information about attached Android devices. """ - - -import os -import re -import shlex -import subprocess -import sys - -# This file, which resides on every Android device, contains a great deal of -# information about the device. -INFO_FILE = '/system/build.prop' - -# Default set of properties to query about a device. -DEFAULT_PROPS_TO_GET = ['ro.product.device', 'ro.build.version.release', - 'ro.build.type'] - - -def GetDeviceInfo(adb, serial, props_to_get): - """ Return a list of values (or "<Unknown>" if no value can be found) for the - given set of properties for the device with the given serial number. - - adb: path to the ADB program. - serial: serial number of the target device. - props_to_get: list of strings indicating which properties to determine. - """ - device_proc = subprocess.Popen([adb, '-s', serial, 'shell', 'cat', - INFO_FILE], stdout=subprocess.PIPE) - code = device_proc.wait() - if code != 0: - raise Exception('Could not query device with serial number %s.' % serial) - output = device_proc.stdout.read() - device_info = [] - for prop in props_to_get: - # Find the property in the outputs - search_str = r'%s=(\S+)' % prop - match = re.search(search_str, output) - if not match: - value = '<Unknown>' - else: - value = match.group(1) - device_info.append(value) - return device_info - - -def PrintPrettyTable(data, file=None): - """ Print out the given data in a nicely-spaced format. This function scans - the list multiple times and uses extra memory, so don't use it for big data - sets. - - data: list of lists of strings, where each list represents a row of data. - This table is assumed to be rectangular; if the length of any list differs - some of the output may not get printed. - file: file-like object into which the table should be written. If none is - provided, the table is written to stdout. - """ - if not file: - file = sys.stdout - column_widths = [0 for length in data[0]] - for line in data: - column_widths = [max(longest_len, len(prop)) for \ - longest_len, prop in zip(column_widths, line)] - for line in data: - for prop, width in zip(line, column_widths): - file.write(prop.ljust(width + 1)) - file.write('\n') - - -def FindADB(hint=None): - """ Attempt to find the ADB program using the following sequence of steps. - Returns the path to ADB if it can be found, or None otherwise. - 1. If a hint was provided, is it a valid path to ADB? - 2. Is ADB in PATH? - 3. Is there an environment variable for ADB? - 4. If the ANDROID_SDK_ROOT variable is set, try to find ADB in the SDK - directory. - - hint: string indicating a possible path to ADB. - """ - # 1. If a hint was provided, does it point to ADB? - if hint: - if os.path.basename(hint) == 'adb': - adb = hint - else: - adb = os.path.join(hint, 'adb') - if subprocess.Popen([adb, 'version'], stdout=subprocess.PIPE).wait() == 0: - return adb - - # 2. Is 'adb' in our PATH? - adb = 'adb' - if subprocess.Popen([adb, 'version'], stdout=subprocess.PIPE).wait() == 0: - return adb - - # 3. Is there an environment variable for ADB? - try: - adb = os.environ.get('ADB') - if subprocess.Popen([adb, 'version'], stdout=subprocess.PIPE).wait() == 0: - return adb - except: - pass - - # 4. If ANDROID_SDK_ROOT is set, try to find ADB in the SDK directory. - try: - sdk_dir = os.environ.get('ANDROID_SDK_ROOT') - adb = os.path.join(sdk_dir, 'platform-tools', 'adb') - if subprocess.Popen([adb, 'version'], stdout=subprocess.PIPE).wait() == 0: - return adb - except: - pass - return None - - -def main(argv): - """ Print out information about connected Android devices. By default, print - the serial number, status, device name, OS version, and build type of each - device. If any arguments are supplied on the command line, print the serial - number and status for each device along with values for those arguments - interpreted as properties. - """ - if len(argv) > 1: - props_to_get = argv[1:] - else: - props_to_get = DEFAULT_PROPS_TO_GET - adb = FindADB() - if not adb: - raise Exception('Could not find ADB!') - proc = subprocess.Popen([adb, 'devices'], stdout=subprocess.PIPE) - code = proc.wait() - if code != 0: - raise Exception('Failure in ADB: could not find attached devices.') - header = ['Serial', 'Status'] - header.extend(props_to_get) - output_lines = [header] - for line in proc.stdout: - line = line.rstrip() - if line != 'List of devices attached' and line != '': - line_list = shlex.split(line) - serial = line_list[0] - status = line_list[1] - device_info = [serial, status] - device_info.extend(GetDeviceInfo(adb, serial, props_to_get)) - output_lines.append(device_info) - PrintPrettyTable(output_lines) - - -if __name__ == '__main__': - sys.exit(main(sys.argv))
\ No newline at end of file diff --git a/platform_tools/android/bin/adb_print_path b/platform_tools/android/bin/adb_print_path deleted file mode 100755 index 4067f04c0e..0000000000 --- a/platform_tools/android/bin/adb_print_path +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# -# adb_print_path: prints the path to the copy of adb that will be used by Skia's -# android scripts. This is used by Skia's build infrastructure to ensure that -# we use the same adb revision (and instance). - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source $SCRIPT_DIR/android_setup.sh -source $SCRIPT_DIR/utils/setup_adb.sh - -echo $ADB -exit 0 diff --git a/platform_tools/android/bin/adb_pull_if_needed b/platform_tools/android/bin/adb_pull_if_needed index 6a35902bdd..36a178bdc7 100755 --- a/platform_tools/android/bin/adb_pull_if_needed +++ b/platform_tools/android/bin/adb_pull_if_needed @@ -3,8 +3,7 @@ # Copy the contents of a directory from a device to the host. SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -SKIP_TOOLCHAIN_SETUP="true" -source $SCRIPT_DIR/android_setup.sh +source $SCRIPT_DIR/utils/android_setup.sh source $SCRIPT_DIR/utils/setup_adb.sh adb_pull_if_needed ${APP_ARGS[@]} diff --git a/platform_tools/android/bin/adb_push_if_needed b/platform_tools/android/bin/adb_push_if_needed index efe6bb8a1f..2f8958e027 100755 --- a/platform_tools/android/bin/adb_push_if_needed +++ b/platform_tools/android/bin/adb_push_if_needed @@ -3,8 +3,7 @@ # Copy the contents of a directory from the host to a device. SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -SKIP_TOOLCHAIN_SETUP="true" -source $SCRIPT_DIR/android_setup.sh +source $SCRIPT_DIR/utils/android_setup.sh source $SCRIPT_DIR/utils/setup_adb.sh adb_push_if_needed ${APP_ARGS[@]} diff --git a/platform_tools/android/bin/adb_wait_for_charge b/platform_tools/android/bin/adb_wait_for_charge deleted file mode 100755 index f05c44f455..0000000000 --- a/platform_tools/android/bin/adb_wait_for_charge +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash -# -# Wait for the device to be charged enough for testing. - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -SKIP_TOOLCHAIN_SETUP="true" -source $SCRIPT_DIR/android_setup.sh -source $SCRIPT_DIR/utils/setup_adb.sh - -# Helper function used by get_battery_level. Parses the battery level from -# dumpsys output. -function _parse_battery_level { - SPLIT=( $@ ) - - HAS_BATTERY=1 - LEVEL="" - - for i in "${!SPLIT[@]}"; do - if [ "${SPLIT[$i]}" = "level:" ]; then - LEVEL="${SPLIT[$i+1]}" - fi - if [ "${SPLIT[$i]}" = "present:" ]; then - PRESENT="$(echo "${SPLIT[$i+1]}" | tr -d '\r')" - if [ "$PRESENT" = "0" ]; then - HAS_BATTERY=0 - fi - if [ "$PRESENT" = "false" ]; then - HAS_BATTERY=0 - fi - fi - done - - if [ "$HAS_BATTERY" = "1" ]; then - echo "$LEVEL" | tr -d '\r' - return - fi - # If there's no battery, report a full battery. - echo "Device has no battery." 1>&2 - echo "100" -} - -# Echo the battery level percentage of the attached Android device. -function get_battery_level { - STATS="$($ADB $DEVICE_SERIAL shell dumpsys batteryproperties)" - SPLIT=( $STATS ) - RV="$(_parse_battery_level ${SPLIT[@]})" - if [ -n "$RV" ]; then - echo "$RV" - return - fi - - echo "Battery level fallback..." 1>&2 - - STATS="$($ADB $DEVICE_SERIAL shell dumpsys battery)" - SPLIT=( $STATS ) - RV="$(_parse_battery_level ${SPLIT[@]})" - if [ -n "$RV" ] && [ "$RV" != "-1" ]; then - echo "$RV" - return - fi - - echo "Could not determine battery level!" 1>&2 - # Just exit to prevent hanging forever or failing the build. - echo "0" -} - -# Wait for battery charge. -DESIRED_BATTERY_LEVEL=80 -CURRENT_BATTERY_LEVEL="$(get_battery_level)" -while [ "${CURRENT_BATTERY_LEVEL}" -lt "${DESIRED_BATTERY_LEVEL}" ]; do - echo "Battery level is ${CURRENT_BATTERY_LEVEL}; waiting to charge to ${DESIRED_BATTERY_LEVEL}" - sleep 5 - CURRENT_BATTERY_LEVEL="$(get_battery_level)" -done - -echo "Charged!" diff --git a/platform_tools/android/bin/adb_wait_for_device b/platform_tools/android/bin/adb_wait_for_device deleted file mode 100755 index 45ed4b2a78..0000000000 --- a/platform_tools/android/bin/adb_wait_for_device +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# -# Wait for the device to be connected. - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -SKIP_TOOLCHAIN_SETUP="true" -source $SCRIPT_DIR/android_setup.sh -source $SCRIPT_DIR/utils/setup_adb.sh - -set -e - -# Wait for the device to be connected and fully booted. -while [ "$($ADB $DEVICE_SERIAL shell getprop sys.boot_completed | tr -d '\r')" != "1" ]; do - echo "Waiting for the device to be connected and ready." - sleep 5 -done - -echo "Connected!" diff --git a/platform_tools/android/bin/android_gdb_native b/platform_tools/android/bin/android_gdb_native index c114a3d309..da513cbf79 100755 --- a/platform_tools/android/bin/android_gdb_native +++ b/platform_tools/android/bin/android_gdb_native @@ -4,10 +4,9 @@ # and enters command line debugging environment. SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source $SCRIPT_DIR/android_setup.sh +source $SCRIPT_DIR/utils/android_setup.sh # setup the gdbserver -export BUILDTYPE # from android_setup.sh $SCRIPT_DIR/android_gdbserver -d ${DEVICE_ID} ${APP_ARGS[@]} # quit if gdbserver setup failed @@ -27,25 +26,29 @@ PORT=5039 # Set up gdb commands GDBSETUP=$GDB_TMP_DIR/gdb.setup { - echo "file ${GDB_TMP_DIR}/skia_launcher" + echo "file ${GDB_TMP_DIR}/${APP_NAME}" echo "target remote :${PORT}" echo "set solib-absolute-prefix ${GDB_TMP_DIR}" echo "set solib-search-path ${GDB_TMP_DIR}" - # The apps shared library symbols are not loaded by default so we - # load them here. - echo "break launch_app" + echo "break main" echo "continue" - echo "sharedLibrary ${APP_NAME}" - - # Load libskia_android.so here. - echo "sharedLibrary skia_android" } > $GDBSETUP # Launch gdb client +HOST=`uname | tr '[A-Z]' '[a-z]'` +if [ $HOST == "darwin" ]; then + GDB_HOST=$ANDROID_NDK_ROOT/prebuilt/darwin-x86_64/bin/gdb +elif [ $HOST == "linux" ]; then + GDB_HOST=$ANDROID_NDK_ROOT/prebuilt/linux-x86_64/bin/gdb +else + echo "Could not automatically determine OS!" + exit 1; +fi + echo "Entering gdb client shell" -$ANDROID_TOOLCHAIN/host_prebuilt/bin/gdb -x $GDBSETUP +$GDB_HOST -x $GDBSETUP # Clean up: # We could 'rm -rf $GDB_TMP_DIR', but doing so would cause subsequent debugging diff --git a/platform_tools/android/bin/android_gdbserver b/platform_tools/android/bin/android_gdbserver index 8e4a6f00a9..432ab7c82b 100755 --- a/platform_tools/android/bin/android_gdbserver +++ b/platform_tools/android/bin/android_gdbserver @@ -3,17 +3,15 @@ # android_gdbserver: Pushes gdbserver. Starts debugging environment. SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source $SCRIPT_DIR/android_setup.sh +source $SCRIPT_DIR/utils/android_setup.sh source $SCRIPT_DIR/utils/setup_adb.sh APP_NAME=${APP_ARGS[0]} -PORT=5039 -BUILD_DIR="${SKIA_OUT}/${BUILDTYPE}" -TARGET_LIBRARY="${BUILD_DIR}/lib/lib${APP_NAME}.so" -if [ ! -f "$TARGET_LIBRARY" ] +TARGET_EXE="${SKIA_OUT}/${APP_NAME}" +if [ ! -f "$TARGET_EXE" ] then - echo "Unable to find the ${APP_NAME} library at ${TARGET_LIBRARY}." + echo "Unable to find ${TARGET_EXE}." exit 1 fi @@ -22,8 +20,9 @@ GDB_TMP_DIR=$SKIA_OUT/android_gdb_tmp mkdir -p $GDB_TMP_DIR echo "Copying symbol files" -if [[ $ANDROID_ARCH == *64* ]]; then +if [[ $IS_64_BIT == "true" ]]; then SYSTEM_LIBRARY_PATH=/system/lib64 + echo "64 bit!" else SYSTEM_LIBRARY_PATH=/system/lib fi @@ -55,17 +54,11 @@ else fi echo "Pushing app..." -for file in \ - "${BUILD_DIR}/skia_launcher" \ - "${BUILD_DIR}/lib/libskia_android.so" \ - "${BUILD_DIR}/lib/lib${APP_NAME}.so" \ - ; do - cp "$file" $GDB_TMP_DIR - adb_push_if_needed "$file" /data/local/tmp -done +cp "$TARGET_EXE" $GDB_TMP_DIR +adb_push_if_needed "${TARGET_EXE}" /data/local/tmp echo "Pushing gdbserver..." -adb_push_if_needed $ANDROID_TOOLCHAIN/gdbserver /data/local/tmp +adb_push_if_needed $GDBSERVER_DIR/gdbserver/gdbserver /data/local/tmp echo "Setting up port forward" $ADB forward "tcp:5039" "tcp:5039" @@ -79,4 +72,4 @@ set -e # Starting up gdbserver in android shell echo "Starting gdbserver with command: ${APP_ARGS[@]}" -$ADB shell LD_LIBRARY_PATH=/data/local/tmp:\$LD_LIBRARY_PATH /data/local/tmp/gdbserver :5039 /data/local/tmp/skia_launcher ${APP_ARGS[@]} & +$ADB shell /data/local/tmp/gdbserver :5039 /data/local/tmp/${APP_ARGS[@]} & diff --git a/platform_tools/android/bin/android_kill_skia b/platform_tools/android/bin/android_kill_skia deleted file mode 100755 index 3c4a757349..0000000000 --- a/platform_tools/android/bin/android_kill_skia +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# -# android_kill_skia: kills any skia processes on the device. - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -SKIP_TOOLCHAIN_SETUP="true" -source $SCRIPT_DIR/android_setup.sh -source $SCRIPT_DIR/utils/setup_adb.sh - -if [ $(uname) == "Linux" ]; then - $ADB $DEVICE_SERIAL shell ps | grep skia | awk '{print $2}' | xargs -r $ADB $DEVICE_SERIAL shell kill -elif [ $(uname) == "Darwin" ]; then - $ADB $DEVICE_SERIAL shell ps | grep skia | awk '{print $2}' | xargs $ADB $DEVICE_SERIAL shell kill -else - echo "Could not automatically determine OS!" - exit 1; -fi diff --git a/platform_tools/android/bin/android_make b/platform_tools/android/bin/android_make index 9601db9b17..cac0cc93c6 100755 --- a/platform_tools/android/bin/android_make +++ b/platform_tools/android/bin/android_make @@ -9,11 +9,12 @@ set -e rm -f .android_config SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}") -source $SCRIPT_DIR/android_setup.sh +source $SCRIPT_DIR/utils/android_setup.sh SKIA_SRC_DIR=$(cd "${SCRIPT_DIR}/../../.."; pwd) -GYP_GENERATORS=ninja-android "${SKIA_SRC_DIR}/gyp_skia" -ninja -C $SKIA_OUT/$BUILDTYPE ${APP_ARGS[@]} +echo $GN_ARGS +gn gen $SKIA_OUT --args="${GN_ARGS}" +ninja -C $SKIA_OUT ${APP_ARGS[@]} # Write the device id into the .android_config file. This tells # android_run_skia the last build we completed. diff --git a/platform_tools/android/bin/android_perf b/platform_tools/android/bin/android_perf index 3754013ef3..cf51074788 100755 --- a/platform_tools/android/bin/android_perf +++ b/platform_tools/android/bin/android_perf @@ -9,7 +9,7 @@ # SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source $SCRIPT_DIR/android_setup.sh +source $SCRIPT_DIR/utils/android_setup.sh source $SCRIPT_DIR/utils/setup_adb.sh if [ $(uname) == "Linux" ]; then @@ -49,37 +49,30 @@ perf_setup() { adb_pull_if_needed /system/lib/libz.so $TMP_SYS_LIB # BUILDTYPE variable is set by android_setup.sh - BUILDDIR="${SKIA_OUT}/${BUILDTYPE}" - if [ ! -f "${BUILDDIR}/lib/lib${runVars[0]}.so" ]; + if [ ! -f "${SKIA_OUT}/${runVars[0]}" ]; then - echo "Unable to find the ${runVars[0]} library in ${BUILDDIR}/lib." + echo "Unable to find the ${runVars[0]} executable" exit 1 fi echo "Pushing app..." - for lib_file in \ - "${BUILDDIR}/skia_launcher" \ - "${BUILDDIR}/lib/libskia_android.so" \ - "${BUILDDIR}/lib/lib${runVars[0]}.so" \ - ; do - adb_push_if_needed "$lib_file" /data/local/tmp - cp "$lib_file" $TMP_APP_LOC - done + adb_push_if_needed "${SKIA_OUT}/${runVars[0]}" /data/local/tmp + cp "${SKIA_OUT}/${runVars[0]}" $TMP_APP_LOC } perf_record() { echo "Killing any running Skia processes." - $ADB shell ps | grep skia_launcher | awk '{print $2}' | xargs $ADB shell kill + $ADB shell ps | grep ${runVars[0]} | awk '{print $2}' | xargs $ADB shell kill echo "Starting application" - $ADB shell /data/local/tmp/skia_launcher ${runVars[@]} & + $ADB shell /data/local/tmp/${runVars[@]} & # WE REALLY REALLY WANT TO BE ABLE TO PASS THE SKIA_LAUNCHER APP DIRECTLY TO # PERF, BUT AT THIS POINT THE DATA FILE WE GET WHEN GOING THAT ROUTE IS UNABLE # TO BE READ BY THE REPORTING TOOL echo "Starting profiler" - APP_PID=$($ADB shell ps | grep skia_launcher | awk '{print $2}') + APP_PID=$($ADB shell ps | grep ${runVars[0]} | awk '{print $2}') $ADB shell perf record -p ${APP_PID} sleep 70 $ADB pull /data/perf.data $PERF_TMP_DIR/perf.data diff --git a/platform_tools/android/bin/android_run_skia b/platform_tools/android/bin/android_run_skia index c4e9056d7e..659b690e2e 100755 --- a/platform_tools/android/bin/android_run_skia +++ b/platform_tools/android/bin/android_run_skia @@ -4,23 +4,17 @@ # output, and kills the app if interrupted. SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -SKIP_TOOLCHAIN_SETUP="true" -source $SCRIPT_DIR/android_setup.sh +source $SCRIPT_DIR/utils/android_setup.sh source $SCRIPT_DIR/utils/setup_adb.sh -if [ ! -f "${SKIA_OUT}/$BUILDTYPE/lib/lib${APP_ARGS[0]}.so" ]; +if [ ! -f "${SKIA_OUT}/${APP_ARGS[0]}" ]; then - echo "Unable to find $BUILDTYPE ${APP_ARGS[0]} library" + echo "Unable to find ${APP_ARGS[0]} executable" exit 1 fi verbose "pushing binaries onto the device..." -adb_push_if_needed "${SKIA_OUT}/$BUILDTYPE/skia_launcher" /data/local/tmp -if [ -f "${SKIA_OUT}/$BUILDTYPE/lib/libskia_android.so" ]; then - # Does not exist for builds with static skia. - adb_push_if_needed "${SKIA_OUT}/$BUILDTYPE/lib/libskia_android.so" /data/local/tmp -fi -adb_push_if_needed "${SKIA_OUT}/$BUILDTYPE/lib/lib${APP_ARGS[0]}.so" /data/local/tmp +adb_push_if_needed "${SKIA_OUT}/${APP_ARGS[0]}" /data/local/tmp if [[ -n $RESOURCE_PATH ]]; then verbose "pushing resources onto the device..." adb_push_if_needed "${SKIA_SRC_DIR}/resources" $RESOURCE_PATH @@ -32,8 +26,7 @@ if [ $LOGCAT ]; then fi STATUS_FILENAME="/data/local/tmp/.skia_tmp_$(date +%s%N)" CMD_FILENAME=".skia_cmd_tmp_$(date +%s%N)" -echo "LD_LIBRARY_PATH=/data/local/tmp:$LD_LIBRARY_PATH \ - /data/local/tmp/skia_launcher ${APP_ARGS[*]}; \ +echo "/data/local/tmp/${APP_ARGS[*]}; \ echo \$? > ${STATUS_FILENAME}" > ${CMD_FILENAME} chmod +x ${CMD_FILENAME} verbose "======== To reproduce this run: ========" diff --git a/platform_tools/android/bin/download_utils.py b/platform_tools/android/bin/download_utils.py deleted file mode 100755 index 298ba9a863..0000000000 --- a/platform_tools/android/bin/download_utils.py +++ /dev/null @@ -1,323 +0,0 @@ -#!/usr/bin/python -# Copyright (c) 2012 The Native Client Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -"""A library to assist automatically downloading files. - -This library is used by scripts that download tarballs, zipfiles, etc. as part -of the build process. -""" - -import hashlib -import http_download -import os.path -import re -import shutil -import sys -import time -import urllib2 - -SOURCE_STAMP = 'SOURCE_URL' -HASH_STAMP = 'SOURCE_SHA1' - - -# Designed to handle more general inputs than sys.platform because the platform -# name may come from the command line. -PLATFORM_COLLAPSE = { - 'windows': 'windows', - 'win32': 'windows', - 'cygwin': 'windows', - 'linux': 'linux', - 'linux2': 'linux', - 'linux3': 'linux', - 'darwin': 'mac', - 'mac': 'mac', -} - -ARCH_COLLAPSE = { - 'i386' : 'x86', - 'i686' : 'x86', - 'x86_64': 'x86', - 'armv7l': 'arm', -} - - -class HashError(Exception): - def __init__(self, download_url, expected_hash, actual_hash): - self.download_url = download_url - self.expected_hash = expected_hash - self.actual_hash = actual_hash - - def __str__(self): - return 'Got hash "%s" but expected hash "%s" for "%s"' % ( - self.actual_hash, self.expected_hash, self.download_url) - - -def PlatformName(name=None): - if name is None: - name = sys.platform - return PLATFORM_COLLAPSE[name] - -def ArchName(name=None): - if name is None: - if PlatformName() == 'windows': - # TODO(pdox): Figure out how to auto-detect 32-bit vs 64-bit Windows. - name = 'i386' - else: - import platform - name = platform.machine() - return ARCH_COLLAPSE[name] - -def EnsureFileCanBeWritten(filename): - directory = os.path.dirname(filename) - if not os.path.exists(directory): - os.makedirs(directory) - - -def WriteData(filename, data): - EnsureFileCanBeWritten(filename) - f = open(filename, 'wb') - f.write(data) - f.close() - - -def WriteDataFromStream(filename, stream, chunk_size, verbose=True): - EnsureFileCanBeWritten(filename) - dst = open(filename, 'wb') - try: - while True: - data = stream.read(chunk_size) - if len(data) == 0: - break - dst.write(data) - if verbose: - # Indicate that we're still writing. - sys.stdout.write('.') - sys.stdout.flush() - finally: - if verbose: - sys.stdout.write('\n') - dst.close() - - -def DoesStampMatch(stampfile, expected, index): - try: - f = open(stampfile, 'r') - stamp = f.read() - f.close() - if stamp.split('\n')[index] == expected: - return "already up-to-date." - elif stamp.startswith('manual'): - return "manual override." - return False - except IOError: - return False - - -def WriteStamp(stampfile, data): - EnsureFileCanBeWritten(stampfile) - f = open(stampfile, 'w') - f.write(data) - f.close() - - -def StampIsCurrent(path, stamp_name, stamp_contents, min_time=None, index=0): - stampfile = os.path.join(path, stamp_name) - - # Check if the stampfile is older than the minimum last mod time - if min_time: - try: - stamp_time = os.stat(stampfile).st_mtime - if stamp_time <= min_time: - return False - except OSError: - return False - - return DoesStampMatch(stampfile, stamp_contents, index) - - -def WriteSourceStamp(path, url): - stampfile = os.path.join(path, SOURCE_STAMP) - WriteStamp(stampfile, url) - -def WriteHashStamp(path, hash_val): - hash_stampfile = os.path.join(path, HASH_STAMP) - WriteStamp(hash_stampfile, hash_val) - - -def Retry(op, *args): - # Windows seems to be prone to having commands that delete files or - # directories fail. We currently do not have a complete understanding why, - # and as a workaround we simply retry the command a few times. - # It appears that file locks are hanging around longer than they should. This - # may be a secondary effect of processes hanging around longer than they - # should. This may be because when we kill a browser sel_ldr does not exit - # immediately, etc. - # Virus checkers can also accidently prevent files from being deleted, but - # that shouldn't be a problem on the bots. - if sys.platform in ('win32', 'cygwin'): - count = 0 - while True: - try: - op(*args) - break - except Exception: - sys.stdout.write("FAILED: %s %s\n" % (op.__name__, repr(args))) - count += 1 - if count < 5: - sys.stdout.write("RETRY: %s %s\n" % (op.__name__, repr(args))) - time.sleep(pow(2, count)) - else: - # Don't mask the exception. - raise - else: - op(*args) - - -def MoveDirCleanly(src, dst): - RemoveDir(dst) - MoveDir(src, dst) - - -def MoveDir(src, dst): - Retry(shutil.move, src, dst) - - -def RemoveDir(path): - if os.path.exists(path): - Retry(shutil.rmtree, path) - - -def RemoveFile(path): - if os.path.exists(path): - Retry(os.unlink, path) - - -def _HashFileHandle(fh): - """sha1 of a file like object. - - Arguments: - fh: file handle like object to hash. - Returns: - sha1 as a string. - """ - hasher = hashlib.sha1() - try: - while True: - data = fh.read(4096) - if not data: - break - hasher.update(data) - finally: - fh.close() - return hasher.hexdigest() - - -def HashFile(filename): - """sha1 a file on disk. - - Arguments: - filename: filename to hash. - Returns: - sha1 as a string. - """ - fh = open(filename, 'rb') - return _HashFileHandle(fh) - - -def HashUrlByDownloading(url): - """sha1 the data at an url. - - Arguments: - url: url to download from. - Returns: - sha1 of the data at the url. - """ - try: - fh = urllib2.urlopen(url) - except: - sys.stderr.write("Failed fetching URL: %s\n" % url) - raise - return _HashFileHandle(fh) - - -# Attempts to get the SHA1 hash of a file given a URL by looking for -# an adjacent file with a ".sha1hash" suffix. This saves having to -# download a large tarball just to get its hash. Otherwise, we fall -# back to downloading the main file. -def HashUrl(url): - hash_url = '%s.sha1hash' % url - try: - fh = urllib2.urlopen(hash_url) - data = fh.read(100) - fh.close() - except urllib2.HTTPError, exn: - if exn.code == 404: - return HashUrlByDownloading(url) - raise - else: - if not re.match('[0-9a-f]{40}\n?$', data): - raise AssertionError('Bad SHA1 hash file: %r' % data) - return data.strip() - - -def SyncURL(url, filename=None, stamp_dir=None, min_time=None, - hash_val=None, keep=False, verbose=False, stamp_index=0): - """Synchronize a destination file with a URL - - if the URL does not match the URL stamp, then we must re-download it. - - Arugments: - url: the url which will to compare against and download - filename: the file to create on download - path: the download path - stamp_dir: the filename containing the URL stamp to check against - hash_val: if set, the expected hash which must be matched - verbose: prints out status as it runs - stamp_index: index within the stamp file to check. - Returns: - True if the file is replaced - False if the file is not replaced - Exception: - HashError: if the hash does not match - """ - - assert url and filename - - # If we are not keeping the tarball, or we already have it, we can - # skip downloading it for this reason. If we are keeping it, - # it must exist. - if keep: - tarball_ok = os.path.isfile(filename) - else: - tarball_ok = True - - # If we don't need the tarball and the stamp_file matches the url, then - # we must be up to date. If the URL differs but the recorded hash matches - # the one we'll insist the tarball has, then that's good enough too. - # TODO(mcgrathr): Download the .sha1sum file first to compare with - # the cached hash, in case --file-hash options weren't used. - if tarball_ok and stamp_dir is not None: - if StampIsCurrent(stamp_dir, SOURCE_STAMP, url, min_time): - if verbose: - print '%s is already up to date.' % filename - return False - if (hash_val is not None and - StampIsCurrent(stamp_dir, HASH_STAMP, hash_val, min_time, stamp_index)): - if verbose: - print '%s is identical to the up to date file.' % filename - return False - - if verbose: - print 'Updating %s\n\tfrom %s.' % (filename, url) - EnsureFileCanBeWritten(filename) - http_download.HttpDownload(url, filename) - - if hash_val: - tar_hash = HashFile(filename) - if hash_val != tar_hash: - raise HashError(actual_hash=tar_hash, expected_hash=hash_val, - download_url=url) - - return True diff --git a/platform_tools/android/bin/http_download.py b/platform_tools/android/bin/http_download.py deleted file mode 100755 index 15f7983b77..0000000000 --- a/platform_tools/android/bin/http_download.py +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/python -# Copyright (c) 2012 The Native Client Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -"""Download a file from a URL to a file on disk. - -This module supports username and password with basic authentication. -""" - -import base64 -import os -import os.path -import sys -import urllib2 - -import download_utils - - -def _CreateDirectory(path): - """Create a directory tree, ignore if it's already there.""" - try: - os.makedirs(path) - return True - except os.error: - return False - - -def HttpDownload(url, target, username=None, password=None, verbose=True, - logger=None): - """Download a file from a remote server. - - Args: - url: A URL to download from. - target: Filename to write download to. - username: Optional username for download. - password: Optional password for download (ignored if no username). - logger: Function to log events to. - """ - - # Log to stdout by default. - if logger is None: - logger = sys.stdout.write - headers = [('Accept', '*/*')] - if username: - if password: - auth_code = base64.b64encode(username + ':' + password) - else: - auth_code = base64.b64encode(username) - headers.append(('Authorization', 'Basic ' + auth_code)) - if os.environ.get('http_proxy'): - proxy = os.environ.get('http_proxy') - proxy_handler = urllib2.ProxyHandler({ - 'http': proxy, - 'https': proxy}) - opener = urllib2.build_opener(proxy_handler) - else: - opener = urllib2.build_opener() - opener.addheaders = headers - urllib2.install_opener(opener) - _CreateDirectory(os.path.split(target)[0]) - # Retry up to 10 times (appengine logger is flaky). - for i in xrange(10): - if i: - logger('Download failed on %s, retrying... (%d)\n' % (url, i)) - try: - # 30 second timeout to ensure we fail and retry on stalled connections. - src = urllib2.urlopen(url, timeout=30) - try: - download_utils.WriteDataFromStream(target, src, chunk_size=2**20, - verbose=verbose) - content_len = src.headers.get('Content-Length') - if content_len: - content_len = int(content_len) - file_size = os.path.getsize(target) - if content_len != file_size: - logger('Filesize:%d does not match Content-Length:%d' % ( - file_size, content_len)) - continue - finally: - src.close() - break - except urllib2.HTTPError, e: - if e.code == 404: - logger('Resource does not exist.\n') - raise - logger('Failed to open.\n') - except urllib2.URLError: - logger('Failed mid stream.\n') - else: - logger('Download failed on %s, giving up.\n' % url) - raise diff --git a/platform_tools/android/bin/android_setup.sh b/platform_tools/android/bin/utils/android_setup.sh index d092922416..a50819efa7 100755 --- a/platform_tools/android/bin/android_setup.sh +++ b/platform_tools/android/bin/utils/android_setup.sh @@ -11,8 +11,7 @@ # Fail-fast if anything in the script fails. set -e -BUILDTYPE=${BUILDTYPE-Release_Developer} -USE_CLANG="true" +IS_DEBUG="false" while (( "$#" )); do if [[ "$1" == "-d" ]]; then @@ -25,17 +24,8 @@ while (( "$#" )); do elif [[ "$1" == "-s" ]]; then DEVICE_SERIAL="-s $2" shift - elif [[ "$1" == "-t" ]]; then - BUILDTYPE=$2 - shift elif [[ "$1" == "--debug" ]]; then - BUILDTYPE=Debug - elif [[ "$1" == "--release" ]]; then - BUILDTYPE=Release - elif [[ "$1" == "--gcc" ]]; then - USE_CLANG="false" - elif [[ "$1" == "--clang" ]]; then - USE_CLANG="true" + IS_DEBUG="true" elif [[ "$1" == "--logcat" ]]; then LOGCAT=1 elif [[ "$1" == "--verbose" ]]; then @@ -48,10 +38,6 @@ while (( "$#" )); do shift done -if [ "$USE_CLANG" == "true" ]; then - export GYP_DEFINES="skia_clang_build=1 $GYP_DEFINES" -fi - function verbose { if [[ -n $VERBOSE ]]; then echo $@ @@ -69,7 +55,7 @@ function absPath { (cd $1; pwd) } -SCRIPT_DIR=$(absPath "$(dirname "$BASH_SOURCE[0]}")") +UTIL_DIR=$(absPath "$(dirname "$BASH_SOURCE[0]}")") if [ -z "$ANDROID_SDK_ROOT" ]; then if ANDROID_SDK_ROOT="$(dirname $(which android))/.."; then @@ -85,19 +71,22 @@ if [ -z "$ANDROID_HOME" ]; then exportVar ANDROID_HOME $ANDROID_SDK_ROOT fi -if [ "$SKIA_VULKAN" == "true" ]; then - export GYP_DEFINES="skia_vulkan=1 $GYP_DEFINES" +if [ -z "$ANDROID_NDK_ROOT" ]; then + if [ -d "${ANDROID_SDK_ROOT}/ndk-bundle" ]; then + exportVar ANDROID_NDK_ROOT ${ANDROID_SDK_ROOT}/ndk-bundle + else + echo "No ANDROID_NDK_ROOT set and can't auto detect it from location of SDK." + exit 1 + fi fi -# Helper function to configure the GYP defines to the appropriate values +# Helper function to configure the GN defines to the appropriate values # based on the target device. setup_device() { - DEFINES="OS=android" - DEFINES="${DEFINES} host_os=$(uname -s | sed -e 's/Linux/linux/;s/Darwin/mac/')" - DEFINES="${DEFINES} skia_os=android" - DEFINES="${DEFINES} android_base=$(absPath ${SCRIPT_DIR}/..)" - if [[ "$GYP_DEFINES" != *skia_shared_lib=* ]]; then - DEFINES="${DEFINES} skia_shared_lib=1" + DEFINES="ndk=\"${ANDROID_NDK_ROOT}\" is_debug=${IS_DEBUG}" + + if [ $SKIA_VULKAN == "true" ]; then + DEFINES="${DEFINES} ndk_api=24" fi # Setup the build variation depending on the target device @@ -108,79 +97,57 @@ setup_device() { TARGET_DEVICE=$(cat .android_config) verbose "no target device (-d), using ${TARGET_DEVICE} from most recent build" else - TARGET_DEVICE="arm_v7_neon" + TARGET_DEVICE="arm_v7" verbose "no target device (-d), using ${TARGET_DEVICE}" fi fi case $TARGET_DEVICE in - arm) - DEFINES="${DEFINES} skia_arch_type=arm arm_neon=0" - ANDROID_ARCH="arm" + arm_v7 | nexus_4 | nexus_5 | nexus_6 | nexus_7 | nexus_10) + DEFINES="${DEFINES} target_cpu=\"arm\"" + GDBSERVER_DIR="${ANDROID_NDK_ROOT}/prebuilt/android-arm" + IS_64_BIT=false ;; - arm_v7 | xoom) - DEFINES="${DEFINES} skia_arch_type=arm arm_neon=0 arm_version=7" - ANDROID_ARCH="arm" - ;; - arm_v7_neon | nexus_4 | nexus_5 | nexus_6 | nexus_7 | nexus_10) - DEFINES="${DEFINES} skia_arch_type=arm arm_neon=1 arm_version=7" - ANDROID_ARCH="arm" - ;; - arm64 | nexus_9) - DEFINES="${DEFINES} skia_arch_type=arm64 arm_version=8" - ANDROID_ARCH="arm64" + arm64 | nexus_9 | nexus_5x | nexus_6p | pixel) + DEFINES="${DEFINES} target_cpu=\"arm64\"" + GDBSERVER_DIR="${ANDROID_NDK_ROOT}/prebuilt/android-arm64" + IS_64_BIT=true ;; x86) - DEFINES="${DEFINES} skia_arch_type=x86" - ANDROID_ARCH="x86" + DEFINES="${DEFINES} target_cpu=\"x86\"" + GDBSERVER_DIR="${ANDROID_NDK_ROOT}/prebuilt/android-x86" + IS_64_BIT=false ;; x86_64 | x64) - DEFINES="${DEFINES} skia_arch_type=x86_64" - ANDROID_ARCH="x86_64" + DEFINES="${DEFINES} target_cpu=\"x64\"" + GDBSERVER_DIR="${ANDROID_NDK_ROOT}/prebuilt/android-x86_64" + IS_64_BIT=true ;; mips) - DEFINES="${DEFINES} skia_arch_type=mips32" - DEFINES="${DEFINES} skia_resource_cache_mb_limit=32" - ANDROID_ARCH="mips" - ;; - mips_dsp2) - DEFINES="${DEFINES} skia_arch_type=mips32" - DEFINES="${DEFINES} mips_arch_variant=mips32r2 mips_dsp=2" - ANDROID_ARCH="mips" + DEFINES="${DEFINES} target_cpu=\"mipsel\"" + GDBSERVER_DIR="${ANDROID_NDK_ROOT}/prebuilt/android-mips" + IS_64_BIT=false + #DEFINES="${DEFINES} skia_resource_cache_mb_limit=32" ;; mips64) - DEFINES="${DEFINES} skia_arch_type=mips64" - ANDROID_ARCH="mips64" + DEFINES="${DEFINES} target_cpu=\"mips64el\"" + GDBSERVER_DIR="${ANDROID_NDK_ROOT}/prebuilt/android-mips64" + IS_64_BIT=true ;; *) - if [ -z "$ANDROID_IGNORE_UNKNOWN_DEVICE" ]; then - echo "ERROR: unknown device $TARGET_DEVICE" - exit 1 - fi - # If ANDROID_IGNORE_UNKNOWN_DEVICE is set, then ANDROID_TOOLCHAIN - # or ANDROID_ARCH should be set; Otherwise, ANDROID_ARCH - # defaults to 'arm' and the default ARM toolchain is used. - DEFINES="${DEFINES} skia_arch_type=${ANDROID_ARCH-arm}" - # If ANDROID_IGNORE_UNKNOWN_DEVICE is set, extra gyp defines can be - # added via ANDROID_GYP_DEFINES - DEFINES="${DEFINES} ${ANDROID_GYP_DEFINES}" + echo "ERROR: unknown device $TARGET_DEVICE" + exit 1 ;; esac verbose "The build is targeting the device: $TARGET_DEVICE" exportVar DEVICE_ID $TARGET_DEVICE + exportVar GN_ARGS "$DEFINES" + exportVar GDBSERVER_DIR $GDBSERVER_DIR + exportVar IS_64_BIT $IS_64_BIT - if [ -z "$SKIP_TOOLCHAIN_SETUP" ]; then - # setup the appropriate cross compiling toolchains - source $SCRIPT_DIR/utils/setup_toolchain.sh - fi - - DEFINES="${DEFINES} android_toolchain=${ANDROID_TOOLCHAIN}" - DEFINES="${DEFINES} android_buildtype=${BUILDTYPE}" - exportVar GYP_DEFINES "$DEFINES $GYP_DEFINES" - - SKIA_SRC_DIR=$(cd "${SCRIPT_DIR}/../../.."; pwd) - DEFAULT_SKIA_OUT="${SKIA_SRC_DIR}/out/config/android-${TARGET_DEVICE}" + SKIA_SRC_DIR=$(cd "${UTIL_DIR}/../../../.."; pwd) + DEFAULT_SKIA_OUT="${SKIA_SRC_DIR}/out/android-${TARGET_DEVICE}" exportVar SKIA_OUT "${SKIA_OUT:-${DEFAULT_SKIA_OUT}}" } diff --git a/platform_tools/android/bin/utils/setup_adb.sh b/platform_tools/android/bin/utils/setup_adb.sh index 81e4851cef..94c4e8eb2a 100644 --- a/platform_tools/android/bin/utils/setup_adb.sh +++ b/platform_tools/android/bin/utils/setup_adb.sh @@ -3,8 +3,6 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -UTIL_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - if [ $PYADB ] && [ -a "$PYADB" ]; then echo "Python ADB detected, going to use that" ADB="python ${PYADB}" diff --git a/platform_tools/android/bin/utils/setup_toolchain.sh b/platform_tools/android/bin/utils/setup_toolchain.sh deleted file mode 100755 index c341c2e341..0000000000 --- a/platform_tools/android/bin/utils/setup_toolchain.sh +++ /dev/null @@ -1,165 +0,0 @@ -# Copyright 2015 Google Inc. -# -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -#!/bin/bash -# -# setup_toolchain.sh: Sets toolchain environment variables used by other scripts. - -# Fail-fast if anything in the script fails. -set -e - -# check that the preconditions for this script are met -if [ $(type -t verbose) != 'function' ]; then - echo "ERROR: The verbose function is expected to be defined" - return 1 -fi - -if [ $(type -t exportVar) != 'function' ]; then - echo "ERROR: The exportVar function is expected to be defined" - return 1 -fi - -if [ $(type -t absPath) != 'function' ]; then - echo "ERROR: The absPath function is expected to be defined" - return 1 -fi - -if [ -z "$SCRIPT_DIR" ]; then - echo "ERROR: The SCRIPT_DIR variable is expected to be defined" - return 1 -fi - -function default_toolchain() { - TOOLCHAINS=${SCRIPT_DIR}/../toolchains - - ANDROID_ARCH=${ANDROID_ARCH-arm} - NDK=r12b - - if [[ $ANDROID_ARCH == *64* ]]; then - API=21 # Android 5.0 - else - API=14 # Android 4.0 - fi - - if [ "$SKIA_VULKAN" == "true" ]; then - API=24 # Android N Preview - fi - - TOOLCHAIN=$ANDROID_ARCH-$NDK-$API - HOST=`uname | tr '[A-Z]' '[a-z]'` - - exportVar ANDROID_TOOLCHAIN "${TOOLCHAINS}/${TOOLCHAIN}" - - if [ ! -d "$ANDROID_TOOLCHAIN" ]; then - mkdir -p $TOOLCHAINS - pushd $TOOLCHAINS - curl -o $NDK.zip https://dl.google.com/android/repository/android-ndk-$NDK-$HOST-x86_64.zip - unzip $NDK.zip - UNZIPPED=android-ndk-$NDK - ./$UNZIPPED/build/tools/make-standalone-toolchain.sh \ - --use-llvm \ - --arch=$ANDROID_ARCH \ - --platform=android-$API \ - --install_dir=$TOOLCHAIN - cp $UNZIPPED/prebuilt/android-$ANDROID_ARCH/gdbserver/gdbserver $TOOLCHAIN - cp -r $UNZIPPED/prebuilt/${HOST}-x86_64 $TOOLCHAIN/host_prebuilt - rm $NDK.zip - rm -rf $UNZIPPED - popd - fi - - verbose "Targeting NDK API $API (NDK Revision $NDK)" -} - -#check to see if the toolchain has been defined and if not setup the default toolchain -if [ -z "$ANDROID_TOOLCHAIN" ]; then - default_toolchain - if [ ! -d "$ANDROID_TOOLCHAIN" ]; then - echo "ERROR: unable to download/setup the required toolchain (${ANDROID_TOOLCHAIN})" - return 1; - fi -fi - -GCC=$(command ls $ANDROID_TOOLCHAIN/bin/*-gcc | head -n1) -if [ -z "$GCC" ]; then - echo "ERROR: Could not find Android cross-compiler in: ${ANDROID_TOOLCHAIN}/bin" - return 1 -fi - -# Remove the '-gcc' at the end to get the full toolchain prefix -ANDROID_TOOLCHAIN_PREFIX=${GCC%%-gcc} - -CCACHE=${ANDROID_MAKE_CCACHE-$(which ccache || true)} - -# Cross compiling Android on Mac is not currently supported by gyp. -# It doesn't appear to be supported on Windows either. -# As of now, we will only support cross compiling on Linux. -# libjpeg-turbo assembly code for x86 and x86-64 Android devices -# must be disabled for Android on non-Linux platforms because -# of this issue. We still support compiling on Mac and other -# variants for local development, but shipping versions of Skia -# should be compiled on Linux for performance reasons. -# TODO (msarett): Collect more information about this. -if [ $HOST == "linux" ]; then - if [ "$USE_CLANG" != "true" ]; then - exportVar CC_target "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-gcc" - exportVar CXX_target "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-g++" - exportVar LINK_target "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-gcc" - exportVar CC_host "$CCACHE cc" - exportVar CXX_host "$CCACHE c++" - exportVar LINK_host "$CCACHE cc" - else - exportVar CC_target "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-clang" - exportVar CXX_target "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-clang++" - exportVar LINK_target "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-clang" - exportVar CC_host "$CCACHE clang" - exportVar CXX_host "$CCACHE clang++" - exportVar LINK_host "$CCACHE clang" - fi - - exportVar AR_target "$ANDROID_TOOLCHAIN_PREFIX-ar" - exportVar RANLIB_target "$ANDROID_TOOLCHAIN_PREFIX-ranlib" - exportVar OBJCOPY_target "$ANDROID_TOOLCHAIN_PREFIX-objcopy" - exportVar STRIP_target "$ANDROID_TOOLCHAIN_PREFIX-strip" - exportVar AR_host "ar" - exportVar RANLIB_host "ranlib" - exportVar OBJCOPY_host "objcopy" - exportVar STRIP_host "strip" -else - if [ "$USE_CLANG" != "true" ]; then - exportVar CC "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-gcc" - exportVar CXX "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-g++" - exportVar LINK "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-gcc" - else - exportVar CC "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-clang" - exportVar CXX "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-clang++" - exportVar LINK "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-clang" - fi - - exportVar AR "$ANDROID_TOOLCHAIN_PREFIX-ar" - exportVar RANLIB "$ANDROID_TOOLCHAIN_PREFIX-ranlib" - exportVar OBJCOPY "$ANDROID_TOOLCHAIN_PREFIX-objcopy" - exportVar STRIP "$ANDROID_TOOLCHAIN_PREFIX-strip" -fi - -# GCC doesn't seem to put this on its include path when setting -march=mips32r2. -# Oddly, it does for mips32, mips32r3, and mips32r5, but it's gone again for mips32r6. -# Clang's fine. -if [ "$USE_CLANG" != "true" ]; then - if [ "$ANDROID_ARCH" == "mips" ]; then - exportVar CXX_target "$CXX_target -isystem $ANDROID_TOOLCHAIN/include/c++/4.9.x/mipsel-linux-android" - fi -fi - -# Create symlinks for nm & readelf and add them to the path so that the ninja -# build uses them instead of attempting to use the one on the system. -# This is required to build using ninja on a Mac. -if [ $HOST == "darwin" ]; then - ln -sf $ANDROID_TOOLCHAIN_PREFIX-nm $ANDROID_TOOLCHAIN/bin/nm - ln -sf $ANDROID_TOOLCHAIN_PREFIX-readelf $ANDROID_TOOLCHAIN/bin/readelf - ln -sf $ANDROID_TOOLCHAIN_PREFIX-as $ANDROID_TOOLCHAIN/bin/as -fi - -exportVar PATH ${ANDROID_TOOLCHAIN}/bin:${PATH} diff --git a/platform_tools/android/third_party/ashmem/LICENSE b/platform_tools/android/third_party/ashmem/LICENSE deleted file mode 100644 index d645695673..0000000000 --- a/platform_tools/android/third_party/ashmem/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. diff --git a/platform_tools/android/third_party/ashmem/README.skia b/platform_tools/android/third_party/ashmem/README.skia deleted file mode 100644 index 10ce2b3b3e..0000000000 --- a/platform_tools/android/third_party/ashmem/README.skia +++ /dev/null @@ -1,10 +0,0 @@ -This is copied directly from chromium/src/third_party/ashmem. It is used only -for testing purposes. The client is expected to provide its own ashmem -implementation. - -Name: Android -URL: http://source.android.com -Description: Android shared memory implementation. Only applies to OS_ANDROID. -Version: 7203eb2a8a29a7b721a48cd291700f38f3da1456 -Security Critical: yes -License: Apache 2.0 diff --git a/platform_tools/android/third_party/ashmem/cutils/ashmem-dev.c b/platform_tools/android/third_party/ashmem/cutils/ashmem-dev.c deleted file mode 100644 index 2303369d81..0000000000 --- a/platform_tools/android/third_party/ashmem/cutils/ashmem-dev.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2008 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. - */ - -/* - * Implementation of the user-space ashmem API for devices, which have our - * ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version, - * used by the simulator. - */ - -#include <unistd.h> -#include <string.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/ioctl.h> -#include <fcntl.h> - -#include <linux/ashmem.h> -#include "ashmem.h" - -#define ASHMEM_DEVICE "/dev/ashmem" - -/* - * ashmem_create_region - creates a new ashmem region and returns the file - * descriptor, or <0 on error - * - * `name' is an optional label to give the region (visible in /proc/pid/maps) - * `size' is the size of the region, in page-aligned bytes - */ -int ashmem_create_region(const char *name, size_t size) -{ - int fd, ret; - - fd = open(ASHMEM_DEVICE, O_RDWR); - if (fd < 0) - return fd; - - if (name) { - char buf[ASHMEM_NAME_LEN]; - - strlcpy(buf, name, sizeof(buf)); - ret = ioctl(fd, ASHMEM_SET_NAME, buf); - if (ret < 0) - goto error; - } - - ret = ioctl(fd, ASHMEM_SET_SIZE, size); - if (ret < 0) - goto error; - - return fd; - -error: - close(fd); - return ret; -} - -int ashmem_set_prot_region(int fd, int prot) -{ - return ioctl(fd, ASHMEM_SET_PROT_MASK, prot); -} - -int ashmem_pin_region(int fd, size_t offset, size_t len) -{ - struct ashmem_pin pin = { offset, len }; - return ioctl(fd, ASHMEM_PIN, &pin); -} - -int ashmem_unpin_region(int fd, size_t offset, size_t len) -{ - struct ashmem_pin pin = { offset, len }; - return ioctl(fd, ASHMEM_UNPIN, &pin); -} - -int ashmem_get_size_region(int fd) -{ - return ioctl(fd, ASHMEM_GET_SIZE, NULL); -} - -int ashmem_purge_all(void) -{ - const int fd = open(ASHMEM_DEVICE, O_RDWR); - if (fd < 0) - return fd; - const int ret = ioctl(fd, ASHMEM_PURGE_ALL_CACHES, 0); - close(fd); - return ret; -} diff --git a/platform_tools/android/third_party/ashmem/cutils/ashmem.h b/platform_tools/android/third_party/ashmem/cutils/ashmem.h deleted file mode 100644 index 7d411cc064..0000000000 --- a/platform_tools/android/third_party/ashmem/cutils/ashmem.h +++ /dev/null @@ -1,46 +0,0 @@ -/* third_party/ashmem/ashmem.h - ** - ** Copyright 2008 The Android Open Source Project - ** - ** This file is dual licensed. It may be redistributed and/or modified - ** under the terms of the Apache 2.0 License OR version 2 of the GNU - ** General Public License. - */ - -#ifndef _THIRD_PARTY_ASHMEM_H -#define _THIRD_PARTY_ASHMEM_H - -#include <stddef.h> - -#ifdef __cplusplus -extern "C" { -#endif - -int ashmem_create_region(const char *name, size_t size); -int ashmem_set_prot_region(int fd, int prot); -int ashmem_pin_region(int fd, size_t offset, size_t len); -int ashmem_unpin_region(int fd, size_t offset, size_t len); -int ashmem_get_size_region(int fd); -int ashmem_purge_all(void); - -#ifdef __cplusplus -} -#endif - -#ifndef __ASHMEMIOC /* in case someone included <linux/ashmem.h> too */ - -#define ASHMEM_NAME_LEN 256 - -#define ASHMEM_NAME_DEF "dev/ashmem" - -/* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */ -#define ASHMEM_NOT_PURGED 0 -#define ASHMEM_WAS_PURGED 1 - -/* Return values from ASHMEM_UNPIN: Is the mapping now pinned or unpinned? */ -#define ASHMEM_IS_UNPINNED 0 -#define ASHMEM_IS_PINNED 1 - -#endif /* ! __ASHMEMIOC */ - -#endif /* _THIRD_PARTY_ASHMEM_H */ diff --git a/platform_tools/android/third_party/cpufeatures/README b/platform_tools/android/third_party/cpufeatures/README deleted file mode 100644 index d92522e040..0000000000 --- a/platform_tools/android/third_party/cpufeatures/README +++ /dev/null @@ -1,5 +0,0 @@ -The contents of this directory are directly copied from the Android NDK to -avoid the need to have a dependency on the NDK directly. - -NDK_REVISION: 10c (October 2014) -NDK_FILE_LOCAtION: ($NDK)/sources/android/cpufeatures diff --git a/platform_tools/android/third_party/cpufeatures/cpu-features.c b/platform_tools/android/third_party/cpufeatures/cpu-features.c deleted file mode 100644 index 2d23efb8f9..0000000000 --- a/platform_tools/android/third_party/cpufeatures/cpu-features.c +++ /dev/null @@ -1,1270 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* ChangeLog for this library: - * - * NDK r9?: Support for 64-bit CPUs (Intel, ARM & MIPS). - * - * NDK r8d: Add android_setCpu(). - * - * NDK r8c: Add new ARM CPU features: VFPv2, VFP_D32, VFP_FP16, - * VFP_FMA, NEON_FMA, IDIV_ARM, IDIV_THUMB2 and iWMMXt. - * - * Rewrite the code to parse /proc/self/auxv instead of - * the "Features" field in /proc/cpuinfo. - * - * Dynamically allocate the buffer that hold the content - * of /proc/cpuinfo to deal with newer hardware. - * - * NDK r7c: Fix CPU count computation. The old method only reported the - * number of _active_ CPUs when the library was initialized, - * which could be less than the real total. - * - * NDK r5: Handle buggy kernels which report a CPU Architecture number of 7 - * for an ARMv6 CPU (see below). - * - * Handle kernels that only report 'neon', and not 'vfpv3' - * (VFPv3 is mandated by the ARM architecture is Neon is implemented) - * - * Handle kernels that only report 'vfpv3d16', and not 'vfpv3' - * - * Fix x86 compilation. Report ANDROID_CPU_FAMILY_X86 in - * android_getCpuFamily(). - * - * NDK r4: Initial release - */ - -#if defined(__le32__) || defined(__le64__) - -// When users enter this, we should only provide interface and -// libportable will give the implementations. - -#else // !__le32__ && !__le64__ - -#include "cpu-features.h" - -#include <dlfcn.h> -#include <errno.h> -#include <fcntl.h> -#include <pthread.h> -#include <stdio.h> -#include <stdlib.h> -#include <sys/system_properties.h> - -static pthread_once_t g_once; -static int g_inited; -static AndroidCpuFamily g_cpuFamily; -static uint64_t g_cpuFeatures; -static int g_cpuCount; - -#ifdef __arm__ -static uint32_t g_cpuIdArm; -#endif - -static const int android_cpufeatures_debug = 0; - -#define D(...) \ - do { \ - if (android_cpufeatures_debug) { \ - printf(__VA_ARGS__); fflush(stdout); \ - } \ - } while (0) - -#ifdef __i386__ -static __inline__ void x86_cpuid(int func, int values[4]) -{ - int a, b, c, d; - /* We need to preserve ebx since we're compiling PIC code */ - /* this means we can't use "=b" for the second output register */ - __asm__ __volatile__ ( \ - "push %%ebx\n" - "cpuid\n" \ - "mov %%ebx, %1\n" - "pop %%ebx\n" - : "=a" (a), "=r" (b), "=c" (c), "=d" (d) \ - : "a" (func) \ - ); - values[0] = a; - values[1] = b; - values[2] = c; - values[3] = d; -} -#endif - -/* Get the size of a file by reading it until the end. This is needed - * because files under /proc do not always return a valid size when - * using fseek(0, SEEK_END) + ftell(). Nor can they be mmap()-ed. - */ -static int -get_file_size(const char* pathname) -{ - int fd, ret, result = 0; - char buffer[256]; - - fd = open(pathname, O_RDONLY); - if (fd < 0) { - D("Can't open %s: %s\n", pathname, strerror(errno)); - return -1; - } - - for (;;) { - int ret = read(fd, buffer, sizeof buffer); - if (ret < 0) { - if (errno == EINTR) - continue; - D("Error while reading %s: %s\n", pathname, strerror(errno)); - break; - } - if (ret == 0) - break; - - result += ret; - } - close(fd); - return result; -} - -/* Read the content of /proc/cpuinfo into a user-provided buffer. - * Return the length of the data, or -1 on error. Does *not* - * zero-terminate the content. Will not read more - * than 'buffsize' bytes. - */ -static int -read_file(const char* pathname, char* buffer, size_t buffsize) -{ - int fd, count; - - fd = open(pathname, O_RDONLY); - if (fd < 0) { - D("Could not open %s: %s\n", pathname, strerror(errno)); - return -1; - } - count = 0; - while (count < (int)buffsize) { - int ret = read(fd, buffer + count, buffsize - count); - if (ret < 0) { - if (errno == EINTR) - continue; - D("Error while reading from %s: %s\n", pathname, strerror(errno)); - if (count == 0) - count = -1; - break; - } - if (ret == 0) - break; - count += ret; - } - close(fd); - return count; -} - -/* Extract the content of a the first occurence of a given field in - * the content of /proc/cpuinfo and return it as a heap-allocated - * string that must be freed by the caller. - * - * Return NULL if not found - */ -static char* -extract_cpuinfo_field(const char* buffer, int buflen, const char* field) -{ - int fieldlen = strlen(field); - const char* bufend = buffer + buflen; - char* result = NULL; - int len, ignore; - const char *p, *q; - - /* Look for first field occurence, and ensures it starts the line. */ - p = buffer; - for (;;) { - p = memmem(p, bufend-p, field, fieldlen); - if (p == NULL) - goto EXIT; - - if (p == buffer || p[-1] == '\n') - break; - - p += fieldlen; - } - - /* Skip to the first column followed by a space */ - p += fieldlen; - p = memchr(p, ':', bufend-p); - if (p == NULL || p[1] != ' ') - goto EXIT; - - /* Find the end of the line */ - p += 2; - q = memchr(p, '\n', bufend-p); - if (q == NULL) - q = bufend; - - /* Copy the line into a heap-allocated buffer */ - len = q-p; - result = malloc(len+1); - if (result == NULL) - goto EXIT; - - memcpy(result, p, len); - result[len] = '\0'; - -EXIT: - return result; -} - -/* Checks that a space-separated list of items contains one given 'item'. - * Returns 1 if found, 0 otherwise. - */ -static int -has_list_item(const char* list, const char* item) -{ - const char* p = list; - int itemlen = strlen(item); - - if (list == NULL) - return 0; - - while (*p) { - const char* q; - - /* skip spaces */ - while (*p == ' ' || *p == '\t') - p++; - - /* find end of current list item */ - q = p; - while (*q && *q != ' ' && *q != '\t') - q++; - - if (itemlen == q-p && !memcmp(p, item, itemlen)) - return 1; - - /* skip to next item */ - p = q; - } - return 0; -} - -/* Parse a number starting from 'input', but not going further - * than 'limit'. Return the value into '*result'. - * - * NOTE: Does not skip over leading spaces, or deal with sign characters. - * NOTE: Ignores overflows. - * - * The function returns NULL in case of error (bad format), or the new - * position after the decimal number in case of success (which will always - * be <= 'limit'). - */ -static const char* -parse_number(const char* input, const char* limit, int base, int* result) -{ - const char* p = input; - int val = 0; - while (p < limit) { - int d = (*p - '0'); - if ((unsigned)d >= 10U) { - d = (*p - 'a'); - if ((unsigned)d >= 6U) - d = (*p - 'A'); - if ((unsigned)d >= 6U) - break; - d += 10; - } - if (d >= base) - break; - val = val*base + d; - p++; - } - if (p == input) - return NULL; - - *result = val; - return p; -} - -static const char* -parse_decimal(const char* input, const char* limit, int* result) -{ - return parse_number(input, limit, 10, result); -} - -static const char* -parse_hexadecimal(const char* input, const char* limit, int* result) -{ - return parse_number(input, limit, 16, result); -} - -/* This small data type is used to represent a CPU list / mask, as read - * from sysfs on Linux. See http://www.kernel.org/doc/Documentation/cputopology.txt - * - * For now, we don't expect more than 32 cores on mobile devices, so keep - * everything simple. - */ -typedef struct { - uint32_t mask; -} CpuList; - -static __inline__ void -cpulist_init(CpuList* list) { - list->mask = 0; -} - -static __inline__ void -cpulist_and(CpuList* list1, CpuList* list2) { - list1->mask &= list2->mask; -} - -static __inline__ void -cpulist_set(CpuList* list, int index) { - if ((unsigned)index < 32) { - list->mask |= (uint32_t)(1U << index); - } -} - -static __inline__ int -cpulist_count(CpuList* list) { - return __builtin_popcount(list->mask); -} - -/* Parse a textual list of cpus and store the result inside a CpuList object. - * Input format is the following: - * - comma-separated list of items (no spaces) - * - each item is either a single decimal number (cpu index), or a range made - * of two numbers separated by a single dash (-). Ranges are inclusive. - * - * Examples: 0 - * 2,4-127,128-143 - * 0-1 - */ -static void -cpulist_parse(CpuList* list, const char* line, int line_len) -{ - const char* p = line; - const char* end = p + line_len; - const char* q; - - /* NOTE: the input line coming from sysfs typically contains a - * trailing newline, so take care of it in the code below - */ - while (p < end && *p != '\n') - { - int val, start_value, end_value; - - /* Find the end of current item, and put it into 'q' */ - q = memchr(p, ',', end-p); - if (q == NULL) { - q = end; - } - - /* Get first value */ - p = parse_decimal(p, q, &start_value); - if (p == NULL) - goto BAD_FORMAT; - - end_value = start_value; - - /* If we're not at the end of the item, expect a dash and - * and integer; extract end value. - */ - if (p < q && *p == '-') { - p = parse_decimal(p+1, q, &end_value); - if (p == NULL) - goto BAD_FORMAT; - } - - /* Set bits CPU list bits */ - for (val = start_value; val <= end_value; val++) { - cpulist_set(list, val); - } - - /* Jump to next item */ - p = q; - if (p < end) - p++; - } - -BAD_FORMAT: - ; -} - -/* Read a CPU list from one sysfs file */ -static void -cpulist_read_from(CpuList* list, const char* filename) -{ - char file[64]; - int filelen; - - cpulist_init(list); - - filelen = read_file(filename, file, sizeof file); - if (filelen < 0) { - D("Could not read %s: %s\n", filename, strerror(errno)); - return; - } - - cpulist_parse(list, file, filelen); -} -#if defined(__aarch64__) -// see <uapi/asm/hwcap.h> kernel header -#define HWCAP_FP (1 << 0) -#define HWCAP_ASIMD (1 << 1) -#define HWCAP_AES (1 << 3) -#define HWCAP_PMULL (1 << 4) -#define HWCAP_SHA1 (1 << 5) -#define HWCAP_SHA2 (1 << 6) -#define HWCAP_CRC32 (1 << 7) -#endif - -#if defined(__arm__) - -// See <asm/hwcap.h> kernel header. -#define HWCAP_VFP (1 << 6) -#define HWCAP_IWMMXT (1 << 9) -#define HWCAP_NEON (1 << 12) -#define HWCAP_VFPv3 (1 << 13) -#define HWCAP_VFPv3D16 (1 << 14) -#define HWCAP_VFPv4 (1 << 16) -#define HWCAP_IDIVA (1 << 17) -#define HWCAP_IDIVT (1 << 18) - -// see <uapi/asm/hwcap.h> kernel header -#define HWCAP2_AES (1 << 0) -#define HWCAP2_PMULL (1 << 1) -#define HWCAP2_SHA1 (1 << 2) -#define HWCAP2_SHA2 (1 << 3) -#define HWCAP2_CRC32 (1 << 4) - -// This is the list of 32-bit ARMv7 optional features that are _always_ -// supported by ARMv8 CPUs, as mandated by the ARM Architecture Reference -// Manual. -#define HWCAP_SET_FOR_ARMV8 \ - ( HWCAP_VFP | \ - HWCAP_NEON | \ - HWCAP_VFPv3 | \ - HWCAP_VFPv4 | \ - HWCAP_IDIVA | \ - HWCAP_IDIVT ) -#endif - -#if defined(__arm__) || defined(__aarch64__) - -#define AT_HWCAP 16 -#define AT_HWCAP2 26 - -// Probe the system's C library for a 'getauxval' function and call it if -// it exits, or return 0 for failure. This function is available since API -// level 20. -// -// This code does *NOT* check for '__ANDROID_API__ >= 20' to support the -// edge case where some NDK developers use headers for a platform that is -// newer than the one really targetted by their application. -// This is typically done to use newer native APIs only when running on more -// recent Android versions, and requires careful symbol management. -// -// Note that getauxval() can't really be re-implemented here, because -// its implementation does not parse /proc/self/auxv. Instead it depends -// on values that are passed by the kernel at process-init time to the -// C runtime initialization layer. -static uint32_t -get_elf_hwcap_from_getauxval(int hwcap_type) { - typedef unsigned long getauxval_func_t(unsigned long); - - dlerror(); - void* libc_handle = dlopen("libc.so", RTLD_NOW); - if (!libc_handle) { - D("Could not dlopen() C library: %s\n", dlerror()); - return 0; - } - - uint32_t ret = 0; - getauxval_func_t* func = (getauxval_func_t*) - dlsym(libc_handle, "getauxval"); - if (!func) { - D("Could not find getauxval() in C library\n"); - } else { - // Note: getauxval() returns 0 on failure. Doesn't touch errno. - ret = (uint32_t)(*func)(hwcap_type); - } - dlclose(libc_handle); - return ret; -} -#endif - -#if defined(__arm__) -// Parse /proc/self/auxv to extract the ELF HW capabilities bitmap for the -// current CPU. Note that this file is not accessible from regular -// application processes on some Android platform releases. -// On success, return new ELF hwcaps, or 0 on failure. -static uint32_t -get_elf_hwcap_from_proc_self_auxv(void) { - const char filepath[] = "/proc/self/auxv"; - int fd = TEMP_FAILURE_RETRY(open(filepath, O_RDONLY)); - if (fd < 0) { - D("Could not open %s: %s\n", filepath, strerror(errno)); - return 0; - } - - struct { uint32_t tag; uint32_t value; } entry; - - uint32_t result = 0; - for (;;) { - int ret = TEMP_FAILURE_RETRY(read(fd, (char*)&entry, sizeof entry)); - if (ret < 0) { - D("Error while reading %s: %s\n", filepath, strerror(errno)); - break; - } - // Detect end of list. - if (ret == 0 || (entry.tag == 0 && entry.value == 0)) - break; - if (entry.tag == AT_HWCAP) { - result = entry.value; - break; - } - } - close(fd); - return result; -} - -/* Compute the ELF HWCAP flags from the content of /proc/cpuinfo. - * This works by parsing the 'Features' line, which lists which optional - * features the device's CPU supports, on top of its reference - * architecture. - */ -static uint32_t -get_elf_hwcap_from_proc_cpuinfo(const char* cpuinfo, int cpuinfo_len) { - uint32_t hwcaps = 0; - long architecture = 0; - char* cpuArch = extract_cpuinfo_field(cpuinfo, cpuinfo_len, "CPU architecture"); - if (cpuArch) { - architecture = strtol(cpuArch, NULL, 10); - free(cpuArch); - - if (architecture >= 8L) { - // This is a 32-bit ARM binary running on a 64-bit ARM64 kernel. - // The 'Features' line only lists the optional features that the - // device's CPU supports, compared to its reference architecture - // which are of no use for this process. - D("Faking 32-bit ARM HWCaps on ARMv%ld CPU\n", architecture); - return HWCAP_SET_FOR_ARMV8; - } - } - - char* cpuFeatures = extract_cpuinfo_field(cpuinfo, cpuinfo_len, "Features"); - if (cpuFeatures != NULL) { - D("Found cpuFeatures = '%s'\n", cpuFeatures); - - if (has_list_item(cpuFeatures, "vfp")) - hwcaps |= HWCAP_VFP; - if (has_list_item(cpuFeatures, "vfpv3")) - hwcaps |= HWCAP_VFPv3; - if (has_list_item(cpuFeatures, "vfpv3d16")) - hwcaps |= HWCAP_VFPv3D16; - if (has_list_item(cpuFeatures, "vfpv4")) - hwcaps |= HWCAP_VFPv4; - if (has_list_item(cpuFeatures, "neon")) - hwcaps |= HWCAP_NEON; - if (has_list_item(cpuFeatures, "idiva")) - hwcaps |= HWCAP_IDIVA; - if (has_list_item(cpuFeatures, "idivt")) - hwcaps |= HWCAP_IDIVT; - if (has_list_item(cpuFeatures, "idiv")) - hwcaps |= HWCAP_IDIVA | HWCAP_IDIVT; - if (has_list_item(cpuFeatures, "iwmmxt")) - hwcaps |= HWCAP_IWMMXT; - - free(cpuFeatures); - } - return hwcaps; -} - -/* Check Houdini Binary Translator is installed on the system. - * - * If this function returns 1, get_elf_hwcap_from_getauxval() function - * will causes SIGSEGV while calling getauxval() function. - */ -static int -has_houdini_binary_translator(void) { - int found = 0; - if (access("/system/lib/libhoudini.so", F_OK) != -1) { - D("Found Houdini binary translator\n"); - found = 1; - } - return found; -} -#endif /* __arm__ */ - -/* Return the number of cpus present on a given device. - * - * To handle all weird kernel configurations, we need to compute the - * intersection of the 'present' and 'possible' CPU lists and count - * the result. - */ -static int -get_cpu_count(void) -{ - CpuList cpus_present[1]; - CpuList cpus_possible[1]; - - cpulist_read_from(cpus_present, "/sys/devices/system/cpu/present"); - cpulist_read_from(cpus_possible, "/sys/devices/system/cpu/possible"); - - /* Compute the intersection of both sets to get the actual number of - * CPU cores that can be used on this device by the kernel. - */ - cpulist_and(cpus_present, cpus_possible); - - return cpulist_count(cpus_present); -} - -static void -android_cpuInitFamily(void) -{ -#if defined(__arm__) - g_cpuFamily = ANDROID_CPU_FAMILY_ARM; -#elif defined(__i386__) - g_cpuFamily = ANDROID_CPU_FAMILY_X86; -#elif defined(__mips64) -/* Needs to be before __mips__ since the compiler defines both */ - g_cpuFamily = ANDROID_CPU_FAMILY_MIPS64; -#elif defined(__mips__) - g_cpuFamily = ANDROID_CPU_FAMILY_MIPS; -#elif defined(__aarch64__) - g_cpuFamily = ANDROID_CPU_FAMILY_ARM64; -#elif defined(__x86_64__) - g_cpuFamily = ANDROID_CPU_FAMILY_X86_64; -#else - g_cpuFamily = ANDROID_CPU_FAMILY_UNKNOWN; -#endif -} - -static void -android_cpuInit(void) -{ - char* cpuinfo = NULL; - int cpuinfo_len; - - android_cpuInitFamily(); - - g_cpuFeatures = 0; - g_cpuCount = 1; - g_inited = 1; - - cpuinfo_len = get_file_size("/proc/cpuinfo"); - if (cpuinfo_len < 0) { - D("cpuinfo_len cannot be computed!"); - return; - } - cpuinfo = malloc(cpuinfo_len); - if (cpuinfo == NULL) { - D("cpuinfo buffer could not be allocated"); - return; - } - cpuinfo_len = read_file("/proc/cpuinfo", cpuinfo, cpuinfo_len); - D("cpuinfo_len is (%d):\n%.*s\n", cpuinfo_len, - cpuinfo_len >= 0 ? cpuinfo_len : 0, cpuinfo); - - if (cpuinfo_len < 0) /* should not happen */ { - free(cpuinfo); - return; - } - - /* Count the CPU cores, the value may be 0 for single-core CPUs */ - g_cpuCount = get_cpu_count(); - if (g_cpuCount == 0) { - g_cpuCount = 1; - } - - D("found cpuCount = %d\n", g_cpuCount); - -#ifdef __arm__ - { - /* Extract architecture from the "CPU Architecture" field. - * The list is well-known, unlike the the output of - * the 'Processor' field which can vary greatly. - * - * See the definition of the 'proc_arch' array in - * $KERNEL/arch/arm/kernel/setup.c and the 'c_show' function in - * same file. - */ - char* cpuArch = extract_cpuinfo_field(cpuinfo, cpuinfo_len, "CPU architecture"); - - if (cpuArch != NULL) { - char* end; - long archNumber; - int hasARMv7 = 0; - - D("found cpuArch = '%s'\n", cpuArch); - - /* read the initial decimal number, ignore the rest */ - archNumber = strtol(cpuArch, &end, 10); - - /* Note that ARMv8 is upwards compatible with ARMv7. */ - if (end > cpuArch && archNumber >= 7) { - hasARMv7 = 1; - } - - /* Unfortunately, it seems that certain ARMv6-based CPUs - * report an incorrect architecture number of 7! - * - * See http://code.google.com/p/android/issues/detail?id=10812 - * - * We try to correct this by looking at the 'elf_format' - * field reported by the 'Processor' field, which is of the - * form of "(v7l)" for an ARMv7-based CPU, and "(v6l)" for - * an ARMv6-one. - */ - if (hasARMv7) { - char* cpuProc = extract_cpuinfo_field(cpuinfo, cpuinfo_len, - "Processor"); - if (cpuProc != NULL) { - D("found cpuProc = '%s'\n", cpuProc); - if (has_list_item(cpuProc, "(v6l)")) { - D("CPU processor and architecture mismatch!!\n"); - hasARMv7 = 0; - } - free(cpuProc); - } - } - - if (hasARMv7) { - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_ARMv7; - } - - /* The LDREX / STREX instructions are available from ARMv6 */ - if (archNumber >= 6) { - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_LDREX_STREX; - } - - free(cpuArch); - } - - /* Check Houdini binary translator is installed */ - int has_houdini = has_houdini_binary_translator(); - - /* Extract the list of CPU features from ELF hwcaps */ - uint32_t hwcaps = 0; - if (!has_houdini) { - hwcaps = get_elf_hwcap_from_getauxval(AT_HWCAP); - } - if (!hwcaps) { - D("Parsing /proc/self/auxv to extract ELF hwcaps!\n"); - hwcaps = get_elf_hwcap_from_proc_self_auxv(); - } - if (!hwcaps) { - // Parsing /proc/self/auxv will fail from regular application - // processes on some Android platform versions, when this happens - // parse proc/cpuinfo instead. - D("Parsing /proc/cpuinfo to extract ELF hwcaps!\n"); - hwcaps = get_elf_hwcap_from_proc_cpuinfo(cpuinfo, cpuinfo_len); - } - - if (hwcaps != 0) { - int has_vfp = (hwcaps & HWCAP_VFP); - int has_vfpv3 = (hwcaps & HWCAP_VFPv3); - int has_vfpv3d16 = (hwcaps & HWCAP_VFPv3D16); - int has_vfpv4 = (hwcaps & HWCAP_VFPv4); - int has_neon = (hwcaps & HWCAP_NEON); - int has_idiva = (hwcaps & HWCAP_IDIVA); - int has_idivt = (hwcaps & HWCAP_IDIVT); - int has_iwmmxt = (hwcaps & HWCAP_IWMMXT); - - // The kernel does a poor job at ensuring consistency when - // describing CPU features. So lots of guessing is needed. - - // 'vfpv4' implies VFPv3|VFP_FMA|FP16 - if (has_vfpv4) - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFPv3 | - ANDROID_CPU_ARM_FEATURE_VFP_FP16 | - ANDROID_CPU_ARM_FEATURE_VFP_FMA; - - // 'vfpv3' or 'vfpv3d16' imply VFPv3. Note that unlike GCC, - // a value of 'vfpv3' doesn't necessarily mean that the D32 - // feature is present, so be conservative. All CPUs in the - // field that support D32 also support NEON, so this should - // not be a problem in practice. - if (has_vfpv3 || has_vfpv3d16) - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFPv3; - - // 'vfp' is super ambiguous. Depending on the kernel, it can - // either mean VFPv2 or VFPv3. Make it depend on ARMv7. - if (has_vfp) { - if (g_cpuFeatures & ANDROID_CPU_ARM_FEATURE_ARMv7) - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFPv3; - else - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFPv2; - } - - // Neon implies VFPv3|D32, and if vfpv4 is detected, NEON_FMA - if (has_neon) { - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFPv3 | - ANDROID_CPU_ARM_FEATURE_NEON | - ANDROID_CPU_ARM_FEATURE_VFP_D32; - if (has_vfpv4) - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_NEON_FMA; - } - - // VFPv3 implies VFPv2 and ARMv7 - if (g_cpuFeatures & ANDROID_CPU_ARM_FEATURE_VFPv3) - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFPv2 | - ANDROID_CPU_ARM_FEATURE_ARMv7; - - if (has_idiva) - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_IDIV_ARM; - if (has_idivt) - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_IDIV_THUMB2; - - if (has_iwmmxt) - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_iWMMXt; - } - - /* Extract the list of CPU features from ELF hwcaps2 */ - uint32_t hwcaps2 = 0; - if (!has_houdini) { - hwcaps2 = get_elf_hwcap_from_getauxval(AT_HWCAP2); - } - if (hwcaps2 != 0) { - int has_aes = (hwcaps2 & HWCAP2_AES); - int has_pmull = (hwcaps2 & HWCAP2_PMULL); - int has_sha1 = (hwcaps2 & HWCAP2_SHA1); - int has_sha2 = (hwcaps2 & HWCAP2_SHA2); - int has_crc32 = (hwcaps2 & HWCAP2_CRC32); - - if (has_aes) - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_AES; - if (has_pmull) - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_PMULL; - if (has_sha1) - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_SHA1; - if (has_sha2) - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_SHA2; - if (has_crc32) - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_CRC32; - } - /* Extract the cpuid value from various fields */ - // The CPUID value is broken up in several entries in /proc/cpuinfo. - // This table is used to rebuild it from the entries. - static const struct CpuIdEntry { - const char* field; - char format; - char bit_lshift; - char bit_length; - } cpu_id_entries[] = { - { "CPU implementer", 'x', 24, 8 }, - { "CPU variant", 'x', 20, 4 }, - { "CPU part", 'x', 4, 12 }, - { "CPU revision", 'd', 0, 4 }, - }; - size_t i; - D("Parsing /proc/cpuinfo to recover CPUID\n"); - for (i = 0; - i < sizeof(cpu_id_entries)/sizeof(cpu_id_entries[0]); - ++i) { - const struct CpuIdEntry* entry = &cpu_id_entries[i]; - char* value = extract_cpuinfo_field(cpuinfo, - cpuinfo_len, - entry->field); - if (value == NULL) - continue; - - D("field=%s value='%s'\n", entry->field, value); - char* value_end = value + strlen(value); - int val = 0; - const char* start = value; - const char* p; - if (value[0] == '0' && (value[1] == 'x' || value[1] == 'X')) { - start += 2; - p = parse_hexadecimal(start, value_end, &val); - } else if (entry->format == 'x') - p = parse_hexadecimal(value, value_end, &val); - else - p = parse_decimal(value, value_end, &val); - - if (p > (const char*)start) { - val &= ((1 << entry->bit_length)-1); - val <<= entry->bit_lshift; - g_cpuIdArm |= (uint32_t) val; - } - - free(value); - } - - // Handle kernel configuration bugs that prevent the correct - // reporting of CPU features. - static const struct CpuFix { - uint32_t cpuid; - uint64_t or_flags; - } cpu_fixes[] = { - /* The Nexus 4 (Qualcomm Krait) kernel configuration - * forgets to report IDIV support. */ - { 0x510006f2, ANDROID_CPU_ARM_FEATURE_IDIV_ARM | - ANDROID_CPU_ARM_FEATURE_IDIV_THUMB2 }, - { 0x510006f3, ANDROID_CPU_ARM_FEATURE_IDIV_ARM | - ANDROID_CPU_ARM_FEATURE_IDIV_THUMB2 }, - }; - size_t n; - for (n = 0; n < sizeof(cpu_fixes)/sizeof(cpu_fixes[0]); ++n) { - const struct CpuFix* entry = &cpu_fixes[n]; - - if (g_cpuIdArm == entry->cpuid) - g_cpuFeatures |= entry->or_flags; - } - - // Special case: The emulator-specific Android 4.2 kernel fails - // to report support for the 32-bit ARM IDIV instruction. - // Technically, this is a feature of the virtual CPU implemented - // by the emulator. Note that it could also support Thumb IDIV - // in the future, and this will have to be slightly updated. - char* hardware = extract_cpuinfo_field(cpuinfo, - cpuinfo_len, - "Hardware"); - if (hardware) { - if (!strcmp(hardware, "Goldfish") && - g_cpuIdArm == 0x4100c080 && - (g_cpuFamily & ANDROID_CPU_ARM_FEATURE_ARMv7) != 0) { - g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_IDIV_ARM; - } - free(hardware); - } - } -#endif /* __arm__ */ -#ifdef __aarch64__ - { - /* Extract the list of CPU features from ELF hwcaps */ - uint32_t hwcaps = 0; - hwcaps = get_elf_hwcap_from_getauxval(AT_HWCAP); - if (hwcaps != 0) { - int has_fp = (hwcaps & HWCAP_FP); - int has_asimd = (hwcaps & HWCAP_ASIMD); - int has_aes = (hwcaps & HWCAP_AES); - int has_pmull = (hwcaps & HWCAP_PMULL); - int has_sha1 = (hwcaps & HWCAP_SHA1); - int has_sha2 = (hwcaps & HWCAP_SHA2); - int has_crc32 = (hwcaps & HWCAP_CRC32); - - if(has_fp == 0) { - D("ERROR: Floating-point unit missing, but is required by Android on AArch64 CPUs\n"); - } - if(has_asimd == 0) { - D("ERROR: ASIMD unit missing, but is required by Android on AArch64 CPUs\n"); - } - - if (has_fp) - g_cpuFeatures |= ANDROID_CPU_ARM64_FEATURE_FP; - if (has_asimd) - g_cpuFeatures |= ANDROID_CPU_ARM64_FEATURE_ASIMD; - if (has_aes) - g_cpuFeatures |= ANDROID_CPU_ARM64_FEATURE_AES; - if (has_pmull) - g_cpuFeatures |= ANDROID_CPU_ARM64_FEATURE_PMULL; - if (has_sha1) - g_cpuFeatures |= ANDROID_CPU_ARM64_FEATURE_SHA1; - if (has_sha2) - g_cpuFeatures |= ANDROID_CPU_ARM64_FEATURE_SHA2; - if (has_crc32) - g_cpuFeatures |= ANDROID_CPU_ARM64_FEATURE_CRC32; - } - } -#endif /* __aarch64__ */ - -#ifdef __i386__ - int regs[4]; - -/* According to http://en.wikipedia.org/wiki/CPUID */ -#define VENDOR_INTEL_b 0x756e6547 -#define VENDOR_INTEL_c 0x6c65746e -#define VENDOR_INTEL_d 0x49656e69 - - x86_cpuid(0, regs); - int vendorIsIntel = (regs[1] == VENDOR_INTEL_b && - regs[2] == VENDOR_INTEL_c && - regs[3] == VENDOR_INTEL_d); - - x86_cpuid(1, regs); - if ((regs[2] & (1 << 9)) != 0) { - g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_SSSE3; - } - if ((regs[2] & (1 << 23)) != 0) { - g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_POPCNT; - } - if (vendorIsIntel && (regs[2] & (1 << 22)) != 0) { - g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_MOVBE; - } -#endif - - free(cpuinfo); -} - - -AndroidCpuFamily -android_getCpuFamily(void) -{ - pthread_once(&g_once, android_cpuInit); - return g_cpuFamily; -} - - -uint64_t -android_getCpuFeatures(void) -{ - pthread_once(&g_once, android_cpuInit); - return g_cpuFeatures; -} - - -int -android_getCpuCount(void) -{ - pthread_once(&g_once, android_cpuInit); - return g_cpuCount; -} - -static void -android_cpuInitDummy(void) -{ - g_inited = 1; -} - -int -android_setCpu(int cpu_count, uint64_t cpu_features) -{ - /* Fail if the library was already initialized. */ - if (g_inited) - return 0; - - android_cpuInitFamily(); - g_cpuCount = (cpu_count <= 0 ? 1 : cpu_count); - g_cpuFeatures = cpu_features; - pthread_once(&g_once, android_cpuInitDummy); - - return 1; -} - -#ifdef __arm__ -uint32_t -android_getCpuIdArm(void) -{ - pthread_once(&g_once, android_cpuInit); - return g_cpuIdArm; -} - -int -android_setCpuArm(int cpu_count, uint64_t cpu_features, uint32_t cpu_id) -{ - if (!android_setCpu(cpu_count, cpu_features)) - return 0; - - g_cpuIdArm = cpu_id; - return 1; -} -#endif /* __arm__ */ - -/* - * Technical note: Making sense of ARM's FPU architecture versions. - * - * FPA was ARM's first attempt at an FPU architecture. There is no Android - * device that actually uses it since this technology was already obsolete - * when the project started. If you see references to FPA instructions - * somewhere, you can be sure that this doesn't apply to Android at all. - * - * FPA was followed by "VFP", soon renamed "VFPv1" due to the emergence of - * new versions / additions to it. ARM considers this obsolete right now, - * and no known Android device implements it either. - * - * VFPv2 added a few instructions to VFPv1, and is an *optional* extension - * supported by some ARMv5TE, ARMv6 and ARMv6T2 CPUs. Note that a device - * supporting the 'armeabi' ABI doesn't necessarily support these. - * - * VFPv3-D16 adds a few instructions on top of VFPv2 and is typically used - * on ARMv7-A CPUs which implement a FPU. Note that it is also mandated - * by the Android 'armeabi-v7a' ABI. The -D16 suffix in its name means - * that it provides 16 double-precision FPU registers (d0-d15) and 32 - * single-precision ones (s0-s31) which happen to be mapped to the same - * register banks. - * - * VFPv3-D32 is the name of an extension to VFPv3-D16 that provides 16 - * additional double precision registers (d16-d31). Note that there are - * still only 32 single precision registers. - * - * VFPv3xD is a *subset* of VFPv3-D16 that only provides single-precision - * registers. It is only used on ARMv7-M (i.e. on micro-controllers) which - * are not supported by Android. Note that it is not compatible with VFPv2. - * - * NOTE: The term 'VFPv3' usually designate either VFPv3-D16 or VFPv3-D32 - * depending on context. For example GCC uses it for VFPv3-D32, but - * the Linux kernel code uses it for VFPv3-D16 (especially in - * /proc/cpuinfo). Always try to use the full designation when - * possible. - * - * NEON, a.k.a. "ARM Advanced SIMD" is an extension that provides - * instructions to perform parallel computations on vectors of 8, 16, - * 32, 64 and 128 bit quantities. NEON requires VFPv32-D32 since all - * NEON registers are also mapped to the same register banks. - * - * VFPv4-D16, adds a few instructions on top of VFPv3-D16 in order to - * perform fused multiply-accumulate on VFP registers, as well as - * half-precision (16-bit) conversion operations. - * - * VFPv4-D32 is VFPv4-D16 with 32, instead of 16, FPU double precision - * registers. - * - * VPFv4-NEON is VFPv4-D32 with NEON instructions. It also adds fused - * multiply-accumulate instructions that work on the NEON registers. - * - * NOTE: Similarly, "VFPv4" might either reference VFPv4-D16 or VFPv4-D32 - * depending on context. - * - * The following information was determined by scanning the binutils-2.22 - * sources: - * - * Basic VFP instruction subsets: - * - * #define FPU_VFP_EXT_V1xD 0x08000000 // Base VFP instruction set. - * #define FPU_VFP_EXT_V1 0x04000000 // Double-precision insns. - * #define FPU_VFP_EXT_V2 0x02000000 // ARM10E VFPr1. - * #define FPU_VFP_EXT_V3xD 0x01000000 // VFPv3 single-precision. - * #define FPU_VFP_EXT_V3 0x00800000 // VFPv3 double-precision. - * #define FPU_NEON_EXT_V1 0x00400000 // Neon (SIMD) insns. - * #define FPU_VFP_EXT_D32 0x00200000 // Registers D16-D31. - * #define FPU_VFP_EXT_FP16 0x00100000 // Half-precision extensions. - * #define FPU_NEON_EXT_FMA 0x00080000 // Neon fused multiply-add - * #define FPU_VFP_EXT_FMA 0x00040000 // VFP fused multiply-add - * - * FPU types (excluding NEON) - * - * FPU_VFP_V1xD (EXT_V1xD) - * | - * +--------------------------+ - * | | - * FPU_VFP_V1 (+EXT_V1) FPU_VFP_V3xD (+EXT_V2+EXT_V3xD) - * | | - * | | - * FPU_VFP_V2 (+EXT_V2) FPU_VFP_V4_SP_D16 (+EXT_FP16+EXT_FMA) - * | - * FPU_VFP_V3D16 (+EXT_Vx3D+EXT_V3) - * | - * +--------------------------+ - * | | - * FPU_VFP_V3 (+EXT_D32) FPU_VFP_V4D16 (+EXT_FP16+EXT_FMA) - * | | - * | FPU_VFP_V4 (+EXT_D32) - * | - * FPU_VFP_HARD (+EXT_FMA+NEON_EXT_FMA) - * - * VFP architectures: - * - * ARCH_VFP_V1xD (EXT_V1xD) - * | - * +------------------+ - * | | - * | ARCH_VFP_V3xD (+EXT_V2+EXT_V3xD) - * | | - * | ARCH_VFP_V3xD_FP16 (+EXT_FP16) - * | | - * | ARCH_VFP_V4_SP_D16 (+EXT_FMA) - * | - * ARCH_VFP_V1 (+EXT_V1) - * | - * ARCH_VFP_V2 (+EXT_V2) - * | - * ARCH_VFP_V3D16 (+EXT_V3xD+EXT_V3) - * | - * +-------------------+ - * | | - * | ARCH_VFP_V3D16_FP16 (+EXT_FP16) - * | - * +-------------------+ - * | | - * | ARCH_VFP_V4_D16 (+EXT_FP16+EXT_FMA) - * | | - * | ARCH_VFP_V4 (+EXT_D32) - * | | - * | ARCH_NEON_VFP_V4 (+EXT_NEON+EXT_NEON_FMA) - * | - * ARCH_VFP_V3 (+EXT_D32) - * | - * +-------------------+ - * | | - * | ARCH_VFP_V3_FP16 (+EXT_FP16) - * | - * ARCH_VFP_V3_PLUS_NEON_V1 (+EXT_NEON) - * | - * ARCH_NEON_FP16 (+EXT_FP16) - * - * -fpu=<name> values and their correspondance with FPU architectures above: - * - * {"vfp", FPU_ARCH_VFP_V2}, - * {"vfp9", FPU_ARCH_VFP_V2}, - * {"vfp3", FPU_ARCH_VFP_V3}, // For backwards compatbility. - * {"vfp10", FPU_ARCH_VFP_V2}, - * {"vfp10-r0", FPU_ARCH_VFP_V1}, - * {"vfpxd", FPU_ARCH_VFP_V1xD}, - * {"vfpv2", FPU_ARCH_VFP_V2}, - * {"vfpv3", FPU_ARCH_VFP_V3}, - * {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16}, - * {"vfpv3-d16", FPU_ARCH_VFP_V3D16}, - * {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16}, - * {"vfpv3xd", FPU_ARCH_VFP_V3xD}, - * {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16}, - * {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, - * {"neon-fp16", FPU_ARCH_NEON_FP16}, - * {"vfpv4", FPU_ARCH_VFP_V4}, - * {"vfpv4-d16", FPU_ARCH_VFP_V4D16}, - * {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16}, - * {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4}, - * - * - * Simplified diagram that only includes FPUs supported by Android: - * Only ARCH_VFP_V3D16 is actually mandated by the armeabi-v7a ABI, - * all others are optional and must be probed at runtime. - * - * ARCH_VFP_V3D16 (EXT_V1xD+EXT_V1+EXT_V2+EXT_V3xD+EXT_V3) - * | - * +-------------------+ - * | | - * | ARCH_VFP_V3D16_FP16 (+EXT_FP16) - * | - * +-------------------+ - * | | - * | ARCH_VFP_V4_D16 (+EXT_FP16+EXT_FMA) - * | | - * | ARCH_VFP_V4 (+EXT_D32) - * | | - * | ARCH_NEON_VFP_V4 (+EXT_NEON+EXT_NEON_FMA) - * | - * ARCH_VFP_V3 (+EXT_D32) - * | - * +-------------------+ - * | | - * | ARCH_VFP_V3_FP16 (+EXT_FP16) - * | - * ARCH_VFP_V3_PLUS_NEON_V1 (+EXT_NEON) - * | - * ARCH_NEON_FP16 (+EXT_FP16) - * - */ - -#endif // defined(__le32__) || defined(__le64__) diff --git a/platform_tools/android/third_party/cpufeatures/cpu-features.h b/platform_tools/android/third_party/cpufeatures/cpu-features.h deleted file mode 100644 index e86cba882f..0000000000 --- a/platform_tools/android/third_party/cpufeatures/cpu-features.h +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -#ifndef CPU_FEATURES_H -#define CPU_FEATURES_H - -#include <sys/cdefs.h> -#include <stdint.h> - -__BEGIN_DECLS - -/* A list of valid values returned by android_getCpuFamily(). - * They describe the CPU Architecture of the current process. - */ -typedef enum { - ANDROID_CPU_FAMILY_UNKNOWN = 0, - ANDROID_CPU_FAMILY_ARM, - ANDROID_CPU_FAMILY_X86, - ANDROID_CPU_FAMILY_MIPS, - ANDROID_CPU_FAMILY_ARM64, - ANDROID_CPU_FAMILY_X86_64, - ANDROID_CPU_FAMILY_MIPS64, - - ANDROID_CPU_FAMILY_MAX /* do not remove */ - -} AndroidCpuFamily; - -/* Return the CPU family of the current process. - * - * Note that this matches the bitness of the current process. I.e. when - * running a 32-bit binary on a 64-bit capable CPU, this will return the - * 32-bit CPU family value. - */ -extern AndroidCpuFamily android_getCpuFamily(void); - -/* Return a bitmap describing a set of optional CPU features that are - * supported by the current device's CPU. The exact bit-flags returned - * depend on the value returned by android_getCpuFamily(). See the - * documentation for the ANDROID_CPU_*_FEATURE_* flags below for details. - * - * NOTE: This will return 0 for the following architectures that don't have - * optional features listed at the moment: - * - * ANDROID_CPU_FAMILY_MIPS - * ANDROID_CPU_FAMILY_ARM64 - * ANDROID_CPU_FAMILY_X86_64 - * ANDROID_CPU_FAMILY_MIPS64 - */ -extern uint64_t android_getCpuFeatures(void); - -/* The list of feature flags for ANDROID_CPU_FAMILY_ARM that can be - * recognized by the library (see note below for 64-bit ARM). Value details - * are: - * - * VFPv2: - * CPU supports the VFPv2 instruction set. Many, but not all, ARMv6 CPUs - * support these instructions. VFPv2 is a subset of VFPv3 so this will - * be set whenever VFPv3 is set too. - * - * ARMv7: - * CPU supports the ARMv7-A basic instruction set. - * This feature is mandated by the 'armeabi-v7a' ABI. - * - * VFPv3: - * CPU supports the VFPv3-D16 instruction set, providing hardware FPU - * support for single and double precision floating point registers. - * Note that only 16 FPU registers are available by default, unless - * the D32 bit is set too. This feature is also mandated by the - * 'armeabi-v7a' ABI. - * - * VFP_D32: - * CPU VFP optional extension that provides 32 FPU registers, - * instead of 16. Note that ARM mandates this feature is the 'NEON' - * feature is implemented by the CPU. - * - * NEON: - * CPU FPU supports "ARM Advanced SIMD" instructions, also known as - * NEON. Note that this mandates the VFP_D32 feature as well, per the - * ARM Architecture specification. - * - * VFP_FP16: - * Half-width floating precision VFP extension. If set, the CPU - * supports instructions to perform floating-point operations on - * 16-bit registers. This is part of the VFPv4 specification, but - * not mandated by any Android ABI. - * - * VFP_FMA: - * Fused multiply-accumulate VFP instructions extension. Also part of - * the VFPv4 specification, but not mandated by any Android ABI. - * - * NEON_FMA: - * Fused multiply-accumulate NEON instructions extension. Optional - * extension from the VFPv4 specification, but not mandated by any - * Android ABI. - * - * IDIV_ARM: - * Integer division available in ARM mode. Only available - * on recent CPUs (e.g. Cortex-A15). - * - * IDIV_THUMB2: - * Integer division available in Thumb-2 mode. Only available - * on recent CPUs (e.g. Cortex-A15). - * - * iWMMXt: - * Optional extension that adds MMX registers and operations to an - * ARM CPU. This is only available on a few XScale-based CPU designs - * sold by Marvell. Pretty rare in practice. - * - * AES: - * CPU supports AES instructions. These instructions are only - * available for 32-bit applications running on ARMv8 CPU. - * - * CRC32: - * CPU supports CRC32 instructions. These instructions are only - * available for 32-bit applications running on ARMv8 CPU. - * - * SHA2: - * CPU supports SHA2 instructions. These instructions are only - * available for 32-bit applications running on ARMv8 CPU. - * - * SHA1: - * CPU supports SHA1 instructions. These instructions are only - * available for 32-bit applications running on ARMv8 CPU. - * - * PMULL: - * CPU supports 64-bit PMULL and PMULL2 instructions. These - * instructions are only available for 32-bit applications - * running on ARMv8 CPU. - * - * If you want to tell the compiler to generate code that targets one of - * the feature set above, you should probably use one of the following - * flags (for more details, see technical note at the end of this file): - * - * -mfpu=vfp - * -mfpu=vfpv2 - * These are equivalent and tell GCC to use VFPv2 instructions for - * floating-point operations. Use this if you want your code to - * run on *some* ARMv6 devices, and any ARMv7-A device supported - * by Android. - * - * Generated code requires VFPv2 feature. - * - * -mfpu=vfpv3-d16 - * Tell GCC to use VFPv3 instructions (using only 16 FPU registers). - * This should be generic code that runs on any CPU that supports the - * 'armeabi-v7a' Android ABI. Note that no ARMv6 CPU supports this. - * - * Generated code requires VFPv3 feature. - * - * -mfpu=vfpv3 - * Tell GCC to use VFPv3 instructions with 32 FPU registers. - * Generated code requires VFPv3|VFP_D32 features. - * - * -mfpu=neon - * Tell GCC to use VFPv3 instructions with 32 FPU registers, and - * also support NEON intrinsics (see <arm_neon.h>). - * Generated code requires VFPv3|VFP_D32|NEON features. - * - * -mfpu=vfpv4-d16 - * Generated code requires VFPv3|VFP_FP16|VFP_FMA features. - * - * -mfpu=vfpv4 - * Generated code requires VFPv3|VFP_FP16|VFP_FMA|VFP_D32 features. - * - * -mfpu=neon-vfpv4 - * Generated code requires VFPv3|VFP_FP16|VFP_FMA|VFP_D32|NEON|NEON_FMA - * features. - * - * -mcpu=cortex-a7 - * -mcpu=cortex-a15 - * Generated code requires VFPv3|VFP_FP16|VFP_FMA|VFP_D32| - * NEON|NEON_FMA|IDIV_ARM|IDIV_THUMB2 - * This flag implies -mfpu=neon-vfpv4. - * - * -mcpu=iwmmxt - * Allows the use of iWMMXt instrinsics with GCC. - * - * IMPORTANT NOTE: These flags should only be tested when - * android_getCpuFamily() returns ANDROID_CPU_FAMILY_ARM, i.e. this is a - * 32-bit process. - * - * When running a 64-bit ARM process on an ARMv8 CPU, - * android_getCpuFeatures() will return a different set of bitflags - */ -enum { - ANDROID_CPU_ARM_FEATURE_ARMv7 = (1 << 0), - ANDROID_CPU_ARM_FEATURE_VFPv3 = (1 << 1), - ANDROID_CPU_ARM_FEATURE_NEON = (1 << 2), - ANDROID_CPU_ARM_FEATURE_LDREX_STREX = (1 << 3), - ANDROID_CPU_ARM_FEATURE_VFPv2 = (1 << 4), - ANDROID_CPU_ARM_FEATURE_VFP_D32 = (1 << 5), - ANDROID_CPU_ARM_FEATURE_VFP_FP16 = (1 << 6), - ANDROID_CPU_ARM_FEATURE_VFP_FMA = (1 << 7), - ANDROID_CPU_ARM_FEATURE_NEON_FMA = (1 << 8), - ANDROID_CPU_ARM_FEATURE_IDIV_ARM = (1 << 9), - ANDROID_CPU_ARM_FEATURE_IDIV_THUMB2 = (1 << 10), - ANDROID_CPU_ARM_FEATURE_iWMMXt = (1 << 11), - ANDROID_CPU_ARM_FEATURE_AES = (1 << 12), - ANDROID_CPU_ARM_FEATURE_PMULL = (1 << 13), - ANDROID_CPU_ARM_FEATURE_SHA1 = (1 << 14), - ANDROID_CPU_ARM_FEATURE_SHA2 = (1 << 15), - ANDROID_CPU_ARM_FEATURE_CRC32 = (1 << 16), -}; - -/* The bit flags corresponding to the output of android_getCpuFeatures() - * when android_getCpuFamily() returns ANDROID_CPU_FAMILY_ARM64. Value details - * are: - * - * FP: - * CPU has Floating-point unit. - * - * ASIMD: - * CPU has Advanced SIMD unit. - * - * AES: - * CPU supports AES instructions. - * - * CRC32: - * CPU supports CRC32 instructions. - * - * SHA2: - * CPU supports SHA2 instructions. - * - * SHA1: - * CPU supports SHA1 instructions. - * - * PMULL: - * CPU supports 64-bit PMULL and PMULL2 instructions. - */ -enum { - ANDROID_CPU_ARM64_FEATURE_FP = (1 << 0), - ANDROID_CPU_ARM64_FEATURE_ASIMD = (1 << 1), - ANDROID_CPU_ARM64_FEATURE_AES = (1 << 2), - ANDROID_CPU_ARM64_FEATURE_PMULL = (1 << 3), - ANDROID_CPU_ARM64_FEATURE_SHA1 = (1 << 4), - ANDROID_CPU_ARM64_FEATURE_SHA2 = (1 << 5), - ANDROID_CPU_ARM64_FEATURE_CRC32 = (1 << 6), -}; -/* The bit flags corresponding to the output of android_getCpuFeatures() - * when android_getCpuFamily() returns ANDROID_CPU_FAMILY_X86. - */ -enum { - ANDROID_CPU_X86_FEATURE_SSSE3 = (1 << 0), - ANDROID_CPU_X86_FEATURE_POPCNT = (1 << 1), - ANDROID_CPU_X86_FEATURE_MOVBE = (1 << 2), -}; - -/* Return the number of CPU cores detected on this device. */ -extern int android_getCpuCount(void); - -/* The following is used to force the CPU count and features - * mask in sandboxed processes. Under 4.1 and higher, these processes - * cannot access /proc, which is the only way to get information from - * the kernel about the current hardware (at least on ARM). - * - * It _must_ be called only once, and before any android_getCpuXXX - * function, any other case will fail. - * - * This function return 1 on success, and 0 on failure. - */ -extern int android_setCpu(int cpu_count, - uint64_t cpu_features); - -#ifdef __arm__ -/* Retrieve the ARM 32-bit CPUID value from the kernel. - * Note that this cannot work on sandboxed processes under 4.1 and - * higher, unless you called android_setCpuArm() before. - */ -extern uint32_t android_getCpuIdArm(void); - -/* An ARM-specific variant of android_setCpu() that also allows you - * to set the ARM CPUID field. - */ -extern int android_setCpuArm(int cpu_count, - uint64_t cpu_features, - uint32_t cpu_id); -#endif - -__END_DECLS - -#endif /* CPU_FEATURES_H */ diff --git a/platform_tools/android/third_party/native_app_glue/README b/platform_tools/android/third_party/native_app_glue/README deleted file mode 100644 index 5dad6dde17..0000000000 --- a/platform_tools/android/third_party/native_app_glue/README +++ /dev/null @@ -1,5 +0,0 @@ -The contents of this directory are directly copied from the Android NDK to -avoid the need to have a dependency on the NDK directly. - -NDK_REVISION: 10c (October 2014) -NDK_FILE_LOCAtION: ($NDK)/sources/android/native_app_glue diff --git a/platform_tools/android/third_party/native_app_glue/android_native_app_glue.c b/platform_tools/android/third_party/native_app_glue/android_native_app_glue.c deleted file mode 100644 index 595bc76347..0000000000 --- a/platform_tools/android/third_party/native_app_glue/android_native_app_glue.c +++ /dev/null @@ -1,448 +0,0 @@ -/* - * Copyright (C) 2010 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. - * - */ - -#include <jni.h> - -#include <errno.h> -#include <string.h> -#include <unistd.h> -#include <sys/resource.h> - -#include "android_native_app_glue.h" -#include <android/log.h> - -#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "threaded_app", __VA_ARGS__)) -#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "threaded_app", __VA_ARGS__)) - -/* For debug builds, always enable the debug traces in this library */ -#ifndef NDEBUG -# define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, "threaded_app", __VA_ARGS__)) -#else -# define LOGV(...) ((void)0) -#endif - -static void free_saved_state(struct android_app* android_app) { - pthread_mutex_lock(&android_app->mutex); - if (android_app->savedState != NULL) { - free(android_app->savedState); - android_app->savedState = NULL; - android_app->savedStateSize = 0; - } - pthread_mutex_unlock(&android_app->mutex); -} - -int8_t android_app_read_cmd(struct android_app* android_app) { - int8_t cmd; - if (read(android_app->msgread, &cmd, sizeof(cmd)) == sizeof(cmd)) { - switch (cmd) { - case APP_CMD_SAVE_STATE: - free_saved_state(android_app); - break; - } - return cmd; - } else { - LOGE("No data on command pipe!"); - } - return -1; -} - -static void print_cur_config(struct android_app* android_app) { - char lang[2], country[2]; - AConfiguration_getLanguage(android_app->config, lang); - AConfiguration_getCountry(android_app->config, country); - - LOGV("Config: mcc=%d mnc=%d lang=%c%c cnt=%c%c orien=%d touch=%d dens=%d " - "keys=%d nav=%d keysHid=%d navHid=%d sdk=%d size=%d long=%d " - "modetype=%d modenight=%d", - AConfiguration_getMcc(android_app->config), - AConfiguration_getMnc(android_app->config), - lang[0], lang[1], country[0], country[1], - AConfiguration_getOrientation(android_app->config), - AConfiguration_getTouchscreen(android_app->config), - AConfiguration_getDensity(android_app->config), - AConfiguration_getKeyboard(android_app->config), - AConfiguration_getNavigation(android_app->config), - AConfiguration_getKeysHidden(android_app->config), - AConfiguration_getNavHidden(android_app->config), - AConfiguration_getSdkVersion(android_app->config), - AConfiguration_getScreenSize(android_app->config), - AConfiguration_getScreenLong(android_app->config), - AConfiguration_getUiModeType(android_app->config), - AConfiguration_getUiModeNight(android_app->config)); -} - -void android_app_pre_exec_cmd(struct android_app* android_app, int8_t cmd) { - switch (cmd) { - case APP_CMD_INPUT_CHANGED: - LOGV("APP_CMD_INPUT_CHANGED\n"); - pthread_mutex_lock(&android_app->mutex); - if (android_app->inputQueue != NULL) { - AInputQueue_detachLooper(android_app->inputQueue); - } - android_app->inputQueue = android_app->pendingInputQueue; - if (android_app->inputQueue != NULL) { - LOGV("Attaching input queue to looper"); - AInputQueue_attachLooper(android_app->inputQueue, - android_app->looper, LOOPER_ID_INPUT, NULL, - &android_app->inputPollSource); - } - pthread_cond_broadcast(&android_app->cond); - pthread_mutex_unlock(&android_app->mutex); - break; - - case APP_CMD_INIT_WINDOW: - LOGV("APP_CMD_INIT_WINDOW\n"); - pthread_mutex_lock(&android_app->mutex); - android_app->window = android_app->pendingWindow; - pthread_cond_broadcast(&android_app->cond); - pthread_mutex_unlock(&android_app->mutex); - break; - - case APP_CMD_TERM_WINDOW: - LOGV("APP_CMD_TERM_WINDOW\n"); - pthread_cond_broadcast(&android_app->cond); - break; - - case APP_CMD_RESUME: - case APP_CMD_START: - case APP_CMD_PAUSE: - case APP_CMD_STOP: - LOGV("activityState=%d\n", cmd); - pthread_mutex_lock(&android_app->mutex); - android_app->activityState = cmd; - pthread_cond_broadcast(&android_app->cond); - pthread_mutex_unlock(&android_app->mutex); - break; - - case APP_CMD_CONFIG_CHANGED: - LOGV("APP_CMD_CONFIG_CHANGED\n"); - AConfiguration_fromAssetManager(android_app->config, - android_app->activity->assetManager); - print_cur_config(android_app); - break; - - case APP_CMD_DESTROY: - LOGV("APP_CMD_DESTROY\n"); - android_app->destroyRequested = 1; - break; - } -} - -void android_app_post_exec_cmd(struct android_app* android_app, int8_t cmd) { - switch (cmd) { - case APP_CMD_TERM_WINDOW: - LOGV("APP_CMD_TERM_WINDOW\n"); - pthread_mutex_lock(&android_app->mutex); - android_app->window = NULL; - pthread_cond_broadcast(&android_app->cond); - pthread_mutex_unlock(&android_app->mutex); - break; - - case APP_CMD_SAVE_STATE: - LOGV("APP_CMD_SAVE_STATE\n"); - pthread_mutex_lock(&android_app->mutex); - android_app->stateSaved = 1; - pthread_cond_broadcast(&android_app->cond); - pthread_mutex_unlock(&android_app->mutex); - break; - - case APP_CMD_RESUME: - free_saved_state(android_app); - break; - } -} - -void app_dummy() { - -} - -static void android_app_destroy(struct android_app* android_app) { - LOGV("android_app_destroy!"); - free_saved_state(android_app); - pthread_mutex_lock(&android_app->mutex); - if (android_app->inputQueue != NULL) { - AInputQueue_detachLooper(android_app->inputQueue); - } - AConfiguration_delete(android_app->config); - android_app->destroyed = 1; - pthread_cond_broadcast(&android_app->cond); - pthread_mutex_unlock(&android_app->mutex); - // Can't touch android_app object after this. -} - -static void process_input(struct android_app* app, struct android_poll_source* source) { - AInputEvent* event = NULL; - while (AInputQueue_getEvent(app->inputQueue, &event) >= 0) { - LOGV("New input event: type=%d\n", AInputEvent_getType(event)); - if (AInputQueue_preDispatchEvent(app->inputQueue, event)) { - continue; - } - int32_t handled = 0; - if (app->onInputEvent != NULL) handled = app->onInputEvent(app, event); - AInputQueue_finishEvent(app->inputQueue, event, handled); - } -} - -static void process_cmd(struct android_app* app, struct android_poll_source* source) { - int8_t cmd = android_app_read_cmd(app); - android_app_pre_exec_cmd(app, cmd); - if (app->onAppCmd != NULL) app->onAppCmd(app, cmd); - android_app_post_exec_cmd(app, cmd); -} - -static void* android_app_entry(void* param) { - struct android_app* android_app = (struct android_app*)param; - - android_app->config = AConfiguration_new(); - AConfiguration_fromAssetManager(android_app->config, android_app->activity->assetManager); - - print_cur_config(android_app); - - android_app->cmdPollSource.id = LOOPER_ID_MAIN; - android_app->cmdPollSource.app = android_app; - android_app->cmdPollSource.process = process_cmd; - android_app->inputPollSource.id = LOOPER_ID_INPUT; - android_app->inputPollSource.app = android_app; - android_app->inputPollSource.process = process_input; - - ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); - ALooper_addFd(looper, android_app->msgread, LOOPER_ID_MAIN, ALOOPER_EVENT_INPUT, NULL, - &android_app->cmdPollSource); - android_app->looper = looper; - - pthread_mutex_lock(&android_app->mutex); - android_app->running = 1; - pthread_cond_broadcast(&android_app->cond); - pthread_mutex_unlock(&android_app->mutex); - - android_main(android_app); - - android_app_destroy(android_app); - return NULL; -} - -// -------------------------------------------------------------------- -// Native activity interaction (called from main thread) -// -------------------------------------------------------------------- - -static struct android_app* android_app_create(ANativeActivity* activity, - void* savedState, size_t savedStateSize) { - struct android_app* android_app = (struct android_app*)malloc(sizeof(struct android_app)); - memset(android_app, 0, sizeof(struct android_app)); - android_app->activity = activity; - - pthread_mutex_init(&android_app->mutex, NULL); - pthread_cond_init(&android_app->cond, NULL); - - if (savedState != NULL) { - android_app->savedState = malloc(savedStateSize); - android_app->savedStateSize = savedStateSize; - memcpy(android_app->savedState, savedState, savedStateSize); - } - - int msgpipe[2]; - if (pipe(msgpipe)) { - LOGE("could not create pipe: %s", strerror(errno)); - return NULL; - } - android_app->msgread = msgpipe[0]; - android_app->msgwrite = msgpipe[1]; - - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - pthread_create(&android_app->thread, &attr, android_app_entry, android_app); - - // Wait for thread to start. - pthread_mutex_lock(&android_app->mutex); - while (!android_app->running) { - pthread_cond_wait(&android_app->cond, &android_app->mutex); - } - pthread_mutex_unlock(&android_app->mutex); - - return android_app; -} - -static void android_app_write_cmd(struct android_app* android_app, int8_t cmd) { - if (write(android_app->msgwrite, &cmd, sizeof(cmd)) != sizeof(cmd)) { - LOGE("Failure writing android_app cmd: %s\n", strerror(errno)); - } -} - -static void android_app_set_input(struct android_app* android_app, AInputQueue* inputQueue) { - pthread_mutex_lock(&android_app->mutex); - android_app->pendingInputQueue = inputQueue; - android_app_write_cmd(android_app, APP_CMD_INPUT_CHANGED); - while (android_app->inputQueue != android_app->pendingInputQueue) { - pthread_cond_wait(&android_app->cond, &android_app->mutex); - } - pthread_mutex_unlock(&android_app->mutex); -} - -static void android_app_set_window(struct android_app* android_app, ANativeWindow* window) { - pthread_mutex_lock(&android_app->mutex); - if (android_app->pendingWindow != NULL) { - android_app_write_cmd(android_app, APP_CMD_TERM_WINDOW); - } - android_app->pendingWindow = window; - if (window != NULL) { - android_app_write_cmd(android_app, APP_CMD_INIT_WINDOW); - } - while (android_app->window != android_app->pendingWindow) { - pthread_cond_wait(&android_app->cond, &android_app->mutex); - } - pthread_mutex_unlock(&android_app->mutex); -} - -static void android_app_set_activity_state(struct android_app* android_app, int8_t cmd) { - pthread_mutex_lock(&android_app->mutex); - android_app_write_cmd(android_app, cmd); - while (android_app->activityState != cmd) { - pthread_cond_wait(&android_app->cond, &android_app->mutex); - } - pthread_mutex_unlock(&android_app->mutex); -} - -static void android_app_free(struct android_app* android_app) { - pthread_mutex_lock(&android_app->mutex); - android_app_write_cmd(android_app, APP_CMD_DESTROY); - while (!android_app->destroyed) { - pthread_cond_wait(&android_app->cond, &android_app->mutex); - } - pthread_mutex_unlock(&android_app->mutex); - - close(android_app->msgread); - close(android_app->msgwrite); - pthread_cond_destroy(&android_app->cond); - pthread_mutex_destroy(&android_app->mutex); - free(android_app); -} - -static void onDestroy(ANativeActivity* activity) { - LOGV("Destroy: %p\n", activity); - android_app_free((struct android_app*)activity->instance); -} - -static void onStart(ANativeActivity* activity) { - LOGV("Start: %p\n", activity); - android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_START); -} - -static void onResume(ANativeActivity* activity) { - LOGV("Resume: %p\n", activity); - android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_RESUME); -} - -static void* onSaveInstanceState(ANativeActivity* activity, size_t* outLen) { - struct android_app* android_app = (struct android_app*)activity->instance; - void* savedState = NULL; - - LOGV("SaveInstanceState: %p\n", activity); - pthread_mutex_lock(&android_app->mutex); - android_app->stateSaved = 0; - android_app_write_cmd(android_app, APP_CMD_SAVE_STATE); - while (!android_app->stateSaved) { - pthread_cond_wait(&android_app->cond, &android_app->mutex); - } - - if (android_app->savedState != NULL) { - savedState = android_app->savedState; - *outLen = android_app->savedStateSize; - android_app->savedState = NULL; - android_app->savedStateSize = 0; - } - - pthread_mutex_unlock(&android_app->mutex); - - return savedState; -} - -static void onPause(ANativeActivity* activity) { - LOGV("Pause: %p\n", activity); - android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_PAUSE); -} - -static void onStop(ANativeActivity* activity) { - LOGV("Stop: %p\n", activity); - android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_STOP); -} - -static void onConfigurationChanged(ANativeActivity* activity) { - struct android_app* android_app = (struct android_app*)activity->instance; - LOGV("ConfigurationChanged: %p\n", activity); - android_app_write_cmd(android_app, APP_CMD_CONFIG_CHANGED); -} - -static void onLowMemory(ANativeActivity* activity) { - struct android_app* android_app = (struct android_app*)activity->instance; - LOGV("LowMemory: %p\n", activity); - android_app_write_cmd(android_app, APP_CMD_LOW_MEMORY); -} - -static void onWindowFocusChanged(ANativeActivity* activity, int focused) { - LOGV("WindowFocusChanged: %p -- %d\n", activity, focused); - android_app_write_cmd((struct android_app*)activity->instance, - focused ? APP_CMD_GAINED_FOCUS : APP_CMD_LOST_FOCUS); -} - -static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* window) { - LOGV("NativeWindowCreated: %p -- %p\n", activity, window); - android_app_set_window((struct android_app*)activity->instance, window); -} - -static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* window) { - LOGV("NativeWindowDestroyed: %p -- %p\n", activity, window); - android_app_set_window((struct android_app*)activity->instance, NULL); -} - -static void onInputQueueCreated(ANativeActivity* activity, AInputQueue* queue) { - LOGV("InputQueueCreated: %p -- %p\n", activity, queue); - android_app_set_input((struct android_app*)activity->instance, queue); -} - -static void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue* queue) { - LOGV("InputQueueDestroyed: %p -- %p\n", activity, queue); - android_app_set_input((struct android_app*)activity->instance, NULL); -} - -static void onContentRectChanged(ANativeActivity* activity, const ARect* rect) { - struct android_app* android_app = (struct android_app*)activity->instance; - LOGV("OnContentRectChanged: %p\n", activity); - android_app->contentRect = *rect; - android_app_write_cmd(android_app, APP_CMD_CONTENT_RECT_CHANGED); -} - -void ANativeActivity_onCreate(ANativeActivity* activity, - void* savedState, size_t savedStateSize) { - LOGV("Creating: %p\n", activity); - activity->callbacks->onDestroy = onDestroy; - activity->callbacks->onStart = onStart; - activity->callbacks->onResume = onResume; - activity->callbacks->onSaveInstanceState = onSaveInstanceState; - activity->callbacks->onPause = onPause; - activity->callbacks->onStop = onStop; - activity->callbacks->onConfigurationChanged = onConfigurationChanged; - activity->callbacks->onLowMemory = onLowMemory; - activity->callbacks->onWindowFocusChanged = onWindowFocusChanged; - activity->callbacks->onNativeWindowCreated = onNativeWindowCreated; - activity->callbacks->onNativeWindowDestroyed = onNativeWindowDestroyed; - activity->callbacks->onInputQueueCreated = onInputQueueCreated; - activity->callbacks->onInputQueueDestroyed = onInputQueueDestroyed; - activity->callbacks->onContentRectChanged = onContentRectChanged; - - activity->instance = android_app_create(activity, savedState, savedStateSize); -} diff --git a/platform_tools/android/third_party/native_app_glue/android_native_app_glue.h b/platform_tools/android/third_party/native_app_glue/android_native_app_glue.h deleted file mode 100644 index 97202e0941..0000000000 --- a/platform_tools/android/third_party/native_app_glue/android_native_app_glue.h +++ /dev/null @@ -1,349 +0,0 @@ -/* - * Copyright (C) 2010 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. - * - */ - -#ifndef _ANDROID_NATIVE_APP_GLUE_H -#define _ANDROID_NATIVE_APP_GLUE_H - -#include <poll.h> -#include <pthread.h> -#include <sched.h> - -#include <android/configuration.h> -#include <android/looper.h> -#include <android/native_activity.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * The native activity interface provided by <android/native_activity.h> - * is based on a set of application-provided callbacks that will be called - * by the Activity's main thread when certain events occur. - * - * This means that each one of this callbacks _should_ _not_ block, or they - * risk having the system force-close the application. This programming - * model is direct, lightweight, but constraining. - * - * The 'android_native_app_glue' static library is used to provide a different - * execution model where the application can implement its own main event - * loop in a different thread instead. Here's how it works: - * - * 1/ The application must provide a function named "android_main()" that - * will be called when the activity is created, in a new thread that is - * distinct from the activity's main thread. - * - * 2/ android_main() receives a pointer to a valid "android_app" structure - * that contains references to other important objects, e.g. the - * ANativeActivity obejct instance the application is running in. - * - * 3/ the "android_app" object holds an ALooper instance that already - * listens to two important things: - * - * - activity lifecycle events (e.g. "pause", "resume"). See APP_CMD_XXX - * declarations below. - * - * - input events coming from the AInputQueue attached to the activity. - * - * Each of these correspond to an ALooper identifier returned by - * ALooper_pollOnce with values of LOOPER_ID_MAIN and LOOPER_ID_INPUT, - * respectively. - * - * Your application can use the same ALooper to listen to additional - * file-descriptors. They can either be callback based, or with return - * identifiers starting with LOOPER_ID_USER. - * - * 4/ Whenever you receive a LOOPER_ID_MAIN or LOOPER_ID_INPUT event, - * the returned data will point to an android_poll_source structure. You - * can call the process() function on it, and fill in android_app->onAppCmd - * and android_app->onInputEvent to be called for your own processing - * of the event. - * - * Alternatively, you can call the low-level functions to read and process - * the data directly... look at the process_cmd() and process_input() - * implementations in the glue to see how to do this. - * - * See the sample named "native-activity" that comes with the NDK with a - * full usage example. Also look at the JavaDoc of NativeActivity. - */ - -struct android_app; - -/** - * Data associated with an ALooper fd that will be returned as the "outData" - * when that source has data ready. - */ -struct android_poll_source { - // The identifier of this source. May be LOOPER_ID_MAIN or - // LOOPER_ID_INPUT. - int32_t id; - - // The android_app this ident is associated with. - struct android_app* app; - - // Function to call to perform the standard processing of data from - // this source. - void (*process)(struct android_app* app, struct android_poll_source* source); -}; - -/** - * This is the interface for the standard glue code of a threaded - * application. In this model, the application's code is running - * in its own thread separate from the main thread of the process. - * It is not required that this thread be associated with the Java - * VM, although it will need to be in order to make JNI calls any - * Java objects. - */ -struct android_app { - // The application can place a pointer to its own state object - // here if it likes. - void* userData; - - // Fill this in with the function to process main app commands (APP_CMD_*) - void (*onAppCmd)(struct android_app* app, int32_t cmd); - - // Fill this in with the function to process input events. At this point - // the event has already been pre-dispatched, and it will be finished upon - // return. Return 1 if you have handled the event, 0 for any default - // dispatching. - int32_t (*onInputEvent)(struct android_app* app, AInputEvent* event); - - // The ANativeActivity object instance that this app is running in. - ANativeActivity* activity; - - // The current configuration the app is running in. - AConfiguration* config; - - // This is the last instance's saved state, as provided at creation time. - // It is NULL if there was no state. You can use this as you need; the - // memory will remain around until you call android_app_exec_cmd() for - // APP_CMD_RESUME, at which point it will be freed and savedState set to NULL. - // These variables should only be changed when processing a APP_CMD_SAVE_STATE, - // at which point they will be initialized to NULL and you can malloc your - // state and place the information here. In that case the memory will be - // freed for you later. - void* savedState; - size_t savedStateSize; - - // The ALooper associated with the app's thread. - ALooper* looper; - - // When non-NULL, this is the input queue from which the app will - // receive user input events. - AInputQueue* inputQueue; - - // When non-NULL, this is the window surface that the app can draw in. - ANativeWindow* window; - - // Current content rectangle of the window; this is the area where the - // window's content should be placed to be seen by the user. - ARect contentRect; - - // Current state of the app's activity. May be either APP_CMD_START, - // APP_CMD_RESUME, APP_CMD_PAUSE, or APP_CMD_STOP; see below. - int activityState; - - // This is non-zero when the application's NativeActivity is being - // destroyed and waiting for the app thread to complete. - int destroyRequested; - - // ------------------------------------------------- - // Below are "private" implementation of the glue code. - - pthread_mutex_t mutex; - pthread_cond_t cond; - - int msgread; - int msgwrite; - - pthread_t thread; - - struct android_poll_source cmdPollSource; - struct android_poll_source inputPollSource; - - int running; - int stateSaved; - int destroyed; - int redrawNeeded; - AInputQueue* pendingInputQueue; - ANativeWindow* pendingWindow; - ARect pendingContentRect; -}; - -enum { - /** - * Looper data ID of commands coming from the app's main thread, which - * is returned as an identifier from ALooper_pollOnce(). The data for this - * identifier is a pointer to an android_poll_source structure. - * These can be retrieved and processed with android_app_read_cmd() - * and android_app_exec_cmd(). - */ - LOOPER_ID_MAIN = 1, - - /** - * Looper data ID of events coming from the AInputQueue of the - * application's window, which is returned as an identifier from - * ALooper_pollOnce(). The data for this identifier is a pointer to an - * android_poll_source structure. These can be read via the inputQueue - * object of android_app. - */ - LOOPER_ID_INPUT = 2, - - /** - * Start of user-defined ALooper identifiers. - */ - LOOPER_ID_USER = 3, -}; - -enum { - /** - * Command from main thread: the AInputQueue has changed. Upon processing - * this command, android_app->inputQueue will be updated to the new queue - * (or NULL). - */ - APP_CMD_INPUT_CHANGED, - - /** - * Command from main thread: a new ANativeWindow is ready for use. Upon - * receiving this command, android_app->window will contain the new window - * surface. - */ - APP_CMD_INIT_WINDOW, - - /** - * Command from main thread: the existing ANativeWindow needs to be - * terminated. Upon receiving this command, android_app->window still - * contains the existing window; after calling android_app_exec_cmd - * it will be set to NULL. - */ - APP_CMD_TERM_WINDOW, - - /** - * Command from main thread: the current ANativeWindow has been resized. - * Please redraw with its new size. - */ - APP_CMD_WINDOW_RESIZED, - - /** - * Command from main thread: the system needs that the current ANativeWindow - * be redrawn. You should redraw the window before handing this to - * android_app_exec_cmd() in order to avoid transient drawing glitches. - */ - APP_CMD_WINDOW_REDRAW_NEEDED, - - /** - * Command from main thread: the content area of the window has changed, - * such as from the soft input window being shown or hidden. You can - * find the new content rect in android_app::contentRect. - */ - APP_CMD_CONTENT_RECT_CHANGED, - - /** - * Command from main thread: the app's activity window has gained - * input focus. - */ - APP_CMD_GAINED_FOCUS, - - /** - * Command from main thread: the app's activity window has lost - * input focus. - */ - APP_CMD_LOST_FOCUS, - - /** - * Command from main thread: the current device configuration has changed. - */ - APP_CMD_CONFIG_CHANGED, - - /** - * Command from main thread: the system is running low on memory. - * Try to reduce your memory use. - */ - APP_CMD_LOW_MEMORY, - - /** - * Command from main thread: the app's activity has been started. - */ - APP_CMD_START, - - /** - * Command from main thread: the app's activity has been resumed. - */ - APP_CMD_RESUME, - - /** - * Command from main thread: the app should generate a new saved state - * for itself, to restore from later if needed. If you have saved state, - * allocate it with malloc and place it in android_app.savedState with - * the size in android_app.savedStateSize. The will be freed for you - * later. - */ - APP_CMD_SAVE_STATE, - - /** - * Command from main thread: the app's activity has been paused. - */ - APP_CMD_PAUSE, - - /** - * Command from main thread: the app's activity has been stopped. - */ - APP_CMD_STOP, - - /** - * Command from main thread: the app's activity is being destroyed, - * and waiting for the app thread to clean up and exit before proceeding. - */ - APP_CMD_DESTROY, -}; - -/** - * Call when ALooper_pollAll() returns LOOPER_ID_MAIN, reading the next - * app command message. - */ -int8_t android_app_read_cmd(struct android_app* android_app); - -/** - * Call with the command returned by android_app_read_cmd() to do the - * initial pre-processing of the given command. You can perform your own - * actions for the command after calling this function. - */ -void android_app_pre_exec_cmd(struct android_app* android_app, int8_t cmd); - -/** - * Call with the command returned by android_app_read_cmd() to do the - * final post-processing of the given command. You must have done your own - * actions for the command before calling this function. - */ -void android_app_post_exec_cmd(struct android_app* android_app, int8_t cmd); - -/** - * Dummy function you can call to ensure glue code isn't stripped. - */ -void app_dummy(); - -/** - * This is the function that application code must implement, representing - * the main entry to the app. - */ -extern void android_main(struct android_app* app); - -#ifdef __cplusplus -} -#endif - -#endif /* _ANDROID_NATIVE_APP_GLUE_H */ |