Skip to content

Commit

Permalink
** If the user is using the screensaver feature, a wake command now d…
Browse files Browse the repository at this point in the history
…isables the screensaver, screensaver is allowed after wake timeout or if user sends wake command with false value.

** Added feature to open settings with command "settings" and completely disable and remove the settings button.  There is a new setting under the general settings screen to remove the settings button and settings has been added to the command list in the documentation.
  • Loading branch information
thanksmister committed May 21, 2021
1 parent c5bbe42 commit 7da979a
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 88 deletions.
18 changes: 11 additions & 7 deletions WallPanelApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply plugin: 'com.google.firebase.crashlytics'
def versionMajor = 0
def versionMinor = 9
def versionPatch = 4
def versionBuild = 5 // bump for dog food builds, public betas, etc.
def versionBuild = 7 // bump for dog food builds, public betas, etc.

android {
kapt {
Expand Down Expand Up @@ -75,6 +75,11 @@ android {
versionName "${versionMajor}.${versionMinor}.${versionPatch} Build ${versionBuild}"
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand All @@ -86,6 +91,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
Expand Down Expand Up @@ -126,19 +132,17 @@ dependencies {

// MQTT
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1', {
exclude module: 'support-v4'
}
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'

implementation 'com.koushikdutta.async:androidasync:2.1.9'

// Logging
implementation 'com.jakewharton.timber:timber:4.5.1'

// Firebase
implementation 'com.google.firebase:firebase-core:18.0.2'
implementation 'com.google.firebase:firebase-crashlytics:17.4.1'
implementation 'com.google.firebase:firebase-analytics:18.0.2'
implementation 'com.google.firebase:firebase-core:19.0.0'
implementation 'com.google.firebase:firebase-crashlytics:18.0.0'
implementation 'com.google.firebase:firebase-analytics:19.0.0'

// Picasso image loading
implementation 'com.squareup.picasso:picasso:2.71828'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import org.junit.After
import org.junit.Before
import org.junit.Test

import org.junit.Assert.*

class BrowserActivityNativeTest : TestCase() {

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.thanksmister.iot.wallpanel

import android.content.Context
import androidx.multidex.MultiDex
import com.google.firebase.FirebaseApp
import com.thanksmister.iot.wallpanel.di.DaggerApplicationComponent
import com.thanksmister.iot.wallpanel.utils.LauncherShortcuts
import dagger.android.AndroidInjector
Expand All @@ -36,6 +37,7 @@ class WallPanel : DaggerApplication() {
Timber.plant(Timber.DebugTree())
}
LauncherShortcuts.createShortcuts(this)
FirebaseApp.initializeApp(applicationContext)
}

override fun attachBaseContext(base: Context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.thanksmister.iot.wallpanel.di

import androidx.lifecycle.ViewModel
import com.thanksmister.iot.wallpanel.BootUpReceiver
import com.thanksmister.iot.wallpanel.network.WallPanelService
import com.thanksmister.iot.wallpanel.ui.*
import com.thanksmister.iot.wallpanel.ui.activities.*
import com.thanksmister.iot.wallpanel.ui.fragments.*
Expand All @@ -34,6 +35,9 @@ internal abstract class AndroidBindingModule {
@ViewModelKey(DetectionViewModel::class)
abstract fun cameraViewModel(viewModel: DetectionViewModel): ViewModel

@ContributesAndroidInjector
internal abstract fun alarmService(): WallPanelService

@ContributesAndroidInjector
internal abstract fun settingsActivity(): SettingsActivity

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
@Component(modules = {
AndroidSupportInjectionModule.class,
ApplicationModule.class,
ServicesModule.class,
ActivityModule.class,
AndroidBindingModule.class,
DaggerViewModelInjectionModule.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,14 @@

package com.thanksmister.iot.wallpanel.di;

import android.app.Service;

import com.thanksmister.iot.wallpanel.network.WallPanelService;

import dagger.Binds;
import dagger.Module;
import dagger.android.AndroidInjector;
import dagger.android.ServiceKey;
import dagger.multibindings.IntoMap;
import dagger.android.ContributesAndroidInjector;

@Module
abstract class ServicesModule {

@Module(subcomponents = {
ServiceSubcomponent.class
})
public abstract class ServicesModule {
@Binds
@IntoMap
@ServiceKey(WallPanelService.class)
abstract AndroidInjector.Factory<? extends Service> syncServiceInjectorFactory(ServiceSubcomponent.Builder builder);
@ContributesAndroidInjector
abstract WallPanelService contributeMyService();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import android.media.MediaPlayer
import android.net.wifi.WifiManager
import android.os.*
import androidx.core.content.ContextCompat
import androidx.core.os.postDelayed
import androidx.lifecycle.LifecycleService
import androidx.lifecycle.Observer
import androidx.localbroadcastmanager.content.LocalBroadcastManager
Expand All @@ -43,6 +42,7 @@ import com.thanksmister.iot.wallpanel.persistence.Configuration
import com.thanksmister.iot.wallpanel.ui.activities.BaseBrowserActivity.Companion.BROADCAST_ACTION_CLEAR_BROWSER_CACHE
import com.thanksmister.iot.wallpanel.ui.activities.BaseBrowserActivity.Companion.BROADCAST_ACTION_JS_EXEC
import com.thanksmister.iot.wallpanel.ui.activities.BaseBrowserActivity.Companion.BROADCAST_ACTION_LOAD_URL
import com.thanksmister.iot.wallpanel.ui.activities.BaseBrowserActivity.Companion.BROADCAST_ACTION_OPEN_SETTINGS
import com.thanksmister.iot.wallpanel.ui.activities.BaseBrowserActivity.Companion.BROADCAST_ACTION_RELOAD_PAGE
import com.thanksmister.iot.wallpanel.utils.MqttUtils
import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_AUDIO
Expand All @@ -56,6 +56,7 @@ import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_SENSOR
import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_SENSOR_FACE
import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_SENSOR_MOTION
import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_SENSOR_QR_CODE
import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_SETTINGS
import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_SPEAK
import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_STATE
import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_URL
Expand All @@ -75,6 +76,7 @@ import java.util.*
import java.util.concurrent.atomic.AtomicBoolean
import javax.inject.Inject

// TODO move this to internal class within application, no longer run as service
class WallPanelService : LifecycleService(), MQTTModule.MQTTListener {

@Inject
Expand Down Expand Up @@ -103,6 +105,7 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener {
private val appStateClearHandler = Handler()
private val qrCodeClearHandler = Handler()
private val faceClearHandler = Handler()
private val wakeScreenHandler = Handler()
private var textToSpeechModule: TextToSpeechModule? = null
private var mqttModule: MQTTModule? = null
private var connectionLiveData: ConnectionLiveData? = null
Expand Down Expand Up @@ -183,7 +186,7 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener {
filter.addAction(Intent.ACTION_SCREEN_OFF)
filter.addAction(Intent.ACTION_USER_PRESENT)
localBroadCastManager = LocalBroadcastManager.getInstance(this)
localBroadCastManager!!.registerReceiver(mBroadcastReceiver, filter)
localBroadCastManager?.registerReceiver(mBroadcastReceiver, filter)
}

override fun onDestroy() {
Expand Down Expand Up @@ -572,14 +575,11 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener {
}
}
if (commandJson.has(COMMAND_WAKE)) {
if (commandJson.getBoolean(COMMAND_WAKE)) {
if (commandJson.getBoolean(COMMAND_WAKE).or(false)) {
val wakeTime = commandJson.optLong(COMMAND_WAKETIME, SCREEN_WAKE_TIME / 1000) * 1000
switchScreenOn(wakeTime)
wakeScreenOn(wakeTime)
} else {
if (partialWakeLock != null && partialWakeLock!!.isHeld) {
Timber.d("Release wakelock")
partialWakeLock!!.release()
}
wakeScreenOff()
}
}
if (commandJson.has(COMMAND_BRIGHTNESS)) {
Expand All @@ -606,6 +606,9 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener {
if (commandJson.has(COMMAND_SPEAK)) {
speakMessage(commandJson.getString(COMMAND_SPEAK))
}
if (commandJson.has(COMMAND_SETTINGS)) {
openSettings()
}
if (commandJson.has(COMMAND_VOLUME)) {
setVolume((commandJson.getInt(COMMAND_VOLUME).toFloat() / 100))
}
Expand Down Expand Up @@ -668,19 +671,30 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener {
}
}

private fun switchScreenOn() {
switchScreenOn(SCREEN_WAKE_TIME)
// TODO temporarily wake screen
private fun switchScreen() {
val intent = Intent(BROADCAST_SCREEN_WAKE)
val bm = LocalBroadcastManager.getInstance(applicationContext)
bm.sendBroadcast(intent)
}

@SuppressLint("WakelockTimeout")
private fun switchScreenOn(wakeTime: Long) {
private fun wakeScreenOn(wakeTime: Long) {
if (partialWakeLock != null && !partialWakeLock!!.isHeld) {
partialWakeLock!!.acquire(wakeTime)
} else if (partialWakeLock != null && partialWakeLock!!.isHeld) {
partialWakeLock!!.release()
partialWakeLock!!.acquire(wakeTime)
partialWakeLock?.acquire(wakeTime)
wakeScreenHandler.postDelayed({
wakeScreenOff()
}, wakeTime)
sendWakeScreenOn()
}
}

@SuppressLint("WakelockTimeout")
private fun wakeScreenOff() {
if (partialWakeLock != null && partialWakeLock!!.isHeld) {
partialWakeLock?.release()
sendWakeScreenOff()
}
sendWakeScreen()
}

private fun changeScreenBrightness(brightness: Int) {
Expand All @@ -703,6 +717,12 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener {
bm.sendBroadcast(intent)
}

private fun openSettings() {
val intent = Intent(BROADCAST_ACTION_OPEN_SETTINGS)
val bm = LocalBroadcastManager.getInstance(applicationContext)
bm.sendBroadcast(intent)
}

private fun clearBrowserCache() {
val intent = Intent(BROADCAST_ACTION_CLEAR_BROWSER_CACHE)
val bm = LocalBroadcastManager.getInstance(applicationContext)
Expand Down Expand Up @@ -916,9 +936,16 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener {
bm.sendBroadcast(intent)
}

private fun sendWakeScreen() {
private fun sendWakeScreenOn() {
Timber.d("sendWakeScreen")
val intent = Intent(BROADCAST_SCREEN_WAKE)
val intent = Intent(BROADCAST_SCREEN_WAKE_ON)
val bm = LocalBroadcastManager.getInstance(applicationContext)
bm.sendBroadcast(intent)
}

private fun sendWakeScreenOff() {
Timber.d("sendWakeScreenOff")
val intent = Intent(BROADCAST_SCREEN_WAKE_OFF)
val bm = LocalBroadcastManager.getInstance(applicationContext)
bm.sendBroadcast(intent)
}
Expand Down Expand Up @@ -975,7 +1002,9 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener {

private val cameraDetectorCallback = object : CameraCallback {
override fun onDetectorError() {
sendToastMessage(getString(R.string.error_missing_vision_lib))
if (configuration.cameraFaceEnabled || configuration.cameraQRCodeEnabled) {
sendToastMessage(getString(R.string.error_missing_vision_lib))
}
}

override fun onCameraError() {
Expand All @@ -985,7 +1014,7 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener {
override fun onMotionDetected() {
Timber.i("Motion detected")
if (configuration.cameraMotionWake) {
switchScreenOn()
switchScreen()
}
publishMotionDetected()
}
Expand All @@ -999,7 +1028,7 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener {
Timber.d("configuration.cameraMotionBright ${configuration.cameraMotionBright}")
if (configuration.cameraFaceWake) {
configurePowerOptions()
switchScreenOn()
switchScreen() // temp turn on screen
}
publishFaceDetected()
}
Expand All @@ -1020,6 +1049,8 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener {
const val BROADCAST_TOAST_MESSAGE = "BROADCAST_TOAST_MESSAGE"
const val BROADCAST_SERVICE_STARTED = "BROADCAST_SERVICE_STARTED"
const val BROADCAST_SCREEN_WAKE = "BROADCAST_SCREEN_WAKE"
const val BROADCAST_SCREEN_WAKE_ON = "BROADCAST_SCREEN_WAKE_ON"
const val BROADCAST_SCREEN_WAKE_OFF = "BROADCAST_SCREEN_WAKE_OFF"
const val BROADCAST_SCREEN_BRIGHTNESS_CHANGE = "BROADCAST_SCREEN_BRIGHTNESS_CHANGE"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ constructor(private val context: Context, private val sharedPreferences: SharedP
get() = this.sharedPreferences.getBoolean(PREF_SETTINGS_TRANSPARENT, false)
set(value) = this.sharedPreferences.edit().putBoolean(PREF_SETTINGS_TRANSPARENT, value).apply()

var settingsDisabled: Boolean
get() = this.sharedPreferences.getBoolean(PREF_SETTINGS_DISABLE, false)
set(value) = this.sharedPreferences.edit().putBoolean(PREF_SETTINGS_DISABLE, value).apply()

var writeScreenPermissionsShown: Boolean
get() = sharedPreferences.getBoolean(PREF_WRITE_SCREEN_PERMISSIONS, false)
set(value) {
Expand Down Expand Up @@ -348,6 +352,7 @@ constructor(private val context: Context, private val sharedPreferences: SharedP
private const val PREF_SETTINGS_CODE = "pref_settings_code"
private const val PREF_SETTINGS_CODE_STRING = "pref_settings_code_string"
private const val PREF_SETTINGS_TRANSPARENT = "pref_settings_transparent"
private const val PREF_SETTINGS_DISABLE = "pref_settings_disable"
private const val PREF_SETTINGS_LOCATION = "pref_settings_location"
const val PREF_FIRST_TIME = "pref_first_time"
const val PREF_WRITE_SCREEN_PERMISSIONS = "pref_write_screen_permissions"
Expand Down
Loading

0 comments on commit 7da979a

Please sign in to comment.