Skip to content

Commit

Permalink
Merge pull request #113 from Mahmud0808/master
Browse files Browse the repository at this point in the history
Merge master into fdroid
  • Loading branch information
Mahmud0808 authored Aug 14, 2024
2 parents be259ce + 93c97cf commit 4adb1a4
Show file tree
Hide file tree
Showing 34 changed files with 991 additions and 584 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

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

1 change: 1 addition & 0 deletions .idea/gradle.xml

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

3 changes: 2 additions & 1 deletion .idea/misc.xml

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

4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
defaultConfig {
minSdk = 31
targetSdk = 34
versionCode = 13
versionName = "v1.5"
versionCode = 14
versionName = "v1.6"
}

buildTypes {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission
android:name="android.permission.READ_MEDIA_IMAGES"
tools:ignore="SelectedPhotoAccess" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

public class Const {

Expand Down Expand Up @@ -46,6 +47,7 @@ public class Const {
public static final String THEME_CUSTOMIZATION_OVERLAY_PACKAGES = "theme_customization_overlay_packages";
public static final String SHIZUKU_THEMING_ENABLED = "shizukuThemingEnabled";
public static final String APP_LIST_FILTER_METHOD = "appListFilterMethod";
public static final AtomicInteger screenOrientation = new AtomicInteger(-1);

// Service preferences
public static final Gson GSON = new Gson();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.drdisagree.colorblendr.service;

import static com.drdisagree.colorblendr.utils.SystemUtil.sensorEventListener;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
Expand All @@ -8,6 +10,8 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.media.AudioManager;
import android.os.IBinder;
import android.os.RemoteException;
Expand All @@ -21,6 +25,7 @@
import com.drdisagree.colorblendr.BuildConfig;
import com.drdisagree.colorblendr.ColorBlendr;
import com.drdisagree.colorblendr.R;
import com.drdisagree.colorblendr.utils.annotations.TestingOnly;
import com.drdisagree.colorblendr.common.Const;
import com.drdisagree.colorblendr.extension.MethodInterface;
import com.drdisagree.colorblendr.provider.RootConnectionProvider;
Expand All @@ -40,15 +45,7 @@ public class AutoStartService extends Service {
private static final String NOTIFICATION_CHANNEL_ID = "Background Service";
private static BroadcastListener myReceiver;
private NotificationManager notificationManager;

// for testing background running service
private final boolean TEST_BACKGROUND_SERVICE = false;
private final boolean debugging = BuildConfig.DEBUG && TEST_BACKGROUND_SERVICE;
public int counter = 0;
private Timer timer;
private static final String packageName = ColorBlendr.getAppContext().getPackageName();
public static final String ACTION_FOO = packageName + ".FOO";
public static final String EXTRA_PARAM_A = packageName + ".PARAM_A";
public static SensorManager sensorManager;

public AutoStartService() {
isRunning = false;
Expand All @@ -69,11 +66,8 @@ public IBinder onBind(Intent intent) {
public void onCreate() {
super.onCreate();

if (notificationManager == null) {
notificationManager = getSystemService(NotificationManager.class);
}

isRunning = true;
registerSystemServices();
createNotificationChannel();
showNotification();
registerReceivers();
Expand All @@ -87,13 +81,13 @@ public void onCreate() {
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);

if (debugging) {
// for testing background running service
setupSystemUIRestartListener();

if (isTestingService) {
// Testing purposes only
startTimer(this);
}

setupSystemUIRestartListener();

return START_STICKY;
}

Expand All @@ -113,9 +107,25 @@ public void onDestroy() {
Intent broadcastIntent = new Intent(this, RestartBroadcastReceiver.class);
sendBroadcast(broadcastIntent);

if (debugging) {
// for testing background running service
stopTimerTask();
if (isTestingService) {
// Testing purposes only
stopTimer();
}
}

private void registerSystemServices() {
if (notificationManager == null) {
notificationManager = getSystemService(NotificationManager.class);
}

if (sensorManager == null) {
sensorManager = getSystemService(SensorManager.class);

if (sensorManager != null) {
sensorManager.registerListener(sensorEventListener,
sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_UI);
}
}
}

Expand Down Expand Up @@ -214,25 +224,48 @@ private void initSystemUIRestartListener() {
}
}

/*
* The following fields and methods are for testing purposes only
*/
@TestingOnly
private static final String TEST_TAG = AutoStartService.class.getSimpleName() + "_TEST";
@TestingOnly
private final boolean TEST_BACKGROUND_SERVICE = false;
@TestingOnly
private final boolean isTestingService = BuildConfig.DEBUG && TEST_BACKGROUND_SERVICE;
@TestingOnly
public int counter = 0;
@TestingOnly
private Timer timer;
@TestingOnly
private static final String packageName = ColorBlendr.getAppContext().getPackageName();
@TestingOnly
public static final String ACTION_FOO = packageName + ".FOO";
@TestingOnly
public static final String EXTRA_PARAM_A = packageName + ".PARAM_A";

@TestingOnly
public void startTimer(Context context) {
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
Log.i(TAG, "Timer is running " + counter++);
Log.i(TEST_TAG, "Timer is running " + counter++);
broadcastActionTest(context, String.valueOf(counter));
}
}, 1000, 1000);
}

@TestingOnly
public static void broadcastActionTest(Context context, String param) {
Intent intent = new Intent(ACTION_FOO);
intent.putExtra(EXTRA_PARAM_A, param);
LocalBroadcastManager bm = LocalBroadcastManager.getInstance(context);
bm.sendBroadcast(intent);
}

public void stopTimerTask() {
@TestingOnly
public void stopTimer() {
if (timer != null) {
timer.cancel();
timer = null;
Expand Down
Loading

0 comments on commit 4adb1a4

Please sign in to comment.