In the settings application I'm trying to receive message about changing network status. It looks like this:

 <receiver android:name="com.android.settings.NetworkStateReceiver">
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
        </intent-filter>
 </receiver>



public class NetworkStateReceiver extends BroadcastReceiver
{
  public static final String TAG = "NetworkStateReceiver";
  public static final String NETWORK_CHANGED_ACTION = "com.android.settings.NetworkStateReceiver.NETWORK_CHANGED";

  @Override
  public void onReceive( Context context, Intent intent )
  {
      Log.d(TAG, "Network state changed");
      Intent i = new Intent();
      i.setAction(NETWORK_CHANGED_ACTION);
      context.sendBroadcast(i);
  }
}

From this receiver I'm trying to send message to DeviceInfoFragment, there is receiver, which should catch this broadcast:

 private BroadcastReceiver mNetwrokStateReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {

        Log.d("NetworkStateReceiver_DEVICE_INFO", "network state changed");
        if (isNetworkConnected()) {
            Log.d("NetworkStateReceiver_DEVICE_INFO", "network connected");
            mHelpPreference.setEnabled(true);
        } else {
            mHelpPreference.setEnabled(false);
            Log.d("NetworkStateReceiver_DEVICE_INFO", "network disconnected");
        }
    }
};

I register it in onResume and unregister in onPause.

But I got error in NetworkStateReceiver in this line:

context.sendBroadcast(i);

Calling a method in the system process without a qualified user

Is there is any way to fix it?

It is just a warning.

You can see that by looking at the source code: https://android.googlesource.com/platform/frameworks/base/+/b267554/core/java/android/app/ContextImpl.java

Just search for the method "warnIfCallingFromSystemProcess()"

  • Thank you for your insightful answer. It's unfortunate there seems to be no way to suppress the warning and maintain the system uid for additional privileges. Nor any documentation as to why it's a warning in the first place for system apps. It's odd. – jschlepp Nov 29 '17 at 18:41

Instead of using sendBroadcast(Intent intent), use this

sendBroadcastAsUser(i, new UserHandle(UserHandle.USER_CURRENT));
  • Tried, doesn't work – Pein Sep 27 '16 at 12:00
  • Did you provide INTERACT_ACROSS_USERS permission? – fluffyBatman Sep 27 '16 at 12:01
  • Tried with permission, the same result :( – Pein Sep 27 '16 at 12:09

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.