Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

Simple application to set the USB DAC volume on UNROOTED Android Devices

[DOWNLOAD](https://github.com/guyman624/usbDacVolumeAndroid/releases/download/release-1.0/app-debug.apk)
## This is a fork of the original app
I improved it so it detects when you connect a usb dac, automatically unlocks the volume and exits. You need to enable recording permission (is necessary on latest android versions) and enable auto exiting.
Works flawlessly with the Apple USB to Jack adapter :)
Go to releases for the latest alpha version.

# Why
The vast majority of high end android smartphones sold today do not contain a 3.5mm headphone jack. To remedy this, most people will use a USB-C to 3.5mm DAC. However, there are certian DACs (namely the Apple USB- C DAC) that do not default to their highest output setting. On most platforms (Windows, Linux, macOS, iOS), this isn't an issue because they either force the highest DAC volume and adjust their own mixer volume, or they control the DAC volume explicitly. Android does neither, so as a result, some DACs are quieter than they possibly can be.
Expand Down
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ android {
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.10.2'
}
}
buildFeatures {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<!-- Used for auto starting when usb is connected -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
Binary file added app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 48 additions & 9 deletions app/src/main/java/com/example/libusbAndroidTest/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.example.libusbAndroidTest;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import android.Manifest;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
Expand All @@ -17,9 +21,11 @@
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.libusbAndroidTest.databinding.ActivityMainBinding;

Expand All @@ -39,10 +45,13 @@ public class MainActivity extends AppCompatActivity {
private EditText volInput;

private CheckBox autoApply;
private CheckBox quitAfterApply;

private int deviceDescriptor = -1;
private Button recordPermissionButton;

private int deviceDescriptor = -1;
private static String deviceName;

private static final String TAG = "USB DAC Volume Adjustment" ;
private static final String ACTION_USB_PERMISSION =
"com.android.example.USB_PERMISSION";
Expand Down Expand Up @@ -79,15 +88,10 @@ protected void connectDevice(UsbDevice device)
deviceName = initializeNativeDevice(fileDescriptor);
deviceDescriptor = fileDescriptor;

if(autoApply.isChecked()){
if(autoApply.isChecked() && quitAfterApply.isChecked()){
setDeviceVolume(fileDescriptor);
finishAndRemoveTask();
}


// Example of a call to a native method
tv.setText(deviceName);
tv.setBackgroundColor(Color.TRANSPARENT);

}

protected void checkUsbDevices()
Expand Down Expand Up @@ -115,10 +119,19 @@ protected void onCreate(Bundle savedInstanceState) {
tv = binding.sampleText;
volInput = binding.volume;
autoApply = binding.autoApply;
quitAfterApply = binding.quitAfterApply;
recordPermissionButton = binding.recordPermissionButton;

SharedPreferences settings = getApplicationContext().getSharedPreferences("myPrefs", 0);
volInput.setText(settings.getString("volume", "0000"));
autoApply.setChecked(settings.getBoolean("autoApply", false));
quitAfterApply.setChecked(settings.getBoolean("quitAfterApply", false));

if (ContextCompat.checkSelfPermission(this,
Manifest.permission.RECORD_AUDIO)
== PackageManager.PERMISSION_GRANTED) {
recordPermissionButton.setEnabled(false);
}

// Initialize UsbManager
usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
Expand Down Expand Up @@ -154,13 +167,19 @@ public void applyButtonPressed(View view){
editor.apply();
}
}
public void checkboxPressed(View view){
public void autoApplyCheckboxPressed(View view){
SharedPreferences settings = getApplicationContext().getSharedPreferences("myPrefs", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("autoApply", autoApply.isChecked());
editor.apply();
}

public void quitAfterApplyCheckboxPressed(View view){
SharedPreferences settings = getApplicationContext().getSharedPreferences("myPrefs", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("quitAfterApply", quitAfterApply.isChecked());
editor.apply();
}

public static byte[] hexStringToByteArray(String s) {
int len = s.length();
Expand All @@ -187,5 +206,25 @@ public void setDeviceVolume(int fileDescriptor){
}

setDeviceVolume(fileDescriptor, hexStringToByteArray(volume));
Toast.makeText(getApplicationContext(), "Volume set for DAC!", Toast.LENGTH_LONG).show();
}

// Trigger the permission popup

private final int CALLBACK_PERMISSION = 1;
public void recordPermissionButtonPressed(View view) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, CALLBACK_PERMISSION);
}

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == CALLBACK_PERMISSION) {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
recordPermissionButton.setEnabled(false);
return;
}
}
}
}
30 changes: 0 additions & 30 deletions app/src/main/res/drawable-v24/ic_launcher_foreground.xml

This file was deleted.

Loading