Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a190879
Remove redundant target API notices
Doomsdayrs Feb 6, 2023
46c7680
Inline old sdk checks
Doomsdayrs Feb 6, 2023
afd054a
Update copyright
Doomsdayrs Feb 6, 2023
a610764
Add NEARBY_WIFI_DEVICES permission
Doomsdayrs Feb 6, 2023
ac886d0
Remove redundant suppression in ScreenshotService
Doomsdayrs Feb 6, 2023
f949e88
Localize variables
Doomsdayrs Feb 6, 2023
8428b6b
Make value final in NotificationPreferences
Doomsdayrs Feb 6, 2023
d8b2f23
Use Main looper in MainActivity.SynchronizationHandler
Doomsdayrs Feb 6, 2023
ddbf9e9
Update method of name retrieval in NotificationParser
Doomsdayrs Feb 6, 2023
3d665b4
Use default super constructor in PhoneStateReceiver
Doomsdayrs Feb 6, 2023
6cb5321
Use main looper for SynchronizationService.SynchronizationHandler
Doomsdayrs Feb 6, 2023
ba6ccc4
Replace setBuiltInZoomControls with direct call in WeatherSettingsFrag
Doomsdayrs Feb 6, 2023
26adbf0
Replace C Style array declaration in WeatherSettingsFragment
Doomsdayrs Feb 6, 2023
09b6aef
Make various non-final variables final due to never being modified
Doomsdayrs Feb 6, 2023
e6f8ad2
Remove unnecessary toString calls
Doomsdayrs Feb 6, 2023
2ef943e
Remove redundant public declaration in interface
Doomsdayrs Feb 6, 2023
19a8e9a
Simplify if statement in AppInfoHelper
Doomsdayrs Feb 6, 2023
7cfa5c3
Make more fields final
Doomsdayrs Feb 6, 2023
244854c
Remove empty method from AsteroidBleManager
Doomsdayrs Feb 6, 2023
6e4974c
Remove unnecessary imports
Doomsdayrs Feb 6, 2023
9eb6ccf
Replace <BluetoothDevice> wi <> in DeviceListFrag arraylist declaration
Doomsdayrs Feb 6, 2023
ded3ab4
Replace Anonymous type with lamba
Doomsdayrs Feb 6, 2023
a53d58f
Replace Collections.sort with list.sort
Doomsdayrs Feb 6, 2023
ffb7627
Make AppInfoAdapter.MyOnItemSelectedListener static
Doomsdayrs Feb 6, 2023
90c6e65
Add nullability annotations
Doomsdayrs Feb 6, 2023
93bd282
Use requireActivity in DeviceDetailFragment
Doomsdayrs Feb 6, 2023
ad474ed
mDetailFragment = not null in MainActivity.onDefaultDeviceSelected
Doomsdayrs Feb 6, 2023
073a1cf
Use requireActivity & requireContext in WeatherSettingsFragment
Doomsdayrs Feb 6, 2023
8a49a13
Inline supported boolean in AsteroidBleManager
Doomsdayrs Feb 6, 2023
27eb2d1
Remove redundant default value for msgType & id in Notification
Doomsdayrs Feb 6, 2023
daf11a6
Remove redundant byte setting in ScreenshotService
Doomsdayrs Feb 6, 2023
ef03207
Make msgType & id in Notification final
Doomsdayrs Feb 6, 2023
8388d66
Clean imports
Doomsdayrs Feb 6, 2023
b8d2608
Use method references instead of lambas in TimeService & WeatherService
Doomsdayrs Feb 6, 2023
67537bf
Update gradle
Doomsdayrs Feb 6, 2023
ac26174
Update to java 11
Doomsdayrs Feb 6, 2023
907ec67
Upgrade appcompat to 1.6.0
Doomsdayrs Feb 6, 2023
8629841
Upgrade material to 1.8.0
Doomsdayrs Feb 6, 2023
5dc5228
Use <> instead of <AppInfo> in AppInfo Parcelable.Creator
Doomsdayrs Feb 6, 2023
6cc66ea
Use auto resource management with try body
Doomsdayrs Feb 6, 2023
4e9642d
Sleep spin in NLService to prevent cpu overuse
Doomsdayrs Feb 6, 2023
d5755fa
Implement view model foundation
Doomsdayrs Feb 7, 2023
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/copyright/GPLv3.xml

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

7 changes: 7 additions & 0 deletions .idea/copyright/profiles_settings.xml

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

4 changes: 4 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Florent Revest [email protected]
Doug Koellmer [email protected]
Justus Tartz [email protected]
Doomsdayrs [email protected]
12 changes: 8 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("com.android.application")
kotlin("android")
}

