-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #788 from predictive-technology-laboratory/mehdi_test
Mehdi test
Showing
16 changed files
with
524 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
Sensus.Android.Shared/Probes/Apps/AndroidKeystrokeProbe.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Sensus.Probes.Apps; | ||
using Syncfusion.SfChart.XForms; | ||
using Android.AccessibilityServices; | ||
using Android.Views.Accessibility; | ||
using Android.Content; | ||
using Android.App; | ||
using Xamarin.Android; | ||
|
||
|
||
namespace Sensus.Android.Probes.Apps | ||
{ | ||
public class AndroidKeystrokeProbe : KeystrokeProbe | ||
{ | ||
private AndroidKeystrokeService _accessibilityListener; | ||
private DateTime? _accessibilityEventTime; | ||
private EventHandler<KeystrokeDatum> _accessibilityCallback; | ||
|
||
public AndroidKeystrokeProbe() | ||
{ | ||
_accessibilityCallback = async (sender, incomingKeystrokedatum) => | ||
{ | ||
|
||
//Console.WriteLine("***** OnAccessibilityEvent Probeeeeeeeeeeeeeeeeeee***** " + incomingKeystrokedatum.Key + " " + incomingKeystrokedatum.App); | ||
|
||
await StoreDatumAsync(incomingKeystrokedatum); | ||
}; | ||
|
||
} | ||
|
||
protected override ChartDataPoint GetChartDataPointFromDatum(Datum datum) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected override ChartAxis GetChartPrimaryAxis() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected override RangeAxisBase GetChartSecondaryAxis() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected override ChartSeries GetChartSeries() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected override Task StartListeningAsync() | ||
{ | ||
|
||
if (!isAccessibilityServiceEnabled()) { | ||
|
||
//This temporary, code should be added to automatically open settings page. | ||
//Xamarin.Forms.Application.Current.MainPage.DisplayAlert("Permission Request", "Please navigate to settings->Accessibility and enable the accessbility service permission for Sensus", "ok", "cancel"); | ||
|
||
//var response = await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("Permission Request", "On the next screen, please enable the accessbility service permission for Sensus", "ok", "cancel"); | ||
|
||
//if (response) | ||
//{ | ||
// //user click ok | ||
// //await SensusServiceHelper.Get().FlashNotificationAsync("starttttttttttttttttt"); | ||
// //Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS); | ||
// //Application.Context.StartActivity(intent); | ||
|
||
//} | ||
|
||
} | ||
|
||
AndroidKeystrokeService.AccessibilityBroadcast += _accessibilityCallback; | ||
//This doesn't work because the accessibility service can be started and stopped only by system apps | ||
//Intent serviceIntent = new Intent(Application.Context, typeof(AndroidKeystrokeService)); | ||
//Application.Context.StartService(serviceIntent); | ||
return Task.CompletedTask; | ||
} | ||
|
||
protected override Task StopListeningAsync() | ||
{ | ||
AndroidKeystrokeService.AccessibilityBroadcast -= _accessibilityCallback; | ||
//This doesn't work | ||
//Intent serviceIntent = new Intent(Application.Context, typeof(AndroidKeystrokeService)); | ||
//Application.Context.StopService(serviceIntent); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Boolean isAccessibilityServiceEnabled() | ||
{ | ||
AccessibilityManager accessibilityManager = (AccessibilityManager)Application.Context.GetSystemService(AccessibilityService.AccessibilityService); | ||
IList<AccessibilityServiceInfo> enabledServices = accessibilityManager.GetEnabledAccessibilityServiceList(FeedbackFlags.AllMask); | ||
bool check = false; | ||
for (int i = 0; i < enabledServices.Count; i++) { | ||
AccessibilityServiceInfo e = enabledServices[i]; | ||
if (e.ResolveInfo.ServiceInfo.PackageName == Application.Context.ApplicationInfo.PackageName) { | ||
check = true; | ||
} | ||
} | ||
return check; | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
Sensus.Android.Shared/Probes/Apps/AndroidKeystrokeService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Android.Views.Accessibility; | ||
using Android.AccessibilityServices; | ||
using Sensus.Android; | ||
using Android.App; | ||
using Android; | ||
using Android.Util; | ||
using Sensus.Probes.Apps; | ||
using Android.Content; | ||
using Sensus.Exceptions; | ||
|
||
namespace Sensus.Android.Probes.Apps | ||
{ | ||
[Service(Permission = Manifest.Permission.BindAccessibilityService)] | ||
[IntentFilter(new[] { "android.accessibilityservice.AccessibilityService" })] | ||
public class AndroidKeystrokeService : AccessibilityService | ||
{ | ||
private AccessibilityServiceInfo info = new AccessibilityServiceInfo(); | ||
public static event EventHandler<KeystrokeDatum> AccessibilityBroadcast; | ||
public override void OnAccessibilityEvent(AccessibilityEvent e) | ||
{ | ||
try { | ||
if (e.Text.Count > 0) | ||
{ | ||
AccessibilityBroadcast?.Invoke(this, new KeystrokeDatum(DateTimeOffset.UtcNow, e.Text[0].ToString(), e.PackageName)); | ||
} | ||
|
||
} | ||
catch (Exception ex) | ||
{ | ||
SensusException.Report("Exception in Kesystroke service: " + ex.Message, ex); | ||
} | ||
} | ||
|
||
public override void OnCreate() | ||
{ | ||
base.OnCreate(); | ||
|
||
} | ||
|
||
public override void OnInterrupt() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override ComponentName StartService(Intent service) | ||
{ | ||
return base.StartService(service); | ||
} | ||
|
||
public override bool StopService(Intent name) | ||
{ | ||
return base.StopService(name); | ||
} | ||
|
||
protected override void OnServiceConnected() | ||
{ | ||
base.OnServiceConnected(); | ||
info.EventTypes = EventTypes.ViewTextChanged; | ||
info.FeedbackType = FeedbackFlags.AllMask; | ||
info.NotificationTimeout = 100; | ||
this.SetServiceInfo(info); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Sensus.Probes.Apps | ||
{ | ||
public class KeystrokeDatum : Datum | ||
{ | ||
private string _key; | ||
private string _app; | ||
|
||
|
||
public KeystrokeDatum(DateTimeOffset timestamp, string key, string app) : base(timestamp) | ||
{ | ||
_key = key == null ? "" : key; | ||
_app = app == null ? "" : app; | ||
} | ||
|
||
public override string DisplayDetail | ||
{ | ||
get | ||
{ | ||
return "(Keystroke Data)"; | ||
} | ||
} | ||
|
||
public string Key { get => _key; set => _key = value; } | ||
public string App { get => _app; set => _app = value; } | ||
|
||
public override object StringPlaceholderValue => throw new NotImplementedException(); | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
return base.Equals(obj); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return base.GetHashCode(); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return base.ToString() + Environment.NewLine + | ||
"Key: " + _key + Environment.NewLine + | ||
"App: " + _app + Environment.NewLine; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Syncfusion.SfChart.XForms; | ||
using Newtonsoft.Json; | ||
|
||
namespace Sensus.Probes.Apps | ||
{ | ||
public abstract class KeystrokeProbe : ListeningProbe | ||
{ | ||
|
||
public override string DisplayName | ||
{ | ||
get | ||
{ | ||
return "Keystroke"; | ||
} | ||
} | ||
public override Type DatumType | ||
{ | ||
get { return typeof(KeystrokeDatum); } | ||
} | ||
|
||
[JsonIgnore] | ||
protected override bool DefaultKeepDeviceAwake | ||
{ | ||
get | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
[JsonIgnore] | ||
protected override string DeviceAwakeWarning | ||
{ | ||
get | ||
{ | ||
return "This setting should not be enabled. It does not affect iOS and will unnecessarily reduce battery life on Android."; | ||
} | ||
} | ||
|
||
[JsonIgnore] | ||
protected override string DeviceAsleepWarning | ||
{ | ||
get | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
public override double? MaxDataStoresPerSecond { get => base.MaxDataStoresPerSecond; set => base.MaxDataStoresPerSecond = value; } | ||
|
||
public override string CollectionDescription => base.CollectionDescription; | ||
|
||
protected override bool WillHaveSignificantNegativeImpactOnBattery => base.WillHaveSignificantNegativeImpactOnBattery; | ||
|
||
protected override double RawParticipation => base.RawParticipation; | ||
|
||
protected override long DataRateSampleSize => base.DataRateSampleSize; | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.