我正在尝试为Google Glass开发Android应用程序,从远程服务器中取出apk,卸载并重新安装。
Glass已植根,我在/ system / app中安装了安装程序应用程序,我通过从cert& amp;创建密钥库文件来签署应用程序pk8文件,
密钥库文件,
https://android.googlesource.com/platform/build/+/android-4.4.2_r2.0.1/target/product/security
我在安装程序apk中安装了代码,
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();
}
}
我进入下面的例外
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)
清单权限
<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"/>
答案 0 :(得分:0)
想通了,
将APK放入/ sys / priv-app文件夹。