Skip to content

Commit 9f750af

Browse files
author
John Spurlock
committed
Update the dream manager to be multi-user aware.
Dream settings are stored per-user, so dream manager operations must act according to the calling or current user. Bug:7041514 Change-Id: I4a0bbbd76886e6440b1afd89c61af5f4569b0e18
1 parent 0bac8bc commit 9f750af

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

core/java/android/service/dreams/DreamManagerService.java

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
import java.io.FileDescriptor;
66
import java.io.PrintWriter;
77

8+
import android.app.ActivityManagerNative;
9+
import android.content.BroadcastReceiver;
810
import android.content.ComponentName;
911
import android.content.Context;
1012
import android.content.Intent;
13+
import android.content.IntentFilter;
1114
import android.content.ServiceConnection;
1215
import android.content.pm.PackageManager;
1316
import android.os.Binder;
1417
import android.os.IBinder;
1518
import android.os.RemoteException;
16-
import android.os.ServiceManager;
19+
import android.os.UserHandle;
1720
import android.provider.Settings;
1821
import android.util.Slog;
1922
import android.view.IWindowManager;
@@ -41,6 +44,7 @@ public class DreamManagerService
4144
private ComponentName mCurrentDreamComponent;
4245
private IDreamService mCurrentDream;
4346
private Binder mCurrentDreamToken;
47+
private int mCurrentUserId;
4448

4549
public DreamManagerService(Context context) {
4650
if (DEBUG) Slog.v(TAG, "DreamManagerService startup");
@@ -58,7 +62,7 @@ private void checkPermission(String permission) {
5862
// IDreamManager method
5963
@Override
6064
public void dream() {
61-
ComponentName[] dreams = getDreamComponents();
65+
ComponentName[] dreams = getDreamComponentsForUser(mCurrentUserId);
6266
ComponentName name = dreams != null && dreams.length > 0 ? dreams[0] : null;
6367
if (name != null) {
6468
synchronized (mLock) {
@@ -75,9 +79,10 @@ public void dream() {
7579
// IDreamManager method
7680
@Override
7781
public void setDreamComponents(ComponentName[] componentNames) {
78-
Settings.Secure.putString(mContext.getContentResolver(),
82+
Settings.Secure.putStringForUser(mContext.getContentResolver(),
7983
SCREENSAVER_COMPONENTS,
80-
componentsToString(componentNames));
84+
componentsToString(componentNames),
85+
UserHandle.getCallingUserId());
8186
}
8287

8388
private static String componentsToString(ComponentName[] componentNames) {
@@ -103,15 +108,22 @@ private static ComponentName[] componentsFromString(String names) {
103108
// IDreamManager method
104109
@Override
105110
public ComponentName[] getDreamComponents() {
106-
// TODO(dsandler) don't load this every time, watch the value
107-
String names = Settings.Secure.getString(mContext.getContentResolver(), SCREENSAVER_COMPONENTS);
111+
return getDreamComponentsForUser(UserHandle.getCallingUserId());
112+
}
113+
114+
private ComponentName[] getDreamComponentsForUser(int userId) {
115+
String names = Settings.Secure.getStringForUser(mContext.getContentResolver(),
116+
SCREENSAVER_COMPONENTS,
117+
userId);
108118
return names == null ? null : componentsFromString(names);
109119
}
110120

111121
// IDreamManager method
112122
@Override
113123
public ComponentName getDefaultDreamComponent() {
114-
String name = Settings.Secure.getString(mContext.getContentResolver(), SCREENSAVER_DEFAULT_COMPONENT);
124+
String name = Settings.Secure.getStringForUser(mContext.getContentResolver(),
125+
SCREENSAVER_DEFAULT_COMPONENT,
126+
UserHandle.getCallingUserId());
115127
return name == null ? null : ComponentName.unflattenFromString(name);
116128
}
117129

@@ -210,6 +222,25 @@ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
210222
}
211223

212224
public void systemReady() {
225+
226+
// dream settings are kept per user, so keep track of current user
227+
try {
228+
mCurrentUserId = ActivityManagerNative.getDefault().getCurrentUser().id;
229+
} catch (RemoteException e) {
230+
Slog.w(TAG, "Couldn't get current user ID; guessing it's 0", e);
231+
}
232+
IntentFilter filter = new IntentFilter();
233+
filter.addAction(Intent.ACTION_USER_SWITCHED);
234+
mContext.registerReceiver(new BroadcastReceiver() {
235+
@Override
236+
public void onReceive(Context context, Intent intent) {
237+
String action = intent.getAction();
238+
if (Intent.ACTION_USER_SWITCHED.equals(action)) {
239+
mCurrentUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
240+
if (DEBUG) Slog.v(TAG, "userId " + mCurrentUserId + " is in the house");
241+
}
242+
}}, filter);
243+
213244
if (DEBUG) Slog.v(TAG, "ready to dream!");
214245
}
215246

0 commit comments

Comments
 (0)