Xamarin.Android Firebase.Messaging - D/FirebaseInstanceId(13164): background sync failed: INVALID_SENDER - c#

I am adding push notifications to a Xamarin app in development.
After following guides I've done everything that should allow it to work.
google-services.json downloaded from firebase, added to project and build action set to GoogleServicesJson
play services is available as confirmed in a check
receiver node added to AndroidManifest.xml
FirebaseIIDService implemented
Notification channel is created
mainfest receiver code:
<application android:label="RMS Metro Calendar">
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
</application>
FirebaseIID code (I'm not implementing registration management on the server side):
[Service]
[IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
public class MyFirebaseIIDService : FirebaseInstanceIdService
{
const string TAG = "MyFirebaseIIDService";
public override void OnTokenRefresh()
{
var refreshedToken = FirebaseInstanceId.Instance.Token;
Log.Debug(TAG, "Refreshed token: " + refreshedToken);
SendRegistrationToServer(refreshedToken);
}
void SendRegistrationToServer(string token)
{
// Add custom implementation, as needed.
}
}
The app builds and deploys fine, I can sucessfully log out that Play services is available and in logging I get: FirebaseApp initialization successful
However it does not generate a Firebase instance and no Instance.Token is ever received. All I get is the following logging message:
09-19 13:48:31.576 D/FirebaseInstanceId(18578): background sync
failed: INVALID_SENDER, retry in 10s
from which is continues to retry in ever growing time scales.
I'm sure there must be something I've configured incorrectly somewhere with regards to the receiver/IID service implementation, but for the life of me cannot figure it out.
Has anyone else ever come across this? Is there a way I can test the FCM service for my configuration to get back more information on why it is failing?
Thank you!

Related

Unity3d 2020.3.10f1 and Android 10 - Want to access my GPX Files by reading them from the downloads folder

Please give advice, since it worked with Android 8. Running it on Android 10 device
results in "Access denied" as exception. Which permissions are needed to be requested, just to read the downloads folder and further read GPX, while it is not a native MIME Type.
Could you please send a short sample, how to set the proper Permission within Unity C# Script?
Thanks in advance,
Oliver
try
{
foreach (string file in System.IO.Directory.GetFiles("/storage/emulated/0/download"))
{
if (file.Substring(file.Length - 4).ToUpper() == ".GPX")
{
text.GetComponent<UnityEngine.UI.Text>().text += file + "\r\n";
}
}
text.GetComponent<UnityEngine.UI.Text>().text = "Place your GPX Files in here: \r\n" + "/storage/emulated/0/download";
}
catch (Exception e)
{
text.GetComponent<UnityEngine.UI.Text>().text = "Cannot access: " + e.Message.ToString();
}
Yes, thanks #blackapps. Thanks, Rene - https://www.udemy.com/user/rene-buhling/
Worked like a charm ... for Android 10 now ;)
I enabled a CUSTOM MAIN MANIFEST in the player settings
which results in activating Assets\Plugins\Android\AndroidManifest.xml
In there add the requestLegacyExternalStorage
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools">
<application android:requestLegacyExternalStorage="true">
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:theme="#style/UnityThemeSelector">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
</application>
Great day ... Thanks

Permission Denial: requires android.permission.READ_PHONE_STATE

I'm trying to detect phone calls in my android app but I receive the following message when receiving a call:
08-23 15:16:04.685 Vodafone VFD 600 Warning 850 BroadcastQueue Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x10 (has extras) } to com....LogCalls requires android.permission.READ_PHONE_STATE due to sender android (uid 1000)
08-23 15:16:04.549 Vodafone VFD 600 Warning 850 BroadcastQueue Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x10 (has extras) } to com....LogCalls requires android.permission.READ_PRIVILEGED_PHONE_STATE due to sender android (uid 1000)
My AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com...." android:installLocation="preferExternal">
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="27" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<application android:label="myapp" android:icon="#drawable/logo">
</application>
</manifest>
And my broadcast receiver:
[BroadcastReceiver]
[IntentFilter(new[] {TelephonyManager.ActionPhoneStateChanged,Intent.ActionNewOutgoingCall })]
public class LogCalls : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
if (intent.Action == TelephonyManager.ActionPhoneStateChanged)
{
Console.WriteLine("state changed");
}
}
}
What I am missing ?
Firstly, third-party apps are not permitted to acquire the READ_PRIVILEGED_PHONE_STATE permission. See Privileged Permission Whitelisting:
Privileged applications are system applications located in the /system/priv-app directory on the system image. Historically, device implementers had little control over which signature|privileged permissions could be granted to privileged apps. Starting in Android 8.0, implementors can explicitly whitelist privileged apps in the system configuration XML files in the /etc/permissions directory. Apps not explicitly listed in these XML files are not granted privileged permissions.
Secondly, when your app is running on API 23 and above, you'll need to first ask the user to grant you the READ_PHONE_STATE permission at runtime, as it is considered a "dangerous" permission (see Permissions Overview).
You'll need to follow the instructions at Request App Permissions to request the permission from the user at runtime, and only once that permission is granted can your BroadcastReceiver receive the intents.

