Sunday, April 5, 2015

networking - How is WhatsApp able to receive messages when not in use?


I'm curious about how WhatsApp is able to receive messages when not in use.


I mean, I understand that WhatsApp works using the Internet connection rather than the cellphone network. Imagine that I haven't touched my phone in hours. At that moment, a friend sends me a message on WhatsApp. I get it immediately. Does that mean that WhatsApp is keeping the Internet connection connected at all times? Does that mean that WhatsApp acts as a server, opening ports on the phone? Or maybe a long-running HTTP request?



Answer



At first, I thought this was most likely an instance of Android cloud to device messaging, but it can't be: WhatsApp doesn't declare the necessary permissions, and it works in Eclair (Android 2.1), while cloud to device messaging (and its replacement, Google Cloud Messaging) require at least Froyo (Android 2.2).


However, it is most likely some sort of push notification service. It's impossible to say exactly how it's implemented without access to WhatsApp's source code.


The part about it being able to receive messages when not in use is relatively easy to explain, though. The app almost certainly has a service which runs in the background to check in with the server periodically (or receive the server push, or whatever it does). When you receive a message, the service pops up a notification.



As for the question as to how the server could do a push, here's a possibility (again, I can't verify without source code):



  1. WhatsApp starts and opens two sockets: One to listen on and one to send a message to the server.

  2. WhatsApps starts listening on the first socket.

  3. WhatsApp sends a message containing your phone number and the port of the listening socket to the server and waits for an acknowledgement.

  4. The server records the phone and port numbers in the message and the IP address that the message came from.

  5. The server sends an acknowledgement to the app.

  6. The app receives the acknowledgement and closes the message socket.

  7. A message with your phone number as the destination comes into the server.

  8. The server uses the IP address and port number it has associated with your phone number and uses that information to push the message to your phone.



For this to work, the app would need to monitor the state of the network connection and reset the listening socket / resend the registration message when necessary (if the IP address changes, for example).


Saturday, April 4, 2015

charging - How to select a Non OEM USB Type C charger or cable for my device?


Internet is replete with reports of problems of Type C accessories. Also reported here, Can a faulty Micro-USB cable cause damage to your device?


How do I go about selecting right cable or charger , assuming I have a Pixel ?


Note: This is a self answered question drawing from the spadework in answering a different question and felt it may be useful to share, given Type C is gaining popularity. Additional answers are of of course welcome ! Guidelines in answer are not restricted to Pixel .



Answer




USB C Chargers/ Cables are a minefield - In implementation




  • The standards (as they should) are said to clear and consistent but implementation has been shoddy causing multiple problems and even burnouts. One Plus pioneered Type C on Android (One Plus Two) and set a wrong precedent by saving few cents, maybe, with a non- standard resistor . They are not the only ones, Apple and Google too , to an extent ( not to forget laptops )




  • Coming to Google, sample this, quoted from reddit post Please ELI5:Chargers, charging cables, and safety for my Pixel where Nathan K , says :



    • On buying USB cables having USB_IF certification (USB C )






