From e00cc6ca37996cb9edc45623aa1f7dc73fde0de9 Mon Sep 17 00:00:00 2001 From: Syuugo Date: Fri, 6 Dec 2024 15:43:01 +0900 Subject: [PATCH] [WIP] 2024/12/06 15:42 --- app/build.gradle | 3 - app/src/main/AndroidManifest.xml | 3 - .../com/saradabar/easyblu/MainActivity.java | 165 ++++++++++-------- 3 files changed, 93 insertions(+), 78 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a55a809..2662380 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -40,9 +40,6 @@ android { targetCompatibility JavaVersion.VERSION_21 } - lintOptions { - ignore 'ProtectedPermissions' - } } dependencies { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 761b857..79c6e4e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,9 +1,6 @@ - - - { - try { - Settings.System.putInt(getContentResolver(), DCHA_STATE, DIGICHALIZE_STATUS_DIGICHALIZED); - } catch (Exception ignored) { - } + setDigichalized(); startActivity(new Intent().setClassName(SETTINGS_PACKAGE, SETTINGS_ACTIVITY)); }) .show(); @@ -203,49 +198,36 @@ public void execute(String str) { void overwriteFrp() { addText("- 通知:DchaService にバインドしています。"); - if (!bindService(new Intent(DCHA_SERVICE).setPackage(DCHA_PACKAGE), new ServiceConnection() { - @Override - public void onServiceConnected(ComponentName componentName, IBinder iBinder) { - mDchaService = IDchaService.Stub.asInterface(iBinder); - addText("- 通知:" + FRP_ORIGIN_PATH + " をコピーしています。"); - try { - mDchaService.copyUpdateImage(FRP_ORIGIN_PATH, DCHA_SYSTEM_COPY + Environment.getExternalStorageDirectory() + FRP_FIXING_FILE); - } catch (Exception e) { - addText("- 通知:" + FRP_ORIGIN_PATH + " のコピーに失敗しました。"); - addText(e.toString()); - init(); - return; - } - try { - File file = new File(Environment.getExternalStorageDirectory(), FRP_FIXING_FILE); - DataInputStream dataInStream = new DataInputStream(new BufferedInputStream(new FileInputStream(new File(Environment.getExternalStorageDirectory(), FRP_FIXING_FILE)))); - DataOutputStream dataOutStream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(new File(Environment.getExternalStorageDirectory(), FRP_FIXING_TEMP)))); - int[] tmpHex = new int[(int) file.length()]; - addText("- 通知:" + FRP_FIXING_FILE + " ファイルサイズ -> " + file.length()); - int i = 0; - while ((tmpHex[i] = dataInStream.read()) != -1) i++; - tmpHex[tmpHex.length - 1] = 1; - for (int q : tmpHex) dataOutStream.write(q); - dataInStream.close(); - dataOutStream.close(); - //addText("- 通知:読込データ -> " + Arrays.toString(tmpHex)); - addText("- 通知:" + FRP_FIXING_FILE + " の修正が完了しました。"); - addText("- 通知:" + FRP_FIXING_FILE + " を " + FRP_ORIGIN_PATH + " に上書きしています。"); - mDchaService.copyUpdateImage(Environment.getExternalStorageDirectory() + FRP_FIXING_FILE, DCHA_SYSTEM_COPY + FRP_ORIGIN_PATH); - - openSettings(); - } catch (Exception e) { - addText("- 通知:エラーが発生しました。"); - addText(e.toString()); - init(); - } - unbindService(this); - } - @Override - public void onServiceDisconnected(ComponentName componentName) { - } - }, Context.BIND_AUTO_CREATE)) { - addText("- 通知:DchaService への接続に失敗しました。"); + addText("- 通知:" + FRP_ORIGIN_PATH + " をコピーしています。"); + try { + copyFile(FRP_ORIGIN_PATH, getFilesDir() + FRP_FIXING_FILE); + } catch (Exception e) { + addText("- 通知:" + FRP_ORIGIN_PATH + " のコピーに失敗しました。"); + addText(e.toString()); + init(); + return; + } + try { + File file = new File(getFilesDir(), FRP_FIXING_FILE); + DataInputStream dataInStream = new DataInputStream(new BufferedInputStream(new FileInputStream(new File(getFilesDir(), FRP_FIXING_FILE)))); + DataOutputStream dataOutStream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(new File(getFilesDir(), FRP_FIXING_TEMP)))); + int[] tmpHex = new int[(int) file.length()]; + addText("- 通知:" + FRP_FIXING_FILE + " ファイルサイズ -> " + file.length()); + int i = 0; + while ((tmpHex[i] = dataInStream.read()) != -1) i++; + tmpHex[tmpHex.length - 1] = 1; + for (int q : tmpHex) dataOutStream.write(q); + dataInStream.close(); + dataOutStream.close(); + //addText("- 通知:読込データ -> " + Arrays.toString(tmpHex)); + addText("- 通知:" + FRP_FIXING_FILE + " の修正が完了しました。"); + addText("- 通知:" + FRP_FIXING_FILE + " を " + FRP_ORIGIN_PATH + " に上書きしています。"); + copyFile(getFilesDir() + FRP_FIXING_FILE, FRP_ORIGIN_PATH); + + openSettings(); + } catch (Exception e) { + addText("- 通知:エラーが発生しました。"); + addText(e.toString()); init(); } } @@ -305,25 +287,7 @@ private void runReset() { new AlertDialog.Builder(MainActivity.this) .setTitle("初期化しますか?") .setMessage("初期化後、もう一度、EasyBLU を実行してください") - .setPositiveButton("実行", (dialog, which) -> { - if (!bindService(new Intent(DCHA_SERVICE).setPackage(DCHA_PACKAGE), new ServiceConnection() { - @Override - public void onServiceConnected(ComponentName componentName, IBinder iBinder) { - mDchaService = IDchaService.Stub.asInterface(iBinder); - try { - mDchaService.rebootPad(DCHA_REBOOT_RECOVERY, null); - } catch (RemoteException ignored) { - } - unbindService(this); - } - @Override - public void onServiceDisconnected(ComponentName componentName) { - } - }, Context.BIND_AUTO_CREATE)) { - addText("- 通知:DchaService への接続に失敗しました。"); - init(); - } - }) + .setPositiveButton("実行", (dialog, which) -> rebootWipeUserData()) .setNegativeButton("キャンセル", (dialog, which) -> dialog.dismiss()) .show(); } @@ -345,10 +309,7 @@ private void openSettings() { ※このアプリの実行が1回目の場合、1度初期化してください 詳しくは GitHub を参照してください""") .setPositiveButton("OK", (dialog, which) -> { - try { - Settings.System.putInt(getContentResolver(), DCHA_STATE, DIGICHALIZE_STATUS_DIGICHALIZED); - } catch (Exception ignored) { - } + setDigichalized(); startActivity( Settings.Secure.getInt(getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1 ? new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS) @@ -360,6 +321,66 @@ private void openSettings() { .show(); } + private void copyFile(String src, String dst) { + if (!bindService(new Intent(DCHA_SERVICE).setPackage(DCHA_PACKAGE), new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName componentName, IBinder iBinder) { + mDchaService = IDchaService.Stub.asInterface(iBinder); + try { + mDchaService.copyUpdateImage(src, DCHA_SYSTEM_COPY + dst); + } catch (RemoteException ignored) { + } + unbindService(this); + } + @Override + public void onServiceDisconnected(ComponentName componentName) { + } + }, Context.BIND_AUTO_CREATE)) { + addText("- 通知:DchaService への接続に失敗しました。"); + init(); + } + } + + private void rebootWipeUserData() { + if (!bindService(new Intent(DCHA_SERVICE).setPackage(DCHA_PACKAGE), new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName componentName, IBinder iBinder) { + mDchaService = IDchaService.Stub.asInterface(iBinder); + try { + mDchaService.rebootPad(DCHA_REBOOT_RECOVERY, null); + } catch (RemoteException ignored) { + } + unbindService(this); + } + @Override + public void onServiceDisconnected(ComponentName componentName) { + } + }, Context.BIND_AUTO_CREATE)) { + addText("- 通知:DchaService への接続に失敗しました。"); + init(); + } + } + + private void setDigichalized() { + if (!bindService(new Intent(DCHA_SERVICE).setPackage(DCHA_PACKAGE), new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName componentName, IBinder iBinder) { + mDchaService = IDchaService.Stub.asInterface(iBinder); + try { + mDchaService.setSetupStatus(DIGICHALIZE_STATUS_DIGICHALIZED); + } catch (RemoteException ignored) { + } + unbindService(this); + } + @Override + public void onServiceDisconnected(ComponentName componentName) { + } + }, Context.BIND_AUTO_CREATE)) { + addText("- 通知:DchaService への接続に失敗しました。"); + init(); + } + } + private void addText(@NonNull String str) { TextView textView = findViewById(R.id.text); textView.append(str.isEmpty() ? System.lineSeparator() : " " + str + System.lineSeparator());