2

In a mobile iOS system, when double-pressing on the home button, the user will enter an App Switcher, a series of App windows will be displayed. If your own App window has sensitive info, it can be leaked at this stage.

I have managed to use FMX.Platform to catch different App events. I was trying to change to another TabItem instead of a sensitive TabItem. My code can compile, but the display on iOS still remains the same. The code looks like this:

procedure TForm1.FormCreate(Sender: TObject);
var
  aFMXApplicationEventService: IFMXApplicationEventService;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(aFMXApplicationEventService)) then
    aFMXApplicationEventService.SetApplicationEventHandler(HandleAppEvent)
  else
    ShowMessage('Application Event Service is not supported.');
end;

...

function TForm1.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
begin      
  if AAppEvent = TApplicationEvent.aeWillBecomeInactive then begin
    tempActiveTbaItem := TabControl1.TabIndex;
    TabControl1.TabIndex := 4; //4 is a blank tabItem
    TabControl1.UpdateEffects;
  end else
  if AAppEvent = TApplicationEvent.aeEnteredBackground then begin
    tempActiveTbaItem := TabControl1.TabIndex;
    TabControl1.TabIndex := 4;
  end else
  if (AAppEvent = TApplicationEvent.aeBecameActive) and (tempActiveTbaItem <> -1) then begin
    TabControl1.TabIndex := 0;
  end;
    
  Result := True;
end;

I googled the web and found two solutions here:

Making sensitive data disappear in the iOS/iPadOS App Switcher

Hide Sensitive Information in the iOS App Switcher Snapshot Image

But these are for the native Xcode only. Can someone tell me how to do it in Delphi for FMX, please?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Haizhou
  • 127
  • 7

1 Answers1

5

For iOS, this should resolve the problem:

uses
  FMX.Platform.iOS;

// Other code snipped

if AAppEvent = TApplicationEvent.aeWillBecomeInactive then
begin
  tempActiveTbaItem := TabControl1.TabIndex;
  TabControl1.TabIndex := 4; //4 is a blank tabItem
  WindowHandleToPlatform(Handle).View.setNeedsDisplay;
end;

Calling setNeedsDisplay forces the view to repaint

Dave Nottage
  • 3,411
  • 1
  • 20
  • 57
  • Beautifully working!!! for iOS. Will it work on Android as well? – Haizhou Jun 22 '21 at 23:45
  • It does not look possible to implement on Android, since it appears that the `onPause` of the `Activity` needs to be overridden, and the action taken *before* the inherited (`super`) `onPause` is called, as per [examples here](https://stackoverflow.com/questions/27284778/need-to-hide-content-of-program-from-android-overview-screen). Currently in Delphi the WillBecomeActive event is sent after the `onPause` has already occurred, in which Android has taken a snapshot of your screen (with the sensitive data). – Dave Nottage Jun 23 '21 at 00:53
  • 1
    I've filed a report about it in the Quality Portal: http://quality.embarcadero.com/browse/RSP-34252 – Dave Nottage Jun 23 '21 at 01:02
  • You are a star. Hopefully it can be a true crossplatform feature soon. Thanks – Haizhou Jun 23 '21 at 09:49