Skip to content

Commit

Permalink
Changed: Use termux-shared
Browse files Browse the repository at this point in the history
- All hardcoded `com.termux` constants have been removed and will be handled by `TermuxConstants` and `TermuxPreferenceConstants`.
- Use extra constants returned by `TermuxService` defined in `TermuxConstants` for `PluginUtils`.
- Use `FileUtils` and `TermuxFileUtils` provided by `termux-shared` to handle all file related functionality which has better, safer and more updated code.
- Use `TermuxTaskerAppSharedPreferences` provided by `termux-shared` for handling `SharedPreferences` functionality.
- Use `Logger` provided by `termux-shared` for logging. Log level will not be got from `SharedPreferences` for each log entry but will be loaded from `SharedPreferences` into the `Logger.CURRENT_LOG_LEVEL` variable at application startup and also in `FireReceiver` which runs as a separate process and maintains separate `Logger` instance. The `termux-app` can also set the log level from its settings.
- Fix issue where log level was not being read from file, which has been fixed in `TermuxTaskerAppSharedPreferences` in upstream.
- Added crash handler so that crash notifications can be shown in `termux-app` at startup.
- Fix javadocs.
- Move functions to `PluginUtils` from `PluginResultsService`. The `Context` requirement is gone too since `Logger` doesn't need it.
- Previously working directory would only be created automatically if it was under `TermuxConstants.TERMUX_HOME_DIR_PATH` but now it will be created even if its under `TermuxConstants.TERMUX_FILES_DIR_PATH`.
- Catch exceptions thrown by `startService()` `startForegroundService()` when sending intent to `TermuxService` for execution.
- Use `ExecutionCommand` class to handle intent extras in `FireReceiver` since they are consistent with that of `TermuxService` `ACTION_SERVICE_EXECUTE` intent.
- Use `TermuxUtils` and `PackageUtils` provided by `termux-shared` and remove existing `TermuxUtils`. The `TermuxUtils.isTermuxAppAccessible()` will also check if `termux-tasker` can access `termux-app` package `Context`.
  • Loading branch information
agnostic-apollo committed Sep 5, 2021
1 parent 552d592 commit 63e7645
Show file tree
Hide file tree
Showing 22 changed files with 803 additions and 1,243 deletions.
28 changes: 20 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
compileSdkVersion project.properties.compileSdkVersion.toInteger()
defaultConfig {
applicationId "com.termux.tasker"
minSdkVersion 24
targetSdkVersion 28
minSdkVersion project.properties.minSdkVersion.toInteger()
targetSdkVersion project.properties.targetSdkVersion.toInteger()
versionCode 5
versionName "0.5"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'

manifestPlaceholders.TERMUX_PACKAGE_NAME = "com.termux"
manifestPlaceholders.TERMUX_APP_NAME = "Termux"
manifestPlaceholders.TERMUX_TASKER_APP_NAME = "Termux:Tasker"
}

signingConfigs {
Expand Down Expand Up @@ -40,12 +44,20 @@ android {
}

dependencies {
implementation 'com.google.android.material:material:1.2.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'

implementation "androidx.annotation:annotation:1.2.0"
implementation 'com.google.android.material:material:1.4.0'
implementation 'com.google.guava:guava:24.1-jre'

implementation 'com.termux.termux-app:termux-shared:f00738fe3a'

testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test:rules:1.3.0'
// Use if below libraries are published locally by termux-app with `./gradlew publishReleasePublicationToMavenLocal` and used with `mavenLocal()`.
// If updates are done, republish there and sync project with gradle files here
//implementation 'com.termux:termux-shared:0.117'
}

task versionName {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner;

import com.termux.shared.termux.TermuxConstants;

import org.junit.Test;
import org.junit.runner.RunWith;

Expand All @@ -22,6 +24,6 @@ public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

assertEquals("com.termux.tasker", appContext.getPackageName());
assertEquals(TermuxConstants.TERMUX_TASKER_PACKAGE_NAME, appContext.getPackageName());
}
}
18 changes: 11 additions & 7 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.termux.tasker"
android:sharedUserId="com.termux">
android:sharedUserId="${TERMUX_PACKAGE_NAME}"
android:sharedUserLabel="@string/shared_user_label" >

<application
android:allowBackup="true"
android:name=".TermuxTaskerApplication"
android:label="@string/application_name"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"

android:allowBackup="true"
android:fullBackupOnly="false"
android:supportsRtl="true" >

<!--
This is the "edit" Activity. Note that Locale will reject plug-in Activities for the following reasons:·
Expand Down Expand Up @@ -42,7 +46,7 @@
android:name=".FireReceiver"
android:exported="true"
android:process=":background"
android:permission="com.termux.permission.RUN_COMMAND">
android:permission="${TERMUX_PACKAGE_NAME}.permission.RUN_COMMAND">
<!-- This Intent filter allows the plug-in to discovered by Locale. -->
<intent-filter>
<action android:name="com.twofortyfouram.locale.intent.action.FIRE_SETTING" />
Expand All @@ -52,7 +56,7 @@
<!--
This is service that will receive execution result from the execution service via a PendingIntent
-->
<service android:name=".PluginResultsService"/>
<service android:name=".PluginResultsService" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import android.view.Menu;
import android.view.MenuItem;

import com.termux.tasker.utils.Logger;

/**
* Superclass for plug-in Activities. This class takes care of initializing aspects of the plug-in's UI to
* look more integrated with the plug-in host.
Expand Down Expand Up @@ -51,7 +49,8 @@ public boolean onOptionsItemSelected(final MenuItem item) {
* During {@link #finish()}, subclasses can call this method to determine whether the Activity was
* canceled.
*
* @return True if the Activity was canceled. False if the Activity was not canceled.
* @return Returns {@code true} if the Activity was canceled, otherwise returns {@code false}
* if the Activity was not canceled.
*/
protected boolean isCanceled() {
return mIsCancelled;
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/java/com/termux/tasker/BundleScrubber.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ public final class BundleScrubber {
* Bundle is null, has no extras, or the extras do not contain a private serializable subclass, the Bundle
* is not mutated.
*
* @param intent {@code Intent} to scrub. This parameter may be mutated if scrubbing is necessary. This
* parameter may be null.
* @return true if the Intent was scrubbed, false if the Intent was not modified.
* @param intent The {@link Intent} to scrub. This parameter may be mutated if scrubbing is
* necessary. This parameter may be {@code null}.
* @return Returns {@code true} if the Intent was scrubbed, otherwise returns {@code false} if
* the {@link Intent} was not modified.
*/
public static boolean scrub(final Intent intent) {
return null != intent && scrub(intent.getExtras());
Expand All @@ -27,9 +28,10 @@ public static boolean scrub(final Intent intent) {
* private serializable subclass, the Bundle is cleared. If the Bundle is null, has no extras, or the
* extras do not contain a private serializable subclass, the Bundle is not mutated.
*
* @param bundle {@code Bundle} to scrub. This parameter may be mutated if scrubbing is necessary. This
* parameter may be null.
* @return true if the Bundle was scrubbed, false if the Bundle was not modified.
* @param bundle The {@link Bundle} to scrub. This parameter may be mutated if scrubbing is necessary.
* This parameter may be {@code null}.
* @return Returns {@code true} if the Bundle was scrubbed, otheriwse {@code false} if the
* {@link Bundle} was not modified.
*/
public static boolean scrub(final Bundle bundle) {
if (null == bundle) return false;
Expand Down
25 changes: 0 additions & 25 deletions app/src/main/java/com/termux/tasker/Constants.java

This file was deleted.

Loading

0 comments on commit 63e7645

Please sign in to comment.