1 /*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.android.intentresolver
18
19 import android.app.prediction.AppTarget
20 import android.app.prediction.AppTargetId
21 import android.content.ComponentName
22 import android.content.Context
23 import android.content.Intent
24 import android.content.pm.ShortcutInfo
25 import android.content.pm.ShortcutManager.ShareShortcutInfo
26 import android.os.Bundle
27 import android.service.chooser.ChooserTarget
28 import org.mockito.kotlin.doReturn
29 import org.mockito.kotlin.mock
30
createShareShortcutInfonull31 internal fun createShareShortcutInfo(
32 id: String,
33 componentName: ComponentName,
34 rank: Int
35 ): ShareShortcutInfo = ShareShortcutInfo(createShortcutInfo(id, componentName, rank), componentName)
36
37 internal fun createShortcutInfo(id: String, componentName: ComponentName, rank: Int): ShortcutInfo {
38 val context = mock<Context> { on { packageName } doReturn componentName.packageName }
39 return ShortcutInfo.Builder(context, id)
40 .setShortLabel("Short Label $id")
41 .setLongLabel("Long Label $id")
42 .setActivity(componentName)
43 .setRank(rank)
44 .build()
45 }
46
createAppTargetnull47 internal fun createAppTarget(shortcutInfo: ShortcutInfo) =
48 AppTarget(
49 AppTargetId(shortcutInfo.id),
50 shortcutInfo,
51 shortcutInfo.activity?.className ?: error("missing activity info")
52 )
53
54 fun createChooserTarget(
55 title: String,
56 score: Float,
57 componentName: ComponentName,
58 shortcutId: String
59 ): ChooserTarget =
60 ChooserTarget(
61 title,
62 null,
63 score,
64 componentName,
65 Bundle().apply { putString(Intent.EXTRA_SHORTCUT_ID, shortcutId) }
66 )
67