Merge pull request #197 from Nutomic/disable-battery-optimization

Added item to disable battery optimizations
This commit is contained in:
Marvin W 2016-11-04 22:37:04 +01:00 committed by GitHub
commit 4893dead0a
5 changed files with 81 additions and 1 deletions

View File

@ -80,7 +80,7 @@ android {
lintOptions {
// TODO: Remove MissingTranslation once we have stable strings and proper translations.
disable 'MissingTranslation', 'InvalidPackage'
disable 'MissingTranslation', 'InvalidPackage', 'BatteryLife'
}
buildTypes {

View File

@ -80,6 +80,8 @@
<uses-permission android:name="com.google.android.c2dm.permission.SEND"/>
<uses-permission android:name="org.microg.gms.STATUS_BROADCAST"/>
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<application
android:allowBackup="false"
android:icon="@mipmap/ic_core_service_app"

View File

@ -16,6 +16,8 @@
package org.microg.gms.ui;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.support.annotation.NonNull;
@ -33,6 +35,7 @@ import org.microg.tools.selfcheck.NlpStatusChecks;
import org.microg.tools.selfcheck.PermissionCheckGroup;
import org.microg.tools.selfcheck.RomSpoofSignatureChecks;
import org.microg.tools.selfcheck.SelfCheckGroup;
import org.microg.tools.selfcheck.SystemChecks;
import org.microg.tools.ui.AbstractAboutFragment;
import org.microg.tools.ui.AbstractSelfCheckFragment;
@ -111,6 +114,9 @@ public class SettingsActivity extends AppCompatActivity {
if (SDK_INT > LOLLIPOP_MR1) {
checks.add(new PermissionCheckGroup(ACCESS_COARSE_LOCATION, WRITE_EXTERNAL_STORAGE, GET_ACCOUNTS, READ_PHONE_STATE));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
checks.add(new SystemChecks());
}
checks.add(new NlpOsCompatChecks());
checks.add(new NlpStatusChecks());
}
@ -119,6 +125,14 @@ public class SettingsActivity extends AppCompatActivity {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
reset(LayoutInflater.from(getContext()));
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SystemChecks.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
reset(LayoutInflater.from(getContext()));
else
super.onActivityResult(requestCode, resultCode, data);
}
}
public static class MyAboutFragment extends AbstractAboutFragment {

View File

@ -0,0 +1,60 @@
/*
* Copyright 2013-2016 microG Project Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.microg.tools.selfcheck;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.PowerManager;
import android.provider.Settings;
import android.support.v4.app.Fragment;
import com.google.android.gms.R;
import static org.microg.tools.selfcheck.SelfCheckGroup.Result.Negative;
import static org.microg.tools.selfcheck.SelfCheckGroup.Result.Positive;
@TargetApi(23)
public class SystemChecks implements SelfCheckGroup, SelfCheckGroup.CheckResolver {
public static final int REQUEST_IGNORE_BATTERY_OPTIMIZATIONS = 417;
@Override
public String getGroupName(Context context) {
return context.getString(R.string.self_check_cat_system);
}
@Override
public void doChecks(Context context, ResultCollector collector) {
isBatterySavingDisabled(context, collector);
}
private void isBatterySavingDisabled(final Context context, ResultCollector collector) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
collector.addResult(context.getString(R.string.self_check_name_battery_optimizations),
pm.isIgnoringBatteryOptimizations(context.getPackageName()) ? Positive : Negative,
context.getString(R.string.self_check_resolution_battery_optimizations), this);
}
@Override
public void tryResolve(Fragment fragment) {
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + fragment.getActivity().getPackageName()));
fragment.startActivityForResult(intent, REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
}
}

View File

@ -99,6 +99,10 @@ This can take a couple of minutes."</string>
<string name="self_check_resolution_correct_sig">Either the installed %1$s is not compatible or signature spoofing is not active for it. Please check the documentation on which applications and ROMs are compatible.</string>
<string name="perm_extended_access_label">Extended access to Google services</string>
<string name="self_check_cat_system">System</string>
<string name="self_check_name_battery_optimizations">Battery optimizations ignored:</string>
<string name="self_check_resolution_battery_optimizations">Touch here to disable battery optimizations. Not doing this may result in misbehaving applications</string>
<string name="lacking_permission_toast">microG Services Core: Lacking permission %1$s</string>
<string name="place_picker_select_title">Select this location</string>