Skip to content

Commit 352584b

Browse files
committed
wip
1 parent 05c3895 commit 352584b

File tree

6 files changed

+223
-51
lines changed

6 files changed

+223
-51
lines changed

app/src/main/cpp/NativeTrack.cpp

+200-26
Large diffs are not rendered by default.

app/src/main/cpp/aosp_stubs.h

+2-11
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
struct fake_sp {
2525
void* /* MUST be RefBase* (or compatible contract, but ymmv) */ thePtr;
2626
};
27-
// make sure to call RefBase::createWeak(thePtr, <arbitrary unique id>) and save returned pointer
28-
// to refs, then call RefBase::weakref_type::decWeak(refs) when you don't need it anymore
27+
// make sure to call RefBase::createWeak(thePtr, <unique id>) and save returned pointer to refs,
28+
// then call RefBase::weakref_type::decWeak(refs, <unique id>) when you don't need it anymore
2929
struct fake_wp {
3030
void* /* MUST be RefBase* */ thePtr;
3131
void* /* RefBase::weakref_type* */ refs;
@@ -94,27 +94,22 @@ namespace android {
9494
class RefBase {
9595
public:
9696
inline RefBase() {
97-
ALOGI("fake base impl of ctor says hello");
9897
ZN7android7RefBaseC2Ev(this);
9998
}
10099

101100
virtual inline ~RefBase() {
102-
ALOGI("fake base impl of dtor says hello");
103101
ZN7android7RefBaseD2Ev(this);
104102
}
105103

106104
inline void incStrong(void* id) {
107-
ALOGI("fake base impl of incStrong says hello, this=%p id=%p", this, id);
108105
ZNK7android7RefBase9incStrongEPKv(this, id);
109106
}
110107

111108
inline void decStrong(void* id) {
112-
ALOGI("fake base impl of decStrong says hello");
113109
ZNK7android7RefBase9decStrongEPKv(this, id);
114110
}
115111

116112
inline void* createWeak(void* id) {
117-
ALOGI("fake base impl of createWeak says hello");
118113
return ZNK7android7RefBase10createWeakEPKv(this, id);
119114
}
120115

@@ -220,21 +215,17 @@ namespace android {
220215

221216
inline void android::RefBase::onFirstRef()
222217
{
223-
ALOGI("fake base impl of onFirstRef says hello");
224218
}
225219

226220
inline void android::RefBase::onLastStrongRef(const void*)
227221
{
228-
ALOGI("fake base impl of onLastStrongRef says hello");
229222
}
230223

231224
inline bool android::RefBase::onIncStrongAttempted(uint32_t flags, const void*)
232225
{
233-
ALOGI("fake base impl of onIncStrongAttempted says hello");
234226
return flags & 1;
235227
}
236228

237229
inline void android::RefBase::onLastWeakRef(const void*)
238230
{
239-
ALOGI("fake base impl of onLastWeakRef says hello");
240231
}

app/src/main/cpp/gramophone.cpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,8 @@ Java_org_akanework_gramophone_logic_utils_AfFormatTracker_00024Companion_findAfF
307307
unsigned int generation1 = 0;
308308
unsigned int generation;
309309
unsigned int numPorts;
310-
std::vector<audio_port_oreo> nPorts;
311-
std::vector<audio_port_legacy> nPortsOld;
310+
void* nPorts;
312311
int attempts = 5;
313-
314312
// get the port count and all the ports until they both return the same generation
315313
do {
316314
if (attempts-- < 0) {
@@ -332,32 +330,39 @@ Java_org_akanework_gramophone_logic_utils_AfFormatTracker_00024Companion_findAfF
332330
}
333331
// Tuck on double the space to prevent heap corruption if OEM made the audio_port bigger
334332
if (oreo)
335-
nPorts.resize(numPorts * 2);
333+
nPorts = new std::vector<audio_port_oreo>(numPorts * 2);
336334
else
337-
nPortsOld.resize(numPorts * 2);
335+
nPorts = new std::vector<audio_port_legacy>(numPorts * 2);
338336

339337
status = ZN7android11AudioSystem14listAudioPortsE17audio_port_role_t17audio_port_type_tPjP13audio_port_v7S3_(
340338
LEGACY_AUDIO_PORT_ROLE_SOURCE, LEGACY_AUDIO_PORT_TYPE_MIX, &numPorts,
341-
oreo ? (void *) &nPorts[0] : (void *) &nPortsOld[0], &generation);
339+
oreo ? (void*)&(*(std::vector<audio_port_oreo>*)nPorts)[0] :
340+
(void*)&(*(std::vector<audio_port_legacy>*)nPorts)[0], &generation);
342341
} while (generation1 != generation && status == 0);
343342

344343
int i = 0;
345344
if (oreo) {
346-
for (auto port: nPorts) {
345+
for (auto port: *(std::vector<audio_port_oreo>*)nPorts) {
347346
if (i++ == numPorts) break; // needed because vector size > numPorts
348347
ALOGE("found port %d named %s", port.id, port.name);
349348
if (port.id == id) {
350-
return (int32_t) port.active_config.channel_mask;
349+
auto ret = (int32_t) port.active_config.channel_mask;
350+
delete (std::vector<audio_port_oreo>*)nPorts;
351+
return ret;
351352
}
352353
}
354+
delete (std::vector<audio_port_oreo>*)nPorts;
353355
} else {
354-
for (auto port: nPortsOld) {
356+
for (auto port: *(std::vector<audio_port_legacy>*)nPorts) {
355357
if (i++ == numPorts) break; // needed because vector size > numPorts
356358
ALOGE("found port %d named %s", port.id, port.name);
357359
if (port.id == id) {
358-
return (int32_t) port.active_config.channel_mask;
360+
auto ret = (int32_t) port.active_config.channel_mask;
361+
delete (std::vector<audio_port_legacy>*)nPorts;
362+
return ret;
359363
}
360364
}
365+
delete (std::vector<audio_port_legacy>*)nPorts;
361366
}
362367
return INT32_MAX;
363368
}

app/src/main/kotlin/org/akanework/gramophone/logic/utils/AfFormatTracker.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -601,19 +601,19 @@ class AfFormatTracker(
601601
private set
602602
var formatChangedCallback: ((AfFormatInfo?) -> Unit)? = null
603603

604-
private val routingChangedListener: Any? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
604+
private val routingChangedListener = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
605605
object : AudioRouting.OnRoutingChangedListener {
606606
override fun onRoutingChanged(router: AudioRouting) {
607607
this@AfFormatTracker.onRoutingChanged(router as AudioTrack)
608608
}
609-
}
609+
} as Any
610610
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
611611
@Suppress("deprecation")
612612
object : AudioTrack.OnRoutingChangedListener {
613613
override fun onRoutingChanged(router: AudioTrack) {
614614
this@AfFormatTracker.onRoutingChanged(router)
615615
}
616-
}
616+
} as Any
617617
} else null
618618

619619
private fun onRoutingChanged(router: AudioTrack) {

app/src/main/kotlin/org/akanework/gramophone/logic/utils/NativeTrack.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class NativeTrack(context: Context) {
5252
private external fun getRealPtr(@Suppress("unused") ptr: Long): Long
5353
private external fun dtor(@Suppress("unused") ptr: Long)
5454
fun set(): Boolean {
55-
//doSet(ptr)
55+
// TODO assert maxRequiredSpeed==1.0f on L
56+
doSet(ptr, 3, 13370, 1, 3, 0, 0, 0, 1.0f, 0, 0, 0, false, false, 16, 0, 1, 0, 0, 0, 2, 0, 0, "", 0, false, 3)
5657
Log.e("hi", "dump:${AfFormatTracker.dumpInternal(getRealPtr(ptr))}")
5758
return myState == State.ALIVE
5859
}

gradle.properties

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ kotlin.code.style=official
2121
# resources declared in the library itself and none from the library's dependencies,
2222
# thereby reducing the size of the R class for that library
2323
android.nonTransitiveRClass=true
24+
android.nonFinalResIds=true
2425
# Generate compile-time only R class for app modules
2526
android.enableAppCompileTimeRClass=true
2627
# Only keep the single relevant constructor for types mentioned in XML files

0 commit comments

Comments
 (0)