• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 android.tools.device.apphelpers
18 
19 import android.app.Instrumentation
20 import android.content.Intent
21 import android.content.pm.PackageManager
22 import android.content.pm.ResolveInfo
23 import android.net.Uri
24 import android.tools.common.traces.component.ComponentNameMatcher
25 
26 /** Helper to launch the Maps app (not compatible with AOSP) */
27 class MapsAppHelper
28 @JvmOverloads
29 constructor(
30     instrumentation: Instrumentation,
31     pkgManager: PackageManager = instrumentation.context.packageManager
32 ) :
33     StandardAppHelper(
34         instrumentation,
35         MapsAppHelper.Companion.getMapLauncherName(pkgManager),
36         MapsAppHelper.Companion.getMapComponent(pkgManager)
37     ) {
38     companion object {
getMapIntentnull39         private fun getMapIntent(): Intent {
40             val gmmIntentUri = Uri.parse("google.streetview:cbll=46.414382,10.013988")
41             return Intent(Intent.ACTION_VIEW, gmmIntentUri)
42         }
43 
getResolveInfonull44         private fun getResolveInfo(pkgManager: PackageManager): ResolveInfo {
45             val intent = MapsAppHelper.Companion.getMapIntent()
46             return pkgManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY)
47                 ?: error("unable to resolve camera activity")
48         }
49 
getMapComponentnull50         private fun getMapComponent(pkgManager: PackageManager): ComponentNameMatcher {
51             val resolveInfo = MapsAppHelper.Companion.getResolveInfo(pkgManager)
52             return ComponentNameMatcher(
53                 resolveInfo.activityInfo.packageName,
54                 className = resolveInfo.activityInfo.name
55             )
56         }
57 
getMapLauncherNamenull58         private fun getMapLauncherName(pkgManager: PackageManager): String {
59             val resolveInfo = MapsAppHelper.Companion.getResolveInfo(pkgManager)
60             return resolveInfo.loadLabel(pkgManager).toString()
61         }
62     }
63 }
64