USB-IF Certification testing costs money -- lots of money. $10,000 per product. So a lot of generic manufacturers simply do not do it. Instead, they make products by the seat-of-their-pants. Others, like Apple and Google say "Screw the USB-IF, we know better than them. We can self-certify." So products you buy in an Apple Store or from Google may not have a USB-IF logo, but are (mostly) good. (There are some exceptions I've discovered, noted in my list.)



(Emphasis supplied)



  • On Chargers




...Google sells people on buying a $35 USB-PD charger its own product doesn't even utilize. The only time it would be used is with expensive peripherals like charge-through hubs.



( I am not sure what exactly is not utilized, haven't researched further )


So, whom to trust ?


Nathan K is an independent tester, not affiliated to anyone (Google Plus ). Benson Leung is a Google software engineer ( Google Plus ). Individually and collectively, they carry out tests of practically any USB Type C equipment , chargers and cables and publish them on Google Plus.


They are doing a yeoman service by advising users on choosing right USB Type C accessories and their testing has at times forced prominent brands to remove products from sale (Anker, for example, see their blogs for more examples


Browse their blogs for the right accessory for your device and you may reach out to them on reddit / Google Plus


For Pixel users


You have it on a platter ! Nathan and Benson together they have curated a list of accessories that are tested for your device (details here ). Consider buying charger and cable based on the recommendations linked above (make sure look at the column titled "IR Drop compensation" (should have that). That is a very important feature to correctly charge


You will notice that some negatively or low rated accessories include OEMs like LG, google and Huawei !



Disclaimer: Haven't owned any device with Type C charging and nor I am affiliated anyway with Nathan or Benson


Additional Information



os - How do I install an apk on PC




I am having trouble installing apk files on my PC which has Windows 7 OS .The apk files are backups from my android mobile. After double clicking the apk files it starts initializing and automatically opens the Google Play Store.




Friday, April 3, 2015

How to bypass "Verify your account" (Factory Reset Protection)


I won a Samsung Galaxy S6 Edge, signed into it with my Google account, played around with it, wiped it, and sold it.


Now the person can't get past setup because it's saying he must login with an account previously synced to the phone.


Is there anything I can do from my side to remove this lock?


screenshot




google play store - Package Install via Market sometimes fails and gives seemingly random error message


Some times when I install an application, the installation will fail.


However, the errors it throws are not only incorrect, but seemingly... random.



An example is, it'll fail and throw 'Insufficient storage space.' Blatant lie, I have plenty of space on the phone.


Another example is 'Package file is invalid.'


When I go to redownload the app, it usually installs just fine. On rarer occasions, it'll throw another (can't remember if it's the same) error, but then it'll install just fine.


I'm using stock market, on a stock Droid 3.



Answer



You can get 'Insufficient storage space' messages if you don't have enough space on the internal SD card for the market to be able to download the APK into a temp or data directory. When you reboot your phone or exit from certain apps various caches/data directories are cleared, freeing up space on the internal SD card. This is why this error appears 'randomnly' - because as you use and close apps, the amount of disk space changes. There are several apps on the market that can force cache clean ups for you.


'Package file is invalid' can occur if you have disk errors or networking errors that corrupt the downloaded file. This is why this error appears 'randomnly', as SD card file system issues or dropped/bad packets corrupting the file won't occur every time. FYI, SD card file system errors are often a result of not unmounting the phone properly when connecting it via USB or by yanking the SD card from a reader without unmounting it first ("safely remove hardware" in Windows parlance)


mount - External Ext4 card mounted only for root (!) on Android 5.1 64 bits


In short: if I mount my Ext4 8GB SD card, only root (SU) can see it. The rest of users (so, the rest of apps) don't detect it.


As long as my Ext4 SD card is not correctly mounted (Android always yields Damaged SD card. Format it... blah blah blah), I followed this guide to mount it. And it works:



SD Card is at /dev/block/mmcblk1, so first partition is at /dev/block/mmcblk1p1.
I performed the (not very clear for me) prior ADB process:


su
setprop service.adb.tcp.port 5555
adb kill-server
stop adbd
start adbd
HOME=/sdcard adb start-server
adb connect localhost
adb -s localhost:5555 shell

exit
stop adbd
cat /sdcard/.android/adbkey.pub >> /data/misc/adb/adb_keys
start adbd

And then the card is correctly mounted by doing (as root):


# mount -t ext4 /dev/block/mmcblk1p1 /storage/extSdCard && sleep 5 && /system/bin/vold

Note how it works as SU but not as normal user:


root@unknown:/ # ls /storage/sdcard1

lost+found
root@unknown:/ # exit
u0_a98@unknown:/ $ ls /storage/sdcard1
ls: can't open '/storage/sdcard1': Permission denied

I have tested the above steps via SSH (remote shell).
The SD Card has been formatted from Windows using Minitool Partition Wizard.


I have tested too:



  • Editing the /system/etc/permissions/platform.xml file manually (adding ) to WRITE_EXTERNAL_STORAGE section, as referred here.


  • SDFix.

  • Using Xposed framework with HandleExternalStorage module.


But the apps (Total Commander, Ghost Commander, or any other program) have no access to the Ext4 SDCard.


What else could I try?
Workarounds to make apps read (and write) SD Card accepted too.


Extra data 1:


Note the output of the mount command for both users:


root@unknown:/ # mount | grep "sdcard" -i
/dev/block/mmcblk1p1 /storage/sdcard1 ext4 rw,seclabel,relatime,data=ordered 0 0

root@unknown:/ # exit
u0_a98@unknown:/ $ mount | grep "sdcard"
u0_a98@unknown:/ $ mount | grep "mmcblk"

As can be seen, the root user has a mounted device that the normal user has not (!). I did not know this could happen on Linux.




Thursday, April 2, 2015

applications - i have 500mb available but can't install 2mb app!



i have 500mb available but can't install 2mb app!!!
it's so frustrating i tried uninstalling apps, clearing cache, deleting files ... nothing works.



Please help.




samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...