Android Accessibility Service stopped working after a day or two on Oreo - accessibilityservice

Background:
I have a class which extends from AccessibilityService. Whenever a window is changed following function is called which gives me the application name of the foreground application.
#Override
public void onAccessibilityEvent(AccessibilityEvent event) {
}
Following is the configuration I set:
#Override
protected void onServiceConnected() {
super.onServiceConnected();
//Configure these here for compatibility with API 13 and below.
AccessibilityServiceInfo config = new AccessibilityServiceInfo();
config.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
config.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
if (Build.VERSION.SDK_INT >= 16) { //Just in case this helps
config.flags = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
}
setServiceInfo(config);
}
AccessibilityService.xml
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
xmlns:android="http://schemas.android.com/apk/res/android"
android:description="#string/accessibility_explanation"
android:accessibilityEventTypes="typeWindowStateChanged|typeAllMask"
android:accessibilityFeedbackType="feedbackSpoken|feedbackHaptic|feedbackAudible|feedbackVisual|feedbackGeneric|feedbackAllMask"
android:notificationTimeout="100" android:canRetrieveWindowContent="true" />
The Problem:
It works fine for some time, but after a day or two it suddenly stops working. It doesn't call the onAccessibilityEvent(AccessibilityEvent event) function. Although the accessibility service of this application is enabled but still it doesn't show the application name when window is changed.
May be it doesn't work if the application comes back from sleep mode? I had to reinstall the application on top of my debug build and then again it started working but for how long.
Question: How can I make sure it always return me the application name when window is changed?

Just restart your app. This is because Accessibility Service is managed by the Android OS, so if any thing causes your service to crash, it will be killed and rescheduled to be started at some time in the fture that you can not control. So it is possible that your service has been killed.

Related

UWP: Can't load and show Interstitial video ad

I'm trying to monetize my app with Universal Windows. I followed the official tutorials but when I tried to load an interstitial ad, always I'm getting this errors:
Interstitial ad is not ready. With this error code: ClientConfiguration.
Failed to make http requestError. With this error code: NetworkConnectionFailure.
I don't know what I am missing.
This is my code:
public sealed partial class Myclass: Page {
InterstitialAd MyVideoAd;
public MyClass() {
this.InitializeComponent();
var MyAppId = "d25517cb-12d4-4699-8bdc-52040c712cab";
var MyAdUnitId = "11389925";
MyVideoAd = new InterstitialAd();
MyVideoAd.ErrorOccurred += MyVideoAd_ErrorOccurred;
MyVideoAd.RequestAd(AdType.Video, MyAppId, MyAdUnitId);
}
private void MyVideoAd_ErrorOccurred(object sender, AdErrorEventArgs e) {
String errrorMessage = e.ErrorMessage;
String errorCode = e.ErrorCode;
}
private void showInterstitial(object sender, TappedRoutedEventArgs e) {
MyVideoAd.Show();
}
}
When I execute the application, a few seconds after the MyVideoAd_ErrorOccurred method is launched with the values of errorMessage and errorCode as I've said. That happens on my Windows 10 mobile device and in the Desktop machine execution. The codes of adUnit and application id are the provided in the Microsoft page for tests.
I hope that you can help me.
For UWP app, please install Microsoft Universal Ad Client SDK and use AdMediatorControl.
References:
Install the Universal Ad Client SDK
Add and use the ad mediator control
Check my sample: https://github.com/Myfreedom614/UWP-Samples/tree/master/AdClientUWPApp
Be sure to have these 3 Capabilities defined inside your manifest:
<Capabilities>
...
<Capability Name="internetClient"/>
<Capability Name="internetClientServer"/>
<Capability Name="privateNetworkClientServer"/>
...
</Capabilities>
The video hasn't finished loading. you need to give it enough time for that. also you need to make sure it is loaded before calling it with.
if ((InterstitialAdState.Ready) == (MyVideoAd.State))
{
MyVideoAd.Show();
}

How to prevent multiple instances of Windows 10 XAML applications?

I'm working on a Windows 10 app. One of the new features of Windows 10 apps is the ability of multiple instances (windows) of the same app. I want to disable this. Has anyone found documentation regarding this scenario?
You can override method OnLaunch in App.xaml.cs :
protected async override void OnLaunched(LaunchActivatedEventArgs e)
{
if (e.PreviousExecutionState != ApplicationExecutionState.Running) //Check if is there any instance of the App is already running
{
base.OnLaunched(e);
}
}
Check out this Instancing property in manifest file.
Instancing

OnConnected not firing when deployed despite correct client binding

