Android O - Accessibility service - fingerprint gesture callback - accessibility

I'm trying to use the new fingerprint gesture callback from android O.
I've declared these in the manifest
<uses-feature android:name="android.hardware.fingerprint"/>
<uses-permission android:name="android.permission.USE_FINGERPRINT"/>
My accessibility service xml looks like this:
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:description="#string/accessibility_service_description"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFlags="flagRequestFingerprintGestures"
android:accessibilityFeedbackType="feedbackAllMask"
android:notificationTimeout="100"
android:canRetrieveWindowContent="false"
android:canRequestEnhancedWebAccessibility="false"
android:settingsActivity="com.example.finger.MainActivity"/>
..and then in the accessibility service onServiceConnected method I'm trying to register a callback with the following
FingerprintGestureController.FingerprintGestureCallback callback = new
FingerprintGestureController.FingerprintGestureCallback(){
#Override
public void onGestureDetectionAvailabilityChanged(boolean available) {
LogUtil.d("available: " + available);
super.onGestureDetectionAvailabilityChanged(available);
}
#Override
public void onGestureDetected(int gesture) {
LogUtil.d("gesture: " + gesture);
super.onGestureDetected(gesture);
}
};
FingerprintGestureController controller =
this.getFingerprintGestureController();
controller.registerFingerprintGestureCallback(callback, null);
The accessibility service registers fine and the code above to register the callback gets called ok, but I never get a call to the onGestureDetectionAvailabilityChanged and onGestureDetected
The documentation around it is somewhat lacking so I'm not sure what else I need to be able to get the callback working.

You need to add android:canRequestFingerprintGestures="true" to the xml file

Related

Cancel Navigating event in Xamarin Forms webview

I'm trying to open tel links in my xamarin forms application webview using the Navigating event:
public async void WebViewNavigating(object sender, WebNavigatedEventArgs args)
{
if (args.Url.StartsWith("tel:"))
{
await Xamarin.Essentials.Launcher.OpenAsync(args.Url);
}
}
But I have two issues, first on IOS it gives an error 500 and next in Android as the navigation is not cancelled, I have a not found error and going back to the app after the call.
I read that args.cancel=true is the way to go but the variable doesn't seem to exist no more.
At first, you can use the Xamarin.Essentials: Phone Dialer to open the telephone number. Furthermore you need to test on the physical device for the ios, because the ios simulator can't call number and will throw an exception.
Open the AndroidManifest.xml file under the Properties folder and add the following inside of the manifest node:
<queries>
<intent>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel"/>
</intent>
</queries>
Use the following code:
public void WebViewNavigating(object sender, WebNavigatingEventArgs args)
{
if (args.Url.StartsWith("tel:"))
{
string number = args.Url.Split(':')[1];
Xamarin.Essentials.PhoneDialer.Open(number);
args.Cancel = true;
}
}
In adition, you can also use the custom renderer to do that, for more information, you can check my answer in this case.

How ImageSharp work with Asp.Net Mvc Controller

How ImageSharp work with Dynamic Images loaded from Database?
Here my controller which get image file:
public async Task<FileResult> GetPhoto([FromQuery] GetFileAttachementInputAsync input)
{
var file = await filesAttachementAppService
.GetFileAsync(new GetFileAttachementInputAsync() { FileId = input.FileId })
.ConfigureAwait(false);
return file != null
? File(new MemoryStream(file.FileDto.FileContent), file.FileDto.ContentType, file.FileDto.FileName)
: null;
}
And this my Html call:
<img src="/PropertyAdministration/GetPhoto?FileId=#item.MainPhotoId&width=554&height=360" alt="" />
I am using ImageSharp as following:
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddImageSharp();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env,ILoggerFactory loggerFactory)
{
app.UseImageSharp();
}
What I am missing here to make this working?
You're not using the middleware nor the services that provide images to the middleware.
For the middleware to work it needs to be able capture an image request. With the default installation this is done by matching the request to an image source in your physical file system in wwwroot.
In your code though you've created an isolated action result returning a stream containing your image which the middleware has no awareness of.
Disclaimer, the following is based on the latest developer build 1.0.0-dev000131 and though unlikely to change could potentially change before final release.
https://www.myget.org/feed/sixlabors/package/nuget/SixLabors.ImageSharp.Web/1.0.0-dev000131
In order to provide images from a custom source you will need to create your own implementation of the IImageProvider and IImageResolver you can use examples in the source to base your implementation from.
Once implemented you will need to register the implementations via dependency injection. This needs to use a more fine grained registration since you are no longer using the defaults.
// Fine-grain control adding the default options and configure all other services. Setting all services is required.
services.AddImageSharpCore()
.SetRequestParser<QueryCollectionRequestParser>()
.SetBufferManager<PooledBufferManager>()
.SetMemoryAllocatorFromMiddlewareOptions()
.SetCacheHash<CacheHash>()
.AddProvider<PhysicalFileSystemProvider>()
/// Add your provider here via AddProvider<T>().
.AddProvider<PhysicalFileSystemProvider>()
.AddProcessor<ResizeWebProcessor>()
.AddProcessor<FormatWebProcessor>()
.AddProcessor<BackgroundColorWebProcessor>();
You should then be able to remove your action result completely and use the IImageProvider and IImageResolver combination to identify the request and return the image.

