Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
danilo-delbusso committed Mar 22, 2021
1 parent 3ef0262 commit 272eeb4
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 48 deletions.
18 changes: 0 additions & 18 deletions app/release/output-metadata.json

This file was deleted.

6 changes: 4 additions & 2 deletions app/src/main/java/com/prj/app/CryptoManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class CryptoManager {
/**
* Generate a new key for SQLite encryption if it doesn't exit. Key is unique per app install and
* all data is lost when key is deleted
*
* @param context the context that will store the encrypted key
*/
public static void generateDatabasePassword(Context context) {
Expand All @@ -40,10 +41,11 @@ public static void generateDatabasePassword(Context context) {

/**
* Get the encrypted SQLite key and decrypt it using the keystore.
*
* @param context the context that stored the encrypted key
* @return a string containing the password for the database
*/
public static String getDatabasePassword(Context context){
public static String getDatabasePassword(Context context) {
Store store = new Store(context);
SharedPreferences sharedPref = context.getSharedPreferences(
context.getString(R.string.preference_file_key), Context.MODE_PRIVATE);
Expand All @@ -52,7 +54,7 @@ public static String getDatabasePassword(Context context){

Crypto crypto = new Crypto(Options.TRANSFORMATION_SYMMETRIC);
String encryptedKey = sharedPref.getString(PREFERENCE_NAME, null);
if(encryptedKey == null){
if (encryptedKey == null) {
return null;
}

Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/com/prj/app/CustomWifiListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import android.net.wifi.WifiManager;

public class CustomWifiListener extends BroadcastReceiver {
Expand All @@ -13,8 +12,7 @@ public void onReceive(Context context, Intent intent) {
NotificationManager notificationManager = NotificationManager.getInstance(context);
int extraWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN);

switch (extraWifiState)
{
switch (extraWifiState) {
case WifiManager.WIFI_STATE_DISABLED:
case WifiManager.WIFI_STATE_DISABLING:
notificationManager.setIsScanningVisible(false);
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/prj/app/ExposureWorker.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.prj.app;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
Expand Down
32 changes: 15 additions & 17 deletions app/src/main/java/com/prj/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ public class MainActivity extends AppCompatActivity {
private static Intent wifiScanningIntent;
private static RippleBackground rippleBackground;

public static void updateRippleAnimation(@NotNull Context context) {
NotificationManager notificationManager = NotificationManager.getInstance(context);

if (rippleBackground != null) {
if (notificationManager.getIsScanningVisible() && !rippleBackground.isRippleAnimationRunning()) {
rippleBackground.startRippleAnimation();
} else if (!notificationManager.getIsScanningVisible() && rippleBackground.isRippleAnimationRunning()) {
rippleBackground.stopRippleAnimation();
}
}
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -44,12 +56,12 @@ protected void onCreate(Bundle savedInstanceState) {
MainActivity.this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
100);
}else{
} else {
initialiseActivity();
}
}

private void initialiseActivity (){
private void initialiseActivity() {
if (wifiScanningIntent == null) {
wifiScanningIntent = new Intent(this, WifiScanningService.class);
wifiScanningIntent.putExtra("inputExtra", "Wifi Scanning Service");
Expand All @@ -61,7 +73,6 @@ private void initialiseActivity (){
startDummyUploadsWorker();
}


/**
* Enqueue a unique request for dummy uploads
*/
Expand All @@ -75,7 +86,6 @@ private void startDummyUploadsWorker() {
.enqueueUniqueWork("DUMMY_UPLOAD", ExistingWorkPolicy.KEEP, uploadRequest);
}


/**
* Enqueue a unique request for exposure checks
*/
Expand All @@ -94,23 +104,11 @@ protected void onResume() {
updateRippleAnimation(getApplicationContext());
}

public static void updateRippleAnimation(@NotNull Context context){
NotificationManager notificationManager = NotificationManager.getInstance(context);

if (rippleBackground != null) {
if (notificationManager.getIsScanningVisible() && !rippleBackground.isRippleAnimationRunning()) {
rippleBackground.startRippleAnimation();
} else if (!notificationManager.getIsScanningVisible() && rippleBackground.isRippleAnimationRunning()) {
rippleBackground.stopRippleAnimation();
}
}
}

public void onRequestPermissionsResult(int requestCode, String @NotNull [] permissions, int @NotNull [] grantResults) {
if (grantResults[0] != PackageManager.PERMISSION_GRANTED) {
NotificationManager.getInstance(getApplicationContext()).setIsScanningVisible(false);
updateRippleAnimation(getApplicationContext());
}else{
} else {
initialiseActivity();
}
}
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/com/prj/app/NotificationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ private static void createNotificationChannel(Context context, String name, Stri
}
}

public boolean getIsScanningVisible() {
return isScanningVisible;
}

public void setIsScanningVisible(boolean isScanningVisible) {
this.isScanningVisible = isScanningVisible;
}
public boolean getIsScanningVisible(){return isScanningVisible;}

/**
* Show a notification of possible exposure to SARS-CoV-2
Expand Down Expand Up @@ -103,10 +106,9 @@ public Notification getScanningNotification() {
}
}

public void updateScanningNotification(){
notificationManager.notify(FOREGROUND_NOTIFICATION_ID, getScanningNotification());
public void updateScanningNotification() {
notificationManager.notify(FOREGROUND_NOTIFICATION_ID, getScanningNotification());
}



}
2 changes: 1 addition & 1 deletion app/src/main/java/com/prj/app/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void updateSettings(View view) {
bssidMatcher.setMIN_NUMBER_OF_CONSECUTIVE_TIMESTAMPS(newMinTimestamps);
minTimestampsEditText.setText("");
}
if(apiUrlEditText.getText().toString().length() >0){
if (apiUrlEditText.getText().toString().length() > 0) {
VolleySingleton.setAPI_URL(apiUrlEditText.getText().toString());
apiUrlEditText.setText("");
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/prj/app/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ public class Util {

/**
* Extrapolate Latitude and Longitude of the average between two points that lie on a great-circle. This method uses the Haversine formula for the great-circle distance between two points.
* @see <a href="https://stackoverflow.com/a/14231286">Stack Overflow</a>
*
* @param locations List of LatLng object corresponding to the locations to average
* @return a LatLng object representing the average point of all input LatLng objects
* @see <a href="https://stackoverflow.com/a/14231286">Stack Overflow</a>
*/
public static LatLng getLocationAverage(List<LatLng> locations) {
if (locations.size() == 1) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/prj/app/VolleySingleton.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static void setAPI_URL(String newUrl) {
API_URL = String.format("http://%s/api/v1/", newUrl);

}

public RequestQueue getRequestQueue() {
return requestQueue;
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/prj/app/WifiScanningService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;

@SuppressLint("StaticFieldLeak")
public class WifiScanningService extends Service {
private static final int DELAY_MILLIS = 30001; //only once every 30s as for Android 9+ (four times in a 2 minute period)
Expand Down Expand Up @@ -79,7 +80,7 @@ public void run() {
* Register a wifi state listener. Used to check the status of wifi services.
*/
private void registerWiFiListener() {
if(wifiListener == null){
if (wifiListener == null) {
wifiListener = new CustomWifiListener();
getApplicationContext().registerReceiver(wifiListener, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));
}
Expand Down

0 comments on commit 272eeb4

Please sign in to comment.