Unity not opening plugin activity, package seems incorrect

I am attempting to use this plugin to open an android image picker, however it errors when launched.
The calling script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using LukeWaffel.AndroidGallery;
public class LoadImageWithMagic : MonoBehaviour {
public Image image;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void OpenGallery() {
Debug.Log ("It clicked");
AndroidGallery.Instance.OpenGallery (GalleryCallback);
}
public void GalleryCallback() {
image.material.mainTexture = AndroidGallery.Instance.GetTexture ();
AndroidGallery.Instance.ResetOutput ();
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"/>
<application
android:theme="#style/UnityThemeSelector"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:debuggable="true">
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<activity android:name= "com.lukewaffel.androidgallery.Gallery"></activity>
</application>
</manifest>
Error from logcat:
08-25 09:53:09.029 3458-3474/com.TNOAB.FindMyPet I/Unity: It clicked
(Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
08-25 09:53:09.036 3458-3474/com.TNOAB.FindMyPet I/Unity: [Singleton] An instance of LukeWaffel.AndroidGallery.AndroidGallery is needed in the scene, so '(singleton) LukeWaffel.AndroidGallery.AndroidGallery (UnityEngine.GameObject)' was created with DontDestroyOnLoad.
(Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
08-25 09:53:09.060 1485-1737/system_process I/ActivityManager: START u0 {cmp=com.TNOAB.FindMyPet/com.lukewaffel.androidgallery.Gallery} from uid 10061 on display 0
08-25 09:53:09.082 3458-3474/com.TNOAB.FindMyPet I/Unity: AndroidJavaException: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.TNOAB.FindMyPet/com.lukewaffel.androidgallery.Gallery}; have you declared this activity in your AndroidManifest.xml?
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.TNOAB.FindMyPet/com.lukewaffel.androidgallery.Gallery}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1777)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501)
at android.app.Activity.startActivityForResult(Activity.java:3745)
at android.app.Activity.startActivityForResult(Activity.java:3706)
at android.app.Activity.startActivity(Activity.java:4016)
at android.app.Activity.startActivity(Activity.java:3984)
at com.lukewaffel.androidgallery.UnityBinder.OpenGallery(UnityBinder.java:12)
at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
at com.unity3d.player.UnityPlayer.c
It appears that the issue is Unity is prepending my package to the package of the plugin, causing it to not be found. I have attempted to change my package to the package of the plugin and it still had the same error.
I have tried reinstalling the app and still cannot get the gallery to open.
I have discovered that the issue was all of the plugin files were placed into a subdirectory, so unity could not find the AndroidManifest.xml. After moving all of the items out of the subdirectory, the Gallery opened.
As a note to anyone copying the above code, I then discovered an unrelated error, image.material.mainTexture = AndroidGallery.Instance.GetTexture (); should be image.sprite = AndroidGallery.Instance.GetSprite ();

Stateless Web API service with HTTPS endpoint throws health state error

