Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android でのハンズフリーに対応する #69

Merged
merged 32 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5bcc832
Android でのハンズフリーを実現するコードを追加する
tnoho Jan 24, 2024
31a7859
必要な API バージョンを 21 まで落とす
tnoho Jan 25, 2024
8c79970
インターフェイスを iOS と揃える
tnoho Jan 28, 2024
593fa6b
メインスレッドでの実行に変えるための処理を追加
tnoho Jan 31, 2024
f97887e
ビルドが通るように整理
tnoho Jan 31, 2024
4938132
stop を 2 回読んでしまうとクラッシュするので修正
tnoho Feb 6, 2024
51cd091
パーミッションチェックをライブラリに移す
tnoho Feb 6, 2024
bc99e64
ハンズフリーに切り替わらなくなる問題を修正する
tnoho Feb 6, 2024
f81ca20
OnChangeRoute の発生をデバイス変更のみにする
tnoho Feb 6, 2024
1e659c4
stop を呼ぶとコールバックが発生するので止める
tnoho Feb 6, 2024
42df19e
API Level 31 以上の処理を分ける
tnoho Feb 7, 2024
1fcd5d1
クラス名を整理
tnoho Feb 7, 2024
142770a
インターフェイスの細かい整理
tnoho Feb 7, 2024
a9f67bc
継承でさせる必要のない変数を整理
tnoho Feb 7, 2024
9135f43
BLUETOOTH_CONNECT が不要な Intent に切り替える
tnoho Feb 16, 2024
435c19e
メインスレッドに振り替える処理をライブラリに追加
tnoho Feb 18, 2024
ab2e848
ログ出力を整理
tnoho Feb 20, 2024
d57fe43
ビルド対象に入れてみる
tnoho Feb 20, 2024
29164da
JDK 17 のセットアップを挟んでみる
tnoho Feb 20, 2024
c7d97dc
Gradle のバージョンを 7.2 に統一する
tnoho Feb 20, 2024
3d24d9e
Gradle と JDK と setup-android のバージョンを上げる
tnoho Feb 21, 2024
35c4abc
namespace を追記
tnoho Feb 21, 2024
21775fd
Android NDK を指定する
tnoho Feb 22, 2024
2d5ec72
targetSdk と compileSdk を 34 にする
tnoho Feb 22, 2024
4992738
Sora にパッケージ名を変更
tnoho Feb 27, 2024
111092a
コードの構成を整理してインターフェイスで集約する
tnoho Feb 27, 2024
afe7cd1
AudioChangeRouteObserver が null でも動くようにする
tnoho Mar 2, 2024
62457db
指摘を受けた点を修正
tnoho Mar 5, 2024
ed1fbae
runOnMainThread を整理
tnoho Mar 5, 2024
74ebe21
コンストラクタにメインスレッド制約はないため制約をなくす
tnoho Mar 5, 2024
c2390c3
createWithMainThreadWrapper を整理する
tnoho Mar 5, 2024
9786829
Merge branch 'develop' into feature/add-android-handsfree
miosakuma Mar 6, 2024
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
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,14 @@ jobs:
if: matrix.name == 'android'
run: |
sudo apt-get -y install ninja-build
- name: Setup JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
if: matrix.name == 'android'
- name: Setup Android SDK
uses: android-actions/setup-android@v2.0.10
uses: android-actions/setup-android@v3.2.0
if: matrix.name == 'android'
- run: pip3 install numpy
- run: python3 run.py --test --package ${{ matrix.name }}
Expand Down
15 changes: 15 additions & 0 deletions android/Sora/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
3 changes: 3 additions & 0 deletions android/Sora/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions android/Sora/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions android/Sora/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions android/Sora/.idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions android/Sora/.idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions android/Sora/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions android/Sora/Sora/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
30 changes: 30 additions & 0 deletions android/Sora/Sora/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
plugins {
id 'com.android.library'
}

android {
namespace 'jp.shiguredo.sora'
compileSdk 34

defaultConfig {
minSdk 21

consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
}
Empty file.
21 changes: 21 additions & 0 deletions android/Sora/Sora/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
5 changes: 5 additions & 0 deletions android/Sora/Sora/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.BLUETOOTH" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package jp.shiguredo.sora.audiomanager;

import android.content.Context;

class MainThreadWrapper implements SoraAudioManager {
private SoraAudioManager soraAudioManager;

private static class OnChangeRouteObserverWrapper implements OnChangeRouteObserver {
OnChangeRouteObserver observer;

public OnChangeRouteObserverWrapper(OnChangeRouteObserver observer) {
this.observer = observer;
}

public void OnChangeRoute() {
//メインスレッドでない場合はメインスレッドで再実行
if (!SoraThreadUtils.runOnMainThread(this::OnChangeRoute)) {
return;
}

if (this.observer == null) {
return;
}
this.observer.OnChangeRoute();
}
}

MainThreadWrapper(Context context) {
//メインスレッドでない場合はメインスレッドで再実行
if (!SoraThreadUtils.runOnMainThread(() -> {
this.soraAudioManager = SoraAudioManagerFactory.create(context);
})) {
return;
}
this.soraAudioManager = SoraAudioManagerFactory.create(context);
}

@Override
public void start(OnChangeRouteObserver observer) {
//メインスレッドでない場合はメインスレッドで再実行
if (!SoraThreadUtils.runOnMainThread(() -> start(observer))) {
return;
}
soraAudioManager.start(new OnChangeRouteObserverWrapper(observer));
}

@Override
public void stop() {
//メインスレッドでない場合はメインスレッドで再実行
if (!SoraThreadUtils.runOnMainThread(this::stop)) {
return;
}
soraAudioManager.stop();
}

@Override
public void setHandsfree(boolean on) {
//メインスレッドでない場合はメインスレッドで再実行
if (!SoraThreadUtils.runOnMainThread(() -> setHandsfree(on))) {
return;
}
soraAudioManager.setHandsfree(on);
}

@Override
public boolean isHandsfree() {
return soraAudioManager.isHandsfree();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package jp.shiguredo.sora.audiomanager;

public interface SoraAudioManager {
interface OnChangeRouteObserver {
// オーディオデバイスの変更を通知するコールバック
void OnChangeRoute();
}

/*
* オーディオの制御を開始する
* Java は destructor がないので start - stop にする
*/
void start(OnChangeRouteObserver observer);

// オーディオの制御を終了する
void stop();

// ハンズフリーに設定する
void setHandsfree(boolean on);

// ハンズフリーかを確認する
boolean isHandsfree();
}
Loading
Loading