这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/attach_debug_apks_to_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Attach Debug APKs To Release

on:
release:
types:
- published

jobs:
attach-apks:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Clone repository
uses: actions/checkout@v2
with:
ref: ${{ env.GITHUB_REF }}
- name: Set vars
run: |
RELEASE_VERSION_NAME="${GITHUB_REF/refs\/tags\//}"
if ! printf "%s" "${RELEASE_VERSION_NAME/v/}" | grep -qP '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'; then
echo "The versionName '${RELEASE_VERSION_NAME/v/}' is not a valid version as per semantic version '2.0.0' spec in the format 'major.minor.patch(-prerelease)(+buildmetadata)'. https://semver.org/spec/v2.0.0.html."
exit 1
fi
echo "TERMUX_API_RELEASE_TAG=$RELEASE_VERSION_NAME" >> $GITHUB_ENV
echo "TERMUX_API_APK_VERSION_TAG=$RELEASE_VERSION_NAME+github-debug" >> $GITHUB_ENV # Used by app/build.gradle
- name: Echo release
run: echo "Attaching debug APK to '${{ env.TERMUX_API_RELEASE_TAG }}' release"
- name: Build
run: ./gradlew assembleDebug
- name: Attach APKs to release
run: >-
hub release edit
-m ""
-a "./app/build/outputs/apk/debug/termux-api_${{ env.TERMUX_API_APK_VERSION_TAG }}.apk"
"${{ env.TERMUX_API_RELEASE_TAG }}"
31 changes: 21 additions & 10 deletions .github/workflows/debug_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Build
run: |
./gradlew assembleDebug
- name: Store generated APK file
uses: actions/upload-artifact@v2
with:
name: termux-api
path: ./app/build/outputs/apk/debug/app-debug.apk
- name: Clone repository
uses: actions/checkout@v2
- name: Set vars
run: |
# Set NEW_VERSION_NAME to "<CURRENT_VERSION_NAME>+<last_commit_hash>"
CURRENT_VERSION_NAME_REGEX='\s+versionName "([^"]+)"$'
CURRENT_VERSION_NAME="$(grep -m 1 -E "$CURRENT_VERSION_NAME_REGEX" ./app/build.gradle | sed -r "s/$CURRENT_VERSION_NAME_REGEX/\1/")"
NEW_VERSION_NAME="$CURRENT_VERSION_NAME+${GITHUB_SHA:0:7}"
echo "TERMUX_WIDGET_APP_VERSION_NAME=$NEW_VERSION_NAME" >> $GITHUB_ENV # Used by app/build.gradle
echo "TERMUX_WIDGET_APK_VERSION_TAG=v$NEW_VERSION_NAME-github-debug" >> $GITHUB_ENV # Used by app/build.gradle
- name: Echo version
run: echo "Building APK for '$TERMUX_WIDGET_APP_VERSION_NAME'"
- name: Build
run: ./gradlew assembleDebug
- name: Store generated APK file
uses: actions/upload-artifact@v2
with:
name: termux-api
path: |
./app/build/outputs/apk/debug/termux-api_${{ env.TERMUX_WIDGET_APK_VERSION_TAG }}.apk
./app/build/outputs/apk/debug/output-metadata.json
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# .gitignore from https://gist.github.com/iainconnor/8605514:

# Built application files
build/
release/
*.apk
*.so
.externalNativeBuild
.cxx
*.zip

# Crashlytics configuations
com_crashlytics_export_strings.xml
Expand Down
48 changes: 38 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 30
compileSdkVersion project.properties.compileSdkVersion.toInteger()
def appVersionName = System.getenv("TERMUX_API_APP_VERSION_NAME") ?: ""
def apkVersionTag = System.getenv("TERMUX_API_APK_VERSION_TAG") ?: ""

defaultConfig {
applicationId "com.termux.api"
minSdkVersion 24
targetSdkVersion 28
minSdkVersion project.properties.minSdkVersion.toInteger()
targetSdkVersion project.properties.targetSdkVersion.toInteger()
versionCode 49
versionName "0.49"
versionName "0.49.0"

if (appVersionName) versionName = appVersionName
validateVersionName(versionName)

manifestPlaceholders.TERMUX_PACKAGE_NAME = "com.termux"
manifestPlaceholders.TERMUX_APP_NAME = "Termux"
manifestPlaceholders.TERMUX_API_APP_NAME = "Termux:API"
}

signingConfigs {
Expand All @@ -22,7 +31,8 @@ android {

buildTypes {
release {
minifyEnabled false
minifyEnabled true
shrinkResources false // Reproducible builds
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}

Expand All @@ -36,19 +46,37 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}

applicationVariants.all { variant ->
variant.outputs.all { output ->
if (variant.buildType.name == "debug") {
outputFileName = new File("termux-api_" + (apkVersionTag ? apkVersionTag : "debug") + ".apk")
} else if (variant.buildType.name == "release") {
outputFileName = new File("termux-api_" + (apkVersionTag ? apkVersionTag : "release") + ".apk")
}
}
}

lintOptions {
disable 'ExpiredTargetSdkVersion'
}
}

dependencies {
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.biometric:biometric:1.2.0-alpha02'
implementation 'androidx.media:media:1.4.1'
implementation 'androidx.biometric:biometric:1.2.0-alpha03'
implementation 'androidx.media:media:1.4.3'
implementation 'com.termux.termux-app:termux-shared:f3ffc36bfd'
}

task versionName {
doLast {
print android.defaultConfig.versionName
}
doLast {
print android.defaultConfig.versionName
}
}

def validateVersionName(String versionName) {
// https://semver.org/spec/v2.0.0.html#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
// ^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$
if (!java.util.regex.Pattern.matches("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?\$", versionName))
throw new GradleException("The versionName '" + versionName + "' is not a valid version as per semantic version '2.0.0' spec in the format 'major.minor.patch(-prerelease)(+buildmetadata)'. https://semver.org/spec/v2.0.0.html.")
}
10 changes: 10 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in android-sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

-dontobfuscate
25 changes: 13 additions & 12 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.termux.api"
android:sharedUserId="com.termux">
android:sharedUserId="${TERMUX_PACKAGE_NAME}">

<uses-feature android:name="android.hardware.touchscreen" android:required="false" />

Expand Down Expand Up @@ -48,18 +48,19 @@

<!-- This permission is not used, but a permission is needed on the sharedfiles contentprovider,
which will always use FLAG_GRANT_READ_URI_PERMISSION. -->
<permission android:name="com.termux.sharedfiles.READ" android:protectionLevel="signature" />
<permission android:name="${TERMUX_PACKAGE_NAME}.sharedfiles.READ" android:protectionLevel="signature" />

<application
android:name=".TermuxAPIApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.Material.Light"
tools:ignore="GoogleAppIndexingWarning">
<receiver android:name="com.termux.api.TermuxApiReceiver"/>
<activity android:name="com.termux.api.DialogActivity" android:theme="@style/DialogTheme" android:noHistory="true" android:excludeFromRecents="true" android:exported="false"/>
<activity android:name="com.termux.api.NfcActivity" android:theme="@style/DialogTheme" android:noHistory="true" android:excludeFromRecents="true" android:exported="false" >
<receiver android:name=".TermuxApiReceiver"/>
<activity android:name=".DialogActivity" android:theme="@style/DialogTheme" android:noHistory="true" android:excludeFromRecents="true" android:exported="false"/>
<activity android:name=".NfcActivity" android:theme="@style/DialogTheme" android:noHistory="true" android:excludeFromRecents="true" android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
Expand All @@ -72,23 +73,23 @@
android:noHistory="true"
android:excludeFromRecents="true"
android:exported="false"/>
<activity android:name="com.termux.api.util.TermuxApiPermissionActivity"
<activity android:name=".util.TermuxApiPermissionActivity"
android:theme="@android:style/Theme.NoDisplay"
android:noHistory="true"
android:excludeFromRecents="true"
android:exported="false"/>
<activity android:name="com.termux.api.StorageGetAPI$StorageActivity"
<activity android:name=".StorageGetAPI$StorageActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:excludeFromRecents="true"
android:exported="false"/>
<service android:name="com.termux.api.SpeechToTextAPI$SpeechToTextService"/>
<service android:name="com.termux.api.TextToSpeechAPI$TextToSpeechService" />
<service android:name=".SpeechToTextAPI$SpeechToTextService"/>
<service android:name=".TextToSpeechAPI$TextToSpeechService" />
<service android:name=".SensorAPI$SensorReaderService"/>
<provider android:authorities="com.termux.sharedfiles"
android:readPermission="com.termux.sharedfiles.READ"
<provider android:authorities="${TERMUX_PACKAGE_NAME}.sharedfiles"
android:readPermission="${TERMUX_PACKAGE_NAME}.sharedfiles.READ"
android:exported="true"
android:grantUriPermissions="true"
android:name="com.termux.api.ShareAPI$ContentProvider" />
android:name=".ShareAPI$ContentProvider" />
<service android:name=".MediaPlayerAPI$PlayerService" android:exported="false"/>
<service android:name=".MicRecorderAPI$MicRecorderService" android:exported="false"/>
<service android:name=".WallpaperAPI$WallpaperService"/>
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/com/termux/api/DialogActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
import java.util.Objects;
import java.util.Properties;

import static com.termux.shared.termux.TermuxConstants.TERMUX_PROPERTIES_PRIMARY_FILE_PATH;
import static com.termux.shared.termux.TermuxConstants.TERMUX_PROPERTIES_SECONDARY_FILE_PATH;

/**
* API that allows receiving user input interactively in a variety of different ways
*/
Expand All @@ -65,10 +68,10 @@ public class DialogActivity extends AppCompatActivity {
private boolean resultReturned = false;

protected boolean getBlackUI() {
File propsFile = new File("/data/data/com.termux/files/home/.termux/termux.properties");
File propsFile = new File(TERMUX_PROPERTIES_PRIMARY_FILE_PATH);

if (!propsFile.exists())
propsFile = new File("/data/data/com.termux/files/home/.config/termux.properties");
propsFile = new File(TERMUX_PROPERTIES_SECONDARY_FILE_PATH);

boolean mUseBlackUi = false;

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/termux/api/NotificationAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
import java.util.Objects;
import java.util.UUID;

import static com.termux.shared.termux.TermuxConstants.TERMUX_PREFIX_DIR_PATH;

public class NotificationAPI {

public static final String TERMUX_SERVICE = "com.termux.app.TermuxService";
public static final String ACTION_EXECUTE = "com.termux.service_execute";
public static final String EXTRA_ARGUMENTS = "com.termux.execute.arguments";
public static final String BIN_SH = "/data/data/com.termux/files/usr/bin/sh";
public static final String BIN_SH = TERMUX_PREFIX_DIR_PATH+"/bin/sh";
private static final String EXTRA_EXECUTE_IN_BACKGROUND = "com.termux.execute.background";
private static final String CHANNEL_ID = "termux-notification";
private static final String CHANNEL_TITLE = "Termux API notification channel";
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/com/termux/api/TermuxAPIApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.termux.api;

import android.app.Application;
import android.content.Context;

import com.termux.shared.crash.TermuxCrashUtils;
import com.termux.shared.logger.Logger;
import com.termux.shared.settings.preferences.TermuxAPIAppSharedPreferences;


public class TermuxAPIApplication extends Application {

public void onCreate() {
super.onCreate();

// Set crash handler for the app
TermuxCrashUtils.setCrashHandler(this);

// Set log config for the app
setLogLevel(getApplicationContext(), true);

Logger.logDebug("Starting Application");
}

public static void setLogLevel(Context context, boolean commitToFile) {
// Load the log level from shared preferences and set it to the {@link Logger.CURRENT_LOG_LEVEL}
TermuxAPIAppSharedPreferences preferences = TermuxAPIAppSharedPreferences.build(context);
if (preferences == null) return;
preferences.setLogLevel(null, preferences.getLogLevel(true), commitToFile);
}

}
12 changes: 10 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE resources [
<!ENTITY TERMUX_PACKAGE_NAME "com.termux">
<!ENTITY TERMUX_APP_NAME "Termux">
<!ENTITY TERMUX_API_APP_NAME "Termux:API">
<!ENTITY TERMUX_PREFIX_DIR_PATH "/data/data/com.termux/files/usr">
]>

<resources>
<string name="app_name">Termux:API</string>
<string name="app_name">&TERMUX_API_APP_NAME;</string>
<string name="share_file_chooser_title">Share with</string>
<string name="grant_permission">Grant permission</string>

<string name="permission_description">Termux:API needs the following permission(s):\n</string>
<string name="permission_description">This app needs the following permission(s):\n</string>
</resources>
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ allprojects {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
}

Expand Down
6 changes: 5 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ org.gradle.jvmargs=-Xmx2048M
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.enableJetifier=true
android.useAndroidX=true
android.useAndroidX=true

minSdkVersion=24
targetSdkVersion=28
compileSdkVersion=30
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists