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
6 changes: 6 additions & 0 deletions .idea/AndroidProjectSystem.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 1 addition & 18 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions .idea/modules.xml

This file was deleted.

8 changes: 8 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 17 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
buildToolsVersion '23.0.3'
namespace "org.rockettrack"

compileSdkVersion 33
defaultConfig {
applicationId "org.rockettrack"
minSdkVersion 17
minSdkVersion 31
targetSdkVersion 28
versionCode 2
versionName "1.0"
Expand All @@ -21,9 +22,18 @@ android {
}

dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
// AndroidX AppCompat
implementation 'androidx.appcompat:appcompat:1.6.1'

// AndroidX Legacy Support Libraries
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'

// Latest Play Services Maps library (update to latest stable version)
implementation 'com.google.android.gms:play-services-maps:19.2.0'
// For developers using AndroidX in their applications
implementation 'pub.devrel:easypermissions:3.0.0'

implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:support-v13:28.0.0'
implementation 'com.google.android.gms:play-services-maps:9.2.0'
// For developers using the Android Support Library
implementation 'pub.devrel:easypermissions:2.0.1'
}
17 changes: 14 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.rockettrack"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:targetSdkVersion="33" />

android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

<permission
android:name="org.rockettrack.permission.MAPS_RECEIVE"
Expand All @@ -21,9 +26,12 @@
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<!-- for g-maps and saving file -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />

<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
Expand All @@ -46,7 +54,7 @@
<activity
android:name="org.rockettrack.Startup"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name">
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -68,6 +76,9 @@
android:label="@string/select_device"
android:theme="@android:style/Theme.Dialog" />

<activity android:name=".LogActivity"
android:theme="@style/Theme.AppCompat" />

<service
android:name=".service.AppService"
android:enabled="true"
Expand Down
52 changes: 49 additions & 3 deletions app/src/main/java/org/rockettrack/DeviceListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.Manifest;
import android.os.Bundle;
import android.os.ParcelUuid;
import android.util.Log;
Expand All @@ -40,14 +41,20 @@
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;

/**
* This Activity appears as a dialog. It lists any paired devices and
* devices detected in the area after discovery. When a device is chosen
* by the user, the MAC address of the device is sent back to the parent
* Activity in the result Intent.
*/
public class DeviceListActivity extends Activity {

private final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

// Debugging
Expand All @@ -57,13 +64,15 @@ public class DeviceListActivity extends Activity {
// Return Intent extra
public static String EXTRA_DEVICE_ADDRESS = "device_address";

private static final int REQUEST_BLUETOOTH_CONNECT = 123;

// Member fields
private BluetoothAdapter mBtAdapter;
private ArrayAdapter<String> mPairedDevicesArrayAdapter;
private ArrayAdapter<String> mNewDevicesArrayAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Setup the window
Expand All @@ -73,6 +82,39 @@ protected void onCreate(Bundle savedInstanceState) {
// Set result CANCELED incase the user backs out
setResult(Activity.RESULT_CANCELED);

// Check and request Bluetooth permission
boolean hasPermissions = EasyPermissions.hasPermissions(this,
Manifest.permission.BLUETOOTH_CONNECT,
Manifest.permission.BLUETOOTH_SCAN);
if (hasPermissions) {
// Permission already granted, proceed with Bluetooth functionality
getBondedDevices();
} else {
// Request Bluetooth permission
EasyPermissions.requestPermissions(
this,
"Bluetooth permission is required to access bonded devices.",
REQUEST_BLUETOOTH_CONNECT,
Manifest.permission.BLUETOOTH_SCAN
);
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}

@AfterPermissionGranted(REQUEST_BLUETOOTH_CONNECT)
private void getBondedDevices() {
// This method will be called when Bluetooth permission is granted
// Proceed with accessing Bluetooth functionality, e.g., get paired devices
// TODO
// Set<BluetoothDevice> pairedDevices = BluetoothAdapter.getDefaultAdapter().getBondedDevices();
// Handle paired devices as needed


// Initialize the button to perform device discovery
Button scanButton = (Button) findViewById(R.id.button_scan);
scanButton.setOnClickListener(new OnClickListener() {
Expand Down Expand Up @@ -111,6 +153,10 @@ public void onClick(View v) {
// Get a set of currently paired devices
Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();

extracted(pairedDevices);
}

private void extracted(Set<BluetoothDevice> pairedDevices) {
// If there are paired devices, add each one to the ArrayAdapter
if (pairedDevices.size() > 0) {
findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE);
Expand All @@ -124,7 +170,7 @@ public void onClick(View v) {
mPairedDevicesArrayAdapter.add(noDevices);
}
}

private boolean isSPPDevice( BluetoothDevice device ) {

ParcelUuid[] supportedFunctions = device.getUuids();
Expand Down
60 changes: 60 additions & 0 deletions app/src/main/java/org/rockettrack/LogActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.rockettrack;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class LogActivity extends AppCompatActivity {

private TextView logTextView;
private final StringBuilder logContent = new StringBuilder();

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

logTextView = findViewById(R.id.log_output);
Button emailButton = findViewById(R.id.email_button);

loadLogcat();

emailButton.setOnClickListener(v -> emailLog());
}

private void loadLogcat() {
try {
Process process = Runtime.getRuntime().exec("logcat -d");
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));

String line;
while ((line = reader.readLine()) != null) {
logContent.append(line).append('\n');
}

logTextView.setText(logContent.toString());

} catch (Exception e) {
logTextView.setText("Failed to load logcat: " + e.getMessage());
}
}

private void emailLog() {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_SUBJECT, "Logcat Output");
intent.putExtra(Intent.EXTRA_TEXT, logContent.toString());

try {
startActivity(Intent.createChooser(intent, "Send Email"));
} catch (android.content.ActivityNotFoundException ex) {
logTextView.setText("No email clients installed.");
}
}
}
Loading