Security exception: Unable to start service. User 0 is restricted
Asked Answered
A

1

8

I've got the below exception trace.

  Fatal Exception: java.lang.RuntimeException: Unable to create application com.myapp.MyApplication: java.lang.SecurityException: Unable to start service Intent { cmp=com.myapp/.background.MyService }: Unable to launch app com.myapp/10232 for service Intent { cmp=com.myapp/.background.MyService }: user 0 is restricted
   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688)
   at android.app.ActivityThread.access$1600(ActivityThread.java:164)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1438)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:150)
   at android.app.ActivityThread.main(ActivityThread.java:5408)
   at java.lang.reflect.Method.invoke(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)

  Caused by java.lang.SecurityException: Unable to start service Intent { cmp=com.myapp/.background.MyService }: Unable to launch app com.myapp/10232 for service Intent { cmp=com.myapp/.background.MyService }: user 0 is restricted
   at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1728)
   at android.app.ContextImpl.startService(ContextImpl.java:1701)
   at android.content.ContextWrapper.startService(ContextWrapper.java:516)
   at com.myapp.MyApplication.onCreate(MyApplication.java:105)
   at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4685)
   at android.app.ActivityThread.access$1600(ActivityThread.java:164)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1438)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:150)
   at android.app.ActivityThread.main(ActivityThread.java:5408)
   at java.lang.reflect.Method.invoke(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)

Any clue on this exception? Looks like, app is installed from guest user and tried to access in admin account? I got this exception from OPPO R7 PLUS device.

Manifest:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.myapp">

    <application
        android:name=".MyApplication"
        android:allowBackup="false"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <service android:name=".background.MyService" />

    </application>

</manifest>
Aggression answered 4/8, 2016 at 10:12 Comment(10)
Can u post your manifest file.Dianemarie
Manifest posted. Also I got this exception only in OPPO R7 PLUS. Any idea on user is restricted error?Aggression
is user profile managed?Trefor
I got this exception from playstore. @Rajen RaiyarelaAggression
Hmm @RajenRaiyarela may be on the right track. Just to get some more info, can you provide the important parts of the onCreate method of MyApplication.java (by important I mean all the stuff that has to do with creating the intent that is used for startService :))?Perspicacity
registerActivityLifecycleCallbacks(Foreground.get(this)); startService(new Intent(this, MyService.class));Aggression
I' m registering life cycle callbacks and starting a service in onCreate of MyApplication.@PerspicacityAggression
Also FYI, I'm not managing any user profiles in my app. @RajenRaiyarelaAggression
any update on this issue @AggressionHaswell
@RajenRaiyarela I am getting this on Note 3 device. My device is profile manager. When I try to remove profile management I get this . Do you know any reason or solution for this problem?Succussion
L
4

Please see post from OPPO: http://bbs.coloros.com/thread-174655-3-1.html

Below is some translation from the post: After auto screen off for a while, the system will start battery management module, it will forbid any app start up. but there is a bug, it should force stop the app instead throw exception.

From developer side, they give a solution: use "try catch" when starting the service.

Lanellelanette answered 21/3, 2017 at 3:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.