InstrumentClusterRenderingService cannot recognize my navigation App - android

I am working on an AAOS (Android Automotive OS) platform. The OS version is 10.
I included "DirectRenderingCluster" in my car_product/build/car.mk as
PRODUCT_PACKAGES += DirectRenderingCluster.
In this App, there is a ClusterRenderingService, which implements InstrumentClusterRenderingService.
In InstrumentClusterRenderingService, it will try to gather some information of the suitable navigation App from the PackageManager. Originally, it will pick the FakeClusterNavigationActivity in EmbeddedKitchenSinkApp.
I want to replace the FakeClusterNavigationActivity with my own navigation App.
I mimicked it and made a similar activity.
However, I am getting error messages printed at line 153 and 299 of InstrumentClusterRenderingService.
What do I miss? What should I do to make the Car service recognize my App is an eligible navigation App for cluster? Thank you.
My AndroidManifest.xml looks like as follows. The targetSdkVersion is 29.
<manifest
package="com.mytest.android"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionName="1.0"
android:versionCode="1"
android:installLocation="auto"
android:sharedUserId="android.uid.system">
<application
android:hardwareAccelerated="true"
android:directBootAware="true"
android:persistent="false"
android:name="com.mytest.android.NaviApp"
android:label="#string/application_label"
android:icon="#drawable/icon">
<!-- Activity for cluster. Note that this is not the only activity in this App. -->
<activity android:process=":map_surface"
android:name=".MapSurfaceActivity"
android:label="MapSurfaceActivity"
android:screenOrientation="landscape"
android:launchMode="singleInstance"
android:allowEmbedded="true"
android:exported="true"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.car.cluster.NAVIGATION"/>
</intent-filter>
</activity>
<!-- Content provider for images (fake, not functional) -->
<provider android:name=".cluster.ClusterContentProvider"
android:authorities="com.mytest.android.cluster.clustercontentprovider"
android:grantUriPermissions="true"
android:exported="true"/>

It turns out to be Google's bug and has been fixed in the later code.
If the navigation app is launched as non-system user and is not installed for system user, this bug will occur.
In the original code, it uses system user's PackageManager to call getPackageInfo() and queryIntentActivities(). However, the navigation app is not installed for system user (maybe being put in the blacklist), so it won't be found.
To fix, PackageManager.MATCH_ANY_USER flag should be used in getPackageInfo(), and queryIntentActivitiesAsUser() should be used in stead of queryIntentActivities().
I don't know what commits fixed them but they are shown in the master branch.
https://android.googlesource.com/platform/packages/services/Car/+/master/car-lib/src/android/car/cluster/renderer/InstrumentClusterRenderingService.java

Related

ActivityNotFoundException: Shortcut could not be started

I'm trying to implement App Shortcuts to my app, but i can't get them work.
My shortcut.xml:
<Shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="shortcut"
android:enabled="true"
android:icon="#drawable/ic_shortcut"
android:shortcutShortLabel="#string/shortcut_label">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.example"
android:targetClass="com.example.package.Activity"/>
</shortcut>
manifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example">
<application
android:name=".Application"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:resizeableActivity="false"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".package.Activity"
android:label="#string/app_name"
android:launchMode="singleTask"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/voice_search_params" />
<meta-data android:name="android.app.shortcuts"
android:resource="#xml/shortcuts" />
</activity>
So, i do shortcut same as in google example. I can see and click on shortcut, but nothing happens. I've tried different activities, changing activity location, activity action, params, like "exported=true", but nothing changes - in logs i can see only
ActivityNotFoundException: Shortcut could not be started
The only difference between my shortcut log, and google camera shortcut log is path to activity:
I/ActivityManager: START u0 {act=android.intent.action.VIEW flg=0x1000c000 cmp=com.example/.package.Activity}
vs
I/ActivityManager: START u0 {act=android.media.action.STILL_IMAGE_CAMERA flg=0x1000c000 cmp=com.google.android.GoogleCamera/com.android.camera.activity.CameraImageActivity}
Google cam has full path to activity, but package path differs.
PS: tried today google sample, static app shortcuts doesn't work in sample too. Dynamic app shortcuts work well.
In addition to Matin's answer, if you have multiple build types that change your application id, it won't work.
In my case, I had .debug and .qa suffix for application id. You can't reference to string reference or use variables inside intent element.
I found two solutions:
1) You will create different shortcuts.xml file for different build types and update your targetPackage.
For example,
<intent
android:action="com.example.ACTION"
android:targetClass="com.example.MainActivity"
android:targetPackage="com.example.debug"/>
2) There is a plugin that allows you to use applicationId variable in your XML file.
https://github.com/timfreiheit/ResourcePlaceholdersPlugin
android:targetPackage have to contain your application ID. So if you have defined your app id in build.gradle as applicationId "com.my.app.id" you have to use android:targetPackage="com.my.app.id"
Change the package name on your Activity to:
android:name=".Activity"
Change your shortcut target class to:
android:targetClass="com.example.Activity"
I also met this problem. Then i found that android:targetClass is not right path.
android:targetClass="com.example.camille.testappshortcuts.Main"
Main is app's access.
Maybe you should change Activity to another name, then add it.

Defining your own permissions in android

