2

I'm trying to create a WifiConfiguration for Android. All other properties can be set. But if i try to set the SSID or BSSID, i'm getting a segmentation fault (11) and the app and Delphi just hangs.

var
  WIFIConfig: JWifiConfiguration;
begin
  WIFIConfig :=  TJWifiConfiguration.JavaClass.init; 
  WIFIConfig.hiddenSSID := false;                         -> works
  WIFIConfig.SSID := StringtoJString('"YOUR_WLAN_SSID"'); -> App just hangs
end;

http://developer.android.com/reference/android/net/wifi/WifiConfiguration.html

   JWifiConfigurationClass = interface(JObjectClass)
    ['{F69F53BC-BC63-436A-8DA9-57389B30CAA8}']
    function init: JWifiConfiguration; cdecl; overload;

  end;

  [JavaSignature('android/net/wifi/WifiConfiguration')]
  JWifiConfiguration = interface(JObject)
    ['{382E85F2-6BF8-4255-BA3C-03C696BC6451}']
    function _GetSSID: JString;
    procedure _SetSSID(Value: JString);
    function _GetBSSID: JString;
    procedure _SetBSSID(Value: JString);
    function _GethiddenSSID: boolean;
    procedure _SethiddenSSID(Value: boolean);
    function _GetallowedAuthAlgorithms: JBitSet;
    procedure _SetallowedAuthAlgorithms(Value: JBitSet);
    function _GetallowedGroupCiphers: JBitSet;
    procedure _SetallowedGroupCiphers(Value: JBitSet);
    function _GetallowedKeyManagement: JBitSet;
    procedure _SetallowedKeyManagement(Value: JBitSet);
    function _GetallowedPairwiseCiphers: JBitSet;
    procedure _SetallowedPairwiseCiphers(Value: JBitSet);
    function _GetallowedProtocols: JBitSet;
    procedure _SetallowedProtocols(Value: JBitSet);
    function _GetnetworkId: integer;
    procedure _SetnetworkId(Value: integer);
    function _GetpreSharedKey: JString;
    procedure _SetpreSharedKey(Value: JString);
    function _Getstatus: integer;
    procedure _Setstatus(Value: integer);
    function _GetwepTxKeyIndex: integer;
    procedure _SetwepTxKeyIndex(Value: integer);
    function _GetwepKeys: TJavaObjectArray<JString>;
    procedure _SetwepKeys(Value: TJavaObjectArray<JString>);

    property SSID: JString read _GetSSID write _SetSSID;
    property BSSID: JString read _GetBSSID write _SetBSSID;
    property allowedAuthAlgorithms: JBitSet read _GetallowedAuthAlgorithms write _SetallowedAuthAlgorithms;
    property allowedGroupCiphers: JBitSet read _GetallowedGroupCiphers write _SetallowedGroupCiphers;
    property allowedKeyManagement: JBitSet read _GetallowedKeyManagement write _SetallowedKeyManagement;
    property allowedPairwiseCiphers: JBitSet read _GetallowedPairwiseCiphers write _SetallowedPairwiseCiphers;
    property allowedProtocols: JBitSet read _GetallowedProtocols write _SetallowedProtocols;
    property hiddenSSID: boolean read _GethiddenSSID write _SethiddenSSID;
    property networkId: integer read _GetnetworkId write _SetnetworkId;
    property preSharedKey: JString read _GetpreSharedKey write _SetpreSharedKey;
    property priority: integer read _GetnetworkId write _SetnetworkId;
    property status: integer read _Getstatus write _Setstatus;
    property wepKeys: TJavaObjectArray<JString> read _GetwepKeys write _SetwepKeys;
    property wepTxKeyIndex: integer read _GetwepTxKeyIndex write _SetwepTxKeyIndex;

  end;

  TJWifiConfiguration = class(TJavaGenericImport<JWifiConfigurationClass,
    JWifiConfiguration>)
  end;

1 Answers1

0

You're missing the cdecl calling convention on all of your JWifiConfiguration methods.

