Compare commits
No commits in common. "883ace4eb27ca86b430bdffedfa06abaf61805bc" and "ca8dd917b8ac0683c4116d019e064e575476eb87" have entirely different histories.
883ace4eb2
...
ca8dd917b8
6 changed files with 31 additions and 68 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -11,4 +11,3 @@ local.properties
|
||||||
*.jks
|
*.jks
|
||||||
*.keystore
|
*.keystore
|
||||||
keystore.properties
|
keystore.properties
|
||||||
/release
|
|
|
@ -24,8 +24,6 @@
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
|
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<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
|
<uses-sdk
|
||||||
android:minSdkVersion="31"
|
android:minSdkVersion="31"
|
||||||
|
@ -40,10 +38,11 @@
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name="net.typeblog.lunatic.BootCompletedReceiver"
|
android:name="net.typeblog.lunatic.BootCompletedReceiver"
|
||||||
android:exported="true">
|
android:exported="true"
|
||||||
|
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
|
<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>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,6 @@ public final class AnimationManager {
|
||||||
public void playCharging() {
|
public void playCharging() {
|
||||||
StatusManager.setChargingLedsActive(true);
|
StatusManager.setChargingLedsActive(true);
|
||||||
submit(() -> {
|
submit(() -> {
|
||||||
final int num_leds = mLEDManager.getNumLEDs();
|
|
||||||
int solid_leds = 0;
|
int solid_leds = 0;
|
||||||
mLEDManager.enableAllLEDs(false);
|
mLEDManager.enableAllLEDs(false);
|
||||||
mLEDManager.setColor(0xffffff);
|
mLEDManager.setColor(0xffffff);
|
||||||
|
@ -132,17 +131,17 @@ public final class AnimationManager {
|
||||||
while (check(Constants.SpotlightMode.CHARGING)) {
|
while (check(Constants.SpotlightMode.CHARGING)) {
|
||||||
int batteryLevel = getBatteryLevel();
|
int batteryLevel = getBatteryLevel();
|
||||||
if (oldBatteryLevel != batteryLevel) {
|
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++) {
|
for (int i = 0; i < solid_leds; i++) {
|
||||||
mLEDManager.enableLED(num_leds - i - 1, true);
|
mLEDManager.enableLED(i, true);
|
||||||
Thread.sleep(150);
|
Thread.sleep(150);
|
||||||
}
|
}
|
||||||
oldBatteryLevel = batteryLevel;
|
oldBatteryLevel = batteryLevel;
|
||||||
}
|
}
|
||||||
if (100 - solid_leds * mLEDManager.getNumLEDs() > 0) {
|
if (100 - solid_leds * mLEDManager.getNumLEDs() > 0) {
|
||||||
mLEDManager.enableLED(num_leds - solid_leds - 1, true);
|
mLEDManager.enableLED(solid_leds, true);
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
mLEDManager.enableLED(num_leds - solid_leds - 1, false);
|
mLEDManager.enableLED(solid_leds, false);
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,8 +214,6 @@ public final class AnimationManager {
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
mLEDManager.enableAllLEDs(false);
|
mLEDManager.enableAllLEDs(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
stopNotifications();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +228,6 @@ public final class AnimationManager {
|
||||||
|
|
||||||
submit(() -> {
|
submit(() -> {
|
||||||
if (check(Constants.SpotlightMode.FLASHLIGHT)) {
|
if (check(Constants.SpotlightMode.FLASHLIGHT)) {
|
||||||
mLEDManager.setColor(0xffffff);
|
|
||||||
mLEDManager.setBrightness((int) (Constants.BRIGHTNESS * 100));
|
mLEDManager.setBrightness((int) (Constants.BRIGHTNESS * 100));
|
||||||
mLEDManager.enableAllLEDs(true);
|
mLEDManager.enableAllLEDs(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ public class NotificationService extends NotificationListenerService {
|
||||||
|
|
||||||
private static final String TAG = "SpotlightNotification";
|
private static final String TAG = "SpotlightNotification";
|
||||||
private static final boolean DEBUG = true;
|
private static final boolean DEBUG = true;
|
||||||
|
private ArrayList<Integer> mNotifications = new ArrayList<>();
|
||||||
private AnimationManager mAnimationManager;
|
private AnimationManager mAnimationManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -86,7 +87,19 @@ public class NotificationService extends NotificationListenerService {
|
||||||
&& !Arrays.asList(Constants.APPSTOIGNORE).contains(packageName)
|
&& !Arrays.asList(Constants.APPSTOIGNORE).contains(packageName)
|
||||||
&& !Arrays.asList(Constants.NOTIFSTOIGNORE).contains(packageName + ":" + packageChannelID)
|
&& !Arrays.asList(Constants.NOTIFSTOIGNORE).contains(packageName + ":" + packageChannelID)
|
||||||
&& (packageImportance >= NotificationManager.IMPORTANCE_DEFAULT || packageImportance == -1)) {
|
&& (packageImportance >= NotificationManager.IMPORTANCE_DEFAULT || packageImportance == -1)) {
|
||||||
|
mNotifications.add(sbn.getId());
|
||||||
mAnimationManager.playNotifications();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,8 +105,7 @@ public class SettingsFragment extends PreferenceFragment implements OnPreference
|
||||||
final String preferenceKey = preference.getKey();
|
final String preferenceKey = preference.getKey();
|
||||||
|
|
||||||
if (preferenceKey.equals(Constants.SPOTLIGHT_NOTIFS_ENABLE)) {
|
if (preferenceKey.equals(Constants.SPOTLIGHT_NOTIFS_ENABLE)) {
|
||||||
mNotifsPreference.setChecked(SettingsManager.isSpotlightNotifsEnabled(getActivity()));
|
SettingsManager.setSpotlightNotifsEnabled(getActivity(), true);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preferenceKey.equals(Constants.SPOTLIGHT_BRIGHTNESS)) {
|
if (preferenceKey.equals(Constants.SPOTLIGHT_BRIGHTNESS)) {
|
||||||
|
|
|
@ -18,12 +18,8 @@
|
||||||
|
|
||||||
package net.typeblog.lunatic.Utils;
|
package net.typeblog.lunatic.Utils;
|
||||||
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.PowerExemptionManager;
|
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import net.typeblog.lunatic.Constants.Constants;
|
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.MusicService;
|
||||||
import net.typeblog.lunatic.Services.NotificationService;
|
import net.typeblog.lunatic.Services.NotificationService;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
public final class ServiceUtils {
|
public final class ServiceUtils {
|
||||||
|
|
||||||
private static final String TAG = "SpotlightServiceUtils";
|
private static final String TAG = "SpotlightServiceUtils";
|
||||||
private static final boolean DEBUG = true;
|
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) {
|
public static void startCallReceiverService(Context context) {
|
||||||
if (DEBUG) Log.d(TAG, "Starting Spotlight call receiver service");
|
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) {
|
protected static void stopCallReceiverService(Context context) {
|
||||||
if (DEBUG) Log.d(TAG, "Stopping Spotlight call receiver service");
|
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) {
|
public static void startChargingService(Context context) {
|
||||||
if (DEBUG) Log.d(TAG, "Starting Spotlight charging service");
|
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) {
|
protected static void stopChargingService(Context context) {
|
||||||
if (DEBUG) Log.d(TAG, "Stopping Spotlight charging service");
|
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) {
|
public static void startNotificationService(Context context) {
|
||||||
if (DEBUG) Log.d(TAG, "Starting Spotlight notifs service");
|
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) {
|
protected static void stopNotificationService(Context context) {
|
||||||
if (DEBUG) Log.d(TAG, "Stopping Spotlight notifs service");
|
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) {
|
public static void startFlashlightService(Context context) {
|
||||||
if (DEBUG) Log.d(TAG, "Starting Spotlight flashlight service");
|
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) {
|
protected static void stopFlashlightService(Context context) {
|
||||||
if (DEBUG) Log.d(TAG, "Stopping Spotlight flashlight service");
|
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) {
|
public static void startMusicService(Context context) {
|
||||||
if (DEBUG) Log.d(TAG, "Starting Spotlight Music service");
|
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) {
|
protected static void stopMusicService(Context context) {
|
||||||
if (DEBUG) Log.d(TAG, "Stopping Spotlight Music service");
|
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) {
|
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);
|
AnimationManager animationManager = new AnimationManager(context);
|
||||||
|
|
||||||
if (SettingsManager.isSpotlightEnabled(context)) {
|
if (SettingsManager.isSpotlightEnabled(context)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue