Skip to content

Commit 435e992

Browse files
committed
Fixed crash when shortcut is updated
Todo: Remove MVI implementation
1 parent a3cbfe5 commit 435e992

File tree

22 files changed

+693
-699
lines changed

22 files changed

+693
-699
lines changed

data/repository/src/main/kotlin/com/android/geto/data/repository/DefaultShortcutRepository.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,37 @@ class DefaultShortcutRepository @Inject constructor(
3737

3838
override fun requestPinShortcut(
3939
packageName: String,
40+
icon: ByteArray?,
4041
appName: String,
41-
getoShortcutInfoCompat: GetoShortcutInfoCompat,
42+
id: String,
43+
shortLabel: String,
44+
longLabel: String,
4245
): Boolean {
4346
return shortcutManagerCompatWrapper.requestPinShortcut(
4447
packageName = packageName,
48+
icon = icon,
4549
appName = appName,
46-
getoShortcutInfoCompat = getoShortcutInfoCompat,
50+
id = id,
51+
shortLabel = shortLabel,
52+
longLabel = longLabel,
4753
)
4854
}
4955

5056
override fun updateShortcuts(
5157
packageName: String,
58+
icon: ByteArray?,
5259
appName: String,
53-
getoShortcutInfoCompats: List<GetoShortcutInfoCompat>,
60+
id: String,
61+
shortLabel: String,
62+
longLabel: String,
5463
): Boolean {
5564
return shortcutManagerCompatWrapper.updateShortcuts(
5665
packageName = packageName,
66+
icon = icon,
5767
appName = appName,
58-
getoShortcutInfoCompats = getoShortcutInfoCompats,
68+
id = id,
69+
shortLabel = shortLabel,
70+
longLabel = longLabel,
5971
)
6072
}
6173

domain/framework/src/main/kotlin/com/android/geto/domain/framework/ShortcutManagerCompatWrapper.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,20 @@ interface ShortcutManagerCompatWrapper {
2525

2626
fun requestPinShortcut(
2727
packageName: String,
28+
icon: ByteArray?,
2829
appName: String,
29-
getoShortcutInfoCompat: GetoShortcutInfoCompat,
30+
id: String,
31+
shortLabel: String,
32+
longLabel: String,
3033
): Boolean
3134

3235
fun updateShortcuts(
3336
packageName: String,
37+
icon: ByteArray?,
3438
appName: String,
35-
getoShortcutInfoCompats: List<GetoShortcutInfoCompat>,
39+
id: String,
40+
shortLabel: String,
41+
longLabel: String,
3642
): Boolean
3743

3844
suspend fun getShortcuts(): List<GetoShortcutInfoCompat>

domain/model/src/main/kotlin/com/android/geto/domain/model/GetoShortcutInfoCompat.kt

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,6 @@ package com.android.geto.domain.model
1919

2020
data class GetoShortcutInfoCompat(
2121
val id: String,
22-
val icon: ByteArray?,
2322
val shortLabel: String,
2423
val longLabel: String,
25-
) {
26-
override fun equals(other: Any?): Boolean {
27-
if (this === other) return true
28-
if (javaClass != other?.javaClass) return false
29-
30-
other as GetoShortcutInfoCompat
31-
32-
if (id != other.id) return false
33-
if (icon != null) {
34-
if (other.icon == null) return false
35-
if (!icon.contentEquals(other.icon)) return false
36-
} else if (other.icon != null) {
37-
return false
38-
}
39-
if (shortLabel != other.shortLabel) return false
40-
if (longLabel != other.longLabel) return false
41-
42-
return true
43-
}
44-
45-
override fun hashCode(): Int {
46-
var result = id.hashCode()
47-
result = 31 * result + (icon?.contentHashCode() ?: 0)
48-
result = 31 * result + shortLabel.hashCode()
49-
result = 31 * result + longLabel.hashCode()
50-
return result
51-
}
52-
}
24+
)

domain/repository/src/main/kotlin/com/android/geto/domain/repository/ShortcutRepository.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,20 @@ interface ShortcutRepository {
2525

2626
fun requestPinShortcut(
2727
packageName: String,
28+
icon: ByteArray?,
2829
appName: String,
29-
getoShortcutInfoCompat: GetoShortcutInfoCompat,
30+
id: String,
31+
shortLabel: String,
32+
longLabel: String,
3033
): Boolean
3134

3235
fun updateShortcuts(
3336
packageName: String,
37+
icon: ByteArray?,
3438
appName: String,
35-
getoShortcutInfoCompats: List<GetoShortcutInfoCompat>,
39+
id: String,
40+
shortLabel: String,
41+
longLabel: String,
3642
): Boolean
3743

3844
suspend fun getPinnedShortcuts(): List<GetoShortcutInfoCompat>

domain/repository/src/testFixtures/kotlin/com/android/geto/domain/repository/TestShortcutRepository.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,22 @@ class TestShortcutRepository : ShortcutRepository {
3333

3434
override fun requestPinShortcut(
3535
packageName: String,
36+
icon: ByteArray?,
3637
appName: String,
37-
getoShortcutInfoCompat: GetoShortcutInfoCompat,
38+
id: String,
39+
shortLabel: String,
40+
longLabel: String,
3841
): Boolean {
3942
return requestPinShortcutSupported
4043
}
4144

4245
override fun updateShortcuts(
4346
packageName: String,
47+
icon: ByteArray?,
4448
appName: String,
45-
getoShortcutInfoCompats: List<GetoShortcutInfoCompat>,
49+
id: String,
50+
shortLabel: String,
51+
longLabel: String,
4652
): Boolean {
4753
return if (updateImmutableShortcuts) {
4854
throw IllegalArgumentException()

domain/use-case/src/main/kotlin/com/android/geto/domain/usecase/RequestPinShortcutUseCase.kt

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
package com.android.geto.domain.usecase
1919

20-
import com.android.geto.domain.model.GetoShortcutInfoCompat
2120
import com.android.geto.domain.model.RequestPinShortcutResult
2221
import com.android.geto.domain.model.RequestPinShortcutResult.SupportedLauncher
2322
import com.android.geto.domain.model.RequestPinShortcutResult.UnsupportedLauncher
@@ -32,39 +31,54 @@ class RequestPinShortcutUseCase @Inject constructor(
3231
) {
3332
suspend operator fun invoke(
3433
packageName: String,
34+
icon: ByteArray?,
3535
appName: String,
36-
getoShortcutInfoCompat: GetoShortcutInfoCompat,
36+
id: String,
37+
shortLabel: String,
38+
longLabel: String,
3739
): RequestPinShortcutResult {
3840
if (!shortcutRepository.isRequestPinShortcutSupported()) {
3941
return UnsupportedLauncher
4042
}
4143

42-
val pinnedShortcut = shortcutRepository.getPinnedShortcut(id = getoShortcutInfoCompat.id)
44+
val pinnedShortcut = shortcutRepository.getPinnedShortcut(id = id)
4345

4446
return if (pinnedShortcut != null) {
4547
updateShortcuts(
4648
packageName = packageName,
49+
icon = icon,
4750
appName = appName,
48-
getoShortcutInfoCompat = getoShortcutInfoCompat,
51+
id = id,
52+
shortLabel = shortLabel,
53+
longLabel = longLabel,
4954
)
5055
} else {
5156
requestPinShortcut(
5257
packageName = packageName,
58+
icon = icon,
5359
appName = appName,
54-
getoShortcutInfoCompat = getoShortcutInfoCompat,
60+
id = id,
61+
shortLabel = shortLabel,
62+
longLabel = longLabel,
5563
)
5664
}
5765
}
5866

5967
private fun requestPinShortcut(
6068
packageName: String,
69+
icon: ByteArray?,
6170
appName: String,
62-
getoShortcutInfoCompat: GetoShortcutInfoCompat,
71+
id: String,
72+
shortLabel: String,
73+
longLabel: String,
6374
): RequestPinShortcutResult {
6475
return if (shortcutRepository.requestPinShortcut(
6576
packageName = packageName,
77+
icon = icon,
6678
appName = appName,
67-
getoShortcutInfoCompat = getoShortcutInfoCompat,
79+
id = id,
80+
shortLabel = shortLabel,
81+
longLabel = longLabel,
6882
)
6983
) {
7084
SupportedLauncher
@@ -75,14 +89,20 @@ class RequestPinShortcutUseCase @Inject constructor(
7589

7690
private fun updateShortcuts(
7791
packageName: String,
92+
icon: ByteArray?,
7893
appName: String,
79-
getoShortcutInfoCompat: GetoShortcutInfoCompat,
94+
id: String,
95+
shortLabel: String,
96+
longLabel: String,
8097
): RequestPinShortcutResult {
8198
return try {
8299
if (shortcutRepository.updateShortcuts(
83100
packageName = packageName,
101+
icon = icon,
84102
appName = appName,
85-
getoShortcutInfoCompats = listOf(getoShortcutInfoCompat),
103+
id = id,
104+
shortLabel = shortLabel,
105+
longLabel = longLabel,
86106
)
87107
) {
88108
UpdateSuccess

feature/app-settings/src/androidTest/kotlin/com/android/geto/feature/appsettings/AppSettingsScreenDialogsTest.kt

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,22 @@ class AppSettingsScreenDialogsTest {
5757
appSettingsResult = null,
5858
revertAppSettingsResult = null,
5959
requestPinShortcutResult = null,
60-
setPrimaryClipResult = false,
6160
templateDialogUiState = TemplateDialogUiState.Loading,
61+
onApplyAppSettings = {},
62+
onRevertAppSettings = {},
63+
onCheckAppSetting = {},
64+
onDeleteAppSetting = {},
65+
onAddAppSetting = {},
66+
onRequestPinShortcut = { _, _, _ -> },
67+
onGetSecureSettingsByName = { _, _ -> },
68+
onLaunchIntentForPackage = {},
69+
onPostNotification = { _, _, _ -> },
70+
onResetApplyAppSettingsResult = {},
71+
onResetRequestPinShortcutResult = {},
72+
onResetRevertAppSettingsResult = {},
73+
onResetAddAppSettingResult = {},
6274
onNavigationIconClick = {},
6375
onShizuku = {},
64-
onEvent = {},
6576
)
6677
}
6778

@@ -92,11 +103,22 @@ class AppSettingsScreenDialogsTest {
92103
appSettingsResult = null,
93104
revertAppSettingsResult = null,
94105
requestPinShortcutResult = null,
95-
setPrimaryClipResult = false,
96106
templateDialogUiState = TemplateDialogUiState.Loading,
107+
onApplyAppSettings = {},
108+
onRevertAppSettings = {},
109+
onCheckAppSetting = {},
110+
onDeleteAppSetting = {},
111+
onAddAppSetting = {},
112+
onRequestPinShortcut = { _, _, _ -> },
113+
onGetSecureSettingsByName = { _, _ -> },
114+
onLaunchIntentForPackage = {},
115+
onPostNotification = { _, _, _ -> },
116+
onResetApplyAppSettingsResult = {},
117+
onResetRequestPinShortcutResult = {},
118+
onResetRevertAppSettingsResult = {},
119+
onResetAddAppSettingResult = {},
97120
onNavigationIconClick = {},
98121
onShizuku = {},
99-
onEvent = {},
100122
)
101123
}
102124

@@ -126,11 +148,22 @@ class AppSettingsScreenDialogsTest {
126148
appSettingsResult = null,
127149
revertAppSettingsResult = null,
128150
requestPinShortcutResult = null,
129-
setPrimaryClipResult = false,
130151
templateDialogUiState = TemplateDialogUiState.Loading,
152+
onApplyAppSettings = {},
153+
onRevertAppSettings = {},
154+
onCheckAppSetting = {},
155+
onDeleteAppSetting = {},
156+
onAddAppSetting = {},
157+
onRequestPinShortcut = { _, _, _ -> },
158+
onGetSecureSettingsByName = { _, _ -> },
159+
onLaunchIntentForPackage = {},
160+
onPostNotification = { _, _, _ -> },
161+
onResetApplyAppSettingsResult = {},
162+
onResetRequestPinShortcutResult = {},
163+
onResetRevertAppSettingsResult = {},
164+
onResetAddAppSettingResult = {},
131165
onNavigationIconClick = {},
132166
onShizuku = {},
133-
onEvent = {},
134167
)
135168
}
136169

@@ -158,11 +191,22 @@ class AppSettingsScreenDialogsTest {
158191
appSettingsResult = null,
159192
revertAppSettingsResult = null,
160193
requestPinShortcutResult = null,
161-
setPrimaryClipResult = false,
162194
templateDialogUiState = TemplateDialogUiState.Loading,
195+
onApplyAppSettings = {},
196+
onRevertAppSettings = {},
197+
onCheckAppSetting = {},
198+
onDeleteAppSetting = {},
199+
onAddAppSetting = {},
200+
onRequestPinShortcut = { _, _, _ -> },
201+
onGetSecureSettingsByName = { _, _ -> },
202+
onLaunchIntentForPackage = {},
203+
onPostNotification = { _, _, _ -> },
204+
onResetApplyAppSettingsResult = {},
205+
onResetRequestPinShortcutResult = {},
206+
onResetRevertAppSettingsResult = {},
207+
onResetAddAppSettingResult = {},
163208
onNavigationIconClick = {},
164209
onShizuku = {},
165-
onEvent = {},
166210
)
167211
}
168212

@@ -240,11 +284,22 @@ class AppSettingsScreenDialogsTest {
240284
appSettingsResult = null,
241285
revertAppSettingsResult = null,
242286
requestPinShortcutResult = null,
243-
setPrimaryClipResult = false,
244287
templateDialogUiState = TemplateDialogUiState.Loading,
288+
onApplyAppSettings = {},
289+
onRevertAppSettings = {},
290+
onCheckAppSetting = {},
291+
onDeleteAppSetting = {},
292+
onAddAppSetting = {},
293+
onRequestPinShortcut = { _, _, _ -> },
294+
onGetSecureSettingsByName = { _, _ -> },
295+
onLaunchIntentForPackage = {},
296+
onPostNotification = { _, _, _ -> },
297+
onResetApplyAppSettingsResult = {},
298+
onResetRequestPinShortcutResult = {},
299+
onResetRevertAppSettingsResult = {},
300+
onResetAddAppSettingResult = {},
245301
onNavigationIconClick = {},
246302
onShizuku = {},
247-
onEvent = {},
248303
)
249304
}
250305

0 commit comments

Comments
 (0)