Skip to content

Commit

Permalink
Merge pull request unoplatform#975 from MartinZikmund/dev/mazi/vibration
Browse files Browse the repository at this point in the history
Implemented VibrationDevice
  • Loading branch information
jeromelaban authored Jun 19, 2019
2 parents a8e1b63 + d284145 commit 06df4f6
Show file tree
Hide file tree
Showing 22 changed files with 673 additions and 61 deletions.
3 changes: 3 additions & 0 deletions .vsts-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:
# Required for the Wasm uitests project
- task: NodeTool@0

- powershell: .\build\Install-WindowsSdkISO.ps1 17763
displayName: Insider SDK

- task: MSBuild@1
inputs:
solution: Build/Uno.UI.Build.csproj
Expand Down
302 changes: 302 additions & 0 deletions build/Install-WindowsSdkISO.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,302 @@
[CmdletBinding()]
param([Parameter(Mandatory=$true)]
[string]$buildNumber)

# Ensure the error action preference is set to the default for PowerShell3, 'Stop'
$ErrorActionPreference = 'Stop'

# Constants
$WindowsSDKOptions = @("OptionId.UWPCpp")
$WindowsSDKRegPath = "HKLM:\Software\Microsoft\Windows Kits\Installed Roots"
$WindowsSDKRegRootKey = "KitsRoot10"
$WindowsSDKVersion = "10.0.$buildNumber.0"
$WindowsSDKInstalledRegPath = "$WindowsSDKRegPath\$WindowsSDKVersion\Installed Options"
$StrongNameRegPath = "HKLM:\SOFTWARE\Microsoft\StrongName\Verification"
$PublicKeyTokens = @("31bf3856ad364e35")

function Download-File
{
param ([string] $outDir,
[string] $downloadUrl,
[string] $downloadName)

$downloadPath = Join-Path $outDir "$downloadName.download"
$downloadDest = Join-Path $outDir $downloadName
$downloadDestTemp = Join-Path $outDir "$downloadName.tmp"

Write-Host -NoNewline "Downloading $downloadName..."

try
{
$webclient = new-object System.Net.WebClient
$webclient.DownloadFile($downloadUrl, $downloadPath)
}
catch [System.Net.WebException]
{
Write-Host
Write-Warning "Failed to fetch updated file from $downloadUrl"
if (!(Test-Path $downloadDest))
{
throw "$downloadName was not found at $downloadDest"
}
else
{
Write-Warning "$downloadName may be out of date"
}
}

Unblock-File $downloadPath

$downloadDestTemp = $downloadPath;

# Delete and rename to final dest
if (Test-Path -PathType Container $downloadDest)
{
[System.IO.Directory]::Delete($downloadDest, $true)
}

Move-Item -Force $downloadDestTemp $downloadDest
Write-Host "Done"

return $downloadDest
}

function Get-ISODriveLetter
{
param ([string] $isoPath)

$diskImage = Get-DiskImage -ImagePath $isoPath
if ($diskImage)
{
$volume = Get-Volume -DiskImage $diskImage

if ($volume)
{
$driveLetter = $volume.DriveLetter
if ($driveLetter)
{
$driveLetter += ":"
return $driveLetter
}
}
}

return $null
}

function Mount-ISO
{
param ([string] $isoPath)

# Check if image is already mounted
$isoDrive = Get-ISODriveLetter $isoPath

if (!$isoDrive)
{
Mount-DiskImage -ImagePath $isoPath -StorageType ISO | Out-Null
}

$isoDrive = Get-ISODriveLetter $isoPath
Write-Verbose "$isoPath mounted to ${isoDrive}:"
}

function Dismount-ISO
{
param ([string] $isoPath)

$isoDrive = (Get-DiskImage -ImagePath $isoPath | Get-Volume).DriveLetter

if ($isoDrive)
{
Write-Verbose "$isoPath dismounted"
Dismount-DiskImage -ImagePath $isoPath | Out-Null
}
}

function Disable-StrongName
{
param ([string] $publicKeyToken = "*")

reg ADD "HKLM\SOFTWARE\Microsoft\StrongName\Verification\*,$publicKeyToken" /f | Out-Null
if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64")
{
reg ADD "HKLM\SOFTWARE\Wow6432Node\Microsoft\StrongName\Verification\*,$publicKeyToken" /f | Out-Null
}
}

function Test-Admin
{
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal $identity
$principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}

function Test-RegistryPathAndValue
{
param (
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string] $path,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string] $value)

try
{
if (Test-Path $path)
{
Get-ItemProperty -Path $path | Select-Object -ExpandProperty $value -ErrorAction Stop | Out-Null
return $true
}
}
catch
{
}

return $false
}

function Test-InstallWindowsSDK
{
$retval = $true

if (Test-RegistryPathAndValue -Path $WindowsSDKRegPath -Value $WindowsSDKRegRootKey)
{
# A Windows SDK is installed
# Is an SDK of our version installed with the options we need?
if (Test-RegistryPathAndValue -Path $WindowsSDKInstalledRegPath -Value "$WindowsSDKOptions")
{
# It appears we have what we need. Double check the disk
$sdkRoot = Get-ItemProperty -Path $WindowsSDKRegPath | Select-Object -ExpandProperty $WindowsSDKRegRootKey
if ($sdkRoot)
{
if (Test-Path $sdkRoot)
{
$refPath = Join-Path $sdkRoot "References\$WindowsSDKVersion"
if (Test-Path $refPath)
{
$umdPath = Join-Path $sdkRoot "UnionMetadata\$WindowsSDKVersion"
if (Test-Path $umdPath)
{
# Pretty sure we have what we need
$retval = $false
}
}
}
}
}
}

return $retval
}

function Test-InstallStrongNameHijack
{
foreach($publicKeyToken in $PublicKeyTokens)
{
$key = "$StrongNameRegPath\*,$publicKeyToken"
if (!(Test-Path $key))
{
return $true
}
}

return $false
}

Write-Host -NoNewline "Checking for installed Windows SDK $WindowsSDKVersion..."
$InstallWindowsSDK = Test-InstallWindowsSDK
if ($InstallWindowsSDK)
{
Write-Host "Installation required"
}
else
{
Write-Host "INSTALLED"
}

$StrongNameHijack = Test-InstallStrongNameHijack
Write-Host -NoNewline "Checking if StrongName bypass required..."

if ($StrongNameHijack)
{
Write-Host "REQUIRED"
}
else
{
Write-Host "Done"
}

if ($StrongNameHijack -or $InstallWindowsSDK)
{
if (!(Test-Admin))
{
Write-Host
throw "ERROR: Elevation required"
}
}

if ($InstallWindowsSDK)
{
# Static(ish) link for Windows SDK
# Note: there is a delay from Windows SDK announcements to availability via the static link
$uri = "https://go.microsoft.com/fwlink/?prd=11966&pver=1.0&plcid=0x409&clcid=0x409&ar=Flight&sar=Sdsurl&o1=$buildNumber"

if ($env:TEMP -eq $null)
{
$env:TEMP = Join-Path $env:SystemDrive 'temp'
}

$winsdkTempDir = Join-Path $env:TEMP "WindowsSDK"

if (![System.IO.Directory]::Exists($winsdkTempDir))
{
[void][System.IO.Directory]::CreateDirectory($winsdkTempDir)
}

$file = "winsdk_$buildNumber.iso"

Write-Verbose "Getting WinSDK from $uri"
$downloadFile = Download-File $winsdkTempDir $uri $file

# TODO Check if zip, exe, iso, etc.
try
{
Write-Host -NoNewline "Mounting ISO $file..."
Mount-ISO $downloadFile
Write-Host "Done"

$isoDrive = Get-ISODriveLetter $downloadFile

if (Test-Path $isoDrive)
{
Write-Host -NoNewLine "Installing WinSDK..."

$setupPath = Join-Path "$isoDrive" "WinSDKSetup.exe"
Start-Process -Wait $setupPath "/features $WindowsSDKOptions /q"
Write-Host "Done"
}
else
{
throw "Could not find mounted ISO at ${isoDrive}"
}
}
finally
{
Write-Host -NoNewline "Dismounting ISO $file..."
#Dismount-ISO $downloadFile
Write-Host "Done"
}
}

