Skip to content

Instantly share code, notes, and snippets.

@ThiagoVinicius
Created May 26, 2013 14:58
Show Gist options
  • Save ThiagoVinicius/26ffeeffd8e4097bb403 to your computer and use it in GitHub Desktop.
Save ThiagoVinicius/26ffeeffd8e4097bb403 to your computer and use it in GitHub Desktop.
[PATCH] profiles: Broadcast profile updates
From e750993106b5bb704865e2adfefed28a470b815c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thiago=20Vin=C3=ADcius=20Freire=20de=20Ara=C3=BAjo=20Ribei?=
=?UTF-8?q?ro?= <thiagovfar@gmail.com>
Date: Sun, 26 May 2013 09:32:41 -0300
Subject: [PATCH] profiles: Broadcast profile updates
Add broadcast to indicate profile changes that does not
cause a profile to be selected.
Use the new broadcast to update the Profile Tile more
reliably.
Currently the tile update is triggered by a profile
selection. However, the active profile may change without
triggering a selection. This happens, for instance, on
locale changes.
The Profile Tile does handle locale changes, but is subject
to a race condition. If it handles the locale change before
the profile manager does, the name change will not be seen.
Change-Id: I193454f5100f1ae04dd24d50f25e75ec961f4d68
---
.../com/android/systemui/quicksettings/ProfileTile.java | 1 +
.../java/com/android/server/ProfileManagerService.java | 17 +++++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/ProfileTile.java b/packages/SystemUI/src/com/android/systemui/quicksettings/ProfileTile.java
index 18b3b49..47cb511 100644
--- a/packages/SystemUI/src/com/android/systemui/quicksettings/ProfileTile.java
+++ b/packages/SystemUI/src/com/android/systemui/quicksettings/ProfileTile.java
@@ -42,6 +42,7 @@ public class ProfileTile extends QuickSettingsTile {
super(context, qsc);
qsc.registerAction(ProfileManagerService.INTENT_ACTION_PROFILE_SELECTED, this);
+ qsc.registerAction(ProfileManagerService.INTENT_ACTION_PROFILE_UPDATED, this);
mProfileManager = (ProfileManager) mContext.getSystemService(Context.PROFILE_SERVICE);
diff --git a/services/java/com/android/server/ProfileManagerService.java b/services/java/com/android/server/ProfileManagerService.java
index c7f12ee..743f051 100644
--- a/services/java/com/android/server/ProfileManagerService.java
+++ b/services/java/com/android/server/ProfileManagerService.java
@@ -54,6 +54,15 @@ public class ProfileManagerService extends IProfileManager.Stub {
*/
public static final String INTENT_ACTION_PROFILE_SELECTED = "android.intent.action.PROFILE_SELECTED";
+ /**
+ * <p>Broadcast Action: Current profile has been updated. This is triggered every time the
+ * currently active profile is updated, instead of selected.</p>
+ * <p> For instance, this includes profile updates caused by a locale change, which doesn't
+ * trigger a profile selection, but causes its name to change.</p>
+ * @hide
+ */
+ public static final String INTENT_ACTION_PROFILE_UPDATED = "android.intent.action.PROFILE_UPDATED";
+
public static final String PERMISSION_CHANGE_SETTINGS = "android.permission.WRITE_SETTINGS";
private static final String PROFILE_FILENAME = "/data/system/profiles.xml";
@@ -218,6 +227,14 @@ public class ProfileManagerService extends IProfileManager.Stub {
restoreCallingIdentity(token);
persistIfDirty();
+ } else if (lastProfile != mActiveProfile) {
+ // Something definitely changed: notify.
+ long token = clearCallingIdentity();
+ Intent broadcast = new Intent(INTENT_ACTION_PROFILE_UPDATED);
+ broadcast.putExtra("name", mActiveProfile.getName());
+ broadcast.putExtra("uuid", mActiveProfile.getUuid().toString());
+ mContext.sendBroadcastAsUser(broadcast, UserHandle.ALL);
+ restoreCallingIdentity(token);
}
return true;
} catch (Exception ex) {
--
1.8.1.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment