Skip to content

Commit 92912e0

Browse files
author
维术
committed
[Exposed-UI]: optimize for doze mode white list
1 parent e180502 commit 92912e0

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

VirtualApp/app/src/main/java/io/virtualapp/home/HomeActivity.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.animation.Animator;
44
import android.animation.ObjectAnimator;
55
import android.annotation.SuppressLint;
6+
import android.content.ActivityNotFoundException;
67
import android.content.Context;
78
import android.content.Intent;
89
import android.graphics.Canvas;
@@ -16,6 +17,7 @@
1617
import android.os.Process;
1718
import android.os.RemoteException;
1819
import android.os.SystemClock;
20+
import android.preference.PreferenceManager;
1921
import android.provider.Settings;
2022
import android.support.annotation.Nullable;
2123
import android.support.v7.app.AlertDialog;
@@ -72,6 +74,8 @@ public class HomeActivity extends VActivity implements HomeContract.HomeView {
7274

7375
private static final String TAG = HomeActivity.class.getSimpleName();
7476

77+
private static final String SHOW_DOZE_ALERT_KEY = "SHOW_DOZE_ALERT_KEY";
78+
7579
private HomeContract.HomePresenter mPresenter;
7680
private TwoGearsView mLoadingView;
7781
private RecyclerView mLauncherView;
@@ -697,6 +701,10 @@ private void alertForDoze() {
697701
if (powerManager == null) {
698702
return;
699703
}
704+
boolean showAlert = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(SHOW_DOZE_ALERT_KEY, true);
705+
if (!showAlert) {
706+
return;
707+
}
700708
String packageName = getPackageName();
701709
boolean ignoringBatteryOptimizations = powerManager.isIgnoringBatteryOptimizations(packageName);
702710
if (!ignoringBatteryOptimizations) {
@@ -707,12 +715,23 @@ private void alertForDoze() {
707715
.setMessage(R.string.alert_for_doze_mode_content)
708716
.setPositiveButton(R.string.alert_for_doze_mode_yes, (dialog, which) -> {
709717
try {
710-
startActivity(new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
711-
Uri.parse("package:" + packageName)));
712-
} catch (Throwable ignored) {
718+
startActivity(new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, Uri.parse("package:" + getPackageName())));
719+
} catch (ActivityNotFoundException ignored) {
713720
// ActivityNotFoundException on some devices.
721+
try {
722+
startActivity(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS));
723+
} catch (Throwable e) {
724+
PreferenceManager.getDefaultSharedPreferences(HomeActivity.this)
725+
.edit().putBoolean(SHOW_DOZE_ALERT_KEY, false).apply();
726+
}
727+
} catch (Throwable e) {
728+
PreferenceManager.getDefaultSharedPreferences(HomeActivity.this)
729+
.edit().putBoolean(SHOW_DOZE_ALERT_KEY, false).apply();
714730
}
715731
})
732+
.setNegativeButton(R.string.alert_for_doze_mode_no, (dialog, which) ->
733+
PreferenceManager.getDefaultSharedPreferences(HomeActivity.this)
734+
.edit().putBoolean(SHOW_DOZE_ALERT_KEY, false).apply())
716735
.create();
717736
try {
718737
alertDialog.show();

VirtualApp/app/src/main/res/values-zh-rCN/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<string name="alert_for_doze_mode_title">关于后台运行</string>
5959
<string name="alert_for_doze_mode_content">为了让VAExposed内部运行的应用不会频繁被系统杀死,请允许把VAExposed加入电池优化白名单;同时,VAExposed会尽量保证APP不滥用此权限。请在接下来的系统弹窗中选择"允许" :)</string>
6060
<string name="alert_for_doze_mode_yes">朕同意了</string>
61+
<string name="alert_for_doze_mode_no">我拒绝</string>
6162
<string name="about_faq_title">常见问题</string>
6263
<string name="clear_app">清除\n数据</string>
6364
<string name="stop_app">强制\n停止</string>

VirtualApp/app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<string name="alert_for_doze_mode_title">Tips</string>
6363
<string name="alert_for_doze_mode_content">Please allow VAExposed running in background, otherwise you may not receive notification of some inner app.</string>
6464
<string name="alert_for_doze_mode_yes">Allow</string>
65+
<string name="alert_for_doze_mode_no">Deny</string>
6566
<string name="about_faq_title">FAQ</string>
6667
<string name="clear_app">Clear\nData</string>
6768
<string name="stop_app">Force\nStop</string>

0 commit comments

Comments
 (0)