Skip to content
Open
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
34 changes: 27 additions & 7 deletions src/co/aospa/glyph/Services/AutoBrightnessService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,33 @@ public class AutoBrightnessService extends Service {
private SensorManager mSensorManager;
private Sensor mLightSensor;
private static int sensorType;
private static final int[] AutoBrightnessLux = ResourceUtils.getIntArray("glyph_auto_brightness_levels");
private static final int[] BrightnessValues = Constants.getBrightnessLevels();
// Lazy initialized to avoid crash before Constants.CONTEXT is set
private static int[] AutoBrightnessLux = null;
private static int[] BrightnessValues = null;

private static int[] getAutoBrightnessLux() {
if (AutoBrightnessLux == null) {
AutoBrightnessLux = ResourceUtils.getIntArray("glyph_auto_brightness_levels");
}
return AutoBrightnessLux;
}

private static int[] getBrightnessValues() {
if (BrightnessValues == null) {
BrightnessValues = Constants.getBrightnessLevels();
}
return BrightnessValues;
}

@Override
public void onCreate() {
if (DEBUG) Log.d(TAG, "Creating service");

// Initialize context before anything else
if (Constants.CONTEXT == null) {
Constants.CONTEXT = getApplicationContext();
}

mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

// Get light sensor type
Expand Down Expand Up @@ -90,19 +110,19 @@ public void onSensorChanged(SensorEvent event) {
int lux_index = 0;
int brightnessValue;

for (int i = 1; i < AutoBrightnessLux.length; i++) {
if (lux < AutoBrightnessLux[i]) {
for (int i = 1; i < getAutoBrightnessLux().length; i++) {
if (lux < getAutoBrightnessLux()[i]) {
break;
} else if (lux >= AutoBrightnessLux[i]) {
} else if (lux >= getAutoBrightnessLux()[i]) {
lux_index = i;
}
}

brightnessValue = BrightnessValues[lux_index];
brightnessValue = getBrightnessValues()[lux_index];

if (brightnessValue != Constants.getBrightness()) {
if (DEBUG) {
int led_lux = AutoBrightnessLux[lux_index];
int led_lux = getAutoBrightnessLux()[lux_index];
Log.d(TAG, "Brightness changed: " + "RealLux: " + lux +
" | BrightnessLux: " + led_lux + " | BrightnessValue: " + brightnessValue);
}
Expand Down
9 changes: 8 additions & 1 deletion src/co/aospa/glyph/Services/BatterySaverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.os.PowerManager;
import android.util.Log;

import co.aospa.glyph.Constants.Constants;
import co.aospa.glyph.Manager.StatusManager;
import co.aospa.glyph.Manager.SettingsManager;
import co.aospa.glyph.Utils.ServiceUtils;
Expand Down Expand Up @@ -46,6 +47,11 @@ private void updateStatus() {

@Override
public void onCreate() {
// Initialize context before anything else
if (Constants.CONTEXT == null) {
Constants.CONTEXT = getApplicationContext();
}

pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
registerReceiver(powerSaveReceiver,
new IntentFilter(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
Expand All @@ -54,7 +60,8 @@ public void onCreate() {

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if ("co.aospa.glyph.UPDATE_BATTERY_SAVER".equals(intent.getAction())){
// Intent can be null when service is restarted by system (START_STICKY)
if (intent != null && "co.aospa.glyph.UPDATE_BATTERY_SAVER".equals(intent.getAction())){
trackBatterySaver = intent.getBooleanExtra("status", false);
}
updateStatus();
Expand Down
6 changes: 6 additions & 0 deletions src/co/aospa/glyph/Services/CallReceiverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.telephony.TelephonyManager;
import android.util.Log;

import co.aospa.glyph.Constants.Constants;
import co.aospa.glyph.Manager.AnimationManager;
import co.aospa.glyph.Manager.SettingsManager;

Expand All @@ -53,6 +54,11 @@ public void run() {
public void onCreate() {
if (DEBUG) Log.d(TAG, "Creating service");

// Initialize context before anything else
if (Constants.CONTEXT == null) {
Constants.CONTEXT = getApplicationContext();
}

// Add a handler thread
thread = new HandlerThread("CallReceiverService");
thread.start();
Expand Down
6 changes: 6 additions & 0 deletions src/co/aospa/glyph/Services/ChargingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import android.os.PowerManager;
import android.util.Log;

import co.aospa.glyph.Constants.Constants;
import co.aospa.glyph.Manager.AnimationManager;

public class ChargingService extends Service {
Expand Down Expand Up @@ -65,6 +66,11 @@ public void run() {
public void onCreate() {
if (DEBUG) Log.d(TAG, "Creating service");

// Initialize context before anything else
if (Constants.CONTEXT == null) {
Constants.CONTEXT = getApplicationContext();
}

// Add a handler thread
thread = new HandlerThread("ChargingService");
thread.start();
Expand Down
6 changes: 6 additions & 0 deletions src/co/aospa/glyph/Services/FlipToGlyphService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import java.io.IOException;

import co.aospa.glyph.Constants.Constants;
import co.aospa.glyph.Manager.AnimationManager;
import co.aospa.glyph.Manager.SettingsManager;
import co.aospa.glyph.Sensors.FlipToGlyphSensor;
Expand All @@ -54,6 +55,11 @@ public class FlipToGlyphService extends Service {
public void onCreate() {
if (DEBUG) Log.d(TAG, "Creating service");

// Initialize context before anything else
if (Constants.CONTEXT == null) {
Constants.CONTEXT = getApplicationContext();
}

// Add a handler thread
thread = new HandlerThread("FlipToGlyphService");
thread.start();
Expand Down
6 changes: 6 additions & 0 deletions src/co/aospa/glyph/Services/MusicVisualizerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.os.Looper;
import android.util.Log;

import co.aospa.glyph.Constants.Constants;
import co.aospa.glyph.Manager.AnimationManager;
import co.aospa.glyph.Manager.StatusManager;

Expand Down Expand Up @@ -58,6 +59,11 @@ public class MusicVisualizerService extends Service {
public void onCreate() {
if (DEBUG) Log.d(TAG, "Creating service");

// Initialize context before anything else
if (Constants.CONTEXT == null) {
Constants.CONTEXT = getApplicationContext();
}

// Run visualizer on a handler thread
thread = new HandlerThread("MusicVisualizerService");
thread.start();
Expand Down
5 changes: 5 additions & 0 deletions src/co/aospa/glyph/Services/NotificationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public class NotificationService extends NotificationListenerService
public void onCreate() {
if (DEBUG) Log.d(TAG, "Creating service");

// Initialize context before anything else
if (Constants.CONTEXT == null) {
Constants.CONTEXT = getApplicationContext();
}

// Add a handler thread
thread = new HandlerThread("NotificationService");
thread.start();
Expand Down
6 changes: 6 additions & 0 deletions src/co/aospa/glyph/Services/PowershareService.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public class PowershareService extends Service {
@Override
public void onCreate() {
if (DEBUG) Log.d(TAG, "Creating service");

// Initialize context before anything else
if (Constants.CONTEXT == null) {
Constants.CONTEXT = getApplicationContext();
}

mPowershareActiveObserver = new PowershareActiveObserver();
mContext = this;
}
Expand Down
6 changes: 6 additions & 0 deletions src/co/aospa/glyph/Services/ProgressService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.os.Looper;
import android.util.Log;

import co.aospa.glyph.Constants.Constants;
import co.aospa.glyph.Manager.AnimationManager;
import co.aospa.glyph.Manager.SettingsManager;
import co.aospa.glyph.Manager.StatusManager;
Expand Down Expand Up @@ -101,6 +102,11 @@ String getKey() {
public void onCreate() {
if (DEBUG) Log.d(TAG, "Creating service");

// Initialize context before anything else
if (Constants.CONTEXT == null) {
Constants.CONTEXT = getApplicationContext();
}

mContext = this;

thread = new HandlerThread("ProgressService");
Expand Down
5 changes: 5 additions & 0 deletions src/co/aospa/glyph/Services/ThirdPartyService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Intent
import android.os.IBinder
import android.os.PowerManager
import android.util.Log
import co.aospa.glyph.Constants.Constants
import co.aospa.glyph.Manager.AnimationManager
import co.aospa.glyph.Manager.StatusManager
import com.nothing.thirdparty.IGlyphService
Expand Down Expand Up @@ -37,6 +38,10 @@ class ThirdPartyService : Service() {

override fun onCreate() {
super.onCreate()
// Initialize context before anything else
if (Constants.CONTEXT == null) {
Constants.CONTEXT = applicationContext
}
}

override fun onBind(intent: Intent?): IBinder {
Expand Down
6 changes: 6 additions & 0 deletions src/co/aospa/glyph/Services/VolumeLevelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.os.Looper;
import android.util.Log;

import co.aospa.glyph.Constants.Constants;
import co.aospa.glyph.Manager.AnimationManager;
import co.aospa.glyph.Manager.StatusManager;

Expand All @@ -55,6 +56,11 @@ public void run() {
public void onCreate() {
if (DEBUG) Log.d(TAG, "Creating service");

// Initialize context before anything else
if (Constants.CONTEXT == null) {
Constants.CONTEXT = getApplicationContext();
}

mContext = this;

// Add a handler thread
Expand Down