mirror of https://github.com/YTVanced/VancedMicroG
66 lines
2.6 KiB
Java
Executable File
66 lines
2.6 KiB
Java
Executable File
/*
|
|
* Copyright (C) 2013-2017 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.gms.ui;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.net.Uri;
|
|
import android.os.Build;
|
|
import android.os.PowerManager;
|
|
import android.provider.Settings;
|
|
import android.view.View;
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
import com.mgoogle.android.gms.R;
|
|
|
|
import org.microg.gms.gcm.GcmPrefs;
|
|
import org.microg.tools.ui.Condition;
|
|
|
|
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
|
|
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
|
|
import static android.Manifest.permission.GET_ACCOUNTS;
|
|
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
|
|
import static android.Manifest.permission.READ_PHONE_STATE;
|
|
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
|
|
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
|
import static android.os.Build.VERSION.SDK_INT;
|
|
|
|
public class Conditions {
|
|
public static final Condition GCM_BATTERY_OPTIMIZATIONS = new Condition.Builder()
|
|
.title(R.string.cond_gcm_bat_title)
|
|
.summary(R.string.cond_gcm_bat_summary)
|
|
.evaluation(new Condition.Evaluation() {
|
|
@Override
|
|
public boolean isActive(Context context) {
|
|
if (SDK_INT < 23) return false;
|
|
if (!GcmPrefs.get(context).isEnabled()) return false;
|
|
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
|
return !pm.isIgnoringBatteryOptimizations(context.getPackageName());
|
|
}
|
|
})
|
|
.firstAction(R.string.cond_gcm_bat_action, v -> {
|
|
if (SDK_INT < 23) return;
|
|
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
|
intent.setData(Uri.parse("package:" + v.getContext().getPackageName()));
|
|
v.getContext().startActivity(intent);
|
|
}).build();
|
|
|
|
}
|