Compare commits

..

No commits in common. "883ace4eb27ca86b430bdffedfa06abaf61805bc" and "ca8dd917b8ac0683c4116d019e064e575476eb87" have entirely different histories.

6 changed files with 31 additions and 68 deletions

1
.gitignore vendored
View file

@ -11,4 +11,3 @@ local.properties
*.jks
*.keystore
keystore.properties
/release

View file

@ -24,8 +24,6 @@
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.MANAGE_NOTIFICATION_LISTENERS" />
<uses-sdk
android:minSdkVersion="31"
@ -40,10 +38,11 @@
<receiver
android:name="net.typeblog.lunatic.BootCompletedReceiver"
android:exported="true">
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>

View file

@ -122,7 +122,6 @@ public final class AnimationManager {
public void playCharging() {
StatusManager.setChargingLedsActive(true);
submit(() -> {
final int num_leds = mLEDManager.getNumLEDs();
int solid_leds = 0;
mLEDManager.enableAllLEDs(false);
mLEDManager.setColor(0xffffff);
@ -132,17 +131,17 @@ public final class AnimationManager {
while (check(Constants.SpotlightMode.CHARGING)) {
int batteryLevel = getBatteryLevel();
if (oldBatteryLevel != batteryLevel) {
solid_leds = (int) Math.floor(batteryLevel / 100.0d * num_leds);
solid_leds = Integer.valueOf(batteryLevel / mLEDManager.getNumLEDs());
for (int i = 0; i < solid_leds; i++) {
mLEDManager.enableLED(num_leds - i - 1, true);
mLEDManager.enableLED(i, true);
Thread.sleep(150);
}
oldBatteryLevel = batteryLevel;
}
if (100 - solid_leds * mLEDManager.getNumLEDs() > 0) {
mLEDManager.enableLED(num_leds - solid_leds - 1, true);
mLEDManager.enableLED(solid_leds, true);
Thread.sleep(500);
mLEDManager.enableLED(num_leds - solid_leds - 1, false);
mLEDManager.enableLED(solid_leds, false);
Thread.sleep(500);
}
}
@ -215,8 +214,6 @@ public final class AnimationManager {
} catch (InterruptedException e) {
mLEDManager.enableAllLEDs(false);
}
stopNotifications();
});
}
@ -231,7 +228,6 @@ public final class AnimationManager {
submit(() -> {
if (check(Constants.SpotlightMode.FLASHLIGHT)) {
mLEDManager.setColor(0xffffff);
mLEDManager.setBrightness((int) (Constants.BRIGHTNESS * 100));
mLEDManager.enableAllLEDs(true);
}

View file

@ -39,6 +39,7 @@ public class NotificationService extends NotificationListenerService {
private static final String TAG = "SpotlightNotification";
private static final boolean DEBUG = true;
private ArrayList<Integer> mNotifications = new ArrayList<>();
private AnimationManager mAnimationManager;
@Override
@ -86,7 +87,19 @@ public class NotificationService extends NotificationListenerService {
&& !Arrays.asList(Constants.APPSTOIGNORE).contains(packageName)
&& !Arrays.asList(Constants.NOTIFSTOIGNORE).contains(packageName + ":" + packageChannelID)
&& (packageImportance >= NotificationManager.IMPORTANCE_DEFAULT || packageImportance == -1)) {
mNotifications.add(sbn.getId());
mAnimationManager.playNotifications();
}
}
@Override
public void onNotificationRemoved(StatusBarNotification sbn){
if (DEBUG) Log.d(TAG, "onNotificationRemoved: package:" + sbn.getPackageName() + " | channel id: " + sbn.getNotification().getChannelId() + " | id: " + sbn.getId());
if (mNotifications.contains(sbn.getId())) {
mNotifications.remove((Integer) sbn.getId());
}
if (mNotifications.isEmpty()) {
mAnimationManager.stopNotifications();
}
}
}

View file

@ -105,8 +105,7 @@ public class SettingsFragment extends PreferenceFragment implements OnPreference
final String preferenceKey = preference.getKey();
if (preferenceKey.equals(Constants.SPOTLIGHT_NOTIFS_ENABLE)) {
mNotifsPreference.setChecked(SettingsManager.isSpotlightNotifsEnabled(getActivity()));
return false;
SettingsManager.setSpotlightNotifsEnabled(getActivity(), true);
}
if (preferenceKey.equals(Constants.SPOTLIGHT_BRIGHTNESS)) {

View file

@ -18,12 +18,8 @@
package net.typeblog.lunatic.Utils;
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.PowerExemptionManager;
import android.os.UserHandle;
import android.util.Log;
import net.typeblog.lunatic.Constants.Constants;
@ -35,101 +31,62 @@ import net.typeblog.lunatic.Services.FlashlightService;
import net.typeblog.lunatic.Services.MusicService;
import net.typeblog.lunatic.Services.NotificationService;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public final class ServiceUtils {
private static final String TAG = "SpotlightServiceUtils";
private static final boolean DEBUG = true;
// Use reflection hack because Android Studio does not use our overridden framework.jar by default
private static void startServiceAsCurrentUser(Context context, Intent intent) {
try {
final Field currentField = UserHandle.class.getField("CURRENT");
UserHandle current = (UserHandle) currentField.get(null);
final Method startServiceAsUser = Context.class.getMethod("startServiceAsUser", Intent.class, UserHandle.class);
startServiceAsUser.invoke(context, intent, current);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static void stopServiceAsCurrentUser(Context context, Intent intent) {
try {
final Field currentField = UserHandle.class.getField("CURRENT");
UserHandle current = (UserHandle) currentField.get(null);
final Method stopServiceAsUser = Context.class.getMethod("stopServiceAsUser", Intent.class, UserHandle.class);
stopServiceAsUser.invoke(context, intent, current);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static void startCallReceiverService(Context context) {
if (DEBUG) Log.d(TAG, "Starting Spotlight call receiver service");
startServiceAsCurrentUser(context, new Intent(context, CallReceiverService.class));
context.startService(new Intent(context, CallReceiverService.class));
}
protected static void stopCallReceiverService(Context context) {
if (DEBUG) Log.d(TAG, "Stopping Spotlight call receiver service");
stopServiceAsCurrentUser(context, new Intent(context, CallReceiverService.class));
context.stopService(new Intent(context, CallReceiverService.class));
}
public static void startChargingService(Context context) {
if (DEBUG) Log.d(TAG, "Starting Spotlight charging service");
startServiceAsCurrentUser(context, new Intent(context, ChargingService.class));
context.startService(new Intent(context, ChargingService.class));
}
protected static void stopChargingService(Context context) {
if (DEBUG) Log.d(TAG, "Stopping Spotlight charging service");
stopServiceAsCurrentUser(context, new Intent(context, ChargingService.class));
context.stopService(new Intent(context, ChargingService.class));
}
public static void startNotificationService(Context context) {
if (DEBUG) Log.d(TAG, "Starting Spotlight notifs service");
startServiceAsCurrentUser(context, new Intent(context, NotificationService.class));
context.startService(new Intent(context, NotificationService.class));
}
protected static void stopNotificationService(Context context) {
if (DEBUG) Log.d(TAG, "Stopping Spotlight notifs service");
stopServiceAsCurrentUser(context, new Intent(context, NotificationService.class));
context.stopService(new Intent(context, NotificationService.class));
}
public static void startFlashlightService(Context context) {
if (DEBUG) Log.d(TAG, "Starting Spotlight flashlight service");
startServiceAsCurrentUser(context, new Intent(context, FlashlightService.class));
context.startService(new Intent(context, FlashlightService.class));
}
protected static void stopFlashlightService(Context context) {
if (DEBUG) Log.d(TAG, "Stopping Spotlight flashlight service");
stopServiceAsCurrentUser(context, new Intent(context, FlashlightService.class));
context.stopService(new Intent(context, FlashlightService.class));
}
public static void startMusicService(Context context) {
if (DEBUG) Log.d(TAG, "Starting Spotlight Music service");
startServiceAsCurrentUser(context, new Intent(context, MusicService.class));
context.startService(new Intent(context, MusicService.class));
}
protected static void stopMusicService(Context context) {
if (DEBUG) Log.d(TAG, "Stopping Spotlight Music service");
stopServiceAsCurrentUser(context, new Intent(context, MusicService.class));
context.stopService(new Intent(context, MusicService.class));
}
public static void checkSpotlightService(Context context) {
PowerExemptionManager pem = context.getSystemService(PowerExemptionManager.class);
pem.addToPermanentAllowList("net.typeblog.lunatic");
// Self-grant notification access because why not :)
NotificationManager nm = context.getSystemService(NotificationManager.class);
try {
Method setNotificationListenerAccessGranted = NotificationManager.class.getMethod("setNotificationListenerAccessGranted",
ComponentName.class, boolean.class, boolean.class);
setNotificationListenerAccessGranted.invoke(nm, new ComponentName(context, NotificationService.class), true, true);
} catch (Exception e) {
throw new RuntimeException(e);
}
AnimationManager animationManager = new AnimationManager(context);
if (SettingsManager.isSpotlightEnabled(context)) {