Firebase Dynamic Links on Android do not survive installation process

My question is similar to this recent question for iOS.
Firebase Dynamic links work as expected on a device with the app already existing, but I fail to get a referral when I install the app (currently in the beta channel) from the Play Store.
Specifically, AppInviteReferral.hasReferral(getIntent()) returns false when the app is installed from the PlayStore beta channel.
According to the linked answer, Dynamic Links work most of the time, but there may be undocumented edge cases that will cause it to fail. I'll highlight what is specific to my case, so you might help me find what's missing in my setup.
I only just updated my Firebase libraries to 10.2.6 from 10.2.4. There was no change to the Firebase Invites library in the changelog.
If it matters, here's the order in which I include the libraries
compile 'com.google.firebase:firebase-core:10.2.6'
compile 'com.google.firebase:firebase-messaging:10.2.6'
compile 'com.google.firebase:firebase-auth:10.2.6'
compile 'com.google.firebase:firebase-database:10.2.6'
compile 'com.google.firebase:firebase-invites:10.2.6'
My SplashScreenActivity.java serves as both the launcher activity, and the activity that accepts and handles deeplinks. Here's the activity declaration in the AndroidManifest
<activity
android:name=".ui.setup.SplashScreenActivity"
android:label="#string/app_name"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="https"
android:host="deeplinks.myCompanyDomain.com"
android:pathPrefix="/mobile"/>
</intent-filter>
</activity>
SplashScreenActivity.java does not setContentView(int id). It just uses a theme to display the splash screen while the rest of the app's resources "load". I don't know if this matters, but I'm putting it out there.
Before anything starts on the app, I check to make sure the app has the needed permissions. A continueIntoApp() method (I couldn't think of a better name) takes the user into the app when it finds it has the needed permissions, or after the user grants the app all four permissions it needs.
continueIntoApp() is where all the code found on the Firebase Dynamic Links Docs is implemented. I first build and connect a GoogleApiClient.
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
LogUtils.e("Deeplink connection failed");
LogUtils.e(connectionResult.getErrorMessage());
LogUtils.e(String.valueOf(connectionResult.getErrorCode()));
}
})
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
#Override
public void onConnected(#Nullable Bundle bundle) {
LogUtils.d("Connected!");
}
#Override
public void onConnectionSuspended(int i) {
LogUtils.e("Connection suspended!");
}
})
.addApi(AppInvite.API)
.build();
googleApiClient.connect();
Just as an aside, the Dynamic Links docs assume the developer already knows how to setup a GoogleApiClient. I didn't. After a few frustrating days, I accidentally found the #connect() method that actually got the GoogleApiClient doing what it was supposed to do.
After this, I check if the AppInviteReferral has a referral.
//boolean autoLaunchDeepLink = true;
if(AppInviteReferral.hasReferral(getIntent())){
LogUtils.d("Referral found!");
AppInvite.AppInviteApi.getInvitation(googleApiClient, SplashScreenActivity.this, true)
.setResultCallback(new ResultCallback<AppInviteInvitationResult>() {
#Override
public void onResult(#NonNull AppInviteInvitationResult appInviteInvitationResult) {
LogUtils.d("Processing appInviteInvitationResult...");
if(appInviteInvitationResult.getStatus().isSuccess()){
Intent intent = appInviteInvitationResult.getInvitationIntent();
String deepLink = AppInviteReferral.getDeepLink(intent);
LogUtils.d("Deeplink is " + deepLink);
AppConfig appConfig = new AppConfig(SplashScreenActivity.this);
appConfig.put(ModelKeys.TEMP_JOIN_BRANCH_DEEPLINK, deepLink);
startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
//parseDeeplink(deepLink);
}else {
LogUtils.d("No deeplink found!");
startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
}
}
});
}else {
LogUtils.d("No referral found!");
startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
}
You will notice I have commented out autoLaunchDeepLink and, by default, pass true to AppInvite.AppInviteApi.getInvitation(). I'm still not sure when I should set this value to true or false. I also don't know how, after a fresh installation from a Dynamic Link (with autoLaunchDeepLink as false), Firebase knows how to "start the dynamic link".
That's as far as the Dynamic Links implementation goes. My problem is as stated above: when I have the app already installed, AppInviteReferral.hasReferral(getIntent()) returns true , and the code runs as normal. When the user follows the Dynamic Link to the PlayStore and downloads the beta release, AppInviteReferral.hasReferral(getIntent()) returns false, and the deeplink is not followed.
Why is this happening? What am I missing?
I don't think you're missing anything - it does seem like the Play Store doesn't send INSTALL_REFERRER broadcasts for the Beta channel installs, and its that referrer which is used as the mechanism for passing the deeplink post-install.
It should work OK if you're using a product app, but it is a little curious that the beta installs don't support that.
Had the same issue. Our problem was that we had two intent-filters almost similar in the AndroidManifest.xml, which caused the Google Play to lose the intent we wanted. Instead of showing "Continue" button it redirected us to uninstall/open page on the play.
Suggesting to work with
https://firebase.google.com/docs/dynamic-links/android/receive

