mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Show instructions for locking Briar to the Xiaomi recent apps list.
This commit is contained in:
@@ -32,6 +32,7 @@ public class DozeFragment extends SetupFragment
|
||||
private DozeView dozeView;
|
||||
private HuaweiProtectedAppsView huaweiProtectedAppsView;
|
||||
private HuaweiAppLaunchView huaweiAppLaunchView;
|
||||
private XiaomiView xiaomiView;
|
||||
private Button next;
|
||||
private boolean secondAttempt = false;
|
||||
|
||||
@@ -53,6 +54,8 @@ public class DozeFragment extends SetupFragment
|
||||
huaweiProtectedAppsView.setOnCheckedChangedListener(this);
|
||||
huaweiAppLaunchView = v.findViewById(R.id.huaweiAppLaunchView);
|
||||
huaweiAppLaunchView.setOnCheckedChangedListener(this);
|
||||
xiaomiView = v.findViewById(R.id.xiaomiView);
|
||||
xiaomiView.setOnCheckedChangedListener(this);
|
||||
next = v.findViewById(R.id.next);
|
||||
ProgressBar progressBar = v.findViewById(R.id.progress);
|
||||
|
||||
@@ -98,7 +101,8 @@ public class DozeFragment extends SetupFragment
|
||||
public void onCheckedChanged() {
|
||||
next.setEnabled(dozeView.isChecked() &&
|
||||
huaweiProtectedAppsView.isChecked() &&
|
||||
huaweiAppLaunchView.isChecked());
|
||||
huaweiAppLaunchView.isChecked() &&
|
||||
xiaomiView.isChecked());
|
||||
}
|
||||
|
||||
@SuppressLint("BatteryLife")
|
||||
|
||||
@@ -10,6 +10,7 @@ class DozeHelperImpl implements DozeHelper {
|
||||
Context appContext = context.getApplicationContext();
|
||||
return needsDozeWhitelisting(appContext) ||
|
||||
HuaweiProtectedAppsView.needsToBeShown(appContext) ||
|
||||
HuaweiAppLaunchView.needsToBeShown(appContext);
|
||||
HuaweiAppLaunchView.needsToBeShown(appContext) ||
|
||||
XiaomiView.isXiaomiOrRedmiDevice();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
|
||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
||||
import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
|
||||
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
|
||||
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE;
|
||||
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN;
|
||||
import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
|
||||
import static org.briarproject.briar.android.account.SetupViewModel.State.AUTHOR_NAME;
|
||||
import static org.briarproject.briar.android.account.SetupViewModel.State.CREATED;
|
||||
@@ -55,10 +58,13 @@ public class SetupActivity extends BaseActivity
|
||||
|
||||
private void onStateChanged(SetupViewModel.State state) {
|
||||
if (state == AUTHOR_NAME) {
|
||||
showKeyboard();
|
||||
showInitialFragment(AuthorNameFragment.newInstance());
|
||||
} else if (state == SET_PASSWORD) {
|
||||
showKeyboard();
|
||||
showPasswordFragment();
|
||||
} else if (state == DOZE) {
|
||||
hideKeyboard();
|
||||
showDozeFragment();
|
||||
} else if (state == CREATED || state == FAILED) {
|
||||
// TODO: Show an error if failed
|
||||
@@ -84,6 +90,16 @@ public class SetupActivity extends BaseActivity
|
||||
overridePendingTransition(R.anim.screen_new_in, R.anim.screen_old_out);
|
||||
}
|
||||
|
||||
private void showKeyboard() {
|
||||
getWindow().setSoftInputMode(SOFT_INPUT_ADJUST_RESIZE |
|
||||
SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
}
|
||||
|
||||
private void hideKeyboard() {
|
||||
getWindow().setSoftInputMode(SOFT_INPUT_ADJUST_RESIZE |
|
||||
SOFT_INPUT_STATE_HIDDEN);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void runOnDbThread(Runnable runnable) {
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package org.briarproject.briar.android.account;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.annotation.UiThread;
|
||||
|
||||
import static android.os.Build.BRAND;
|
||||
import static org.briarproject.bramble.util.AndroidUtils.getSystemProperty;
|
||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||
import static org.briarproject.briar.android.util.UiUtils.showOnboardingDialog;
|
||||
|
||||
@UiThread
|
||||
@NotNullByDefault
|
||||
class XiaomiView extends PowerView {
|
||||
|
||||
public XiaomiView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public XiaomiView(Context context, @Nullable AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public XiaomiView(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 isXiaomiOrRedmiDevice();
|
||||
}
|
||||
|
||||
public static boolean isXiaomiOrRedmiDevice() {
|
||||
return "Xiaomi".equalsIgnoreCase(BRAND) ||
|
||||
"Redmi".equalsIgnoreCase(BRAND);
|
||||
}
|
||||
|
||||
@Override
|
||||
@StringRes
|
||||
protected int getHelpText() {
|
||||
return R.string.setup_xiaomi_help;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onButtonClick() {
|
||||
int bodyRes = isMiuiTenOrLater()
|
||||
? R.string.setup_xiaomi_dialog_body_new
|
||||
: R.string.setup_xiaomi_dialog_body_old;
|
||||
showOnboardingDialog(getContext(), getContext().getString(bodyRes));
|
||||
setChecked(true);
|
||||
}
|
||||
|
||||
private boolean isMiuiTenOrLater() {
|
||||
String version = getSystemProperty("ro.miui.ui.version.name");
|
||||
if (isNullOrEmpty(version)) return false;
|
||||
version = version.replaceAll("[^\\d]", "");
|
||||
try {
|
||||
return Integer.parseInt(version) >= 10;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user