mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Add button for opening Xiaomi battery settings during setup.
This commit is contained in:
@@ -459,6 +459,7 @@
|
|||||||
<package android:name="com.huawei.systemmanager" />
|
<package android:name="com.huawei.systemmanager" />
|
||||||
<package android:name="com.huawei.powergenie" />
|
<package android:name="com.huawei.powergenie" />
|
||||||
<package android:name="com.evenwell.PowerMonitor" />
|
<package android:name="com.evenwell.PowerMonitor" />
|
||||||
|
<package android:name="com.miui.powerkeeper" />
|
||||||
|
|
||||||
<intent>
|
<intent>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public class DozeFragment extends SetupFragment
|
|||||||
private DozeView dozeView;
|
private DozeView dozeView;
|
||||||
private HuaweiProtectedAppsView huaweiProtectedAppsView;
|
private HuaweiProtectedAppsView huaweiProtectedAppsView;
|
||||||
private HuaweiAppLaunchView huaweiAppLaunchView;
|
private HuaweiAppLaunchView huaweiAppLaunchView;
|
||||||
|
private XiaomiBatterySaverView xiaomiBatterySaverView;
|
||||||
private Button next;
|
private Button next;
|
||||||
private boolean secondAttempt = false;
|
private boolean secondAttempt = false;
|
||||||
|
|
||||||
@@ -53,6 +54,8 @@ public class DozeFragment extends SetupFragment
|
|||||||
huaweiProtectedAppsView.setOnCheckedChangedListener(this);
|
huaweiProtectedAppsView.setOnCheckedChangedListener(this);
|
||||||
huaweiAppLaunchView = v.findViewById(R.id.huaweiAppLaunchView);
|
huaweiAppLaunchView = v.findViewById(R.id.huaweiAppLaunchView);
|
||||||
huaweiAppLaunchView.setOnCheckedChangedListener(this);
|
huaweiAppLaunchView.setOnCheckedChangedListener(this);
|
||||||
|
xiaomiBatterySaverView = v.findViewById(R.id.xiaomiBatterySaverView);
|
||||||
|
xiaomiBatterySaverView.setOnCheckedChangedListener(this);
|
||||||
next = v.findViewById(R.id.next);
|
next = v.findViewById(R.id.next);
|
||||||
ProgressBar progressBar = v.findViewById(R.id.progress);
|
ProgressBar progressBar = v.findViewById(R.id.progress);
|
||||||
|
|
||||||
@@ -98,7 +101,8 @@ public class DozeFragment extends SetupFragment
|
|||||||
public void onCheckedChanged() {
|
public void onCheckedChanged() {
|
||||||
next.setEnabled(dozeView.isChecked() &&
|
next.setEnabled(dozeView.isChecked() &&
|
||||||
huaweiProtectedAppsView.isChecked() &&
|
huaweiProtectedAppsView.isChecked() &&
|
||||||
huaweiAppLaunchView.isChecked());
|
huaweiAppLaunchView.isChecked() &&
|
||||||
|
xiaomiBatterySaverView.isChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("BatteryLife")
|
@SuppressLint("BatteryLife")
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ class DozeHelperImpl implements DozeHelper {
|
|||||||
Context appContext = context.getApplicationContext();
|
Context appContext = context.getApplicationContext();
|
||||||
return needsDozeWhitelisting(appContext) ||
|
return needsDozeWhitelisting(appContext) ||
|
||||||
HuaweiProtectedAppsView.needsToBeShown(appContext) ||
|
HuaweiProtectedAppsView.needsToBeShown(appContext) ||
|
||||||
HuaweiAppLaunchView.needsToBeShown(appContext);
|
HuaweiAppLaunchView.needsToBeShown(appContext) ||
|
||||||
|
XiaomiBatterySaverView.needsToBeShown(appContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package org.briarproject.briar.android.account;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.ResolveInfo;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.briar.R;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes;
|
||||||
|
import androidx.annotation.UiThread;
|
||||||
|
|
||||||
|
import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY;
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
@NotNullByDefault
|
||||||
|
class XiaomiBatterySaverView extends PowerView {
|
||||||
|
|
||||||
|
private final static String PACKAGE_NAME = "com.miui.powerkeeper";
|
||||||
|
private final static String CLASS_NAME =
|
||||||
|
PACKAGE_NAME + ".ui.HiddenAppsConfigActivity";
|
||||||
|
|
||||||
|
public XiaomiBatterySaverView(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public XiaomiBatterySaverView(Context context,
|
||||||
|
@Nullable AttributeSet attrs) {
|
||||||
|
this(context, attrs, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public XiaomiBatterySaverView(Context context, @Nullable AttributeSet attrs,
|
||||||
|
int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
setText(R.string.setup_xiaomi_text);
|
||||||
|
setButtonText(R.string.setup_xiaomi_button);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean needsToBeShown() {
|
||||||
|
return needsToBeShown(getContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean needsToBeShown(Context context) {
|
||||||
|
PackageManager pm = context.getPackageManager();
|
||||||
|
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(getIntent(),
|
||||||
|
MATCH_DEFAULT_ONLY);
|
||||||
|
return !resolveInfos.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@StringRes
|
||||||
|
protected int getHelpText() {
|
||||||
|
return R.string.setup_xiaomi_help;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onButtonClick() {
|
||||||
|
getContext().startActivity(getIntent());
|
||||||
|
setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Intent getIntent() {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.setClassName(PACKAGE_NAME, CLASS_NAME);
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -38,6 +38,15 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/huaweiProtectedAppsView" />
|
app:layout_constraintTop_toBottomOf="@+id/huaweiProtectedAppsView" />
|
||||||
|
|
||||||
|
<org.briarproject.briar.android.account.XiaomiBatterySaverView
|
||||||
|
android:id="@+id/xiaomiBatterySaverView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingBottom="@dimen/margin_large"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/huaweiAppLaunchView" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/next"
|
android:id="@+id/next"
|
||||||
style="@style/BriarButton"
|
style="@style/BriarButton"
|
||||||
@@ -48,7 +57,7 @@
|
|||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/huaweiAppLaunchView"
|
app:layout_constraintTop_toBottomOf="@+id/xiaomiBatterySaverView"
|
||||||
app:layout_constraintVertical_bias="1.0"
|
app:layout_constraintVertical_bias="1.0"
|
||||||
tools:enabled="true" />
|
tools:enabled="true" />
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,9 @@
|
|||||||
<string name="setup_huawei_app_launch_text">Please tap the button below, open the \"App launch\" screen and make sure Briar is set to \"Manage manually\".</string>
|
<string name="setup_huawei_app_launch_text">Please tap the button below, open the \"App launch\" screen and make sure Briar is set to \"Manage manually\".</string>
|
||||||
<string name="setup_huawei_app_launch_button">Open Battery Settings</string>
|
<string name="setup_huawei_app_launch_button">Open Battery Settings</string>
|
||||||
<string name="setup_huawei_app_launch_help">If Briar is not set to \"Manage manually\" in the \"App launch\" screen, it will not be able to run in the background.</string>
|
<string name="setup_huawei_app_launch_help">If Briar is not set to \"Manage manually\" in the \"App launch\" screen, it will not be able to run in the background.</string>
|
||||||
|
<string name="setup_xiaomi_text">Please tap the button below and make sure Briar is set to \"No restrictions\".</string>
|
||||||
|
<string name="setup_xiaomi_button">Open Background Settings</string>
|
||||||
|
<string name="setup_xiaomi_help">Briar must be set to \"No restrictions\" in the \"Background settings\" screen so that it can run in the background.</string>
|
||||||
<string name="warning_dozed">%s was unable to run in the background</string>
|
<string name="warning_dozed">%s was unable to run in the background</string>
|
||||||
|
|
||||||
<!-- Login -->
|
<!-- Login -->
|
||||||
|
|||||||
Reference in New Issue
Block a user