androidgoogle-glass

Exception with Install APK programmatically


Am trying to develop a android app for Google Glass which pulls apk from remote server, uninstalls and re-installs.

Glass is rooted, I installed installer app in /system/app, I signed the app by creating keystore file from cert & pk8 files,

keystore files,

  1. platform.pk8
  2. platform.x509.pem

https://android.googlesource.com/platform/build/+/android-4.4.2_r2.0.1/target/product/security

Code I followed in installer apk to install,

private void install(String result) throws Exception{
    text.setText("Installing...");
    final String libs = "LD_LIBRARY_PATH=/vendor/lib:/system/lib ";
    final String[] commands = {
            libs + "pm install --user -1 -r " + result
            //        ,libs + "am start -n " + context.getPackageName() + "/" + get_main_activity()
    };


    File file = new File(result);
    if (file.exists()){
        Log.d(TAG,"Found file" + file.getAbsolutePath());
    }else{
        Log.d(TAG, "File not found");
    }




   execute_as_root(commands);


}

private void execute_as_root( String[] commands ) throws Exception{
    try {
        // Do the magic
        Process p = Runtime.getRuntime().exec( "su" );
        InputStream es = p.getErrorStream();
        DataOutputStream os = new DataOutputStream(p.getOutputStream());

        for( String command : commands ) {
            //Log.i(TAG,command);
            os.writeBytes(command + "\n");
        }
        os.writeBytes("exit\n");
        os.flush();
        os.close();

        int read;
        byte[] buffer = new byte[4096];
        String output = new String();
        while ((read = es.read(buffer)) > 0) {
            output += new String(buffer, 0, read);
        }

        p.waitFor();

        Log.e(TAG, output.trim() + " (" + p.exitValue() + ")");
        text.setText("Done");


    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
    } catch (InterruptedException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
    }finally{
        manager.release();
        finish();
    }
}

I get into below exception

java.lang.SecurityException: Permission Denial: broadcast asks to run as user -1 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL or android.permission.INTERACT_ACROSS_USERS
                                                                                           at android.os.Parcel.readException(Parcel.java:1465)
                                                                                           at android.os.Parcel.readException(Parcel.java:1419)
                                                                                           at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:2373)
                                                                                           at com.android.commands.am.Am.sendBroadcast(Am.java:810)
                                                                                           at com.android.commands.am.Am.onRun(Am.java:285)
                                                                                           at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
                                                                                           at com.android.commands.am.Am.main(Am.java:77)
                                                                                           at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
                                                                                           at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:243)
                                                                                           at dalvik.system.NativeStart.main(Native Method)
                                                                                       Permission denied (1)

Manifest Permissions

<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.DELETE_PACKAGES"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL"/>

Solution

  • Figured out,

    Just put the APK in /sys/priv-app folder.