Skip to content

Commit 2278898

Browse files
Amith YamasaniAndroid (Google) Code Review
authored andcommitted
Merge "System server should always send broadcasts to a specific or all users" into jb-mr1-dev
2 parents cd92db8 + cd75706 commit 2278898

File tree

7 files changed

+36
-10
lines changed

7 files changed

+36
-10
lines changed

core/java/android/app/ContextImpl.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import android.nfc.NfcManager;
7878
import android.os.Binder;
7979
import android.os.Bundle;
80+
import android.os.Debug;
8081
import android.os.DropBoxManager;
8182
import android.os.Environment;
8283
import android.os.FileUtils;
@@ -97,6 +98,7 @@
9798
import android.content.ClipboardManager;
9899
import android.util.AndroidRuntimeException;
99100
import android.util.Log;
101+
import android.util.Slog;
100102
import android.view.CompatibilityInfoHolder;
101103
import android.view.ContextThemeWrapper;
102104
import 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 {

core/java/android/content/SyncManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2530,7 +2530,7 @@ private void sendSyncStateIntent() {
25302530
syncStateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
25312531
syncStateIntent.putExtra("active", mNeedSyncActiveNotification);
25322532
syncStateIntent.putExtra("failing", false);
2533-
mContext.sendBroadcast(syncStateIntent);
2533+
mContext.sendBroadcastAsUser(syncStateIntent, UserHandle.OWNER);
25342534
}
25352535

25362536
private void installHandleTooManyDeletesNotification(Account account, String authority,

policy/src/com/android/internal/policy/impl/keyguard/ClockView.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.database.ContentObserver;
2424
import android.graphics.Typeface;
2525
import android.os.Handler;
26+
import android.os.UserHandle;
2627
import android.provider.Settings;
2728
import android.text.format.DateFormat;
2829
import android.util.AttributeSet;
@@ -172,7 +173,7 @@ protected void onAttachedToWindow() {
172173
filter.addAction(Intent.ACTION_TIME_TICK);
173174
filter.addAction(Intent.ACTION_TIME_CHANGED);
174175
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
175-
mContext.registerReceiver(mIntentReceiver, filter);
176+
mContext.registerReceiverAsUser(mIntentReceiver, UserHandle.OWNER, filter, null, null );
176177
}
177178

178179
/* monitor 12/24-hour display preference */

services/java/com/android/server/BackupManagerService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,8 @@ public BackupManagerService(Context context) {
836836
if ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
837837
if (DEBUG) Slog.v(TAG, "Binding to Google transport");
838838
Intent intent = new Intent().setComponent(transportComponent);
839-
context.bindService(intent, mGoogleConnection, Context.BIND_AUTO_CREATE);
839+
context.bindService(intent, mGoogleConnection, Context.BIND_AUTO_CREATE,
840+
UserHandle.USER_OWNER);
840841
} else {
841842
Slog.w(TAG, "Possible Google transport spoof: ignoring " + info);
842843
}

services/java/com/android/server/InputMethodManagerService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ public boolean notifySuggestionPicked(SuggestionSpan span, String originalString
15611561
intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_BEFORE, originalString);
15621562
intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_AFTER, suggestions[index]);
15631563
intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_HASHCODE, span.hashCode());
1564-
mContext.sendBroadcast(intent);
1564+
mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
15651565
return true;
15661566
}
15671567
}
@@ -1649,7 +1649,7 @@ void updateFromSettingsLocked() {
16491649
Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED);
16501650
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
16511651
intent.putExtra("input_method_id", id);
1652-
mContext.sendBroadcast(intent);
1652+
mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
16531653
}
16541654
unbindCurrentClientLocked();
16551655
} finally {

services/java/com/android/server/SystemServer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import android.os.StrictMode;
3838
import android.os.SystemClock;
3939
import android.os.SystemProperties;
40+
import android.os.UserHandle;
4041
import android.server.search.SearchManagerService;
4142
import android.service.dreams.DreamService;
4243
import android.util.DisplayMetrics;
@@ -1005,7 +1006,7 @@ static final void startSystemUi(Context context) {
10051006
intent.setComponent(new ComponentName("com.android.systemui",
10061007
"com.android.systemui.SystemUIService"));
10071008
Slog.d(TAG, "Starting service: " + intent);
1008-
context.startService(intent);
1009+
context.startServiceAsUser(intent, UserHandle.OWNER);
10091010
}
10101011
}
10111012

services/java/com/android/server/dreams/DreamController.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.os.IBinder;
2626
import android.os.RemoteException;
2727
import android.os.IBinder.DeathRecipient;
28+
import android.os.UserHandle;
2829
import android.service.dreams.DreamService;
2930
import android.service.dreams.IDreamService;
3031
import android.util.Slog;
@@ -83,8 +84,8 @@ public void dump(PrintWriter pw) {
8384
public void startDream(Binder token, ComponentName name, boolean isTest, int userId) {
8485
stopDream();
8586

86-
// Close the notification shade
87-
mContext.sendBroadcast(mCloseNotificationShadeIntent);
87+
// Close the notification shade. Don't need to send to all, but better to be explicit.
88+
mContext.sendBroadcastAsUser(mCloseNotificationShadeIntent, UserHandle.ALL);
8889

8990
Slog.i(TAG, "Starting dream: name=" + name + ", isTest=" + isTest + ", userId=" + userId);
9091

@@ -128,7 +129,7 @@ public void stopDream() {
128129
+ ", isTest=" + oldDream.mIsTest + ", userId=" + oldDream.mUserId);
129130

130131
if (oldDream.mSentStartBroadcast) {
131-
mContext.sendBroadcast(mDreamingStoppedIntent);
132+
mContext.sendBroadcastAsUser(mDreamingStoppedIntent, UserHandle.ALL);
132133
}
133134

134135
if (oldDream.mService != null) {
@@ -180,7 +181,7 @@ private void attach(IDreamService service) {
180181
mCurrentDream.mService = service;
181182

182183
if (!mCurrentDream.mIsTest) {
183-
mContext.sendBroadcast(mDreamingStartedIntent);
184+
mContext.sendBroadcastAsUser(mDreamingStartedIntent, UserHandle.ALL);
184185
mCurrentDream.mSentStartBroadcast = true;
185186
}
186187
}

0 commit comments

Comments
 (0)