Add button for opening Huawei battery settings during setup.

This commit is contained in:
akwizgran
2021-04-23 14:25:24 +01:00
parent 93ad483066
commit 4a8d89e2bb
7 changed files with 117 additions and 16 deletions

View File

@@ -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")

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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();
}

View File

@@ -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) {