I've scoured the site, coming across SignalR OnConnected and OnDisconnected not firing and similar, but the solution does not apply in my case. I already do have the client methods registered.
Additionally, the OnConnected method of my hub does fire when running on my local box. It simply does not fire when deployed. All other methods work fine, however. For the present, I've created a work-around as such:
<script>
$(function () {
var myHub = $.connection.myHub;
myHub.client.clientMessage = function (message) { alert(message); };
// Start the connection.
$.connection.hub.start().done(function () {
myHub.server.superfluousMethodToDoSameThingInOnConnect();
});
});
</script>
I would really like to stop using this second call, however, and simply have OnConnected work properly as it should. What is necessary on my deployment server to have it work the same?
For reference, my SignalR is version 1.2.2 (limited to .NET 4.0, for now) incorporated into an MVC site (with no errors, otherwise).
My dev box is Windows 7 hosting in IIS Express 8.5
The deployment box is Winows Server 2003 hosting in IIS V6.0.
Edit 1: I've included a
myHub.connection.stateChanged(function (change) { alert("State: " + change.newState); });
for debugging, and when the page loads, it displays popup of "State: 0" followed by a popup of "State: 1" a short time later, and a "State: 4" when I leave the page, so it looks like my connection itself is behaving correctly. This functions the same both locally and on the deploy server.
Edit 2: To test further, I have updated the methods in the hub as below:
public override Task OnConnected()
{
Groups.Add(Context.ConnectionId, Context.User.Identity.Name);
Clients.All.clientMessage("OnConnected:: ID: " + Context.ConnectionId + " USER: " + Context.User.Identity.Name);
return base.OnConnected();
}
public void SuperfluousMethodToDoSameThingInOnConnect()
{
Clients.All.clientMessage("SuperfluousMethodToDoSameThingInOnConnect:: ID: " + Context.ConnectionId + " USER: " + Context.User.Identity.Name);
}
Results of this testing show that only the text sent from SuperfluousMethodToDoSameThingInOnConnect is shown back to the Caller. However, other clients (tested in other browser windows) see both the text from OnConnected and SuperfluousMethodToDoSameThingInOnConnect.
Additionally, when I try to send a message back to the caller using Context.Groups(Context.User.Identity.Name) then the message is not sent. However, if I move the group registration line Groups.Add(Context.ConnectionId, Context.User.Identity.Name) from OnConnected into SuperfluousMethodToDoSameThingInOnConnect, then messages can be sent using Groups.Add(Context.ConnectionId, Context.User.Identity.Name). This seems extremely bizarre, as I can see that the OnConnected method is called, but the Group is not really registered?
Really at a loss for anything to explain this erratic behavior.
Edit 3: Pushed the web app out to a Windows Server 2012 VM, where I found it works correctly, same as my local dev box. Is it that SignalR does not fully work on IIS 6?
As per 'Supported server IIS versions' in the http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/supported-platforms only IIS7 or newer are supported.

Smooth Streaming SDK for Windows 8 - Error with Headphones Plugged

I'm doing some tests with the Smooth Streaming Client SDK for Windows 8, and I have a very basic application playing a fullscreen video:
private MediaExtensionManager extensions = new MediaExtensionManager();
public MainPage()
{
this.InitializeComponent();
extensions.RegisterByteStreamHandler("Microsoft.Media.AdaptiveStreaming.SmoothByteStreamHandler", ".ism", "text/xml");
extensions.RegisterByteStreamHandler("Microsoft.Media.AdaptiveStreaming.SmoothByteStreamHandler", ".ism", "application/vnd.ms-sstr+xml");
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string url = "http://my.smooth.streaming.url/manifest";
this.slPlayer.Source = new Uri(url);
this.slPlayer.Play();
}
This seems to be working fine, unless I plug my headphones, at which point the application stops working. Adding a handler for the MediaFailed event informs I'm getting a MF_MEDIA_ENGINE_ERR_SRC_NOT_SUPPORTED error.
Any idea what may be causing this?
Badaro, I just tried this and was not able to repro the problem (on both x86 & x64, both starting with and without headphones and switching during playback). My guess is that you are either:
1) running into a driver issue.
2) there is something specific about the way your stream is encoded that causes this.
I suggest ruling out #1 by trying on a few different machines.
or, rule out #2 by trying the sample smooth SDK stream: http://mediadl.microsoft.com/mediadl/iisnet/smoothmedia/Experience/BigBuckBunny_720p.ism/Manifest

SignalR WPF Client can't reach hub deployed on IIS when IIS runs on a different system

I just play a little bit with signalR. My application has only one simple hub which is stored in an ASP.NET Application and I wrote a WPF client, which interacts via the hubconnection and the created proxy with the ASP.NET Application. Everything works fine on my local PC. I deployed the ASP.NET Application on IIS.
Now I am getting to the point...
When I type the following into my browser on my own PC (pcthi-and)
http://pcthi-and:8080/signalr/hubs
I'll get what I want
When I type the same url into a browser of another pc I'll get the same response and everything looks fine.
But my Application only works on my pc and not on the other one. When I start the hubconnection on the other pc I don't get a connectionId.
I tried to change the url to my IP-Address without effect.
Browser call to hub works but the Application doesn't work.
The call looks like this:
private bool tryToConnectToCoffeService()
{
try
{
this.hubConnection = new HubConnection(ConfigurationManager.ConnectionStrings["coffeeConnection"].ConnectionString);
this.hubConnection.Credentials = CredentialCache.DefaultNetworkCredentials;
this.coffeeService = this.hubConnection.CreateHubProxy("coffee");
this.hubConnection.Start();
if (string.IsNullOrEmpty(hubConnection.ConnectionId))
{
return false;
}
return true;
}
catch(Exception ex)
{
return false;
}
}
The Global.asax:
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapHubs();
}
The hub like this
[HubName("coffee")]
public class CoffeeHub : Hub
{
My Hub Connection String is this:
"http://pcthi-and:8080/"
Or:
"http://My-Current-IP-Address:8080/"
I use SignalR 1.0 rc2.
Does anyone have an idea? Thanks for helping.
Cheers
Frank
I think you need to change
hubConnection.Start();
to
hubConnection.Start().Wait();
If you are running .NET 4.5 you could make the tryToConnectToCoffeService method async and then await when you start the hub connection.
await hubConnection.Start();
It likely works today on localhost because the client can finish connecting before if (string.IsNullOrEmpty(hubConnection.ConnectionId)) executes.
It is probably taking longer to connect from another machine which exposes the race condition present when you don't wait for HubConnection.Start() to complete.