I want a https endpoint for my in a local service fabric (GA version) cluster hosted stateless Web API service. After achieving that, I want to deploy my cluster in Azure.
I followed the steps in the "Secure a Service Fabric cluster" article of the service fabric documentation and created a self-signed certificate and uploaded it to my key vault. I also imported my certificate to my machine's "trusted people" store with the Import-PfxCertificate commands on step 2.5.
AddCertToKeyVault:
Invoke-AddCertToKeyVault -SubscriptionId <Id> -ResourceGroupName 'ResourceGroupName' -Location 'West Europe' -VaultName 'VaultName' -CertificateName 'TestCert' -Password '****' -CreateSelfSignedCertificate -DnsName 'www.<clustername>.westeurope.cloudapp.azure.com' -OutputPath 'C:\MyCertificates'
Now I adjusted the ServiceManifest.xml, ApplicationManifest.xml (like in RunAs: Run a Service Fabric application with different security permissions) and my OwinCommunicationListener.cs:
ServiceManifest.xml (MasterDataServiceWebApi):
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="MasterDataServiceWebApiPkg"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<StatelessServiceType ServiceTypeName="MasterDataServiceWebApiType" />
</ServiceTypes>
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>MasterDataServiceWebApi.exe</Program>
</ExeHost>
</EntryPoint>
</CodePackage>
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<Endpoint Name="ServiceEndpoint" Type="Input" Protocol="https" Port="5030" CertificateRef="TestCert"/>
</Endpoints>
</Resources>
</ServiceManifest>
ApplicationManifest:
<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="exCHANGETestCluster2Type" ApplicationTypeVersion="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="MasterDataServiceWebApi_InstanceCount" DefaultValue="-1" />
</Parameters>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="MasterDataServiceWebApiPkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
<Policies>
<EndpointBindingPolicy EndpointRef="ServiceEndpoint" CertificateRef="TestCert" />
</Policies>
</ServiceManifestImport>
<DefaultServices>
<Service Name="MasterDataServiceWebApi">
<StatelessService ServiceTypeName="MasterDataServiceWebApiType" InstanceCount="[MasterDataServiceWebApi_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
</DefaultServices>
<Certificates>
<EndpointCertificate X509FindValue="<Thumbprint>" Name="TestCert" />
</Certificates>
</ApplicationManifest>
OwinCommunicationListener.cs:
[...]
public Task<string> OpenAsync(CancellationToken cancellationToken)
{
var serviceEndpoint = this.serviceContext.CodePackageActivationContext.GetEndpoint(this.endpointName);
int port = serviceEndpoint.Port; //NEW!
if (this.serviceContext is StatefulServiceContext)
{
[...]
}
else if (this.serviceContext is StatelessServiceContext)
{
var protocol = serviceEndpoint.Protocol;
this.listeningAddress = string.Format(
CultureInfo.InvariantCulture,
//"http://+:{0}/{1}",
"{0}://+:{1}/{2}", //NEW!
protocol,
port,
string.IsNullOrWhiteSpace(this.appRoot)
? string.Empty
: this.appRoot.TrimEnd('/') + '/');
}
else
{
throw new InvalidOperationException();
}
[...]
When I deploy the stateless service to my local cluster now, my service fabric explorer reports some very "expressive" errors and I am not able to access my service:
Kind Health State Description
=============================================================================
Services Error Unhealthy services: 100% (1/1), ServiceType='MasterDataServiceWebApiType', MaxPercentUnhealthyServices=0%.
Service Error Unhealthy service: ServiceName='fabric:/sfCluster/MasterDataServiceWebApi', AggregatedHealthState='Error'.
Partitions Error Unhealthy partitions: 100% (1/1), MaxPercentUnhealthyPartitionsPerService=0%.
Partition Error Unhealthy partition: PartitionId='e5635b85-3c23-426b-bd12-13ae56796f23', AggregatedHealthState='Error'.
Event Error Error event: SourceId='System.FM', Property='State'. Partition is below target replica or instance count.
Visual Studio isn't providing me with any further error details. It's quite the opposite. The stacktrace prints: fabric:/sfCluster/MasterDataServiceWebApi is ready.
What did I miss? Did I configured something wrong?
BTW: After that, I created a new cluster in Azure with my self-signed certificate, but when I try to acess the Service Fabric Explorer of this cluster I have no UI and a blank site..
I have learned, that Service Fabric uses the local machine store for the certificate validation. (https://github.com/Azure-Samples/service-fabric-dotnet-web-reference-app/issues/3)
So I had to import the certificate into my local machine store by this slightly modified powershell-script:
Import-PfxCertificate -Exportable -CertStoreLocation cert:\localMachine\my -FilePath C:\MyCertificates\TestCert.pfx -Password (Read-Host -AsSecureString -Prompt "Enter Certificate Password")
Before that, I imported my certificate into Cert:\CurrentUser\TrustedPeople and Cert:\CurrentUser\My. But the local Service Fabric cluster doesn't look up there.
BTW:
I still get a blank site, when I try to access the Service Fabric Explorer of my azure-hosted Service Fabric cluster, that I have secured with the same certification key. I will create another question for this problem. EDIT: Using the Internet Explorer instead of Firefox solved my blank site issue.

How can I get WCF Routing to give me a more detailed error message than - No matching MessageFilter?

Is there a way to configure WCF Routing so that if your filters don't match you can get more information about the message that could not be routed?
Currently we're using AppFabric and we only get the following message.
This message is not very helpful when trying to figure out which message did not match a filter.
No matching MessageFilter was found for the given Message.
this is not the best solution, I have been experimenting a way to verify that a routing service is working as configured, but haven't found the best way yet.
But one way is to provide a match all filter, and have a service which accepts all requests and logs it, and returns a 404 back to the client
<routing>
<filters>
<filter name="Other" filterType="MatchAll" />
<filter name="action1" filterType="Action" filterData="http://tempuri.org/action2" />
<filter name="action2" filterType="Action" filterData="http://tempuri.org/action1" />
</filters>
<filterTables>
<filterTable name="FilterTable">
<add filterName="action1" endpointName="Service1" priority="1" />
<add filterName="action2" endpointName="Service2" priority="1" />
<add filterName="Other" endpointName="Logger" priority="0" />
</filterTable>
</filterTables>
</routing>
The Logger end point simply points to a simple service which accepts a Message and logs it, and returns a 404
some psudo code:
[ServiceBehavior]
public class RoutingLogger : IYourInterface
{
public System.ServiceModel.Channels.Message YourInterfaceMethod(System.ServiceModel.Channels.Message message)
{
LogMessage(message);
return new Custom404Message();
}
}

Categories