Skip to content

Commit

Permalink
opt: gallery - change backup server, now support onedrive in some ver…
Browse files Browse the repository at this point in the history
…sion and fixed google backup
  • Loading branch information
Sevtinge committed May 5, 2024
1 parent bb1fdb7 commit aea47e4
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,87 @@
/*
* This file is part of HyperCeiler.
* This file is part of HyperCeiler.
* HyperCeiler is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License.
* HyperCeiler is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
package com.sevtinge.hyperceiler.module.hook.gallery;

import com.sevtinge.hyperceiler.module.base.BaseHook;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodReplacement;

public class ChangeBackupServer extends BaseHook {
@Override
public void init() throws NoSuchMethodException {
boolean getBackupServer = mPrefsMap.getStringAsInt("gallery_backup_server", 0) == 2;
findAndHookMethod("com.miui.gallery.transfer.GoogleSyncHelper", "isCloudServiceOffLine", new MethodHook(){
@Override
protected void before(MethodHookParam param) throws Throwable {
param.setResult(getBackupServer);
boolean isXiaomi = mPrefsMap.getStringAsInt("gallery_backup_server", 0) == 1;
boolean isGoogle = mPrefsMap.getStringAsInt("gallery_backup_server", 0) == 2;
boolean isOneDrive = mPrefsMap.getStringAsInt("gallery_backup_server", 0) == 3;
if (isOneDrive) {
findAndHookMethod("com.miui.gallery.ui.GallerySettingsFragment", "initGlobalBackupPreference", new MethodHook() {
XC_MethodHook.Unhook isInternationalHook;

@Override
protected void before(MethodHookParam param) throws Throwable {
isInternationalHook = findAndHookMethodUseUnhook("com.miui.gallery.util.BaseBuildUtil", lpparam.classLoader, "isInternational", XC_MethodReplacement.returnConstant(true));
}

@Override
protected void after(MethodHookParam param) throws Throwable {
if (isInternationalHook != null) isInternationalHook.unhook();
isInternationalHook = null;
}
});
findAndHookMethod("com.miui.gallery.util.PhotoModelTypeUtil", "isSupportOneDrive", new MethodHook() {
@Override
protected void before(MethodHookParam param) throws Throwable {
param.setResult(true);
}
});
} else {
if (isXiaomi) {
findAndHookMethod("com.miui.gallery.ui.GallerySettingsFragment", "initGlobalBackupPreference", new MethodHook() {
XC_MethodHook.Unhook isInternationalHook;

@Override
protected void before(MethodHookParam param) throws Throwable {
isInternationalHook = findAndHookMethodUseUnhook("com.miui.gallery.util.BaseBuildUtil", lpparam.classLoader, "isInternational", XC_MethodReplacement.returnConstant(false));
}

@Override
protected void after(MethodHookParam param) throws Throwable {
if (isInternationalHook != null) isInternationalHook.unhook();
isInternationalHook = null;
}
});
}
try {
findAndHookMethod("com.miui.gallery.transfer.GoogleSyncHelper", "isCloudServiceOffLine", new MethodHook() {
@Override
protected void before(MethodHookParam param) throws Throwable {
param.setResult(isGoogle);
}
});
} catch (Throwable t) {
findAndHookMethod("com.miui.gallery.util.BuildUtil", "isGlobal", new MethodHook() {
@Override
protected void before(MethodHookParam param) throws Throwable {
param.setResult(isGoogle);
}
});
}
});
}
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@
<string name="gallery_backup_server">备份服务提供商</string>
<string name="gallery_backup_server_xiaomi">小米云服务</string>
<string name="gallery_backup_server_google">Google</string>
<string name="gallery_backup_server_onedrive">Google 与 OneDrive</string>
<!--MIUI 安全组件-->
<string name="guard_provider">MIUI 安全组件</string>
<string name="guard_provider_hyperos">系统安全组件</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -968,12 +968,14 @@
<item>@string/array_default</item>
<item>@string/gallery_backup_server_xiaomi</item>
<item>@string/gallery_backup_server_google</item>
<item>@string/gallery_backup_server_onedrive</item>
</string-array>

<string-array name="gallery_backup_server_values">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>

<string-array name="theme_manager_version_code">
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@
<string name="gallery_backup_server">Backup server</string>
<string name="gallery_backup_server_xiaomi">Xiaomi Cloud Service</string>
<string name="gallery_backup_server_google">Google</string>
<string name="gallery_backup_server_onedrive">Google &amp; OneDrive</string>
<!--MIUI security components-->
<string name="guard_provider">MIUI security components</string>
<string name="guard_provider_hyperos">System Security Components</string>
Expand Down

0 comments on commit aea47e4

Please sign in to comment.