Skip to content
Open
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
8 changes: 5 additions & 3 deletions agent/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="33"
android:versionName="3.1.0" >
android:versionName="3.1.1" >


<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

<application
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:name=".DzApplication">
<activity
android:name=".activities.AboutActivity"
android:label="@string/title_about"
Expand Down Expand Up @@ -180,7 +182,7 @@
android:process=":remote" />

<provider
android:authorities=".providers.Provider"
android:authorities="${applicationId}.providers.Provider"
android:name="com.WithSecure.dz.providers.Provider"
android:exported="true"
/>
Expand Down
17 changes: 17 additions & 0 deletions agent/src/main/java/com/WithSecure/dz/DzApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.WithSecure.dz;

import android.app.Application;

import com.WithSecure.dz.models.ForegroundServiceNotification;
import com.WithSecure.dz.models.GlobalSettings;

public class DzApplication extends Application {
@Override
public void onCreate() {
super.onCreate();

ForegroundServiceNotification.Init(this.getApplicationContext());
Agent.getInstance().setContext(this.getApplicationContext());
GlobalSettings.Init(this.getApplicationContext());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import android.view.Menu;
import android.widget.TextView;

public class AboutActivity extends Activity {
public class AboutActivity extends BaseActivity {

private TextView description;

Expand All @@ -22,7 +22,7 @@ private String getVersionName() {
}

@Override
protected void onCreate(Bundle savedInstanceState) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);

Expand Down
16 changes: 16 additions & 0 deletions agent/src/main/java/com/WithSecure/dz/activities/BaseActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.WithSecure.dz.activities;

import android.app.Activity;
import android.os.Bundle;

import com.WithSecure.dz.models.GlobalSettings;

public class BaseActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(GlobalSettings.themeFromString(GlobalSettings.get("theme")));

super.onCreate(savedInstanceState);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.WithSecure.dz.activities;

import android.os.Bundle;
import android.preference.PreferenceActivity;

import com.WithSecure.dz.models.GlobalSettings;

public class BasePreferenceActivity extends PreferenceActivity {
@Override
@SuppressWarnings("deprecation")
public void onCreate(Bundle savedInstanceState) {
setTheme(GlobalSettings.themeFromString(GlobalSettings.get("theme")));

super.onCreate(savedInstanceState);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import android.view.Menu;
import android.view.MenuItem;

public abstract class ConnectorActivity extends Activity {
public abstract class ConnectorActivity extends BaseActivity {

public static class IncomingFingerprintHandler extends Handler {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import android.view.View;
import android.widget.Button;

public class EndpointSettingsActivity extends PreferenceActivity {
public class EndpointSettingsActivity extends BasePreferenceActivity {

public static final String ENDPOINT_SETTINGS_PREFERENCE = "endpoint_settings";
public static final String SECURITY_SETTINGS_PREFERENCE = "security_settings";
Expand Down
47 changes: 44 additions & 3 deletions agent/src/main/java/com/WithSecure/dz/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,29 @@
import com.WithSecure.dz.views.ServerListRowView;
import com.WithSecure.jsolar.api.connectors.Endpoint;

import android.Manifest;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.RemoteException;
import android.app.Activity;
import android.content.Intent;
import android.provider.Settings;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends Activity {
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MainActivity extends BaseActivity {

private EndpointListView endpoint_list_view = null;
private ServerListRowView server_list_row_view = null;
Expand All @@ -36,8 +49,6 @@ private void launchServerActivity() {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Agent.getInstance().setContext(this.getApplicationContext());

setContentView(R.layout.activity_main);

this.endpoint_list_view = (EndpointListView)this.findViewById(R.id.endpoint_list_view);
Expand Down Expand Up @@ -80,6 +91,36 @@ public void onToggle(boolean toggle) {
}

});

// request all unrequested perms in manifest
try {
PackageInfo pi = getPackageManager().getPackageInfo(getApplicationContext().getPackageName(), PackageManager.GET_PERMISSIONS);
String[] requestedPermissions = pi.requestedPermissions;

List<String> toRequest = new ArrayList<>();
for (String p : requestedPermissions) {
if (ContextCompat.checkSelfPermission(getApplicationContext(), p) != PackageManager.PERMISSION_GRANTED) {
if (p.equals(Manifest.permission.SYSTEM_ALERT_WINDOW)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivity(intent);
}
}
else {
toRequest.add(p);
}
}
}

if (!toRequest.isEmpty()) {
String[] asArray = new String[toRequest.size()];
toRequest.toArray(asArray);
ActivityCompat.requestPermissions(this, asArray, 1);
}
} catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.WithSecure.dz.activities;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import com.WithSecure.dz.Agent;
import com.WithSecure.dz.R;
import com.WithSecure.dz.models.NetworkInterfaceModel;
import com.WithSecure.dz.models.ServerSettings;
import com.WithSecure.dz.views.CheckListItemView;
import com.WithSecure.dz.views.ConnectorStatusIndicator;
import com.WithSecure.dz.views.NetworkInterfaceListAdapter;
import com.WithSecure.dz.views.logger.LogMessageAdapter;
import com.WithSecure.jsolar.api.connectors.Connector;
import com.WithSecure.jsolar.api.connectors.Endpoint;
Expand All @@ -28,6 +33,10 @@ public class ServerActivity extends ConnectorActivity implements Observer, Serve
private CompoundButton server_enabled = null;
private ListView server_messages = null;
private ConnectorStatusIndicator server_status_indicator = null;

private ListView server_interface_list = null;
private NetworkInterfaceListAdapter server_interface_adapter = null;
private List<NetworkInterfaceModel> server_interface_data;

private CheckListItemView status_enabled = null;
private CheckListItemView status_listening = null;
Expand All @@ -51,9 +60,18 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

this.setContentView(R.layout.activity_server);

this.server_status_indicator = (ConnectorStatusIndicator)this.findViewById(R.id.server_status_indicator);


this.server_status_indicator = (ConnectorStatusIndicator)this.findViewById(R.id.server_status_indicator);

this.server_interface_list = (ListView)this.findViewById(R.id.server_endpoint);
this.server_interface_data = new ArrayList<>();
this.server_interface_adapter = new NetworkInterfaceListAdapter(this, server_interface_data);
server_interface_list.setAdapter(server_interface_adapter);

server_interface_adapter.clear();
server_interface_adapter.addAll(ServerSettings.getInterfaces());
server_interface_adapter.notifyDataSetChanged();

this.server_enabled = (CompoundButton)this.findViewById(R.id.server_enabled);
this.server_enabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

Expand Down Expand Up @@ -99,6 +117,9 @@ public void onDetailedStatus(Bundle status) {
* Refresh the status indicators, to show the current status of the Endpoint.
*/
protected void refreshStatus() {
server_interface_adapter.clear();
server_interface_adapter.addAll(ServerSettings.getInterfaces());
server_interface_adapter.notifyDataSetChanged();
this.getDetailedServerStatus();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import android.preference.PreferenceCategory;
import android.widget.Toast;

public class SettingsActivity extends PreferenceActivity {
public class SettingsActivity extends BasePreferenceActivity {

public static final String ABOUT_DROZER_PREFERENCE = "about_drozer";
public static final String ENDPOINT_SETTINGS_PREFERENCE = "endpoint_settings";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import java.util.ArrayList;

public class StartBroadcastActivity extends Activity {
public class StartBroadcastActivity extends BaseActivity {

public void onCreate(Bundle bundle) {
super.onCreate(bundle);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.WithSecure.dz.helpers;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;

import com.WithSecure.dz.activities.BaseActivity;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;

public class IntentProxyToContentProvider extends Activity {
public class IntentProxyToContentProvider extends BaseActivity {

// This class is meant to help download files from unexported Content Providers
// Assuming the unexported Content Provider has GrantURIPermissions set to True
Expand All @@ -27,7 +28,7 @@ public class IntentProxyToContentProvider extends Activity {

String filename = "yayoutputyay"; // save file as "yayoutputyay"

protected void onCreate(Bundle savedInstanceState) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Uri uri = Uri.parse(getIntent().getDataString()); // Get the Uri for the unexported content provider
if (getIntent().getStringExtra("filename") != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.WithSecure.dz.models;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;

import androidx.core.app.NotificationCompat;

import com.WithSecure.dz.R;
import com.WithSecure.dz.activities.MainActivity;

public class ForegroundServiceNotification {
private static final String CHANNEL_ID = "ForegroundServiceChannel";
private static final int NOTIFICATION_ID = 1;

private Notification notification;
private static ForegroundServiceNotification instance = null;

private ForegroundServiceNotification(Context ctx) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
CHANNEL_ID,
"Foreground Service Channel",
NotificationManager.IMPORTANCE_HIGH
);
channel.setDescription("Channel for foreground service");

NotificationManager manager = ctx.getSystemService(NotificationManager.class);
if (manager != null) {
manager.createNotificationChannel(channel);
}

Intent notificationIntent = new Intent(ctx, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE);

notification = new NotificationCompat.Builder(ctx, CHANNEL_ID)
.setContentTitle("Drozer")
.setContentText("Drozer is running in background")
.setSmallIcon(R.drawable.ic_notification)
.setContentIntent(pendingIntent)
.build();
}
}

public static void Init(Context ctx) {
if (instance == null) {
instance = new ForegroundServiceNotification(ctx);
}
}

public static Notification getNotification() {
return instance.notification;
}

public static int getId() {
return NOTIFICATION_ID;
}
}
Loading