As per android developers documentation:
There is no provision to provide a user defined permission to secure a sticky broadcast.
I have tried using sendStickyBroadcastAsUser which requires an application to have two things (as per the above link) : 1. Have the permission "INTERACT_ACROSS_USERS" and 2. the application must be a system app.
However I have tried implementing it with the guidelines but still could receive the sticky broadcast without the above two mentioned pre conditions (i.e with a normal application without the required permission) which still keeps my broadcast insecure.
Following is my code snippet:
// send sticky broadcast.
Intent intent = new Intent("my_action");
intent.putExtra("my_extra", state);
if (DebugMode.DEBUG) {
Log.d(TAG, "Sending Broadcast " + intent.toUri(0));
}
Parcel in = Parcel.obtain();
context.sendStickyBroadcastAsUser(intent, new UserHandle(in ));
in.recycle();
I cannot use a normal broadcast since it needs to stay in system for other apps to read my application's status from it.
Is there a way to secure my sticky broadcast?