2016-03-25 13 views
0

system directoryにインストールする必要のあるアプリがあります。私はadb commandsを使っていくつかの方法を見てきました。私はこれがPCとUSBケーブル上のadbシェルを使用して行わなければならないと思う。しかし、アプリがDataからsystemにPCを必要とせずに自分自身をコピーする方法はありますか?Androidアプリは、ルートデバイス上のシステムディレクトリに自分自身をコピーできますか?

私が知っているように、Runtimeを使用してアンドロイドアプリ内でコマンドを実行できます。だから、onCreateの中でこのコードを試しましたが、.apkファイルはコピーされません。これはコードです:

boolean isSystemApp = (getApplicationInfo().flags 
      & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0; 
    if (!isSystemApp) { 
     Toast.makeText(getApplicationContext(), "not system app", Toast.LENGTH_LONG).show(); 
     try { 

      String [] commandsOldVersions = {"adb shell\n", "su\n", "mount -o rw,remount /system\n", 
        "adb push eyedetection.apk /sdcard/\n", "adb shell\n","su cd /sdcard\n" 
      , "mv eyedetection.apk /system/app\n","su chmod 644/system/app/eyedetection.apk\n" }; 

      String [] commandsNewVersions = {"adb shell\n", "su\n", "mount -o rw,remount /system\n", 
        "adb push eyedetection.apk /sdcard/\n", "adb shell\n","su cd /sdcard\n" 
      , "mv eyedetection.apk /system/priv-app\n", "su chmod 644/system/priv-app/eyedetection.apk\n" }; 

      if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { 
       // for 4.3 and higher versions, execute the following line (because they've changed their system files hierarchies): 
       Process process = Runtime.getRuntime().exec(commandsNewVersions); 
       BufferedReader br= new BufferedReader(new InputStreamReader(process.getInputStream())); 
       Log.i("cmd", br.readLine()); 

      }//end if 
      else { 
       //for older version, execute this line instead 
       Process process= Runtime.getRuntime().exec(commandsOldVersions); 
       BufferedReader br= new BufferedReader(new InputStreamReader(process.getInputStream())); 
       Log.i("cmd", br.readLine()); 
      }//end else. 

      Runtime.getRuntime().exec("adb reboot"); 


     }//end try. 

     catch (IOException e) { 
      Log.i("eyedetection", "error in executing adb commands"); 
     }//end catch. 
    }//end if the app is not system app. 

    else { 
     Toast.makeText(getApplicationContext(), "It's system app", Toast.LENGTH_LONG).show(); 

    } 

アプリがクラッシュしていませんが、私はlogcatにこれらの行を取得:

03-24 22:28:37.661 22576-22576/com.project.android.eyedetection W/dalvikvm: VFY: unable to resolve virtual method 143: Landroid/app/Notification$Builder;.setPriority (I)Landroid/app/Notification$Builder; 
03-24 22:28:37.661 22576-22576/com.project.android.eyedetection D/dalvikvm: VFY: replacing opcode 0x6e at 0x0042 
03-24 22:28:37.661 22576-22576/com.project.android.eyedetection I/dalvikvm: Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method com.google.android.gms.common.os.b 
03-24 22:28:37.661 22576-22576/com.project.android.eyedetection W/dalvikvm: VFY: unable to resolve virtual method 142: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder; 
03-24 22:28:37.661 22576-22576/com.project.android.eyedetection D/dalvikvm: VFY: replacing opcode 0x6e at 0x00ce 
03-24 22:28:37.661 22576-22576/com.project.android.eyedetection E/dalvikvm: Could not find class 'android.app.Notification$BigTextStyle', referenced from method com.google.android.gms.common.os.b 
03-24 22:28:37.661 22576-22576/com.project.android.eyedetection W/dalvikvm: VFY: unable to resolve new-instance 42 (Landroid/app/Notification$BigTextStyle;) in Lcom/google/android/gms/common/os; 
03-24 22:28:37.661 22576-22576/com.project.android.eyedetection D/dalvikvm: VFY: replacing opcode 0x22 at 0x00d7 
03-24 22:28:37.661 22576-22576/com.project.android.eyedetection D/dalvikvm: DexOpt: couldn't find field Landroid/app/Notification;.extras 
03-24 22:28:37.661 22576-22576/com.project.android.eyedetection W/dalvikvm: VFY: unable to resolve instance field 10 
03-24 22:28:37.661 22576-22576/com.project.android.eyedetection D/dalvikvm: VFY: replacing opcode 0x54 at 0x00ed 
03-24 22:28:37.661 22576-22576/com.project.android.eyedetection D/dalvikvm: DexOpt: unable to opt direct call 0x0084 at 0x4c in Lcom/google/android/gms/common/os;.b 
03-24 22:28:37.669 22576-22576/com.project.android.eyedetection D/dalvikvm: DexOpt: unable to opt direct call 0x0084 at 0xd9 in Lcom/google/android/gms/common/os;.b 
03-24 22:28:37.669 22576-22576/com.project.android.eyedetection E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.ou.a 
03-24 22:28:37.669 22576-22576/com.project.android.eyedetection W/dalvikvm: VFY: unable to resolve check-cast 30 (Landroid/app/AppOpsManager;) in Lcom/google/android/gms/common/ou; 
03-24 22:28:37.669 22576-22576/com.project.android.eyedetection D/dalvikvm: VFY: replacing opcode 0x1f at 0x0010 
03-24 22:28:37.669 22576-22576/com.project.android.eyedetection I/dalvikvm: Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.ou.a 
03-24 22:28:37.669 22576-22576/com.project.android.eyedetection W/dalvikvm: VFY: unable to resolve virtual method 430: Landroid/content/pm/PackageManager;.getPackageInstaller()Landroid/content/pm/PackageInstaller; 
03-24 22:28:37.669 22576-22576/com.project.android.eyedetection D/dalvikvm: VFY: replacing opcode 0x6e at 0x000d 
03-24 22:28:37.677 22576-22576/com.project.android.eyedetection E/dalvikvm: Could not find class 'android.os.UserManager', referenced from method com.google.android.gms.common.ou.p 
03-24 22:28:37.677 22576-22576/com.project.android.eyedetection W/dalvikvm: VFY: unable to resolve check-cast 235 (Landroid/os/UserManager;) in Lcom/google/android/gms/common/ou; 
03-24 22:28:37.677 22576-22576/com.project.android.eyedetection D/dalvikvm: VFY: replacing opcode 0x1f at 0x000e 
03-24 22:28:37.677 22576-22576/com.project.android.eyedetection D/dalvikvm: DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_64_BIT_ABIS 
03-24 22:28:37.677 22576-22576/com.project.android.eyedetection W/dalvikvm: VFY: unable to resolve static field 119 (SUPPORTED_64_BIT_ABIS) in Landroid/os/Build; 
03-24 22:28:37.677 22576-22576/com.project.android.eyedetection D/dalvikvm: VFY: replacing opcode 0x62 at 0x000d 
03-24 22:28:37.685 22576-22576/com.project.android.eyedetection D/dalvikvm: DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_ABIS 
03-24 22:28:37.685 22576-22576/com.project.android.eyedetection W/dalvikvm: VFY: unable to resolve static field 120 (SUPPORTED_ABIS) in Landroid/os/Build; 
03-24 22:28:37.685 22576-22576/com.project.android.eyedetection D/dalvikvm: VFY: replacing opcode 0x62 at 0x0008 
03-24 22:28:37.685 22576-22576/com.project.android.eyedetection D/dalvikvm: DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_32_BIT_ABIS 
03-24 22:28:37.685 22576-22576/com.project.android.eyedetection W/dalvikvm: VFY: unable to resolve static field 118 (SUPPORTED_32_BIT_ABIS) in Landroid/os/Build; 
03-24 22:28:37.685 22576-22576/com.project.android.eyedetection D/dalvikvm: VFY: replacing opcode 0x62 at 0x0008 
03-24 22:28:37.685 22576-22576/com.project.android.eyedetection D/dalvikvm: DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_64_BIT_ABIS 
03-24 22:28:37.685 22576-22576/com.project.android.eyedetection W/dalvikvm: VFY: unable to resolve static field 119 (SUPPORTED_64_BIT_ABIS) in Landroid/os/Build; 

また、これらの行:

03-24 22:29:54.388 23305-23305/com.project.android.eyedetection E/GMPM: GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services. Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin. 
03-24 22:29:54.388 23305-23305/com.project.android.eyedetection E/GMPM: Scheduler not set. Not logging error/warn. 
03-24 22:29:54.403 23305-23335/com.project.android.eyedetection E/GMPM: Uploading is not possible. App measurement disabled 

私はできませんでした問題をlogcatから把握してください。なぜコードが機能しないのですか?アプリをルートのあるデバイスの別のフォルダに自分自身をコピーさせることは可能ですか、またはusbケーブルを使用する必要がありますか?

+0

root権限を持っていない限り、システムディレクトリにアクセスすることはできません。 – Shahzeb

+0

ルートアクセスとはどういう意味ですか?私のデバイスはrootになっていてsuを走らせることができます。ありがとう。 – Dania

+1

@ Shahzeb私は彼が明示的に彼は手動でそれをadbを使って行うことができると言ったが、それをプログラム的に行う必要があると思う。つまり、アプリは単独でそれを行います。 –

答えて

1

'adb xxx'コマンドは、Android/LinuxシェルではなくPCシェルでのみ使用できます。あなたの代わりに

  • Runtime.getRuntime().exec("adb reboot")

    • Runtime.getRuntime().exec("reboot")

    を使用する必要があり、ある

+0

ありがとう、私はすべてのadbキーワードを削除しましたが、それでも動作していません。アプリがクラッシュすることはありませんが、問題に投稿されているlogcatに示されているエラーが表示されます。これらのエラーが関連していて、どのように解決できるか教えてください。 – Dania

関連する問題