Skip to content

Commit

Permalink
Fixes notification blacklisting, adds (un)check all button #67
Browse files Browse the repository at this point in the history
  • Loading branch information
C0Newb committed Feb 27, 2023
1 parent 555880e commit 391d190
Show file tree
Hide file tree
Showing 21 changed files with 337 additions and 379 deletions.
4 changes: 2 additions & 2 deletions Client/Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "com.neptune.app"
minSdk 23
targetSdk 32
versionCode 1
versionName "0.2"
versionCode 2
versionName "0.5"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ public void sendRequestAsync(String apiURL, JsonObject requestData) {
public void run(){
try {
sendRequest(apiURL, requestData);
} catch (JsonParseException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
} catch (Exception e) {
e.printStackTrace();
}
}
Expand Down Expand Up @@ -461,7 +459,7 @@ public void onError(Exception ex) {
}
};


//webSocketClient.connect();
}

public void sendWebSocketInfo (String apiURL, JsonObject requestData) throws MalformedURLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
import java.io.ByteArrayOutputStream;

public class NotificationListenerService extends android.service.notification.NotificationListenerService {

private NotificationManager notificationManager;

Context context;

@Override
Expand All @@ -29,7 +26,6 @@ public void onCreate() {
context = getApplicationContext();

Log.d("NotificationListener", "Created.");

}

public void cancelNotification (Notification[] notification) {
Expand Down Expand Up @@ -59,64 +55,23 @@ public void onDestroy() {
}

public void onNotificationPosted(StatusBarNotification notification) {
// Note, only do global filtering here. Things like THIS app get filtered..
// The Server class will filter out whatever it doesn't want

//Different Approach to see if this would be better/works (May need help with figuring this out)
String pack = notification.getPackageName();
String ticker = "";

if (notification.getNotification().tickerText != null) {
ticker = notification.getNotification().tickerText.toString();
}


Bundle extras = notification.getNotification().extras;

Log.d("NotificationListener", "Notification from package: " + notification.getPackageName());
Bundle extras = notification.getNotification().extras;
if (extras.getCharSequence("android.title") == null) { //Some notifications are not handled correctly, so we'll just skip em
return;
}

String title = extras.getCharSequence("android.title").toString();
String text = "";
if (extras.getCharSequence("android.text") != null) {
text = extras.getCharSequence("android.text").toString();
}
int id1 = extras.getInt(Notification.EXTRA_SMALL_ICON);
Bitmap id = notification.getNotification().largeIcon;

Log.i("Ticker", ticker);
Log.i("Title", title);
Log.i("Text", text);

Intent message = new Intent("Msg");
message.putExtra("package", pack);
message.putExtra("ticker", ticker);
message.putExtra("title", title);
message.putExtra("text", text);

if (id != null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
byte[] byteArray = stream.toByteArray();
message.putExtra("icon", byteArray);
}

NeptuneNotification notify = null;
try {
notify = new NeptuneNotification(notification, getApplicationContext());
MainActivity.serverManager.processNotification(notify);
NeptuneNotification notify = new NeptuneNotification(notification, getApplicationContext());
MainActivity.notificationManager.setNotification(notify);
} catch (Exception e) {
e.printStackTrace();
// yepirr
}

LocalBroadcastManager.getInstance(context).sendBroadcast(message);

}

public void onNotificationRemoved(StatusBarNotification notification) {
Log.i("Msg", "Notification Removed");

MainActivity.notificationManager.deleteNotification(notification.getId());
}

public void onSilentStatusBariconsVisibilityChanged(boolean status) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
package com.neptune.app.Backend;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import com.neptune.app.Backend.Adapters.ClientConfigEncryptionAdapter;
import com.neptune.app.Backend.Structs.ClientConfigEncryption;

import org.json.JSONException;

import java.io.IOException;
import java.sql.Array;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -88,8 +79,7 @@ public void fromJson(JsonObject jsonObject) {
if (jsonObject.has("dateAdded")) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
TemporalAccessor ta = DateTimeFormatter.ISO_INSTANT.parse(jsonObject.get("dateAdded").getAsString());
Instant i = null;
i = Instant.from(ta);
Instant i = Instant.from(ta);
Date date = Date.from(i);
this.dateAdded = date;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class ServerManager {
Expand All @@ -36,13 +34,16 @@ public void addServer(Server s) {


public void pair(UUID serverId, IPAddress ipAddress) throws ConnectionManager.FailedToPair {
Server server = servers.get(serverId);
server.ipAddress = ipAddress;
server.pair();
if (servers.containsKey(serverId)) {
Server server = servers.get(serverId);
server.ipAddress = ipAddress;
server.pair();
}
}

public void unpair(UUID server) {
servers.get(server).unpair();
public void unpair(UUID serverId) {
if (servers.containsKey(serverId))
servers.get(serverId).unpair();
}

public Server getServer(UUID serverId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class DeviceActivity extends AppCompatActivity {
//public Button temp;
public ConnectionManager cm;
private Button delete;
private Button btnSave;
private EditText ipAddress;
private TextView notificationsTextView;
private TextView clipboardTextView;
Expand All @@ -52,50 +53,21 @@ protected void onCreate(Bundle savedInstanceState) {
//Setting various TextViews based on the friendly name of the device connected.
String serverFriendlyName = getIntent().getStringExtra("FRIENDLY_NAME");
notificationsTextView = findViewById(R.id.notificationsTextView);
notificationsTextView.setText("Send notifications to " + serverFriendlyName + ".");
notificationsTextView.setText("Send notifications to " + server.friendlyName + ".");

clipboardTextView = findViewById(R.id.clipboardTextView);
clipboardTextView.setText("Allow " + serverFriendlyName + " to read and write clipboard data.");
clipboardTextView.setText("Allow " + server.friendlyName + " to read and write clipboard data.");

fileTextView = findViewById(R.id.fileTextView);
fileTextView.setText("Allow " + serverFriendlyName + " to send files.");
fileTextView.setText("Allow " + server.friendlyName + " to send files.");

notificationsCheckbox = findViewById(R.id.notificationsCheckbox);
if(server.syncNotifications) {
notificationsCheckbox.setChecked(true);
}
notificationsCheckbox.setChecked(server.syncNotifications);

notificationsCheckbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(server.syncNotifications) {
notificationsCheckbox.setChecked(false);
server.syncNotifications = false;
}
else {
notificationsCheckbox.setChecked(true);
server.syncNotifications = true;
}

try {
server.save();
} catch (JsonParseException e) {
e.printStackTrace();
if (server != null)
server.delete();
runOnUiThread(() -> showErrorMessage("Failed to pair device", e.getMessage()));

} catch (IOException e) {
e.printStackTrace();
if (server != null)
server.delete();
runOnUiThread(() -> showErrorMessage("Failed to pair device", e.getMessage()));

}/* catch (ConnectionManager.FailedToPair e) {
e.printStackTrace();
if (server != null)
server.delete();
runOnUiThread(() -> showErrorMessage("Failed to pair device", e.getMessage()));
}*/
server.syncNotifications = notificationsCheckbox.isChecked();
}
});

Expand Down Expand Up @@ -133,6 +105,19 @@ public void onClick(View view) {
}
});


btnSave = findViewById(R.id.btnSave);
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
server.save();
} catch (Exception e) {
showErrorMessage("Failed to save settings.", "An error occurred while saving the settings: " + e.getMessage());
}
}
});

/*connect = (Button) findViewById(R.id.connec);
connect.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -168,21 +153,6 @@ protected void onPause() {
super.onPause();
}

public void onRadioButtonClicked(View view) {
boolean checked = ((RadioButton) view).isChecked();

switch(view.getId()) {
case R.id.radio_auto:
if(checked)
//
break;
case R.id.radio_key:
if(checked)
//
break;
}
}

@Override
protected void onResume() {
super.onResume();
Expand Down
Loading

0 comments on commit 391d190

Please sign in to comment.