if ($StrongNameHijack)
{
Write-Host -NoNewline "Disabling StrongName for Windows SDK..."

foreach($key in $PublicKeyTokens)
{
Disable-StrongName $key
}

Write-Host "Done"
}
17 changes: 10 additions & 7 deletions build/PackageDiffIgnore.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<DiffIgnore>
<IgnoreSets>
<IgnoreSets>
<IgnoreSet baseVersion="1.43.1">
<Methods>
<Member fullName="System.Void Windows.UI.Xaml.WindowCreatedEventArgs..ctor()"
Expand Down Expand Up @@ -113,7 +113,7 @@
reason="Moved to Uno.Extensions"/>
</Types>

<Methods>
<Methods>
<Member fullName="System.Boolean Uno.Foundation.WebAssemblyRuntime.InvokeJSUnmarshalled(System.String functionIdentifier, System.IntPtr arg0, System.IntPtr arg1, System.IntPtr arg2)"
reason="Removed to improve the C#/JS call performance"/>

Expand Down Expand Up @@ -171,11 +171,14 @@
reason="Invalid method visibility"/>
<Member fullName="System.Void Uno.UI.Controls.Legacy.ListViewBase.OnLayoutUpdated()"
reason="Invalid method visibility"/>

<Member fullName="Android.Views.View Windows.UI.Xaml.Controls.Popup.get_Anchor()"
reason="Invalid method visibility"/>
<Member fullName="System.Void Windows.UI.Xaml.Controls.Popup.set_Anchor(Android.Views.View value)"
reason="Invalid method visibility"/>
<Member fullName="System.Void Windows.Phone.Devices.Notification.VibrationDevice..ctor()"
reason="Parameter-less ctor does not exist in UWP" />
<Member fullName="System.Void Windows.UI.Xaml.Controls.VirtualizingPanelLayout.UpdateLayoutAttributesForItem(UIKit.UICollectionViewLayoutAttributes layoutAttributes)"
reason="Implementation detail, made internal"/>
<Member fullName="Android.Views.View Windows.UI.Xaml.Controls.Popup.get_Anchor()"
reason="Invalid method visibility"/>
<Member fullName="System.Void Windows.UI.Xaml.Controls.Popup.set_Anchor(Android.Views.View value)"
reason="Invalid method visibility"/>
</Methods>

<Fields>
Expand Down
1 change: 1 addition & 0 deletions doc/ReleaseNotes/_ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Release notes

## Next version
* Add support for `Windows.Phone.Devices.Notification.VibrationDevice` API on iOS, Android and WASM
* `LinearGradientBrush.EndPoint` now defaults to (1,1) to match UWP
* Add support for `Windows.System.Display.DisplayRequest` API on iOS and Android
* Add support for the following `Windows.System.Power.PowerManager` APIs on iOS and Android:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Uno Support for Windows.Phone.Devices.Notification APIs

## `VibrationDevice`

### Limitations

**iOS**
- The `Cancel` method is not supported.
- The parameter of the `Vibrate(TimeSpan)` method is not taken into account - iOS supports only a default vibration duration.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="SamplesApp" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="28" />
<application android:label="SamplesApp"></application>
<meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR API KEY" />
</manifest>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="28" />
<uses-permission android:name="android.permission.VIBRATE" />
<application android:label="SamplesApp"></application>
<meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR API KEY" />
</manifest>
Loading

0 comments on commit 06df4f6

Please sign in to comment.