mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Catch exception in Huawei power management setup.
This commit is contained in:
@@ -4,13 +4,14 @@ package org.briarproject.briar.android.account;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@@ -19,13 +20,25 @@ import androidx.annotation.UiThread;
|
|||||||
|
|
||||||
import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY;
|
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;
|
||||||
|
import static android.widget.Toast.LENGTH_LONG;
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class HuaweiAppLaunchView extends PowerView {
|
class HuaweiAppLaunchView extends PowerView {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
getLogger(HuaweiAppLaunchView.class.getName());
|
||||||
|
|
||||||
private final static String PACKAGE_NAME = "com.huawei.systemmanager";
|
private final static String PACKAGE_NAME = "com.huawei.systemmanager";
|
||||||
private final static String CLASS_NAME =
|
// First try to open StartupNormalAppListActivity
|
||||||
|
private final static String CLASS_NAME_1 =
|
||||||
|
PACKAGE_NAME + ".startupmgr.ui.StartupNormalAppListActivity";
|
||||||
|
// Fall back to HwPowerManagerActivity
|
||||||
|
private final static String CLASS_NAME_2 =
|
||||||
PACKAGE_NAME + ".power.ui.HwPowerManagerActivity";
|
PACKAGE_NAME + ".power.ui.HwPowerManagerActivity";
|
||||||
|
|
||||||
public HuaweiAppLaunchView(Context context) {
|
public HuaweiAppLaunchView(Context context) {
|
||||||
@@ -52,9 +65,12 @@ class HuaweiAppLaunchView extends PowerView {
|
|||||||
// "App launch" was introduced in EMUI 8 (Android 8.0)
|
// "App launch" was introduced in EMUI 8 (Android 8.0)
|
||||||
if (SDK_INT < 26) return false;
|
if (SDK_INT < 26) return false;
|
||||||
PackageManager pm = context.getPackageManager();
|
PackageManager pm = context.getPackageManager();
|
||||||
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(getIntent(),
|
for (Intent i : getIntents()) {
|
||||||
MATCH_DEFAULT_ONLY);
|
if (!pm.queryIntentActivities(i, MATCH_DEFAULT_ONLY).isEmpty()) {
|
||||||
return !resolveInfos.isEmpty();
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,14 +81,27 @@ class HuaweiAppLaunchView extends PowerView {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onButtonClick() {
|
protected void onButtonClick() {
|
||||||
getContext().startActivity(getIntent());
|
Context context = getContext();
|
||||||
|
for (Intent i : getIntents()) {
|
||||||
|
try {
|
||||||
|
context.startActivity(i);
|
||||||
|
setChecked(true);
|
||||||
|
return;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Toast.makeText(context, R.string.setup_huawei_app_launch_error_toast,
|
||||||
|
LENGTH_LONG).show();
|
||||||
|
// Let the user continue with setup
|
||||||
setChecked(true);
|
setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Intent getIntent() {
|
private static List<Intent> getIntents() {
|
||||||
Intent intent = new Intent();
|
Intent intent1 = new Intent();
|
||||||
intent.setClassName(PACKAGE_NAME, CLASS_NAME);
|
intent1.setClassName(PACKAGE_NAME, CLASS_NAME_1);
|
||||||
return intent;
|
Intent intent2 = new Intent();
|
||||||
|
intent2.setClassName(PACKAGE_NAME, CLASS_NAME_2);
|
||||||
|
return asList(intent1, intent2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
<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_huawei_app_launch_error_toast">Could not open battery settings</string>
|
||||||
<string name="setup_xiaomi_text">To run in the background, Briar needs to be locked to the recent apps list.</string>
|
<string name="setup_xiaomi_text">To run in the background, Briar needs to be locked to the recent apps list.</string>
|
||||||
<string name="setup_xiaomi_button">Protect Briar</string>
|
<string name="setup_xiaomi_button">Protect Briar</string>
|
||||||
<string name="setup_xiaomi_help">If Briar is not locked to the recent apps list, it will be unable to run in the background.</string>
|
<string name="setup_xiaomi_help">If Briar is not locked to the recent apps list, it will be unable to run in the background.</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user