7777import android .nfc .NfcManager ;
7878import android .os .Binder ;
7979import android .os .Bundle ;
80+ import android .os .Debug ;
8081import android .os .DropBoxManager ;
8182import android .os .Environment ;
8283import android .os .FileUtils ;
9798import android .content .ClipboardManager ;
9899import android .util .AndroidRuntimeException ;
99100import android .util .Log ;
101+ import android .util .Slog ;
100102import android .view .CompatibilityInfoHolder ;
101103import android .view .ContextThemeWrapper ;
102104import android .view .Display ;
@@ -925,6 +927,7 @@ public void clearWallpaper() throws IOException {
925927
926928 @ Override
927929 public void startActivity (Intent intent ) {
930+ warnIfCallingFromSystemProcess ();
928931 startActivity (intent , null );
929932 }
930933
@@ -936,6 +939,7 @@ public void startActivityAsUser(Intent intent, UserHandle user) {
936939
937940 @ Override
938941 public void startActivity (Intent intent , Bundle options ) {
942+ warnIfCallingFromSystemProcess ();
939943 if ((intent .getFlags ()&Intent .FLAG_ACTIVITY_NEW_TASK ) == 0 ) {
940944 throw new AndroidRuntimeException (
941945 "Calling startActivity() from outside of an Activity "
@@ -962,6 +966,7 @@ public void startActivityAsUser(Intent intent, Bundle options, UserHandle user)
962966
963967 @ Override
964968 public void startActivities (Intent [] intents ) {
969+ warnIfCallingFromSystemProcess ();
965970 startActivities (intents , null );
966971 }
967972
@@ -981,6 +986,7 @@ public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle u
981986
982987 @ Override
983988 public void startActivities (Intent [] intents , Bundle options ) {
989+ warnIfCallingFromSystemProcess ();
984990 if ((intents [0 ].getFlags ()&Intent .FLAG_ACTIVITY_NEW_TASK ) == 0 ) {
985991 throw new AndroidRuntimeException (
986992 "Calling startActivities() from outside of an Activity "
@@ -1023,6 +1029,7 @@ public void startIntentSender(IntentSender intent, Intent fillInIntent,
10231029
10241030 @ Override
10251031 public void sendBroadcast (Intent intent ) {
1032+ warnIfCallingFromSystemProcess ();
10261033 String resolvedType = intent .resolveTypeIfNeeded (getContentResolver ());
10271034 try {
10281035 intent .setAllowFds (false );
@@ -1036,6 +1043,7 @@ public void sendBroadcast(Intent intent) {
10361043
10371044 @ Override
10381045 public void sendBroadcast (Intent intent , String receiverPermission ) {
1046+ warnIfCallingFromSystemProcess ();
10391047 String resolvedType = intent .resolveTypeIfNeeded (getContentResolver ());
10401048 try {
10411049 intent .setAllowFds (false );
@@ -1050,6 +1058,7 @@ public void sendBroadcast(Intent intent, String receiverPermission) {
10501058 @ Override
10511059 public void sendOrderedBroadcast (Intent intent ,
10521060 String receiverPermission ) {
1061+ warnIfCallingFromSystemProcess ();
10531062 String resolvedType = intent .resolveTypeIfNeeded (getContentResolver ());
10541063 try {
10551064 intent .setAllowFds (false );
@@ -1066,6 +1075,7 @@ public void sendOrderedBroadcast(Intent intent,
10661075 String receiverPermission , BroadcastReceiver resultReceiver ,
10671076 Handler scheduler , int initialCode , String initialData ,
10681077 Bundle initialExtras ) {
1078+ warnIfCallingFromSystemProcess ();
10691079 IIntentReceiver rd = null ;
10701080 if (resultReceiver != null ) {
10711081 if (mPackageInfo != null ) {
@@ -1154,6 +1164,7 @@ resultReceiver, getOuterContext(), scheduler,
11541164
11551165 @ Override
11561166 public void sendStickyBroadcast (Intent intent ) {
1167+ warnIfCallingFromSystemProcess ();
11571168 String resolvedType = intent .resolveTypeIfNeeded (getContentResolver ());
11581169 try {
11591170 intent .setAllowFds (false );
@@ -1170,6 +1181,7 @@ public void sendStickyOrderedBroadcast(Intent intent,
11701181 BroadcastReceiver resultReceiver ,
11711182 Handler scheduler , int initialCode , String initialData ,
11721183 Bundle initialExtras ) {
1184+ warnIfCallingFromSystemProcess ();
11731185 IIntentReceiver rd = null ;
11741186 if (resultReceiver != null ) {
11751187 if (mPackageInfo != null ) {
@@ -1337,11 +1349,13 @@ public void unregisterReceiver(BroadcastReceiver receiver) {
13371349
13381350 @ Override
13391351 public ComponentName startService (Intent service ) {
1352+ warnIfCallingFromSystemProcess ();
13401353 return startServiceAsUser (service , mUser );
13411354 }
13421355
13431356 @ Override
13441357 public boolean stopService (Intent service ) {
1358+ warnIfCallingFromSystemProcess ();
13451359 return stopServiceAsUser (service , mUser );
13461360 }
13471361
@@ -1389,6 +1403,7 @@ public boolean stopServiceAsUser(Intent service, UserHandle user) {
13891403 @ Override
13901404 public boolean bindService (Intent service , ServiceConnection conn ,
13911405 int flags ) {
1406+ warnIfCallingFromSystemProcess ();
13921407 return bindService (service , conn , flags , UserHandle .getUserId (Process .myUid ()));
13931408 }
13941409
@@ -1697,6 +1712,13 @@ public void enforceUriPermission(
16971712 message );
16981713 }
16991714
1715+ private void warnIfCallingFromSystemProcess () {
1716+ if (Process .myUid () == Process .SYSTEM_UID ) {
1717+ Slog .w (TAG , "Calling a method in the system process without a qualified user: "
1718+ + Debug .getCallers (3 ));
1719+ }
1720+ }
1721+
17001722 @ Override
17011723 public Context createPackageContext (String packageName , int flags )
17021724 throws NameNotFoundException {
0 commit comments