10

I need to create a Robotium application that would use Settings application to turn ON/OFF WIFi from menu Settings->Wireless & networks->Wi-Fi. I managed to find some sample code here that demonstrates how to launch application by having apk file only. The problem is that my Robotium application should have the same signature with the (system) Settings application. While trying to run application I get the error message:

Test run failed: Permission Denial: starting instrumentation ComponentInfo{com.jayway.test/android.test.InstrumentationTestRunner} from pid=354, uid=354 not allowed because package com.jayway.test does not have a signature matching the target com.android.settings

  1. Can I somehow make it work with the Android Emulator?
  2. If I compile an Android phone image, how can I use the Android system signature with my application?
boettger1
  • 418
  • 1
  • 3
  • 9
Michalis
  • 3,109
  • 6
  • 26
  • 24

2 Answers2

16

I was having the same problem.. There are some permissions that only system apps are allowed to have . I was trying to access the adb shell dumpsys commands from my application with the permissions android.permission.DUMP .

The solution to this is ...

In the Android manifest file of your project add the following line in the manifest tag

android:sharedUserId="android.uid.system"

You need to have two signature keys present in the code that is used to build the binary.

platform.x509.pem

platform.pk8

that is present in the

android/build/target/product/security

Download a tool from the net i.e.

signapk.jar

From the eclipse export your unsigned apk. by right click on the project from the android tools. Keep all the things i.e. keys , unsigned apk, and signapk.jar in a folder. Run the following Command

java -jar signapk.jar platform.x509.pem platform.pk8 unsigned.apk signed.apk

unsigned apk is the name of your apk and signed apk is the new name you want . After this just install your signed app in the phone with the command

adb install signed.apk
abraun
  • 35
  • 8
Lord Nick
  • 582
  • 8
  • 29
  • 1
    Nirmit forgot to mention that in order to get `android/build/target/product/security`, you have to checkout the Android source codes tree from [here](http://source.android.com/source/downloading.html). – ChuongPham Dec 10 '13 at 14:09
  • 2
    If you can't checkout full android source code (e.g. youre on Windows) you can checkout this single repository: git clone https://android.googlesource.com/platform/build . Platform files will be under target/product/security – Alexey May 13 '14 at 15:07
  • @NirmitSrivastava: Once an app is signed with the system keys,then if we sideload from eclipse/update it remotely ..in all these cases,will the app automatically get stored in the system/apps folder everytime? – Basher51 Aug 07 '14 at 12:52
  • @NirmitSrivastava: Also,while making the app as system app,other than 'android:sharedUserId="android.uid.system"' in the manifest, do we need to specify any other permissions in there or anywhere else while compiling the apk? – Basher51 Aug 07 '14 at 12:54
  • 2
    Hi I am getting following error while signing. Pls help java.security.cert.CertificateException: Could not parse certificate: java.io.IO Exception: Empty input – Utsav Gupta Aug 25 '14 at 11:48
  • Can somebody give a correct link for correct signapk.jar ? – Utsav Gupta Aug 25 '14 at 11:50
  • I'm getting INSTALL_FAILED_SHARED_USER_INCOMPATIBLE error while trying to install an apk signed by the described procedure. There is no `install` command in `adb shell` in my case, so I'm using `adb install ...` instead of `adb shell install...`. PS. zipalign is utilized as well. – Stan Jun 23 '15 at 13:51
  • @Stan Make sure you are using the correct signature keys for your device. Also you can refer to the following answer http://stackoverflow.com/questions/15205159/install-failed-shared-user-incompatible-while-using-shared-user-id – Lord Nick Jun 24 '15 at 05:43
1

The best way to enable wifi from your application would be to use the WifiManager.

WifiManager wManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);

if(!wManager.isWifiEnabled() && wManager.getWifiState() != WifiManager.WIFI_STATE_ENABLING)
    wManager.setWifiEnabled(true);

Note: You also have to add the following permissions to your manifest

<uses-permission android:name="android.permissions.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permissions.CHANGE_WIFI_STATE" />
Jwsonic
  • 297
  • 4
  • 8
  • I don't just need to switch on/off WiFi. I need to control Settings application with a Robotium script. In fact I want to simulate user clicks to switch on/off WiFi. This process can be done by using a custom script with monkey tool. Although I would like to use Robotium in order to verify if a Access Point was really found. My primary goal is to make this Robotium script have access over com.android.settings.apk. This will bypass the signature mismatch and will let my Robotium script control this APK. – Michalis Aug 25 '10 at 06:45