Browse Source

Add Android activity and resources.

chirpmodem-v8.0.0
Jon Beniston 5 months ago
parent
commit
83c929a63a
  1. 67
      android/qt6/AndroidManifest.xml
  2. 5
      android/qt6/res/mipmap-anydpi-v26/ic_launcher.xml
  3. BIN
      android/qt6/res/mipmap-hdpi/ic_launcher.png
  4. BIN
      android/qt6/res/mipmap-hdpi/ic_launcher_background.png
  5. BIN
      android/qt6/res/mipmap-hdpi/ic_launcher_foreground.png
  6. BIN
      android/qt6/res/mipmap-mdpi/ic_launcher.png
  7. BIN
      android/qt6/res/mipmap-mdpi/ic_launcher_background.png
  8. BIN
      android/qt6/res/mipmap-mdpi/ic_launcher_foreground.png
  9. BIN
      android/qt6/res/mipmap-xhdpi/ic_launcher.png
  10. BIN
      android/qt6/res/mipmap-xhdpi/ic_launcher_background.png
  11. BIN
      android/qt6/res/mipmap-xhdpi/ic_launcher_foreground.png
  12. BIN
      android/qt6/res/mipmap-xxhdpi/ic_launcher.png
  13. BIN
      android/qt6/res/mipmap-xxhdpi/ic_launcher_background.png
  14. BIN
      android/qt6/res/mipmap-xxhdpi/ic_launcher_foreground.png
  15. BIN
      android/qt6/res/mipmap-xxxhdpi/ic_launcher.png
  16. BIN
      android/qt6/res/mipmap-xxxhdpi/ic_launcher_background.png
  17. BIN
      android/qt6/res/mipmap-xxxhdpi/ic_launcher_foreground.png
  18. 338
      android/qt6/src/org/sdrangel/SDRangelActivity.java

67
android/qt6/AndroidManifest.xml

@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
<?xml version="1.0"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.sdrangel"
android:installLocation="auto"
android:versionCode="13"
android:versionName="7.25.1.1">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
<application
android:name="org.qtproject.qt.android.bindings.QtApplication"
android:hardwareAccelerated="true"
android:label="SDRangel"
android:extractNativeLibs="true"
android:requestLegacyExternalStorage="true"
android:allowBackup="true"
android:fullBackupOnly="false"
android:icon="@mipmap/ic_launcher">
<activity
android:name="org.sdrangel.SDRangelActivity"
android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density"
android:label="SDRangel"
android:launchMode="singleTop"
android:screenOrientation="unspecified"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="sdrangel" />
<meta-data
android:name="android.app.arguments"
android:value="" />
<meta-data
android:name="android.app.background_running"
android:value="true" />
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.qtprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/qtprovider_paths"/>
</provider>
</application>
</manifest>

5
android/qt6/res/mipmap-anydpi-v26/ic_launcher.xml

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

BIN
android/qt6/res/mipmap-hdpi/ic_launcher.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
android/qt6/res/mipmap-hdpi/ic_launcher_background.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 852 B

BIN
android/qt6/res/mipmap-hdpi/ic_launcher_foreground.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
android/qt6/res/mipmap-mdpi/ic_launcher.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
android/qt6/res/mipmap-mdpi/ic_launcher_background.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 B

BIN
android/qt6/res/mipmap-mdpi/ic_launcher_foreground.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
android/qt6/res/mipmap-xhdpi/ic_launcher.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

BIN
android/qt6/res/mipmap-xhdpi/ic_launcher_background.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
android/qt6/res/mipmap-xhdpi/ic_launcher_foreground.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

BIN
android/qt6/res/mipmap-xxhdpi/ic_launcher.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
android/qt6/res/mipmap-xxhdpi/ic_launcher_background.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
android/qt6/res/mipmap-xxhdpi/ic_launcher_foreground.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

BIN
android/qt6/res/mipmap-xxxhdpi/ic_launcher.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
android/qt6/res/mipmap-xxxhdpi/ic_launcher_background.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
android/qt6/res/mipmap-xxxhdpi/ic_launcher_foreground.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

338
android/qt6/src/org/sdrangel/SDRangelActivity.java

