这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
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
29 changes: 1 addition & 28 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,34 +1,7 @@
# .gitignore from https://gist.github.com/iainconnor/8605514:

# Built application files
build/

# Crashlytics configuations
com_crashlytics_export_strings.xml

# Local configuration file (sdk path, etc)
local.properties

# Gradle generated files
.gradle/

# Signing files
.signing/

# User-specific configurations
.idea/libraries/
.idea/workspace.xml
.idea/tasks.xml
.idea/.name
.idea/compiler.xml
.idea/copyright/profiles_settings.xml
.idea/encodings.xml
.idea/misc.xml
.idea/modules.xml
.idea/scopes/scope_settings.xml
.idea/vcs.xml
.idea/caches/
.idea/codeStyles/
.idea/
*.iml

# OS-specific files
Expand Down
19 changes: 0 additions & 19 deletions .idea/gradle.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ Termux API
This is an app exposing Android API to command line usage and scripts or programs.

- [Termux:API on Google Play](https://play.google.com/store/apps/details?id=com.termux.api)
- [Termux:API on F-Droid](https://f-droid.org/packages/com.termux.api)

When developing or packaging, note that this app needs to be signed with the same key as the main Termux app for permissions to work (only the main Termux app are allowed to call the API methods in this app).

License
=======
Released under the [GPLv3 license](http://www.gnu.org/licenses/gpl-3.0.en.html).
Released under the [GPLv3 license](https://www.gnu.org/licenses/gpl-3.0.html).

How API calls are made through the termux-api helper binary
===========================================================
Expand Down
13 changes: 9 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 28

buildToolsVersion '28.0.2'
defaultConfig {
applicationId "com.termux.api"
minSdkVersion 21
Expand All @@ -14,11 +14,16 @@ android {
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation 'com.android.support:design:27.1.1'
}
implementation 'com.android.support:design:28.0.0-rc02'
}
72 changes: 47 additions & 25 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
package="com.termux.api"
android:sharedUserId="com.termux">

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

<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_SMS" />
Expand All @@ -23,7 +25,8 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"
<uses-permission
android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />

Expand All @@ -40,7 +43,9 @@

<!-- 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="com.termux.sharedfiles.READ"
android:protectionLevel="signature" />

<application
android:allowBackup="true"
Expand All @@ -50,32 +55,50 @@
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=".FingerprintAPI$FingerprintActivity" android:theme="@android:style/Theme.NoDisplay"
android:noHistory="true"
android:excludeFromRecents="true"
android:exported="false"/>
<activity android:name="com.termux.api.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"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:excludeFromRecents="true"
android:exported="false"/>
<service android:name="com.termux.api.SpeechToTextAPI$SpeechToTextService"/>
<receiver android:name="com.termux.api.TermuxApiReceiver" />

<activity
android:name="com.termux.api.DialogActivity"
android:excludeFromRecents="true"
android:exported="false"
android:noHistory="true"
android:theme="@style/DialogTheme" />
<activity
android:name=".FingerprintAPI$FingerprintActivity"
android:excludeFromRecents="true"
android:exported="false"
android:noHistory="true"
android:theme="@android:style/Theme.NoDisplay" />
<activity
android:name="com.termux.api.util.TermuxApiPermissionActivity"
android:excludeFromRecents="true"
android:exported="false"
android:noHistory="true"
android:theme="@android:style/Theme.NoDisplay" />
<activity
android:name="com.termux.api.StorageGetAPI$StorageActivity"
android:excludeFromRecents="true"
android:exported="false"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />

<service android:name="com.termux.api.SpeechToTextAPI$SpeechToTextService" />
<service android:name="com.termux.api.TextToSpeechAPI$TextToSpeechService" />
<service android:name=".SensorAPI$SensorReaderService"/>
<provider android:authorities="com.termux.sharedfiles"
<service android:name=".SensorAPI$SensorReaderService" />

<provider
android:authorities="com.termux.sharedfiles"
android:readPermission="com.termux.sharedfiles.READ"
android:exported="true"
android:grantUriPermissions="true"
android:name="com.termux.api.ShareAPI$ContentProvider" />
<service android:name=".MediaPlayerAPI$PlayerService" android:exported="false"/>
<service android:name=".MicRecorderAPI$MicRecorderService" android:exported="false"/>
<service android:name=".WallpaperAPI$WallpaperService"/>

<service
android:name=".MediaPlayerAPI$PlayerService"
android:exported="false" />
<service
android:name=".MicRecorderAPI$MicRecorderService"
android:exported="false" />
<service android:name=".WallpaperAPI$WallpaperService" />
<service
android:name=".NotificationService"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
Expand All @@ -87,5 +110,4 @@
</intent-filter>
</service>
</application>

</manifest>
37 changes: 18 additions & 19 deletions app/src/main/java/com/termux/api/AudioAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,41 @@ static void onReceive(TermuxApiReceiver apiReceiver, final Context context, Inte
nosr = 0;
AudioTrack at;
at = new AudioTrack.Builder()
.setBufferSizeInBytes(4) // one 16bit 2ch frame
.build();
.setBufferSizeInBytes(4) // one 16bit 2ch frame
.build();
sr = at.getSampleRate();
bs = at.getBufferSizeInFrames();
at.release();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
at = new AudioTrack.Builder()
.setBufferSizeInBytes(4) // one 16bit 2ch frame
.setPerformanceMode(AudioTrack.PERFORMANCE_MODE_LOW_LATENCY)
.build();
.setBufferSizeInBytes(4) // one 16bit 2ch frame
.setPerformanceMode(AudioTrack.PERFORMANCE_MODE_LOW_LATENCY)
.build();
} else {
AudioAttributes aa = new AudioAttributes.Builder()
.setFlags(AudioAttributes.FLAG_LOW_LATENCY)
.build();
.setFlags(AudioAttributes.FLAG_LOW_LATENCY)
.build();
at = new AudioTrack.Builder()
.setAudioAttributes(aa)
.setBufferSizeInBytes(4) // one 16bit 2ch frame
.build();
.setAudioAttributes(aa)
.setBufferSizeInBytes(4) // one 16bit 2ch frame
.build();
}
sr_ll = at.getSampleRate();
bs_ll = at.getBufferSizeInFrames();
at.release();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
at = new AudioTrack.Builder()
.setBufferSizeInBytes(4) // one 16bit 2ch frame
.setPerformanceMode(AudioTrack.PERFORMANCE_MODE_POWER_SAVING)
.build();
sr_ps = at.getSampleRate();
bs_ps = at.getBufferSizeInFrames();
at.release();
.setBufferSizeInBytes(4) // one 16bit 2ch frame
.setPerformanceMode(AudioTrack.PERFORMANCE_MODE_POWER_SAVING)
.build();
sr_ps = at.getSampleRate();
bs_ps = at.getBufferSizeInFrames();
at.release();
} else {
sr_ps = sr;
bs_ps = bs;
sr_ps = sr;
bs_ps = bs;
}
} else {
sr = bs = sr_ll = bs_ll = sr_ps = bs_ps = 0;
Expand Down Expand Up @@ -90,5 +90,4 @@ public void writeJson(JsonWriter out) throws Exception {
}
});
}

}
47 changes: 33 additions & 14 deletions app/src/main/java/com/termux/api/CallLogAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.provider.CallLog;
import android.support.v4.app.ActivityCompat;
import android.util.JsonWriter;