android {
Expand Down Expand Up @@ -35,8 +36,8 @@ android {
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
lint {
checkReleaseBuilds = true
Expand All @@ -53,11 +54,14 @@ repositories {

dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation("androidx.core:core-ktx:1.9.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1")
testImplementation("junit:junit:4.13.2")
implementation("androidx.appcompat:appcompat:1.5.1")
implementation("androidx.appcompat:appcompat:1.6.0")
implementation("androidx.legacy:legacy-support-v4:1.0.0")
implementation("androidx.cardview:cardview:1.0.0")
implementation("com.google.android.material:material:1.6.1")
implementation("com.google.android.material:material:1.8.0")
implementation("com.github.MagneFire:EasyWeather:1.3")
implementation("com.google.code.gson:gson:2.9.1")
implementation("org.osmdroid:osmdroid-android:6.1.14")
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES" android:usesPermissionFlags="neverForLocation"/>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
Expand Down
123 changes: 40 additions & 83 deletions app/src/main/java/org/asteroidos/sync/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
/*
* AsteroidOSSync
* Copyright (c) 2023 AsteroidOS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.asteroidos.sync;

import static android.os.ParcelUuid.fromString;

import android.Manifest;
import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
Expand All @@ -17,10 +37,7 @@
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.Messenger;
import android.os.ParcelUuid;
import android.os.RemoteException;
import android.provider.Settings;
import android.util.Log;
import android.view.MenuItem;
Expand All @@ -35,6 +52,7 @@
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;

import org.asteroidos.sync.asteroid.IAsteroidDevice;
import org.asteroidos.sync.fragments.AppListFragment;
Expand All @@ -45,6 +63,8 @@
import org.asteroidos.sync.utils.AppInfo;
import org.asteroidos.sync.utils.AppInfoHelper;
import org.asteroidos.sync.utils.AsteroidUUIDS;
import org.asteroidos.sync.viewmodel.base.MainActivityViewModel;
import org.asteroidos.sync.viewmodel.impl.MainActivityViewModelImpl;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -55,8 +75,6 @@
import no.nordicsemi.android.support.v18.scanner.ScanResult;
import no.nordicsemi.android.support.v18.scanner.ScanSettings;

import static android.os.ParcelUuid.fromString;

public class MainActivity extends AppCompatActivity implements DeviceListFragment.OnDefaultDeviceSelectedListener,
DeviceListFragment.OnScanRequestedListener, DeviceDetailFragment.OnDefaultDeviceUnselectedListener,
DeviceDetailFragment.OnConnectRequestedListener, DeviceDetailFragment.OnAppSettingsClickedListener,
Expand All @@ -67,29 +85,25 @@ public class MainActivity extends AppCompatActivity implements DeviceListFragmen
public static final String PREFS_DEFAULT_LOC_NAME = "defaultLocalName";
private static final String TAG = "MainActivity";
public static ArrayList<AppInfo> appInfoList;
final Messenger mDeviceDetailMessenger = new Messenger(new MainActivity.SynchronizationHandler(this));
public ParcelUuid asteroidUUID = fromString(AsteroidUUIDS.SERVICE_UUID.toString());
Messenger mSyncServiceMessenger;
public final ParcelUuid asteroidUUID = fromString(AsteroidUUIDS.SERVICE_UUID.toString());
ActivityResultLauncher<Intent> mLocationEnableActivityLauncher;
LocationManager mLocationManager;
/* Synchronization service events handling */
private final ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className,
IBinder service) {
mSyncServiceMessenger = new Messenger(service);
onUpdateRequested();
}

public void onServiceDisconnected(ComponentName className) {
mSyncServiceMessenger = null;
}
};
Intent mSyncServiceIntent;
IAsteroidDevice.ConnectionState mStatus = IAsteroidDevice.ConnectionState.STATUS_DISCONNECTED;
ScanSettings mSettings;
List<ScanFilter> mFilters;
private DeviceListFragment mListFragment;
public ScanCallback scanCallback = new ScanCallback() {
public final ScanCallback scanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, @NonNull ScanResult result) {
super.onScanResult(callbackType, result);
Expand All @@ -102,30 +116,31 @@ public void onScanResult(int callbackType, @NonNull ScanResult result) {
}
return;
}
Log.d(TAG, "SCAN RESULT:" + result.getDevice().toString() + " Name:" + result.getDevice().getName());
Log.d(TAG, "SCAN RESULT:" + result.getDevice() + " Name:" + result.getDevice().getName());
ParcelUuid[] arr = result.getDevice().getUuids();
}
};
private DeviceDetailFragment mDetailFragment;
private Fragment mPreviousFragment;
private BluetoothLeScannerCompat mScanner;
private SharedPreferences mPrefs;
MainActivityViewModel viewModel;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewModel = new ViewModelProvider(this).get(MainActivityViewModelImpl.class);
viewModel.onWatchLocalNameChanged(this::handleSetLocalName);
viewModel.onWatchConnectionStateChanged(this::handleSetStatus);
viewModel.onWatchBatteryPercentageChanged(this::handleSetBatteryPercentage);

mScanner = BluetoothLeScannerCompat.getScanner();

mPrefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
String defaultDevMacAddr = mPrefs.getString(PREFS_DEFAULT_MAC_ADDR, "");

Thread appInfoRetrieval = new Thread(new Runnable() {
public void run() {
appInfoList = AppInfoHelper.getPackageInfo(MainActivity.this);
}
});
Thread appInfoRetrieval = new Thread(() -> appInfoList = AppInfoHelper.getPackageInfo(MainActivity.this));
appInfoRetrieval.start();

mSettings = new ScanSettings.Builder()
Expand Down Expand Up @@ -179,20 +194,14 @@ public void onDefaultDeviceSelected(BluetoothDevice mDevice) {
mDetailFragment = new DeviceDetailFragment();

if (mListFragment != null) mListFragment.scanningStopped();
else if (mDetailFragment != null) mDetailFragment.scanningStopped();
else mDetailFragment.scanningStopped();

getSupportFragmentManager()
.beginTransaction()
.replace(R.id.flContainer, mDetailFragment)
.commit();

try {
Message msg = Message.obtain(null, SynchronizationService.MSG_SET_DEVICE);
msg.obj = mDevice;
msg.replyTo = mDeviceDetailMessenger;
mSyncServiceMessenger.send(msg);
} catch (RemoteException ignored) {
}
viewModel.onDefaultDeviceSelected(mDevice);

onConnectRequested();

Expand All @@ -209,49 +218,27 @@ public void onDefaultDeviceUnselected() {
.replace(R.id.flContainer, mListFragment)
.commit();

try {
Message msg = Message.obtain(null, SynchronizationService.MSG_UNSET_DEVICE);
msg.obj = "";
msg.replyTo = mDeviceDetailMessenger;
mSyncServiceMessenger.send(msg);
} catch (RemoteException ignored) {
}
viewModel.requestUnsetDevice();

mDetailFragment = null;
setTitle(R.string.app_name);
}

@Override
public void onUpdateRequested() {
try {
Message msg = Message.obtain(null, SynchronizationService.MSG_UPDATE);
msg.replyTo = mDeviceDetailMessenger;
if (mSyncServiceMessenger != null)
mSyncServiceMessenger.send(msg);
} catch (RemoteException ignored) {
}
viewModel.requestUpdate();
}

@Override
public void onConnectRequested() {
if (mScanner != null)
mScanner.stopScan(scanCallback);
try {
Message msg = Message.obtain(null, SynchronizationService.MSG_CONNECT);
msg.replyTo = mDeviceDetailMessenger;
mSyncServiceMessenger.send(msg);
} catch (RemoteException ignored) {
}
viewModel.requestConnect();
}

@Override
public void onDisconnectRequested() {
try {
Message msg = Message.obtain(null, SynchronizationService.MSG_DISCONNECT);
msg.replyTo = mDeviceDetailMessenger;
mSyncServiceMessenger.send(msg);
} catch (RemoteException ignored) {
}
viewModel.requestDisconnect();
}

@Override
Expand Down Expand Up @@ -342,12 +329,7 @@ private void handleSetStatus(IAsteroidDevice.ConnectionState status) {
mStatus = status;
}
if (status == IAsteroidDevice.ConnectionState.STATUS_CONNECTED) {
try {
Message msg = Message.obtain(null, SynchronizationService.MSG_REQUEST_BATTERY_LIFE);
msg.replyTo = mDeviceDetailMessenger;
mSyncServiceMessenger.send(msg);
} catch (RemoteException ignored) {
}
viewModel.requestBatteryLevel();
}
}

Expand Down Expand Up @@ -418,7 +400,7 @@ protected void onPause() {
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
getDelegate().onConfigurationChanged(newConfig);
int currentNightMode = newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK;
Expand All @@ -435,29 +417,4 @@ public void onConfigurationChanged(Configuration newConfig) {
overridePendingTransition(0, 0);
startActivity(getIntent());
}

static private class SynchronizationHandler extends Handler {
private final MainActivity mActivity;

SynchronizationHandler(MainActivity activity) {
mActivity = activity;
}

@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case SynchronizationService.MSG_SET_LOCAL_NAME:
mActivity.handleSetLocalName((String) msg.obj);
break;
case SynchronizationService.MSG_SET_STATUS:
mActivity.handleSetStatus((IAsteroidDevice.ConnectionState) msg.obj);
break;
case SynchronizationService.MSG_SET_BATTERY_PERCENTAGE:
mActivity.handleSetBatteryPercentage(msg.arg1);
break;
default:
super.handleMessage(msg);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* AsteroidOSSync
* Copyright (c) 2023 AsteroidOS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.asteroidos.sync;

import android.content.Context;
Expand All @@ -21,7 +39,7 @@ public enum NotificationOption {
STRONG_VIBRATION(4),
RINGTONE_VIBRATION(5);

private int value;
private final int value;
NotificationOption(int value) {
this.value = value;
}
Expand Down
Loading