Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8f03009e authored by Steve Kondik's avatar Steve Kondik Committed by Gerrit Code Review
Browse files

Merge "Framework: Add the ability to enable/disable use of Profiles (Part 2/2)" into jellybean

parents bc6dc12d 11218100
Loading
Loading
Loading
Loading
+40 −13
Original line number Diff line number Diff line
@@ -24,8 +24,12 @@ import android.os.IBinder;
import android.os.ParcelUuid;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings;
import android.util.Log;

import com.android.internal.R;


/**
 * @hide
 */
@@ -37,6 +41,11 @@ public class ProfileManager {

    private static final String TAG = "ProfileManager";

    private static final String SYSTEM_PROFILES_ENABLED = "system_profiles_enabled";

    // A blank profile that is created to be returned if profiles disabled
    private static Profile mEmptyProfile;

    /** @hide */
    static public IProfileManager getService() {
        if (sService != null) {
@@ -50,32 +59,50 @@ public class ProfileManager {
    /** @hide */
    ProfileManager(Context context, Handler handler) {
        mContext = context;
        mEmptyProfile = new Profile("EmptyProfile");
    }

    @Deprecated
    public void setActiveProfile(String profileName) {
        if (Settings.System.getInt(mContext.getContentResolver(),
                SYSTEM_PROFILES_ENABLED, 1) == 1) {
            // Profiles are enabled, return active profile
            try {
                getService().setActiveProfileByName(profileName);
            } catch (RemoteException e) {
                Log.e(TAG, e.getLocalizedMessage(), e);
            }
        }
    }

    public void setActiveProfile(UUID profileUuid) {
        if (Settings.System.getInt(mContext.getContentResolver(),
                SYSTEM_PROFILES_ENABLED, 1) == 1) {
            // Profiles are enabled, return active profile
            try {
                getService().setActiveProfile(new ParcelUuid(profileUuid));
            } catch (RemoteException e) {
                Log.e(TAG, e.getLocalizedMessage(), e);
            }
        }
    }

    public Profile getActiveProfile() {
        if (Settings.System.getInt(mContext.getContentResolver(),
                SYSTEM_PROFILES_ENABLED, 1) == 1) {
            // Profiles are enabled, return active profile
            try {
                return getService().getActiveProfile();
            } catch (RemoteException e) {
                Log.e(TAG, e.getLocalizedMessage(), e);
            }
            return null;

        } else {
            // Profiles are not enabled, return the empty profile
            return mEmptyProfile;
        }

    }

    /** @hide */
+6 −0
Original line number Diff line number Diff line
@@ -2648,6 +2648,12 @@ public final class Settings {
         */
        public static final String STATUS_BAR_NOTIF_COUNT = "status_bar_notif_count";

        /**
         * Show the pending notification counts as overlays on the status bar
         * @hide
         */
        public static final String SYSTEM_PROFILES_ENABLED = "system_profiles_enabled";

        /**
         * Settings to backup. This is here so that it's in the same place as the settings
         * keys and easy to update.
+19 −17
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
    private IWindowManager mIWindowManager;
    private Profile mChosenProfile;

    private static final String SYSTEM_PROFILES_ENABLED = "system_profiles_enabled";

    /**
     * @param context everything needs a context :(
@@ -258,8 +259,8 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
                }
            });

	
        // next: profile
        // next: profile - only shown if enabled, which is true by default
        if (Settings.System.getInt(mContext.getContentResolver(), SYSTEM_PROFILES_ENABLED, 1) == 1) {
            mItems.add(
                new ProfileChooseAction() {
                    public void onPress() {
@@ -278,6 +279,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
                        return false;
                    }
                });
        }

        // next: screenshot
        mItems.add(
+7 −4
Original line number Diff line number Diff line
@@ -670,11 +670,14 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
        }

        // if the current profile has disabled us, don't show
        Profile profile = mProfileManager.getActiveProfile();
        if (profile != null) {
            if (!lockedOrMissing
                && mProfileManager.getActiveProfile().getScreenLockMode() == Profile.LockMode.DISABLE) {
                    && profile.getScreenLockMode() == Profile.LockMode.DISABLE) {
                if (DEBUG) Log.d(TAG, "doKeyguard: not showing because of profile override");
                return;
            }
        }

        if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");
        showLocked();