Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <TargetConditionals.h>

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

/// Shows and hides the alert that `GIDEMMErrorHandler` uses to explain an EMM error to the user.
///
/// Production code uses `GIDEMMAlertWindowPresenter`; tests use `GIDFakeEMMAlertPresenter`.
@protocol GIDEMMAlertPresenter <NSObject>

/// Presents `alert` above `keyWindow`. Must be called on the main thread.
- (void)presentAlert:(UIAlertController *)alert overKeyWindow:(UIWindow *)keyWindow;

/// Tears down whatever `-presentAlert:overKeyWindow:` set up and makes that call's `keyWindow` the
/// key window again. Must be called on the main thread.
- (void)dismissAlert;

@end

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <TargetConditionals.h>

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#import "GoogleSignIn/Sources/GIDEMMAlertPresenter/API/GIDEMMAlertPresenter.h"

NS_ASSUME_NONNULL_BEGIN

/// An in-memory `GIDEMMAlertPresenter` for tests. Records the alert instead of showing it.
@interface GIDFakeEMMAlertPresenter : NSObject <GIDEMMAlertPresenter>

/// The alert passed to the most recent `-presentAlert:overKeyWindow:` that has not yet been
/// dismissed, or nil.
@property(nonatomic, readonly, nullable) UIAlertController *presentedAlert;

/// The key window passed to the most recent `-presentAlert:overKeyWindow:`, or nil.
@property(nonatomic, readonly, nullable) UIWindow *presentedOverKeyWindow;

/// The number of times `-dismissAlert` has been called.
@property(nonatomic, readonly) NSUInteger dismissCount;

@end

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <TargetConditionals.h>

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#import "GoogleSignIn/Sources/GIDEMMAlertPresenter/Fake/GIDFakeEMMAlertPresenter.h"

NS_ASSUME_NONNULL_BEGIN

@implementation GIDFakeEMMAlertPresenter

- (void)presentAlert:(UIAlertController *)alert overKeyWindow:(UIWindow *)keyWindow {
_presentedAlert = alert;
_presentedOverKeyWindow = keyWindow;
}

- (void)dismissAlert {
_presentedAlert = nil;
_dismissCount++;
}

@end

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <TargetConditionals.h>

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#import <Foundation/Foundation.h>

#import "GoogleSignIn/Sources/GIDEMMAlertPresenter/API/GIDEMMAlertPresenter.h"

NS_ASSUME_NONNULL_BEGIN

/// Presents the EMM alert in a transparent `UIWindow` of its own at `UIWindowLevelAlert`.
@interface GIDEMMAlertWindowPresenter : NSObject <GIDEMMAlertPresenter>
@end

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <TargetConditionals.h>

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#import "GoogleSignIn/Sources/GIDEMMAlertPresenter/Implementation/GIDEMMAlertWindowPresenter.h"

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@implementation GIDEMMAlertWindowPresenter {
// The transparent window the alert is presented in while it is showing, or nil.
UIWindow *_alertWindow;
// The window that was key before the alert was shown; made key again on dismissal.
UIWindow *_keyWindow;
}

- (void)presentAlert:(UIAlertController *)alert overKeyWindow:(UIWindow *)keyWindow {
_keyWindow = keyWindow;
UIWindow *alertWindow;
if (keyWindow.windowScene) {
alertWindow = [[UIWindow alloc] initWithWindowScene:keyWindow.windowScene];
}
if (!alertWindow) {
CGRect keyWindowBounds = CGRectIsEmpty(keyWindow.bounds) ?
keyWindow.bounds : [UIScreen mainScreen].bounds;
alertWindow = [[UIWindow alloc] initWithFrame:keyWindowBounds];
}
alertWindow.backgroundColor = [UIColor clearColor];
alertWindow.rootViewController = [[UIViewController alloc] init];
alertWindow.rootViewController.view.backgroundColor = [UIColor clearColor];
alertWindow.windowLevel = UIWindowLevelAlert;
[alertWindow makeKeyAndVisible];
_alertWindow = alertWindow;
[alertWindow.rootViewController presentViewController:alert animated:YES completion:nil];
}

- (void)dismissAlert {
_alertWindow.hidden = YES;
_alertWindow.rootViewController = nil;
_alertWindow = nil;
[_keyWindow makeKeyAndVisible];
_keyWindow = nil;
}

@end

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
Loading