Solution for BLE scan's SCAN_FAILED_APPLICATION_REGISTRATION_FAILED?

My Android app scans BLE devices, and from a certain point it start to fails with error code 2 (ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED). I'm using Nexus 9, 5.0.1 Lollipop.
This problem continued even after I relaunched the app, and when I restarted the Bluetooth service from Settings, I could finally get rid of the problem. But this problem is recurring, and I think I'm coding in a wrong way; BLE related APIs are new and there is few information.
Does anyone know a general solution for this error, preferably not requiring restart of the Bluetooth service? Even though this error code is documented in Android API reference, I don't know how to handle it properly.
When you got the error
SCAN_FAILED_APPLICATION_REGISTRATION_FAILED
You should disable the BluetoothAdapter
BluetoothAdapter.getDefaultAdapter().disable();
Disabling BluetoothAdapter, the event STATE_TURNING_OFF is fired. Once this event is fired, try to reconnect to the BluetoothAdapter:
case BluetoothAdapter.STATE_OFF:
Log.d(TAG, "bluetooth adapter turned off");
handler.postDelayed(new Runnable() {
#Override
public void run() {
Log.d(TAG, "bluetooth adapter try to enable");
BluetoothAdapter.getDefaultAdapter().enable();
}}, 500);
break;
It turns out that Bluetooth LE requires the following Android application permissions in AndroidManifest.xml:
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!--BLE scanning is commonly used to determine a user's location with Bluetooth LE beacons. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- if your app targets API level 21 or higher. -->
<uses-feature android:name="android.hardware.location.gps" />
<!--app is available to BLE-capable devices only. -->
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
Besides on main activity:
// onResume()
if (ContextCompat.checkSelfPermission(this.getApplicationContext(),
android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
} else {
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
REQUEST_LOCATION_ENABLE_CODE);
}
You should perform operations only success initialization of BT adapter.
To be sure that it is ready create intent filter:
val filter = IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)
and broadcast receiver(you will perform action only if adapter is ready):
val broadcastReceiver = object: BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent?) {
val action = intent?.action
if (action != null && action == BluetoothAdapter.ACTION_STATE_CHANGED) {
val state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)
when (state) {
BluetoothAdapter.STATE_ON -> {
if (bluetoothAdapter.isEnabled) {
//perform your task here
}
}
BluetoothAdapter.STATE_OFF -> {}
}
}
}
}
then register receiver:
registerReceiver(broadcastReceiver, filter)
and relaunch adapter(this part can be replaces with check):
bluetoothAdapter.disable()
bluetoothAdapter.enable()
DONE!
I had this happen to me today. While manually disabling and then enabling BT in the Android Settings did not fix this, I was able to get it working after only disabling it manually and then have the app that is affected by the issue enable BT.
The app then pops up an Android System message "An app is requesting permission to turn on BT" (I have a German UI, so it may be worded differently), and when I then press allow, the app finally has proper access to BT and this error no longer shows.
Sounds like a bug or something.

Exception Logging for WCF Services using ELMAH

