Verified Commit 4a8d89e2 authored by akwizgran's avatar akwizgran
Browse files

Add button for opening Huawei battery settings during setup.

parent 93ad4830
Pipeline #6530 passed with stages
in 42 minutes and 25 seconds
......@@ -30,7 +30,8 @@ public class DozeFragment extends SetupFragment
private final static String TAG = DozeFragment.class.getName();
private DozeView dozeView;
private HuaweiView huaweiView;
private HuaweiProtectedAppsView huaweiProtectedAppsView;
private HuaweiAppLaunchView huaweiAppLaunchView;
private Button next;
private boolean secondAttempt = false;
......@@ -48,8 +49,10 @@ public class DozeFragment extends SetupFragment
false);
dozeView = v.findViewById(R.id.dozeView);
dozeView.setOnCheckedChangedListener(this);
huaweiView = v.findViewById(R.id.huaweiView);
huaweiView.setOnCheckedChangedListener(this);
huaweiProtectedAppsView = v.findViewById(R.id.huaweiProtectedAppsView);
huaweiProtectedAppsView.setOnCheckedChangedListener(this);
huaweiAppLaunchView = v.findViewById(R.id.huaweiAppLaunchView);
huaweiAppLaunchView.setOnCheckedChangedListener(this);
next = v.findViewById(R.id.next);
ProgressBar progressBar = v.findViewById(R.id.progress);
......@@ -93,7 +96,9 @@ public class DozeFragment extends SetupFragment
@Override
public void onCheckedChanged() {
next.setEnabled(dozeView.isChecked() && huaweiView.isChecked());
next.setEnabled(dozeView.isChecked() &&
huaweiProtectedAppsView.isChecked() &&
huaweiAppLaunchView.isChecked());
}
@SuppressLint("BatteryLife")
......
......@@ -2,13 +2,14 @@ package org.briarproject.briar.android.account;
import android.content.Context;
import static org.briarproject.briar.android.account.HuaweiView.needsToBeShown;
import static org.briarproject.briar.android.util.UiUtils.needsDozeWhitelisting;
class DozeHelperImpl implements DozeHelper {
@Override
public boolean needToShowDozeFragment(Context context) {
return needsDozeWhitelisting(context.getApplicationContext()) ||
needsToBeShown(context.getApplicationContext());
Context appContext = context.getApplicationContext();
return needsDozeWhitelisting(appContext) ||
HuaweiProtectedAppsView.needsToBeShown(appContext) ||
HuaweiAppLaunchView.needsToBeShown(appContext);
}
}
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.UiThread;
import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY;
import static android.os.Build.VERSION.SDK_INT;
@UiThread
@NotNullByDefault
class HuaweiView extends PowerView {
class HuaweiProtectedAppsView extends PowerView {
private final static String PACKAGE_NAME = "com.huawei.systemmanager";
private final static String CLASS_NAME =
PACKAGE_NAME + ".optimize.process.ProtectActivity";
public HuaweiView(Context context) {
public HuaweiProtectedAppsView(Context context) {
this(context, null);
}
public HuaweiView(Context context, @Nullable AttributeSet attrs) {
public HuaweiProtectedAppsView(Context context,
@Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public HuaweiView(Context context, @Nullable AttributeSet attrs,
public HuaweiProtectedAppsView(Context context,
@Nullable AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
setText(R.string.setup_huawei_text);
......@@ -52,7 +55,7 @@ class HuaweiView extends PowerView {
if (SDK_INT >= 24) return false;
PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(getIntent(),
PackageManager.MATCH_DEFAULT_ONLY);
MATCH_DEFAULT_ONLY);
return !resolveInfos.isEmpty();
}
......
......@@ -43,7 +43,6 @@ abstract class PowerView extends ConstraintLayout {
this(context, attrs, 0);
}
@SuppressWarnings("ConstantConditions")
public PowerView(Context context, @Nullable AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
......@@ -85,6 +84,7 @@ abstract class PowerView extends ConstraintLayout {
setChecked(ss.value[0]); // also calls listener
}
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public abstract boolean needsToBeShown();
public void setChecked(boolean checked) {
......
......@@ -15,18 +15,29 @@
android:id="@+id/dozeView"
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_toTopOf="parent" />
<org.briarproject.briar.android.account.HuaweiView
android:id="@+id/huaweiView"
<org.briarproject.briar.android.account.HuaweiProtectedAppsView
android:id="@+id/huaweiProtectedAppsView"
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/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
android:id="@+id/next"
style="@style/BriarButton"
......@@ -37,7 +48,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/huaweiView"
app:layout_constraintTop_toBottomOf="@+id/huaweiAppLaunchView"
app:layout_constraintVertical_bias="1.0"
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_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_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>
<!-- Login -->
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment