├── app ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── values │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── layout │ │ │ └── activity_main.xml │ │ ├── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ └── drawable │ │ │ └── ic_launcher_background.xml │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── zipalign ├── .gitignore ├── consumer-rules.pro ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ ├── cpp │ │ ├── android │ │ │ ├── native │ │ │ │ ├── include │ │ │ │ │ └── utils │ │ │ │ │ │ ├── Atomic.h │ │ │ │ │ │ ├── SystemClock.h │ │ │ │ │ │ ├── Functor.h │ │ │ │ │ │ ├── Endian.h │ │ │ │ │ │ ├── threads.h │ │ │ │ │ │ ├── ashmem.h │ │ │ │ │ │ ├── Compat.h │ │ │ │ │ │ ├── StopWatch.h │ │ │ │ │ │ ├── ZipFileCRO.h │ │ │ │ │ │ ├── misc.h │ │ │ │ │ │ ├── BufferedTextOutput.h │ │ │ │ │ │ ├── LinearTransform.h │ │ │ │ │ │ ├── CallStack.h │ │ │ │ │ │ ├── StringArray.h │ │ │ │ │ │ ├── ByteOrder.h │ │ │ │ │ │ ├── Log.h │ │ │ │ │ │ ├── ZipUtils.h │ │ │ │ │ │ ├── Debug.h │ │ │ │ │ │ ├── Singleton.h │ │ │ │ │ │ ├── Errors.h │ │ │ │ │ │ ├── PropertyMap.h │ │ │ │ │ │ ├── RWLock.h │ │ │ │ │ │ ├── ThreadDefs.h │ │ │ │ │ │ ├── WorkQueue.h │ │ │ │ │ │ ├── Mutex.h │ │ │ │ │ │ ├── Thread.h │ │ │ │ │ │ └── BitSet.h │ │ │ │ └── src │ │ │ │ │ └── utils │ │ │ │ │ └── SharedBuffer.cpp │ │ │ ├── core │ │ │ │ └── include │ │ │ │ │ ├── cutils │ │ │ │ │ ├── partition_utils.h │ │ │ │ │ ├── dir_hash.h │ │ │ │ │ ├── open_memstream.h │ │ │ │ │ ├── uevent.h │ │ │ │ │ ├── zygote.h │ │ │ │ │ ├── sched_policy.h │ │ │ │ │ ├── cpu_info.h │ │ │ │ │ ├── bitops.h │ │ │ │ │ ├── android_reboot.h │ │ │ │ │ ├── iosched_policy.h │ │ │ │ │ ├── process_name.h │ │ │ │ │ ├── ashmem.h │ │ │ │ │ ├── record_stream.h │ │ │ │ │ ├── uio.h │ │ │ │ │ ├── klog.h │ │ │ │ │ ├── memory.h │ │ │ │ │ ├── event_tag_map.h │ │ │ │ │ ├── jstring.h │ │ │ │ │ ├── compiler.h │ │ │ │ │ ├── logd.h │ │ │ │ │ ├── misc.h │ │ │ │ │ ├── logger.h │ │ │ │ │ ├── list.h │ │ │ │ │ ├── tztime.h │ │ │ │ │ ├── str_parms.h │ │ │ │ │ ├── config_utils.h │ │ │ │ │ ├── qtaguid.h │ │ │ │ │ ├── array.h │ │ │ │ │ ├── native_handle.h │ │ │ │ │ ├── atomic-inline.h │ │ │ │ │ ├── properties.h │ │ │ │ │ ├── mq.h │ │ │ │ │ ├── sockets.h │ │ │ │ │ ├── abort_socket.h │ │ │ │ │ ├── hashmap.h │ │ │ │ │ ├── atomic-x86.h │ │ │ │ │ ├── selector.h │ │ │ │ │ ├── logprint.h │ │ │ │ │ ├── mspace.h │ │ │ │ │ └── threads.h │ │ │ │ │ ├── zipfile │ │ │ │ │ └── zipfile.h │ │ │ │ │ ├── system │ │ │ │ │ ├── audio_policy.h │ │ │ │ │ └── graphics.h │ │ │ │ │ └── android │ │ │ │ │ └── log.h │ │ │ └── base │ │ │ │ └── include │ │ │ │ └── androidfw │ │ │ │ ├── PowerManager.h │ │ │ │ ├── misc.h │ │ │ │ ├── ZipUtils.h │ │ │ │ ├── StreamingZipInflater.h │ │ │ │ └── ObbFile.h │ │ ├── CMakeLists.txt │ │ ├── ZipAlign.cpp │ │ └── zipalign │ │ │ └── include │ │ │ └── zipalign │ │ │ └── ZipAlign.h │ │ └── java │ │ └── io │ │ └── github │ │ └── muntashirakon │ │ └── zipalign │ │ └── ZipAlign.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── jitpack.yml ├── README.md ├── gradle.properties └── gradlew.bat /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /zipalign/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /zipalign/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':zipalign' 2 | include ':app' 3 | rootProject.name = "ZipAlign" -------------------------------------------------------------------------------- /zipalign/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MuntashirAkon/zipalign-android/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/ 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | .cxx 10 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MuntashirAkon/zipalign-android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MuntashirAkon/zipalign-android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MuntashirAkon/zipalign-android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MuntashirAkon/zipalign-android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MuntashirAkon/zipalign-android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /jitpack.yml: -------------------------------------------------------------------------------- 1 | jdk: 2 | - openjdk17 3 | before_install: 4 | - sdk install java 17.0.3-tem 5 | - sdk use java 17.0.3-tem 6 | - sdk install maven 7 | - mvn -v -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MuntashirAkon/zipalign-android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MuntashirAkon/zipalign-android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MuntashirAkon/zipalign-android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MuntashirAkon/zipalign-android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MuntashirAkon/zipalign-android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #6200EE 4 | #3700B3 5 | #03DAC5 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ZipAlignTest 3 | Select APK 4 | APK has already been aligned. 5 | Couldn\'t align the APK file 6 | APK successfully aligned. 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /zipalign/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/Atomic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_UTILS_ATOMIC_H 18 | #define ANDROID_UTILS_ATOMIC_H 19 | 20 | #include 21 | 22 | #endif // ANDROID_UTILS_ATOMIC_H 23 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdk 33 5 | 6 | defaultConfig { 7 | namespace "io.github.muntashirakon.zipalign.test" 8 | applicationId "io.github.muntashirakon.zipalign.test" 9 | minSdkVersion 21 10 | targetSdk 33 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | compileOptions { 22 | sourceCompatibility JavaVersion.VERSION_1_8 23 | targetCompatibility JavaVersion.VERSION_1_8 24 | } 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(dir: "libs", include: ["*.jar"]) 29 | implementation project(path: ':zipalign') 30 | implementation 'androidx.appcompat:appcompat:1.6.1' 31 | } 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ZipAlign for Android 2 | 3 | Android port of [`zipalign` tool](http://developer.android.com/tools/help/zipalign.html). 4 | 5 | [![](https://jitpack.io/v/MuntashirAkon/zipalign-android.svg)](https://jitpack.io/#MuntashirAkon/zipalign-android) 6 | 7 | ## Quick start 8 | ZipAlign for Android is available via JitPack. 9 | 10 | ```groovy 11 | // Top level build file 12 | repositories { 13 | maven { url "https://jitpack.io" } 14 | } 15 | 16 | // Add to dependencies section 17 | dependencies { 18 | implementation 'com.github.MuntashirAkon:zipalign-android:1.0' 19 | } 20 | ``` 21 | 22 | After importing the library, use the `ZipAlign` class to align or verify alignment of a ZIP or APK file. 23 | 24 | This library is a native library, so make sure to define architectures/instruction sets based on your need. 25 | 26 | ## Credits 27 | ZipAlign for Android is based on [android-lib-zipalign](https://github.com/animehunter/android-lib-zipalign) by @animehunter. 28 | -------------------------------------------------------------------------------- /zipalign/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdk 30 5 | 6 | defaultConfig { 7 | namespace "io.github.muntashirakon.zipalign" 8 | minSdk 21 9 | targetSdk 30 10 | 11 | externalNativeBuild { 12 | cmake { 13 | cppFlags "" 14 | } 15 | } 16 | ndk { 17 | abiFilters 'armeabi-v7a', 'x86', 'arm64-v8a', 'x86_64' 18 | } 19 | } 20 | 21 | buildTypes { 22 | release { 23 | minifyEnabled false 24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 25 | } 26 | } 27 | externalNativeBuild { 28 | cmake { 29 | path "src/main/cpp/CMakeLists.txt" 30 | version "3.10.2" 31 | } 32 | } 33 | } 34 | 35 | dependencies { 36 | implementation fileTree(dir: "libs", include: ["*.jar"]) 37 | implementation 'androidx.annotation:annotation:1.5.0' 38 | } -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/partition_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_PARTITION_WIPED_H__ 18 | #define __CUTILS_PARTITION_WIPED_H__ 19 | 20 | __BEGIN_DECLS 21 | 22 | int partition_wiped(char *source); 23 | void erase_footer(const char *dev_path, long long size); 24 | 25 | __END_DECLS 26 | 27 | #endif /* __CUTILS_PARTITION_WIPED_H__ */ 28 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/dir_hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | typedef enum { 18 | SHA_1, 19 | } HashAlgorithm; 20 | 21 | int get_file_hash(HashAlgorithm algorithm, const char *path, 22 | char *output_string, size_t max_output_string); 23 | 24 | int get_recursive_hash_manifest(HashAlgorithm algorithm, 25 | const char *directory_path, 26 | char **output_string); 27 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/open_memstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_OPEN_MEMSTREAM_H__ 18 | #define __CUTILS_OPEN_MEMSTREAM_H__ 19 | 20 | #include 21 | 22 | #ifndef HAVE_OPEN_MEMSTREAM 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | FILE *open_memstream(char **bufp, size_t *sizep); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /*!HAVE_OPEN_MEMSTREAM*/ 35 | 36 | #endif /*__CUTILS_OPEN_MEMSTREAM_H__*/ 37 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/uevent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_UEVENT_H 18 | #define __CUTILS_UEVENT_H 19 | 20 | #include 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | int uevent_open_socket(int buf_sz, bool passcred); 28 | ssize_t uevent_kernel_multicast_recv(int socket, void *buffer, size_t length); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /* __CUTILS_UEVENT_H */ 35 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/zygote.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_ZYGOTE_H 18 | #define __CUTILS_ZYGOTE_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | int zygote_run_oneshot(int sendStdio, int argc, const char **argv); 25 | int zygote_run(int argc, const char **argv); 26 | int zygote_run_wait(int argc, const char **argv, void (*post_run_func)(int)); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif /* __CUTILS_ZYGOTE_H */ 33 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/SystemClock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_UTILS_SYSTEMCLOCK_H 18 | #define ANDROID_UTILS_SYSTEMCLOCK_H 19 | 20 | #include 21 | #include 22 | 23 | namespace android { 24 | 25 | int setCurrentTimeMillis(int64_t millis); 26 | int64_t uptimeMillis(); 27 | int64_t elapsedRealtime(); 28 | int64_t elapsedRealtimeNano(); 29 | 30 | }; // namespace android 31 | 32 | #endif // ANDROID_UTILS_SYSTEMCLOCK_H 33 | 34 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/Functor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_FUNCTOR_H 18 | #define ANDROID_FUNCTOR_H 19 | 20 | #include 21 | 22 | namespace android { 23 | 24 | class Functor { 25 | public: 26 | Functor() {} 27 | virtual ~Functor() {} 28 | virtual status_t operator ()(int what, void *data) { 29 | return NO_ERROR; 30 | } 31 | }; 32 | 33 | }; // namespace android 34 | 35 | #endif // ANDROID_FUNCTOR_H 36 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/sched_policy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_SCHED_POLICY_H 18 | #define __CUTILS_SCHED_POLICY_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | typedef enum { 25 | SP_BACKGROUND = 0, 26 | SP_FOREGROUND = 1, 27 | } SchedPolicy; 28 | 29 | extern int set_sched_policy(int tid, SchedPolicy policy); 30 | extern int get_sched_policy(int tid, SchedPolicy *policy); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif /* __CUTILS_SCHED_POLICY_H */ 37 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/base/include/androidfw/PowerManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _ANDROIDFW_POWER_MANAGER_H 18 | #define _ANDROIDFW_POWER_MANAGER_H 19 | 20 | 21 | namespace android { 22 | 23 | enum { 24 | USER_ACTIVITY_EVENT_OTHER = 0, 25 | USER_ACTIVITY_EVENT_BUTTON = 1, 26 | USER_ACTIVITY_EVENT_TOUCH = 2, 27 | 28 | USER_ACTIVITY_EVENT_LAST = USER_ACTIVITY_EVENT_TOUCH, // Last valid event code. 29 | }; 30 | 31 | } // namespace android 32 | 33 | #endif // _ANDROIDFW_POWER_MANAGER_H 34 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/cpu_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_CPU_INFO_H 18 | #define __CUTILS_CPU_INFO_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /* returns a string contiaining an ASCII representation of the CPU serial number, 25 | ** or NULL if cpu info not available. 26 | ** The string is a static variable, so don't call free() on it. 27 | */ 28 | extern const char *get_cpu_serial_number(void); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /* __CUTILS_CPU_INFO_H */ 35 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | 3 | add_definitions(-DHAVE_PTHREADS=1) 4 | add_definitions(-DHAVE_OFF64_T=1) #might cause problem on older systems! 5 | add_definitions(-DOS_PATH_SEPARATOR=47) #ascii code for / (slash) 6 | add_definitions(-DHAVE_SYS_SOCKET_H=1) 7 | add_definitions(-DANDROID_SMP=1) #always needed? (Required by SharedBuffer.cpp/atomic.h) 8 | 9 | set(CMAKE_C_FLAGS_DEBUG "-ggdb") 10 | set(CMAKE_CXX_FLAGS_DEBUG "-ggdb") 11 | set(CMAKE_C_FLAGS_RELEASE "-O3") 12 | set(CMAKE_CXX_FLAGS_RELEASE "-O3") 13 | 14 | add_library(zipalign SHARED 15 | ZipAlign.cpp 16 | zipalign/ZipAlign.cpp 17 | zipalign/ZipEntry.cpp 18 | zipalign/ZipFile.cpp 19 | android/native/src/utils/SharedBuffer.cpp 20 | android/native/src/utils/ZipUtils.cpp 21 | android/native/src/utils/VectorImpl.cpp) 22 | 23 | target_include_directories(zipalign BEFORE PUBLIC 24 | zipalign/include 25 | android/base/include 26 | android/core/include 27 | android/native/include) 28 | 29 | target_link_libraries(zipalign log) 30 | 31 | target_link_libraries(zipalign z) 32 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/bitops.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_BITOPS_H 18 | #define __CUTILS_BITOPS_H 19 | 20 | #include 21 | 22 | __BEGIN_DECLS 23 | 24 | static inline int popcount(unsigned int x) { 25 | return __builtin_popcount(x); 26 | } 27 | 28 | static inline int popcountl(unsigned long x) { 29 | return __builtin_popcountl(x); 30 | } 31 | 32 | static inline int popcountll(unsigned long long x) { 33 | return __builtin_popcountll(x); 34 | } 35 | 36 | __END_DECLS 37 | 38 | #endif /* __CUTILS_BITOPS_H */ 39 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/android_reboot.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_ANDROID_REBOOT_H__ 18 | #define __CUTILS_ANDROID_REBOOT_H__ 19 | 20 | __BEGIN_DECLS 21 | 22 | /* Commands */ 23 | #define ANDROID_RB_RESTART 0xDEAD0001 24 | #define ANDROID_RB_POWEROFF 0xDEAD0002 25 | #define ANDROID_RB_RESTART2 0xDEAD0003 26 | 27 | /* Flags */ 28 | #define ANDROID_RB_FLAG_NO_SYNC 0x1 29 | #define ANDROID_RB_FLAG_NO_REMOUNT_RO 0x2 30 | 31 | int android_reboot(int cmd, int flags, char *arg); 32 | 33 | __END_DECLS 34 | 35 | #endif /* __CUTILS_ANDROID_REBOOT_H__ */ 36 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/Endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // 18 | // Android endian-ness defines. 19 | // 20 | #ifndef _LIBS_UTILS_ENDIAN_H 21 | #define _LIBS_UTILS_ENDIAN_H 22 | 23 | #if defined(HAVE_ENDIAN_H) 24 | 25 | #include 26 | 27 | #else /*not HAVE_ENDIAN_H*/ 28 | 29 | #define __BIG_ENDIAN 0x1000 30 | #define __LITTLE_ENDIAN 0x0001 31 | 32 | #if defined(HAVE_LITTLE_ENDIAN) 33 | # define __BYTE_ORDER __LITTLE_ENDIAN 34 | #else 35 | # define __BYTE_ORDER __BIG_ENDIAN 36 | #endif 37 | 38 | #endif /*not HAVE_ENDIAN_H*/ 39 | 40 | #endif /*_LIBS_UTILS_ENDIAN_H*/ 41 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/threads.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _LIBS_UTILS_THREADS_H 18 | #define _LIBS_UTILS_THREADS_H 19 | 20 | /* 21 | * Please, DO NOT USE! 22 | * 23 | * This file is here only for legacy reasons. Instead, include directly 24 | * the headers you need below. 25 | * 26 | */ 27 | 28 | #include 29 | 30 | #ifdef __cplusplus 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #endif 37 | 38 | #endif // _LIBS_UTILS_THREADS_H 39 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/iosched_policy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_IOSCHED_POLICY_H 18 | #define __CUTILS_IOSCHED_POLICY_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | typedef enum { 25 | IoSchedClass_NONE, 26 | IoSchedClass_RT, 27 | IoSchedClass_BE, 28 | IoSchedClass_IDLE, 29 | } IoSchedClass; 30 | 31 | extern int android_set_ioprio(int pid, IoSchedClass clazz, int ioprio); 32 | extern int android_get_ioprio(int pid, IoSchedClass *clazz, int *ioprio); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif /* __CUTILS_IOSCHED_POLICY_H */ 39 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/process_name.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Gives the current process a name. 19 | */ 20 | 21 | #ifndef __PROCESS_NAME_H 22 | #define __PROCESS_NAME_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /** 29 | * Sets the current process name. 30 | * 31 | * Warning: This leaks a string every time you call it. Use judiciously! 32 | */ 33 | void set_process_name(const char *process_name); 34 | 35 | /** Gets the current process name. */ 36 | const char *get_process_name(void); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* __PROCESS_NAME_H */ 43 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/ashmem.h: -------------------------------------------------------------------------------- 1 | /* cutils/ashmem.h 2 | ** 3 | ** Copyright 2008 The Android Open Source Project 4 | ** 5 | ** This file is dual licensed. It may be redistributed and/or modified 6 | ** under the terms of the Apache 2.0 License OR version 2 of the GNU 7 | ** General Public License. 8 | */ 9 | 10 | #ifndef _CUTILS_ASHMEM_H 11 | #define _CUTILS_ASHMEM_H 12 | 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | int ashmem_create_region(const char *name, size_t size); 20 | int ashmem_set_prot_region(int fd, int prot); 21 | int ashmem_pin_region(int fd, size_t offset, size_t len); 22 | int ashmem_unpin_region(int fd, size_t offset, size_t len); 23 | int ashmem_get_size_region(int fd); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #ifndef __ASHMEMIOC /* in case someone included too */ 30 | 31 | #define ASHMEM_NAME_LEN 256 32 | 33 | #define ASHMEM_NAME_DEF "dev/ashmem" 34 | 35 | /* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */ 36 | #define ASHMEM_NOT_PURGED 0 37 | #define ASHMEM_WAS_PURGED 1 38 | 39 | /* Return values from ASHMEM_UNPIN: Is the mapping now pinned or unpinned? */ 40 | #define ASHMEM_IS_UNPINNED 0 41 | #define ASHMEM_IS_PINNED 1 42 | 43 | #endif /* ! __ASHMEMIOC */ 44 | 45 | #endif /* _CUTILS_ASHMEM_H */ 46 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/record_stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * A simple utility for reading fixed records out of a stream fd 19 | */ 20 | 21 | #ifndef _CUTILS_RECORD_STREAM_H 22 | #define _CUTILS_RECORD_STREAM_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | 29 | typedef struct RecordStream RecordStream; 30 | 31 | extern RecordStream *record_stream_new(int fd, size_t maxRecordLen); 32 | extern void record_stream_free(RecordStream *p_rs); 33 | 34 | extern int record_stream_get_next (RecordStream *p_rs, void **p_outRecord, 35 | size_t *p_outRecordLen); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | 42 | #endif /*_CUTILS_RECORD_STREAM_H*/ 43 | 44 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/uio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // 18 | // implementation of sys/uio.h for platforms that don't have it (Win32) 19 | // 20 | #ifndef _LIBS_CUTILS_UIO_H 21 | #define _LIBS_CUTILS_UIO_H 22 | 23 | #ifdef HAVE_SYS_UIO_H 24 | #include 25 | #else 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #include 32 | 33 | struct iovec { 34 | const void *iov_base; 35 | size_t iov_len; 36 | }; 37 | 38 | extern int readv( int fd, struct iovec *vecs, int count ); 39 | extern int writev( int fd, const struct iovec *vecs, int count ); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* !HAVE_SYS_UIO_H */ 46 | 47 | #endif /* _LIBS_UTILS_UIO_H */ 48 | 49 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/klog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CUTILS_KLOG_H_ 18 | #define _CUTILS_KLOG_H_ 19 | 20 | void klog_init(void); 21 | void klog_set_level(int level); 22 | void klog_close(void); 23 | void klog_write(int level, const char *fmt, ...) 24 | __attribute__ ((format(printf, 2, 3))); 25 | 26 | #define KLOG_ERROR(tag,x...) klog_write(3, "<3>" tag ": " x) 27 | #define KLOG_WARNING(tag,x...) klog_write(4, "<4>" tag ": " x) 28 | #define KLOG_NOTICE(tag,x...) klog_write(5, "<5>" tag ": " x) 29 | #define KLOG_INFO(tag,x...) klog_write(6, "<6>" tag ": " x) 30 | #define KLOG_DEBUG(tag,x...) klog_write(7, "<7>" tag ": " x) 31 | 32 | #define KLOG_DEFAULT_LEVEL 3 /* messages <= this level are logged */ 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_CUTILS_MEMORY_H 18 | #define ANDROID_CUTILS_MEMORY_H 19 | 20 | #include 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* size is given in bytes and must be multiple of 2 */ 28 | void android_memset16(uint16_t *dst, uint16_t value, size_t size); 29 | 30 | /* size is given in bytes and must be multiple of 4 */ 31 | void android_memset32(uint32_t *dst, uint32_t value, size_t size); 32 | 33 | #if !HAVE_STRLCPY 34 | /* Declaration of strlcpy() for platforms that don't already have it. */ 35 | size_t strlcpy(char *dst, const char *src, size_t size); 36 | #endif 37 | 38 | #ifdef __cplusplus 39 | } // extern "C" 40 | #endif 41 | 42 | #endif // ANDROID_CUTILS_MEMORY_H 43 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/ashmem.h: -------------------------------------------------------------------------------- 1 | /* utils/ashmem.h 2 | ** 3 | ** Copyright 2008 The Android Open Source Project 4 | ** 5 | ** This file is dual licensed. It may be redistributed and/or modified 6 | ** under the terms of the Apache 2.0 License OR version 2 of the GNU 7 | ** General Public License. 8 | */ 9 | 10 | #ifndef _UTILS_ASHMEM_H 11 | #define _UTILS_ASHMEM_H 12 | 13 | #include 14 | #include 15 | 16 | #define ASHMEM_NAME_LEN 256 17 | 18 | #define ASHMEM_NAME_DEF "dev/ashmem" 19 | 20 | /* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */ 21 | #define ASHMEM_NOT_REAPED 0 22 | #define ASHMEM_WAS_REAPED 1 23 | 24 | /* Return values from ASHMEM_UNPIN: Is the mapping now pinned or unpinned? */ 25 | #define ASHMEM_NOW_UNPINNED 0 26 | #define ASHMEM_NOW_PINNED 1 27 | 28 | #define __ASHMEMIOC 0x77 29 | 30 | #define ASHMEM_SET_NAME _IOW(__ASHMEMIOC, 1, char[ASHMEM_NAME_LEN]) 31 | #define ASHMEM_GET_NAME _IOR(__ASHMEMIOC, 2, char[ASHMEM_NAME_LEN]) 32 | #define ASHMEM_SET_SIZE _IOW(__ASHMEMIOC, 3, size_t) 33 | #define ASHMEM_GET_SIZE _IO(__ASHMEMIOC, 4) 34 | #define ASHMEM_SET_PROT_MASK _IOW(__ASHMEMIOC, 5, unsigned long) 35 | #define ASHMEM_GET_PROT_MASK _IO(__ASHMEMIOC, 6) 36 | #define ASHMEM_PIN _IO(__ASHMEMIOC, 7) 37 | #define ASHMEM_UNPIN _IO(__ASHMEMIOC, 8) 38 | #define ASHMEM_ISPINNED _IO(__ASHMEMIOC, 9) 39 | #define ASHMEM_PURGE_ALL_CACHES _IO(__ASHMEMIOC, 10) 40 | 41 | #endif /* _UTILS_ASHMEM_H */ 42 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/Compat.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIB_UTILS_COMPAT_H 2 | #define __LIB_UTILS_COMPAT_H 3 | 4 | #include 5 | 6 | /* Compatibility definitions for non-Linux (i.e., BSD-based) hosts. */ 7 | #ifndef HAVE_OFF64_T 8 | #if _FILE_OFFSET_BITS < 64 9 | #error "_FILE_OFFSET_BITS < 64; large files are not supported on this platform" 10 | #endif /* _FILE_OFFSET_BITS < 64 */ 11 | 12 | typedef loff_t off64_t; 13 | 14 | inline off64_t lseek64(int fd, off64_t offset, int whence) { 15 | return lseek(fd, offset, whence); 16 | } 17 | 18 | #ifdef HAVE_PREAD 19 | inline ssize_t pread64(int fd, void *buf, size_t nbytes, off64_t offset) { 20 | return pread(fd, buf, nbytes, offset); 21 | } 22 | #endif 23 | 24 | #endif /* !HAVE_OFF64_T */ 25 | 26 | #if HAVE_PRINTF_ZD 27 | # define ZD "%zd" 28 | # define ZD_TYPE ssize_t 29 | #else 30 | # define ZD "%ld" 31 | # define ZD_TYPE long 32 | #endif 33 | 34 | /* 35 | * TEMP_FAILURE_RETRY is defined by some, but not all, versions of 36 | * . (Alas, it is not as standard as we'd hoped!) So, if it's 37 | * not already defined, then define it here. 38 | */ 39 | #ifndef TEMP_FAILURE_RETRY 40 | /* Used to retry syscalls that can return EINTR. */ 41 | #define TEMP_FAILURE_RETRY(exp) ({ \ 42 | typeof (exp) _rc; \ 43 | do { \ 44 | _rc = (exp); \ 45 | } while (_rc == -1 && errno == EINTR); \ 46 | _rc; }) 47 | #endif 48 | 49 | #endif /* __LIB_UTILS_COMPAT_H */ 50 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/ZipAlign.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace android; 6 | 7 | extern "C" 8 | JNIEXPORT jboolean 9 | JNICALL Java_io_github_muntashirakon_zipalign_ZipAlign_doZipAlign 10 | (JNIEnv *env, jclass clazz, jstring inZipFile, jstring outZipFile, jint alignment, jboolean pageAlignSharedLibs, jboolean force) { 11 | const char *inFileName = env->GetStringUTFChars(inZipFile, nullptr); 12 | if (!inFileName) { 13 | return JNI_FALSE; 14 | } 15 | const char *outFileName = env->GetStringUTFChars(outZipFile, nullptr); 16 | if(!outFileName) { 17 | env->ReleaseStringUTFChars(inZipFile, inFileName); 18 | return JNI_FALSE; 19 | } 20 | bool aligned = process(inFileName, outFileName, alignment, pageAlignSharedLibs, force) == 0; 21 | env->ReleaseStringUTFChars(inZipFile, inFileName); 22 | env->ReleaseStringUTFChars(outZipFile, outFileName); 23 | return aligned ? JNI_TRUE : JNI_FALSE; 24 | } 25 | 26 | extern "C" 27 | JNIEXPORT jboolean 28 | JNICALL Java_io_github_muntashirakon_zipalign_ZipAlign_isZipAligned 29 | (JNIEnv *env, jclass clazz, jstring zipFile, jint alignment, jboolean pageAlignSharedLibs) { 30 | const char *fileName = env->GetStringUTFChars(zipFile, nullptr); 31 | if(!fileName) { 32 | return JNI_FALSE; 33 | } 34 | bool verified = verify(fileName, alignment, pageAlignSharedLibs, false) == 0; 35 | env->ReleaseStringUTFChars(zipFile, fileName); 36 | return verified ? JNI_TRUE : JNI_FALSE; 37 | } 38 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/event_tag_map.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _LIBS_CUTILS_EVENTTAGMAP_H 18 | #define _LIBS_CUTILS_EVENTTAGMAP_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #define EVENT_TAG_MAP_FILE "/system/etc/event-log-tags" 25 | 26 | struct EventTagMap; 27 | typedef struct EventTagMap EventTagMap; 28 | 29 | /* 30 | * Open the specified file as an event log tag map. 31 | * 32 | * Returns NULL on failure. 33 | */ 34 | EventTagMap *android_openEventTagMap(const char *fileName); 35 | 36 | /* 37 | * Close the map. 38 | */ 39 | void android_closeEventTagMap(EventTagMap *map); 40 | 41 | /* 42 | * Look up a tag by index. Returns the tag string, or NULL if not found. 43 | */ 44 | const char *android_lookupEventTag(const EventTagMap *map, int tag); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /*_LIBS_CUTILS_EVENTTAGMAP_H*/ 51 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/jstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_STRING16_H 18 | #define __CUTILS_STRING16_H 19 | 20 | #include 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | typedef uint16_t char16_t; 28 | 29 | extern char *strndup16to8 (const char16_t *s, size_t n); 30 | extern size_t strnlen16to8 (const char16_t *s, size_t n); 31 | extern char *strncpy16to8 (char *dest, const char16_t *s, size_t n); 32 | 33 | extern char16_t *strdup8to16 (const char *s, size_t *out_len); 34 | extern size_t strlen8to16 (const char *utf8Str); 35 | extern char16_t *strcpy8to16 (char16_t *dest, const char *s, size_t *out_len); 36 | extern char16_t *strcpylen8to16 (char16_t *dest, const char *s, int length, 37 | size_t *out_len); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif /* __CUTILS_STRING16_H */ 44 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/compiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_CUTILS_COMPILER_H 18 | #define ANDROID_CUTILS_COMPILER_H 19 | 20 | /* 21 | * helps the compiler's optimizer predicting branches 22 | */ 23 | 24 | #ifdef __cplusplus 25 | # define CC_LIKELY( exp ) (__builtin_expect( !!(exp), true )) 26 | # define CC_UNLIKELY( exp ) (__builtin_expect( !!(exp), false )) 27 | #else 28 | # define CC_LIKELY( exp ) (__builtin_expect( !!(exp), 1 )) 29 | # define CC_UNLIKELY( exp ) (__builtin_expect( !!(exp), 0 )) 30 | #endif 31 | 32 | /** 33 | * exports marked symbols 34 | * 35 | * if used on a C++ class declaration, this macro must be inserted 36 | * after the "class" keyword. For instance: 37 | * 38 | * template 39 | * class ANDROID_API Singleton { } 40 | */ 41 | 42 | #define ANDROID_API __attribute__((visibility("default"))) 43 | 44 | #endif // ANDROID_CUTILS_COMPILER_H 45 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/logd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _ANDROID_CUTILS_LOGD_H 18 | #define _ANDROID_CUTILS_LOGD_H 19 | 20 | /* the stable/frozen log-related definitions have been 21 | * moved to this header, which is exposed by the NDK 22 | */ 23 | #include 24 | 25 | /* the rest is only used internally by the system */ 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #ifdef HAVE_PTHREADS 32 | #include 33 | #endif 34 | #include 35 | #include 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | int __android_log_bwrite(int32_t tag, const void *payload, size_t len); 42 | int __android_log_btwrite(int32_t tag, char type, const void *payload, 43 | size_t len); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif /* _LOGD_H */ 50 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 3 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 17 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/misc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_MISC_H 18 | #define __CUTILS_MISC_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /* Load an entire file into a malloc'd chunk of memory 25 | * that is length_of_file + 1 (null terminator). If 26 | * sz is non-zero, return the size of the file via sz. 27 | * Returns 0 on failure. 28 | */ 29 | extern void *load_file(const char *fn, unsigned *sz); 30 | 31 | /* Connects your process to the system debugger daemon 32 | * so that on a crash it may be logged or interactively 33 | * debugged (depending on system settings). 34 | */ 35 | extern void debuggerd_connect(void); 36 | 37 | 38 | /* This is the range of UIDs (and GIDs) that are reserved 39 | * for assigning to applications. 40 | */ 41 | #define FIRST_APPLICATION_UID 10000 42 | #define LAST_APPLICATION_UID 99999 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif /* __CUTILS_MISC_H */ 49 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/logger.h: -------------------------------------------------------------------------------- 1 | /* utils/logger.h 2 | ** 3 | ** Copyright 2007, The Android Open Source Project 4 | ** 5 | ** This file is dual licensed. It may be redistributed and/or modified 6 | ** under the terms of the Apache 2.0 License OR version 2 of the GNU 7 | ** General Public License. 8 | */ 9 | 10 | #ifndef _UTILS_LOGGER_H 11 | #define _UTILS_LOGGER_H 12 | 13 | #include 14 | 15 | struct logger_entry { 16 | uint16_t len; /* length of the payload */ 17 | uint16_t __pad; /* no matter what, we get 2 bytes of padding */ 18 | int32_t pid; /* generating process's pid */ 19 | int32_t tid; /* generating process's tid */ 20 | int32_t sec; /* seconds since Epoch */ 21 | int32_t nsec; /* nanoseconds */ 22 | char msg[0]; /* the entry's payload */ 23 | }; 24 | 25 | #define LOGGER_LOG_MAIN "log/main" 26 | #define LOGGER_LOG_RADIO "log/radio" 27 | #define LOGGER_LOG_EVENTS "log/events" 28 | #define LOGGER_LOG_SYSTEM "log/system" 29 | 30 | #define LOGGER_ENTRY_MAX_LEN (4*1024) 31 | #define LOGGER_ENTRY_MAX_PAYLOAD \ 32 | (LOGGER_ENTRY_MAX_LEN - sizeof(struct logger_entry)) 33 | 34 | #ifdef HAVE_IOCTL 35 | 36 | #include 37 | 38 | #define __LOGGERIO 0xAE 39 | 40 | #define LOGGER_GET_LOG_BUF_SIZE _IO(__LOGGERIO, 1) /* size of log */ 41 | #define LOGGER_GET_LOG_LEN _IO(__LOGGERIO, 2) /* used log len */ 42 | #define LOGGER_GET_NEXT_ENTRY_LEN _IO(__LOGGERIO, 3) /* next entry len */ 43 | #define LOGGER_FLUSH_LOG _IO(__LOGGERIO, 4) /* flush log */ 44 | 45 | #endif // HAVE_IOCTL 46 | 47 | #endif /* _UTILS_LOGGER_H */ 48 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/base/include/androidfw/misc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | 19 | // 20 | // Handy utility functions and portability code. 21 | // 22 | #ifndef _LIBS_ANDROID_FW_MISC_H 23 | #define _LIBS_ANDROID_FW_MISC_H 24 | 25 | namespace android { 26 | 27 | /* 28 | * Some utility functions for working with files. These could be made 29 | * part of a "File" class. 30 | */ 31 | typedef enum FileType { 32 | kFileTypeUnknown = 0, 33 | kFileTypeNonexistent, // i.e. ENOENT 34 | kFileTypeRegular, 35 | kFileTypeDirectory, 36 | kFileTypeCharDev, 37 | kFileTypeBlockDev, 38 | kFileTypeFifo, 39 | kFileTypeSymlink, 40 | kFileTypeSocket, 41 | } FileType; 42 | /* get the file's type; follows symlinks */ 43 | FileType getFileType(const char *fileName); 44 | /* get the file's modification date; returns -1 w/errno set on failure */ 45 | time_t getFileModDate(const char *fileName); 46 | 47 | }; // namespace android 48 | 49 | #endif // _LIBS_ANDROID_FW_MISC_H 50 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CUTILS_LIST_H_ 18 | #define _CUTILS_LIST_H_ 19 | 20 | #include 21 | 22 | struct listnode { 23 | struct listnode *next; 24 | struct listnode *prev; 25 | }; 26 | 27 | #define node_to_item(node, container, member) \ 28 | (container *) (((char*) (node)) - offsetof(container, member)) 29 | 30 | #define list_declare(name) \ 31 | struct listnode name = { \ 32 | .next = &name, \ 33 | .prev = &name, \ 34 | } 35 | 36 | #define list_for_each(node, list) \ 37 | for (node = (list)->next; node != (list); node = node->next) 38 | 39 | #define list_for_each_reverse(node, list) \ 40 | for (node = (list)->prev; node != (list); node = node->prev) 41 | 42 | void list_init(struct listnode *list); 43 | void list_add_tail(struct listnode *list, struct listnode *item); 44 | void list_remove(struct listnode *item); 45 | 46 | #define list_empty(list) ((list) == (list)->next) 47 | #define list_head(list) ((list)->next) 48 | #define list_tail(list) ((list)->prev) 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /zipalign/src/main/java/io/github/muntashirakon/zipalign/ZipAlign.java: -------------------------------------------------------------------------------- 1 | package io.github.muntashirakon.zipalign; 2 | 3 | public class ZipAlign { 4 | static { 5 | System.loadLibrary("zipalign"); 6 | } 7 | 8 | /** 9 | * Generate a new, aligned, zip "output" from an "input" zip. 10 | *

