Security exception: Unable to start service. User 0 is restricted - android

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>

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.

Related

Android Application crashed on android 10

My Android App is crashed on android 10 Q mobile but I am unable to reproduce this crash and resolve it.
This is the error message:
Fatal Exception: java.lang.SecurityException: Not allowed to bind to service Intent { act=com.google.android.gms.clearcut.service.START pkg=com.google.android.gms }
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1741)
at android.app.ContextImpl.bindService(ContextImpl.java:1651)
at android.content.ContextWrapper.bindService(ContextWrapper.java:705)
at com.google.android.gms.common.stats.ConnectionTracker.zza(:22)
at com.google.android.gms.common.internal.zzf.zze(:30)
at com.google.android.gms.common.internal.zze.zza(:15)
at com.google.android.gms.common.internal.BaseGmsClient.zza(:103)
at com.google.android.gms.common.internal.BaseGmsClient.connect(:142)
at com.google.android.gms.common.api.internal.GoogleApiManager$zaa.connect(:224)
at com.google.android.gms.common.api.internal.GoogleApiManager.zab(:47)
at com.google.android.gms.common.api.internal.GoogleApiManager.handleMessage(:173)
at android.os.Handler.dispatchMessage(Handler.java:103)
at com.google.android.gms.internal.base.zap.dispatchMessage(:8)
at android.os.Looper.loop(Looper.java:232)
at android.os.HandlerThread.run(HandlerThread.java:67)
Here are the firebase crash pics:
please register your service in manifest if not ex: <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

MediaProjection service type not recognized in android Q

With the new privacy changes in effect with Android Q, it is now mandatory for any app using MediaProjection api to specify android:foregroundServiceType attribute in the service tag under manifest.
But recently, I noticed that though I set the android:foregroundServiceType="mediaprojection" there is a security exception thrown. Does anybody have any idea what I'm doing wrong?
Manifest:
<service
android:name=".services.MediaProjectionService"
android:enabled="true"
android:exported="false"
android:foregroundServiceType="mediaProjection" />
Exception thrown:
java.lang.RuntimeException: Unable to start service com.package.app.services.MediaProjectionService#6d0fed2 with Intent { act=com.package.app.services.action.startrecording cmp=com.package.app/.services.MediaProjectionService(has extras) }: java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4103)
at android.app.ActivityThread.access$1800(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7343)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:933)
Caused by: java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
at android.os.Parcel.createException(Parcel.java:2071)
at android.os.Parcel.readException(Parcel.java:2039)
at android.os.Parcel.readException(Parcel.java:1987)
at android.media.projection.IMediaProjection$Stub$Proxy.start(IMediaProjection.java:231)
at android.media.projection.MediaProjection.<init>(MediaProjection.java:58)
at android.media.projection.MediaProjectionManager.getMediaProjection(MediaProjectionManager.java:104)
at com.package.app.services.MediaProjectionService.startRecording(MediaProjectionService.java:190)
at com.package.app.services.MediaProjectionService.onStartCommand(MediaProjectionService.java:142)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4085)
at android.app.ActivityThread.access$1800(ActivityThread.java:219) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:7343) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:933) 
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.media.projection.MediaProjectionManagerService$MediaProjection.start(MediaProjectionManagerService.java:476)
at android.media.projection.IMediaProjection$Stub.onTransact(IMediaProjection.java:135)
at android.os.Binder.execTransactInternal(Binder.java:1021)
at android.os.Binder.execTransact(Binder.java:994)
P.S: This is experienced on Android Q DP5 GSI with target SDK 29. The app works fine with target sdk 28 without any changes.
Don't you forget to add permission <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> into AndroidManifest.xml ?
UPDATE
Make sure you call startForeground() before getMediaProjection()!
The best solution is to call startForeground() from onCreate() without any conditions, displaying some sort of default messages in notification. Then you can execute your logic and call NotificationManager.notify() with updated notification at any time.
Changing the following attributes
android:foregroundServiceType="mediaProjection"
tools:targetApi="q"
in AndroidManifest.xml worked for me.
< service
android:name="SERVICE_NAME"
android:foregroundServiceType="mediaProjection"
tools:targetApi="q"
android:enabled="true"
android:exported="false" />

No Activity found to handle Intent { act=android.app.action.ADD_DEVICE_ADMIN (has extras) }

