diff options
author | Roman Birg <roman@cyngn.com> | 2015-12-18 09:37:00 -0800 |
---|---|---|
committer | Roman Birg <roman@cyngn.com> | 2015-12-21 10:30:15 -0800 |
commit | cb4a990216b9e0960a6c927651eba8649f8d9619 (patch) | |
tree | eed8e6f238926fa316ea8b60699168620af55262 /cm/lib | |
parent | c81519d31be8a2adac3d51f2656bcb1708919e57 (diff) | |
download | vendor_cmsdk-cb4a990216b9e0960a6c927651eba8649f8d9619.zip vendor_cmsdk-cb4a990216b9e0960a6c927651eba8649f8d9619.tar.gz vendor_cmsdk-cb4a990216b9e0960a6c927651eba8649f8d9619.tar.bz2 |
Profiles: add isEnabled(); send state changes
Ref: CYNGNOS-1461
Change-Id: Idee9417a2f0b181c8d15cd763859c0a0e581dce6
Signed-off-by: Roman Birg <roman@cyngn.com>
Diffstat (limited to 'cm/lib')
-rw-r--r-- | cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java b/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java index aa7c27c..1a93c86 100644 --- a/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java +++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java @@ -18,7 +18,11 @@ package org.cyanogenmod.platform.internal; import android.content.ComponentName; import android.content.ServiceConnection; +import android.database.ContentObserver; +import android.net.Uri; +import android.os.Message; import com.android.internal.policy.IKeyguardService; +import cyanogenmod.providers.CMSettings; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; @@ -70,6 +74,8 @@ public class ProfileManagerService extends SystemService { /* package */ static final File PROFILE_FILE = new File(Environment.getSystemSecureDirectory(), "profiles.xml"); + private static final int MSG_SEND_PROFILE_STATE = 10; + private Map<UUID, Profile> mProfiles; // Match UUIDs and names, used for reverse compatibility @@ -89,6 +95,7 @@ public class ProfileManagerService extends SystemService { private boolean mDirty; private BackupManager mBackupManager; private ProfileTriggerHelper mTriggerHelper; + private Profile mEmptyProfile; private Runnable mBindKeyguard = new Runnable() { @Override @@ -127,10 +134,41 @@ public class ProfileManagerService extends SystemService { } }; + private final Handler.Callback mHandlerCallback = new Handler.Callback() { + @Override + public boolean handleMessage(Message msg) { + switch (msg.what) { + case MSG_SEND_PROFILE_STATE: + Intent newState = new Intent(ProfileManager.PROFILES_STATE_CHANGED_ACTION); + newState.putExtra(ProfileManager.EXTRA_PROFILES_STATE, msg.arg1); + + mContext.sendBroadcastAsUser(newState, UserHandle.ALL); + + + return true; + } + return false; + } + }; + + private class ProfilesObserver extends ContentObserver { + public ProfilesObserver(Handler handler) { + super(handler); + } + + @Override + public void onChange(boolean selfChange, Uri uri) { + int state = CMSettings.System.getInt(mContext.getContentResolver(), + CMSettings.System.SYSTEM_PROFILES_ENABLED, + ProfileManager.PROFILES_STATE_ENABLED); + mHandler.obtainMessage(MSG_SEND_PROFILE_STATE, state, 0 /* unused */).sendToTarget(); + } + } + public ProfileManagerService(Context context) { super(context); mContext = context; - mHandler = new Handler(); + mHandler = new Handler(mHandlerCallback); publishBinderService(CMContextConstants.CM_PROFILE_SERVICE, mService); } @@ -149,6 +187,10 @@ public class ProfileManagerService extends SystemService { filter.addAction(Intent.ACTION_LOCALE_CHANGED); filter.addAction(Intent.ACTION_SHUTDOWN); mContext.registerReceiver(mIntentReceiver, filter); + + mContext.getContentResolver().registerContentObserver( + CMSettings.System.getUriFor(CMSettings.System.SYSTEM_PROFILES_ENABLED), + false, new ProfilesObserver(mHandler), UserHandle.USER_ALL); } private void bindKeyguard() { @@ -178,6 +220,7 @@ public class ProfileManagerService extends SystemService { mProfiles = new HashMap<UUID, Profile>(); mProfileNames = new HashMap<String, UUID>(); mGroups = new HashMap<UUID, NotificationGroup>(); + mEmptyProfile = new Profile("EmptyProfile"); mDirty = false; boolean init = skipFile; @@ -214,6 +257,10 @@ public class ProfileManagerService extends SystemService { @Override @Deprecated public boolean setActiveProfileByName(String profileName) { + if (!isEnabled()) { + Log.w(TAG, "Unable to set active profile because profiles are disabled."); + return false; + } if (!mProfileNames.containsKey(profileName)) { // Since profileName could not be casted into a UUID, we can call it a string. Log.w(TAG, "Unable to find profile to set active, based on string: " + profileName); @@ -237,6 +284,10 @@ public class ProfileManagerService extends SystemService { @Override public boolean setActiveProfile(ParcelUuid profileParcelUuid) { + if (!isEnabled()) { + Log.w(TAG, "Unable to set active profile because profiles are disabled."); + return false; + } /* * We need to clear the caller's identity in order to * - allow the profile switch to execute actions @@ -286,6 +337,10 @@ public class ProfileManagerService extends SystemService { @Override public Profile getActiveProfile() { + if (!isEnabled()) { + // Profiles are not enabled, return empty profile + return mEmptyProfile; + } return getActiveProfileInternal(); } @@ -416,6 +471,19 @@ public class ProfileManagerService extends SystemService { } return mGroups.get(uuid.getUuid()); } + + @Override + public boolean isEnabled() { + long token = clearCallingIdentity(); + try { + return CMSettings.System.getIntForUser(mContext.getContentResolver(), + CMSettings.System.SYSTEM_PROFILES_ENABLED, + ProfileManager.PROFILES_STATE_ENABLED, + UserHandle.USER_CURRENT) == ProfileManager.PROFILES_STATE_ENABLED; + } finally { + restoreCallingIdentity(token); + } + } }; private void addProfileInternal(Profile profile) { |