import com.termux.api.util.ResultReturner;
Expand All @@ -18,7 +20,7 @@
/**
* API that allows you to get call log history information
*/
public class CallLogAPI {
public abstract class CallLogAPI extends Context {

static void onReceive(final Context context, final Intent intent) {
final int offset = intent.getIntExtra("offset", 0);
Expand All @@ -32,10 +34,39 @@ public void writeJson(JsonWriter out) throws Exception {

}

private static void getCallLogs(Context context, JsonWriter out, int offset, int limit) throws IOException {
private static String getCallTypeString(int type) {
switch (type) {
case CallLog.Calls.BLOCKED_TYPE:
return "BLOCKED";
case CallLog.Calls.INCOMING_TYPE:
return "INCOMING";
case CallLog.Calls.MISSED_TYPE:
return "MISSED";
case CallLog.Calls.OUTGOING_TYPE:
return "OUTGOING";
case CallLog.Calls.REJECTED_TYPE:
return "REJECTED";
case CallLog.Calls.VOICEMAIL_TYPE:
return "VOICEMAIL";
default:
return "UNKNOWN_TYPE";
}
}

private void getCallLogs(Context context, JsonWriter out, int offset, int limit) throws IOException {
ContentResolver cr = context.getContentResolver();
String sortOrder = "date DESC LIMIT + " + limit + " OFFSET " + offset;

if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
try (Cursor cur = cr.query(CallLog.Calls.CONTENT_URI, null, null, null, sortOrder)) {
cur.moveToLast();

Expand Down Expand Up @@ -64,18 +95,6 @@ private static void getCallLogs(Context context, JsonWriter out, int offset, int
}
}

private static String getCallTypeString(int type) {
switch (type) {
case CallLog.Calls.BLOCKED_TYPE: return "BLOCKED";
case CallLog.Calls.INCOMING_TYPE: return "INCOMING";
case CallLog.Calls.MISSED_TYPE: return "MISSED";
case CallLog.Calls.OUTGOING_TYPE: return "OUTGOING";
case CallLog.Calls.REJECTED_TYPE: return "REJECTED";
case CallLog.Calls.VOICEMAIL_TYPE: return "VOICEMAIL";
default: return "UNKNOWN_TYPE";
}
}

private static String getCallerNameString(String name) {
return name == null ? "UNKNOWN_CALLER" : name;
}
Expand Down
Loading