I'm trying to enable the device administration, so I can create secondary users in Android 9.
First is to send an intent with ACTION_ADD_DEVICE_ADMIN like this below :
// Launch the activity to have the user enable our admin.
Intent deviceAdminIntent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
deviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminRen);
deviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
getResources().getString(R.string.device_admin_activation_message));
startActivityForResult(deviceAdminIntent, REQ_ENABLE_DEVICE_ADMIN);
A deviceAdminReceiver must be prior defined in the manifest.xml with the proper intent filter:
<activity android:name=".AuthSessionActivity" />
<activity android:name=".CreateRenUser"/>
<receiver android:name=".DeviceAdminRen"
android:label="#string/renault_device_admin"
android:description="#string/ren_device_admin_description"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin"
android:resource="#xml/device_admin_ren" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
Also the deviceAdminReceiver class is defined :
public class DeviceAdminRen extends DeviceAdminReceiver {
.........
But then I'm getting the error :
03-28 16:44:54.573 7173 7173 E AndroidRuntime: java.lang.RuntimeException: Unable to resume activity {com.sensory.trulysecureexample/com.sensory.trulysecure.custom.CreateRenaultUser}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.app.action.ADD_DEVICE_ADMIN (has extras) }
03-28 16:44:54.573 7173 7173 E AndroidRuntime: at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3822)
03-28 16:44:54.573 7173 7173 E AndroidRuntime: at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3854)
03-28 16:44:54.573 7173 7173 E AndroidRuntime: at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityIte
My Android application has several activities and fragments but if I understand well, this should be an Android system activity. Also my device has "feature:android.software.device_admin" when listing with "adb shell pm list features"
Is there any limitation in my device preventing to handle the ACTION_ADD_DEVICE_ADMIN intent ??
Note: I followed this Google Android guide https://developer.android.com/guide/topics/admin/device-admin.html
Thanks
What is the content of the constant / variable mDeviceAdminRen? That seems to be missing from your code snippet.
It should contain the component name of the device admin component, so in your case DeviceAdminRen.getComponentName(Context context).
Is this the case?
As I'm building my application with the Android NDK, I added the LOCAL_PRIVILEGED_MODULE build directive in the Makefile of the C++ lib.
gnu-libstdc++/Android.mk:LOCAL_PRIVILEGED_MODULE := true
And it worked !! There is a prompt in Android asking for enabling device administration, and then it becomes easy to create secondary users.

Android libraries not exact version?

so i'm making an app which can upload an image to the server, the web service is good and running and tested with postman.
on The application side, when i tried to add the implementation of the upload service 3.4.2 it's showing me an error, and the app is crashing at the moment of the upload.
here is a screenshot i'm new and not allowed to add pictures,https://i.stack.imgur.com/s3s8x.png
i need fast help please.
here is the run error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.simou.myapplication, PID: 5205
java.lang.RuntimeException: Unable to start service net.gotev.uploadservice.UploadService#c425f01 with Intent { act=net.gotev.uploadservice.action.upload cmp=com.simou.myapplication/net.gotev.uploadservice.UploadService (has extras) }: java.lang.IllegalArgumentException: Hey dude, please set the namespace for your app by following the setup instructions: https://github.com/gotev/android-upload-service/wiki/Setup
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3314)
at android.app.ActivityThread.-wrap21(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1565)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.IllegalArgumentException: Hey dude, please set the namespace for your app by following the setup instructions: https://github.com/gotev/android-upload-service/wiki/Setup
at net.gotev.uploadservice.UploadService.onStartCommand(UploadService.java:257)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3297)
As mentioned in the error you need to set the namespace for your application as privided the library's wiki
public class Initializer extends Application {
#Override
public void onCreate() {
super.onCreate();
// setup the broadcast action namespace string which will
// be used to notify upload status.
// Gradle automatically generates proper variable as below.
UploadService.NAMESPACE = BuildConfig.APPLICATION_ID;
// Or, you can define it manually.
UploadService.NAMESPACE = "com.yourcompany.yourapp";
}
}
and register it to your manifest
<application
android:name=".Initializer"
...
>

Permission Denial when onMessageReceived should be called

I'm following this tutorial and got a WearableListenerService. I just implemented the onMessageReceived method and didn't change anything else.
The entry for the service looks like this:
<service android:name=".WearableRemoteCommandListener"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER"></action>
</intent-filter>
</service>
The application element contains this meta-data element:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
But when I send a message to the wearable I get this security exception:
06-08 21:15:41.337 579-842/? W/ActivityManager﹕ Permission Denial: Accessing service ComponentInfo{net.bplaced.schlingel.wearabletest1/net.bplaced.schlingel.anmosela.WearableRemoteCommandListener} from pid=822, uid=10009 requires android.permission.BIND_NOTIFICATION_LISTENER_SERVICE
06-08 21:15:41.437 822-940/? W/WearableService﹕ ensureBindStarted: Permission denied connecting to net.bplaced.schlingel.anmosela.WearableRemoteCommandListener
java.lang.SecurityException: Not allowed to bind to service Intent { act=com.google.android.gms.wearable.BIND_LISTENER cmp=net.bplaced.schlingel.wearabletest1/net.bplaced.schlingel.anmosela.WearableRemoteCommandListener }
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1793)
at android.app.ContextImpl.bindService(ContextImpl.java:1757)
at android.content.ContextWrapper.bindService(ContextWrapper.java:539)
at com.google.android.gms.wearable.service.t.b(SourceFile:1157)
at com.google.android.gms.wearable.service.t.a(SourceFile:1099)
at com.google.android.gms.wearable.service.t.handleMessage(SourceFile:1077)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
I tried to add the exported and enabled attribute, restarted the wearable but the exception happens again. Is there a permission missing? What is wrong with my setup?
get rid of this line
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
from the documentation
Must be required by an NotificationListenerService, to ensure that
only the system can bind to it.

Categories

Resources