void OnCreate( Bundle savedInstanceState, ActivationFlags flags) { _activityCreated = true; if (!AllowFragmentRestore) { // Remove the automatically persisted fragment structure; we don't need them // because we're rebuilding everything from scratch. This saves a bit of memory // and prevents loading errors from child fragment managers savedInstanceState?.Remove("android:support:fragments"); } base.OnCreate(savedInstanceState); AToolbar bar; if (ToolbarResource != 0) { bar = LayoutInflater.Inflate(ToolbarResource, null).JavaCast <AToolbar>(); if (bar == null) { throw new InvalidOperationException("ToolbarResource must be set to a Android.Support.V7.Widget.Toolbar"); } } else { bar = new AToolbar(this); } SetSupportActionBar(bar); _layout = new ARelativeLayout(BaseContext); SetContentView(_layout); Xamarin.Forms.Application.ClearCurrent(); _previousState = _currentState; _currentState = AndroidApplicationLifecycleState.OnCreate; OnStateChanged(); if (Forms.IsLollipopOrNewer) { // Allow for the status bar color to be changed if ((flags & ActivationFlags.DisableSetStatusBarColor) == 0) { Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); } } if (Forms.IsLollipopOrNewer) { // Listen for the device going into power save mode so we can handle animations being disabled _powerSaveModeBroadcastReceiver = new PowerSaveModeBroadcastReceiver(); } }
void OnCreate( Bundle savedInstanceState, ActivationFlags flags) { Profile.FrameBegin(); _activityCreated = true; if (!AllowFragmentRestore) { // Remove the automatically persisted fragment structure; we don't need them // because we're rebuilding everything from scratch. This saves a bit of memory // and prevents loading errors from child fragment managers savedInstanceState?.Remove("android:support:fragments"); } Profile.FramePartition("Xamarin.Android.OnCreate"); base.OnCreate(savedInstanceState); Profile.FramePartition("SetSupportActionBar"); AToolbar bar = null; #if __ANDROID_29__ if (ToolbarResource == 0) { ToolbarResource = Resource.Layout.Toolbar; } if (TabLayoutResource == 0) { TabLayoutResource = Resource.Layout.Tabbar; } #endif if (ToolbarResource != 0) { try { bar = LayoutInflater.Inflate(ToolbarResource, null).JavaCast <AToolbar>(); } #if __ANDROID_29__ catch (global::Android.Views.InflateException ie) { if ((ie.Cause is Java.Lang.ClassNotFoundException || ie.Cause.Cause is Java.Lang.ClassNotFoundException) && ie.Message.Contains("Error inflating class android.support.v7.widget.Toolbar") && this.TargetSdkVersion() >= 29) { Internals.Log.Warning(nameof(FormsAppCompatActivity), "Toolbar layout needs to be updated from android.support.v7.widget.Toolbar to androidx.appcompat.widget.Toolbar. " + "Tabbar layout need to be updated from android.support.design.widget.TabLayout to com.google.android.material.tabs.TabLayout. " + "Or if you haven't made any changes to the default Toolbar and Tabbar layouts they can just be deleted."); ToolbarResource = Resource.Layout.FallbackToolbarDoNotUse; TabLayoutResource = Resource.Layout.FallbackTabbarDoNotUse; bar = LayoutInflater.Inflate(ToolbarResource, null).JavaCast <AToolbar>(); } else { throw; } #else catch { throw; #endif } if (bar == null) #if __ANDROID_29__ { throw new InvalidOperationException("ToolbarResource must be set to a Android.Support.V7.Widget.Toolbar"); } #else { throw new InvalidOperationException("ToolbarResource must be set to a androidx.appcompat.widget.Toolbar"); } #endif } else { bar = new AToolbar(this); } SetSupportActionBar(bar); Profile.FramePartition("SetContentView"); _layout = new ARelativeLayout(BaseContext); SetContentView(_layout); Profile.FramePartition("OnStateChanged"); Xamarin.Forms.Application.ClearCurrent(); _previousState = _currentState; _currentState = AndroidApplicationLifecycleState.OnCreate; OnStateChanged(); Profile.FramePartition("Forms.IsLollipopOrNewer"); if (Forms.IsLollipopOrNewer) { // Allow for the status bar color to be changed if ((flags & ActivationFlags.DisableSetStatusBarColor) == 0) { Profile.FramePartition("Set DrawsSysBarBkgrnds"); Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); } } if (Forms.IsLollipopOrNewer) { // Listen for the device going into power save mode so we can handle animations being disabled Profile.FramePartition("Allocate PowerSaveModeReceiver"); _powerSaveModeBroadcastReceiver = new PowerSaveModeBroadcastReceiver(); } ContextExtensions.SetDesignerContext(_layout); Profile.FrameEnd(); }
private bool IsActivated(ActivationFlags activateFlags) { CheckDisposed(); return (0 == SafeNativeMethods.DRMIsActivated(_hSession, (uint)activateFlags, null)); }
/// <summary> /// The Activate function obtains a lockbox and machine certificate for a machine or a rights /// account certificate for a user (depend on activationFlags). /// </summary> private string Activate( ActivationFlags activationFlags, Uri url) { // Optional server information. To query UDDI for an activation URL, pass in NULL ActivationServerInfo activationServer = null; if (url != null) { activationServer = new ActivationServerInfo(); activationServer.PubKey = null; activationServer.Url = url.AbsoluteUri; // We are using Uri class as a basic validation mechanism. These URIs come from unmanaged // code libraries and go back as parameters into the unmanaged code libraries. // We use AbsoluteUri property as means of verifying that it is actually an absolute and // well formed Uri. If by any chance it happened to be a relative URI, an exception will // be thrown here. This will perform the necessary escaping. activationServer.Version = NativeConstants.DrmCallbackVersion; } int hr = SafeNativeMethods.DRMActivate( _hSession, (uint)activationFlags, 0, //language Id activationServer, IntPtr.Zero, // context IntPtr.Zero); // parent Window handle Errors.ThrowOnErrorCode(hr); _callbackHandler.WaitForCompletion(); // it will throw a proper exception in a failure case return _callbackHandler.CallbackData; }
void OnCreate( Bundle savedInstanceState, ActivationFlags flags) { Profile.FrameBegin(); _activityCreated = true; if (!AllowFragmentRestore) { // Remove the automatically persisted fragment structure; we don't need them // because we're rebuilding everything from scratch. This saves a bit of memory // and prevents loading errors from child fragment managers savedInstanceState?.Remove("android:support:fragments"); } Profile.FramePartition("Xamarin.Android.OnCreate"); base.OnCreate(savedInstanceState); Profile.FramePartition("SetSupportActionBar"); AToolbar bar = null; if (_toolbarResource == 0) { ToolbarResource = Resource.Layout.toolbar; } if (_tabLayoutResource == 0) { _tabLayoutResource = Resource.Layout.tabbar; } if (ToolbarResource != 0) { try { bar = LayoutInflater.Inflate(ToolbarResource, null).JavaCast <AToolbar>(); } catch (global::Android.Views.InflateException ie) { throw new InvalidOperationException("ToolbarResource must be set to a androidx.appcompat.widget.Toolbar", ie); } if (bar == null) { throw new InvalidOperationException("ToolbarResource must be set to a androidx.appcompat.widget.Toolbar"); } } else { bar = new AToolbar(this); } SetSupportActionBar(bar); Profile.FramePartition("SetContentView"); _layout = new ARelativeLayout(BaseContext); SetContentView(_layout); Profile.FramePartition("OnStateChanged"); Microsoft.Maui.Controls.Application.Current = null; _previousState = _currentState; _currentState = AndroidApplicationLifecycleState.OnCreate; OnStateChanged(); // Allow for the status bar color to be changed if ((flags & ActivationFlags.DisableSetStatusBarColor) == 0) { Profile.FramePartition("Set DrawsSysBarBkgrnds"); Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); } Profile.FrameEnd(); }
public static string[] ValidateActivationkey(ICDESecrets mySecrets, string activationKeyString, Guid deviceId, List <TheLicense> allLicenses, out List <TheLicenseActivationInformation> activatedLicenses, out DateTimeOffset expirationDate) { expirationDate = DateTimeOffset.MinValue; activatedLicenses = null; string signingKey = mySecrets.GetActivationKeySignatureKey(); var normalizedKey = activationKeyString.Trim().Replace("-", "").ToUpper().Replace('O', '0').Replace('U', 'V').Replace('I', 'J').Replace('L', 'J'); if (normalizedKey.Length != 36) { return(new string[] { "Invalid activation key: not the proper length", String.Format("{0}", activationKeyString) }); } byte[] activationKey = TheActivationUtils.Base32Decode(normalizedKey); if (activationKey == null || activationKey.Length != 23 || activationKey[22] != 15) { return(new string[] { "Invalid activation key: failed to decode.", String.Format("{0}", activationKeyString) }); } string activationKeyHash = Convert.ToBase64String((SHA1.Create().ComputeHash(activationKey))); byte[] signature = new byte[8]; activationKey.Take(8).ToArray().CopyTo(signature, 0); int expirationInDays = (activationKey[8] + (activationKey[9] << 8)); if (expirationInDays < 0) { return(new string[] { "Invalid activation key: invalid expiration date.", String.Format("{0}. Expiration: {1}", activationKeyString, expirationInDays) }); } expirationDate = new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc) + new TimeSpan(expirationInDays, 0, 0, 0); if (expirationDate < DateTime.Now) { return(new string[] { "Invalid activation key: key expired.", String.Format("{0}. Expiration: {1}", activationKeyString, expirationDate.ToString()) }); } ActivationFlags flags = (ActivationFlags)activationKey[10]; if ((flags & ActivationFlags.RequireOnline) != 0) { return(new string[] { "Invalid activation key: online activation required but not supported in this cdeEngine version.", String.Format("{0}", activationKeyString) }); } byte licenseCount = activationKey[12]; if (licenseCount > MaxLicensesInActivationKey) { return(new string[] { "Invalid activation key: too many licenses specified.", String.Format("{0}. License Count: {1}", activationKeyString, licenseCount) }); } if (licenseCount == 0) { return(new string[] { "Invalid activation key: no licenses specified.", String.Format("{0}. License Count: {1}", activationKeyString, 0) }); } if (licenseCount > allLicenses.Count) { return(new string[] { "Unable to apply activation key: some licenses not available on the system.", String.Format("{0}. License Count in key: {1}. Total valid licenses on system: {2}", activationKeyString, licenseCount, allLicenses.Count) }); } byte[] parameters = new byte[TheActivationUtils.MaxLicenseParameters]; int paramOffset = 13; for (int j = 0; j < TheActivationUtils.MaxLicenseParameters; j++) { parameters[j] = activationKey[paramOffset]; paramOffset++; } int[] candidateIndices = new int[licenseCount]; TheLicense[] candidates = new TheLicense[licenseCount]; bool done = false; do { bool validCombination = true; for (int i = 0; i < licenseCount; i++) { candidates[i] = allLicenses[candidateIndices[i]]; if (i > 0 && String.CompareOrdinal(candidates[i].LicenseId.ToString(), candidates[i - 1].LicenseId.ToString()) <= 0) { validCombination = false; break; } } if (validCombination && TheActivationUtils.GenerateLicenseSignature(deviceId, signingKey, (uint)expirationInDays, candidates.ToArray(), parameters, flags, out byte[] candidateSignature))
/// <summary> /// Generated an activation key for the target deviceid. /// </summary> /// <param name="deviceId">Identifier of the cdeEngine node that is to be activated with the activation key.</param> /// <param name="signingKey">Symmetric key (arbitrary string) used to sign the activation key. The same key must be provided on the runtime node.</param> /// <param name="Expiration">Expiration date of the activation key. Licenses and entitlements activated using this key will cease to be valid after this date.</param> /// <param name="licenses">Note: values in the License.LicenseParameters property will be included in the activation key and added to the values in the license at activation time. /// This means that often you will want to set these values to 0 if the license already contains non-zero default paremeters.</param> /// <param name="activationKeyParameters">Additional parameters (typically entitlements for thing instances) to be unlocked with this activation key.</param> /// <param name="flags">Flags requesting additional activation key behavior.</param> /// <returns></returns> public static string GenerateActivationKey(Guid deviceId, string signingKey, DateTime Expiration, TheLicense[] licenses, List <TheLicenseParameter> activationKeyParameters, ActivationFlags flags) { if (licenses.Length > MaxLicensesInActivationKey || licenses.Length == 0) { return(null); } var sortedLicenses = licenses.OrderBy((l) => l.LicenseId.ToString()); byte[] licenseSignature; byte[] licenseParams = GenerateLicenseParameters(sortedLicenses); if (licenseParams == null || licenseParams.Length > TheActivationUtils.MaxLicenseParameters) { return(null); } int index = 0; foreach (var param in activationKeyParameters) { licenseParams[index] = param.Value; index++; } double expirationTemp = Math.Ceiling((Expiration.ToUniversalTime() - new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalDays); if (expirationTemp < 0 || expirationTemp > 0xFFFF) { return(null); } uint expirationInDays = (uint)expirationTemp; if (!TheActivationUtils.GenerateLicenseSignature(deviceId, signingKey, expirationInDays, sortedLicenses.ToArray(), licenseParams, flags, out licenseSignature)) { return(null); } byte[] activationKey = new byte[23]; // 0-7: HMACSHA1 (appId, licenseAuthorization) -> truncate to 8 bytes (64 bits) licenseSignature.Take(8).ToArray().CopyTo(activationKey, 0); // 8-9: Expiration: Days since January 2016. Resulting Range: 2016 - 2195 activationKey[8] = (byte)(expirationInDays & 0xFF); activationKey[9] = (byte)((expirationInDays >> 8) & 0xFF); // 10: Flags activationKey[10] = (byte)flags; // 11: Reserved (0) activationKey[11] = 0; // 12: License count activationKey[12] = (byte)sortedLicenses.Count(); // 13-21: License parameters ( licenseParams.CopyTo(activationKey, 13); // 22: Padding activationKey[22] = 15; // Ensure we always get 6x6 characters in base32 var key = TheActivationUtils.Base32Encode(activationKey); //var testKey = TheActivationUtils.Base32Decode(key.Replace("-","")); return(key); }