11 | * NOTE: If the APK is to be signed with schema v2 or later, the APK must be aligned before 12 | * signing it, and for v1 schema (AKA jar signing), the APK must be aligned after signing it. 13 | * 14 | * @param inZipFile The zip file to be aligned. 15 | * @param outZipFile File where the aligned zip file will be saved. 16 | * @param alignment Alignment (in bytes) for uncompressed entries. 17 | * @param pageAlignSharedLibs Align .so files to 4096 and other files to {@code alignment}, or all files to {@code alignment} if false 18 | * @param force Overwrite output if it exists, fail otherwise. 19 | * @return {@code true} on success. 20 | */ 21 | public static native boolean doZipAlign(String inZipFile, String outZipFile, int alignment, boolean pageAlignSharedLibs, boolean force); 22 | 23 | /** 24 | * Verify the alignment of a zip archive. 25 | * 26 | * @param zipFie The zip file whose alignment has to be verified 27 | * @param alignment Alignment (in bytes) for uncompressed entries. 28 | * @param pageAlignSharedLibs Align .so files to 4096 and other files to {@code alignment}, or all files to {@code alignment} if false 29 | * @return {@code true} on success. 30 | */ 31 | public static native boolean isZipAligned(String zipFie, int alignment, boolean pageAlignSharedLibs); 32 | } 33 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/tztime.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CUTILS_TZTIME_H 18 | #define _CUTILS_TZTIME_H 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | time_t mktime_tz(struct tm *const tmp, char const *tz); 27 | void localtime_tz(const time_t *const timep, struct tm *tmp, const char *tz); 28 | 29 | #ifndef HAVE_ANDROID_OS 30 | /* the following is defined in in Bionic */ 31 | 32 | struct strftime_locale { 33 | const char *mon[12]; /* short names */ 34 | const char *month[12]; /* long names */ 35 | const char *standalone_month[12]; /* long standalone names */ 36 | const char *wday[7]; /* short names */ 37 | const char *weekday[7]; /* long names */ 38 | const char *X_fmt; 39 | const char *x_fmt; 40 | const char *c_fmt; 41 | const char *am; 42 | const char *pm; 43 | const char *date_fmt; 44 | }; 45 | 46 | size_t strftime_tz(char *s, size_t max, const char *format, const struct tm *tm, const struct strftime_locale *locale); 47 | 48 | #endif /* !HAVE_ANDROID_OS */ 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* __CUTILS_TZTIME_H */ 55 | 56 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/zipalign/include/zipalign/ZipAlign.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __LIBS_ZIPALIGN_H 18 | #define __LIBS_ZIPALIGN_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif // __cplusplus 23 | 24 | namespace android { 25 | 26 | /* 27 | * Generate a new, aligned, zip "output" from an "input" zip. 28 | * - alignTo: Alignment (in bytes) for uncompressed entries. 29 | * - pageAlignSharedLibs: Align .so files to 4096 and other files to 30 | * alignTo, or all files to alignTo if false. 31 | * - force : Overwrite output if it exists, fail otherwise. 32 | * 33 | * Returns 0 on success. 34 | */ 35 | int process(const char* input, const char* output, int alignTo, bool pageAlignSharedLibs, bool force); 36 | 37 | /* 38 | * Verify the alignment of a zip archive. 39 | * - alignTo: Alignment (in bytes) for uncompressed entries. 40 | * - pageAlignSharedLibs: Align .so files to 4096 and other files to 41 | * alignTo, or all files to alignTo if false. 42 | * 43 | * Returns 0 on success. 44 | */ 45 | int verify(const char* fileName, int alignTo, bool pageAlignSharedLibs, bool verbose); 46 | 47 | }; // namespace android 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif // __cplusplus 52 | 53 | #endif // __LIBS_ZIPALIGN_H 54 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/StopWatch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_STOPWATCH_H 18 | #define ANDROID_STOPWATCH_H 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | // --------------------------------------------------------------------------- 26 | 27 | namespace android { 28 | 29 | class StopWatch { 30 | public: 31 | StopWatch( const char *name, 32 | int clock = SYSTEM_TIME_MONOTONIC, 33 | uint32_t flags = 0); 34 | ~StopWatch(); 35 | 36 | const char *name() const; 37 | nsecs_t lap(); 38 | nsecs_t elapsedTime() const; 39 | 40 | void reset(); 41 | 42 | private: 43 | const char *mName; 44 | int mClock; 45 | uint32_t mFlags; 46 | 47 | struct lap_t { 48 | nsecs_t soFar; 49 | nsecs_t thisLap; 50 | }; 51 | 52 | nsecs_t mStartTime; 53 | lap_t mLaps[8]; 54 | int mNumLaps; 55 | }; 56 | 57 | 58 | }; // namespace android 59 | 60 | 61 | // --------------------------------------------------------------------------- 62 | 63 | #endif // ANDROID_STOPWATCH_H 64 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/str_parms.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_STR_PARMS_H 18 | #define __CUTILS_STR_PARMS_H 19 | 20 | #include 21 | 22 | struct str_parms; 23 | 24 | struct str_parms *str_parms_create(void); 25 | struct str_parms *str_parms_create_str(const char *_string); 26 | void str_parms_destroy(struct str_parms *str_parms); 27 | 28 | void str_parms_del(struct str_parms *str_parms, const char *key); 29 | 30 | int str_parms_add_str(struct str_parms *str_parms, const char *key, 31 | const char *value); 32 | int str_parms_add_int(struct str_parms *str_parms, const char *key, int value); 33 | 34 | int str_parms_add_float(struct str_parms *str_parms, const char *key, 35 | float value); 36 | 37 | int str_parms_get_str(struct str_parms *str_parms, const char *key, 38 | char *out_val, int len); 39 | int str_parms_get_int(struct str_parms *str_parms, const char *key, 40 | int *out_val); 41 | int str_parms_get_float(struct str_parms *str_parms, const char *key, 42 | float *out_val); 43 | 44 | char *str_parms_to_str(struct str_parms *str_parms); 45 | 46 | /* debug */ 47 | void str_parms_dump(struct str_parms *str_parms); 48 | 49 | #endif /* __CUTILS_STR_PARMS_H */ 50 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/ZipFileCRO.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // 18 | // C API for ead-only access to Zip archives, with minimal heap allocation. 19 | // 20 | #ifndef __LIBS_ZIPFILECRO_H 21 | #define __LIBS_ZIPFILECRO_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | /* 34 | * Trivial typedef to ensure that ZipFileCRO is not treated as a simple integer. 35 | */ 36 | typedef void *ZipFileCRO; 37 | 38 | /* 39 | * Trivial typedef to ensure that ZipEntryCRO is not treated as a simple 40 | * integer. We use NULL to indicate an invalid value. 41 | */ 42 | typedef void *ZipEntryCRO; 43 | 44 | extern ZipFileCRO ZipFileXRO_open(const char *path); 45 | 46 | extern void ZipFileCRO_destroy(ZipFileCRO zip); 47 | 48 | extern ZipEntryCRO ZipFileCRO_findEntryByName(ZipFileCRO zip, 49 | const char *fileName); 50 | 51 | extern bool ZipFileCRO_getEntryInfo(ZipFileCRO zip, ZipEntryCRO entry, 52 | int *pMethod, size_t *pUncompLen, 53 | size_t *pCompLen, off64_t *pOffset, long *pModWhen, long *pCrc32); 54 | 55 | extern bool ZipFileCRO_uncompressEntry(ZipFileCRO zip, ZipEntryCRO entry, int fd); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /*__LIBS_ZIPFILECRO_H*/ 62 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/config_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_CONFIG_UTILS_H 18 | #define __CUTILS_CONFIG_UTILS_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | typedef struct cnode cnode; 25 | 26 | 27 | struct cnode { 28 | cnode *next; 29 | cnode *first_child; 30 | cnode *last_child; 31 | const char *name; 32 | const char *value; 33 | }; 34 | 35 | /* parse a text string into a config node tree */ 36 | void config_load(cnode *root, char *data); 37 | 38 | /* parse a file into a config node tree */ 39 | void config_load_file(cnode *root, const char *fn); 40 | 41 | /* create a single config node */ 42 | cnode *config_node(const char *name, const char *value); 43 | 44 | /* locate a named child of a config node */ 45 | cnode *config_find(cnode *root, const char *name); 46 | 47 | /* look up a child by name and return the boolean value */ 48 | int config_bool(cnode *root, const char *name, int _default); 49 | 50 | /* look up a child by name and return the string value */ 51 | const char *config_str(cnode *root, const char *name, const char *_default); 52 | 53 | /* add a named child to a config node (or modify it if it already exists) */ 54 | void config_set(cnode *root, const char *name, const char *value); 55 | 56 | /* free a config node tree */ 57 | void config_free(cnode *root); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/misc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // 18 | // Handy utility functions and portability code. 19 | // 20 | #ifndef _LIBS_UTILS_MISC_H 21 | #define _LIBS_UTILS_MISC_H 22 | 23 | #include 24 | #include 25 | 26 | /* get #of elements in a static array */ 27 | #ifndef NELEM 28 | # define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0]))) 29 | #endif 30 | 31 | namespace android { 32 | 33 | /* 34 | * Some utility functions for working with files. These could be made 35 | * part of a "File" class. 36 | */ 37 | typedef enum FileType { 38 | kFileTypeUnknown = 0, 39 | kFileTypeNonexistent, // i.e. ENOENT 40 | kFileTypeRegular, 41 | kFileTypeDirectory, 42 | kFileTypeCharDev, 43 | kFileTypeBlockDev, 44 | kFileTypeFifo, 45 | kFileTypeSymlink, 46 | kFileTypeSocket, 47 | } FileType; 48 | /* get the file's type; follows symlinks */ 49 | FileType getFileType(const char *fileName); 50 | /* get the file's modification date; returns -1 w/errno set on failure */ 51 | time_t getFileModDate(const char *fileName); 52 | 53 | typedef void (*sysprop_change_callback)(void); 54 | void add_sysprop_change_callback(sysprop_change_callback cb, int priority); 55 | void report_sysprop_change(); 56 | 57 | }; // namespace android 58 | 59 | #endif // _LIBS_UTILS_MISC_H 60 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/zipfile/zipfile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _ZIPFILE_ZIPFILE_H 18 | #define _ZIPFILE_ZIPFILE_H 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | typedef void *zipfile_t; 27 | typedef void *zipentry_t; 28 | 29 | // Provide a buffer. Returns NULL on failure. 30 | zipfile_t init_zipfile(const void *data, size_t size); 31 | 32 | // Release the zipfile resources. 33 | void release_zipfile(zipfile_t file); 34 | 35 | // Get a named entry object. Returns NULL if it doesn't exist 36 | // or if we won't be able to decompress it. The zipentry_t is 37 | // freed by release_zipfile() 38 | zipentry_t lookup_zipentry(zipfile_t file, const char *entryName); 39 | 40 | // Return the size of the entry. 41 | size_t get_zipentry_size(zipentry_t entry); 42 | 43 | // return the filename of this entry, you own the memory returned 44 | char *get_zipentry_name(zipentry_t entry); 45 | 46 | // The buffer must be 1.001 times the buffer size returned 47 | // by get_zipentry_size. Returns nonzero on failure. 48 | int decompress_zipentry(zipentry_t entry, void *buf, int bufsize); 49 | 50 | // iterate through the entries in the zip file. pass a pointer to 51 | // a void* initialized to NULL to start. Returns NULL when done 52 | zipentry_t iterate_zipfile(zipfile_t file, void **cookie); 53 | 54 | #ifdef __cplusplus 55 | } // extern "C" 56 | #endif 57 | 58 | #endif // _ZIPFILE_ZIPFILE_H 59 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/qtaguid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_QTAGUID_H 18 | #define __CUTILS_QTAGUID_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* 29 | * Set tags (and owning UIDs) for network sockets. 30 | */ 31 | extern int qtaguid_tagSocket(int sockfd, int tag, uid_t uid); 32 | 33 | /* 34 | * Untag a network socket before closing. 35 | */ 36 | extern int qtaguid_untagSocket(int sockfd); 37 | 38 | /* 39 | * For the given uid, switch counter sets. 40 | * The kernel only keeps a limited number of sets. 41 | * 2 for now. 42 | */ 43 | extern int qtaguid_setCounterSet(int counterSetNum, uid_t uid); 44 | 45 | /* 46 | * Delete all tag info that relates to the given tag an uid. 47 | * If the tag is 0, then ALL info about the uid is freeded. 48 | * The delete data also affects active tagged socketd, which are 49 | * then untagged. 50 | * The calling process can only operate on its own tags. 51 | * Unless it is part of the happy AID_NET_BW_ACCT group. 52 | * In which case it can clobber everything. 53 | */ 54 | extern int qtaguid_deleteTagData(int tag, uid_t uid); 55 | 56 | /* 57 | * Enable/disable qtaguid functionnality at a lower level. 58 | * When pacified, the kernel will accept commands but do nothing. 59 | */ 60 | extern int qtaguid_setPacifier(int on); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* __CUTILS_QTAG_UID_H */ 67 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/array.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * A pointer array which intelligently expands its capacity ad needed. 19 | */ 20 | 21 | #ifndef __ARRAY_H 22 | #define __ARRAY_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include 29 | 30 | /** An array. */ 31 | typedef struct Array Array; 32 | 33 | /** Constructs a new array. Returns NULL if we ran out of memory. */ 34 | Array *arrayCreate(); 35 | 36 | /** Frees an array. Does not free elements themselves. */ 37 | void arrayFree(Array *array); 38 | 39 | /** Adds a pointer. Returns 0 is successful, < 0 otherwise. */ 40 | int arrayAdd(Array *array, void *pointer); 41 | 42 | /** Gets the pointer at the specified index. */ 43 | void *arrayGet(Array *array, int index); 44 | 45 | /** Removes the pointer at the given index and returns it. */ 46 | void *arrayRemove(Array *array, int index); 47 | 48 | /** Sets pointer at the given index. Returns old pointer. */ 49 | void *arraySet(Array *array, int index, void *pointer); 50 | 51 | /** Sets the array size. Sets new pointers to NULL. Returns 0 if successful, < 0 otherwise . */ 52 | int arraySetSize(Array *array, int size); 53 | 54 | /** Returns the size of the given array. */ 55 | int arraySize(Array *array); 56 | 57 | /** 58 | * Returns a pointer to a C-style array which will be valid until this array 59 | * changes. 60 | */ 61 | const void **arrayUnwrap(Array *array); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif /* __ARRAY_H */ 68 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/native_handle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef NATIVE_HANDLE_H_ 18 | #define NATIVE_HANDLE_H_ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | typedef struct native_handle { 25 | int version; /* sizeof(native_handle_t) */ 26 | int numFds; /* number of file-descriptors at &data[0] */ 27 | int numInts; /* number of ints at &data[numFds] */ 28 | int data[0]; /* numFds + numInts ints */ 29 | } native_handle_t; 30 | 31 | /* 32 | * native_handle_close 33 | * 34 | * closes the file descriptors contained in this native_handle_t 35 | * 36 | * return 0 on success, or a negative error code on failure 37 | * 38 | */ 39 | int native_handle_close(const native_handle_t *h); 40 | 41 | 42 | /* 43 | * native_handle_create 44 | * 45 | * creates a native_handle_t and initializes it. must be destroyed with 46 | * native_handle_delete(). 47 | * 48 | */ 49 | native_handle_t *native_handle_create(int numFds, int numInts); 50 | 51 | /* 52 | * native_handle_delete 53 | * 54 | * frees a native_handle_t allocated with native_handle_create(). 55 | * This ONLY frees the memory allocated for the native_handle_t, but doesn't 56 | * close the file descriptors; which can be achieved with native_handle_close(). 57 | * 58 | * return 0 on success, or a negative error code on failure 59 | * 60 | */ 61 | int native_handle_delete(native_handle_t *h); 62 | 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif /* NATIVE_HANDLE_H_ */ 69 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/BufferedTextOutput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_BUFFEREDTEXTOUTPUT_H 18 | #define ANDROID_BUFFEREDTEXTOUTPUT_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | // --------------------------------------------------------------------------- 25 | namespace android { 26 | 27 | class BufferedTextOutput : public TextOutput { 28 | public: 29 | //** Flags for constructor */ 30 | enum { 31 | MULTITHREADED = 0x0001 32 | }; 33 | 34 | BufferedTextOutput(uint32_t flags = 0); 35 | virtual ~BufferedTextOutput(); 36 | 37 | virtual status_t print(const char *txt, size_t len); 38 | virtual void moveIndent(int delta); 39 | 40 | virtual void pushBundle(); 41 | virtual void popBundle(); 42 | 43 | protected: 44 | virtual status_t writeLines(const struct iovec &vec, size_t N) = 0; 45 | 46 | private: 47 | struct BufferState; 48 | struct ThreadState; 49 | 50 | static ThreadState *getThreadState(); 51 | static void threadDestructor(void *st); 52 | 53 | BufferState *getBuffer() const; 54 | 55 | uint32_t mFlags; 56 | const int32_t mSeq; 57 | const int32_t mIndex; 58 | 59 | Mutex mLock; 60 | BufferState *mGlobalState; 61 | }; 62 | 63 | // --------------------------------------------------------------------------- 64 | }; // namespace android 65 | 66 | #endif // ANDROID_BUFFEREDTEXTOUTPUT_H 67 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/atomic-inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_CUTILS_ATOMIC_INLINE_H 18 | #define ANDROID_CUTILS_ATOMIC_INLINE_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /* 25 | * Inline declarations and macros for some special-purpose atomic 26 | * operations. These are intended for rare circumstances where a 27 | * memory barrier needs to be issued inline rather than as a function 28 | * call. 29 | * 30 | * Most code should not use these. 31 | * 32 | * Anything that does include this file must set ANDROID_SMP to either 33 | * 0 or 1, indicating compilation for UP or SMP, respectively. 34 | * 35 | * Macros defined in this header: 36 | * 37 | * void ANDROID_MEMBAR_FULL(void) 38 | * Full memory barrier. Provides a compiler reordering barrier, and 39 | * on SMP systems emits an appropriate instruction. 40 | */ 41 | 42 | #if !defined(ANDROID_SMP) 43 | # error "Must define ANDROID_SMP before including atomic-inline.h" 44 | #endif 45 | 46 | #if defined(__arm__) 47 | #include 48 | #elif defined(__i386__) || defined(__x86_64__) 49 | #include 50 | #elif defined(__sh__) 51 | /* implementation is in atomic-android-sh.c */ 52 | #else 53 | #error atomic operations are unsupported 54 | #endif 55 | 56 | #if ANDROID_SMP == 0 57 | #define ANDROID_MEMBAR_FULL android_compiler_barrier 58 | #else 59 | #define ANDROID_MEMBAR_FULL android_memory_barrier 60 | #endif 61 | 62 | #if ANDROID_SMP == 0 63 | #define ANDROID_MEMBAR_STORE android_compiler_barrier 64 | #else 65 | #define ANDROID_MEMBAR_STORE android_memory_store_barrier 66 | #endif 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif /* ANDROID_CUTILS_ATOMIC_INLINE_H */ 73 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/LinearTransform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _LIBS_UTILS_LINEAR_TRANSFORM_H 18 | #define _LIBS_UTILS_LINEAR_TRANSFORM_H 19 | 20 | #include 21 | 22 | namespace android { 23 | 24 | // LinearTransform defines a structure which hold the definition of a 25 | // transformation from single dimensional coordinate system A into coordinate 26 | // system B (and back again). Values in A and in B are 64 bit, the linear 27 | // scale factor is expressed as a rational number using two 32 bit values. 28 | // 29 | // Specifically, let 30 | // f(a) = b 31 | // F(b) = f^-1(b) = a 32 | // then 33 | // 34 | // f(a) = (((a - a_zero) * a_to_b_numer) / a_to_b_denom) + b_zero; 35 | // 36 | // and 37 | // 38 | // F(b) = (((b - b_zero) * a_to_b_denom) / a_to_b_numer) + a_zero; 39 | // 40 | struct LinearTransform { 41 | int64_t a_zero; 42 | int64_t b_zero; 43 | int32_t a_to_b_numer; 44 | uint32_t a_to_b_denom; 45 | 46 | // Transform from A->B 47 | // Returns true on success, or false in the case of a singularity or an 48 | // overflow. 49 | bool doForwardTransform(int64_t a_in, int64_t *b_out) const; 50 | 51 | // Transform from B->A 52 | // Returns true on success, or false in the case of a singularity or an 53 | // overflow. 54 | bool doReverseTransform(int64_t b_in, int64_t *a_out) const; 55 | 56 | // Helpers which will reduce the fraction N/D using Euclid's method. 57 | template static void reduce(T *N, T *D); 58 | static void reduce(int32_t *N, uint32_t *D); 59 | }; 60 | 61 | 62 | } 63 | 64 | #endif // _LIBS_UTILS_LINEAR_TRANSFORM_H 65 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/properties.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_PROPERTIES_H 18 | #define __CUTILS_PROPERTIES_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /* System properties are *small* name value pairs managed by the 25 | ** property service. If your data doesn't fit in the provided 26 | ** space it is not appropriate for a system property. 27 | ** 28 | ** WARNING: system/bionic/include/sys/system_properties.h also defines 29 | ** these, but with different names. (TODO: fix that) 30 | */ 31 | #define PROPERTY_KEY_MAX 32 32 | #define PROPERTY_VALUE_MAX 92 33 | 34 | /* property_get: returns the length of the value which will never be 35 | ** greater than PROPERTY_VALUE_MAX - 1 and will always be zero terminated. 36 | ** (the length does not include the terminating zero). 37 | ** 38 | ** If the property read fails or returns an empty value, the default 39 | ** value is used (if nonnull). 40 | */ 41 | int property_get(const char *key, char *value, const char *default_value); 42 | 43 | /* property_set: returns 0 on success, < 0 on failure 44 | */ 45 | int property_set(const char *key, const char *value); 46 | 47 | int property_list(void (*propfn)(const char *key, const char *value, void *cookie), void *cookie); 48 | 49 | 50 | #ifdef HAVE_SYSTEM_PROPERTY_SERVER 51 | /* 52 | * We have an external property server instead of built-in libc support. 53 | * Used by the simulator. 54 | */ 55 | #define SYSTEM_PROPERTY_PIPE_NAME "/tmp/android-sysprop" 56 | 57 | enum { 58 | kSystemPropertyUnknown = 0, 59 | kSystemPropertyGet, 60 | kSystemPropertySet, 61 | kSystemPropertyList 62 | }; 63 | #endif /*HAVE_SYSTEM_PROPERTY_SERVER*/ 64 | 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/CallStack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_CALLSTACK_H 18 | #define ANDROID_CALLSTACK_H 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | // --------------------------------------------------------------------------- 27 | 28 | namespace android { 29 | 30 | class CallStack { 31 | public: 32 | enum { 33 | MAX_DEPTH = 31 34 | }; 35 | 36 | CallStack(); 37 | CallStack(const CallStack &rhs); 38 | ~CallStack(); 39 | 40 | CallStack &operator = (const CallStack &rhs); 41 | 42 | bool operator == (const CallStack &rhs) const; 43 | bool operator != (const CallStack &rhs) const; 44 | bool operator < (const CallStack &rhs) const; 45 | bool operator >= (const CallStack &rhs) const; 46 | bool operator > (const CallStack &rhs) const; 47 | bool operator <= (const CallStack &rhs) const; 48 | 49 | const void *operator [] (int index) const; 50 | 51 | void clear(); 52 | 53 | void update(int32_t ignoreDepth = 1, int32_t maxDepth = MAX_DEPTH); 54 | 55 | // Dump a stack trace to the log 56 | void dump(const char *prefix = 0) const; 57 | 58 | // Return a string (possibly very long) containing the complete stack trace 59 | String8 toString(const char *prefix = 0) const; 60 | 61 | size_t size() const { 62 | return mCount; 63 | } 64 | 65 | private: 66 | size_t mCount; 67 | backtrace_frame_t mStack[MAX_DEPTH]; 68 | }; 69 | 70 | }; // namespace android 71 | 72 | 73 | // --------------------------------------------------------------------------- 74 | 75 | #endif // ANDROID_CALLSTACK_H 76 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/StringArray.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // 18 | // Sortable array of strings. STL-ish, but STL-free. 19 | // 20 | #ifndef _LIBS_UTILS_STRING_ARRAY_H 21 | #define _LIBS_UTILS_STRING_ARRAY_H 22 | 23 | #include 24 | #include 25 | 26 | namespace android { 27 | 28 | // 29 | // An expanding array of strings. Add, get, sort, delete. 30 | // 31 | class StringArray { 32 | public: 33 | StringArray(); 34 | virtual ~StringArray(); 35 | 36 | // 37 | // Add a string. A copy of the string is made. 38 | // 39 | bool push_back(const char *str); 40 | 41 | // 42 | // Delete an entry. 43 | // 44 | void erase(int idx); 45 | 46 | // 47 | // Sort the array. 48 | // 49 | void sort(int (*compare)(const void *, const void *)); 50 | 51 | // 52 | // Pass this to the sort routine to do an ascending alphabetical sort. 53 | // 54 | static int cmpAscendingAlpha(const void *pstr1, const void *pstr2); 55 | 56 | // 57 | // Get the #of items in the array. 58 | // 59 | inline int size(void) const { 60 | return mCurrent; 61 | } 62 | 63 | // 64 | // Return entry N. 65 | // [should use operator[] here] 66 | // 67 | const char *getEntry(int idx) const { 68 | return (unsigned(idx) >= unsigned(mCurrent)) ? NULL : mArray[idx]; 69 | } 70 | 71 | // 72 | // Set entry N to specified string. 73 | // [should use operator[] here] 74 | // 75 | void setEntry(int idx, const char *str); 76 | 77 | private: 78 | int mMax; 79 | int mCurrent; 80 | char **mArray; 81 | }; 82 | 83 | }; // namespace android 84 | 85 | #endif // _LIBS_UTILS_STRING_ARRAY_H 86 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/ByteOrder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // 18 | 19 | #ifndef _LIBS_UTILS_BYTE_ORDER_H 20 | #define _LIBS_UTILS_BYTE_ORDER_H 21 | 22 | #include 23 | #include 24 | #ifdef HAVE_WINSOCK 25 | #include 26 | #else 27 | #include 28 | #endif 29 | 30 | /* 31 | * These macros are like the hton/ntoh byte swapping macros, 32 | * except they allow you to swap to and from the "device" byte 33 | * order. The device byte order is the endianness of the target 34 | * device -- for the ARM CPUs we use today, this is little endian. 35 | * 36 | * Note that the byte swapping functions have not been optimized 37 | * much; performance is currently not an issue for them since the 38 | * intent is to allow us to avoid byte swapping on the device. 39 | */ 40 | 41 | static inline uint32_t android_swap_long(uint32_t v) { 42 | return (v << 24) | ((v << 8) & 0x00FF0000) | ((v >> 8) & 0x0000FF00) | (v >> 24); 43 | } 44 | 45 | static inline uint16_t android_swap_short(uint16_t v) { 46 | return (v << 8) | (v >> 8); 47 | } 48 | 49 | #define DEVICE_BYTE_ORDER LITTLE_ENDIAN 50 | 51 | #if BYTE_ORDER == DEVICE_BYTE_ORDER 52 | 53 | #define dtohl(x) (x) 54 | #define dtohs(x) (x) 55 | #define htodl(x) (x) 56 | #define htods(x) (x) 57 | 58 | #else 59 | 60 | #define dtohl(x) (android_swap_long(x)) 61 | #define dtohs(x) (android_swap_short(x)) 62 | #define htodl(x) (android_swap_long(x)) 63 | #define htods(x) (android_swap_short(x)) 64 | 65 | #endif 66 | 67 | #if BYTE_ORDER == LITTLE_ENDIAN 68 | #define fromlel(x) (x) 69 | #define fromles(x) (x) 70 | #define tolel(x) (x) 71 | #define toles(x) (x) 72 | #else 73 | #define fromlel(x) (android_swap_long(x)) 74 | #define fromles(x) (android_swap_short(x)) 75 | #define tolel(x) (android_swap_long(x)) 76 | #define toles(x) (android_swap_short(x)) 77 | #endif 78 | 79 | #endif // _LIBS_UTILS_BYTE_ORDER_H 80 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/Log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // 18 | // C/C++ logging functions. See the logging documentation for API details. 19 | // 20 | // We'd like these to be available from C code (in case we import some from 21 | // somewhere), so this has a C interface. 22 | // 23 | // The output will be correct when the log file is shared between multiple 24 | // threads and/or multiple processes so long as the operating system 25 | // supports O_APPEND. These calls have mutex-protected data structures 26 | // and so are NOT reentrant. Do not use LOG in a signal handler. 27 | // 28 | #ifndef _LIBS_UTILS_LOG_H 29 | #define _LIBS_UTILS_LOG_H 30 | 31 | #include 32 | #include 33 | 34 | #ifdef __cplusplus 35 | 36 | namespace android { 37 | 38 | /* 39 | * A very simple utility that yells in the log when an operation takes too long. 40 | */ 41 | class LogIfSlow { 42 | public: 43 | LogIfSlow(const char *tag, android_LogPriority priority, 44 | int timeoutMillis, const char *message); 45 | ~LogIfSlow(); 46 | 47 | private: 48 | const char *const mTag; 49 | const android_LogPriority mPriority; 50 | const int mTimeoutMillis; 51 | const char *const mMessage; 52 | const int64_t mStart; 53 | }; 54 | 55 | /* 56 | * Writes the specified debug log message if this block takes longer than the 57 | * specified number of milliseconds to run. Includes the time actually taken. 58 | * 59 | * { 60 | * ALOGD_IF_SLOW(50, "Excessive delay doing something."); 61 | * doSomething(); 62 | * } 63 | */ 64 | #define ALOGD_IF_SLOW(timeoutMillis, message) \ 65 | LogIfSlow _logIfSlow(LOG_TAG, ANDROID_LOG_DEBUG, timeoutMillis, message); 66 | 67 | } // namespace android 68 | 69 | #endif // __cplusplus 70 | 71 | #endif // _LIBS_UTILS_LOG_H 72 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/ZipUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // 18 | // Miscellaneous zip/gzip utility functions. 19 | // 20 | #ifndef __LIBS_ZIPUTILS_H 21 | #define __LIBS_ZIPUTILS_H 22 | 23 | #include 24 | 25 | namespace android { 26 | 27 | /* 28 | * Container class for utility functions, primarily for namespace reasons. 29 | */ 30 | class ZipUtils { 31 | public: 32 | /* 33 | * General utility function for uncompressing "deflate" data from a file 34 | * to a buffer. 35 | */ 36 | static bool inflateToBuffer(int fd, void *buf, long uncompressedLen, 37 | long compressedLen); 38 | static bool inflateToBuffer(FILE *fp, void *buf, long uncompressedLen, 39 | long compressedLen); 40 | 41 | /* 42 | * Someday we might want to make this generic and handle bzip2 ".bz2" 43 | * files too. 44 | * 45 | * We could declare gzip to be a sub-class of zip that has exactly 46 | * one always-compressed entry, but we currently want to treat Zip 47 | * and gzip as distinct, so there's no value. 48 | * 49 | * The zlib library has some gzip utilities, but it has no interface 50 | * for extracting the uncompressed length of the file (you do *not* 51 | * want to gzseek to the end). 52 | * 53 | * Pass in a seeked file pointer for the gzip file. If this is a gzip 54 | * file, we set our return values appropriately and return "true" with 55 | * the file seeked to the start of the compressed data. 56 | */ 57 | static bool examineGzip(FILE *fp, int *pCompressionMethod, 58 | long *pUncompressedLen, long *pCompressedLen, unsigned long *pCRC32); 59 | 60 | private: 61 | ZipUtils() {} 62 | ~ZipUtils() {} 63 | }; 64 | 65 | }; // namespace android 66 | 67 | #endif /*__LIBS_ZIPUTILS_H*/ 68 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/base/include/androidfw/ZipUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // 18 | // Miscellaneous zip/gzip utility functions. 19 | // 20 | #ifndef __LIBS_ZIPUTILS_H 21 | #define __LIBS_ZIPUTILS_H 22 | 23 | #include 24 | 25 | namespace android { 26 | 27 | /* 28 | * Container class for utility functions, primarily for namespace reasons. 29 | */ 30 | class ZipUtils { 31 | public: 32 | /* 33 | * General utility function for uncompressing "deflate" data from a file 34 | * to a buffer. 35 | */ 36 | static bool inflateToBuffer(int fd, void *buf, long uncompressedLen, 37 | long compressedLen); 38 | static bool inflateToBuffer(FILE *fp, void *buf, long uncompressedLen, 39 | long compressedLen); 40 | 41 | /* 42 | * Someday we might want to make this generic and handle bzip2 ".bz2" 43 | * files too. 44 | * 45 | * We could declare gzip to be a sub-class of zip that has exactly 46 | * one always-compressed entry, but we currently want to treat Zip 47 | * and gzip as distinct, so there's no value. 48 | * 49 | * The zlib library has some gzip utilities, but it has no interface 50 | * for extracting the uncompressed length of the file (you do *not* 51 | * want to gzseek to the end). 52 | * 53 | * Pass in a seeked file pointer for the gzip file. If this is a gzip 54 | * file, we set our return values appropriately and return "true" with 55 | * the file seeked to the start of the compressed data. 56 | */ 57 | static bool examineGzip(FILE *fp, int *pCompressionMethod, 58 | long *pUncompressedLen, long *pCompressedLen, unsigned long *pCRC32); 59 | 60 | private: 61 | ZipUtils() {} 62 | ~ZipUtils() {} 63 | }; 64 | 65 | }; // namespace android 66 | 67 | #endif /*__LIBS_ZIPUTILS_H*/ 68 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/Debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_DEBUG_H 18 | #define ANDROID_DEBUG_H 19 | 20 | #include 21 | #include 22 | 23 | namespace android { 24 | // --------------------------------------------------------------------------- 25 | 26 | #ifdef __cplusplus 27 | template struct CompileTimeAssert; 28 | template<> struct CompileTimeAssert {}; 29 | #define COMPILE_TIME_ASSERT(_exp) \ 30 | template class CompileTimeAssert< (_exp) >; 31 | #endif 32 | #define COMPILE_TIME_ASSERT_FUNCTION_SCOPE(_exp) \ 33 | CompileTimeAssert<( _exp )>(); 34 | 35 | // --------------------------------------------------------------------------- 36 | 37 | #ifdef __cplusplus 38 | template struct CompileTimeIfElse; 39 | template 40 | struct CompileTimeIfElse { 41 | typedef LHS TYPE; 42 | }; 43 | template 44 | struct CompileTimeIfElse { 45 | typedef RHS TYPE; 46 | }; 47 | #endif 48 | 49 | // --------------------------------------------------------------------------- 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | const char *stringForIndent(int32_t indentLevel); 56 | 57 | typedef void (*debugPrintFunc)(void *cookie, const char *txt); 58 | 59 | void printTypeCode(uint32_t typeCode, 60 | debugPrintFunc func = 0, void *cookie = 0); 61 | 62 | void printHexData(int32_t indent, const void *buf, size_t length, 63 | size_t bytesPerLine = 16, int32_t singleLineBytesCutoff = 16, 64 | size_t alignment = 0, bool cArrayStyle = false, 65 | debugPrintFunc func = 0, void *cookie = 0); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | // --------------------------------------------------------------------------- 72 | }; // namespace android 73 | 74 | #endif // ANDROID_DEBUG_H 75 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/Singleton.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_UTILS_SINGLETON_H 18 | #define ANDROID_UTILS_SINGLETON_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace android { 26 | // --------------------------------------------------------------------------- 27 | 28 | template 29 | class ANDROID_API Singleton { 30 | public: 31 | static TYPE &getInstance() { 32 | Mutex::Autolock _l(sLock); 33 | TYPE *instance = sInstance; 34 | if (instance == 0) { 35 | instance = new TYPE(); 36 | sInstance = instance; 37 | } 38 | return *instance; 39 | } 40 | 41 | static bool hasInstance() { 42 | Mutex::Autolock _l(sLock); 43 | return sInstance != 0; 44 | } 45 | 46 | protected: 47 | ~Singleton() { }; 48 | Singleton() { }; 49 | 50 | private: 51 | Singleton(const Singleton &); 52 | Singleton &operator = (const Singleton &); 53 | static Mutex sLock; 54 | static TYPE *sInstance; 55 | }; 56 | 57 | /* 58 | * use ANDROID_SINGLETON_STATIC_INSTANCE(TYPE) in your implementation file 59 | * (eg: .cpp) to create the static instance of Singleton<>'s attributes, 60 | * and avoid to have a copy of them in each compilation units Singleton 61 | * is used. 62 | * NOTE: we use a version of Mutex ctor that takes a parameter, because 63 | * for some unknown reason using the default ctor doesn't emit the variable! 64 | */ 65 | 66 | #define ANDROID_SINGLETON_STATIC_INSTANCE(TYPE) \ 67 | template<> Mutex Singleton< TYPE >::sLock(Mutex::PRIVATE); \ 68 | template<> TYPE* Singleton< TYPE >::sInstance(0); \ 69 | template class Singleton< TYPE >; 70 | 71 | 72 | // --------------------------------------------------------------------------- 73 | }; // namespace android 74 | 75 | #endif // ANDROID_UTILS_SINGLETON_H 76 | 77 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/src/utils/SharedBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | //#include 6 | 7 | // --------------------------------------------------------------------------- 8 | 9 | namespace android { 10 | 11 | SharedBuffer *SharedBuffer::alloc(size_t size) { 12 | SharedBuffer *sb = static_cast(malloc(sizeof(SharedBuffer) + size)); 13 | if (sb) { 14 | sb->mRefs = 1; 15 | sb->mSize = size; 16 | } 17 | return sb; 18 | } 19 | 20 | 21 | ssize_t SharedBuffer::dealloc(const SharedBuffer *released) { 22 | if (released->mRefs != 0) return -1; // XXX: invalid operation 23 | free(const_cast(released)); 24 | return 0; 25 | } 26 | 27 | SharedBuffer *SharedBuffer::edit() const { 28 | if (onlyOwner()) { 29 | return const_cast(this); 30 | } 31 | SharedBuffer *sb = alloc(mSize); 32 | if (sb) { 33 | memcpy(sb->data(), data(), size()); 34 | release(); 35 | } 36 | return sb; 37 | } 38 | 39 | SharedBuffer *SharedBuffer::editResize(size_t newSize) const { 40 | if (onlyOwner()) { 41 | SharedBuffer *buf = const_cast(this); 42 | if (buf->mSize == newSize) return buf; 43 | buf = (SharedBuffer *)realloc(buf, sizeof(SharedBuffer) + newSize); 44 | if (buf != nullptr) { 45 | buf->mSize = newSize; 46 | return buf; 47 | } 48 | } 49 | SharedBuffer *sb = alloc(newSize); 50 | if (sb) { 51 | const size_t mySize = mSize; 52 | memcpy(sb->data(), data(), newSize < mySize ? newSize : mySize); 53 | release(); 54 | } 55 | return sb; 56 | } 57 | 58 | SharedBuffer *SharedBuffer::attemptEdit() const { 59 | if (onlyOwner()) { 60 | return const_cast(this); 61 | } 62 | return 0; 63 | } 64 | 65 | SharedBuffer *SharedBuffer::reset(size_t new_size) const { 66 | // cheap-o-reset. 67 | SharedBuffer *sb = alloc(new_size); 68 | if (sb) { 69 | release(); 70 | } 71 | return sb; 72 | } 73 | 74 | void SharedBuffer::acquire() const { 75 | //android_atomic_inc(&mRefs); 76 | } 77 | 78 | int32_t SharedBuffer::release(uint32_t flags) const { 79 | int32_t prev = 1; 80 | if (onlyOwner() /*|| ((prev = android_atomic_dec(&mRefs)) == 1)*/) { 81 | mRefs = 0; 82 | if ((flags & eKeepStorage) == 0) { 83 | free(const_cast(this)); 84 | } 85 | } 86 | return prev; 87 | } 88 | 89 | 90 | }; // namespace android -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/Errors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_ERRORS_H 18 | #define ANDROID_ERRORS_H 19 | 20 | #include 21 | #include 22 | 23 | namespace android { 24 | 25 | // use this type to return error codes 26 | #ifdef HAVE_MS_C_RUNTIME 27 | typedef int status_t; 28 | #else 29 | typedef int32_t status_t; 30 | #endif 31 | 32 | /* the MS C runtime lacks a few error codes */ 33 | 34 | /* 35 | * Error codes. 36 | * All error codes are negative values. 37 | */ 38 | 39 | // Win32 #defines NO_ERROR as well. It has the same value, so there's no 40 | // real conflict, though it's a bit awkward. 41 | #ifdef _WIN32 42 | # undef NO_ERROR 43 | #endif 44 | 45 | enum { 46 | OK = 0, // Everything's swell. 47 | NO_ERROR = 0, // No errors. 48 | 49 | UNKNOWN_ERROR = 0x80000000, 50 | 51 | NO_MEMORY = -ENOMEM, 52 | INVALID_OPERATION = -ENOSYS, 53 | BAD_VALUE = -EINVAL, 54 | BAD_TYPE = 0x80000001, 55 | NAME_NOT_FOUND = -ENOENT, 56 | PERMISSION_DENIED = -EPERM, 57 | NO_INIT = -ENODEV, 58 | ALREADY_EXISTS = -EEXIST, 59 | DEAD_OBJECT = -EPIPE, 60 | FAILED_TRANSACTION = 0x80000002, 61 | JPARKS_BROKE_IT = -EPIPE, 62 | #if !defined(HAVE_MS_C_RUNTIME) 63 | BAD_INDEX = -EOVERFLOW, 64 | NOT_ENOUGH_DATA = -ENODATA, 65 | WOULD_BLOCK = -EWOULDBLOCK, 66 | TIMED_OUT = -ETIMEDOUT, 67 | UNKNOWN_TRANSACTION = -EBADMSG, 68 | #else 69 | BAD_INDEX = -E2BIG, 70 | NOT_ENOUGH_DATA = 0x80000003, 71 | WOULD_BLOCK = 0x80000004, 72 | TIMED_OUT = 0x80000005, 73 | UNKNOWN_TRANSACTION = 0x80000006, 74 | #endif 75 | FDS_NOT_ALLOWED = 0x80000007, 76 | }; 77 | 78 | // Restore define; enumeration is in "android" namespace, so the value defined 79 | // there won't work for Win32 code in a different namespace. 80 | #ifdef _WIN32 81 | # define NO_ERROR 0L 82 | #endif 83 | 84 | }; // namespace android 85 | 86 | // --------------------------------------------------------------------------- 87 | 88 | #endif // ANDROID_ERRORS_H 89 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/base/include/androidfw/StreamingZipInflater.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __LIBS_STREAMINGZIPINFLATER_H 18 | #define __LIBS_STREAMINGZIPINFLATER_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | namespace android { 27 | 28 | class StreamingZipInflater { 29 | public: 30 | static const size_t INPUT_CHUNK_SIZE = 64 * 1024; 31 | static const size_t OUTPUT_CHUNK_SIZE = 64 * 1024; 32 | 33 | // Flavor that pages in the compressed data from a fd 34 | StreamingZipInflater(int fd, off64_t compDataStart, size_t uncompSize, size_t compSize); 35 | 36 | // Flavor that gets the compressed data from an in-memory buffer 37 | StreamingZipInflater(class FileMap *dataMap, size_t uncompSize); 38 | 39 | ~StreamingZipInflater(); 40 | 41 | // read 'count' bytes of uncompressed data from the current position. outBuf may 42 | // be NULL, in which case the data is consumed and discarded. 43 | ssize_t read(void *outBuf, size_t count); 44 | 45 | // seeking backwards requires uncompressing fom the beginning, so is very 46 | // expensive. seeking forwards only requires uncompressing from the current 47 | // position to the destination. 48 | off64_t seekAbsolute(off64_t absoluteInputPosition); 49 | 50 | private: 51 | void initInflateState(); 52 | int readNextChunk(); 53 | 54 | // where to find the uncompressed data 55 | int mFd; 56 | off64_t mInFileStart; // where the compressed data lives in the file 57 | class FileMap *mDataMap; 58 | 59 | z_stream mInflateState; 60 | bool mStreamNeedsInit; 61 | 62 | // output invariants for this asset 63 | uint8_t *mOutBuf; // output buf for decompressed bytes 64 | size_t mOutBufSize; // allocated size of mOutBuf 65 | size_t mOutTotalSize; // total uncompressed size of the blob 66 | 67 | // current output state bookkeeping 68 | off64_t mOutCurPosition; // current position in total offset 69 | size_t mOutLastDecoded; // last decoded byte + 1 in mOutbuf 70 | size_t mOutDeliverable; // next undelivered byte of decoded output in mOutBuf 71 | 72 | // input invariants 73 | uint8_t *mInBuf; 74 | size_t mInBufSize; // allocated size of mInBuf; 75 | size_t mInTotalSize; // total size of compressed data for this blob 76 | 77 | // input state bookkeeping 78 | size_t mInNextChunkOffset; // offset from start of blob at which the next input chunk lies 79 | // the z_stream contains state about input block consumption 80 | }; 81 | 82 | } 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/system/audio_policy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | #ifndef ANDROID_AUDIO_POLICY_CORE_H 19 | #define ANDROID_AUDIO_POLICY_CORE_H 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | __BEGIN_DECLS 28 | 29 | /* The enums were moved here mostly from 30 | * frameworks/base/include/media/AudioSystem.h 31 | */ 32 | 33 | /* request to open a direct output with get_output() (by opposition to 34 | * sharing an output with other AudioTracks) 35 | */ 36 | typedef enum { 37 | AUDIO_POLICY_OUTPUT_FLAG_INDIRECT = 0x0, 38 | AUDIO_POLICY_OUTPUT_FLAG_DIRECT = 0x1 39 | } audio_policy_output_flags_t; 40 | 41 | /* device categories used for audio_policy->set_force_use() */ 42 | typedef enum { 43 | AUDIO_POLICY_FORCE_NONE, 44 | AUDIO_POLICY_FORCE_SPEAKER, 45 | AUDIO_POLICY_FORCE_HEADPHONES, 46 | AUDIO_POLICY_FORCE_BT_SCO, 47 | AUDIO_POLICY_FORCE_BT_A2DP, 48 | AUDIO_POLICY_FORCE_WIRED_ACCESSORY, 49 | AUDIO_POLICY_FORCE_BT_CAR_DOCK, 50 | AUDIO_POLICY_FORCE_BT_DESK_DOCK, 51 | AUDIO_POLICY_FORCE_ANALOG_DOCK, 52 | AUDIO_POLICY_FORCE_DIGITAL_DOCK, 53 | 54 | AUDIO_POLICY_FORCE_CFG_CNT, 55 | AUDIO_POLICY_FORCE_CFG_MAX = AUDIO_POLICY_FORCE_CFG_CNT - 1, 56 | 57 | AUDIO_POLICY_FORCE_DEFAULT = AUDIO_POLICY_FORCE_NONE, 58 | } audio_policy_forced_cfg_t; 59 | 60 | /* usages used for audio_policy->set_force_use() */ 61 | typedef enum { 62 | AUDIO_POLICY_FORCE_FOR_COMMUNICATION, 63 | AUDIO_POLICY_FORCE_FOR_MEDIA, 64 | AUDIO_POLICY_FORCE_FOR_RECORD, 65 | AUDIO_POLICY_FORCE_FOR_DOCK, 66 | 67 | AUDIO_POLICY_FORCE_USE_CNT, 68 | AUDIO_POLICY_FORCE_USE_MAX = AUDIO_POLICY_FORCE_USE_CNT - 1, 69 | } audio_policy_force_use_t; 70 | 71 | /* device connection states used for audio_policy->set_device_connection_state() 72 | */ 73 | typedef enum { 74 | AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, 75 | AUDIO_POLICY_DEVICE_STATE_AVAILABLE, 76 | 77 | AUDIO_POLICY_DEVICE_STATE_CNT, 78 | AUDIO_POLICY_DEVICE_STATE_MAX = AUDIO_POLICY_DEVICE_STATE_CNT - 1, 79 | } audio_policy_dev_state_t; 80 | 81 | typedef enum { 82 | /* Used to generate a tone to notify the user of a 83 | * notification/alarm/ringtone while they are in a call. */ 84 | AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION = 0, 85 | 86 | AUDIO_POLICY_TONE_CNT, 87 | AUDIO_POLICY_TONE_MAX = AUDIO_POLICY_TONE_CNT - 1, 88 | } audio_policy_tone_t; 89 | 90 | 91 | static inline bool audio_is_low_visibility(audio_stream_type_t stream) { 92 | switch (stream) { 93 | case AUDIO_STREAM_SYSTEM: 94 | case AUDIO_STREAM_NOTIFICATION: 95 | case AUDIO_STREAM_RING: 96 | return true; 97 | default: 98 | return false; 99 | } 100 | } 101 | 102 | 103 | __END_DECLS 104 | 105 | #endif // ANDROID_AUDIO_POLICY_CORE_H 106 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/mq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * IPC messaging library. 19 | */ 20 | 21 | #ifndef __MQ_H 22 | #define __MQ_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /** A message. */ 29 | typedef struct MqMessage MqMessage; 30 | 31 | /** A destination to which messages can be sent. */ 32 | typedef struct MqDestination MqDestination; 33 | 34 | /* Array of bytes. */ 35 | typedef struct MqBytes MqBytes; 36 | 37 | /** 38 | * Hears messages. 39 | * 40 | * @param destination to which the message was sent 41 | * @param message the message to hear 42 | */ 43 | typedef void MqMessageListener(MqDestination *destination, MqMessage *message); 44 | 45 | /** 46 | * Hears a destination close. 47 | * 48 | * @param destination that closed 49 | */ 50 | typedef void MqCloseListener(MqDestination *destination); 51 | 52 | /** Message functions. */ 53 | 54 | /** 55 | * Creates a new Message. 56 | * 57 | * @param header as defined by user 58 | * @param body as defined by user 59 | * @param replyTo destination to which replies should be sent, NULL if none 60 | */ 61 | MqMessage *mqCreateMessage(MqBytes header, MqBytes body, 62 | MqDestination *replyTo); 63 | 64 | /** Sends a message to a destination. */ 65 | void mqSendMessage(MqMessage *message, MqDestination *destination); 66 | 67 | /** Destination functions. */ 68 | 69 | /** 70 | * Creates a new destination. Acquires a reference implicitly. 71 | * 72 | * @param messageListener function to call when a message is recieved 73 | * @param closeListener function to call when the destination closes 74 | * @param userData user-specific data to associate with the destination. 75 | * Retrieve using mqGetDestinationUserData(). 76 | */ 77 | MqDestination *mqCreateDestination(MqMessageListener *messageListener, 78 | MqCloseListener *closeListener, void *userData); 79 | 80 | /** 81 | * Gets user data which was associated with the given destination at 82 | * construction time. 83 | * 84 | * It is only valid to call this function in the same process that the 85 | * given destination was created in. 86 | * This function returns a null pointer if you call it on a destination 87 | * created in a remote process. 88 | */ 89 | void *mqGetUserData(MqDestination *destination); 90 | 91 | /** 92 | * Returns 1 if the destination was created in this process, or 0 if 93 | * the destination was created in a different process, in which case you have 94 | * a remote stub. 95 | */ 96 | int mqIsDestinationLocal(MqDestination *destination); 97 | 98 | /** 99 | * Increments the destination's reference count. 100 | */ 101 | void mqKeepDestination(MqDesintation *destination); 102 | 103 | /** 104 | * Decrements the destination's reference count. 105 | */ 106 | void mqFreeDestination(MqDestination *desintation); 107 | 108 | /** Registry API. */ 109 | 110 | /** 111 | * Gets the destination bound to a name. 112 | */ 113 | MqDestination *mqGetDestination(char *name); 114 | 115 | /** 116 | * Binds a destination to a name. 117 | */ 118 | void mqPutDestination(char *name, MqDestination *desintation); 119 | 120 | #ifdef __cplusplus 121 | } 122 | #endif 123 | 124 | #endif /* __MQ_H */ 125 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/sockets.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_SOCKETS_H 18 | #define __CUTILS_SOCKETS_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #ifdef HAVE_WINSOCK 26 | #include 27 | typedef int socklen_t; 28 | #elif HAVE_SYS_SOCKET_H 29 | #include 30 | #endif 31 | 32 | #define ANDROID_SOCKET_ENV_PREFIX "ANDROID_SOCKET_" 33 | #define ANDROID_SOCKET_DIR "/dev/socket" 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | /* 40 | * android_get_control_socket - simple helper function to get the file 41 | * descriptor of our init-managed Unix domain socket. `name' is the name of the 42 | * socket, as given in init.rc. Returns -1 on error. 43 | * 44 | * This is inline and not in libcutils proper because we want to use this in 45 | * third-party daemons with minimal modification. 46 | */ 47 | static inline int android_get_control_socket(const char *name) { 48 | char key[64] = ANDROID_SOCKET_ENV_PREFIX; 49 | const char *val; 50 | int fd; 51 | 52 | /* build our environment variable, counting cycles like a wolf ... */ 53 | #if HAVE_STRLCPY 54 | strlcpy(key + sizeof(ANDROID_SOCKET_ENV_PREFIX) - 1, 55 | name, 56 | sizeof(key) - sizeof(ANDROID_SOCKET_ENV_PREFIX)); 57 | #else /* for the host, which may lack the almightly strncpy ... */ 58 | strncpy(key + sizeof(ANDROID_SOCKET_ENV_PREFIX) - 1, 59 | name, 60 | sizeof(key) - sizeof(ANDROID_SOCKET_ENV_PREFIX)); 61 | key[sizeof(key) - 1] = '\0'; 62 | #endif 63 | 64 | val = getenv(key); 65 | if (!val) 66 | return -1; 67 | 68 | errno = 0; 69 | fd = strtol(val, NULL, 10); 70 | if (errno) 71 | return -1; 72 | 73 | return fd; 74 | } 75 | 76 | /* 77 | * See also android.os.LocalSocketAddress.Namespace 78 | */ 79 | // Linux "abstract" (non-filesystem) namespace 80 | #define ANDROID_SOCKET_NAMESPACE_ABSTRACT 0 81 | // Android "reserved" (/dev/socket) namespace 82 | #define ANDROID_SOCKET_NAMESPACE_RESERVED 1 83 | // Normal filesystem namespace 84 | #define ANDROID_SOCKET_NAMESPACE_FILESYSTEM 2 85 | 86 | extern int socket_loopback_client(int port, int type); 87 | extern int socket_network_client(const char *host, int port, int type); 88 | extern int socket_loopback_server(int port, int type); 89 | extern int socket_local_server(const char *name, int namespaceId, int type); 90 | extern int socket_local_server_bind(int s, const char *name, int namespaceId); 91 | extern int socket_local_client_connect(int fd, 92 | const char *name, int namespaceId, int type); 93 | extern int socket_local_client(const char *name, int namespaceId, int type); 94 | extern int socket_inaddr_any_server(int port, int type); 95 | 96 | /* 97 | * socket_peer_is_trusted - Takes a socket which is presumed to be a 98 | * connected local socket (e.g. AF_LOCAL) and returns whether the peer 99 | * (the userid that owns the process on the other end of that socket) 100 | * is one of the two trusted userids, root or shell. 101 | * 102 | * Note: This only works as advertised on the Android OS and always 103 | * just returns true when called on other operating systems. 104 | */ 105 | extern bool socket_peer_is_trusted(int fd); 106 | 107 | #ifdef __cplusplus 108 | } 109 | #endif 110 | 111 | #endif /* __CUTILS_SOCKETS_H */ 112 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/abort_socket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* Helper to perform abortable blocking operations on a socket: 18 | * asocket_connect() 19 | * asocket_accept() 20 | * asocket_read() 21 | * asocket_write() 22 | * These calls are similar to the regular syscalls, but can be aborted with: 23 | * asocket_abort() 24 | * 25 | * Calling close() on a regular POSIX socket does not abort blocked syscalls on 26 | * that socket in other threads. 27 | * 28 | * After calling asocket_abort() the socket cannot be reused. 29 | * 30 | * Call asocket_destory() *after* all threads have finished with the socket to 31 | * finish closing the socket and free the asocket structure. 32 | * 33 | * The helper is implemented by setting the socket non-blocking to initiate 34 | * syscalls connect(), accept(), read(), write(), then using a blocking poll() 35 | * on both the primary socket and a local pipe. This makes the poll() abortable 36 | * by writing a byte to the local pipe in asocket_abort(). 37 | * 38 | * asocket_create() sets the fd to non-blocking mode. It must not be changed to 39 | * blocking mode. 40 | * 41 | * Using asocket will triple the number of file descriptors required per 42 | * socket, due to the local pipe. It may be possible to use a global pipe per 43 | * process rather than per socket, but we have not been able to come up with a 44 | * race-free implementation yet. 45 | * 46 | * All functions except asocket_init() and asocket_destroy() are thread safe. 47 | */ 48 | 49 | #include 50 | #include 51 | 52 | #ifndef __CUTILS_ABORT_SOCKET_H__ 53 | #define __CUTILS_ABORT_SOCKET_H__ 54 | #ifdef __cplusplus 55 | extern "C" { 56 | #endif 57 | 58 | struct asocket { 59 | int fd; /* primary socket fd */ 60 | int abort_fd[2]; /* pipe used to abort */ 61 | }; 62 | 63 | /* Create an asocket from fd. 64 | * Sets the socket to non-blocking mode. 65 | * Returns NULL on error with errno set. 66 | */ 67 | struct asocket *asocket_init(int fd); 68 | 69 | /* Blocking socket I/O with timeout. 70 | * Calling asocket_abort() from another thread will cause each of these 71 | * functions to immediately return with value -1 and errno ECANCELED. 72 | * timeout is in ms, use -1 to indicate no timeout. On timeout -1 is returned 73 | * with errno ETIMEDOUT. 74 | * EINTR is handled in-call. 75 | * Other semantics are identical to the regular syscalls. 76 | */ 77 | int asocket_connect(struct asocket *s, const struct sockaddr *addr, 78 | socklen_t addrlen, int timeout); 79 | 80 | int asocket_accept(struct asocket *s, struct sockaddr *addr, 81 | socklen_t *addrlen, int timeout); 82 | 83 | int asocket_read(struct asocket *s, void *buf, size_t count, int timeout); 84 | 85 | int asocket_write(struct asocket *s, const void *buf, size_t count, 86 | int timeout); 87 | 88 | /* Abort above calls and shutdown socket. 89 | * Further I/O operations on this socket will immediately fail after this call. 90 | * asocket_destroy() should be used to release resources once all threads 91 | * have returned from blocking calls on the socket. 92 | */ 93 | void asocket_abort(struct asocket *s); 94 | 95 | /* Close socket and free asocket structure. 96 | * Must not be called until all calls on this structure have completed. 97 | */ 98 | void asocket_destroy(struct asocket *s); 99 | 100 | #ifdef __cplusplus 101 | } 102 | #endif 103 | #endif //__CUTILS_ABORT_SOCKET__H__ 104 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/PropertyMap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _UTILS_PROPERTY_MAP_H 18 | #define _UTILS_PROPERTY_MAP_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace android { 26 | 27 | /* 28 | * Provides a mechanism for passing around string-based property key / value pairs 29 | * and loading them from property files. 30 | * 31 | * The property files have the following simple structure: 32 | * 33 | * # Comment 34 | * key = value 35 | * 36 | * Keys and values are any sequence of printable ASCII characters. 37 | * The '=' separates the key from the value. 38 | * The key and value may not contain whitespace. 39 | * 40 | * The '\' character is reserved for escape sequences and is not currently supported. 41 | * The '"" character is reserved for quoting and is not currently supported. 42 | * Files that contain the '\' or '"' character will fail to parse. 43 | * 44 | * The file must not contain duplicate keys. 45 | * 46 | * TODO Support escape sequences and quoted values when needed. 47 | */ 48 | class PropertyMap { 49 | public: 50 | /* Creates an empty property map. */ 51 | PropertyMap(); 52 | ~PropertyMap(); 53 | 54 | /* Clears the property map. */ 55 | void clear(); 56 | 57 | /* Adds a property. 58 | * Replaces the property with the same key if it is already present. 59 | */ 60 | void addProperty(const String8 &key, const String8 &value); 61 | 62 | /* Returns true if the property map contains the specified key. */ 63 | bool hasProperty(const String8 &key) const; 64 | 65 | /* Gets the value of a property and parses it. 66 | * Returns true and sets outValue if the key was found and its value was parsed successfully. 67 | * Otherwise returns false and does not modify outValue. (Also logs a warning.) 68 | */ 69 | bool tryGetProperty(const String8 &key, String8 &outValue) const; 70 | bool tryGetProperty(const String8 &key, bool &outValue) const; 71 | bool tryGetProperty(const String8 &key, int32_t &outValue) const; 72 | bool tryGetProperty(const String8 &key, float &outValue) const; 73 | 74 | /* Adds all values from the specified property map. */ 75 | void addAll(const PropertyMap *map); 76 | 77 | /* Gets the underlying property map. */ 78 | inline const KeyedVector &getProperties() const { 79 | return mProperties; 80 | } 81 | 82 | /* Loads a property map from a file. */ 83 | static status_t load(const String8 &filename, PropertyMap **outMap); 84 | 85 | private: 86 | class Parser { 87 | PropertyMap *mMap; 88 | Tokenizer *mTokenizer; 89 | 90 | public: 91 | Parser(PropertyMap *map, Tokenizer *tokenizer); 92 | ~Parser(); 93 | status_t parse(); 94 | 95 | private: 96 | status_t parseType(); 97 | status_t parseKey(); 98 | status_t parseKeyProperty(); 99 | status_t parseModifier(const String8 &token, int32_t *outMetaState); 100 | status_t parseCharacterLiteral(char16_t *outCharacter); 101 | }; 102 | 103 | KeyedVector mProperties; 104 | }; 105 | 106 | } // namespace android 107 | 108 | #endif // _UTILS_PROPERTY_MAP_H 109 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/base/include/androidfw/ObbFile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef OBBFILE_H_ 18 | #define OBBFILE_H_ 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | namespace android { 27 | 28 | // OBB flags (bit 0) 29 | #define OBB_OVERLAY (1 << 0) 30 | #define OBB_SALTED (1 << 1) 31 | 32 | class ObbFile : public RefBase { 33 | protected: 34 | virtual ~ObbFile(); 35 | 36 | public: 37 | ObbFile(); 38 | 39 | bool readFrom(const char *filename); 40 | bool readFrom(int fd); 41 | bool writeTo(const char *filename); 42 | bool writeTo(int fd); 43 | bool removeFrom(const char *filename); 44 | bool removeFrom(int fd); 45 | 46 | const char *getFileName() const { 47 | return mFileName; 48 | } 49 | 50 | const String8 getPackageName() const { 51 | return mPackageName; 52 | } 53 | 54 | void setPackageName(String8 packageName) { 55 | mPackageName = packageName; 56 | } 57 | 58 | int32_t getVersion() const { 59 | return mVersion; 60 | } 61 | 62 | void setVersion(int32_t version) { 63 | mVersion = version; 64 | } 65 | 66 | int32_t getFlags() const { 67 | return mFlags; 68 | } 69 | 70 | void setFlags(int32_t flags) { 71 | mFlags = flags; 72 | } 73 | 74 | const unsigned char *getSalt(size_t *length) const { 75 | if ((mFlags & OBB_SALTED) == 0) { 76 | *length = 0; 77 | return NULL; 78 | } 79 | 80 | *length = sizeof(mSalt); 81 | return mSalt; 82 | } 83 | 84 | bool setSalt(const unsigned char *salt, size_t length) { 85 | if (length != sizeof(mSalt)) { 86 | return false; 87 | } 88 | 89 | memcpy(mSalt, salt, sizeof(mSalt)); 90 | mFlags |= OBB_SALTED; 91 | return true; 92 | } 93 | 94 | bool isOverlay() { 95 | return (mFlags & OBB_OVERLAY) == OBB_OVERLAY; 96 | } 97 | 98 | void setOverlay(bool overlay) { 99 | if (overlay) { 100 | mFlags |= OBB_OVERLAY; 101 | } else { 102 | mFlags &= ~OBB_OVERLAY; 103 | } 104 | } 105 | 106 | static inline uint32_t get4LE(const unsigned char *buf) { 107 | return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24); 108 | } 109 | 110 | static inline void put4LE(unsigned char *buf, uint32_t val) { 111 | buf[0] = val & 0xFF; 112 | buf[1] = (val >> 8) & 0xFF; 113 | buf[2] = (val >> 16) & 0xFF; 114 | buf[3] = (val >> 24) & 0xFF; 115 | } 116 | 117 | private: 118 | /* Package name this ObbFile is associated with */ 119 | String8 mPackageName; 120 | 121 | /* Package version this ObbFile is associated with */ 122 | int32_t mVersion; 123 | 124 | /* Flags for this OBB type. */ 125 | int32_t mFlags; 126 | 127 | /* Whether the file is salted. */ 128 | bool mSalted; 129 | 130 | /* The encryption salt. */ 131 | unsigned char mSalt[8]; 132 | 133 | const char *mFileName; 134 | 135 | size_t mFileSize; 136 | 137 | size_t mFooterStart; 138 | 139 | unsigned char *mReadBuf; 140 | 141 | bool parseObbFile(int fd); 142 | }; 143 | 144 | } 145 | #endif /* OBBFILE_H_ */ 146 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/hashmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Hash map. 19 | */ 20 | 21 | #ifndef __HASHMAP_H 22 | #define __HASHMAP_H 23 | 24 | #include 25 | #include 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /** A hash map. */ 32 | typedef struct Hashmap Hashmap; 33 | 34 | /** 35 | * Creates a new hash map. Returns NULL if memory allocation fails. 36 | * 37 | * @param initialCapacity number of expected entries 38 | * @param hash function which hashes keys 39 | * @param equals function which compares keys for equality 40 | */ 41 | Hashmap *hashmapCreate(size_t initialCapacity, 42 | int (*hash)(void *key), bool (*equals)(void *keyA, void *keyB)); 43 | 44 | /** 45 | * Frees the hash map. Does not free the keys or values themselves. 46 | */ 47 | void hashmapFree(Hashmap *map); 48 | 49 | /** 50 | * Hashes the memory pointed to by key with the given size. Useful for 51 | * implementing hash functions. 52 | */ 53 | int hashmapHash(void *key, size_t keySize); 54 | 55 | /** 56 | * Puts value for the given key in the map. Returns pre-existing value if 57 | * any. 58 | * 59 | * If memory allocation fails, this function returns NULL, the map's size 60 | * does not increase, and errno is set to ENOMEM. 61 | */ 62 | void *hashmapPut(Hashmap *map, void *key, void *value); 63 | 64 | /** 65 | * Gets a value from the map. Returns NULL if no entry for the given key is 66 | * found or if the value itself is NULL. 67 | */ 68 | void *hashmapGet(Hashmap *map, void *key); 69 | 70 | /** 71 | * Returns true if the map contains an entry for the given key. 72 | */ 73 | bool hashmapContainsKey(Hashmap *map, void *key); 74 | 75 | /** 76 | * Gets the value for a key. If a value is not found, this function gets a 77 | * value and creates an entry using the given callback. 78 | * 79 | * If memory allocation fails, the callback is not called, this function 80 | * returns NULL, and errno is set to ENOMEM. 81 | */ 82 | void *hashmapMemoize(Hashmap *map, void *key, 83 | void *(*initialValue)(void *key, void *context), void *context); 84 | 85 | /** 86 | * Removes an entry from the map. Returns the removed value or NULL if no 87 | * entry was present. 88 | */ 89 | void *hashmapRemove(Hashmap *map, void *key); 90 | 91 | /** 92 | * Gets the number of entries in this map. 93 | */ 94 | size_t hashmapSize(Hashmap *map); 95 | 96 | /** 97 | * Invokes the given callback on each entry in the map. Stops iterating if 98 | * the callback returns false. 99 | */ 100 | void hashmapForEach(Hashmap *map, 101 | bool (*callback)(void *key, void *value, void *context), 102 | void *context); 103 | 104 | /** 105 | * Concurrency support. 106 | */ 107 | 108 | /** 109 | * Locks the hash map so only the current thread can access it. 110 | */ 111 | void hashmapLock(Hashmap *map); 112 | 113 | /** 114 | * Unlocks the hash map so other threads can access it. 115 | */ 116 | void hashmapUnlock(Hashmap *map); 117 | 118 | /** 119 | * Key utilities. 120 | */ 121 | 122 | /** 123 | * Hashes int keys. 'key' is a pointer to int. 124 | */ 125 | int hashmapIntHash(void *key); 126 | 127 | /** 128 | * Compares two int keys for equality. 129 | */ 130 | bool hashmapIntEquals(void *keyA, void *keyB); 131 | 132 | /** 133 | * For debugging. 134 | */ 135 | 136 | /** 137 | * Gets current capacity. 138 | */ 139 | size_t hashmapCurrentCapacity(Hashmap *map); 140 | 141 | /** 142 | * Counts the number of entry collisions. 143 | */ 144 | size_t hashmapCountCollisions(Hashmap *map); 145 | 146 | #ifdef __cplusplus 147 | } 148 | #endif 149 | 150 | #endif /* __HASHMAP_H */ 151 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/atomic-x86.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_CUTILS_ATOMIC_X86_H 18 | #define ANDROID_CUTILS_ATOMIC_X86_H 19 | 20 | #include 21 | 22 | extern inline void android_compiler_barrier(void) { 23 | __asm__ __volatile__ ("" : : : "memory"); 24 | } 25 | 26 | #if ANDROID_SMP == 0 27 | extern inline void android_memory_barrier(void) { 28 | android_compiler_barrier(); 29 | } 30 | extern inline void android_memory_store_barrier(void) { 31 | android_compiler_barrier(); 32 | } 33 | #else 34 | extern inline void android_memory_barrier(void) { 35 | __asm__ __volatile__ ("mfence" : : : "memory"); 36 | } 37 | extern inline void android_memory_store_barrier(void) { 38 | android_compiler_barrier(); 39 | } 40 | #endif 41 | 42 | extern inline int32_t android_atomic_acquire_load(volatile const int32_t *ptr) { 43 | int32_t value = *ptr; 44 | android_compiler_barrier(); 45 | return value; 46 | } 47 | 48 | extern inline int32_t android_atomic_release_load(volatile const int32_t *ptr) { 49 | android_memory_barrier(); 50 | return *ptr; 51 | } 52 | 53 | extern inline void android_atomic_acquire_store(int32_t value, 54 | volatile int32_t *ptr) { 55 | *ptr = value; 56 | android_memory_barrier(); 57 | } 58 | 59 | extern inline void android_atomic_release_store(int32_t value, 60 | volatile int32_t *ptr) { 61 | android_compiler_barrier(); 62 | *ptr = value; 63 | } 64 | 65 | extern inline int android_atomic_cas(int32_t old_value, int32_t new_value, 66 | volatile int32_t *ptr) { 67 | int32_t prev; 68 | __asm__ __volatile__ ("lock; cmpxchgl %1, %2" 69 | : "=a" (prev) 70 | : "q" (new_value), "m" (*ptr), "0" (old_value) 71 | : "memory"); 72 | return prev != old_value; 73 | } 74 | 75 | extern inline int android_atomic_acquire_cas(int32_t old_value, 76 | int32_t new_value, 77 | volatile int32_t *ptr) { 78 | /* Loads are not reordered with other loads. */ 79 | return android_atomic_cas(old_value, new_value, ptr); 80 | } 81 | 82 | extern inline int android_atomic_release_cas(int32_t old_value, 83 | int32_t new_value, 84 | volatile int32_t *ptr) { 85 | /* Stores are not reordered with other stores. */ 86 | return android_atomic_cas(old_value, new_value, ptr); 87 | } 88 | 89 | extern inline int32_t android_atomic_add(int32_t increment, 90 | volatile int32_t *ptr) { 91 | __asm__ __volatile__ ("lock; xaddl %0, %1" 92 | : "+r" (increment), "+m" (*ptr) 93 | : : "memory"); 94 | /* increment now holds the old value of *ptr */ 95 | return increment; 96 | } 97 | 98 | extern inline int32_t android_atomic_inc(volatile int32_t *addr) { 99 | return android_atomic_add(1, addr); 100 | } 101 | 102 | extern inline int32_t android_atomic_dec(volatile int32_t *addr) { 103 | return android_atomic_add(-1, addr); 104 | } 105 | 106 | extern inline int32_t android_atomic_and(int32_t value, 107 | volatile int32_t *ptr) { 108 | int32_t prev, status; 109 | do { 110 | prev = *ptr; 111 | status = android_atomic_cas(prev, prev & value, ptr); 112 | } while (__builtin_expect(status != 0, 0)); 113 | return prev; 114 | } 115 | 116 | extern inline int32_t android_atomic_or(int32_t value, volatile int32_t *ptr) { 117 | int32_t prev, status; 118 | do { 119 | prev = *ptr; 120 | status = android_atomic_cas(prev, prev | value, ptr); 121 | } while (__builtin_expect(status != 0, 0)); 122 | return prev; 123 | } 124 | 125 | #endif /* ANDROID_CUTILS_ATOMIC_X86_H */ 126 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/system/graphics.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H 18 | #define SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /* 25 | * If the HAL needs to create service threads to handle graphics related 26 | * tasks, these threads need to run at HAL_PRIORITY_URGENT_DISPLAY priority 27 | * if they can block the main rendering thread in any way. 28 | * 29 | * the priority of the current thread can be set with: 30 | * 31 | * #include 32 | * setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); 33 | * 34 | */ 35 | 36 | #define HAL_PRIORITY_URGENT_DISPLAY (-8) 37 | 38 | /** 39 | * pixel format definitions 40 | */ 41 | 42 | enum { 43 | HAL_PIXEL_FORMAT_RGBA_8888 = 1, 44 | HAL_PIXEL_FORMAT_RGBX_8888 = 2, 45 | HAL_PIXEL_FORMAT_RGB_888 = 3, 46 | HAL_PIXEL_FORMAT_RGB_565 = 4, 47 | HAL_PIXEL_FORMAT_BGRA_8888 = 5, 48 | HAL_PIXEL_FORMAT_RGBA_5551 = 6, 49 | HAL_PIXEL_FORMAT_RGBA_4444 = 7, 50 | 51 | /* 0x8 - 0xFF range unavailable */ 52 | 53 | /* 54 | * 0x100 - 0x1FF 55 | * 56 | * This range is reserved for pixel formats that are specific to the HAL 57 | * implementation. Implementations can use any value in this range to 58 | * communicate video pixel formats between their HAL modules. These formats 59 | * must not have an alpha channel. Additionally, an EGLimage created from a 60 | * gralloc buffer of one of these formats must be supported for use with the 61 | * GL_OES_EGL_image_external OpenGL ES extension. 62 | */ 63 | 64 | /* 65 | * Android YUV format: 66 | * 67 | * This format is exposed outside of the HAL to software decoders and 68 | * applications. EGLImageKHR must support it in conjunction with the 69 | * OES_EGL_image_external extension. 70 | * 71 | * YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed 72 | * by (W/2) x (H/2) Cr and Cb planes. 73 | * 74 | * This format assumes 75 | * - an even width 76 | * - an even height 77 | * - a horizontal stride multiple of 16 pixels 78 | * - a vertical stride equal to the height 79 | * 80 | * y_size = stride * height 81 | * c_size = ALIGN(stride/2, 16) * height/2 82 | * size = y_size + c_size * 2 83 | * cr_offset = y_size 84 | * cb_offset = y_size + c_size 85 | * 86 | */ 87 | HAL_PIXEL_FORMAT_YV12 = 0x32315659, // YCrCb 4:2:0 Planar 88 | 89 | 90 | 91 | /* Legacy formats (deprecated), used by ImageFormat.java */ 92 | HAL_PIXEL_FORMAT_YCbCr_422_SP = 0x10, // NV16 93 | HAL_PIXEL_FORMAT_YCrCb_420_SP = 0x11, // NV21 94 | HAL_PIXEL_FORMAT_YCbCr_422_I = 0x14, // YUY2 95 | }; 96 | 97 | 98 | /** 99 | * Transformation definitions 100 | * 101 | * IMPORTANT NOTE: 102 | * HAL_TRANSFORM_ROT_90 is applied CLOCKWISE and AFTER HAL_TRANSFORM_FLIP_{H|V}. 103 | * 104 | */ 105 | 106 | enum { 107 | /* flip source image horizontally (around the vertical axis) */ 108 | HAL_TRANSFORM_FLIP_H = 0x01, 109 | /* flip source image vertically (around the horizontal axis)*/ 110 | HAL_TRANSFORM_FLIP_V = 0x02, 111 | /* rotate source image 90 degrees clockwise */ 112 | HAL_TRANSFORM_ROT_90 = 0x04, 113 | /* rotate source image 180 degrees */ 114 | HAL_TRANSFORM_ROT_180 = 0x03, 115 | /* rotate source image 270 degrees clockwise */ 116 | HAL_TRANSFORM_ROT_270 = 0x07, 117 | }; 118 | 119 | #ifdef __cplusplus 120 | } 121 | #endif 122 | 123 | #endif /* SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H */ 124 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/selector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Framework for multiplexing I/O. A selector manages a set of file 19 | * descriptors and calls out to user-provided callback functions to read and 20 | * write data and handle errors. 21 | */ 22 | 23 | #ifndef __SELECTOR_H 24 | #define __SELECTOR_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | #include 31 | 32 | /** 33 | * Manages SelectableFds and invokes their callbacks at appropriate times. 34 | */ 35 | typedef struct Selector Selector; 36 | 37 | /** 38 | * A selectable descriptor. Contains callbacks which the selector can invoke 39 | * before calling select(), when the descriptor is readable or writable, and 40 | * when the descriptor contains out-of-band data. Simply set a callback to 41 | * NULL if you're not interested in that particular event. 42 | * 43 | * A selectable descriptor can indicate that it needs to be removed from the 44 | * selector by setting the 'remove' flag. The selector will remove the 45 | * descriptor at a later time and invoke the onRemove() callback. 46 | * 47 | * SelectableFd fields should only be modified from the selector loop. 48 | */ 49 | typedef struct SelectableFd SelectableFd; 50 | struct SelectableFd { 51 | 52 | /** The file descriptor itself. */ 53 | int fd; 54 | 55 | /** Pointer to user-specific data. Can be NULL. */ 56 | void *data; 57 | 58 | /** 59 | * Set this flag when you no longer wish to be selected. The selector 60 | * will invoke onRemove() when the descriptor is actually removed. 61 | */ 62 | bool remove; 63 | 64 | /** 65 | * Invoked by the selector before calling select. You can set up other 66 | * callbacks from here as necessary. 67 | */ 68 | void (*beforeSelect)(SelectableFd *self); 69 | 70 | /** 71 | * Invoked by the selector when the descriptor has data available. Set to 72 | * NULL to indicate that you're not interested in reading. 73 | */ 74 | void (*onReadable)(SelectableFd *self); 75 | 76 | /** 77 | * Invoked by the selector when the descriptor can accept data. Set to 78 | * NULL to indicate that you're not interested in writing. 79 | */ 80 | void (*onWritable)(SelectableFd *self); 81 | 82 | /** 83 | * Invoked by the selector when out-of-band (OOB) data is available. Set to 84 | * NULL to indicate that you're not interested in OOB data. 85 | */ 86 | void (*onExcept)(SelectableFd *self); 87 | 88 | /** 89 | * Invoked by the selector after the descriptor is removed from the 90 | * selector but before the selector frees the SelectableFd memory. 91 | */ 92 | void (*onRemove)(SelectableFd *self); 93 | 94 | /** 95 | * The selector which selected this fd. Set by the selector itself. 96 | */ 97 | Selector *selector; 98 | }; 99 | 100 | /** 101 | * Creates a new selector. 102 | */ 103 | Selector *selectorCreate(void); 104 | 105 | /** 106 | * Creates a new selectable fd, adds it to the given selector and returns a 107 | * pointer. Outside of 'selector' and 'fd', all fields are set to 0 or NULL 108 | * by default. 109 | * 110 | * The selectable fd should only be modified from the selector loop thread. 111 | */ 112 | SelectableFd *selectorAdd(Selector *selector, int fd); 113 | 114 | /** 115 | * Wakes up the selector even though no I/O events occurred. Use this 116 | * to indicate that you're ready to write to a descriptor. 117 | */ 118 | void selectorWakeUp(Selector *selector); 119 | 120 | /** 121 | * Loops continuously selecting file descriptors and firing events. 122 | * Does not return. 123 | */ 124 | void selectorLoop(Selector *selector); 125 | 126 | #ifdef __cplusplus 127 | } 128 | #endif 129 | 130 | #endif /* __SELECTOR_H */ 131 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/android/log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _ANDROID_LOG_H 18 | #define _ANDROID_LOG_H 19 | 20 | /****************************************************************** 21 | * 22 | * IMPORTANT NOTICE: 23 | * 24 | * This file is part of Android's set of stable system headers 25 | * exposed by the Android NDK (Native Development Kit) since 26 | * platform release 1.5 27 | * 28 | * Third-party source AND binary code relies on the definitions 29 | * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES. 30 | * 31 | * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES) 32 | * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS 33 | * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY 34 | * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES 35 | */ 36 | 37 | /* 38 | * Support routines to send messages to the Android in-kernel log buffer, 39 | * which can later be accessed through the 'logcat' utility. 40 | * 41 | * Each log message must have 42 | * - a priority 43 | * - a log tag 44 | * - some text 45 | * 46 | * The tag normally corresponds to the component that emits the log message, 47 | * and should be reasonably small. 48 | * 49 | * Log message text may be truncated to less than an implementation-specific 50 | * limit (e.g. 1023 characters max). 51 | * 52 | * Note that a newline character ("\n") will be appended automatically to your 53 | * log message, if not already there. It is not possible to send several messages 54 | * and have them appear on a single line in logcat. 55 | * 56 | * PLEASE USE LOGS WITH MODERATION: 57 | * 58 | * - Sending log messages eats CPU and slow down your application and the 59 | * system. 60 | * 61 | * - The circular log buffer is pretty small (<64KB), sending many messages 62 | * might push off other important log messages from the rest of the system. 63 | * 64 | * - In release builds, only send log messages to account for exceptional 65 | * conditions. 66 | * 67 | * NOTE: These functions MUST be implemented by /system/lib/liblog.so 68 | */ 69 | 70 | #include 71 | 72 | #ifdef __cplusplus 73 | extern "C" { 74 | #endif 75 | 76 | /* 77 | * Android log priority values, in ascending priority order. 78 | */ 79 | typedef enum android_LogPriority { 80 | ANDROID_LOG_UNKNOWN = 0, 81 | ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */ 82 | ANDROID_LOG_VERBOSE, 83 | ANDROID_LOG_DEBUG, 84 | ANDROID_LOG_INFO, 85 | ANDROID_LOG_WARN, 86 | ANDROID_LOG_ERROR, 87 | ANDROID_LOG_FATAL, 88 | ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */ 89 | } android_LogPriority; 90 | 91 | /* 92 | * Send a simple string to the log. 93 | */ 94 | int __android_log_write(int prio, const char *tag, const char *text); 95 | 96 | /* 97 | * Send a formatted string to the log, used like printf(fmt,...) 98 | */ 99 | int __android_log_print(int prio, const char *tag, const char *fmt, ...) 100 | #if defined(__GNUC__) 101 | __attribute__ ((format(printf, 3, 4))) 102 | #endif 103 | ; 104 | 105 | /* 106 | * A variant of __android_log_print() that takes a va_list to list 107 | * additional parameters. 108 | */ 109 | int __android_log_vprint(int prio, const char *tag, 110 | const char *fmt, va_list ap); 111 | 112 | /* 113 | * Log an assertion failure and SIGTRAP the process to have a chance 114 | * to inspect it, if a debugger is attached. This uses the FATAL priority. 115 | */ 116 | void __android_log_assert(const char *cond, const char *tag, 117 | const char *fmt, ...) 118 | #if defined(__GNUC__) 119 | __attribute__ ((noreturn)) 120 | __attribute__ ((format(printf, 3, 4))) 121 | #endif 122 | ; 123 | 124 | #ifdef __cplusplus 125 | } 126 | #endif 127 | 128 | #endif /* _ANDROID_LOG_H */ 129 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/RWLock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _LIBS_UTILS_RWLOCK_H 18 | #define _LIBS_UTILS_RWLOCK_H 19 | 20 | #include 21 | #include 22 | 23 | #if defined(HAVE_PTHREADS) 24 | # include 25 | #endif 26 | 27 | #include 28 | #include 29 | 30 | // --------------------------------------------------------------------------- 31 | namespace android { 32 | // --------------------------------------------------------------------------- 33 | 34 | #if defined(HAVE_PTHREADS) 35 | 36 | /* 37 | * Simple mutex class. The implementation is system-dependent. 38 | * 39 | * The mutex must be unlocked by the thread that locked it. They are not 40 | * recursive, i.e. the same thread can't lock it multiple times. 41 | */ 42 | class RWLock { 43 | public: 44 | enum { 45 | PRIVATE = 0, 46 | SHARED = 1 47 | }; 48 | 49 | RWLock(); 50 | RWLock(const char *name); 51 | RWLock(int type, const char *name = NULL); 52 | ~RWLock(); 53 | 54 | status_t readLock(); 55 | status_t tryReadLock(); 56 | status_t writeLock(); 57 | status_t tryWriteLock(); 58 | void unlock(); 59 | 60 | class AutoRLock { 61 | public: 62 | inline AutoRLock(RWLock &rwlock) : mLock(rwlock) { 63 | mLock.readLock(); 64 | } 65 | inline ~AutoRLock() { 66 | mLock.unlock(); 67 | } 68 | private: 69 | RWLock &mLock; 70 | }; 71 | 72 | class AutoWLock { 73 | public: 74 | inline AutoWLock(RWLock &rwlock) : mLock(rwlock) { 75 | mLock.writeLock(); 76 | } 77 | inline ~AutoWLock() { 78 | mLock.unlock(); 79 | } 80 | private: 81 | RWLock &mLock; 82 | }; 83 | 84 | private: 85 | // A RWLock cannot be copied 86 | RWLock(const RWLock &); 87 | RWLock &operator = (const RWLock &); 88 | 89 | pthread_rwlock_t mRWLock; 90 | }; 91 | 92 | inline RWLock::RWLock() { 93 | pthread_rwlock_init(&mRWLock, NULL); 94 | } 95 | inline RWLock::RWLock(const char *name) { 96 | pthread_rwlock_init(&mRWLock, NULL); 97 | } 98 | inline RWLock::RWLock(int type, const char *name) { 99 | if (type == SHARED) { 100 | pthread_rwlockattr_t attr; 101 | pthread_rwlockattr_init(&attr); 102 | pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); 103 | pthread_rwlock_init(&mRWLock, &attr); 104 | pthread_rwlockattr_destroy(&attr); 105 | } else { 106 | pthread_rwlock_init(&mRWLock, NULL); 107 | } 108 | } 109 | inline RWLock::~RWLock() { 110 | pthread_rwlock_destroy(&mRWLock); 111 | } 112 | inline status_t RWLock::readLock() { 113 | return -pthread_rwlock_rdlock(&mRWLock); 114 | } 115 | inline status_t RWLock::tryReadLock() { 116 | return -pthread_rwlock_tryrdlock(&mRWLock); 117 | } 118 | inline status_t RWLock::writeLock() { 119 | return -pthread_rwlock_wrlock(&mRWLock); 120 | } 121 | inline status_t RWLock::tryWriteLock() { 122 | return -pthread_rwlock_trywrlock(&mRWLock); 123 | } 124 | inline void RWLock::unlock() { 125 | pthread_rwlock_unlock(&mRWLock); 126 | } 127 | 128 | #endif // HAVE_PTHREADS 129 | 130 | // --------------------------------------------------------------------------- 131 | }; // namespace android 132 | // --------------------------------------------------------------------------- 133 | 134 | #endif // _LIBS_UTILS_RWLOCK_H 135 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/logprint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _LOGPRINT_H 18 | #define _LOGPRINT_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | typedef enum { 30 | FORMAT_OFF = 0, 31 | FORMAT_BRIEF, 32 | FORMAT_PROCESS, 33 | FORMAT_TAG, 34 | FORMAT_THREAD, 35 | FORMAT_RAW, 36 | FORMAT_TIME, 37 | FORMAT_THREADTIME, 38 | FORMAT_LONG, 39 | } AndroidLogPrintFormat; 40 | 41 | typedef struct AndroidLogFormat_t AndroidLogFormat; 42 | 43 | typedef struct AndroidLogEntry_t { 44 | time_t tv_sec; 45 | long tv_nsec; 46 | android_LogPriority priority; 47 | pid_t pid; 48 | pthread_t tid; 49 | const char *tag; 50 | size_t messageLen; 51 | const char *message; 52 | } AndroidLogEntry; 53 | 54 | AndroidLogFormat *android_log_format_new(); 55 | 56 | void android_log_format_free(AndroidLogFormat *p_format); 57 | 58 | void android_log_setPrintFormat(AndroidLogFormat *p_format, 59 | AndroidLogPrintFormat format); 60 | 61 | /** 62 | * Returns FORMAT_OFF on invalid string 63 | */ 64 | AndroidLogPrintFormat android_log_formatFromString(const char *s); 65 | 66 | /** 67 | * filterExpression: a single filter expression 68 | * eg "AT:d" 69 | * 70 | * returns 0 on success and -1 on invalid expression 71 | * 72 | * Assumes single threaded execution 73 | * 74 | */ 75 | 76 | int android_log_addFilterRule(AndroidLogFormat *p_format, 77 | const char *filterExpression); 78 | 79 | 80 | /** 81 | * filterString: a whitespace-separated set of filter expressions 82 | * eg "AT:d *:i" 83 | * 84 | * returns 0 on success and -1 on invalid expression 85 | * 86 | * Assumes single threaded execution 87 | * 88 | */ 89 | 90 | int android_log_addFilterString(AndroidLogFormat *p_format, 91 | const char *filterString); 92 | 93 | 94 | /** 95 | * returns 1 if this log line should be printed based on its priority 96 | * and tag, and 0 if it should not 97 | */ 98 | int android_log_shouldPrintLine ( 99 | AndroidLogFormat *p_format, const char *tag, android_LogPriority pri); 100 | 101 | 102 | /** 103 | * Splits a wire-format buffer into an AndroidLogEntry 104 | * entry allocated by caller. Pointers will point directly into buf 105 | * 106 | * Returns 0 on success and -1 on invalid wire format (entry will be 107 | * in unspecified state) 108 | */ 109 | int android_log_processLogBuffer(struct logger_entry *buf, 110 | AndroidLogEntry *entry); 111 | 112 | /** 113 | * Like android_log_processLogBuffer, but for binary logs. 114 | * 115 | * If "map" is non-NULL, it will be used to convert the log tag number 116 | * into a string. 117 | */ 118 | int android_log_processBinaryLogBuffer(struct logger_entry *buf, 119 | AndroidLogEntry *entry, const EventTagMap *map, char *messageBuf, 120 | int messageBufLen); 121 | 122 | 123 | /** 124 | * Formats a log message into a buffer 125 | * 126 | * Uses defaultBuffer if it can, otherwise malloc()'s a new buffer 127 | * If return value != defaultBuffer, caller must call free() 128 | * Returns NULL on malloc error 129 | */ 130 | 131 | char *android_log_formatLogLine ( 132 | AndroidLogFormat *p_format, 133 | char *defaultBuffer, 134 | size_t defaultBufferSize, 135 | const AndroidLogEntry *p_line, 136 | size_t *p_outLength); 137 | 138 | 139 | /** 140 | * Either print or do not print log line, based on filter 141 | * 142 | * Assumes single threaded execution 143 | * 144 | */ 145 | int android_log_printLogLine( 146 | AndroidLogFormat *p_format, 147 | int fd, 148 | const AndroidLogEntry *entry); 149 | 150 | 151 | #ifdef __cplusplus 152 | } 153 | #endif 154 | 155 | 156 | #endif /*_LOGPRINT_H*/ 157 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/ThreadDefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _LIBS_UTILS_THREAD_DEFS_H 18 | #define _LIBS_UTILS_THREAD_DEFS_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | // --------------------------------------------------------------------------- 25 | // C API 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | typedef void *android_thread_id_t; 32 | 33 | typedef int (*android_thread_func_t)(void *); 34 | 35 | enum { 36 | /* 37 | * *********************************************** 38 | * ** Keep in sync with android.os.Process.java ** 39 | * *********************************************** 40 | * 41 | * This maps directly to the "nice" priorities we use in Android. 42 | * A thread priority should be chosen inverse-proportionally to 43 | * the amount of work the thread is expected to do. The more work 44 | * a thread will do, the less favorable priority it should get so that 45 | * it doesn't starve the system. Threads not behaving properly might 46 | * be "punished" by the kernel. 47 | * Use the levels below when appropriate. Intermediate values are 48 | * acceptable, preferably use the {MORE|LESS}_FAVORABLE constants below. 49 | */ 50 | ANDROID_PRIORITY_LOWEST = 19, 51 | 52 | /* use for background tasks */ 53 | ANDROID_PRIORITY_BACKGROUND = 10, 54 | 55 | /* most threads run at normal priority */ 56 | ANDROID_PRIORITY_NORMAL = 0, 57 | 58 | /* threads currently running a UI that the user is interacting with */ 59 | ANDROID_PRIORITY_FOREGROUND = -2, 60 | 61 | /* the main UI thread has a slightly more favorable priority */ 62 | ANDROID_PRIORITY_DISPLAY = -4, 63 | 64 | /* ui service treads might want to run at a urgent display (uncommon) */ 65 | ANDROID_PRIORITY_URGENT_DISPLAY = HAL_PRIORITY_URGENT_DISPLAY, 66 | 67 | /* all normal audio threads */ 68 | ANDROID_PRIORITY_AUDIO = -16, 69 | 70 | /* service audio threads (uncommon) */ 71 | ANDROID_PRIORITY_URGENT_AUDIO = -19, 72 | 73 | /* should never be used in practice. regular process might not 74 | * be allowed to use this level */ 75 | ANDROID_PRIORITY_HIGHEST = -20, 76 | 77 | ANDROID_PRIORITY_DEFAULT = ANDROID_PRIORITY_NORMAL, 78 | ANDROID_PRIORITY_MORE_FAVORABLE = -1, 79 | ANDROID_PRIORITY_LESS_FAVORABLE = +1, 80 | }; 81 | 82 | #ifdef __cplusplus 83 | } // extern "C" 84 | #endif 85 | 86 | // --------------------------------------------------------------------------- 87 | // C++ API 88 | #ifdef __cplusplus 89 | namespace android { 90 | // --------------------------------------------------------------------------- 91 | 92 | typedef android_thread_id_t thread_id_t; 93 | typedef android_thread_func_t thread_func_t; 94 | 95 | enum { 96 | PRIORITY_LOWEST = ANDROID_PRIORITY_LOWEST, 97 | PRIORITY_BACKGROUND = ANDROID_PRIORITY_BACKGROUND, 98 | PRIORITY_NORMAL = ANDROID_PRIORITY_NORMAL, 99 | PRIORITY_FOREGROUND = ANDROID_PRIORITY_FOREGROUND, 100 | PRIORITY_DISPLAY = ANDROID_PRIORITY_DISPLAY, 101 | PRIORITY_URGENT_DISPLAY = ANDROID_PRIORITY_URGENT_DISPLAY, 102 | PRIORITY_AUDIO = ANDROID_PRIORITY_AUDIO, 103 | PRIORITY_URGENT_AUDIO = ANDROID_PRIORITY_URGENT_AUDIO, 104 | PRIORITY_HIGHEST = ANDROID_PRIORITY_HIGHEST, 105 | PRIORITY_DEFAULT = ANDROID_PRIORITY_DEFAULT, 106 | PRIORITY_MORE_FAVORABLE = ANDROID_PRIORITY_MORE_FAVORABLE, 107 | PRIORITY_LESS_FAVORABLE = ANDROID_PRIORITY_LESS_FAVORABLE, 108 | }; 109 | 110 | // --------------------------------------------------------------------------- 111 | }; // namespace android 112 | #endif // __cplusplus 113 | // --------------------------------------------------------------------------- 114 | 115 | 116 | #endif // _LIBS_UTILS_THREAD_DEFS_H 117 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/mspace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* A wrapper file for dlmalloc.h that defines prototypes for the 18 | * mspace_*() functions, which provide an interface for creating 19 | * multiple heaps. 20 | */ 21 | 22 | #ifndef MSPACE_H_ 23 | #define MSPACE_H_ 24 | 25 | /* It's a pain getting the mallinfo stuff to work 26 | * with Linux, OSX, and klibc, so just turn it off 27 | * for now. 28 | * TODO: make mallinfo work 29 | */ 30 | #define NO_MALLINFO 1 31 | 32 | /* Allow setting the maximum heap footprint. 33 | */ 34 | #define USE_MAX_ALLOWED_FOOTPRINT 1 35 | 36 | #define USE_CONTIGUOUS_MSPACES 1 37 | #if USE_CONTIGUOUS_MSPACES 38 | #define HAVE_MMAP 0 39 | #define HAVE_MORECORE 1 40 | #define MORECORE_CONTIGUOUS 0 41 | #endif 42 | 43 | #define MSPACES 1 44 | #define ONLY_MSPACES 1 45 | #include "../../../../bionic/libc/bionic/dlmalloc.h" 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | /* 52 | mspace_usable_size(void* p); 53 | 54 | Returns the number of bytes you can actually use in 55 | an allocated chunk, which may be more than you requested (although 56 | often not) due to alignment and minimum size constraints. 57 | You can use this many bytes without worrying about 58 | overwriting other allocated objects. This is not a particularly great 59 | programming practice. mspace_usable_size can be more useful in 60 | debugging and assertions, for example: 61 | 62 | p = mspace_malloc(msp, n); 63 | assert(mspace_usable_size(msp, p) >= 256); 64 | */ 65 | size_t mspace_usable_size(mspace, const void *); 66 | 67 | #if USE_CONTIGUOUS_MSPACES 68 | /* 69 | Similar to create_mspace(), but the underlying memory is 70 | guaranteed to be contiguous. No more than max_capacity 71 | bytes is ever allocated to the mspace. 72 | */ 73 | mspace create_contiguous_mspace(size_t starting_capacity, size_t max_capacity, 74 | int locked); 75 | 76 | /* 77 | Identical to create_contiguous_mspace, but labels the mapping 'mspace/name' 78 | instead of 'mspace' 79 | */ 80 | mspace create_contiguous_mspace_with_name(size_t starting_capacity, 81 | size_t max_capacity, int locked, const char *name); 82 | 83 | /* 84 | Identical to create_contiguous_mspace, but uses previously mapped memory. 85 | */ 86 | mspace create_contiguous_mspace_with_base(size_t starting_capacity, 87 | size_t max_capacity, int locked, void *base); 88 | 89 | size_t destroy_contiguous_mspace(mspace msp); 90 | 91 | /* 92 | Returns the position of the "break" within the given mspace. 93 | */ 94 | void *contiguous_mspace_sbrk0(mspace msp); 95 | #endif 96 | 97 | /* 98 | Call the handler for each block in the specified mspace. 99 | chunkptr and chunklen refer to the heap-level chunk including 100 | the chunk overhead, and userptr and userlen refer to the 101 | user-usable part of the chunk. If the chunk is free, userptr 102 | will be NULL and userlen will be 0. userlen is not guaranteed 103 | to be the same value passed into malloc() for a given chunk; 104 | it is >= the requested size. 105 | */ 106 | void mspace_walk_heap(mspace msp, 107 | void(*handler)(const void *chunkptr, size_t chunklen, 108 | const void *userptr, size_t userlen, void *arg), void *harg); 109 | 110 | /* 111 | mspace_walk_free_pages(handler, harg) 112 | 113 | Calls the provided handler on each free region in the specified 114 | mspace. The memory between start and end are guaranteed not to 115 | contain any important data, so the handler is free to alter the 116 | contents in any way. This can be used to advise the OS that large 117 | free regions may be swapped out. 118 | 119 | The value in harg will be passed to each call of the handler. 120 | */ 121 | void mspace_walk_free_pages(mspace msp, 122 | void(*handler)(void *start, void *end, void *arg), void *harg); 123 | 124 | #ifdef __cplusplus 125 | }; /* end of extern "C" */ 126 | #endif 127 | 128 | #endif /* MSPACE_H_ */ 129 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/WorkQueue.h: -------------------------------------------------------------------------------- 1 | /*] 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _LIBS_UTILS_WORK_QUEUE_H 18 | #define _LIBS_UTILS_WORK_QUEUE_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace android { 25 | 26 | /* 27 | * A threaded work queue. 28 | * 29 | * This class is designed to make it easy to run a bunch of isolated work 30 | * units in parallel, using up to the specified number of threads. 31 | * To use it, write a loop to post work units to the work queue, then synchronize 32 | * on the queue at the end. 33 | */ 34 | class WorkQueue { 35 | public: 36 | class WorkUnit { 37 | public: 38 | WorkUnit() { } 39 | virtual ~WorkUnit() { } 40 | 41 | /* 42 | * Runs the work unit. 43 | * If the result is 'true' then the work queue continues scheduling work as usual. 44 | * If the result is 'false' then the work queue is canceled. 45 | */ 46 | virtual bool run() = 0; 47 | }; 48 | 49 | /* Creates a work queue with the specified maximum number of work threads. */ 50 | WorkQueue(size_t maxThreads, bool canCallJava = true); 51 | 52 | /* Destroys the work queue. 53 | * Cancels pending work and waits for all remaining threads to complete. 54 | */ 55 | ~WorkQueue(); 56 | 57 | /* Posts a work unit to run later. 58 | * If the work queue has been canceled or is already finished, returns INVALID_OPERATION 59 | * and does not take ownership of the work unit (caller must destroy it itself). 60 | * Otherwise, returns OK and takes ownership of the work unit (the work queue will 61 | * destroy it automatically). 62 | * 63 | * For flow control, this method blocks when the size of the pending work queue is more 64 | * 'backlog' times the number of threads. This condition reduces the rate of entry into 65 | * the pending work queue and prevents it from growing much more rapidly than the 66 | * work threads can actually handle. 67 | * 68 | * If 'backlog' is 0, then no throttle is applied. 69 | */ 70 | status_t schedule(WorkUnit *workUnit, size_t backlog = 2); 71 | 72 | /* Cancels all pending work. 73 | * If the work queue is already finished, returns INVALID_OPERATION. 74 | * If the work queue is already canceled, returns OK and does nothing else. 75 | * Otherwise, returns OK, discards all pending work units and prevents additional 76 | * work units from being scheduled. 77 | * 78 | * Call finish() after cancel() to wait for all remaining work to complete. 79 | */ 80 | status_t cancel(); 81 | 82 | /* Waits for all work to complete. 83 | * If the work queue is already finished, returns INVALID_OPERATION. 84 | * Otherwise, waits for all work to complete and returns OK. 85 | */ 86 | status_t finish(); 87 | 88 | private: 89 | class WorkThread : public Thread { 90 | public: 91 | WorkThread(WorkQueue *workQueue, bool canCallJava); 92 | virtual ~WorkThread(); 93 | 94 | private: 95 | virtual bool threadLoop(); 96 | 97 | WorkQueue *const mWorkQueue; 98 | }; 99 | 100 | status_t cancelLocked(); 101 | bool threadLoop(); // called from each work thread 102 | 103 | const size_t mMaxThreads; 104 | const bool mCanCallJava; 105 | 106 | Mutex mLock; 107 | Condition mWorkChangedCondition; 108 | Condition mWorkDequeuedCondition; 109 | 110 | bool mCanceled; 111 | bool mFinished; 112 | size_t mIdleThreads; 113 | Vector > mWorkThreads; 114 | Vector mWorkUnits; 115 | }; 116 | 117 | }; // namespace android 118 | 119 | #endif // _LIBS_UTILS_WORK_QUEUE_H 120 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/core/include/cutils/threads.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _LIBS_CUTILS_THREADS_H 18 | #define _LIBS_CUTILS_THREADS_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /***********************************************************************/ 25 | /***********************************************************************/ 26 | /***** *****/ 27 | /***** local thread storage *****/ 28 | /***** *****/ 29 | /***********************************************************************/ 30 | /***********************************************************************/ 31 | 32 | #ifdef HAVE_PTHREADS 33 | 34 | #include 35 | 36 | typedef struct { 37 | pthread_mutex_t lock; 38 | int has_tls; 39 | pthread_key_t tls; 40 | 41 | } thread_store_t; 42 | 43 | #define THREAD_STORE_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0, 0 } 44 | 45 | #elif defined HAVE_WIN32_THREADS 46 | 47 | #include 48 | 49 | typedef struct { 50 | int lock_init; 51 | int has_tls; 52 | DWORD tls; 53 | CRITICAL_SECTION lock; 54 | 55 | } thread_store_t; 56 | 57 | #define THREAD_STORE_INITIALIZER { 0, 0, 0, {0, 0, 0, 0, 0, 0} } 58 | 59 | #else 60 | # error "no thread_store_t implementation for your platform !!" 61 | #endif 62 | 63 | typedef void (*thread_store_destruct_t)(void *value); 64 | 65 | extern void *thread_store_get(thread_store_t *store); 66 | 67 | extern void thread_store_set(thread_store_t *store, 68 | void *value, 69 | thread_store_destruct_t destroy); 70 | 71 | /***********************************************************************/ 72 | /***********************************************************************/ 73 | /***** *****/ 74 | /***** mutexes *****/ 75 | /***** *****/ 76 | /***********************************************************************/ 77 | /***********************************************************************/ 78 | 79 | #ifdef HAVE_PTHREADS 80 | 81 | typedef pthread_mutex_t mutex_t; 82 | 83 | #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER 84 | 85 | static __inline__ void mutex_lock(mutex_t *lock) { 86 | pthread_mutex_lock(lock); 87 | } 88 | static __inline__ void mutex_unlock(mutex_t *lock) { 89 | pthread_mutex_unlock(lock); 90 | } 91 | static __inline__ int mutex_init(mutex_t *lock) { 92 | return pthread_mutex_init(lock, NULL); 93 | } 94 | static __inline__ void mutex_destroy(mutex_t *lock) { 95 | pthread_mutex_destroy(lock); 96 | } 97 | #endif 98 | 99 | #ifdef HAVE_WIN32_THREADS 100 | typedef struct { 101 | int init; 102 | CRITICAL_SECTION lock[1]; 103 | } mutex_t; 104 | 105 | #define MUTEX_INITIALIZER { 0, {{ NULL, 0, 0, NULL, NULL, 0 }} } 106 | 107 | static __inline__ void mutex_lock(mutex_t *lock) { 108 | if (!lock->init) { 109 | lock->init = 1; 110 | InitializeCriticalSection( lock->lock ); 111 | lock->init = 2; 112 | } else while (lock->init != 2) 113 | Sleep(10); 114 | 115 | EnterCriticalSection(lock->lock); 116 | } 117 | 118 | static __inline__ void mutex_unlock(mutex_t *lock) { 119 | LeaveCriticalSection(lock->lock); 120 | } 121 | static __inline__ int mutex_init(mutex_t *lock) { 122 | InitializeCriticalSection(lock->lock); 123 | lock->init = 2; 124 | return 0; 125 | } 126 | static __inline__ void mutex_destroy(mutex_t *lock) { 127 | if (lock->init) { 128 | lock->init = 0; 129 | DeleteCriticalSection(lock->lock); 130 | } 131 | } 132 | #endif 133 | 134 | #ifdef __cplusplus 135 | } 136 | #endif 137 | 138 | #endif /* _LIBS_CUTILS_THREADS_H */ 139 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/Mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _LIBS_UTILS_MUTEX_H 18 | #define _LIBS_UTILS_MUTEX_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #if defined(HAVE_PTHREADS) 25 | # include 26 | #endif 27 | 28 | #include 29 | 30 | // --------------------------------------------------------------------------- 31 | namespace android { 32 | // --------------------------------------------------------------------------- 33 | 34 | class Condition; 35 | 36 | /* 37 | * Simple mutex class. The implementation is system-dependent. 38 | * 39 | * The mutex must be unlocked by the thread that locked it. They are not 40 | * recursive, i.e. the same thread can't lock it multiple times. 41 | */ 42 | class Mutex { 43 | public: 44 | enum { 45 | PRIVATE = 0, 46 | SHARED = 1 47 | }; 48 | 49 | Mutex(); 50 | Mutex(const char *name); 51 | Mutex(int type, const char *name = NULL); 52 | ~Mutex(); 53 | 54 | // lock or unlock the mutex 55 | status_t lock(); 56 | void unlock(); 57 | 58 | // lock if possible; returns 0 on success, error otherwise 59 | status_t tryLock(); 60 | 61 | // Manages the mutex automatically. It'll be locked when Autolock is 62 | // constructed and released when Autolock goes out of scope. 63 | class Autolock { 64 | public: 65 | inline Autolock(Mutex &mutex) : mLock(mutex) { 66 | mLock.lock(); 67 | } 68 | inline Autolock(Mutex *mutex) : mLock(*mutex) { 69 | mLock.lock(); 70 | } 71 | inline ~Autolock() { 72 | mLock.unlock(); 73 | } 74 | private: 75 | Mutex &mLock; 76 | }; 77 | 78 | private: 79 | friend class Condition; 80 | 81 | // A mutex cannot be copied 82 | Mutex(const Mutex &); 83 | Mutex &operator = (const Mutex &); 84 | 85 | #if defined(HAVE_PTHREADS) 86 | pthread_mutex_t mMutex; 87 | #else 88 | void _init(); 89 | void *mState; 90 | #endif 91 | }; 92 | 93 | // --------------------------------------------------------------------------- 94 | 95 | #if defined(HAVE_PTHREADS) 96 | 97 | inline Mutex::Mutex() { 98 | pthread_mutex_init(&mMutex, NULL); 99 | } 100 | inline Mutex::Mutex(const char *name) { 101 | pthread_mutex_init(&mMutex, NULL); 102 | } 103 | inline Mutex::Mutex(int type, const char *name) { 104 | if (type == SHARED) { 105 | pthread_mutexattr_t attr; 106 | pthread_mutexattr_init(&attr); 107 | pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); 108 | pthread_mutex_init(&mMutex, &attr); 109 | pthread_mutexattr_destroy(&attr); 110 | } else { 111 | pthread_mutex_init(&mMutex, NULL); 112 | } 113 | } 114 | inline Mutex::~Mutex() { 115 | pthread_mutex_destroy(&mMutex); 116 | } 117 | inline status_t Mutex::lock() { 118 | return -pthread_mutex_lock(&mMutex); 119 | } 120 | inline void Mutex::unlock() { 121 | pthread_mutex_unlock(&mMutex); 122 | } 123 | inline status_t Mutex::tryLock() { 124 | return -pthread_mutex_trylock(&mMutex); 125 | } 126 | 127 | #endif // HAVE_PTHREADS 128 | 129 | // --------------------------------------------------------------------------- 130 | 131 | /* 132 | * Automatic mutex. Declare one of these at the top of a function. 133 | * When the function returns, it will go out of scope, and release the 134 | * mutex. 135 | */ 136 | 137 | typedef Mutex::Autolock AutoMutex; 138 | 139 | // --------------------------------------------------------------------------- 140 | }; // namespace android 141 | // --------------------------------------------------------------------------- 142 | 143 | #endif // _LIBS_UTILS_MUTEX_H 144 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/Thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _LIBS_UTILS_THREAD_H 18 | #define _LIBS_UTILS_THREAD_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #if defined(HAVE_PTHREADS) 25 | # include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | // --------------------------------------------------------------------------- 36 | namespace android { 37 | // --------------------------------------------------------------------------- 38 | 39 | class Thread : virtual public RefBase { 40 | public: 41 | // Create a Thread object, but doesn't create or start the associated 42 | // thread. See the run() method. 43 | Thread(bool canCallJava = true); 44 | virtual ~Thread(); 45 | 46 | // Start the thread in threadLoop() which needs to be implemented. 47 | virtual status_t run( const char *name = 0, 48 | int32_t priority = PRIORITY_DEFAULT, 49 | size_t stack = 0); 50 | 51 | // Ask this object's thread to exit. This function is asynchronous, when the 52 | // function returns the thread might still be running. Of course, this 53 | // function can be called from a different thread. 54 | virtual void requestExit(); 55 | 56 | // Good place to do one-time initializations 57 | virtual status_t readyToRun(); 58 | 59 | // Call requestExit() and wait until this object's thread exits. 60 | // BE VERY CAREFUL of deadlocks. In particular, it would be silly to call 61 | // this function from this object's thread. Will return WOULD_BLOCK in 62 | // that case. 63 | status_t requestExitAndWait(); 64 | 65 | // Wait until this object's thread exits. Returns immediately if not yet running. 66 | // Do not call from this object's thread; will return WOULD_BLOCK in that case. 67 | status_t join(); 68 | 69 | #ifdef HAVE_ANDROID_OS 70 | // Return the thread's kernel ID, same as the thread itself calling gettid() or 71 | // androidGetTid(), or -1 if the thread is not running. 72 | pid_t getTid() const; 73 | #endif 74 | 75 | protected: 76 | // exitPending() returns true if requestExit() has been called. 77 | bool exitPending() const; 78 | 79 | private: 80 | // Derived class must implement threadLoop(). The thread starts its life 81 | // here. There are two ways of using the Thread object: 82 | // 1) loop: if threadLoop() returns true, it will be called again if 83 | // requestExit() wasn't called. 84 | // 2) once: if threadLoop() returns false, the thread will exit upon return. 85 | virtual bool threadLoop() = 0; 86 | 87 | private: 88 | Thread &operator=(const Thread &); 89 | static int _threadLoop(void *user); 90 | const bool mCanCallJava; 91 | // always hold mLock when reading or writing 92 | thread_id_t mThread; 93 | mutable Mutex mLock; 94 | Condition mThreadExitedCondition; 95 | status_t mStatus; 96 | // note that all accesses of mExitPending and mRunning need to hold mLock 97 | volatile bool mExitPending; 98 | volatile bool mRunning; 99 | sp mHoldSelf; 100 | #ifdef HAVE_ANDROID_OS 101 | // legacy for debugging, not used by getTid() as it is set by the child thread 102 | // and so is not initialized until the child reaches that point 103 | pid_t mTid; 104 | #endif 105 | }; 106 | 107 | 108 | }; // namespace android 109 | 110 | // --------------------------------------------------------------------------- 111 | #endif // _LIBS_UTILS_THREAD_H 112 | // --------------------------------------------------------------------------- 113 | -------------------------------------------------------------------------------- /zipalign/src/main/cpp/android/native/include/utils/BitSet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef UTILS_BITSET_H 18 | #define UTILS_BITSET_H 19 | 20 | #include 21 | #include 22 | 23 | /* 24 | * Contains some bit manipulation helpers. 25 | */ 26 | 27 | namespace android { 28 | 29 | // A simple set of 32 bits that can be individually marked or cleared. 30 | struct BitSet32 { 31 | uint32_t value; 32 | 33 | inline BitSet32() : value(0) { } 34 | explicit inline BitSet32(uint32_t value) : value(value) { } 35 | 36 | // Gets the value associated with a particular bit index. 37 | static inline uint32_t valueForBit(uint32_t n) { 38 | return 0x80000000 >> n; 39 | } 40 | 41 | // Clears the bit set. 42 | inline void clear() { 43 | value = 0; 44 | } 45 | 46 | // Returns the number of marked bits in the set. 47 | inline uint32_t count() const { 48 | return __builtin_popcount(value); 49 | } 50 | 51 | // Returns true if the bit set does not contain any marked bits. 52 | inline bool isEmpty() const { 53 | return ! value; 54 | } 55 | 56 | // Returns true if the bit set does not contain any unmarked bits. 57 | inline bool isFull() const { 58 | return value == 0xffffffff; 59 | } 60 | 61 | // Returns true if the specified bit is marked. 62 | inline bool hasBit(uint32_t n) const { 63 | return value & valueForBit(n); 64 | } 65 | 66 | // Marks the specified bit. 67 | inline void markBit(uint32_t n) { 68 | value |= valueForBit(n); 69 | } 70 | 71 | // Clears the specified bit. 72 | inline void clearBit(uint32_t n) { 73 | value &= ~ valueForBit(n); 74 | } 75 | 76 | // Finds the first marked bit in the set. 77 | // Result is undefined if all bits are unmarked. 78 | inline uint32_t firstMarkedBit() const { 79 | return __builtin_clz(value); 80 | } 81 | 82 | // Finds the first unmarked bit in the set. 83 | // Result is undefined if all bits are marked. 84 | inline uint32_t firstUnmarkedBit() const { 85 | return __builtin_clz(~ value); 86 | } 87 | 88 | // Finds the last marked bit in the set. 89 | // Result is undefined if all bits are unmarked. 90 | inline uint32_t lastMarkedBit() const { 91 | return 31 - __builtin_ctz(value); 92 | } 93 | 94 | // Finds the first marked bit in the set and clears it. Returns the bit index. 95 | // Result is undefined if all bits are unmarked. 96 | inline uint32_t clearFirstMarkedBit() { 97 | uint32_t n = firstMarkedBit(); 98 | clearBit(n); 99 | return n; 100 | } 101 | 102 | // Finds the first unmarked bit in the set and marks it. Returns the bit index. 103 | // Result is undefined if all bits are marked. 104 | inline uint32_t markFirstUnmarkedBit() { 105 | uint32_t n = firstUnmarkedBit(); 106 | markBit(n); 107 | return n; 108 | } 109 | 110 | // Finds the last marked bit in the set and clears it. Returns the bit index. 111 | // Result is undefined if all bits are unmarked. 112 | inline uint32_t clearLastMarkedBit() { 113 | uint32_t n = lastMarkedBit(); 114 | clearBit(n); 115 | return n; 116 | } 117 | 118 | // Gets the index of the specified bit in the set, which is the number of 119 | // marked bits that appear before the specified bit. 120 | inline uint32_t getIndexOfBit(uint32_t n) const { 121 | return __builtin_popcount(value & ~(0xffffffffUL >> n)); 122 | } 123 | 124 | inline bool operator== (const BitSet32 &other) const { 125 | return value == other.value; 126 | } 127 | inline bool operator!= (const BitSet32 &other) const { 128 | return value != other.value; 129 | } 130 | }; 131 | 132 | ANDROID_BASIC_TYPES_TRAITS(BitSet32) 133 | 134 | } // namespace android 135 | 136 | #endif // UTILS_BITSET_H 137 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 9 | 11 | 13 | 15 | 17 | 19 | 21 | 23 | 25 | 27 | 29 | 31 | 33 | 35 | 37 | 39 | 41 | 43 | 45 | 47 | 49 | 51 | 53 | 55 | 57 | 59 | 61 | 63 | 65 | 67 | 69 | 70 | --------------------------------------------------------------------------------