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

Commit d39a1f8b authored by DvTonder's avatar DvTonder Committed by Ricardo Cerqueira
Browse files

Framework: Add the ability to enable/disable use of Profiles

This will remove the Profiles item from the Power menu when the user has
selected to disable the use of System Profiles.

TODO: Better handling of returning a default profile when requested

Change-Id: I3c29b1bbd8f72c5432a1906a6b412d9412279c9f
parent 7310642c
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
@@ -2911,6 +2911,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
@@ -120,6 +120,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac

    private Profile mChosenProfile;

    private static final String SYSTEM_PROFILES_ENABLED = "system_profiles_enabled";

    /**
     * @param context everything needs a context :(
@@ -290,8 +291,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() {
@@ -310,6 +311,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
                        return false;
                    }
                });
        }

        // next: screenshot
        mItems.add(