Skip to content

Commit

Permalink
Merge pull request phhusson#23 from boydaihungst/feat/nubia/shoulder-btn
Browse files Browse the repository at this point in the history
feat(nubia): add switch to enable/disable shoulder buttons/triggers
  • Loading branch information
phhusson authored Nov 21, 2023
2 parents a89c14e + 90b6533 commit 3d44671
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 1 deletion.
15 changes: 15 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>
<service
android:name=".NubiaShoulderBtnTilesService"
android:exported="true"
android:icon="@drawable/tile_game_mode"
android:label="Shoulder triggers"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
android:enabled="false">
<meta-data
android:name="android.service.quicksettings.TOGGLEABLE_TILE"
android:value="true" />

<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>

<receiver android:name=".Starter"
android:exported="true">
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/me/phh/treble/app/Nubia.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ object Nubia : EntryStartup {
val b = sp.getBoolean(key, false)
SystemProperties.set("nubia.perf.ufs", if(b) "1" else "0")
}
NubiaSettings.shoulderBtn -> {
val i = if(sp.getBoolean(key, false)) "1" else "0"
if (NubiaSettings.is6Series()){
// Right
writeToFileNofail("/sys/devices/platform/soc/a88000.i2c/i2c-3/3-0010/mode", i)
// Left
writeToFileNofail("/sys/devices/platform/soc/998000.i2c/i2c-1/1-0010/mode", i)
} else if (NubiaSettings.is5GLite()){
// both right and left
writeToFileNofail("/sys/devices/platform/soc/880000.i2c/i2c-0/0-0010/mode", i)
} else if (NubiaSettings.is5G5S()){
// Right
writeToFileNofail("/sys/devices/platform/soc/988000.i2c/i2c-1/1-0010/mode", i)
// Left
writeToFileNofail("/sys/devices/platform/soc/990000.i2c/i2c-2/2-0010/mode", i)
}
}
}
}

Expand All @@ -99,6 +116,7 @@ object Nubia : EntryStartup {
//Refresh parameters on boot
spListener.onSharedPreferenceChanged(sp, NubiaSettings.dt2w)
spListener.onSharedPreferenceChanged(sp, NubiaSettings.tsGameMode)
spListener.onSharedPreferenceChanged(sp, NubiaSettings.shoulderBtn)
spListener.onSharedPreferenceChanged(sp, NubiaSettings.bypassCharger)
spListener.onSharedPreferenceChanged(sp, NubiaSettings.highTouchScreenSampleRate)

Expand All @@ -125,6 +143,14 @@ object Nubia : EntryStartup {
ctxt,
NubiaGameModeTilesService::class.java
), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0)
if (NubiaSettings.is5G5S() || NubiaSettings.is6Series() || NubiaSettings.is5GLite()) {
// Enable shoulder triggers quick setting tile
ctxt.packageManager.setComponentEnabledSetting(
ComponentName(
ctxt,
NubiaShoulderBtnTilesService::class.java
), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0)

}
}
}
3 changes: 3 additions & 0 deletions app/src/main/java/me/phh/treble/app/NubiaSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ object NubiaSettings : Settings {
val boostGpu = "nubia_boost_gpu"
val boostCache = "nubia_boost_cache"
val boostUfs = "nubia_boost_ufs"
val shoulderBtn = "nubia_shoulder_btn"

override fun enabled() = Tools.vendorFp.toLowerCase().startsWith("nubia/")
fun is6Series() = Tools.vendorFp.toLowerCase().startsWith("nubia/nx669")
fun is5GLite() = Tools.vendorFp.toLowerCase().startsWith("nubia/nx651")
fun is5G5S() = Tools.vendorFp.toLowerCase().startsWith("nubia/nx659")

}

Expand Down
48 changes: 47 additions & 1 deletion app/src/main/java/me/phh/treble/app/NubiaTilesService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,50 @@ class NubiaFanControlTilesService: TileService() {
override fun onTileRemoved() {
super.onTileRemoved()
}
}
}


class NubiaShoulderBtnTilesService: TileService() {
private lateinit var sp: SharedPreferences

override fun onCreate() {
this.sp = PreferenceManager.getDefaultSharedPreferences(this)
}

// Called when the user adds your tile.
override fun onTileAdded() {
super.onTileAdded()
}
// Called when your app can update your tile.
override fun onStartListening() {
super.onStartListening()
val shouldBtnEnabled: Boolean = sp.getBoolean(NubiaSettings.shoulderBtn, false)
qsTile.contentDescription = if (shouldBtnEnabled) "On" else "Off"
qsTile.state = if (shouldBtnEnabled) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE
qsTile.updateTile()

}

// Called when your app can no longer update your tile.
override fun onStopListening() {
super.onStopListening()
}

// Called when the user taps on your tile in an active or inactive state.
override fun onClick() {
super.onClick()
val shouldBtnEnabled: Boolean = sp.getBoolean(NubiaSettings.shoulderBtn, false)
with (sp.edit()) {
putBoolean(NubiaSettings.shoulderBtn, !shouldBtnEnabled)
apply()
}
qsTile.state = if (shouldBtnEnabled) Tile.STATE_INACTIVE else Tile.STATE_ACTIVE
qsTile.contentDescription = if (shouldBtnEnabled) "Off" else "On"
qsTile.updateTile()
}
// Called when the user removes your tile.
override fun onTileRemoved() {
super.onTileRemoved()
}

}
7 changes: 7 additions & 0 deletions app/src/main/res/xml/pref_nubia.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
android:key="nubia_touchscreen_game_mode"
android:title="Enable game mode"
app:summaryOn="Auto stop fan is disabled" />
<CheckBoxPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="false"
android:key="nubia_shoulder_btn"
android:title="Enable shoulder buttons"
app:summary="Shoulder buttons/triggers" />
<CheckBoxPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down

0 comments on commit 3d44671

Please sign in to comment.