Skip to content

Commit

Permalink
[WIP] 2024/12/06 15:42
Browse files Browse the repository at this point in the history
  • Loading branch information
s1204IT committed Dec 6, 2024
1 parent eacf07e commit e00cc6c
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 78 deletions.
3 changes: 0 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ android {
targetCompatibility JavaVersion.VERSION_21
}

lintOptions {
ignore 'ProtectedPermissions'
}
}

dependencies {
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="jp.co.benesse.dcha.permission.ACCESS_SYSTEM" />

<application
Expand Down
165 changes: 93 additions & 72 deletions app/src/main/java/com/saradabar/easyblu/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.content.ServiceConnection;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
Expand Down Expand Up @@ -40,7 +39,6 @@ public class MainActivity extends Activity {
private static final boolean CT3 = Build.PRODUCT.equals("TAB-A04-BR3");
private static final String DCHA_PACKAGE = "jp.co.benesse.dcha.dchaservice";
private static final String DCHA_SERVICE = DCHA_PACKAGE + ".DchaService";
private static final String DCHA_STATE = "dcha_state";
private static final int DIGICHALIZE_STATUS_DIGICHALIZED = 3;
private static final String DCHA_SYSTEM_COPY = "/cache/..";
private static final int DCHA_REBOOT_RECOVERY = 1;
Expand Down Expand Up @@ -107,10 +105,7 @@ private void init() {

})
.setNegativeButton("キャンセル", (dialog, which) -> {
try {
Settings.System.putInt(getContentResolver(), DCHA_STATE, DIGICHALIZE_STATUS_DIGICHALIZED);
} catch (Exception ignored) {
}
setDigichalized();
startActivity(new Intent().setClassName(SETTINGS_PACKAGE, SETTINGS_ACTIVITY));
})
.show();
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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)
Expand All @@ -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());
Expand Down

0 comments on commit e00cc6c

Please sign in to comment.