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

Commit fd116ad1 authored by Glenn Kasten's avatar Glenn Kasten
Browse files

Inform AudioFlinger of device's low RAM attribute

to help it configure it's memory

Bug: 9798886
Change-Id: Ia2df59cfcb76f5ff48cca92b107915e2adde899c
parent 3d2469d1
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -282,6 +282,12 @@ android_media_AudioSystem_getOutputLatency(JNIEnv *env, jobject clazz, jint stre
    return (jint) afLatency;
}

static jint
android_media_AudioSystem_setLowRamDevice(JNIEnv *env, jobject clazz, jboolean isLowRamDevice)
{
    return (jint) AudioSystem::setLowRamDevice((bool) isLowRamDevice);
}

// ----------------------------------------------------------------------------

static JNINativeMethod gMethods[] = {
@@ -308,6 +314,7 @@ static JNINativeMethod gMethods[] = {
    {"getPrimaryOutputSamplingRate", "()I", (void *)android_media_AudioSystem_getPrimaryOutputSamplingRate},
    {"getPrimaryOutputFrameCount",   "()I", (void *)android_media_AudioSystem_getPrimaryOutputFrameCount},
    {"getOutputLatency",    "(I)I",     (void *)android_media_AudioSystem_getOutputLatency},
    {"setLowRamDevice",     "(Z)I",     (void *)android_media_AudioSystem_setLowRamDevice},
};

int register_android_media_AudioSystem(JNIEnv *env)
+13 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.media.AudioManager.RINGER_MODE_SILENT;
import static android.media.AudioManager.RINGER_MODE_VIBRATE;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.AppOpsManager;
import android.app.KeyguardManager;
@@ -528,6 +529,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
        updateStreamVolumeAlias(false /*updateVolumes*/);
        createStreamStates();

        readAndSetLowRamDevice();
        mMediaServerOk = true;

        // Call setRingerModeInt() to apply correct mute
@@ -3469,6 +3471,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                    // process restarts after a crash, not the first time it is started.
                    AudioSystem.setParameters("restarting=true");

                    readAndSetLowRamDevice();

                    // Restore device connection states
                    synchronized (mConnectedDevices) {
                        Set set = mConnectedDevices.entrySet();
@@ -6698,4 +6702,13 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
        pw.print("  mMainType=0x"); pw.println(Integer.toHexString(mCurAudioRoutes.mMainType));
        pw.print("  mBluetoothName="); pw.println(mCurAudioRoutes.mBluetoothName);
    }

    // Inform AudioFlinger of our device's low RAM attribute
    private static void readAndSetLowRamDevice()
    {
        int status = AudioSystem.setLowRamDevice(ActivityManager.isLowRamDeviceStatic());
        if (status != 0) {
            Log.w(TAG, "AudioFlinger informed of device's low RAM attribute; status " + status);
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -403,4 +403,6 @@ public class AudioSystem
    public static native int getPrimaryOutputFrameCount();
    public static native int getOutputLatency(int stream);

    public static native int setLowRamDevice(boolean isLowRamDevice);

}