mirror of
https://github.com/syncthing/syncthing-android.git
synced 2025-01-07 10:42:07 +00:00
* AndroidManifest: Add WRITE_SETTINGS, WRITE_SECURE_SETTINGS permissions * Disable DuraSpeed on HMD Global phones (fixes #404) * lint: Ignore ProtectedPermissions
This commit is contained in:
parent
0ad977fb4e
commit
ab1fffe8d2
3 changed files with 36 additions and 0 deletions
|
@ -13,6 +13,7 @@
|
|||
<issue id="UnusedAttribute" severity="ignore" />
|
||||
<!-- We don't care about Google App Indexing -->
|
||||
<issue id="GoogleAppIndexingWarning" severity="ignore" />
|
||||
<issue id="ProtectedPermissions" severity="ignore" />
|
||||
<!-- Disabling battery optimizations is optional, so this warning doesn't apply to us -->
|
||||
<issue id="BatteryLife" severity="ignore" />
|
||||
<!-- Ignore types in translations (not handled by us) -->
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<!-- FOREGROUND_SERVICE is required since Android 9 SDK 28 -->
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<!-- WRITE_SETTINGS, WRITE_SECURE_SETTINGS are required to disable DuraSpeed -->
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
|
||||
|
||||
<application
|
||||
android:allowBackup="false"
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package com.nutomic.syncthingandroid.receiver;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import com.nutomic.syncthingandroid.service.Constants;
|
||||
|
@ -14,6 +17,8 @@ import com.nutomic.syncthingandroid.service.SyncthingService;
|
|||
|
||||
import eu.chainfire.libsuperuser.Shell;
|
||||
|
||||
import java.lang.SecurityException;
|
||||
|
||||
public class BootReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final String TAG = "BootReceiver";
|
||||
|
@ -30,6 +35,10 @@ public class BootReceiver extends BroadcastReceiver {
|
|||
return;
|
||||
}
|
||||
|
||||
if ("HMD Global".equals(Build.MANUFACTURER)) {
|
||||
disableDuraSpeed(context);
|
||||
}
|
||||
|
||||
if (packageReplaced) {
|
||||
if (getPrefUseRoot(context) && Shell.SU.available()) {
|
||||
/**
|
||||
|
@ -73,4 +82,27 @@ public class BootReceiver extends BroadcastReceiver {
|
|||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return sp.getBoolean(Constants.PREF_USE_ROOT, false);
|
||||
}
|
||||
|
||||
@TargetApi(17)
|
||||
/**
|
||||
* Prerequisistes:
|
||||
* - android.permission.WRITE_SETTINGS
|
||||
* - android.permission.WRITE_SECURE_SETTINGS
|
||||
* adb shell pm grant com.github.catfriend1.syncthingandroid android.permission.WRITE_SECURE_SETTINGS
|
||||
* adb shell pm grant com.github.catfriend1.syncthingandroid.debug android.permission.WRITE_SECURE_SETTINGS
|
||||
*/
|
||||
private static void disableDuraSpeed(Context context) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "Disabling DuraSpeed");
|
||||
try {
|
||||
Settings.Global.putInt(context.getContentResolver(), "setting.duraspeed.enabled", -1);
|
||||
Settings.Global.putInt(context.getContentResolver(), "setting.duraspeed.enabled", 0);
|
||||
} catch (SecurityException e) {
|
||||
Log.e(TAG, "Insufficient permissions to disable DuraSpeed. Run the following command from a computer: 'adb shell pm grant " +
|
||||
context.getPackageName() +
|
||||
" android.permission.WRITE_SECURE_SETTINGS'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue