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

Commit 4a21b25f authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Allow profile and device owners to change and get the master volume mute state.

Also protect muting master volume with op code OP_AUDIO_MASTER_VOLUME.
Bug: 13585918
Change-Id: I91fe7ee60cd291cca15966b3127c0bb8a4828f6a
parent f89fa833
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -5205,6 +5205,7 @@ package android.app.admin {
    method public boolean isApplicationBlocked(android.content.ComponentName, java.lang.String);
    method public boolean isDeviceOwnerApp(java.lang.String);
    method public boolean isLockTaskPermitted(android.content.ComponentName);
    method public boolean isMasterVolumeMuted(android.content.ComponentName);
    method public boolean isProfileOwnerApp(java.lang.String);
    method public void lockNow();
    method public void removeActiveAdmin(android.content.ComponentName);
@@ -5218,6 +5219,7 @@ package android.app.admin {
    method public void setGlobalSetting(android.content.ComponentName, java.lang.String, java.lang.String);
    method public void setKeyguardDisabledFeatures(android.content.ComponentName, int);
    method public void setLockTaskComponents(android.content.ComponentName[]) throws java.lang.SecurityException;
    method public void setMasterVolumeMuted(android.content.ComponentName, boolean);
    method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int);
    method public void setMaximumTimeToLock(android.content.ComponentName, long);
    method public void setPasswordExpirationTimeout(android.content.ComponentName, long);
+34 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.RestrictionsManager;
import android.media.AudioService;
import android.net.ProxyInfo;
import android.os.Bundle;
import android.os.Handler;
@@ -2406,4 +2407,37 @@ public class DevicePolicyManager {
            }
        }
    }

    /**
     * Called by profile or device owners to set the master volume mute on or off.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param on {@code true} to mute master volume, {@code false} to turn mute off.
     */
    public void setMasterVolumeMuted(ComponentName admin, boolean on) {
        if (mService != null) {
            try {
                mService.setMasterVolumeMuted(admin, on);
            } catch (RemoteException re) {
                Log.w(TAG, "Failed to setMasterMute on device policy service");
            }
        }
    }

    /**
     * Called by profile or device owners to check whether the master volume mute is on or off.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @return {@code true} if master volume is muted, {@code false} if it's not.
     */
    public boolean isMasterVolumeMuted(ComponentName admin) {
        if (mService != null) {
            try {
                return mService.isMasterVolumeMuted(admin);
            } catch (RemoteException re) {
                Log.w(TAG, "Failed to get isMasterMute on device policy service");
            }
        }
        return false;
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -147,4 +147,7 @@ interface IDevicePolicyManager {

    void setGlobalSetting(in ComponentName who, in String setting, in String value);
    void setSecureSetting(in ComponentName who, in String setting, in String value);

    void setMasterVolumeMuted(in ComponentName admin, boolean on);
    boolean isMasterVolumeMuted(in ComponentName admin);
}
+1 −1
Original line number Diff line number Diff line
@@ -1017,7 +1017,7 @@ public class AudioManager {
    public void setMasterMute(boolean state, int flags) {
        IAudioService service = getService();
        try {
            service.setMasterMute(state, flags, mICallBack);
            service.setMasterMute(state, flags, mContext.getOpPackageName(), mICallBack);
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in setMasterMute", e);
        }
+6 −1
Original line number Diff line number Diff line
@@ -1321,11 +1321,16 @@ public class AudioService extends IAudioService.Stub {
    }

    /** @see AudioManager#setMasterMute(boolean, int) */
    public void setMasterMute(boolean state, int flags, IBinder cb) {
    public void setMasterMute(boolean state, int flags, String callingPackage, IBinder cb) {
        if (mUseFixedVolume) {
            return;
        }

        if (mAppOps.noteOp(AppOpsManager.OP_AUDIO_MASTER_VOLUME, Binder.getCallingUid(),
                callingPackage) != AppOpsManager.MODE_ALLOWED) {
            return;
        }

        if (state != AudioSystem.getMasterMute()) {
            AudioSystem.setMasterMute(state);
            // Post a persist master volume msg
Loading