diff --git a/Client/Android/app/build.gradle b/Client/Android/app/build.gradle index 6aa24d0..3139d18 100644 --- a/Client/Android/app/build.gradle +++ b/Client/Android/app/build.gradle @@ -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" } diff --git a/Client/Android/app/src/main/java/com/neptune/app/Backend/ConnectionManager.java b/Client/Android/app/src/main/java/com/neptune/app/Backend/ConnectionManager.java index de57c48..3465170 100644 --- a/Client/Android/app/src/main/java/com/neptune/app/Backend/ConnectionManager.java +++ b/Client/Android/app/src/main/java/com/neptune/app/Backend/ConnectionManager.java @@ -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(); } } @@ -461,7 +459,7 @@ public void onError(Exception ex) { } }; - + //webSocketClient.connect(); } public void sendWebSocketInfo (String apiURL, JsonObject requestData) throws MalformedURLException { diff --git a/Client/Android/app/src/main/java/com/neptune/app/Backend/NotificationListenerService.java b/Client/Android/app/src/main/java/com/neptune/app/Backend/NotificationListenerService.java index aef2c67..5205ead 100644 --- a/Client/Android/app/src/main/java/com/neptune/app/Backend/NotificationListenerService.java +++ b/Client/Android/app/src/main/java/com/neptune/app/Backend/NotificationListenerService.java @@ -18,9 +18,6 @@ import java.io.ByteArrayOutputStream; public class NotificationListenerService extends android.service.notification.NotificationListenerService { - - private NotificationManager notificationManager; - Context context; @Override @@ -29,7 +26,6 @@ public void onCreate() { context = getApplicationContext(); Log.d("NotificationListener", "Created."); - } public void cancelNotification (Notification[] notification) { @@ -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) { diff --git a/Client/Android/app/src/main/java/com/neptune/app/Backend/ServerConfig.java b/Client/Android/app/src/main/java/com/neptune/app/Backend/ServerConfig.java index 98e3a61..6878dc0 100644 --- a/Client/Android/app/src/main/java/com/neptune/app/Backend/ServerConfig.java +++ b/Client/Android/app/src/main/java/com/neptune/app/Backend/ServerConfig.java @@ -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; @@ -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 { diff --git a/Client/Android/app/src/main/java/com/neptune/app/Backend/ServerManager.java b/Client/Android/app/src/main/java/com/neptune/app/Backend/ServerManager.java index c67d6bd..3217212 100644 --- a/Client/Android/app/src/main/java/com/neptune/app/Backend/ServerManager.java +++ b/Client/Android/app/src/main/java/com/neptune/app/Backend/ServerManager.java @@ -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 { @@ -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) { diff --git a/Client/Android/app/src/main/java/com/neptune/app/DeviceActivity.java b/Client/Android/app/src/main/java/com/neptune/app/DeviceActivity.java index d52b01e..103d419 100644 --- a/Client/Android/app/src/main/java/com/neptune/app/DeviceActivity.java +++ b/Client/Android/app/src/main/java/com/neptune/app/DeviceActivity.java @@ -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; @@ -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(); } }); @@ -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 @@ -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(); diff --git a/Client/Android/app/src/main/java/com/neptune/app/NotificationsActivity.java b/Client/Android/app/src/main/java/com/neptune/app/NotificationsActivity.java index 581a4ac..572445e 100644 --- a/Client/Android/app/src/main/java/com/neptune/app/NotificationsActivity.java +++ b/Client/Android/app/src/main/java/com/neptune/app/NotificationsActivity.java @@ -25,7 +25,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; public class NotificationsActivity extends AppCompatActivity { @@ -33,6 +35,13 @@ public class NotificationsActivity extends AppCompatActivity { Button showBut; ListView notifView; + Button btnUncheckAll; + Button btnCheckAll; + + Server server; + + public HashMap applicationNamesToPackageNames = new HashMap<>(); + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -43,8 +52,11 @@ protected void onCreate(Bundle savedInstanceState) { aBar.setDisplayHomeAsUpEnabled(true); } + btnUncheckAll = findViewById(R.id.btnUncheckAll); + btnCheckAll = findViewById(R.id.btnCheckAlll); + notifView = findViewById(R.id.listview); - showBut = findViewById(R.id.check); + showBut = findViewById(R.id.check); // ????????? showBut.setVisibility(View.INVISIBLE); showBut.performClick(); } @@ -55,24 +67,28 @@ public void getallapps(View view) throws PackageManager.NameNotFoundException{ List ril = getPackageManager().queryIntentActivities(mainIntent, 0); //List componentList = new ArrayList(); - String name = null; - int i = 0; - - String[] apps = new String[ril.size()]; + String name; + List appsList = new ArrayList<>(); for (ResolveInfo ri : ril) { - if (ri.activityInfo != null) { - Resources res = getPackageManager().getResourcesForApplication(ri.activityInfo.applicationInfo); - if (ri.activityInfo.labelRes != 0) { - name = res.getString(ri.activityInfo.labelRes); - } else { - name = ri.activityInfo.applicationInfo.loadLabel( - getPackageManager()).toString(); + try { + if (ri.activityInfo != null) { + Resources res = getPackageManager().getResourcesForApplication(ri.activityInfo.applicationInfo); + if (ri.activityInfo.labelRes != 0) { + name = res.getString(ri.activityInfo.labelRes); + } else { + name = ri.activityInfo.applicationInfo.loadLabel( + getPackageManager()).toString(); + } + appsList.add(name); + applicationNamesToPackageNames.put(name, ri.activityInfo.applicationInfo.packageName); } - apps[i] = name; - i++; - } + } catch (Exception r) {}; } + String[] apps = new String[appsList.size()]; + for (int i = 0; i(NotificationsActivity.this, android.R.layout.simple_list_item_multiple_choice, apps)); ArrayAdapter allApps = new ArrayAdapter(NotificationsActivity.this, android.R.layout.simple_list_item_multiple_choice, apps); @@ -83,88 +99,77 @@ public void getallapps(View view) throws PackageManager.NameNotFoundException{ This also grabs the server ID from the other activities so that we can call the correct server's blacklist here. * */ String serverId = getIntent().getStringExtra("ID2"); - Server server = MainActivity.serverManager.getServer(UUID.fromString(serverId)); - List blacklistedApps = new ArrayList(); - for(int j=0; j< apps.length; j++) { - blacklistedApps.add(apps[j]); - } + server = MainActivity.serverManager.getServer(UUID.fromString(serverId)); /* These lines of code check if there is a blacklist created for the server and adds all apps to it if there is not one. If there is one created, it checks the boxes of the apps not in the blacklist. */ - int count = 0; - if(server.notificationBlacklistApps.size() == 0) { - server.notificationBlacklistApps = blacklistedApps; - } - else { - for(int k=0; k(); + for (String packageName : applicationNamesToPackageNames.values()) { + server.notificationBlacklistApps.add(packageName); + } + } else { + for (int a = 0; a parent, View view, int position, long id) { - String selectedItem = (String) parent.getItemAtPosition(position); - blackListedAppsCheck(server.notificationBlacklistApps, selectedItem); - 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())); - }*/ - /* Log to check if the apps are being stored correctly in the list. They do. - for (int j = 0; j blackListedAppsCheck(List before, String app) { - if(before.size()==0) { - before.add(app); - return before; - } + btnUncheckAll.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + for (int a = 0; a + app:layout_constraintTop_toTopOf="parent" />