Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade target api and dependencies #129

Merged
merged 21 commits into from
Jan 2, 2024
Merged
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
25 changes: 16 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ apply plugin: 'kotlin-android'
def pfaFile = rootProject.file('pfa.properties')

android {
namespace 'org.secuso.privacyfriendlyactivitytracker'

signingConfigs {
if (pfaFile.exists()) {
Expand All @@ -18,14 +19,15 @@ android {
}
}
}
compileSdk 34

compileSdkVersion 32
defaultConfig {
applicationId 'org.secuso.privacyfriendlyactivitytracker'
minSdkVersion 17
targetSdkVersion 32
targetSdkVersion 34
versionCode 15
versionName "3.0.1"
multiDexEnabled true
}

applicationVariants.all { variant ->
Expand All @@ -48,7 +50,10 @@ android {
}
productFlavors {
}
namespace 'org.secuso.privacyfriendlyactivitytracker'
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}

repositories {
Expand All @@ -58,18 +63,20 @@ repositories {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(path: ':backup-api')
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.0-beta1'
implementation 'androidx.multidex:multidex:2.0.1' //with androidx libraries

def work_version = "2.7.1"
def work_version = '2.9.0'
implementation "androidx.work:work-runtime:$work_version"
implementation "androidx.work:work-runtime-ktx:$work_version"
androidTestImplementation "androidx.work:work-testing:$work_version"

implementation "androidx.sqlite:sqlite-ktx:2.2.0"
implementation 'androidx.sqlite:sqlite-framework:2.2.0'
implementation 'androidx.sqlite:sqlite-ktx:2.4.0'
implementation 'androidx.sqlite:sqlite-framework:2.4.0'
}

10 changes: 8 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_HEALTH" />
<!-- <uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS" /> -->

<application
android:allowBackup="true"
Expand All @@ -59,7 +63,6 @@
</activity>
<activity
android:name="org.secuso.privacyfriendlyactivitytracker.activities.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity
Expand Down Expand Up @@ -185,11 +188,14 @@
<receiver android:name="org.secuso.privacyfriendlyactivitytracker.receivers.MotivationAlertReceiver" />

<service android:name="org.secuso.privacyfriendlyactivitytracker.services.MovementSpeedService"
android:foregroundServiceType="health"
android:permission="android.permission.BIND_JOB_SERVICE"/>
<service android:name="org.secuso.privacyfriendlyactivitytracker.services.AccelerometerStepDetectorService"
android:foregroundServiceType="health"
android:permission="android.permission.BIND_JOB_SERVICE"/>
<service
android:name="org.secuso.privacyfriendlyactivitytracker.services.HardwareStepService"
android:foregroundServiceType="health"
android:stopWithTask="false"
android:permission="android.permission.BIND_JOB_SERVICE"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.multidex.MultiDexApplication;
import androidx.work.Configuration;

import org.secuso.privacyfriendlyactivitytracker.backup.BackupCreator;
Expand All @@ -15,7 +16,7 @@
import java.lang.ref.WeakReference;
import java.util.concurrent.atomic.AtomicBoolean;

public class PFAPedometerApplication extends Application implements Configuration.Provider {
public class PFAPedometerApplication extends MultiDexApplication implements Configuration.Provider {

@Override
public void onCreate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* @version 20160704
*/

public class BaseActivity extends AppCompatActivity implements OnNavigationItemSelectedListener {
public class BaseActivity extends PermissionRequestActivity implements OnNavigationItemSelectedListener {

// delay to launch nav drawer item, to allow close animation to play
static final int NAVDRAWER_LAUNCH_DELAY = 250;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,18 @@
*/
package org.secuso.privacyfriendlyactivitytracker.activities;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Build;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentTransaction;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import org.secuso.privacyfriendlyactivitytracker.R;
import org.secuso.privacyfriendlyactivitytracker.fragments.DailyReportFragment;
import org.secuso.privacyfriendlyactivitytracker.fragments.MainFragment;
import org.secuso.privacyfriendlyactivitytracker.fragments.MonthlyReportFragment;
import org.secuso.privacyfriendlyactivitytracker.fragments.WeeklyReportFragment;
import org.secuso.privacyfriendlyactivitytracker.utils.StepDetectionServiceHelper;
import org.secuso.privacyfriendlyactivitytracker.tutorial.TutorialActivity;

/**
* Main view incl. navigation drawer and fragments
Expand All @@ -47,14 +39,15 @@

public class MainActivity extends BaseActivity implements DailyReportFragment.OnFragmentInteractionListener, WeeklyReportFragment.OnFragmentInteractionListener, MonthlyReportFragment.OnFragmentInteractionListener {

private static final int ACTIVITY_RECOGNITION = 1;
private boolean askedAlready = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!hasActivityRecognitionPermission()) {
startActivity(new Intent(MainActivity.this, TutorialActivity.class));
finish();
}
setContentView(R.layout.activity_main);

// init preferences
PreferenceManager.setDefaultValues(this, R.xml.pref_general, false);
PreferenceManager.setDefaultValues(this, R.xml.pref_notification, false);
Expand All @@ -64,44 +57,12 @@ protected void onCreate(Bundle savedInstanceState) {
fragmentTransaction.replace(R.id.content_frame, new MainFragment(), "MainFragment");
fragmentTransaction.commit();

// Start step detection if enabled and not yet started
StepDetectionServiceHelper.startAllIfEnabled(this);
//Log.i(LOG_TAG, "MainActivity initialized");
}

@Override
protected int getNavigationDrawerID() {
return R.id.menu_home;
}

public void requestPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && ContextCompat.checkSelfPermission(this, Manifest.permission.ACTIVITY_RECOGNITION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{ Manifest.permission.ACTIVITY_RECOGNITION }, ACTIVITY_RECOGNITION);
}
}

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

// if permission is not granted ask again
if(requestCode == ACTIVITY_RECOGNITION) {
if(grantResults.length > 0 && grantResults[0] != PackageManager.PERMISSION_GRANTED) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
if(askedAlready) {
builder.setMessage(R.string.dialog_permission_activity_recognition_2);
builder.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
dialogInterface.dismiss();
});
} else {
builder.setMessage(R.string.dialog_permission_activity_recognition);
builder.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
requestPermission();
dialogInterface.dismiss();
});
}
builder.create().show();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package org.secuso.privacyfriendlyactivitytracker.activities;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import org.secuso.privacyfriendlyactivitytracker.R;
import org.secuso.privacyfriendlyactivitytracker.tutorial.TutorialActivity;

public class PermissionRequestActivity extends AppCompatActivity {
private final String TAG = this.getClass().getSimpleName();
private ActivityResultLauncher<String[]> multiplePermissionLauncher;
private static final String[] PERMISSIONS = new String[]{
Manifest.permission.ACTIVITY_RECOGNITION,
Manifest.permission.POST_NOTIFICATIONS
};

int alreadyAskedForActivityRecognition = 0;
int alreadyAskedForOther = 0;
private boolean launchMainActivityAfterPermissionsGranted;

void multiplePermissionsCallback(java.util.Map<String, Boolean> isGranted) {
if (isGranted.containsValue(false)) {
if (Boolean.FALSE.equals(isGranted.get(Manifest.permission.ACTIVITY_RECOGNITION))) {
alreadyAskedForActivityRecognition++;
if (alreadyAskedForActivityRecognition > 1) {
Log.d(TAG, "Activity recognition permission was still not granted, showing final dialog");
new AlertDialog.Builder(this)
.setMessage(R.string.dialog_permission_activity_recognition_2)
.setPositiveButton(android.R.string.ok, (dialog, which) -> finish())
.show();
} else {
Log.d(TAG, "Activity recognition permission was not granted, showing dialog");
new AlertDialog.Builder(this)
.setMessage(R.string.dialog_permission_activity_recognition)
.setPositiveButton(android.R.string.ok, (dialog, which) -> multiplePermissionLauncher.launch(PERMISSIONS))
.show();

}
} else {
alreadyAskedForOther++;
if (alreadyAskedForOther < 2) {
multiplePermissionLauncher.launch(PERMISSIONS);
}
}
}
if (hasActivityRecognitionPermission()) {
if (launchMainActivityAfterPermissionsGranted) {
launchMainActivityAfterPermissionsGranted = false;
Log.d(TAG, "Activity recognition permission was granted, launching main activity");
startActivity(new Intent(this, MainActivity.class));
finish();
}
}
}

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityResultContracts.RequestMultiplePermissions multiplePermissionsContract = new ActivityResultContracts.RequestMultiplePermissions();
multiplePermissionLauncher = registerForActivityResult(multiplePermissionsContract, this::multiplePermissionsCallback);
// askPermissions(multiplePermissionLauncher);
}

private void askPermissions(ActivityResultLauncher<String[]> multiplePermissionLauncher) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (!hasPermissions(PERMISSIONS) && alreadyAskedForOther < 2 && alreadyAskedForActivityRecognition < 2) {
Log.d(TAG, "Launching multiple contract permission launcher for ALL required permissions");
multiplePermissionLauncher.launch(PERMISSIONS);
} else {
Log.d(TAG, "All permissions are already granted");
}
}
}

public void askPermissions() {
askPermissions(multiplePermissionLauncher);
}

public void askPermissionsAndLaunch() {
launchMainActivityAfterPermissionsGranted = true;
askPermissions(multiplePermissionLauncher);
}

private boolean hasPermissions(String[] permissions) {
if (permissions != null) {
for (String permission : permissions) {
if (ActivityCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Permission is not granted: " + permission);
return false;
}
Log.d(TAG, "Permission already granted: " + permission);
}
return true;
}
return false;
}

protected boolean hasActivityRecognitionPermission() {
return (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || hasPermissions(new String[]{Manifest.permission.ACTIVITY_RECOGNITION}));
}
}
Loading