ttlock / Android_TTLock_Demo_Deprecated

19 stars 16 forks source link

Add support for Android Pie #12

Open azlekov opened 5 years ago

azlekov commented 5 years ago

Following the guide I get when starting for Bluetooth search

java.lang.RuntimeException: Unable to create service com.ttlock.bl.sdk.service.BluetoothLeService: java.lang.SecurityException: Permission Denial: startForeground from pid=10555, uid=10046 requires android.permission.FOREGROUND_SERVICE
        at android.app.ActivityThread.handleCreateService(ActivityThread.java:3556)
        at android.app.ActivityThread.access$1300(ActivityThread.java:200)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6762)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.SecurityException: Permission Denial: startForeground from pid=10555, uid=10046 requires android.permission.FOREGROUND_SERVICE
        at android.os.Parcel.createException(Parcel.java:1950)
        at android.os.Parcel.readException(Parcel.java:1918)
        at android.os.Parcel.readException(Parcel.java:1868)
        at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:5198)
        at android.app.Service.startForeground(Service.java:695)
        at com.ttlock.bl.sdk.service.BluetoothLeService.onCreate(BluetoothLeService.java:916)
        at android.app.ActivityThread.handleCreateService(ActivityThread.java:3544)
        at android.app.ActivityThread.access$1300(ActivityThread.java:200) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6762) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
     Caused by: android.os.RemoteException: Remote stack trace:
        at com.android.server.am.ActivityManagerService.enforcePermission(ActivityManagerService.java:9337)
        at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:1193)
        at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:874)
        at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:20633)
        at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:976)

Then I added FOREGROUND permission in the manifest as follow:

<service android:name="com.ttlock.bl.sdk.service.BluetoothLeService" />

Then I get:

2019-07-13 17:20:24.683 11271-11271/li.dodi.ttlockx.sample E/AndroidRuntime: FATAL EXCEPTION: main
    Process: li.dodi.ttlockx.sample, PID: 11271
    android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=com.ttlock.bl.sdk pri=-1 contentView=null vibrate=null sound=null defaults=0x0 flags=0x42 color=0x00000000 vis=PRIVATE)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1747)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6762)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
azlekov commented 5 years ago

This was fixed in 067baeb56299aadb4f69d27ba93d406f9f76fa8d

Can you also introduce a way to setup the Channel title and notification icon to custom one?

Attempted to start a foreground service (ComponentInfo
{li.dodi.ttlockx.sample/com.ttlock.bl.sdk.service.BluetoothLeService}) 
with a broken notification(no icon: Notification(channel=com.ttlock.bl.sdk pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 vis=PRIVATE))