Skip to content

Commit

Permalink
[Exposed-UI]: optimize for doze mode white list
Browse files Browse the repository at this point in the history
  • Loading branch information
维术 committed Feb 2, 2018
1 parent e180502 commit 92912e0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
25 changes: 22 additions & 3 deletions VirtualApp/app/src/main/java/io/virtualapp/home/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
Expand All @@ -16,6 +17,7 @@
import android.os.Process;
import android.os.RemoteException;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
Expand Down Expand Up @@ -72,6 +74,8 @@ public class HomeActivity extends VActivity implements HomeContract.HomeView {

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

private static final String SHOW_DOZE_ALERT_KEY = "SHOW_DOZE_ALERT_KEY";

private HomeContract.HomePresenter mPresenter;
private TwoGearsView mLoadingView;
private RecyclerView mLauncherView;
Expand Down Expand Up @@ -697,6 +701,10 @@ private void alertForDoze() {
if (powerManager == null) {
return;
}
boolean showAlert = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(SHOW_DOZE_ALERT_KEY, true);
if (!showAlert) {
return;
}
String packageName = getPackageName();
boolean ignoringBatteryOptimizations = powerManager.isIgnoringBatteryOptimizations(packageName);
if (!ignoringBatteryOptimizations) {
Expand All @@ -707,12 +715,23 @@ private void alertForDoze() {
.setMessage(R.string.alert_for_doze_mode_content)
.setPositiveButton(R.string.alert_for_doze_mode_yes, (dialog, which) -> {
try {
startActivity(new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
Uri.parse("package:" + packageName)));
} catch (Throwable ignored) {
startActivity(new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, Uri.parse("package:" + getPackageName())));
} catch (ActivityNotFoundException ignored) {
// ActivityNotFoundException on some devices.
try {
startActivity(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS));
} catch (Throwable e) {
PreferenceManager.getDefaultSharedPreferences(HomeActivity.this)
.edit().putBoolean(SHOW_DOZE_ALERT_KEY, false).apply();
}
} catch (Throwable e) {
PreferenceManager.getDefaultSharedPreferences(HomeActivity.this)
.edit().putBoolean(SHOW_DOZE_ALERT_KEY, false).apply();
}
})
.setNegativeButton(R.string.alert_for_doze_mode_no, (dialog, which) ->
PreferenceManager.getDefaultSharedPreferences(HomeActivity.this)
.edit().putBoolean(SHOW_DOZE_ALERT_KEY, false).apply())
.create();
try {
alertDialog.show();
Expand Down
1 change: 1 addition & 0 deletions VirtualApp/app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<string name="alert_for_doze_mode_title">关于后台运行</string>
<string name="alert_for_doze_mode_content">为了让VAExposed内部运行的应用不会频繁被系统杀死,请允许把VAExposed加入电池优化白名单;同时,VAExposed会尽量保证APP不滥用此权限。请在接下来的系统弹窗中选择"允许" :)</string>
<string name="alert_for_doze_mode_yes">朕同意了</string>
<string name="alert_for_doze_mode_no">我拒绝</string>
<string name="about_faq_title">常见问题</string>
<string name="clear_app">清除\n数据</string>
<string name="stop_app">强制\n停止</string>
Expand Down
1 change: 1 addition & 0 deletions VirtualApp/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<string name="alert_for_doze_mode_title">Tips</string>
<string name="alert_for_doze_mode_content">Please allow VAExposed running in background, otherwise you may not receive notification of some inner app.</string>
<string name="alert_for_doze_mode_yes">Allow</string>
<string name="alert_for_doze_mode_no">Deny</string>
<string name="about_faq_title">FAQ</string>
<string name="clear_app">Clear\nData</string>
<string name="stop_app">Force\nStop</string>
Expand Down

0 comments on commit 92912e0

Please sign in to comment.