Fixed foreground being killed, keep the code updated.

This commit is contained in:
simonpunk 2019-02-15 04:48:39 +08:00
parent 47b2804fc8
commit d66e636fb5
17 changed files with 52 additions and 80 deletions

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>

View File

@ -1,3 +0,0 @@
<component name="CopyrightManager">
<settings default="" />
</component>

View File

@ -1,6 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>

View File

@ -1,7 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<option name="myLocal" value="true" />
<inspection_tool class="AndroidLintSdCardPath" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>

View File

@ -1,7 +0,0 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="Project Default" />
<option name="USE_PROJECT_PROFILE" value="true" />
<version value="1.0" />
</settings>
</component>

View File

@ -1,5 +0,0 @@
<component name="DependencyValidationManager">
<state>
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
</state>
</component>

View File

@ -25,4 +25,4 @@ LOCAL_SRC_FILES := $(nhterm_dir)/$(nhterm_apk)
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
include $(BUILD_PREBUILT)

View File

@ -3,5 +3,4 @@
package="com.offsec.nhterm.emulatorview"
android:versionCode="43"
android:versionName="1.0.42">
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="11" />
</manifest>

View File

@ -112,11 +112,12 @@ public class TermSession {
private FinishCallback mFinishCallback;
private boolean mIsRunning = false;
private final Handler mMsgHandler = new Handler() {
private final Handler mMsgHandler = new Handler(new Handler.Callback() {
@Override
public void handleMessage(Message msg) {
public boolean handleMessage(Message msg) {
if (!mIsRunning) {
return;
return false;
}
if (msg.what == NEW_INPUT) {
readFromProcess();
@ -128,8 +129,9 @@ public class TermSession {
}
});
}
return true;
}
};
});
private UpdateCallback mTitleChangedListener;
@ -186,16 +188,17 @@ public class TermSession {
Looper.prepare();
Log.d("TermSession.java: ", "new Handler");
mWriterHandler = new Handler() {
mWriterHandler = new Handler(new Handler.Callback() {
@Override
public void handleMessage(Message msg) {
public boolean handleMessage(Message msg) {
if (msg.what == NEW_OUTPUT) {
writeToOutput();
} else if (msg.what == FINISH) {
Looper.myLooper().quit();
}
return true;
}
};
});
// Drain anything in the queue from before we started
Log.d("TermSession.java: ", "writeToOutput()");

View File

@ -1,2 +1,2 @@
# Build for ARMv5TE, mips and x86 architectures.
APP_ABI := armeabi mips x86 arm64-v8a armeabi-v7a
APP_ABI := mips x86 arm64-v8a armeabi-v7a

View File

@ -26,8 +26,9 @@
#include <unistd.h>
#include <termios.h>
#include <signal.h>
#include <string.h>
typedef unsigned short char16_t;
typedef unsigned short uint_least16_t;
class String8 {
public:
@ -41,7 +42,7 @@ public:
}
}
void set(const char16_t* o, size_t numChars) {
void set(const uint_least16_t* o, size_t numChars) {
if (mString) {
free(mString);
}

View File

@ -10,6 +10,8 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<permission android:name="com.offsec.nhterm.permission.RUN_SCRIPT"
android:label="@string/perm_run_script"
android:description="@string/permdesc_run_script"
@ -129,7 +131,7 @@
android:label="@string/preferences"/>
<activity android:name="com.offsec.nhterm.WindowList"
android:label="@string/window_list" />
<service android:name="com.offsec.nhterm.TermService" >
<service android:name="com.offsec.nhterm.TermService" android:permission="android.permission.BIND_JOB_SERVICE">
<intent-filter>
<action android:name="com.offsec.nhterm.action.START_TERM.v1"/>
<category android:name="android.intent.category.DEFAULT"/>

View File

@ -15,7 +15,6 @@
*/
package com.offsec.nhterm;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
@ -35,6 +34,7 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.nfc.Tag;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@ -376,7 +376,7 @@ public class Term extends Activity implements UpdateCallback, SharedPreferences.
Intent broadcast = new Intent(ACTION_PATH_BROADCAST);
if (AndroidCompat.SDK >= 12) {
broadcast.addFlags(FLAG_INCLUDE_STOPPED_PACKAGES);
broadcast.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
}
mPendingPathBroadcasts++;
sendOrderedBroadcast(broadcast, PERMISSION_PATH_BROADCAST, mPathReceiver, null, RESULT_OK, null, null);
@ -388,7 +388,6 @@ public class Term extends Activity implements UpdateCallback, SharedPreferences.
TSIntent = new Intent(this, TermService.class);
startService(TSIntent);
if (AndroidCompat.SDK >= 11) {
int actionBarMode = mSettings.actionBarMode();
mActionBarMode = actionBarMode;
@ -411,7 +410,7 @@ public class Term extends Activity implements UpdateCallback, SharedPreferences.
setFunctionKeyListener();
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TermDebug.LOG_TAG);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "com.offsec.nhterm:TermDebug.LOG_TAG");
WifiManager wm = (WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
int wifiLockMode = WifiManager.WIFI_MODE_FULL;
if (AndroidCompat.SDK >= 12) {

View File

@ -15,7 +15,7 @@
*/
package com.offsec.nhterm;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
@ -31,14 +31,11 @@ import android.preference.PreferenceManager;
import android.support.v4.app.TaskStackBuilder;
import android.text.TextUtils;
import android.util.Log;
import android.app.Notification;
import android.support.v4.app.NotificationCompat;
import android.app.PendingIntent;
import com.offsec.nhterm.R;
import com.offsec.nhterm.emulatorview.TermSession;
import com.offsec.nhterm.compat.ServiceForegroundCompat;
import com.offsec.nhterm.libtermexec.v1.*;
import com.offsec.nhterm.util.SessionList;
@ -51,9 +48,9 @@ public class TermService extends Service implements TermSession.FinishCallback
/* Parallels the value of START_STICKY on API Level >= 5 */
private static final int COMPAT_START_STICKY = 1;
private NotificationManager mNotificationManager;
private final int notifyID = 1;
private NotificationManager notificationManager;
private static final int notifyID = 1;
private static final String NH_TERM_CHANNEL_ID = "NH_TERM_CHANNEL";
private static final int RUNNING_NOTIFICATION = 1;
private ServiceForegroundCompat compat;
@ -102,14 +99,28 @@ public class TermService extends Service implements TermSession.FinishCallback
//compat = new ServiceForegroundCompat(this);
mTermSessions = new SessionList();
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Create the NotificationChannel
CharSequence name = getString(R.string.nh_term_notification_channel);
String description = getString(R.string.nh_term_notification_channel);
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel mChannel = new NotificationChannel(NH_TERM_CHANNEL_ID, name, importance);
mChannel.setDescription(description);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
notificationManager = (NotificationManager) getSystemService(
NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.createNotificationChannel(mChannel);
}
}
// Building the notification
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, NH_TERM_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_stat_service_notification_icon) // notification icon
.setContentTitle(getText(R.string.application_terminal)) // main title of the notification
.setContentText(getText(R.string.service_notify_text)); // notification text
//.setContentIntent(pendingIntent); // notification intent
//.setContentIntent(pendingIntent); // notification intent
Intent notifyIntent = new Intent(this, Term.class);
@ -133,16 +144,16 @@ public class TermService extends Service implements TermSession.FinishCallback
mBuilder.setContentIntent(resultPendingIntent);
// mId allows you to update the notification later on.
mNotificationManager.notify(notifyID, mBuilder.build());
//notificationManager.notify(notifyID, mBuilder.build());
startForeground(notifyID, mBuilder.build());
//compat.startForeground(RUNNING_NOTIFICATION, notification);
Log.d(TermDebug.LOG_TAG, "TermService started");
}
@Override
public void onDestroy() {
// Remove notification
mNotificationManager.cancel(notifyID);
notificationManager.cancel(notifyID);
for (TermSession session : mTermSessions) {
/* Don't automatically remove from list of sessions -- we clear the

View File

@ -21,6 +21,7 @@ import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import android.app.Service;
import android.util.Log;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;

View File

@ -1,2 +1,2 @@
# Build for ARMv5TE, mips and x86 architectures.
APP_ABI := armeabi mips x86 arm64-v8a armeabi-v7a
APP_ABI := mips x86 arm64-v8a armeabi-v7a

View File

@ -46,7 +46,9 @@
<string name="service_notify_text">Terminal session is running</string>
<string name="process_exit_message">Terminal session finished</string>
<!--Notification Channel-->
<string name="nh_term_notification_channel">nh_term</string>
<string name="nh_term_notification_channel_description">Notification for nh_term</string>
<!-- Preference dialog -->
<string name="screen_preferences">Screen</string>