diff options
author | John Spurlock <jspurlock@google.com> | 2012-09-10 15:56:16 -0400 |
---|---|---|
committer | John Spurlock <jspurlock@google.com> | 2012-09-11 09:50:23 -0400 |
commit | 9f750af6c178d8abb5c12d34efba599e3d53aea4 (patch) | |
tree | 99fa933fa558dd75b2fddbd6d5e2119cab16d158 /core/java | |
parent | 0bac8bcbcc281afc041f621a156fd21549d686e1 (diff) | |
download | frameworks_base-9f750af6c178d8abb5c12d34efba599e3d53aea4.zip frameworks_base-9f750af6c178d8abb5c12d34efba599e3d53aea4.tar.gz frameworks_base-9f750af6c178d8abb5c12d34efba599e3d53aea4.tar.bz2 |
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
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/service/dreams/DreamManagerService.java | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/core/java/android/service/dreams/DreamManagerService.java b/core/java/android/service/dreams/DreamManagerService.java index 2cec6c3..4aa1cbb 100644 --- a/core/java/android/service/dreams/DreamManagerService.java +++ b/core/java/android/service/dreams/DreamManagerService.java @@ -5,15 +5,18 @@ import static android.provider.Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT; import java.io.FileDescriptor; import java.io.PrintWriter; +import android.app.ActivityManagerNative; +import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.content.ServiceConnection; import android.content.pm.PackageManager; import android.os.Binder; import android.os.IBinder; import android.os.RemoteException; -import android.os.ServiceManager; +import android.os.UserHandle; import android.provider.Settings; import android.util.Slog; import android.view.IWindowManager; @@ -41,6 +44,7 @@ public class DreamManagerService private ComponentName mCurrentDreamComponent; private IDreamService mCurrentDream; private Binder mCurrentDreamToken; + private int mCurrentUserId; public DreamManagerService(Context context) { if (DEBUG) Slog.v(TAG, "DreamManagerService startup"); @@ -58,7 +62,7 @@ public class DreamManagerService // IDreamManager method @Override public void dream() { - ComponentName[] dreams = getDreamComponents(); + ComponentName[] dreams = getDreamComponentsForUser(mCurrentUserId); ComponentName name = dreams != null && dreams.length > 0 ? dreams[0] : null; if (name != null) { synchronized (mLock) { @@ -75,9 +79,10 @@ public class DreamManagerService // IDreamManager method @Override public void setDreamComponents(ComponentName[] componentNames) { - Settings.Secure.putString(mContext.getContentResolver(), + Settings.Secure.putStringForUser(mContext.getContentResolver(), SCREENSAVER_COMPONENTS, - componentsToString(componentNames)); + componentsToString(componentNames), + UserHandle.getCallingUserId()); } private static String componentsToString(ComponentName[] componentNames) { @@ -103,15 +108,22 @@ public class DreamManagerService // IDreamManager method @Override public ComponentName[] getDreamComponents() { - // TODO(dsandler) don't load this every time, watch the value - String names = Settings.Secure.getString(mContext.getContentResolver(), SCREENSAVER_COMPONENTS); + return getDreamComponentsForUser(UserHandle.getCallingUserId()); + } + + private ComponentName[] getDreamComponentsForUser(int userId) { + String names = Settings.Secure.getStringForUser(mContext.getContentResolver(), + SCREENSAVER_COMPONENTS, + userId); return names == null ? null : componentsFromString(names); } // IDreamManager method @Override public ComponentName getDefaultDreamComponent() { - String name = Settings.Secure.getString(mContext.getContentResolver(), SCREENSAVER_DEFAULT_COMPONENT); + String name = Settings.Secure.getStringForUser(mContext.getContentResolver(), + SCREENSAVER_DEFAULT_COMPONENT, + UserHandle.getCallingUserId()); return name == null ? null : ComponentName.unflattenFromString(name); } @@ -210,6 +222,25 @@ public class DreamManagerService } public void systemReady() { + + // dream settings are kept per user, so keep track of current user + try { + mCurrentUserId = ActivityManagerNative.getDefault().getCurrentUser().id; + } catch (RemoteException e) { + Slog.w(TAG, "Couldn't get current user ID; guessing it's 0", e); + } + IntentFilter filter = new IntentFilter(); + filter.addAction(Intent.ACTION_USER_SWITCHED); + mContext.registerReceiver(new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (Intent.ACTION_USER_SWITCHED.equals(action)) { + mCurrentUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0); + if (DEBUG) Slog.v(TAG, "userId " + mCurrentUserId + " is in the house"); + } + }}, filter); + if (DEBUG) Slog.v(TAG, "ready to dream!"); } |