I am trying make my own permission for android application.
For this my android manifest file looks like this.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hp.happybirthday" >
<permission
android:name="com.example.hp.happybirthday.PERM"
android:description="#string/pdesc"
android:label="#string/CAREFUL"
/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:permission="com.example.hp.happybirthday.PERM">
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The problem that I am facing is that I want to have my own permission associated with this application and hence i have added the following line as shown above under the application tag, so that only those activities have access to this app which possess my defined permission.
android:permission="com.example.hp.happybirthday.PERM"
But the problem is that when I try to run my app, the app whose manifest file I have declared, it shows the error app is not installed.
But when I remove the above mentioned line, it works, but then any activity will have access to this app which I do not want.
when I try to run my app, the app whose manifest file I have declared, it shows the error app is not installed
That is because the home screen is an app, and the home screen does not hold your custom permission. Hence, the home screen cannot start your launcher activity.
then any activity will have access to this app which I do not want
First, custom permissions do not work all that well.
Second, permissions are usually applied at a finer granularity than "this app". You only secure those components that need the security, and you leave public other components, like the launcher activity.
It looks like you've defined the permission, and set it to be required... but you haven't actually granted it to your own app. Add a uses-permission tag

Android accessory displays splash screen instead of launching app

I'm developing an Android app to interface with a custom accessory, using a Moto X 1st-gen and a Galaxy S5 for testing. On both of these phones, when the accessory is connected, instead of prompting the user to launch the app, it simply displays a gray modal with the accessory company's logo. The strange thing is that if I have multiple apps installed with this accessory filter, the launch-app prompt does pop up, and if I select my app and launch it through the prompt, it works as expected. If I select 'always launch' and then uninstall the other app, it works as expected. But if I update the app, the problem resurfaces.
I can't seem to find any other instances of this problem occurring. I've tried changing which Activity the intent-filter is tied to; no luck.
I've configured the AndroidManifest like so:
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="19" />
<uses-feature android:name="android.hardware.usb.accessory" />
...
<application>
<uses-library android:name="com.android.future.usb.accessory" />
...
<activity
android:name=".activity.AccessoryActivity"
android:label="#string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="#xml/accessory_filter" />
</activity>
</application>
And have my accessory_filter set up like so:
<resources>
<usb-accessory manufacturer="My-Manufacturer" model="My-Model" version="1.0"/>
</resources>
It seems that this behavior was occurring because I was using a large PNG (671x725) in the drawable folder as the app icon. When I got around to creating individual icons at the appropriate dpi sizes, the problem vanished. I have no clue why icon size would have any bearing whatsoever on the ability of the OS to launch an app on accessory connect, but there you go.

Android application doesn't appear on recent apps list

i'm deploying an android application (Android 4.0.3) and when I press the home screen the application doesn't stay on the recent apps list. I've noticed that when I restart the application, it starts on the last screen i've navigated before press the home button. Anyone can help? Here is me Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="#drawable/logo_home"
android:allowBackup="true">
<activity
android:name="com.test.activity.CommunicatorActivity"
android:launchMode="singleTop"
android:label="" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.test.activity.InputActivity"
android:windowSoftInputMode="adjustPan|stateHidden">
</activity>
<activity android:name="com.test.activity.SettingsActivity"
android:windowSoftInputMode="adjustPan|stateHidden">
</activity>
<activity android:name="com.test.activity.OutputActivity"
android:windowSoftInputMode="adjustPan|stateHidden">
</activity>
</application>
</manifest>
I'm going to go out on a limb and suggest that this is your problem:
android:label=""
In your root activity CommunicatorActivity you've set the label to be an empty string. This label is used to identify your app in the list of available apps and because it is empty, this may be causing it not to show up in the list of recent apps.
Remove android:excludeFromRecents="true" from your manifest
You should use
android:label="your app_name"
2 things
Ok, there isn't something obvious in your manifest that should prevent it from appearing in your recents list.
1. Wrong identification
It's not always straight forward to tell which task contains your activity, using the GUI.
One of the possibilities is that an activity from some other app is on top of your task making you believe that your activity isn't there. Since, clearly it resumes to the last screen.
I suggest you to remove the single top temporarily and check the same.
2. Launcher modification
Has the launcher you use the standard launcher? Has the launcher or some other app modified the presentation or behavior of the recents screen (unlikely but worth a check)
For this, I suggest using a stock launcher or try the same app on a different phone or an emulator.
What would help is steps you followed and some screen shots of recents
screen and also of your app
I had the same problem.
The reason is that I had set android:label="" in manifest.xml.
I hadn't set android:launchMode="singleTop".
I declared on purpose android:label="" because I didn't find any better way to remove the title of the action bar from my main activity.
I turned android:label="app_name" again and everything now is OK; the app appears again in recent app list when pressing the home screen and doesn't start on the last navigated screen when restarting it.

Widgets not showing in Android 4.0+

I have a basic clock widget here, it works just fine on versions of android below 4.0, you can long press, select widgets and its right there. But when i try to run it on 4.0 or later emulator or real device, it does not show up in widgets section only in Settings>Storage>Apps. I have tried adding a simple activity that just gives users directions on how to install the widget , that suggestion was given as an answer here: Android 4.0: widgets not appearing? . Unless i did it wrong the widget still does not show up in widget drawer.
Here is my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.widgetexample1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".ExampleAppWidgetProvider"
android:label="8-bit cloud widget 1">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="#xml/widget1_info" />
</receiver>
</application>
</manifest>
add below in your manifest.xml.
"android:exported="true".
it might help.
try it.
In your widget metadata xml file check tag <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:xmlns attribute should start with http://.
It looks like you are being hit by a security upgrade which I think happened in HoneyComb.
Basically, in newer versions of Android, you cannot have your widget working, without first launching an Activity.
So add an activity to the project, run it first, and I think your widgets will update.
A good example would be to use a Settings style activity, or perhaps and About box type of thing, to tell the user a bit about your widget. (I use settings in my widgets).
For more info:
Android 4.0: widgets not appearing?

Categories

Resources