We are using the excellent ELMAH to deal with unhandled exceptions in an ASP.NET 3.5 web application. This works extremely well for all of the site apart from WCF services which are being consumed using the REST features. When an exception occurs within the operation methods that is not handled by the application code, WCF handles it in various ways depending on the service contracts and configuration settings. This means that the exception does not end up firing the ASP.NET HttpApplication.Error event that ELMAH uses. The two solutions I am aware of to deal with this are:
Wrap all method calls in a try { } catch(Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); throw; } to explicitly call Elmah within the catch block.
Use IErrorHandler as described in Will Hughes' blog post Making WCF and ELMAH play nice together to factor out the call to ELMAH to a separate ErrorHandler.
The first option is extremely simple but is not exactly DRY. The second option only requires you to decorate each service with the custom attribute after implementing the attribute and the ErrorHandler. I have done this based on Will's work but I want to verify that this is the correct approach before posting the code.
Is there a better way that I have missed?
The MSDN documenation for IErrorHandler says that the HandleError method is the place to do the logging but ELMAH accesses the HttpContext.Current.ApplicationInstance, which is null within this method even though HttpContext.Current is available. Making the call to Elmah within the ProvideFault method is a workaround as ApplicationInstance is set but this does not match the intent described in the API documentation. Am I missing something here? The documentation does state that you should not rely on the HandleError method being called on the operation thread which may be why ApplicationInstance is null in this scope.
The solution from my blog post (referenced in the OP) was based on an existing solution we were/are using to alter HTTP Response Codes during an error state.
So, for us it was a one-line change to pass the Exception to ELMAH. If there's a better solution, I'd love to know about it too.
For Posterity/Reference, and potential improvement - here's the code from the current solution.
HttpErrorHandler and ServiceErrorBehaviourAttribute Classes
using System;
using System.ServiceModel;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Collections.ObjectModel;
using System.Net;
using System.Web;
using Elmah;
namespace YourApplication
{
/// <summary>
/// Your handler to actually tell ELMAH about the problem.
/// </summary>
public class HttpErrorHandler : IErrorHandler
{
public bool HandleError(Exception error)
{
return false;
}
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
if (error != null ) // Notify ELMAH of the exception.
{
if (System.Web.HttpContext.Current == null)
return;
Elmah.ErrorSignal.FromCurrentContext().Raise(error);
}
}
}
/// <summary>
/// So we can decorate Services with the [ServiceErrorBehaviour(typeof(HttpErrorHandler))]
/// ...and errors reported to ELMAH
/// </summary>
public class ServiceErrorBehaviourAttribute : Attribute, IServiceBehavior
{
Type errorHandlerType;
public ServiceErrorBehaviourAttribute(Type errorHandlerType)
{
this.errorHandlerType = errorHandlerType;
}
public void Validate(ServiceDescription description, ServiceHostBase serviceHostBase)
{
}
public void AddBindingParameters(ServiceDescription description, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection parameters)
{
}
public void ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase)
{
IErrorHandler errorHandler;
errorHandler = (IErrorHandler)Activator.CreateInstance(errorHandlerType);
foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
{
ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
channelDispatcher.ErrorHandlers.Add(errorHandler);
}
}
}
}
Usage Example
Decorate your WCF Services with the ServiceErrorBehaviour Attribute:
[ServiceContract(Namespace = "http://example.com/api/v1.0/")]
[ServiceErrorBehaviour(typeof(HttpErrorHandler))]
public class MyServiceService
{
// ...
}
When creating a BehaviorExtensionElement it is even possible to activate the behavior using config:
public class ErrorBehaviorExtensionElement : BehaviorExtensionElement
{
public override Type BehaviorType
{
get { return typeof(ServiceErrorBehaviourAttribute); }
}
protected override object CreateBehavior()
{
return new ServiceErrorBehaviourAttribute(typeof(HttpErrorHandler));
}
}
Config:
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="elmah" type="Namespace.ErrorBehaviorExtensionElement, YourAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
<behaviors>
<serviceBehaviors>
<behavior>
<elmah />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
That way it is also possible to use ELMAH in combination with RIA services!
This may well be obvious to some people but I just spent quite a while trying to figure out why my HttpContext.Current was null despite following all of Will Hughes' excellent answer. Embarassingly, I realised that this was because my WCF service is activated by a MSMQ message.
I ended up rewriting the ProvideFault() method:
if (HttpContext.Current == null)
{
ErrorLog.GetDefault(null).Log(new Error(error));
}
else
{
ErrorSignal.FromCurrentContext().Raise(error);
}
I have done this based on Will's work
but I want to verify that this is the
correct approach before posting the
code.
I think this is a great approach (kudos to Will for this posting!). I don't think Will or you have missed anything here. Implementing IErrorHandler is the preferred way of capturing all possible server-side exceptions that could otherwise cause the communication channel to be faulted (torn down) and thus it's a natural place to hook in some logging like ELMAH.
Marc
I was unable to get the proposed answer working with a WCF Data Service. I wired up the behavior attribute, etc, but still did not get any errors logged. Instead, I ended up adding the following to the service implementation:
protected override void HandleException(HandleExceptionArgs args)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(args.Exception);
base.HandleException(args);
}
I haven't tried doing this explicitly with the REST stuff, and haven't used ELMAH myself, but another option worth looking into might be to hook into WCF using an IDispatchMessageInspector instead of an IErrorHandler.

Resources