[JavaSignature('android/net/wifi/WifiConfiguration')]
JWifiConfiguration = interface(JObject)
  ['{382E85F2-6BF8-4255-BA3C-03C696BC6451}']
  function _GetSSID: JString; cdecl;
  procedure _SetSSID(Value: JString); cdecl;
  function _GetBSSID: JString; cdecl;
  procedure _SetBSSID(Value: JString); cdecl;
  function _GethiddenSSID: boolean; cdecl;
  procedure _SethiddenSSID(Value: boolean); cdecl;
  function _GetallowedAuthAlgorithms: JBitSet; cdecl;
  procedure _SetallowedAuthAlgorithms(Value: JBitSet); cdecl;
  function _GetallowedGroupCiphers: JBitSet; cdecl;
  procedure _SetallowedGroupCiphers(Value: JBitSet); cdecl;
  function _GetallowedKeyManagement: JBitSet; cdecl;
  procedure _SetallowedKeyManagement(Value: JBitSet); cdecl;
  function _GetallowedPairwiseCiphers: JBitSet; cdecl;
  procedure _SetallowedPairwiseCiphers(Value: JBitSet); cdecl;
  function _GetallowedProtocols: JBitSet; cdecl;
  procedure _SetallowedProtocols(Value: JBitSet); cdecl;
  function _GetnetworkId: integer; cdecl;
  procedure _SetnetworkId(Value: integer); cdecl;
  function _GetpreSharedKey: JString; cdecl;
  procedure _SetpreSharedKey(Value: JString); cdecl;
  function _Getstatus: integer; cdecl;
  procedure _Setstatus(Value: integer); cdecl;
  function _GetwepTxKeyIndex: integer; cdecl;
  procedure _SetwepTxKeyIndex(Value: integer); cdecl;
  function _GetwepKeys: TJavaObjectArray<JString>; cdecl;
  procedure _SetwepKeys(Value: TJavaObjectArray<JString>); cdecl;

  property SSID: JString read _GetSSID write _SetSSID;
  property BSSID: JString read _GetBSSID write _SetBSSID;
  property allowedAuthAlgorithms: JBitSet read _GetallowedAuthAlgorithms write _SetallowedAuthAlgorithms;
  property allowedGroupCiphers: JBitSet read _GetallowedGroupCiphers write _SetallowedGroupCiphers;
  property allowedKeyManagement: JBitSet read _GetallowedKeyManagement write _SetallowedKeyManagement;
  property allowedPairwiseCiphers: JBitSet read _GetallowedPairwiseCiphers write _SetallowedPairwiseCiphers;
  property allowedProtocols: JBitSet read _GetallowedProtocols write _SetallowedProtocols;
  property hiddenSSID: boolean read _GethiddenSSID write _SethiddenSSID;
  property networkId: integer read _GetnetworkId write _SetnetworkId;
  property preSharedKey: JString read _GetpreSharedKey write _SetpreSharedKey;
  property priority: integer read _GetnetworkId write _SetnetworkId;
  property status: integer read _Getstatus write _Setstatus;
  property wepKeys: TJavaObjectArray<JString> read _GetwepKeys write _SetwepKeys;
  property wepTxKeyIndex: integer read _GetwepTxKeyIndex write _SetwepTxKeyIndex;
end;
Ken White
  • 123,280
  • 14
  • 225
  • 444
  • Tried your soluion, but the cdecl callings doesn't matter. Like i said, the only properties i can't set are SSID and BSSID, all the others work. – user2976209 Nov 10 '13 at 18:29
  • What does logcat tell you? Are there any error messages logged? – Ken White Nov 10 '13 at 18:42
  • 1
    "Tried your soluion, but the cdecl callings doesn't matter." Actually, they do matter. Just because you get away with omitting it sometimes doesn't mean your stack isn't still getting trashed. So you assert that you've now marked the getter & setter as `cdecl` and it still crashes with a segmentation fault? If this is so, why does your comment in the code suggest it hangs? – blong Nov 11 '13 at 09:19
  • What happens if you add in a `const` modifier into the setter declaration? – blong Nov 11 '13 at 09:20
  • Tried with procedure _SetSSID(const Value: JString); cdecl; still crashed with segmentation fault (11). The App hangs with no exception or error messages. Delphi only throws a segmentation fault. – user2976209 Nov 11 '13 at 18:54
  • 1
    I still don't get it. Please rationalise how the app can hang with no error and still throw a segmentation fault. How are you discerning the segmentation fault if it has hung? Illucidate, clarité, expand, expound, if you please. Details aid understanding, you know? – blong Nov 12 '13 at 08:40