Update for Android (N)

* Updated Targeted/Compil SDK to 24 (Android N)
* Redid notification manager since previous one is deprecated
* Term.java add SDK check
* Other lint cleanups

https://github.com/offensive-security/kali-nethunter/issues/604
Signed-off-by: binkybear <binkybear@nethunter.com>
This commit is contained in:
binkybear 2016-10-09 11:53:15 -05:00
parent 5af38a650f
commit 477a9e9073
15 changed files with 83 additions and 52 deletions

View File

@ -1,12 +1,12 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
compileSdkVersion 24
buildToolsVersion '24.0.1'
defaultConfig {
applicationId 'com.offsec.nhterm'
minSdkVersion 14
targetSdkVersion 22
targetSdkVersion 24
ndk {
moduleName "libjackpal-androidterm5nhj1"
@ -34,4 +34,5 @@ android {
dependencies {
compile project(':emulatorview')
compile project(':libtermexec')
compile 'com.android.support:support-v4:24.2.1'
}

View File

@ -43,6 +43,7 @@
<application android:icon="@mipmap/ic_launcher"
android:label="@string/application_terminal"
android:hardwareAccelerated="true"
android:allowBackup="false"
android:theme="@style/Theme">
<activity android:name="com.offsec.nhterm.Term"
android:launchMode="singleTask"

View File

@ -168,7 +168,7 @@ public class ShellTermSession extends GenericTermSession {
final int WHITESPACE = 1;
final int INQUOTE = 2;
int state = WHITESPACE;
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
int cmdLen = cmd.length();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < cmdLen; i++) {

View File

@ -19,6 +19,7 @@ package com.offsec.nhterm;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.text.TextUtils;
import com.offsec.nhterm.R;
@ -190,7 +191,7 @@ public class Term extends Activity implements UpdateCallback, SharedPreferences.
// From android.R.style in API 13
private static final int TextAppearance_Holo_Widget_ActionBar_Title = 0x01030112;
public WindowListActionBarAdapter(SessionList sessions) {
WindowListActionBarAdapter(SessionList sessions) {
super(sessions);
}
@ -951,7 +952,7 @@ public class Term extends Activity implements UpdateCallback, SharedPreferences.
// Check for symlink for bootkali
// http://stackoverflow.com/questions/813710/java-1-6-determine-symbolic-links/813730#813730
@TargetApi(Build.VERSION_CODES.KITKAT)
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public static boolean isSymlink(File file) throws IOException {
Log.d("SYMLINK FILE TO CHECK: ", String.valueOf(file));
Log.d("SYMLINK REAL PATH: ", String.valueOf(file.getCanonicalFile()));

View File

@ -16,7 +16,9 @@
package com.offsec.nhterm;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.IntentSender;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
@ -26,11 +28,14 @@ import android.net.Uri;
import android.os.*;
import android.content.Intent;
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;
@ -46,6 +51,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 static final int RUNNING_NOTIFICATION = 1;
private ServiceForegroundCompat compat;
@ -65,7 +73,7 @@ public class TermService extends Service implements TermSession.FinishCallback
/* This should be @Override if building with API Level >=5 */
public int onStartCommand(Intent intent, int flags, int startId) {
return COMPAT_START_STICKY;
return Service.START_STICKY;
}
@Override
@ -89,27 +97,53 @@ public class TermService extends Service implements TermSession.FinishCallback
String defValue = getDir("HOME", MODE_PRIVATE).getAbsolutePath();
String homePath = prefs.getString("home_path", defValue);
editor.putString("home_path", homePath);
editor.commit();
editor.apply();
compat = new ServiceForegroundCompat(this);
//compat = new ServiceForegroundCompat(this);
mTermSessions = new SessionList();
/* Put the service in the foreground. */
Notification notification = new Notification(R.drawable.ic_stat_service_notification_icon, getText(R.string.service_notify_text), System.currentTimeMillis());
notification.flags |= Notification.FLAG_ONGOING_EVENT;
Intent notifyIntent = new Intent(this, Term.class);
notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0);
notification.setLatestEventInfo(this, getText(R.string.application_terminal), getText(R.string.service_notify_text), pendingIntent);
compat.startForeground(RUNNING_NOTIFICATION, notification);
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
// Building the notification
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.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
Intent notifyIntent = new Intent(this, Term.class);
// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(Term.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(notifyIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
// mId allows you to update the notification later on.
mNotificationManager.notify(notifyID, mBuilder.build());
//compat.startForeground(RUNNING_NOTIFICATION, notification);
Log.d(TermDebug.LOG_TAG, "TermService started");
return;
}
@Override
public void onDestroy() {
compat.stopForeground(true);
// Remove notification
mNotificationManager.cancel(notifyID);
for (TermSession session : mTermSessions) {
/* Don't automatically remove from list of sessions -- we clear the
* list below anyway and we could trigger
@ -118,7 +152,6 @@ public class TermService extends Service implements TermSession.FinishCallback
session.finish();
}
mTermSessions.clear();
return;
}
public SessionList getSessions() {

View File

@ -94,7 +94,7 @@ public class TermViewFlipper extends ViewFlipper implements Iterable<View> {
private void commonConstructor(Context context) {
this.context = context;
callbacks = new LinkedList<UpdateCallback>();
callbacks = new LinkedList<>();
updateVisibleRect();
Rect visible = mVisibleRect;
@ -325,7 +325,7 @@ public class TermViewFlipper extends ViewFlipper implements Iterable<View> {
SharedPreferences pref = context.getSharedPreferences("dev", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();
editor.putInt(key, value);
editor.commit();
editor.apply();
return value;
}

View File

@ -243,7 +243,7 @@ public class AddShortcut
if(path!=null && !path.equals("")) cmd.append(RemoteInterface.quoteForBash(path));
if(arguments!=null && !arguments.equals("")) cmd.append(" ").append(arguments);
String cmdStr=cmd.toString();
String cmdEnc=null;
String cmdEnc;
try
{
cmdEnc=ShortcutEncryption.encrypt(cmdStr, keys);
@ -291,14 +291,14 @@ public class AddShortcut
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
Uri uri= null;
Uri uri;
path= null;
switch(requestCode)
{
case OP_MAKE_SHORTCUT:
if(data!=null && (uri=data.getData())!=null && (path=uri.getPath())!=null)
{
SP.edit().putString("lastPath", path).commit();
SP.edit().putString("lastPath", path).apply();
et[PATH].setText(path);
name=path.replaceAll(".*/", "");
if(et[NAME].getText().toString().equals("")) et[NAME].setText(name);

View File

@ -183,7 +183,7 @@ public class ColorValue
int view=(Integer)buttonView.getTag();
locks[view]=isChecked;
barLock=false;
for(int i=0; i<locks.length; i++) if(locks[i]) barLock=true;
for (boolean lock : locks) if (lock) barLock = true;
}
////////////////////////////////////////////////////////////
private void buttonHit(int hit, int color)

View File

@ -66,9 +66,9 @@ public class FSNavigator
titleView= directoryEntry("..");
pathEntryView= fileEntry(null);
contentView= makeContentView();
cachedDirectoryView= new HashMap<Integer, LinearLayout>();
cachedFileView= new HashMap<Integer, LinearLayout>();
cachedDividerView= new HashMap<Integer, TextView>();
cachedDirectoryView= new HashMap<>();
cachedFileView= new HashMap<>();
cachedDividerView= new HashMap<>();
}
////////////////////////////////////////////////////////////
public void onPause()
@ -79,7 +79,7 @@ public class FSNavigator
////////////////////////////////////////////////////////////
private void doPause()
{
SP.edit().putString("lastDirectory", getCanonicalPath(cd)).commit();
SP.edit().putString("lastDirectory", getCanonicalPath(cd)).apply();
}
////////////////////////////////////////////////////////////
public void onResume()
@ -101,7 +101,7 @@ public class FSNavigator
case android.R.style.Theme_Light: theme=android.R.style.Theme; break;
default: return;
}
SP.edit().putInt("theme", theme).commit();
SP.edit().putInt("theme", theme).apply();
startActivityForResult(getIntent().addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT), -1);
finish();
}
@ -460,10 +460,9 @@ public class FSNavigator
if(zd!=null)
{
java.util.Arrays.sort(zd, 0, zd.length, stringSortComparator);
for(int i=0, n=zd.length; i<n; i++)
{
if(zd[i].equals(".")) continue;
ll.addView(directoryEntry(zd[i]));
for (String aZd : zd) {
if (aZd.equals(".")) continue;
ll.addView(directoryEntry(aZd));
ll.addView(entryDividerH());
}
}
@ -471,9 +470,8 @@ public class FSNavigator
if(zf!=null)
{
java.util.Arrays.sort(zf, 0, zf.length, stringSortComparator);
for(int i=0, n=zf.length; i<n; i++)
{
ll.addView(fileEntry(zf[i]));
for (String aZf : zf) {
ll.addView(fileEntry(aZf));
ll.addView(entryDividerH());
}
}

View File

@ -30,18 +30,18 @@ public class TextIcon
for(int i=0; i<nLines; ++i)
{
p. getTextBounds(lines[i], 0, lines[i].length(), R);
float h= Float.valueOf(Math.abs(R.top-R.bottom));
float w= Float.valueOf(Math.abs(R.right-R.left));
float h= (float) Math.abs(R.top - R.bottom);
float w= (float) Math.abs(R.right - R.left);
if(nLines>1) h+=0.1f*h; // Add space between lines.
HH[i]= h;
H+= h;
if(w>W) W=w;
}
float f= ((float)width)*H/((float)height);
int hBitmap= (int)H;
int wBitmap= (int)W;
if(W<f) {wBitmap=(int)FloatMath.ceil(f); hBitmap=(int)FloatMath.ceil(H);}
else {wBitmap=(int)FloatMath.ceil(W); hBitmap=(int)FloatMath.ceil(height*wBitmap/width);}
int hBitmap;
int wBitmap;
if(W<f) {wBitmap=(int) Math.ceil(f); hBitmap=(int) Math.ceil(H);}
else {wBitmap=(int) Math.ceil(W); hBitmap=(int) Math.ceil(height*wBitmap/width);}
Bitmap b= Bitmap.createBitmap(wBitmap, hBitmap, Config.ARGB_8888);
b. setDensity(Bitmap.DENSITY_NONE);

View File

@ -30,8 +30,8 @@ import com.offsec.nhterm.emulatorview.UpdateCallback;
@SuppressWarnings("serial")
public class SessionList extends ArrayList<TermSession>
{
LinkedList<UpdateCallback> callbacks = new LinkedList<UpdateCallback>();
LinkedList<UpdateCallback> titleChangedListeners = new LinkedList<UpdateCallback>();
LinkedList<UpdateCallback> callbacks = new LinkedList<>();
LinkedList<UpdateCallback> titleChangedListeners = new LinkedList<>();
UpdateCallback mTitleChangedListener = new UpdateCallback() {
public void onUpdate() {
notifyTitleChanged();

View File

@ -163,7 +163,7 @@ public final class ShortcutEncryption {
SharedPreferences.Editor edit = prefs.edit();
edit.putString(SHORTCUT_KEYS_PREF, keys.encode());
edit.commit();
edit.apply();
}
/**

View File

@ -377,8 +377,7 @@ public class TermSettings {
}
public boolean backKeySendsCharacter() {
if (mBackKeyAction == BACK_KEY_TOGGLE_IME) return false;
return mBackKeyAction >= BACK_KEY_SENDS_ESC;
return mBackKeyAction != BACK_KEY_TOGGLE_IME && mBackKeyAction >= BACK_KEY_SENDS_ESC;
}
public boolean getAltSendsEscFlag() {

View File

@ -23,12 +23,11 @@
android:orientation="horizontal"
android:background="@color/primary">
<TextView android:id="@+id/window_list_label"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="15dp"
android:maxLines="1"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
<View android:id="@+id/window_list_separator"
android:background="#ff313431"

View File

@ -21,7 +21,6 @@
android:layout_height="fill_parent"
android:padding="15dp"
android:maxLines="1"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/new_window"
/>