@ -0,0 +1,338 @@ @@ -0,0 +1,338 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2022 Jon Beniston, M7RCE //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
package org.sdrangel;
import org.qtproject.qt.android.bindings.QtActivity;
import android.hardware.usb.*;
import android.app.*;
import android.content.*;
import android.os.*;
import android.os.PowerManager.WakeLock;
import android.view.WindowManager;
import android.util.Log;
import java.util.HashMap;
import java.util.Vector;
import java.util.Iterator;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
public class SDRangelActivity extends QtActivity
{
private String TAG = "sdrangel";
private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
private static final long USB_PERMISSION_TIMEOUT_SECONDS = 30;
private PendingIntent m_permissionIntent;
private UsbManager m_manager;
private HandlerThread m_usbReceiverThread;
private Handler m_usbReceiverHandler;
private HashMap<Integer, UsbDeviceConnection> m_connectedDevices; // fd to connection
private HashMap<String, UsbDevice> m_devicesBySerial;
private final Object m_lock = new Object();
CountDownLatch m_doneSignal;
boolean m_permissionGranted;
int m_fd;
private WakeLock m_wakeLock;
public SDRangelActivity()
{
super();
Log.e(TAG, "SDRangelActivity");
m_connectedDevices = new HashMap<Integer, UsbDeviceConnection>();
m_devicesBySerial = new HashMap<String, UsbDevice>();
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
try {
m_manager = (UsbManager) getSystemService(Context.USB_SERVICE);
Intent permissionIntent = new Intent(ACTION_USB_PERMISSION);
permissionIntent.setPackage(getPackageName());
m_permissionIntent = PendingIntent.getBroadcast(this, 0, permissionIntent, PendingIntent.FLAG_MUTABLE);
m_usbReceiverThread = new HandlerThread("SDRangelUsbReceiver");
m_usbReceiverThread.start();
m_usbReceiverHandler = new Handler(m_usbReceiverThread.getLooper());
IntentFilter permissionFilter = new IntentFilter(ACTION_USB_PERMISSION);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
registerReceiver(usbManagerBroadcastReceiver, permissionFilter, null, m_usbReceiverHandler, Context.RECEIVER_NOT_EXPORTED);
} else {
registerReceiver(usbManagerBroadcastReceiver, permissionFilter, null, m_usbReceiverHandler);
}
} catch (Exception e) {
Log.e(TAG, "SDRangelActivity::onCreate: Exception " + e.toString());
}
}
@Override
public void onDestroy()
{
try {
unregisterReceiver(usbManagerBroadcastReceiver);
} catch (Exception e) {
Log.d(TAG, "SDRangelActivity::onDestroy: unregisterReceiver: " + e.toString());
}
if (m_usbReceiverThread != null) {
m_usbReceiverThread.quitSafely();
m_usbReceiverThread = null;
m_usbReceiverHandler = null;
}
super.onDestroy();
}
// Prevent app from being put too sleep (which can stop acquisition)
public void acquireWakeLock()
{
if (m_wakeLock == null)
{
PowerManager powerManager = (PowerManager)getSystemService(POWER_SERVICE);
m_wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SDRangel::WakeLockTag");
}
Log.e(TAG, "Acquiring wake lock");
m_wakeLock.acquire();
}
public void releaseWakeLock()
{
if (m_wakeLock != null)
{
Log.e(TAG, "Releasing wake lock");
m_wakeLock.release();
}
}
public void acquireScreenLock()
{
Log.e(TAG, "Acquiring screen lock");
runOnUiThread(new Runnable() {
@Override
public void run() {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
});
}
public void releaseScreenLock()
{
Log.e(TAG, "Releasing screen lock");
runOnUiThread(new Runnable() {
@Override
public void run() {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
});
}
public String[] listUSBDeviceSerials(int vid, int pid)
{
Vector<String> serials = new Vector<String>();
try
{
synchronized(m_lock)
{
HashMap<String, UsbDevice> deviceList = m_manager.getDeviceList();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
while(deviceIterator.hasNext())
{
UsbDevice device = deviceIterator.next();
if ((device.getVendorId() == vid) && (device.getProductId() == pid))
{
// From Android Q, we need permission to read serial
if (requestUSBPermission(device))
{
String serial = device.getSerialNumber();
if (serial != null)
{
Log.d(TAG, "Found a device: ID=" + device.getDeviceId() + " Name=" + device.getDeviceName() + " Serial=" + serial);
m_devicesBySerial.put(serial, device);
serials.add(serial);
}
else
{
Log.d(TAG, "Found a device with no serial: ID=" + device.getDeviceId() + " Name=" + device.getDeviceName());
}
}
}
}
}
}
catch (Exception e)
{
Log.e(TAG, "SDRangelActivity::listUSBDeviceSerials: Exception " + e.toString());
}
return serials.toArray(new String[serials.size()]);
}
public int openUSBDevice(String serial)
{
Log.e(TAG, "SDRangelActivity::openUSBDevice serial=" + serial);
try
{
synchronized(m_lock)
{
m_fd = -1;
UsbDevice device = m_devicesBySerial.get(serial);
if (device != null)
{
if (requestUSBPermission(device))
{
String deviceSerial = device.getSerialNumber();
if ((deviceSerial != null) && (deviceSerial.compareToIgnoreCase(serial) == 0))
{
m_fd = connectToUSBDevice(device);
return m_fd;
}
}
}
HashMap<String, UsbDevice> deviceList = m_manager.getDeviceList();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
while(deviceIterator.hasNext())
{
device = deviceIterator.next();
if (m_manager.hasPermission(device))
{
String deviceSerial = device.getSerialNumber();
if ((deviceSerial != null) && (deviceSerial.compareToIgnoreCase(serial) == 0))
{
m_fd = connectToUSBDevice(device);
break;
}
}
}
return m_fd;
}
}
catch (Exception e)
{
Log.e(TAG, "SDRangelActivity::openUSBDevice: Exception " + e.toString());
return -1;
}
}
public void closeUSBDevice(int fd)
{
Log.e(TAG, "SDRangelActivity::closeUSBDevice: fd=" + fd);
UsbDeviceConnection connection = m_connectedDevices.get(fd);
if (connection != null)
{
connection.close();
m_connectedDevices.remove(fd);
}
}
private boolean requestUSBPermission(UsbDevice device) throws InterruptedException
{
if (m_manager == null)
{
Log.e(TAG, "SDRangelActivity::requestUSBPermission: UsbManager is not available");
return false;
}
if (m_manager.hasPermission(device)) {
return true;
}
if (m_permissionIntent == null)
{
Log.e(TAG, "SDRangelActivity::requestUSBPermission: permission intent is not available");
return false;
}
m_permissionGranted = false;
m_doneSignal = new CountDownLatch(1);
m_manager.requestPermission(device, m_permissionIntent);
if (!m_doneSignal.await(USB_PERMISSION_TIMEOUT_SECONDS, TimeUnit.SECONDS))
{
Log.e(TAG, "SDRangelActivity::requestUSBPermission: timed out waiting for permission for device " + device);
return false;
}
return m_permissionGranted;
}
private int connectToUSBDevice(UsbDevice device)
{
UsbDeviceConnection connection = m_manager.openDevice(device);
if (connection != null)
{
// Can disconnect kernel driver with:
//connection.claimInterface(device.getInterface(0), true);
// However, this results in airspyhf.c:libusb_set_configuration returning BUSY
int fd = connection.getFileDescriptor();
if (fd >= 0)
{
m_connectedDevices.put(fd, connection);
return fd;
}
connection.close();
}
return -1;
}
private final BroadcastReceiver usbManagerBroadcastReceiver = new BroadcastReceiver()
{
public void onReceive(Context context, Intent intent)
{
try
{
String action = intent.getAction();
Log.d(TAG, "INTENT ACTION: " + action);
if (ACTION_USB_PERMISSION.equals(action))
{
synchronized (this)
{
UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false))
{
if(device != null)
{
m_permissionGranted = true;
Log.d(TAG, "Granted permission for device " + device.getDeviceId());
}
}
else
{
Log.d(TAG, "Permission denied for device " + device);
}
if (m_doneSignal != null) {
m_doneSignal.countDown();
}
}
}
}
catch(Exception e)
{
Log.d(TAG, "Exception: " + e);
}
}
};
}
Loading…
Cancel
Save