private void getfixedfeatures() { version v = environment.osversion.version; bool g =...
TRANSCRIPT
![Page 1: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/1.jpg)
![Page 2: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/2.jpg)
Andrew WHITECHAPELProgram Manager
Managing Resource Constraints in Windows Phone
3-542
![Page 3: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/3.jpg)
Why do you care?What are your choices?Windows Phone Resource Manager.Managing memory.What’s different in Blue?
Agenda
![Page 4: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/4.jpg)
Why do you care?
Make your app available on the widest range of WP devices possible.Ensure users have a great experience with your app on all devices, and at all times.
![Page 5: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/5.jpg)
Why do you care?Make your app available on the widest range of WP devices possible.Ensure users have a great experience with your app on all devices, and at all times.
Memory/hardware constraints can make this an interesting challenge.Windows convergence: a desktop OS on a phone.Disproportionate growth in mid-tier devices.Apps live in an ecosystem on the phone. We did work to scale to devices; now it’s your turn.
![Page 6: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/6.jpg)
Device variability – what are your choices?
Selective targeting. Resilience to variability, and feature
light-up.
![Page 7: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/7.jpg)
Selective targeting
Maximum breadth. Aim for the lowest common denominator. Eliminate non-universal
features/capabilities/memory usage.
Scoped. By OS/platform version (single or multiple app
versions). By device requirements (ID_REQ_*). By device memory.
![Page 8: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/8.jpg)
Resilience and feature light-up
Resilience to platform variability. By device capabilities (ID_CAP_*). Runtime API calls (Is*Supported).
Resilience to dynamic variability. Cell/Network. Battery/PowerSource. Sensor access. Memory.
![Page 9: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/9.jpg)
Demo: optional features
![Page 10: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/10.jpg)
Fixed (per device) and dynamic (per user selection).
Check for optional featuresprivate void GetFixedFeatures(){ Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported; bool c = Compass.IsSupported; bool p = Camera.IsCameraTypeSupported(CameraType.Primary); bool f = Camera.IsCameraTypeSupported(CameraType.FrontFacing); int i = App.Current.Host.Content.ScaleFactor;}
private void GetDynamicFeatures(){ bool d = DeviceNetworkInformation.IsCellularDataEnabled; bool r = DeviceNetworkInformation.IsCellularDataRoamingEnabled; bool x = (DeviceStatus.PowerSource == PowerSource.External); ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile(); ConnectionCost cost = profile.GetConnectionCost();}
private void AddEventHandlers(){ DeviceNetworkInformation.NetworkAvailabilityChanged += OnNetworkAvailabilityChanged; NetworkInformation.NetworkStatusChanged += OnNetworkStatusChanged; DeviceStatus.PowerSourceChanged += OnPowerSourceChanged; PowerManager.PowerSavingModeChanged += OnPowerSavingModeChanged;}
![Page 11: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/11.jpg)
Why? To maintain an optimal user experience across all scenarios.
Memory quotas and caps. CPU quotas and caps. Task priorities. Sensor resources. Monitoring your app’s memory
usage.
Windows Phone resource management
![Page 12: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/12.jpg)
Caps are not quotas.
Memory caps WP8.0 (GDR3)
App/Agent Type 512MB device 1GB device 2GB device
VOIP 51 60 80
Background Audio Playback 20* 25* 25*
Generic Background Agents 11* 20 20
Continuous Background Execution 150 150 150
Foreground App** 150/150/180 150/300/380 150/450/570
*Cannot run concurrently with VOIP.**Min native/Min Silverlight/Max
Foreground App** 150/150/180 150/300/380 150/450/570
![Page 13: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/13.jpg)
More task types.
Higher caps.
No min cap.
Memory caps WP8.1
App/Agent Type 512MB device 1GB device 2GB device
VOIP 51 60 80
Background Audio 20 25 25
Bluetooth 16 16 16
VPN 10 15 15
Calendar Child/FileProvider Target 100 100 100CachedFileUpdater/ShareDataPackage 10 10 10
Background Transfer 5 5 5
WP8 Generic Background Agents 16 20 30
WP8.1 Background Tasks 16 30 40
Continuous Background Execution 150 150 300
Foreground App (WP8.0 context) 180 380 780
Foreground App (modern context) 185 390 825
WP8 Generic Background Agents 16 20 30
WP8.1 Background Tasks 16 30 40
Foreground App (WP8.0 context) 180 380 780
Foreground App (modern context) 185 390 825
![Page 14: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/14.jpg)
Don’t.
Memory cap options
<!-- WP8.1 AppxManifest.xml --><Prerequisites> <m3:MinDeviceMemory>1GB</m3:MinDeviceMemory></Prerequisites>
<!-- WP7 and WP8.0 WMAppManifest.xml --><Requirements> <!--<Requirement Name="ID_REQ_MEMORY_90" />--> <Requirement Name="ID_REQ_MEMORY_300" /></Requirements> <!– Ignored in WP8.1 --><FunctionalCapabilities> <FunctionalCapability Name="ID_FUNCCAP_EXTEND_MEM" /></FunctionalCapabilities>
![Page 15: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/15.jpg)
Memory usage breakdown
Component usage (ballpark) 512MB
Total physical 512
Paging level 200
712
BSP 133
OS, drivers, services 300
OEM/MO service agents 22
VOIP or Background audio 51
Bluetooth 16
VPN 10
532
Foreground App, Back-stack, CBE, GBAs 180
94% of apps peak at <150MB.
96% of apps average at <100MB.
![Page 16: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/16.jpg)
Scenario-based prioritization.
Task Priorities
App/Agent Type Priority
Foreground App 2
VOIP 2
Background Audio 2
Bluetooth 2
VPN 2
Background Transfer 2 or 6*
Calendar Child/FileProvider Target 3
CachedFileUpdater/ShareDataPackage Task 3 or 6*
Continuous Background Execution 4
Geofence-triggered Task 5
WP8.0 Generic Background Agents 6
WP8.1 Background Tasks 6
*Higher priority if part of the Foreground experience.
![Page 17: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/17.jpg)
Monitoring memory usage// WP7.long totalBytes = Microsoft.Phone.Info.DeviceStatus.DeviceTotalMemory;long memUsageLimit = Microsoft.Phone.Info.DeviceStatus.ApplicationMemoryUsageLimit;long currentMemUsage = Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage;
// WP8.0.ulong committedLimit = Windows.Phone.System.Memory.MemoryManager.ProcessCommittedLimit;ulong committedBytes = Windows.Phone.System.Memory.MemoryManager.ProcessCommittedBytes;
// WP8.1.ulong usageLimit = Windows.System.MemoryManager.AppMemoryUsageLimit;ulong currentUsage = Windows.System.MemoryManager.AppMemoryUsage;MemoryManager.AppMemoryUsageIncreased += OnAppMemoryUsageIncreased;MemoryManager.AppMemoryUsageDecreased += OnAppMemoryUsageDecreased;
private void OnAppMemoryUsageIncreased(object sender, object e){ switch (MemoryManager.AppMemoryUsageLevel) { case AppMemoryUsageLevel.High: break; case AppMemoryUsageLevel.Medium: break; case AppMemoryUsageLevel.Low: break; }}
![Page 18: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/18.jpg)
Demo: monitoring memory usage
![Page 19: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/19.jpg)
AppMemoryUsageLimitChanging
private void Init(){ MemoryManager.AppMemoryUsageLimitChanging += OnAppMemoryUsageLimitChanging;}
private void OnAppMemoryUsageLimitChanging( object sender, AppMemoryUsageLimitChangingEventArgs e){ Debug.WriteLine(String.Format( "AppMemoryUsageLimitChanging: old={0} MB, new={1} MB", (double)e.OldLimit / 1024 / 1024, (double)e.NewLimit / 1024 / 1024));}
![Page 20: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/20.jpg)
Demo: AppMemoryUsageLimitChanging
![Page 21: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/21.jpg)
Example: Background Audio Agent
Sensor resources
Resource Allowed?
Microphone Camera Proximity Gyro Compass Accelerometer Vibrator Push SpeechSynthesis SpeechRecognition Audio InterruptiveUI
![Page 22: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/22.jpg)
Background tasks
CPU quotas. (Partially) converged with Windows RT. Parity in behavior with WP8.0 GBAs. Call BackgroundExecutionManager.RequestAccessAsync
(8.1)
Bluetooth tasks. Short-running: high priority, 30 sec lifetime. Long-running: lower priority, no lifetime cap.
Graphics buffers. One medium tile, one wide tile, one wallpaper.
Battery saver app & battery saver mode.Rude termination (not VOIP/BAP).
![Page 23: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/23.jpg)
Shared Foreground/Background memory
Remove hidden cost imbalances.A VOIP UI app, and its background agents.Any foreground app that invokes a modern background transfer to start while the app is in the foreground.Any foreground app that uses foreground agents.Any foreground app that uses a long-running Bluetooth background task.Any combinations of the above.Subtractions re-added when the background task terminates.
DeviceParticipating tasks Count Cap Max BG Max FG
512MB Background transfer 1 185 5 180
1GB Background transfer 5 390 25 365
![Page 24: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/24.jpg)
Demo: shared fg/bg memory
![Page 25: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/25.jpg)
Use memory APIs to check your usage (debug & release).
Check for optional & user-disabled features. Tailor image resolution to device; use
thumbnails. Launchers instead of full controls. Disable page transitions. Use virtualized lists, load on demand. Test on all your target emulators; focus on the
LCD. Test on real devices. Use the profiler (Windows App Certification
Kit). Use the Windows Phone Developer Power
Tools. Seek out memory spikes.
See Stefan Wick’s talk: 3-545 Quality & Performance.
See Lalithra Fernando’s talk: 4-557 How to Analyze Performance Issues.
Best practices
![Page 26: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/26.jpg)
For maximum success, do work to support the widest range of devices.Your app belongs to a balanced ecosystem.Profile your app, query the device, monitor dynamic features & memory.
Summary
![Page 27: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/27.jpg)
Resources
App memory limits for Windows Phone 8: http://aka.ms/Tfdyf7 Developing apps for lower-memory phones: http://aka.ms/To4as5 The evolution of Windows Phone memory management: http://
aka.ms/Jo85ot Best practice tips for delivering apps with 256 MB: http://aka.ms/Inx8pg Optimizing apps for lower-cost devices: http://aka.ms/Rwt4ll App platform compatibility for Windows Phone: http://aka.ms/Y8fxim Windows Phone 8 Development Internals (book): http://aka.ms/J83ips
![Page 28: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/28.jpg)
Your Feedback is Important
Fill out an evaluation of this session and help shape future events.
Scan the QR code to evaluate this session on your mobile device.
You’ll also be entered into a daily prize drawing!
![Page 29: private void GetFixedFeatures() { Version v = Environment.OSVersion.Version; bool g = Gyroscope.IsSupported; bool a = Accelerometer.IsSupported;](https://reader036.vdocuments.site/reader036/viewer/2022062423/56649c7d5503460f949322b8/html5/thumbnails/29.jpg)
© 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.