mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Add button for opening Huawei battery settings during setup.
This commit is contained in:
@@ -30,7 +30,8 @@ public class DozeFragment extends SetupFragment
|
|||||||
private final static String TAG = DozeFragment.class.getName();
|
private final static String TAG = DozeFragment.class.getName();
|
||||||
|
|
||||||
private DozeView dozeView;
|
private DozeView dozeView;
|
||||||
private HuaweiView huaweiView;
|
private HuaweiProtectedAppsView huaweiProtectedAppsView;
|
||||||
|
private HuaweiAppLaunchView huaweiAppLaunchView;
|
||||||
private Button next;
|
private Button next;
|
||||||
private boolean secondAttempt = false;
|
private boolean secondAttempt = false;
|
||||||
|
|
||||||
@@ -48,8 +49,10 @@ public class DozeFragment extends SetupFragment
|
|||||||
false);
|
false);
|
||||||
dozeView = v.findViewById(R.id.dozeView);
|
dozeView = v.findViewById(R.id.dozeView);
|
||||||
dozeView.setOnCheckedChangedListener(this);
|
dozeView.setOnCheckedChangedListener(this);
|
||||||
huaweiView = v.findViewById(R.id.huaweiView);
|
huaweiProtectedAppsView = v.findViewById(R.id.huaweiProtectedAppsView);
|
||||||
huaweiView.setOnCheckedChangedListener(this);
|
huaweiProtectedAppsView.setOnCheckedChangedListener(this);
|
||||||
|
huaweiAppLaunchView = v.findViewById(R.id.huaweiAppLaunchView);
|
||||||
|
huaweiAppLaunchView.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);
|
||||||
|
|
||||||
@@ -93,7 +96,9 @@ public class DozeFragment extends SetupFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged() {
|
public void onCheckedChanged() {
|
||||||
next.setEnabled(dozeView.isChecked() && huaweiView.isChecked());
|
next.setEnabled(dozeView.isChecked() &&
|
||||||
|
huaweiProtectedAppsView.isChecked() &&
|
||||||
|
huaweiAppLaunchView.isChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("BatteryLife")
|
@SuppressLint("BatteryLife")
|
||||||
|
|||||||
@@ -2,13 +2,14 @@ package org.briarproject.briar.android.account;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import static org.briarproject.briar.android.account.HuaweiView.needsToBeShown;
|
|
||||||
import static org.briarproject.briar.android.util.UiUtils.needsDozeWhitelisting;
|
import static org.briarproject.briar.android.util.UiUtils.needsDozeWhitelisting;
|
||||||
|
|
||||||
class DozeHelperImpl implements DozeHelper {
|
class DozeHelperImpl implements DozeHelper {
|
||||||
@Override
|
@Override
|
||||||
public boolean needToShowDozeFragment(Context context) {
|
public boolean needToShowDozeFragment(Context context) {
|
||||||
return needsDozeWhitelisting(context.getApplicationContext()) ||
|
Context appContext = context.getApplicationContext();
|
||||||
needsToBeShown(context.getApplicationContext());
|
return needsDozeWhitelisting(appContext) ||
|
||||||
|
HuaweiProtectedAppsView.needsToBeShown(appContext) ||
|
||||||
|
HuaweiAppLaunchView.needsToBeShown(appContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
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;
|
||||||
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
@NotNullByDefault
|
||||||
|
class HuaweiAppLaunchView extends PowerView {
|
||||||
|
|
||||||
|
private final static String PACKAGE_NAME = "com.huawei.systemmanager";
|
||||||
|
private final static String CLASS_NAME =
|
||||||
|
PACKAGE_NAME + ".power.ui.HwPowerManagerActivity";
|
||||||
|
|
||||||
|
public HuaweiAppLaunchView(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HuaweiAppLaunchView(Context context, @Nullable AttributeSet attrs) {
|
||||||
|
this(context, attrs, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HuaweiAppLaunchView(Context context, @Nullable AttributeSet attrs,
|
||||||
|
int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
setText(R.string.setup_huawei_app_launch_text);
|
||||||
|
setButtonText(R.string.setup_huawei_app_launch_button);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean needsToBeShown() {
|
||||||
|
return needsToBeShown(getContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean needsToBeShown(Context context) {
|
||||||
|
// "App launch" was introduced in EMUI 8 (Android 8.0)
|
||||||
|
if (SDK_INT < 26) return false;
|
||||||
|
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_huawei_app_launch_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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -17,25 +17,28 @@ import javax.annotation.Nullable;
|
|||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
|
||||||
|
import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY;
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class HuaweiView extends PowerView {
|
class HuaweiProtectedAppsView extends PowerView {
|
||||||
|
|
||||||
private final static String PACKAGE_NAME = "com.huawei.systemmanager";
|
private final static String PACKAGE_NAME = "com.huawei.systemmanager";
|
||||||
private final static String CLASS_NAME =
|
private final static String CLASS_NAME =
|
||||||
PACKAGE_NAME + ".optimize.process.ProtectActivity";
|
PACKAGE_NAME + ".optimize.process.ProtectActivity";
|
||||||
|
|
||||||
public HuaweiView(Context context) {
|
public HuaweiProtectedAppsView(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HuaweiView(Context context, @Nullable AttributeSet attrs) {
|
public HuaweiProtectedAppsView(Context context,
|
||||||
|
@Nullable AttributeSet attrs) {
|
||||||
this(context, attrs, 0);
|
this(context, attrs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HuaweiView(Context context, @Nullable AttributeSet attrs,
|
public HuaweiProtectedAppsView(Context context,
|
||||||
|
@Nullable AttributeSet attrs,
|
||||||
int defStyleAttr) {
|
int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
setText(R.string.setup_huawei_text);
|
setText(R.string.setup_huawei_text);
|
||||||
@@ -52,7 +55,7 @@ class HuaweiView extends PowerView {
|
|||||||
if (SDK_INT >= 24) return false;
|
if (SDK_INT >= 24) return false;
|
||||||
PackageManager pm = context.getPackageManager();
|
PackageManager pm = context.getPackageManager();
|
||||||
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(getIntent(),
|
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(getIntent(),
|
||||||
PackageManager.MATCH_DEFAULT_ONLY);
|
MATCH_DEFAULT_ONLY);
|
||||||
return !resolveInfos.isEmpty();
|
return !resolveInfos.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +43,6 @@ abstract class PowerView extends ConstraintLayout {
|
|||||||
this(context, attrs, 0);
|
this(context, attrs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
|
||||||
public PowerView(Context context, @Nullable AttributeSet attrs,
|
public PowerView(Context context, @Nullable AttributeSet attrs,
|
||||||
int defStyleAttr) {
|
int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
@@ -85,6 +84,7 @@ abstract class PowerView extends ConstraintLayout {
|
|||||||
setChecked(ss.value[0]); // also calls listener
|
setChecked(ss.value[0]); // also calls listener
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||||
public abstract boolean needsToBeShown();
|
public abstract boolean needsToBeShown();
|
||||||
|
|
||||||
public void setChecked(boolean checked) {
|
public void setChecked(boolean checked) {
|
||||||
|
|||||||
@@ -15,18 +15,29 @@
|
|||||||
android:id="@+id/dozeView"
|
android:id="@+id/dozeView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingBottom="@dimen/margin_large"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<org.briarproject.briar.android.account.HuaweiView
|
<org.briarproject.briar.android.account.HuaweiProtectedAppsView
|
||||||
android:id="@+id/huaweiView"
|
android:id="@+id/huaweiProtectedAppsView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingBottom="@dimen/margin_large"
|
||||||
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/dozeView" />
|
app:layout_constraintTop_toBottomOf="@+id/dozeView" />
|
||||||
|
|
||||||
|
<org.briarproject.briar.android.account.HuaweiAppLaunchView
|
||||||
|
android:id="@+id/huaweiAppLaunchView"
|
||||||
|
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/huaweiProtectedAppsView" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/next"
|
android:id="@+id/next"
|
||||||
style="@style/BriarButton"
|
style="@style/BriarButton"
|
||||||
@@ -37,7 +48,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/huaweiView"
|
app:layout_constraintTop_toBottomOf="@+id/huaweiAppLaunchView"
|
||||||
app:layout_constraintVertical_bias="1.0"
|
app:layout_constraintVertical_bias="1.0"
|
||||||
tools:enabled="true" />
|
tools:enabled="true" />
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,9 @@
|
|||||||
<string name="setup_huawei_text">Please tap the button below and make sure Briar is protected in the \"Protected Apps\" screen.</string>
|
<string name="setup_huawei_text">Please tap the button below and make sure Briar is protected in the \"Protected Apps\" screen.</string>
|
||||||
<string name="setup_huawei_button">Protect Briar</string>
|
<string name="setup_huawei_button">Protect Briar</string>
|
||||||
<string name="setup_huawei_help">If Briar is not added to the protected apps list, it will be unable to run in the background.</string>
|
<string name="setup_huawei_help">If Briar is not added to the protected apps list, it will be unable to run in the background.</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_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="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