Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-26253

Android: NotificationManager.notify() will crash while screen is off and if app is missing WAKE_LOCK permission


    • Story Points:


      As of Titanium 6.2.0, posting a local notification while the screen is off will cause the app to crash if the app does not have the WAKE_LOCK permission.

      Titanium should not require the WAKE_LOCK permission.

      Steps to reproduce:

      1. Connect an Android device to your machine.
      2. Turn the Android device's screen off.
      3. Build and run the below code on that Android device.
      4. View the log and notice an exception was printed on startup.
      5. Turn on the device's screen and view the app. Notice an exception dialog was displayed.

      Ti.Android.NotificationManager.notify(123, Ti.Android.createNotification({
      	contentTitle: "Titanium Notification",
      	contentText: "Content Text",
      	contentIntent: Ti.Android.createPendingIntent({
      		intent: Ti.App.Android.launchIntent,

      The following exception gets logged...

      [ERROR] :  TiExceptionHandler: Error: Neither user 10256 nor current process has android.permission.WAKE_LOCK.
      [ERROR] :  TiExceptionHandler:     at /ActivitySingleTaskTest.js:29:32
      [ERROR] :  TiExceptionHandler:     at Module._runScript (ti:/module.js:613:9)
      [ERROR] :  TiExceptionHandler:     at Module.load (ti:/module.js:105:7)
      [ERROR] :  TiExceptionHandler:     at Module.loadJavascriptText (ti:/module.js:457:9)
      [ERROR] :  TiExceptionHandler:     at Module.loadAsFile (ti:/module.js:512:15)
      [ERROR] :  TiExceptionHandler:     at Module.loadAsFileOrDirectory (ti:/module.js:429:20)
      [ERROR] :  TiExceptionHandler:     at Module.require (ti:/module.js:296:17)
      [ERROR] :  TiExceptionHandler:     at require (ti:/module.js:570:15)
      [ERROR] :  TiExceptionHandler:     at /app.js:7:1
      [ERROR] :  TiExceptionHandler:     at Module._runScript (ti:/module.js:596:17)
      [ERROR] :  TiExceptionHandler:
      [ERROR] :  TiExceptionHandler:     android.os.Parcel.readException(Parcel.java:1942)
      [ERROR] :  TiExceptionHandler:     android.os.Parcel.readException(Parcel.java:1888)
      [ERROR] :  TiExceptionHandler:     android.os.IPowerManager$Stub$Proxy.acquireWakeLock(IPowerManager.java:405)
      [ERROR] :  TiExceptionHandler:     android.os.PowerManager$WakeLock.acquireLocked(PowerManager.java:1342)
      [ERROR] :  TiExceptionHandler:     android.os.PowerManager$WakeLock.acquire(PowerManager.java:1326)
      [ERROR] :  TiExceptionHandler:     ti.modules.titanium.android.notificationmanager.NotificationManagerModule.notify(NotificationManagerModule.java:159)
      [ERROR] :  TiExceptionHandler:     org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
      [ERROR] :  TiExceptionHandler:     org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:184)
      [ERROR] :  TiExceptionHandler:     org.appcelerator.kroll.KrollRuntime.runModule(KrollRuntime.java:247)
      [ERROR] :  TiExceptionHandler:     org.appcelerator.titanium.TiLaunchActivity.loadActivityScript(TiLaunchActivity.java:135)

      Expected Result:
      App should not require the WAKE_LOCK permission. Java code should check if app has WAKE_LOCK before attempting to use it. If the permission is missing, then avoid it and do not turn on the screen.

      Note that many Android users tend to avoid apps that use the WAKE_LOCK permission since they're considered to waste battery life. This permission is a dirty word in the Android world and is best avoided if possible.

      This is an issue in Titanium's Java NotificationManagerModule.notify() method...

      The solution is to do the following:

      • Check if WAKE_LOCK permission is defined in "AndroidManifest.xml" via the Context class before creating a wake lock.
      • catch block should catch the Exception type to catch all exception.


          Issue Links



              • Assignee:
                jquick Joshua Quick
                jquick Joshua Quick
                Gary Mathews
              • Watchers:
                1 Start watching this issue


                • Created:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    Sync status:
                    Last received:
                    Last sent:

                    Git Source Code