View Single Post
Posts: 61 | Thanked: 64 times | Joined on Oct 2007 @ EU
#33
@peterleinchen

Thanks, I will check your improved version of the application next week.

However, I still believe there is something wrong with saving data for both files:

/home/user/.config/sim-switcher/.tmp/currentSIM
/home/user/.config/sim-switcher/.tmp/home.plugins

Today I had a situation where home.plugins file was not saved (.tmp directory was empty) and then I didn't got home plugins restored. This would have been very bad if I would not use yesterday savehome command. Maybe you could do a check that the file home.plugins was really saved before killing hildon-home?

Regarding the other problem, I already tried with unlock and the following code is working for me although is not nice. I made it generic so that other users could use it if they will replace WLAN1,2,3 on line 22 with own wlans and then opcode (operator code) for SIM1 on line 58 and 90 from 1 to whatever operator code is in particular case, but this works only if operator code for SIM1 differ from SIM2. Of course if this is useful, the script could be made more generic and add these data that needs to be changed at the beginning of the script.

Code:
#!/bin/sh

CONNECTED=false
DROPCONN=false

call_check ()
{
  # Check no call in progress
  oncall=`run-standalone.sh dbus-send --system --type=method_call --print-reply=literal --dest=com.nokia.csd.Call /com/nokia/csd/call/1 com.nokia.csd.Call.Instance.GetStatus`
  if [ $oncall != "uint32 0" ]; then
    dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:"Sync dropped due to active call!" uint32:0 string:"OK"
    exit 1
  fi
}

# check for existing wifi connectivity
if [ "$(/sbin/route | awk '/au/ {print $1}')" == "default" ]; then
  CONNECTED=true
else
  #Bring up WLAN
  sudo ifconfig wlan0 up
  for i in WLAN1 WLAN2 WLAN3
  do
    # scan for SSIDs, if not found continue
    if [ -z `sudo iwlist wlan0 scan | grep -m 1 -o \"$i\"` ]; then
      continue;
    fi
    # find IAP_ID from SSID
    IAP_ID=`gconftool-2 -R /system/osso/connectivity/IAP | tac | awk "/name = $i/,/connectivity\/IAP/" | awk -F '/|:' '/connectivity\/IAP/{ print $6}'`
    # try to connect to known wifi
    dbus-send --system --type=method_call --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect string:"$IAP_ID" uint32:0
    sleep 20
    if [ "$(/sbin/route | awk '/au/ {print $1}')" == "default" ]; then
      CONNECTED=true
      DROPCONN=true
      break
    fi
  done
  # if no WLAN was found (i.e. outdoor), then put WLAN down
  if [ "$DROPCONN" == "false" ]; then 
    sudo ifconfig wlan0 down
  fi
fi

# If no wifi try with GPRS
if [ "$CONNECTED" == "false" ]; then
  opcode=`dbus-send --system --print-reply=literal --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_registration_status | tr '\n' ' ' | awk '{print $8,$10}' | cut -f1 -d' '`
  
  # Temporary disable SIM switch
  #opcode=10

  # Check lock state of the phone and unlock
  lock=`dbus-send --system --type=method_call --dest="com.nokia.mce" --print-reply "/com/nokia/mce/request" com.nokia.mce.request.get_tklock_mode|awk -F "\"" '/g/ {print $2}'`
  call_check
  dbus-send --system --type=method_call --dest=com.nokia.mce /com/nokia/mce/request com.nokia.mce.request.req_tklock_mode_change string:"unlocked"

  # if operator code is (1) switch to SIM2
  if [ $opcode == 1 ]; then
    sim-switcher SIM2
    if [ $? -ne 0 ]; then
      exit 1
    fi
  fi
  # Connect Internet
  dbus-send --system --type=method_call --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect string:"Internet" uint32:0
  if [ $? -ne 0 ]; then
    exit 1
  fi
  CONNECTED=true
  DROPCONN=true
  sleep 10
fi

if [ "$CONNECTED" == "true" ]; then
  # sync erminig if having connectivity
  #/usr/bin/erminig -a

  # sync MfE
  dbus-send --print-reply --type=method_call --session --dest=com.nokia.asdbus /com/nokia/asdbus com.nokia.asdbus.sync
  sleep 90

  # drop the wifi connection if it was initiated by this script (saves battery)
  if [ "$DROPCONN" == "true" ]; then
    call_check
    dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
  fi
fi

# Switch back to SIM1
if [ $opcode == 1 ]; then
  sim-switcher SIM1
fi

# Lock back if needed
if [ "$lock" == "locked" ]; then
  call_check
  dbus-send --system --type=method_call --dest=com.nokia.mce /com/nokia/mce/request com.nokia.mce.request.req_tklock_mode_change string:"locked"
fi
 

The Following 2 Users Say Thank You to yrannadx For This Useful Post: